From 130e6c1a3f0636f703120781c6b7aebbbbebe3b2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 24 May 2006 14:50:24 +0000 Subject: [PATCH] fix some intermediate file issues --- tools/qfcc/include/cpp.h | 2 +- tools/qfcc/source/cpp.c | 16 +++++++++------- tools/qfcc/source/qfcc.c | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/qfcc/include/cpp.h b/tools/qfcc/include/cpp.h index 9ac5ccb63..6756150b2 100644 --- a/tools/qfcc/include/cpp.h +++ b/tools/qfcc/include/cpp.h @@ -38,7 +38,7 @@ void parse_cpp_name (void); void add_cpp_def (const char *arg); void intermediate_file (struct dstring_s *ifile, const char *filename, const char *ext); -FILE * preprocess_file (const char *filename); +FILE * preprocess_file (const char *filename, const char *ext); extern const char *cpp_name; extern struct dstring_s *tempname; diff --git a/tools/qfcc/source/cpp.c b/tools/qfcc/source/cpp.c index 537995615..7b868d189 100644 --- a/tools/qfcc/source/cpp.c +++ b/tools/qfcc/source/cpp.c @@ -150,14 +150,14 @@ build_cpp_args (const char *in_name, const char *out_name) void intermediate_file (dstring_t *ifile, const char *filename, const char *ext) { - const char *temp1; - char *temp2 = strrchr (this_program, PATH_SEPARATOR); - if (options.save_temps) { char *basename = strdup (filename); char *temp; - temp = strrchr (basename, '.'); + temp = strrchr (basename, '/'); + if (!temp) + temp = basename; + temp = strrchr (temp, '.'); if (temp) *temp = '\0'; // ignore the rest of the string @@ -175,7 +175,9 @@ intermediate_file (dstring_t *ifile, const char *filename, const char *ext) } free (basename); } else { - temp1 = getenv ("TMPDIR"); + const char *temp1 = getenv ("TMPDIR"); + char *temp2 = strrchr (this_program, PATH_SEPARATOR); + if ((!temp1) || (!temp1[0])) { temp1 = getenv ("TEMP"); if ((!temp1) || (!temp1[0])) { @@ -189,7 +191,7 @@ intermediate_file (dstring_t *ifile, const char *filename, const char *ext) } FILE * -preprocess_file (const char *filename) +preprocess_file (const char *filename, const char *ext) { #ifndef _WIN32 pid_t pid; @@ -197,7 +199,7 @@ preprocess_file (const char *filename) #endif if (cpp_name) { - intermediate_file (tempname, filename, "p"); + intermediate_file (tempname, filename, ext ? ext : "p"); build_cpp_args (filename, tempname->str); #ifdef _WIN32 diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 9df94535c..250bdb470 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -515,7 +515,7 @@ compile_to_obj (const char *file, const char *obj) { int err; - yyin = preprocess_file (file); + yyin = preprocess_file (file, 0); if (!yyin) return !options.preprocess_only; @@ -660,7 +660,7 @@ load_file (const char *fname) QFile *file; char *src; - file = Qfopen (preprocess_file (fname), "rt"); + file = Qfopen (preprocess_file (fname, "i1"), "rt"); if (!file) return 0; src = malloc (Qfilesize (file) + 1); @@ -693,7 +693,7 @@ compile_file (const char *filename) { int err; - yyin = preprocess_file (filename); + yyin = preprocess_file (filename, 0); if (!yyin) return !options.preprocess_only; @@ -735,7 +735,7 @@ progs_src_compile (void) dsprintf (filename, "%s", progs_src); if (options.single_cpp) { - intermediate_file (single_name, filename->str, "i"); + intermediate_file (single_name, filename->str, "i2"); if (!options.save_temps) { #ifdef _WIN32 mktemp (single_name->str);