From 3f6b2fd87b4e4f2d5985970af1df0961d956fb82 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 1 May 2004 03:39:33 +0000 Subject: [PATCH] has some issues, but support writting to stdout --- tools/qfbsp/include/options.h | 1 + tools/qfbsp/source/options.c | 4 ++++ tools/qfbsp/source/readbsp.c | 27 +++++++++++++++++++-------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tools/qfbsp/include/options.h b/tools/qfbsp/include/options.h index 0afefc2c0..a3318804b 100644 --- a/tools/qfbsp/include/options.h +++ b/tools/qfbsp/include/options.h @@ -51,6 +51,7 @@ typedef struct { char *portfile; char *pointfile; char *hullfile; + char *output_file; const char *wadpath; } options_t; diff --git a/tools/qfbsp/source/options.c b/tools/qfbsp/source/options.c index f1323e800..946f6b2ab 100644 --- a/tools/qfbsp/source/options.c +++ b/tools/qfbsp/source/options.c @@ -78,6 +78,7 @@ static const char *short_options = "f" // nofill "c" // noclip "e" // onlyents + "o:" // outputfile "p" // portal "u" // usehulls "H:" // hullnum @@ -155,6 +156,9 @@ DecodeArgs (int argc, char **argv) case 'e': // onlyents options.onlyents = true; break; + case 'o': + options.output_file = strdup (optarg); + break; case 'p': // portal options.extract = true; options.portal = true; diff --git a/tools/qfbsp/source/readbsp.c b/tools/qfbsp/source/readbsp.c index a3bdbc22a..a09301b88 100644 --- a/tools/qfbsp/source/readbsp.c +++ b/tools/qfbsp/source/readbsp.c @@ -246,12 +246,20 @@ output_file (const char *ext) { char *name; - name = malloc (strlen (options.bspfile) + strlen (ext) + 1); - QFS_StripExtension (options.bspfile, name); - if (strcmp (QFS_FileExtension (options.bspfile), ".gz") == 0) { - QFS_StripExtension (name, name); + if (options.output_file) { + if (strcmp (options.output_file, "-") == 0) + return options.output_file; + name = malloc (strlen (options.output_file) + strlen (ext) + 1); + strcpy (name, options.output_file); + QFS_DefaultExtension (name, ext); + } else { + name = malloc (strlen (options.bspfile) + strlen (ext) + 1); + QFS_StripExtension (options.bspfile, name); + if (strcmp (QFS_FileExtension (options.bspfile), ".gz") == 0) { + QFS_StripExtension (name, name); + } + strcat (name, ext); } - strcat (name, ext); return name; } @@ -342,7 +350,7 @@ extract_textures (void) dmiptexlump_t *miptexlump = (dmiptexlump_t *) bsp->texdata; miptex_t *miptex; int i, mtsize, pixels; - char *wadfile = malloc (strlen (options.bspfile) + 5); + char *wadfile; wad_t *wad; wadfile = output_file (".wad"); @@ -371,7 +379,7 @@ extract_textures (void) void extract_entities (void) { - char *entfile = malloc (strlen (options.bspfile) + 5); + char *entfile; int i; QFile *ef; @@ -381,7 +389,10 @@ extract_entities (void) if (bsp->entdata[i - 1]) break; - ef = Qopen (entfile, "wt"); + if (strcmp (entfile, "-") == 0) + ef = Qdopen (1, "wt"); + else + ef = Qopen (entfile, "wt"); Qwrite (ef, bsp->entdata, i); Qclose (ef); }