6 Includelist includelist
[NINCLUDE
];
10 void appendDirToIncludeList( char *dir
)
15 fqdir
= (char *)newstring( (uchar
*)includelist
[NINCLUDE
-1].file
, 256, 0 );
19 //avoid adding it more than once
20 for (i
=NINCLUDE
-2; i
>=0; i
--) {
21 if (includelist
[i
].file
&&
22 !strcmp (includelist
[i
].file
, fqdir
)) {
27 for (i
=NINCLUDE
-2; i
>=0; i
--) {
28 if (includelist
[i
].file
==NULL
) {
29 includelist
[i
].always
= 1;
30 includelist
[i
].file
= fqdir
;
35 error(FATAL
, "Too many -I directives");
39 doinclude(Tokenrow
*trp
)
41 char fname
[256], iname
[256];
43 int angled
, len
, fd
, i
;
48 if (trp
->tp
->type
!=STRING
&& trp
->tp
->type
!=LT
) {
49 len
= trp
->tp
- trp
->bp
;
50 expandrow(trp
, "<include>");
51 trp
->tp
= trp
->bp
+len
;
53 if (trp
->tp
->type
==STRING
) {
55 if (len
> sizeof(fname
) - 1)
56 len
= sizeof(fname
) - 1;
57 strncpy(fname
, (char*)trp
->tp
->t
+1, len
);
59 } else if (trp
->tp
->type
==LT
) {
62 while (trp
->tp
->type
!=GT
) {
63 if (trp
->tp
>trp
->lp
|| len
+trp
->tp
->len
+2 >= sizeof(fname
))
65 strncpy(fname
+len
, (char*)trp
->tp
->t
, trp
->tp
->len
);
73 if (trp
->tp
< trp
->lp
|| len
==0)
77 appendDirToIncludeList( basepath( fname
) );
82 } else for (fd
= -1,i
=NINCLUDE
-1; i
>=0; i
--) {
84 if (ip
->file
==NULL
|| ip
->deleted
|| (angled
&& ip
->always
==0))
86 if (strlen(fname
)+strlen(ip
->file
)+2 > sizeof(iname
))
88 strcpy(iname
, ip
->file
);
91 if ((fd
= open(iname
, 0)) >= 0)
94 if ( Mflag
>1 || (!angled
&&Mflag
==1) ) {
95 write(1,objname
,strlen(objname
));
96 write(1,iname
,strlen(iname
));
101 error(FATAL
, "#include too deeply nested");
102 setsource((char*)newstring((uchar
*)iname
, strlen(iname
), 0), fd
, NULL
);
106 error(ERROR
, "Could not find include file %r", trp
);
110 error(ERROR
, "Syntax error in #include");
115 * Generate a line directive for cursource
120 static Token ta
= { UNCLASS
};
121 static Tokenrow tr
= { &ta
, &ta
, &ta
+1, 1 };
124 ta
.t
= p
= (uchar
*)outp
;
125 strcpy((char*)p
, "#line ");
126 p
+= sizeof("#line ")-1;
127 p
= (uchar
*)outnum((char*)p
, cursource
->line
);
128 *p
++ = ' '; *p
++ = '"';
129 if (cursource
->filename
[0]!='/' && wd
[0]) {
130 strcpy((char*)p
, wd
);
134 strcpy((char*)p
, cursource
->filename
);
135 p
+= strlen((char*)p
);
136 *p
++ = '"'; *p
++ = '\n';
137 ta
.len
= (char*)p
-outp
;
147 objname
= (char*)domalloc(n
+5);
149 if(objname
[n
-2]=='.'){
150 strcpy(objname
+n
-1,"$O: ");
152 strcpy(objname
+n
,"$O: ");