modify code
[build-config.git] / src / config / lxrgmr-code / token / srcfile.c
blobc2d7a13185cd3e266ba1646b8bd626fce11a586e
2 #ifndef LXRGMR_CODE
4 struct buffer *current_buf;
6 /*********************************************************************
7 * zconf_xxx().
8 *********************************************************************/
10 /* this buffer released in gmr parser code. */
11 void zconf_starthelp(void)
13 // do not alloc buff in command.
14 // new_string(&strbuff);
15 BEGIN(HELP_TXT);
18 void zconf_endhelp(void)
20 yylval.string = strbuff.text;
21 BEGIN(INITIAL);
26 * Try to open specified file with following names:
27 * ./name
28 * $(srctree)/name
29 * The latter is used when srctree is separate from objtree
30 * when compiling the kernel.
31 * Return NULL if file is not found.
33 FILE *zconf_fopen(const char *name)
35 char *env, fullname[PATH_MAX+1];
36 FILE *f;
38 f = fopen(name, "r");
39 if (!f && name != NULL && name[0] != '/') {
40 env = getenv(SRCTREE);
41 if (env) {
42 sprintf(fullname, "%s/%s", env, name);
43 f = fopen(fullname, "r");
46 return f;
49 void zconf_initscan(const char *name)
51 yyin = zconf_fopen(name);
52 if (!yyin) {
53 fprintf(stderr, "can't find file %s\n", name);
54 exit(1);
57 current_buf = xmalloc(sizeof(*current_buf));
58 memset(current_buf, 0, sizeof(*current_buf));
60 current_file = file_lookup(name);
61 yylineno = 1;
64 void zconf_nextfile(const char *name)
66 struct file *iter;
67 struct file *file = file_lookup(name);
68 struct buffer *buf = xmalloc(sizeof(*buf));
69 memset(buf, 0, sizeof(*buf));
71 current_buf->state = YY_CURRENT_BUFFER;
72 yyin = zconf_fopen(file->name);
73 if (!yyin) {
74 fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
75 zconf_curname(), zconf_lineno(), file->name);
76 exit(1);
78 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
79 buf->parent = current_buf;
80 current_buf = buf;
82 current_file->lineno = yylineno;
83 file->parent = current_file;
85 for (iter = current_file; iter; iter = iter->parent) {
86 if (!strcmp(iter->name, file->name)) {
87 fprintf(stderr,
88 "Recursive inclusion detected.\n"
89 "Inclusion path:\n"
90 " current file : %s\n", file->name);
91 iter = file;
92 do {
93 iter = iter->parent;
94 fprintf(stderr, " included from: %s:%d\n",
95 iter->name, iter->lineno - 1);
96 } while (strcmp(iter->name, file->name));
97 exit(1);
101 yylineno = 1;
102 current_file = file;
105 void zconf_endfile(void)
107 struct buffer *parent;
109 current_file = current_file->parent;
110 if (current_file)
111 yylineno = current_file->lineno;
113 parent = current_buf->parent;
114 if (parent) {
115 fclose(yyin);
116 yy_delete_buffer(YY_CURRENT_BUFFER);
117 yy_switch_to_buffer(parent->state);
119 free(current_buf);
120 current_buf = parent;
123 int zconf_lineno(void)
125 return current_pos.lineno;
128 const char *zconf_curname(void)
130 return current_pos.file ? current_pos.file->name : "<none>";
133 #else
135 void zconf_endfile(void)
137 return;
140 #endif