diff -u -r --exclude-from=.diffignore freeciv-old/acconfig.h freeciv/acconfig.h --- freeciv-old/acconfig.h Sat Mar 6 14:54:17 1999 +++ freeciv/acconfig.h Mon Mar 8 10:59:41 1999 @@ -29,6 +29,8 @@ #undef HAVE_LIBXMU #undef HAVE_LIBXPM #undef HAVE_LIBXT +#undef HAVE_LIBIMLIB +#undef HAVE_LIBZ @BOTTOM@ diff -u -r --exclude-from=.diffignore freeciv-old/client/Makefile.am freeciv/client/Makefile.am --- freeciv-old/client/Makefile.am Thu Feb 18 15:17:42 1999 +++ freeciv/client/Makefile.am Thu Mar 4 14:34:12 1999 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in bin_PROGRAMS = civclient -INCLUDES = -I$(srcdir)/../common -I. $(X_CFLAGS) +INCLUDES = -I$(srcdir)/../common -I. $(X_CFLAGS) $(IMLIB_CFLAGS) BUILT_SOURCES = Freeciv.h @@ -12,7 +12,7 @@ $(srcdir)/ad2c $(srcdir)/../data/Freeciv >> Freeciv.h civclient_DEPENDENCIES = ad2c cityicon.ico freeciv.ico ../common/libcivcommon.a -civclient_LDADD = ../common/libcivcommon.a $(X_LIBS) $(X_EXTRA_LIBS) +civclient_LDADD = ../common/libcivcommon.a $(X_LIBS) $(X_EXTRA_LIBS) $(IMLIB_LIBS) civclient_SOURCES = \ cityicon.ico freeciv.ico ad2c \ diff -u -r --exclude-from=.diffignore freeciv-old/client/cityrep.c freeciv/client/cityrep.c --- freeciv-old/client/cityrep.c Sat Mar 6 14:56:07 1999 +++ freeciv/client/cityrep.c Sun Mar 7 16:24:18 1999 @@ -318,7 +318,7 @@ { struct city_report_spec *spec; int i; - + assert(text); text[0] = '\0'; /* init for strlen */ for(i=0, spec=city_report_specs; ishow) continue; diff -u -r --exclude-from=.diffignore freeciv-old/client/graphics.c freeciv/client/graphics.c --- freeciv-old/client/graphics.c Sun Feb 21 12:54:39 1999 +++ freeciv/client/graphics.c Mon Mar 8 22:18:51 1999 @@ -22,6 +22,17 @@ #include #include +#if defined(HAVE_LIBZ) +#include +#include +#endif + +#ifdef HAVE_LIBIMLIB +#include +#include +#include +#endif + #include #include #include @@ -33,6 +44,10 @@ extern int display_depth; extern Widget map_canvas; extern Display *display; +#ifdef HAVE_LIBIMLIB +ImlibData *id; +ImlibImage *im; +#endif extern XColor colors[MAX_COLORS]; extern GC fill_bg_gc; extern GC civ_gc, font_gc; @@ -99,6 +114,15 @@ struct Sprite *roads_sprite, *space_sprite, *flags_sprite; int row; +#ifdef HAVE_LIBIMLIB + big_sprite = load_xpmfile(tilefilename("tiles.png")); + unit_sprite = load_xpmfile(tilefilename("units.png")); + small_sprite = load_xpmfile(tilefilename("small.png")); + treaty_sprite= load_xpmfile(tilefilename("treaty.png")); + roads_sprite = load_xpmfile(tilefilename("roads.png")); + space_sprite = load_xpmfile(tilefilename("space.png")); + flags_sprite = load_xpmfile(tilefilename("flags.png")); +#else big_sprite = load_xpmfile(tilefilename("tiles.xpm")); unit_sprite = load_xpmfile(tilefilename("units.xpm")); small_sprite = load_xpmfile(tilefilename("small.xpm")); @@ -106,6 +130,7 @@ roads_sprite = load_xpmfile(tilefilename("roads.xpm")); space_sprite = load_xpmfile(tilefilename("space.xpm")); flags_sprite = load_xpmfile(tilefilename("flags.xpm")); +#endif ntiles= (20*19) + (20*3) + (31*1) + 3 + (16*4) + 6 + (14*2); @@ -377,6 +402,39 @@ { struct Sprite *mysprite; Pixmap mypixmap, mask_bitmap; + char *fn = filename; + int w,h; +#ifdef HAVE_LIBIMLIB + ImlibImage *im; + +#ifdef HAVE_LIBZ + if (access(fn, R_OK) == -1) + { + sz = strlen(filename)+3; + fn = malloc(sz+1); + sprintf(fn,"%s.gz",filename); + fn[sz] = '\0'; + } +#endif /* HAVE_LIBZ */ + + im = Imlib_load_image(id,fn); + if (fn != filename) free(fn); + + if (!im) + { + freelog(LOG_FATAL, "Failed reading image file: %s", filename); + freelog(LOG_FATAL, "The environment variable FREECIV_DATADIR is '%s'", + getenv("FREECIV_DATADIR") ? getenv("FREECIV_DATADIR") : ""); + freelog(LOG_FATAL, "Check if you got read permissions to the file"); + exit(1); + } + w=im->rgb_width; + h=im->rgb_height; + + Imlib_render(id,im,w,h); + mypixmap=Imlib_move_image(id,im); + mask_bitmap=Imlib_move_mask(id,im); +#else int err; XpmAttributes attributes; @@ -385,14 +443,60 @@ attributes.colormap = cmap; attributes.closeness = 40000; -again: - - if((err=XpmReadFileToPixmap(display, root_window, filename, &mypixmap, - &mask_bitmap, &attributes))!=XpmSuccess) { +#ifdef HAVE_LIBZ + { + void *mm, *mmp, *mmf; + size_t sz, tsz, chunk; + int ok; + gzFile *file; + + chunk = 4096; + mm = malloc(chunk); + if (mm == NULL) { perror("malloc"); exit(EXIT_FAILURE); } + mmp = mmf = NULL; + tsz = 0; + + if (access(fn, R_OK) == -1) + { + sz = strlen(filename)+3; + fn = malloc(sz+1); + sprintf(fn,"%s.gz",filename); + fn[sz] = '\0'; + } + + file = gzopen(fn,"r"); + if (file == NULL) { perror("gzopen"); exit(EXIT_FAILURE); } + if (fn != filename) free(fn); + ok = 1; + while(ok) + { + sz = gzread(file, mm, chunk); + if (sz < 0) { perror("gzread"); exit(EXIT_FAILURE); } + printf("read %d bytes, %d total\n",sz, tsz + sz); + if (sz > 0) + { + mmf = realloc(mmf, tsz + sz); + if (mmf == NULL) { perror("realloc"); exit(EXIT_FAILURE); } + mmp = mmf + tsz; + memcpy(mmp, mm, sz); + tsz += sz; + } + if (sz < chunk) ok = 0; + } + err=XpmCreatePixmapFromBuffer(display, root_window, mmf, + &mypixmap, &mask_bitmap, &attributes); + free(mmf); + } +#else + err=XpmReadFileToPixmap(display, root_window, filename, &mypixmap, + &mask_bitmap, &attributes); +#endif /* HAVE_LIBZ */ + if(err!=XpmSuccess) { if(err==XpmColorError || err==XpmColorFailed) { color_error(); goto again; } +again: freelog(LOG_FATAL, "Failed reading XPM file: %s", filename); freelog(LOG_FATAL, "The environment variable FREECIV_DATADIR is '%s'", @@ -401,16 +505,20 @@ exit(1); } + w = attributes.width; + h = attributes.height; +#endif /* HAVE_LIBIMLIB */ + if(!(mysprite=(struct Sprite *)malloc(sizeof(struct Sprite)))) { freelog(LOG_FATAL, "failed mallocing sprite struct for %s", filename); exit(1); } - + mysprite->pixmap=mypixmap; mysprite->mask=mask_bitmap; mysprite->has_mask=(mask_bitmap!=0); - mysprite->width=attributes.width; - mysprite->height=attributes.height; + mysprite->width=w; + mysprite->height=h; return mysprite; } diff -u -r --exclude-from=.diffignore freeciv-old/client/xmain.c freeciv/client/xmain.c --- freeciv-old/client/xmain.c Mon Feb 22 15:15:19 1999 +++ freeciv/client/xmain.c Thu Mar 4 14:20:34 1999 @@ -33,6 +33,13 @@ #include #include +#ifdef HAVE_LIBIMLIB +#include +#include +#include +#include +#endif + #include #include #include @@ -138,6 +145,10 @@ /**************************************************************************/ Display *display; +#ifdef HAVE_LIBIMLIB +ImlibData *id; +ImlibImage *im; +#endif int display_depth; int screen_number; enum Display_color_type display_color_type; @@ -273,10 +284,13 @@ &fallback_resources[1], /* for missing app-defaults file */ XtNallowShellResize, True, NULL); - + display = XtDisplay(toplevel); +#ifdef HAVE_LIBIMLIB + id=Imlib_init(display); +#endif XtGetApplicationResources(toplevel, &appResources, resources, XtNumber(resources), NULL, 0); - + log_init(appResources.logfile); log_set_level(appResources.loglevel); @@ -333,7 +347,6 @@ boot_help_texts(); /* after log_init */ - display = XtDisplay(toplevel); screen_number=XScreenNumberOfScreen(XtScreen(toplevel)); display_depth=DefaultDepth(display, screen_number); root_window=DefaultRootWindow(display); diff -u -r --exclude-from=.diffignore freeciv-old/config.h.in freeciv/config.h.in --- freeciv-old/config.h.in Sat Mar 6 14:54:17 1999 +++ freeciv/config.h.in Mon Mar 8 11:01:04 1999 @@ -44,6 +44,8 @@ #undef HAVE_LIBXMU #undef HAVE_LIBXPM #undef HAVE_LIBXT +#undef HAVE_LIBIMLIB +#undef HAVE_LIBZ /* Define if you have the gethostname function. */ #undef HAVE_GETHOSTNAME @@ -68,6 +70,9 @@ /* Define if you have the nls library (-lnls). */ #undef HAVE_LIBNLS + +/* Define if you have the z library (-lz). */ +#undef HAVE_LIBZ /* Name of package */ #undef PACKAGE diff -u -r --exclude-from=.diffignore freeciv-old/configure.in freeciv/configure.in --- freeciv-old/configure.in Sat Mar 6 14:54:48 1999 +++ freeciv/configure.in Mon Mar 8 10:26:53 1999 @@ -60,6 +60,17 @@ WITH_XAW3D=1 ) +AC_ARG_WITH(imlib, + [ --with-imlib compile with imlib ], + [WITH_IMLIB=1 + echo "We try to use imlib"] +) + +AC_ARG_WITH(zlib, + [ --with-zlib use zlib (allows compressed savegames) ], + WITH_ZLIB=1 +) + AC_ARG_ENABLE(client, [ --disable-client do not compile the client], [case "${enableval}" in @@ -160,6 +171,9 @@ else FC_CHECK_X_LIB(Xaw3d, main) fi + if test x$WITH_IMLIB != x; then + AM_PATH_IMLIB(1.9.4,AC_DEFINE(HAVE_LIBIMLIB)) + fi dnl Don't do following because don't want server to link with X: dnl LIBS="$LIBS $X_LIBS $X_EXTRA_LIBS" fi @@ -182,6 +196,10 @@ AC_SUBST(SERVER_LIBS) AC_CHECK_LIB(nls,main) +if test ! -z $WITH_ZLIB; then + AC_CHECK_LIB(z, inflate, , AC_MSG_WARN(Defined --with-zlib, but no zlib available. Can't enable compressed savegames.), $LIBS) + AC_CHECK_HEADER(zlib.h, , AC_MSG_ERROR(zlib found, but no zlib.h.)) +fi dnl Checks for header files. AC_HEADER_STDC diff -u -r --exclude-from=.diffignore freeciv-old/data/default/Makefile.am freeciv/data/default/Makefile.am --- freeciv-old/data/default/Makefile.am Sun Feb 21 12:54:47 1999 +++ freeciv/data/default/Makefile.am Sun Mar 7 16:00:36 1999 @@ -13,6 +13,13 @@ space.xpm \ tiles.xpm \ treaty.xpm \ - units.xpm + units.xpm \ + flags.png \ + roads.png \ + small.png \ + space.png \ + tiles.png \ + treaty.png \ + units.png EXTRA_DIST = $(pkgdata_DATA) diff -u -r --exclude-from=.diffignore freeciv-old/server/civserver.c freeciv/server/civserver.c --- freeciv-old/server/civserver.c Sat Mar 6 14:56:54 1999 +++ freeciv/server/civserver.c Mon Mar 8 10:26:51 1999 @@ -743,10 +743,16 @@ void save_game(void) { - char filename[512]; + char filename[1037]; struct section_file file; - sprintf(filename, "%s%d.sav", game.save_name, game.year); + sprintf(filename, +#if defined(HAVE_LIBZ) + "%s%d.sav.gz" +#else + "%s%d.sav" +#endif + , game.save_name, game.year); section_file_init(&file); diff -u -r --exclude-from=.diffignore freeciv-old/server/registry.c freeciv/server/registry.c --- freeciv-old/server/registry.c Fri Feb 12 15:31:04 1999 +++ freeciv/server/registry.c Mon Mar 8 10:55:57 1999 @@ -120,6 +120,22 @@ #include #include +#if defined(HAVE_LIBZ) +#include +#include +#define fc_FILE gzFile +#define fc_fopen gzopen +#define fc_fprintf gzprintf +#define fc_fclose gzclose +#define fc_fgets(s, size, stream) gzgets((stream), (s), (size)) +#else +#define fc_FILE FILE +#define fc_fopen fopen +#define fc_fprintf fprintf +#define fc_fclose fclose +#define fc_fgets fgets +#endif + /************************************************************************** Hashing registry lookups: (by dwp) - Have a hash table direct to entries, bypassing sections division. @@ -365,7 +381,7 @@ **************************************************************************/ int section_file_load(struct section_file *my_section_file, char *filename) { - FILE *fs; + fc_FILE *fs; char buffer[512], temp_name[512]; int lineno; struct section *current_section=NULL; @@ -376,7 +392,7 @@ struct flat_entry_list entries = {NULL, 0, 0}; int i; - if(!(fs=fopen(filename, "r"))) { + if(!(fs=fc_fopen(filename, "r"))) { freelog(LOG_NORMAL, "Could not open file \"%s\"", filename); return 0; } @@ -384,7 +400,7 @@ section_file_init(my_section_file); lineno=0; - while(fgets(buffer, sizeof(buffer), fs)) { + while(fc_fgets(buffer, sizeof(buffer), fs)) { char *cptr; if (strlen(buffer)==sizeof(buffer)-1) { @@ -514,7 +530,7 @@ exit(1); } - fclose(fs); + fc_fclose(fs); free(columns.plist); free(entries.plist); @@ -541,19 +557,27 @@ **************************************************************************/ int section_file_save(struct section_file *my_section_file, char *filename) { - FILE *fs; + fc_FILE *fs; struct genlist_iterator sec_iter, ent_iter, save_iter, col_iter; struct section *psection; struct section_entry *pentry, *col_pentry; - if(!(fs=fopen(filename, "w"))) - return 0; + if(!(fs=fc_fopen(filename, "w"))) + if(!(fs=fc_fopen(filename, +#if defined(HAVE_LIBZ) + "w9" +#else + "w" +#endif + ))) + return 0; + for(genlist_iterator_init(&sec_iter, &my_section_file->section_list, 0); (psection = ITERATOR_PTR(sec_iter)); ITERATOR_NEXT(sec_iter)) { - fprintf(fs, "\n[%s]\n", psection->name); + fc_fprintf(fs, "\n[%s]\n", psection->name); for(genlist_iterator_init(&ent_iter, &psection->entry_list, 0); (pentry = ITERATOR_PTR(ent_iter)); @@ -589,7 +613,7 @@ first[offset-2] = '\0'; strcpy(base, first); first[offset-2] = '0'; - fprintf(fs, "%s={", base); + fc_fprintf(fs, "%s={", base); /* Save an iterator at this first entry, which we can later use * to repeatedly iterate over column names: @@ -602,10 +626,10 @@ for( ; (col_pentry = ITERATOR_PTR(col_iter)); ITERATOR_NEXT(col_iter)) { if(strncmp(col_pentry->name, first, offset) != 0) break; - fprintf(fs, "%c\"%s\"", (ncol==0?' ':','), col_pentry->name+offset); + fc_fprintf(fs, "%c\"%s\"", (ncol==0?' ':','), col_pentry->name+offset); ncol++; } - fprintf(fs, "\n"); + fc_fprintf(fs, "\n"); /* Iterate over rows and columns, incrementing ent_iter as we go, * and writing values to the table. Have a separate iterator @@ -626,25 +650,25 @@ if(icol != 0) { freelog(LOG_NORMAL, "unexpected exit from tabular at %s", pentry->name); - fprintf(fs, "\n"); + fc_fprintf(fs, "\n"); } - fprintf(fs, "}\n"); + fc_fprintf(fs, "}\n"); break; } if(icol>0) - fprintf(fs, ","); + fc_fprintf(fs, ","); if(pentry->svalue) - fprintf(fs, "\"%s\"", pentry->svalue); + fc_fprintf(fs, "\"%s\"", pentry->svalue); else - fprintf(fs, "%d", pentry->ivalue); + fc_fprintf(fs, "%d", pentry->ivalue); ITERATOR_NEXT(ent_iter); ITERATOR_NEXT(col_iter); icol++; if(icol==ncol) { - fprintf(fs, "\n"); + fc_fprintf(fs, "\n"); irow++; icol = 0; col_iter = save_iter; @@ -655,14 +679,31 @@ if(!pentry) break; if(pentry->svalue) - fprintf(fs, "%s=\"%s\"\n", pentry->name, pentry->svalue); + fc_fprintf(fs, "%s=\"%s\"\n", pentry->name, pentry->svalue); else - fprintf(fs, "%s=%d\n", pentry->name, pentry->ivalue); + fc_fprintf(fs, "%s=%d\n", pentry->name, pentry->ivalue); } } - if(ferror(fs) || fclose(fs) == EOF) - return 0; +#if defined(HAVE_LIBZ) + { + int errnum; + const char *err = gzerror(fs, &errnum); + if (errnum) { + freelog(LOG_NORMAL, "gzerror set: %s %s", + err, strerror(errno)); + return 0; + } + } + if (fc_fclose(fs)) { + freelog(LOG_NORMAL, "error closing gzfile: %s", + strerror(errno)); + return 0; + } +#else + if(ferror(fs) || fc_fclose(fs) == EOF) + return 0; +#endif return 1; }