34 static struct search_path *search_path_head, **search_path_tail;
39 const char *slash =
strrchr(path,
'/');
56 #define MAX_SRCFILE_DEPTH (100)
57 static int srcfile_depth;
71 static char *try_open(
const char *dirname,
const char *
fname, FILE **
fp)
75 if (!dirname || fname[0] ==
'/')
80 *fp = fopen(fullname,
"r");
98 static char *fopen_any_on_path(
const char *
fname, FILE **
fp)
100 const char *cur_dir =
NULL;
107 cur_dir = current_srcfile->
dir;
108 fullname = try_open(cur_dir, fname, fp);
111 for (node = search_path_head; !*fp &&
node; node = node->next)
112 fullname = try_open(node->dirname, fname, fp);
122 if (
streq(fname,
"-")) {
126 fullname = fopen_any_on_path(fname, &f);
128 die(
"Couldn't open \"%s\": %s\n", fname,
136 *fullnamep = fullname;
148 die(
"Includes nested too deeply");
150 srcfile =
xmalloc(
sizeof(*srcfile));
153 srcfile->
dir = dirname(srcfile->
name);
159 current_srcfile = srcfile;
168 current_srcfile = srcfile->
prev;
170 if (fclose(srcfile->
f))
171 die(
"Error closing \"%s\": %s\n", srcfile->
name,
180 return current_srcfile ? 1 : 0;
193 if (search_path_tail)
194 *search_path_tail =
node;
196 search_path_head =
node;
197 search_path_tail = &node->
next;
223 for (i = 0; i < len; i++)
224 if (text[i] ==
'\n') {
225 current_srcfile->
lineno++;
226 current_srcfile->
colno = 1;
227 }
else if (text[i] ==
'\t') {
228 current_srcfile->
colno =
231 current_srcfile->
colno++;
255 pos->
file ? (
char *) pos->
file :
"<no file>");
267 const char *fname =
"<no-file>";
272 fname = pos->
file->name;
276 rc = asprintf(&pos_str,
"%s:%d.%d-%d.%d", fname,
280 rc = asprintf(&pos_str,
"%s:%d.%d-%d", fname,
284 rc = asprintf(&pos_str,
"%s:%d.%d", fname,
288 die(
"Couldn't allocate in srcpos string");
300 fprintf(stdout,
"Error: %s ", srcstr);
325 fprintf(stderr,
"Warning: %s ", srcstr);
334 current_srcfile->
name =
f;