From eacdd0d3dea8f5c682462a33ec2eff15244442e5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 28 Mar 2020 18:52:57 +0900 Subject: [PATCH] [qfcc] Make file_basename accessible and more usable --- tools/qfcc/include/qfcc.h | 1 + tools/qfcc/source/qfcc.c | 13 +++++++------ tools/qfcc/source/stub.c | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index e428831cb..dc8dddac2 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -109,6 +109,7 @@ extern pr_info_t pr; #define POINTER_OFS(s,p) ((pr_type_t *) (p) - (s)->data) const char *strip_path (const char *filename) __attribute__((pure)); +const char *file_basename (const char *filename, int keepdot) __attribute__((pure)); extern FILE *qc_yyin; extern FILE *qp_yyin; diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 7d0f8c800..15f3d31d7 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -313,8 +313,8 @@ strip_path (const char *filename) return filename; } -static const char * -file_basename (const char *filename) +const char * +file_basename (const char *filename, int keepdot) { const char *p; const char *dot; @@ -325,7 +325,7 @@ file_basename (const char *filename) for (dot = p = filename + strlen (filename); p > filename; p--) { if (p[-1] == '/' || p[-1] == '\\') break; - if (p[0] == '.') + if (!keepdot && p[0] == '.') dot = p; } dstring_copysubstr (base, p, dot - p); @@ -395,7 +395,7 @@ compile_to_obj (const char *file, const char *obj, lang_t lang) } } if (options.frames_files) { - write_frame_macros (va ("%s.frame", file_basename (file))); + write_frame_macros (va ("%s.frame", file_basename (file, 0))); } if (!err) { qfo_t *qfo; @@ -753,13 +753,14 @@ progs_src_compile (void) fprintf (single, "#include \"%s\"\n", qc_filename->str); if (options.frames_files) fprintf (single, "$frame_write \"%s.frame\"\n", - file_basename (qc_filename->str)); + file_basename (qc_filename->str, 0)); } else { if (compile_file (qc_filename->str)) return 1; if (options.frames_files) { write_frame_macros (va ("%s.frame", - file_basename (qc_filename->str))); + file_basename (qc_filename->str, + 0))); } } if (!Script_TokenAvailable (script, 0)) diff --git a/tools/qfcc/source/stub.c b/tools/qfcc/source/stub.c index f3601d04b..7180f9e88 100644 --- a/tools/qfcc/source/stub.c +++ b/tools/qfcc/source/stub.c @@ -53,3 +53,5 @@ int compare_protocols (protocollist_t *protos1, protocollist_t *protos2){return void dump_dot (const char *stage, void *data, void (*dump_func) (void *data, const char *fname)){} void dump_dot_type (void *_t, const char *filename){} +const char *strip_path(const char *p) { return p;} +const char *file_basename(const char *p, int keepdot) { return p;}