diff options
-rw-r--r-- | def.h | 4 | ||||
-rw-r--r-- | include.c | 24 | ||||
-rw-r--r-- | main.c | 2 |
3 files changed, 21 insertions, 9 deletions
@@ -112,6 +112,7 @@ struct symtab { struct inclist { char *i_incstring; /* string from #include line */ char *i_file; /* path name of the include file */ + char *i_realpath; /* path name processed by realpath() */ struct inclist **i_list; /* list of files it itself includes */ struct symtab **i_defs; /* symbol table for this file and its children when merged */ @@ -146,7 +147,8 @@ struct symtab **fdefined(const char *symbol, struct inclist *file, struct inclist **srcfile); struct filepointer *getfile(const char *file); void included_by(struct inclist *ip, struct inclist *newfile); -struct inclist *newinclude(const char *newfile, const char *incstring); +struct inclist *newinclude(const char *newfile, const char *incstring, + const char *incpath); void inc_clean(void); struct inclist *inc_path(const char *file, const char *include, int type); @@ -143,7 +143,7 @@ remove_dotdot(char *path) * Add an include file to the list of those included by 'file'. */ struct inclist * -newinclude(const char *newfile, const char *incstring) +newinclude(const char *newfile, const char *incstring, const char *incpath) { struct inclist *ip; @@ -165,6 +165,20 @@ newinclude(const char *newfile, const char *incstring) fatalerr("strdup() failure in %s()\n", __func__); } + if (incpath == NULL) { + char r_include[PATHMAX + 1]; + + if (realpath(ip->i_file, r_include) == NULL) + ip->i_realpath = ip->i_file; + else + ip->i_realpath = strdup(r_include); + } + else { + ip->i_realpath = strdup(incpath); + } + if (ip->i_realpath == NULL) + fatalerr("strdup() failure in %s()\n", __func__); + inclistnext = inclistp; return (ip); } @@ -328,16 +342,12 @@ inc_path(const char *file, const char *include, int type) /* * Same filename but same file ? */ - char r_saved_path[PATHMAX + 1]; - - if (realpath(ip->i_file, r_saved_path) == NULL) - continue; - if (!strcmp(r_include, r_saved_path)) { + if (!strcmp(r_include, ip->i_realpath)) { inclistnext = ip + 1; return ip; } } } - return newinclude(fp, include); + return newinclude(fp, include, r_include); } @@ -518,7 +518,7 @@ main(int argc, char *argv[]) DBG_PRINT(stderr, "file: %s\n", *fp); filecontent = getfile(*fp); setfile_cmdinc(filecontent, cmdinc_count, cmdinc_list); - ip = newinclude(*fp, (char *) NULL); + ip = newinclude(*fp, NULL, NULL); find_includes(filecontent, ip, ip, 0, FALSE); freefile(filecontent); |