Skip to content

Commit

Permalink
2007-05-08 Krzysztof Kosciuszkiewicz <[email protected]>
Browse files Browse the repository at this point in the history
	* V162
	* New logging framework - tweaked log4c lite.
  • Loading branch information
drvee committed May 8, 2007
1 parent 8482574 commit fe99788
Show file tree
Hide file tree
Showing 27 changed files with 1,130 additions and 169 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2007-05-08 Krzysztof Kosciuszkiewicz <[email protected]>

* V162

* New logging framework - tweaked log4c lite.

2007-05-05 Krzysztof Kosciuszkiewicz <[email protected]>

* V161
Expand Down
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ EXTRA_SOURCES = AUTHORS README COPYING DEVELOPER TODO ChangeLog \

BARIS_HFILES = av.h Buzz_inc.h data.h endianness.h externs.h gamedata.h \
int_types.h macros.h mis.h music.h pace.h proto.h records.h soundfx.h \
soundint.h mmfile.h options.h fs.h utils.h
soundint.h mmfile.h options.h fs.h utils.h log4c.h logging.h

BARIS_OBJS = $(addsuffix .@OBJEXT@, \
admin aimast aimis aipur ast0 ast1 ast2 ast3 ast4 budget crew endgame \
endianness futbub future hardef intel intro main mc2 mc mis_c mis_m museum \
newmis news news_sup news_suq place port prefs prest radar rdplex records \
replay review rush start vab pace gx gr sdl music gamedata mmfile options fs \
utils \
utils logging log4c log_default \
)

all: $(PROG_NAME)
Expand Down
16 changes: 10 additions & 6 deletions admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "externs.h"
#include "av.h"
#include "utils.h"
#include "logging.h"

#define MODEM_ERROR 4
#define NOTSAME 2
Expand All @@ -37,6 +38,8 @@
#define YES 1
#define NO 0

LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT);

extern char Sounds,Option,MAIL;
extern int fOFF;

Expand Down Expand Up @@ -844,8 +847,7 @@ save_game (char *name)
EndOfTurnSave((char *) Data, sizeof ( struct Players));

if ((inf = sOpen("ENDTURN.TMP","rb",1)) == NULL) {
/* WARN */ fprintf (stderr,
"save_game: can't open ENDTURN.TMP\n");
WARNING1("can't read ENDTURN.TMP");
return;
}

Expand All @@ -865,15 +867,15 @@ save_game (char *name)
hdr.compSize = 0; //filelength (fileno (inf));

if ((outf = sOpen (name, "wb", 1)) == NULL) {
/* WARN */ fprintf (stderr, "save_game: can't create %s\n", name);
WARNING2("can't save to file `%s'", name);
goto cleanup;
}

size = fread_dyn(&buf, &buflen, inf);
fclose(inf);
inf = NULL;
if (size < 0) {
perror("save_game");
WARNING1("read error in ENDTURN.TMP");
goto cleanup;
}
hdr.compSize = size;
Expand All @@ -887,7 +889,7 @@ save_game (char *name)
fwrite(buf, size, 1, outf);
else
{
perror("save_game");
WARNING1("read error in REPLAY.DAT");
goto cleanup;
}
fclose(inf);
Expand All @@ -900,12 +902,14 @@ save_game (char *name)
fwrite(buf, size, 1, outf);
else
{
perror("save_game");
WARNING1("read error in EVENT.TMP");
goto cleanup;
}
fclose(inf);
inf = NULL;
}
else
WARNING1("can't read EVENT.TMP");

cleanup:
if (outf)
Expand Down
34 changes: 24 additions & 10 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "options.h"
#include "pace.h"
#include "utils.h"
#include "logging.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -69,6 +70,8 @@
# endif
#endif

LOG_DEFAULT_CATEGORY(filesys);

static DIR *save_dir;

/*
Expand All @@ -91,17 +94,15 @@ try_fopen(const char *fname, const char *mode)
FILE* fp = NULL;
assert(fname);
assert(mode);
/* DEBUG */ /* fprintf(stderr, "fs: trying to fopen(\"%s\", \"%s\")\n",
cooked, mode); */
TRACE3("trying to open `%s' (mode %s)", fname, mode);

fp = fopen(fname, mode);

