From ecdb5a5cb410601ccbdcc6350992033fa685c60e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 24 Jun 2002 22:53:21 +0000 Subject: [PATCH] allow the output file to be specified on the command line --- tools/qfcc/include/cmdlib.h | 6 +++--- tools/qfcc/include/options.h | 1 + tools/qfcc/source/class.c | 3 ++- tools/qfcc/source/cmdlib.c | 6 +++--- tools/qfcc/source/options.c | 2 ++ tools/qfcc/source/qfcc.c | 12 ++++++------ 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tools/qfcc/include/cmdlib.h b/tools/qfcc/include/cmdlib.h index 434faeaa4..077002851 100644 --- a/tools/qfcc/include/cmdlib.h +++ b/tools/qfcc/include/cmdlib.h @@ -30,12 +30,12 @@ int FileLength (FILE *f); void Error (char *error, ...)__attribute__((format(printf, 1,2))); -FILE *SafeOpenWrite (char *filename); -FILE *SafeOpenRead (char *filename); +FILE *SafeOpenWrite (const char *filename); +FILE *SafeOpenRead (const char *filename); void SafeRead (FILE *f, void *buffer, int count); void SafeWrite (FILE *f, void *buffer, int count); -int LoadFile (char *filename, void **bufferptr); +int LoadFile (const char *filename, void **bufferptr); char *Parse (char *data); diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index b6c6a4532..eb45a48a8 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -66,6 +66,7 @@ typedef struct { qboolean compile; // serparate compilation mode int strip_path; // number of leading path elements to strip // from source file names + const char *output_file; } options_t; extern options_t options; diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index ffc80af22..76efd753c 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -53,6 +53,7 @@ static const char rcsid[] = #include "expr.h" #include "immediate.h" #include "method.h" +#include "options.h" #include "reloc.h" #include "struct.h" #include "type.h" @@ -469,7 +470,7 @@ class_finish_module (void) module_def->initialized = module_def->constant = 1; module = &G_STRUCT (pr_module_t, module_def->ofs); module->size = type_size (type_module); - module->name = ReuseString (destfile); + module->name = ReuseString (options.output_file); module->symtab = symtab_def->ofs; exec_class_def = get_def (&type_obj_exec_class, "__obj_exec_class", diff --git a/tools/qfcc/source/cmdlib.c b/tools/qfcc/source/cmdlib.c index 1cbe9734a..905077a46 100644 --- a/tools/qfcc/source/cmdlib.c +++ b/tools/qfcc/source/cmdlib.c @@ -167,7 +167,7 @@ FileLength (FILE *f) FILE * -SafeOpenWrite (char *filename) +SafeOpenWrite (const char *filename) { FILE *f; @@ -180,7 +180,7 @@ SafeOpenWrite (char *filename) } FILE * -SafeOpenRead (char *filename) +SafeOpenRead (const char *filename) { FILE *f; @@ -213,7 +213,7 @@ SafeWrite (FILE *f, void *buffer, int count) LoadFile */ int -LoadFile (char *filename, void **bufferptr) +LoadFile (const char *filename, void **bufferptr) { FILE *f; int length; diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index 498e950ea..281590b56 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -54,6 +54,7 @@ static const char rcsid[] = const char *this_program; static struct option const long_options[] = { + {"output-file", required_argument, 0, 'o'}, {"source", required_argument, 0, 's'}, {"progs-src", required_argument, 0, 'P'}, {"save-temps", no_argument, 0, 'S'}, @@ -75,6 +76,7 @@ static struct option const long_options[] = { }; static const char *short_options = + "o:" // output file "c" // separate compilation "s:" // source dir "P:" // progs.src name diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index c4c3ef1a1..6c1490e41 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -82,7 +82,6 @@ options_t options; const char *sourcedir; const char *progs_src; -char destfile[1024]; char debugfile[1024]; pr_info_t pr; @@ -175,7 +174,7 @@ WriteData (int crc) printf ("%6i entity fields\n", pr.entity_data->size); } - h = SafeOpenWrite (destfile); + h = SafeOpenWrite (options.output_file); SafeWrite (h, &progs, sizeof (progs)); progs.ofs_strings = ftell (h); @@ -255,7 +254,7 @@ WriteData (int crc) return; } - h = SafeOpenRead (destfile); + h = SafeOpenRead (options.output_file); debug.version = LittleLong (PROG_DEBUG_VERSION); CRC_Init (&debug.crc); @@ -434,9 +433,10 @@ main (int argc, char **argv) if (!(src = Parse (src))) Error ("No destination filename. qfcc --help for info.\n"); - strcpy (destfile, qfcc_com_token); + if (!options.output_file) + options.output_file = strdup (qfcc_com_token); if (options.verbosity >= 1) { - printf ("outputfile: %s\n", destfile); + printf ("output file: %s\n", options.output_file); } if (options.code.debug) { char *s; @@ -496,7 +496,7 @@ main (int argc, char **argv) } if (options.compile) { - write_obj_file ("test.qfo"); + write_obj_file (options.output_file); } else { if (!finish_compilation ()) Error ("compilation errors");