#include <stdlib.h>
#include <string.h>
#include "cpp.h"
Include dependency graph for include.c:

Go to the source code of this file.
Functions | |
| void | doinclude (Tokenrow *trp) |
| void | genline (void) |
| void | setobjname (char *f) |
Variables | |
| Includelist | includelist [NINCLUDE] |
| char * | objname |
|
|
Definition at line 10 of file include.c. References includelist::always, tokenrow::bp, includelist::deleted, ERROR, error(), expandrow(), FATAL, includelist::file, genline(), i, incdepth, includelist, Includelist, token::len, tokenrow::lp, Mflag, newstring(), NINCLUDE, NULL, objname, open(), setsource(), strcat(), strcpy(), STRING, strlen(), strncpy(), token::t, Tokenrow, tokenrow::tp, token::type, uchar, and write(). Referenced by control(). 00011 {
00012 char fname[256], iname[256];
00013 Includelist *ip;
00014 int angled, len, fd, i;
00015
00016 trp->tp += 1;
00017 if (trp->tp>=trp->lp)
00018 goto syntax;
00019 if (trp->tp->type!=STRING && trp->tp->type!=LT) {
00020 len = trp->tp - trp->bp;
00021 expandrow(trp, "<include>");
00022 trp->tp = trp->bp+len;
00023 }
00024 if (trp->tp->type==STRING) {
00025 len = trp->tp->len-2;
00026 if (len > sizeof(fname) - 1)
00027 len = sizeof(fname) - 1;
00028 strncpy(fname, (char*)trp->tp->t+1, len);
00029 angled = 0;
00030 } else if (trp->tp->type==LT) {
00031 len = 0;
00032 trp->tp++;
00033 while (trp->tp->type!=GT) {
00034 if (trp->tp>trp->lp || len+trp->tp->len+2 >= sizeof(fname))
00035 goto syntax;
00036 strncpy(fname+len, (char*)trp->tp->t, trp->tp->len);
00037 len += trp->tp->len;
00038 trp->tp++;
00039 }
00040 angled = 1;
00041 } else
00042 goto syntax;
00043 trp->tp += 2;
00044 if (trp->tp < trp->lp || len==0)
00045 goto syntax;
00046 fname[len] = '\0';
00047 if (fname[0]=='/') {
00048 fd = open(fname, 0);
00049 strcpy(iname, fname);
00050 } else for (fd = -1,i=NINCLUDE-1; i>=0; i--) {
00051 ip = &includelist[i];
00052 if (ip->file==NULL || ip->deleted || (angled && ip->always==0))
00053 continue;
00054 if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname))
00055 continue;
00056 strcpy(iname, ip->file);
00057 strcat(iname, "/");
00058 strcat(iname, fname);
00059 if ((fd = open(iname, 0)) >= 0)
00060 break;
00061 }
00062 if ( Mflag>1 || !angled&&Mflag==1 ) {
00063 write(1,objname,strlen(objname));
00064 write(1,iname,strlen(iname));
00065 write(1,"\n",1);
00066 }
00067 if (fd >= 0) {
00068 if (++incdepth > 10)
00069 error(FATAL, "#include too deeply nested");
00070 setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL);
00071 genline();
00072 } else {
00073 trp->tp = trp->bp+2;
00074 error(ERROR, "Could not find include file %r", trp);
00075 }
00076 return;
00077 syntax:
00078 error(ERROR, "Syntax error in #include");
00079 return;
00080 }
|
Here is the call graph for this function:

|
|
Definition at line 86 of file include.c. References cursource, source::filename, token::len, source::line, outnum(), outp, p, puttokens(), strcpy(), strlen(), token::t, Token, Tokenrow, tr, uchar, UNCLASS, and wd. Referenced by doinclude(), main(), and process(). 00087 {
00088 static Token ta = { UNCLASS };
00089 static Tokenrow tr = { &ta, &ta, &ta+1, 1 };
00090 uchar *p;
00091
00092 ta.t = p = (uchar*)outp;
00093 strcpy((char*)p, "#line ");
00094 p += sizeof("#line ")-1;
00095 p = (uchar*)outnum((char*)p, cursource->line);
00096 *p++ = ' '; *p++ = '"';
00097 if (cursource->filename[0]!='/' && wd[0]) {
00098 strcpy((char*)p, wd);
00099 p += strlen(wd);
00100 *p++ = '/';
00101 }
00102 strcpy((char*)p, cursource->filename);
00103 p += strlen((char*)p);
00104 *p++ = '"'; *p++ = '\n';
00105 ta.len = (char*)p-outp;
00106 outp = (char*)p;
00107 tr.tp = tr.bp;
00108 puttokens(&tr);
00109 }
|
Here is the call graph for this function:

|
|
Definition at line 112 of file include.c. References domalloc(), f, n, objname, strcpy(), and strlen(). Referenced by setup(). 00113 {
00114 int n = strlen(f);
00115 objname = (char*)domalloc(n+5);
00116 strcpy(objname,f);
00117 if(objname[n-2]=='.'){
00118 strcpy(objname+n-1,"$O: ");
00119 }else{
00120 strcpy(objname+n,"$O: ");
00121 }
00122 }
|
Here is the call graph for this function:

|
|
Definition at line 5 of file include.c. Referenced by doinclude(). |
|
|
Definition at line 12 of file unix.c. Referenced by doinclude(), and setobjname(). |
1.3.9.1