From b660e7550420b700b18f74fce264dec0a223bb1d Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 8 May 2024 15:42:05 +0200 Subject: [PATCH] Save path to .include file, add it to the search paths for loading the next .include file. If input directory dir_name is not set when loading .include files, set it to the first .include found. Both instruction add to the search paths for file to be inluded and are valuable when the netlist is sent by circbyline without input file involved. --- src/frontend/inpcom.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index e5f7c4bf6..35c99037c 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -1433,11 +1433,15 @@ static struct inp_read_t inp_read(FILE* fp, int call_depth, const char* dir_name char* y_resolved = inp_pathresolve_at(y, dir_name); char* y_dir_name; FILE* newfp; + static char oldpath[512]; if (!y_resolved) { - fprintf(cp_err, "Error: Could not find include file %s\n", - y); - controlled_exit(EXIT_FAILURE); + /* try again with most recent .include path */ + y_resolved = inp_pathresolve_at(y, oldpath); + if (!y_resolved) { + fprintf(cp_err, "Error: Could not find include file %s\n", y); + controlled_exit(EXIT_FAILURE); + } } newfp = fopen(y_resolved, "r"); @@ -1456,7 +1460,14 @@ static struct inp_read_t inp_read(FILE* fp, int call_depth, const char* dir_name .cc; /* read stuff in include file into netlist */ - tfree(y_dir_name); + strncpy(oldpath, y_dir_name, 511); + + /* if we don't have dir_name, e.g. when the netlist is loaded via + circbyline, then set dir_name to first .include path found. */ + if (dir_name) + tfree(y_dir_name); + else + dir_name = y_dir_name; tfree(y_resolved); (void)fclose(newfp);