cpp: search source file directory first for quoted #include (thanks Ori_B)
foo.c includes bar/bar.h, which includes "baz.h"; it wants bar/baz.h meanwhile, it also includes meh/quux.h, which includes "baz.h"; it wants meh/baz.h
This commit is contained in:
parent
a5efa0e252
commit
cd9da74cbc
1 changed files with 29 additions and 17 deletions
|
@ -47,27 +47,39 @@ doinclude(Tokenrow *trp)
|
|||
if (fname[0]=='/') {
|
||||
fd = open(fname, 0);
|
||||
strcpy(iname, fname);
|
||||
} else for (fd=-1,i=NINCLUDE-1; i>=0; i--) {
|
||||
ip = &includelist[i];
|
||||
if (ip->file==NULL || ip->deleted || (angled && ip->always==0))
|
||||
continue;
|
||||
if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname))
|
||||
continue;
|
||||
strcpy(iname, ip->file);
|
||||
strcat(iname, "/");
|
||||
strcat(iname, fname);
|
||||
if ((fd = open(iname, 0)) >= 0)
|
||||
break;
|
||||
}
|
||||
if(fd < 0) {
|
||||
strcpy(iname, cursource->filename);
|
||||
p = strrchr(iname, '/');
|
||||
if(p != NULL) {
|
||||
*p = '\0';
|
||||
} else {
|
||||
fd = -1;
|
||||
if (!angled) {
|
||||
strcpy(iname, cursource->filename);
|
||||
p = strrchr(iname, '/');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
strcat(iname, "/");
|
||||
strcat(iname, fname);
|
||||
fd = open(iname, 0);
|
||||
}
|
||||
}
|
||||
for (i=NINCLUDE-1; fd<0 && i>=0; i--) {
|
||||
ip = &includelist[i];
|
||||
if (ip->file==NULL || ip->deleted || (angled && ip->always==0))
|
||||
continue;
|
||||
if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname))
|
||||
continue;
|
||||
strcpy(iname, ip->file);
|
||||
strcat(iname, "/");
|
||||
strcat(iname, fname);
|
||||
fd = open(iname, 0);
|
||||
}
|
||||
if (fd<0 && angled) {
|
||||
strcpy(iname, cursource->filename);
|
||||
p = strrchr(iname, '/');
|
||||
if(p != NULL) {
|
||||
*p = '\0';
|
||||
strcat(iname, "/");
|
||||
strcat(iname, fname);
|
||||
fd = open(iname, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( Mflag>1 || !angled&&Mflag==1 ) {
|
||||
write(1,objname,strlen(objname));
|
||||
|
|
Loading…
Reference in a new issue