diff -ur xwadtools-20010615/include/wadfile.h xwadtools-20010615_aym/include/wadfile.h --- xwadtools-20010615/include/wadfile.h Fri Jun 15 11:44:12 2001 +++ xwadtools-20010615_aym/include/wadfile.h Thu Aug 30 14:04:28 2001 @@ -18,6 +18,8 @@ #ifndef __WADFILE_H__ #define __WADFILE_H__ +#include /* size_t */ + /* magic number for WAD file structure */ #define WFILE_MAGIC (('W'<<24)+('F'<<16)+('I'<<8)+'L') @@ -33,6 +35,7 @@ void close_wad(wadfile_t *); int check_lump_name(wadfile_t *, char *); void *get_lump_by_name(wadfile_t *, char *); +void *get_lump_by_num(wadfile_t *wf, size_t lnum); void *get_map_lump(wadfile_t *, char *, char *, int *); int lump_name_cmp(const char *, const char *); diff -ur xwadtools-20010615/lib/wadfile.c xwadtools-20010615_aym/lib/wadfile.c --- xwadtools-20010615/lib/wadfile.c Fri Jun 15 11:48:08 2001 +++ xwadtools-20010615_aym/lib/wadfile.c Thu Aug 30 13:29:46 2001 @@ -30,6 +30,10 @@ * * UM 1999-08-23 * Print file name which can't be opened by open_wad(). + * + * AYM 2001-08-30 + * Fixed typos. + * Added get_lump_by_num() so that wadflat works. */ #include @@ -151,7 +155,7 @@ /* * Find a lump by name in the WAD file directory. If found allocate - * memory and read it's data. + * memory and read its data. */ void *get_lump_by_name(wadfile_t *wf, char *lname) { @@ -212,8 +216,50 @@ } /* + * Find a lump by name in the WAD file directory. If found allocate + * memory and read its data. + */ +void *get_lump_by_num(wadfile_t *wf, size_t lnum) +{ + void *lump = (void *)0; + + /* is this a wadfile_t structure? */ + if (wf->magic != WFILE_MAGIC) { + fprintf(stderr, "get_lump_by_num(): not a wadfile_t structure\n"); + exit(1); + } + + /* check lump number */ + if (lnum >= wf->wh.numlumps) { + fprintf(stderr, "get_lump_by_num(): lump num out of range\n"); + exit(1); + } + + /* allocate memory for the lump data */ + if ((lump = malloc(wf->lp->lumps[lnum]->size)) == NULL) { + fprintf(stderr, + "get_lump_by_num(): can't allocate memory for lump data\n"); + exit(1); + } + + /* seek to the lump in WAD file */ + if (fseek(wf->fp, (long)wf->lp->lumps[lnum]->filepos, SEEK_SET) == -1) { + fprintf(stderr, "get_lump_by_num(): can't seek to lump data\n"); + exit(1); + } + + /* read the lump data */ + if (fread(lump, wf->lp->lumps[lnum]->size, 1, wf->fp) != 1) { + fprintf(stderr, "get_lump_by_num(): can't read lump data\n"); + exit(1); + } + + return lump; +} + +/* * Find a map lump by name in the WAD file directory. If found allocate - * memory and read it's data. + * memory and read its data. */ void *get_map_lump(wadfile_t *wf, char *map, char *lname, int *size) { diff -ur xwadtools-20010615/wadflat/wadflat.6 xwadtools-20010615_aym/wadflat/wadflat.6 --- xwadtools-20010615/wadflat/wadflat.6 Fri Jun 15 12:08:30 2001 +++ xwadtools-20010615_aym/wadflat/wadflat.6 Thu Aug 30 14:09:09 2001 @@ -1,4 +1,4 @@ -.TH wadflat 6 "15 June 2001" +.TH wadflat 6 2001-08-30 .SH NAME wadflat \- extract floor and ceiling flats from WAD files into ppm graphic files @@ -14,7 +14,7 @@ .SH DESCRIPTION The program takes a WAD file (either IWAD or PWAD) as input, and decompiles all flats used for floors and ceilings found between the F_START or FF_START -and F_END labels into raw ppm graphic files. +and F_END or FF_END labels into raw ppm graphic files. .P A flat named \fBFRED\fP would be saved as \fB./flats/fred.ppm\fP. If the \fB./flats\fP directory does not already exist, it is created. @@ -37,9 +37,10 @@ .SH SEE ALSO The Unofficial Doom Specs by Matthew S Fell. .br -.BR tkwadcad "(6), " -.BR wadgc "(6), " -.BR ppm "(5), " +.BR deutex (6), +.BR ppm (5), +.BR tkwadcad (6), +.BR wadgc (6), .BR xwadtools (6) .SH BUGS/ERRORS diff -ur xwadtools-20010615/wadflat/wadflat.c xwadtools-20010615_aym/wadflat/wadflat.c --- xwadtools-20010615/wadflat/wadflat.c Fri Jun 15 12:08:46 2001 +++ xwadtools-20010615_aym/wadflat/wadflat.c Thu Aug 30 14:12:40 2001 @@ -1,5 +1,6 @@ /************************************************************************/ /* Copyright (C) 1998, 1999 by Udo Munk (munkudo@aol.com) */ +/* Copyright (C) 1999, 2001 by André Majorel (amajorel@teaser.fr) */ /* */ /* Permission to use, copy, modify, and distribute this software */ /* and its documentation for any purpose and without fee is */ @@ -30,8 +31,20 @@ * - Added support for Strife. * - Accept FF_START as start label too, to be able to extract flats from * PWADS, where FF_START is used by convention. + * + * 1.4 (AYM 2001-08-30) + * - If there was another lump in the wad named like the flat, wadflat + * would extract the wrong lump. Fixed by using get_lump_by_num() + * instead of get_lump_by_name(). + * - Changed directory mode from 0755 to 0777 on the theory that we + * should not substitute for umask. + * - Accept FF_END as end label too, for compatibility with pwads made + * with DeuTex 3. + * - Accept flats with a size of 4160 (64x65) for compatibility with + * Heretic and 8192 (64x128) for compatibility with Hexen. */ +#include #include #include #include @@ -44,7 +57,7 @@ #include "lump_dir.h" #include "wadfile.h" -#define VERSION "1.3" +#define VERSION "1.4" extern unsigned char doom_rgb[]; extern unsigned char heretic_rgb[]; @@ -65,17 +78,24 @@ exit(1); } -void decompile(wadfile_t *wf, char *name) +void decompile(wadfile_t *wf, size_t num) { int i; FILE *fp; char fn[50]; unsigned char *flat; + char name[9]; + size_t size; + int width; + int height; + + name[0] = '\0'; + strncat(name, wf->lp->lumps[num]->name, 8); printf(" %s\n", name); /* get flat lump */ - if ((flat = (unsigned char *)get_lump_by_name(wf, name)) == NULL) { + if ((flat = (unsigned char *)get_lump_by_num(wf, num)) == NULL) { fprintf(stderr, "can't get lump %s??\n", name); exit(1); } @@ -91,12 +111,16 @@ exit(1); } + size = wf->lp->lumps[num]->size; + width = 64; + height = size / width; + fprintf(fp, "P6\n"); fprintf(fp, "# CREATOR: wadflat Release %s\n", VERSION); - fprintf(fp, "64 64\n"); + fprintf(fp, "%d %d\n", width, height); fprintf(fp, "255\n"); - for (i = 0; i < 4096; i++) { + for (i = 0; i < size; i++) { fputc((int) palette[*(flat+i) * 3], fp); fputc((int) palette[*(flat+i) * 3 + 1], fp); fputc((int) palette[*(flat+i) * 3 + 2], fp); @@ -113,10 +137,6 @@ wadfile_t *wf; char *s; char *program; - char name[9]; - - /* initialize */ - memset(&name[0], 0, 9); /* save program name for usage() */ program = *argv; @@ -158,32 +178,38 @@ wf = open_wad(*argv); /* just make flats directory, ignore errors, deal with it later */ - mkdir("flats", 0755); + mkdir("flats", 0777); /* loop over all lumps and look for the flats */ for (i = 0; i < wf->wh.numlumps; i++) { /* start processing after F_START */ - if (!strncmp(wf->lp->lumps[i]->name, "F_START", 7)) { + if (!lump_name_cmp(wf->lp->lumps[i]->name, "F_START")) { if (start_flag) continue; start_flag = 1; printf("found F_START, start decompiling flats\n"); continue; /* also accept FF_START */ - } else if (!strncmp(wf->lp->lumps[i]->name, "FF_START", 8)) { + } else if (!lump_name_cmp(wf->lp->lumps[i]->name, "FF_START")) { if (start_flag) continue; start_flag = 1; printf("found FF_START, start decompiling flats\n"); continue; - } else if (!strncmp(wf->lp->lumps[i]->name, "F_END", 5)) { + } else if (!lump_name_cmp(wf->lp->lumps[i]->name, "F_END")) { start_flag = 0; printf("found F_END, done\n"); break; + } else if (!lump_name_cmp(wf->lp->lumps[i]->name, "FF_END")) { + start_flag = 0; + printf("found FF_END, done\n"); + break; } else { - if (start_flag && (wf->lp->lumps[i]->size == 4096)) { - strncpy(&name[0], wf->lp->lumps[i]->name, 8); - decompile(wf, &name[0]); + if (start_flag + && (wf->lp->lumps[i]->size == 4096 + || wf->lp->lumps[i]->size == 4160 + || wf->lp->lumps[i]->size == 8192)) { + decompile(wf, i); } } }