diff --git a/cs-code/Makefile.am b/cs-code/Makefile.am index c3bfc0f11..0413d522e 100644 --- a/cs-code/Makefile.am +++ b/cs-code/Makefile.am @@ -14,6 +14,7 @@ GZ=.gz else GZ= endif +STRIP=$(shell echo -n $(srcdir)/ | sed -e 's/[^/]//g' | wc -c) pkgdata_DATA= menu.dat$(GZ) @@ -24,7 +25,7 @@ menu_src= \ servlist.qc string_def.qc stringh_def.qc menu.dat$(GZ): menu.src $(menu_src) - $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -P $< + $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -p $(STRIP) -P $< $(GZIP) EXTRA_DIST= $(menu_src) diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 2286f8bb0..f79fddaa2 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -571,6 +571,7 @@ ddef_t *new_local (void); int CopyString (const char *str); int ReuseString (const char *str); +const char *strip_path (const char *filename); typedef struct { qboolean cow; // Turn constants into variables if written to @@ -595,6 +596,8 @@ typedef struct { qboolean save_temps; // save temporary files qboolean files_dat; // generate files.dat qboolean traditional; // behave more like qcc + int strip_path; // number of leading path elements to strip + // from source file names } options_t; extern options_t options; diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index c5e72ee79..6c5b737f8 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -138,7 +138,7 @@ m ([\-+]?) while (*p && *p != '\n') // ignore flags p++; pr_source_line = line - 1; - s_file = ReuseString (s); + s_file = ReuseString (strip_path (s)); free (s); } diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 6c1ff13f1..06365aaa5 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -82,6 +82,7 @@ static struct option const long_options[] = { {"version", no_argument, 0, 'V'}, {"files", no_argument, 0, 'F'}, {"traditional", no_argument, 0, 't'}, + {"strip-path", required_argument, 0, 'p'}, #ifdef USE_CPP {"define", required_argument, 0, 'D'}, {"include", required_argument, 0, 'I'}, @@ -813,6 +814,7 @@ DecodeArgs (int argc, char **argv) options.save_temps = false; options.verbosity = 0; + options.strip_path = 0; sourcedir = ""; progs_src = "progs.src"; @@ -827,6 +829,7 @@ DecodeArgs (int argc, char **argv) "W:" // warning options "h" // help "V" // version + "p:" // strip path #ifdef USE_CPP "S" // save temps "D:" // define @@ -848,6 +851,9 @@ DecodeArgs (int argc, char **argv) case 'P': // progs-src progs_src = strdup (optarg); break; + case 'p': + options.strip_path = atoi (optarg); + break; case 'F': options.files_dat = true; break; @@ -1122,6 +1128,22 @@ preprocess_file (const char *filename) return fopen (filename, "rt"); } +const char * +strip_path (const char *filename) +{ + const char *p = filename; + int i = options.strip_path; + + while (i-- > 0) { + while (*p && *p != '/') + p++; + if (!*p) + break; + filename = ++p; + } + return filename; +} + /* main @@ -1212,7 +1234,7 @@ main (int argc, char **argv) yyin = preprocess_file (filename); - s_file = ReuseString (filename); + s_file = ReuseString (strip_path (filename)); pr_source_line = 1; clear_frame_macros (); error = yyparse () || pr_error_count;