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.
This commit is contained in:
Holger Vogt 2024-05-08 15:42:05 +02:00
parent 63a6234c92
commit b660e75504
1 changed files with 15 additions and 4 deletions

View File

@ -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);