From b11bdcded0316eca2f8bef7cf228ca60fbb9cd80 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Tue, 30 Jul 2024 23:50:10 +0000 Subject: [PATCH] moved filename-used-for-resolving-relative-paths out of input struct git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@385 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/global.c | 11 ++++++++++- src/input.c | 10 +++++----- src/input.h | 8 ++++---- src/version.h | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/global.c b/src/global.c index a62eeb6..cd86a9d 100644 --- a/src/global.c +++ b/src/global.c @@ -439,12 +439,18 @@ int parse_optional_block(void) void parse_and_close_platform_file(FILE *fd, const char *eternal_plat_filename) { struct inputchange_buf icb; + const char *ppb; // path buffer in platform format // be verbose if (config.process_verbosity >= 3) printf("Parsing source file \"%s\".\n", eternal_plat_filename); - // set up new input + + // remember base for relative paths and set new one: + ppb = input_plat_pathref_filename; + input_plat_pathref_filename = eternal_plat_filename; + // remember input and set up new one: inputchange_new_file(&icb, fd, eternal_plat_filename); + // parse block and check end reason parse_until_eob_or_eof(); if (GotByte != CHAR_EOF) @@ -453,8 +459,11 @@ void parse_and_close_platform_file(FILE *fd, const char *eternal_plat_filename) // (this looks like we could just use "fd" as arg, but maybe the file // has been replaced with a different one in the meantime...) fclose(input_now->src.fd); + // restore outer input inputchange_back(&icb); + // restore outer base for relative paths + input_plat_pathref_filename = ppb; } // read optional info about parameter length diff --git a/src/input.c b/src/input.c index cea24e5..b95502b 100644 --- a/src/input.c +++ b/src/input.c @@ -43,7 +43,6 @@ const char FILE_READBINARY[] = "rb"; // fake input structure (for error msgs before any real input is established) static struct input outermost = { - "", // file name for resolving paths { "", // file name where code initially came from (differs during macro execution) 0, // line number @@ -58,8 +57,10 @@ static struct input outermost = { // variables struct input *input_now = &outermost; // current input structure -char GotByte; // last byte read (processed) -// TODO: move GotByte into input struct! +char GotByte; // last byte read (processed) TODO: move into input struct! +// name of source file used for resolving relative paths +// (i.e. not changed during macro execution): +const char *input_plat_pathref_filename = ""; // file name in platform format // functions @@ -759,7 +760,7 @@ static void library_path_to_pathbuf(void) // copy "default search path" from current file's file name into pathbuf: static void default_path_to_pathbuf(void) { - const char *start = input_now->plat_pathref_filename, + const char *start = input_plat_pathref_filename, *readptr, *found; @@ -846,7 +847,6 @@ void inputchange_new_file(struct inputchange_buf *icb, FILE *fd, const char *ete // TODO: in future, really buffer old data here! (instead of storing new data and changing pointer) // setup new input icb->new_input = *input_now; // copy current input structure into new - icb->new_input.plat_pathref_filename = eternal_plat_filename; icb->new_input.location.plat_filename = eternal_plat_filename; icb->new_input.location.line_number = 1; icb->new_input.source = INPUTSRC_FILE; diff --git a/src/input.h b/src/input.h index 3265fc1..ff9e2f5 100644 --- a/src/input.h +++ b/src/input.h @@ -18,10 +18,7 @@ enum inputsrc { INPUTSRC_RAM }; struct input { - const char *plat_pathref_filename; // file - // the filename *above* refers to the source file currently being parsed, which - // is needed as a reference for relative paths. - // the filename *below* (in "location") refers to the source file where + // the filename below (in "location") refers to the source file where // the current code initially came from, i.e. it may change during macro execution. struct location location; // file + line (during RAM reads as well) enum inputsrc source; @@ -52,6 +49,9 @@ extern const char FILE_READBINARY[]; // Variables extern struct input *input_now; // current input structure extern char GotByte; // last byte read (processed) +// name of source file used for resolving relative paths +// (i.e. not changed during macro execution): +extern const char *input_plat_pathref_filename; // file name in platform format diff --git a/src/version.h b/src/version.h index eca39ac..66d00e9 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ #define RELEASE "0.97" // update before release FIXME #define CODENAME "Zem" // update before release -#define CHANGE_DATE "21 Jul" // update before release FIXME +#define CHANGE_DATE "22 Jul" // update before release FIXME #define CHANGE_YEAR "2024" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME