ref: cd9da74cbc2ff04de2179565bf31d8536eb9bd6b
parent: a5efa0e252692b888a5de679cfc901a0421ffe73
author: cinap_lenrek <[email protected]>
date: Sun Jul 12 20:54:56 EDT 2015
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
--- a/sys/src/cmd/cpp/include.c
+++ b/sys/src/cmd/cpp/include.c
@@ -47,26 +47,38 @@
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 ) {