5 Includelist includelist[NINCLUDE];
10 doinclude(Tokenrow *trp)
12 char fname[256], iname[256], *p;
14 int angled, len, fd, i;
19 if (trp->tp->type!=STRING && trp->tp->type!=LT) {
20 len = trp->tp - trp->bp;
21 expandrow(trp, "<include>", Notinmacro);
22 trp->tp = trp->bp+len;
24 if (trp->tp->type==STRING) {
26 if (len > sizeof(fname) - 1)
27 len = sizeof(fname) - 1;
28 strncpy(fname, (char*)trp->tp->t+1, len);
30 } else if (trp->tp->type==LT) {
33 while (trp->tp->type!=GT) {
34 if (trp->tp>trp->lp || len+trp->tp->len+2 >= sizeof(fname))
36 strncpy(fname+len, (char*)trp->tp->t, trp->tp->len);
44 if (trp->tp < trp->lp || len==0)
53 strcpy(iname, cursource->filename);
54 p = strrchr(iname, '/');
62 for (i=NINCLUDE-1; fd<0 && i>=0; i--) {
64 if (ip->file==NULL || ip->deleted || (angled && ip->always==0))
66 if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname))
68 strcpy(iname, ip->file);
74 strcpy(iname, cursource->filename);
75 p = strrchr(iname, '/');
84 if ( Mflag>1 || !angled&&Mflag==1 ) {
85 write(1,objname,strlen(objname));
86 write(1,iname,strlen(iname));
91 error(FATAL, "#include too deeply nested");
92 setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL);
96 error(ERROR, "Could not find include file %r", trp);
100 error(ERROR, "Syntax error in #include");
105 * Generate a line directive for cursource
110 static Token ta = { UNCLASS, NULL, 0, 0 };
111 static Tokenrow tr = { &ta, &ta, &ta+1, 1 };
117 ta.t = p = (uchar*)outp;
118 strcpy((char*)p, "#line ");
119 p += sizeof("#line ")-1;
120 p = (uchar*)outnum((char*)p, cursource->line);
121 *p++ = ' '; *p++ = '"';
122 if (cursource->filename[0]!='/' && wd[0]) {
123 strcpy((char*)p, wd);
127 strcpy((char*)p, cursource->filename);
128 p += strlen((char*)p);
129 *p++ = '"'; *p++ = '\n';
130 ta.len = (char*)p-outp;
140 objname = (char*)domalloc(n+5);
142 if(objname[n-2]=='.'){
143 strcpy(objname+n-1,"$O: ");
145 strcpy(objname+n,"$O: ");