/* TODO: ENOENT is POSIX, ANSI equivalent for file does not exist??? */
if (!fp && errno != ENOENT)
{
int esave = errno;
/* WARN */ fprintf(stderr, "fs: can't open %s: %s\n",
fname, strerror(errno));
WARNING3("can't access file `%s': %s", fname, strerror(errno));
errno = esave;
}

Expand All @@ -128,6 +129,7 @@ s_open_helper(const char *base, const char *name, const char *mode, ...)
for (p = va_arg(ap, char *); p; p = va_arg(ap, char *))
{
char *s = NULL;
int was_upper = 0;
size_t len_p = strlen(p);

len2 = len_base + len_name + len_p + 3;
Expand All @@ -144,14 +146,20 @@ s_open_helper(const char *base, const char *name, const char *mode, ...)
/* try lowercase version */
for (s = cooked + len_base + len_p + 2; *s; ++s)
if (isupper(*s))
{
was_upper += 1;
*s = tolower(*s);
}

f = try_fopen(cooked, mode);
if (was_upper)
f = try_fopen(cooked, mode);
if (f)
break;
}
serrno = errno;
va_end(ap);
if (f)
INFO3("opened file `%s' (mode %s)", cooked, mode);
free(cooked);
errno = serrno;
return f;
Expand Down Expand Up @@ -212,8 +220,8 @@ sOpen(const char *name, const char *mode, int type)
if (!f)
{
int serrno = errno;
/* WARN */ fprintf(stderr, "can't %s file %s in %s dir(s).\n",
strchr(mode, 'w') ? "create" : "access", name, where);
WARNING4("can't %s file `%s' in %s dir(s)",
strchr(mode, 'w') ? "write" : "open", name, where);
errno = serrno;
}
return f;
Expand All @@ -228,8 +236,12 @@ remove_savedat(const char *name)
int rv = 0;

sprintf(cooked, "%s/%s", options.dir_savegame, name);
INFO2("removing save game file `%s'", cooked);
fix_pathsep(cooked);
rv = remove(cooked);
if (rv < 0)
WARNING3("failed to remove save game file `%s': %s",
cooked, strerror(errno));
free(cooked);
return rv;
}
Expand Down Expand Up @@ -262,7 +274,7 @@ slurp_gamedat(const char *name)

if (len < 0)
{
/* ERROR */ perror("slurp_gamedat");
CRITICAL2("could not read file `%s'", name);
exit(EXIT_FAILURE);
}

Expand All @@ -274,8 +286,11 @@ slurp_gamedat(const char *name)
int
create_save_dir(void)
{
if (mkdir(options.dir_savegame, 0777) < 0 && errno != EEXIST)
if (mkdir(options.dir_savegame, 0777) < 0 && errno != EEXIST) {
WARNING3("can't create savegame directory `%s': %s",
options.dir_savegame, strerror(errno));
return -1;
}
return 0;
}

Expand Down Expand Up @@ -323,4 +338,3 @@ next_saved_game(struct ffblk *ffblk)
}

/* vim: set noet ts=4 sw=4 tw=77: */

15 changes: 10 additions & 5 deletions intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
#include "Buzz_inc.h"
#include "externs.h"
#include "utils.h"
#include "logging.h"
GXHEADER local2;

LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT);

struct CREDIT {
char page;
int col;
Expand Down Expand Up @@ -193,7 +196,7 @@ read_img_frame (FILE *inf, struct intro_image *ip)
Swap32bit(len);

if (len > sizeof compressed) {
fprintf (stderr, "frame too big\n");
WARNING1("frame too big");
goto bad;
}

Expand All @@ -205,8 +208,9 @@ read_img_frame (FILE *inf, struct intro_image *ip)
return (0);

bad:
fprintf (stderr, "bad img file\n");
exit (1);
CRITICAL1("corrupted image file");
/* XXX: quite drastic */
exit(EXIT_FAILURE);
}

void
Expand All @@ -221,8 +225,9 @@ read_intro_images (void)

for (i = 0; i < 15; i++) {
if (read_img_frame (fin, &intro_images[i]) < 0) {
fprintf (stderr, "error reading first.img\n");
exit (1);
CRITICAL1("error reading first.img");
/* XXX: quite drastic */
exit(EXIT_FAILURE);
}
}

Expand Down
Loading

0 comments on commit fe99788

Please sign in to comment.