1 #if (defined(_WIN32) || defined(_MSDOS) || defined(__IBMC__))
19 #if defined(__IBMC__) || defined(__EMX__)
21 # define PATH_MAX _MAX_PATH
27 Includelist includelist
[NINCLUDE
];
28 Wraplist wraplist
[NINCLUDE
];
31 doinclude(Tokenrow
* trp
, int depth
, int import
)
33 char fname
[PATH_MAX
], iname
[PATH_MAX
];
39 if (trp
->tp
>= trp
->lp
)
41 if (trp
->tp
->type
!= STRING
&& trp
->tp
->type
!= LT
)
43 len
= trp
->tp
- trp
->bp
;
44 expandrow(trp
, "<include>");
45 trp
->tp
= trp
->bp
+ len
;
47 if (trp
->tp
->type
== STRING
)
49 len
= trp
->tp
->len
- 2;
50 if (len
> sizeof(fname
) - 1)
51 len
= sizeof(fname
) - 1;
52 strncpy(fname
, (char *) trp
->tp
->t
+ 1, len
);
57 if (trp
->tp
->type
== LT
)
61 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
);
75 if (trp
->tp
< trp
->lp
|| len
== 0)
80 fd
= open(fname
, O_RDONLY
);
85 for (fd
= -1, i
= (depth
< 0) ? (NINCLUDE
- 1) : (depth
- 1); i
>= 0; i
--)
88 if (ip
->file
== NULL
|| ip
->deleted
|| (angled
&& ip
->always
== 0))
90 if (strlen(fname
) + strlen(ip
->file
) + 2 > sizeof(iname
))
92 strcpy(iname
, ip
->file
);
95 if ((fd
= open(iname
, O_RDONLY
)) >= 0)
102 if (++incdepth
> NINC
)
103 error(FATAL
, "#%s too deeply nested", import
? "import" : "include");
105 genimport(fname
, angled
, iname
, import
);
107 error(INFO
, "Open %s file [%s]", import
? "import" : "include", iname
);
109 for (i
= NINCLUDE
- 1; i
>= 0; i
--)
111 if ((wraplist
[i
].file
!= NULL
) &&
112 (strncmp(wraplist
[i
].file
, iname
, strlen(wraplist
[i
].file
)) == 0))
116 setsource((char *) newstring((uchar
*) iname
, strlen(iname
), 0), i
, fd
, NULL
, (i
>= 0) ? 1 : 0);
123 trp
->tp
= trp
->bp
+ 2;
124 error(ERROR
, "Could not find %s file %r", import
? "import" : "include", trp
);
128 error(ERROR
, "Syntax error in #%s", import
? "import" : "include");
133 * Generate a line directive for cursource
138 static Token ta
= {UNCLASS
, 0, 0, 0, NULL
, 0};
139 static Tokenrow tr
= {&ta
, &ta
, &ta
+ 1, 1};
142 ta
.t
= p
= (uchar
*) outptr
;
143 strcpy((char *) p
, "#line ");
144 p
+= sizeof("#line ") - 1;
145 p
= (uchar
*) outnum((char *) p
, cursource
->line
);
148 if (cursource
->filename
[0] != '/' && wd
[0])
150 strcpy((char *) p
, wd
);
154 strcpy((char *) p
, cursource
->filename
);
155 p
+= strlen((char *) p
);
158 ta
.len
= (char *) p
- outptr
;
165 * Generate a pragma import/include directive
168 genimport(char *fname
, int angled
, char *iname
, int import
)
170 static Token ta
= {UNCLASS
, 0, 0, 0, NULL
, 0};
171 static Tokenrow tr
= {&ta
, &ta
, &ta
+ 1, 1};
174 ta
.t
= p
= (uchar
*) outptr
;
177 strcpy((char *) p
, "#pragma import");
179 strcpy((char *) p
, "#pragma include");
181 p
+= strlen((char *) p
);
185 *p
++ = angled
? '<' : '"';
186 strcpy((char *) p
, fname
);
188 *p
++ = angled
? '>' : '"';
193 strcpy((char *) p
, iname
);
200 ta
.len
= (char *) p
- outptr
;
207 * Generate a extern C directive
212 static Token ta
= {UNCLASS
, 0, 0, 0, NULL
, 0};
213 static Tokenrow tr
= {&ta
, &ta
, &ta
+ 1, 1};
218 ta
.t
= p
= (uchar
*) outptr
;
221 strcpy((char *) p
, "extern \"C\" {");
223 strcpy((char *) p
, "}");
225 p
+= strlen((char *) p
);
229 ta
.len
= (char *) p
- outptr
;