Commit bbc776e7 authored by Michaël Cadilhac's avatar Michaël Cadilhac
Browse files

2005-06-09 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>

	* parser.y: Search through `include_dirs' paths for file to include.
	* monoburg.h,
	* monoburg.c: Add a `-I' option to precise include directories.
parent deade0bf
2005-06-09 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* parser.y: Search through `include_dirs' paths for file to include.
* monoburg.h,
* monoburg.c: Add a `-I' option to precise include directories.
2005-06-09 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* parser.y: Add `#line' directives output on `%include', CODE and
......
......@@ -37,6 +37,9 @@ static int default_cost = 0;
char *namespaces[MAX_NAMESPACES];
int n_namespace = 0;
char **include_dirs;
int n_include_dir = 0;
static void output (char *fmt, ...)
{
va_list ap;
......@@ -1171,6 +1174,8 @@ main (int argc, char *argv [])
definedvars = g_hash_table_new (g_str_hash, g_str_equal);
g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, warning_handler, stderr);
include_dirs = g_new (char *, 10);
include_dirs [n_include_dir++] = ".";
for (i = 1; i < argc; i++){
if (argv [i][0] == '-'){
......@@ -1192,6 +1197,10 @@ main (int argc, char *argv [])
} else if (argv [i][1] == 'D') {
g_hash_table_insert (definedvars, &argv [i][2],
GUINT_TO_POINTER (1));
} else if (argv [i][1] == 'I') {
if (n_include_dir % 10 == 0)
include_dirs = g_renew (char *, include_dirs, n_include_dir + 10);
include_dirs [n_include_dir++] = argv [++i];
} else if (argv [i][1] == '-') {
/* Long options */
......@@ -1315,6 +1324,6 @@ main (int argc, char *argv [])
if (cfile)
fclose (cfd);
g_free (include_dirs);
return 0;
}
......@@ -15,6 +15,9 @@ extern FILE *outputfd;
extern GHashTable *definedvars;
extern char *namespaces[MAX_NAMESPACES];
extern int n_namespace;
extern char **include_dirs;
extern int n_include_dir;
typedef struct _Rule Rule;
......
......@@ -110,8 +110,10 @@ static int n_input = 0;
char *fgets_inc(char *s, int size)
{
int n_length;
int n_length, i;
char filename[MAX_FILENAME_LEN];
int b_found = FALSE;
char path[MAX_FILENAME_LEN * 2];
/* 9 == strlen("%include "); */
assert (size > 9 + MAX_FILENAME_LEN);
......@@ -139,12 +141,18 @@ char *fgets_inc(char *s, int size)
if (s[n_length - 1] == '\n')
s[n_length - 1] = 0;
strcpy (filename, s + 9);
if (!(inputs[n_input + 1].fd = fopen (filename, "r")))
for (i = 0; (b_found == FALSE) && i < n_include_dir; ++i)
{
sprintf (path, "%s/%s", include_dirs[i], filename);
if ((inputs[n_input + 1].fd = fopen (path, "r")))
b_found = TRUE;
}
if (b_found == FALSE)
yyerror ("`%%include %s': %s",
filename, strerror(errno));
fprintf (outputfd, "#line %d \"%s\"\n", 1, filename);
fprintf (outputfd, "#line %d \"%s\"\n", 1, path);
inputs[++n_input].yylineno = 0;
inputs[n_input].filename = strdup (filename);
inputs[n_input].filename = strdup (path);
return fgets_inc(s, size);
}
return s;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment