summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/main.c b/main.c
index 1ee55da..4014595 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.35 2010/12/27 01:21:59 tom Exp $ */
+/* $Id: main.c,v 1.36 2011/09/06 22:44:45 tom Exp $ */
#include <signal.h>
#include <unistd.h> /* for _exit() */
@@ -34,6 +34,7 @@ static MY_TMPFILES *my_tmpfiles;
char dflag;
char gflag;
+char iflag;
char lflag;
static char oflag;
char rflag;
@@ -53,7 +54,9 @@ static char *file_prefix = default_file_prefix;
char *code_file_name;
char *input_file_name = empty_string;
-static char *defines_file_name;
+char *defines_file_name;
+char *externs_file_name;
+
static char *graph_file_name;
static char *output_file_name;
static char *verbose_file_name;
@@ -62,6 +65,7 @@ FILE *action_file; /* a temp file, used to save actions associated */
/* with rules until the parser is written */
FILE *code_file; /* y.code.c (used when the -r option is specified) */
FILE *defines_file; /* y.tab.h */
+FILE *externs_file; /* y.tab.i */
FILE *input_file; /* the input file */
FILE *output_file; /* y.tab.c */
FILE *text_file; /* a temp file, used to save text until all */
@@ -132,6 +136,9 @@ done(int k)
if (dflag)
DO_FREE(defines_file_name);
+ if (iflag)
+ DO_FREE(externs_file_name);
+
if (oflag)
DO_FREE(output_file_name);
@@ -187,6 +194,7 @@ usage(void)
,"Options:"
," -b file_prefix set filename prefix (default \"y.\")"
," -d write definitions (y.tab.h)"
+ ," -i write interface (y.tab.i)"
," -g write a graphical description"
," -l suppress #line directives"
," -o output_file (default \"y.tab.c\")"
@@ -220,6 +228,10 @@ setflag(int ch)
gflag = 1;
break;
+ case 'i':
+ iflag = 1;
+ break;
+
case 'l':
lflag = 1;
break;
@@ -359,17 +371,22 @@ create_file_names(void)
{
size_t len;
const char *defines_suffix;
+ const char *externs_suffix;
char *prefix;
prefix = NULL;
defines_suffix = DEFINES_SUFFIX;
+ externs_suffix = EXTERNS_SUFFIX;
/* compute the file_prefix from the user provided output_file_name */
if (output_file_name != 0)
{
if (!(prefix = strstr(output_file_name, ".tab.c"))
&& (prefix = strstr(output_file_name, ".c")))
+ {
defines_suffix = ".h";
+ externs_suffix = ".i";
+ }
}
if (prefix != NULL)
@@ -401,6 +418,11 @@ create_file_names(void)
CREATE_FILE_NAME(defines_file_name, defines_suffix);
}
+ if (iflag)
+ {
+ CREATE_FILE_NAME(externs_file_name, externs_suffix);
+ }
+
if (vflag)
{
CREATE_FILE_NAME(verbose_file_name, VERBOSE_SUFFIX);
@@ -592,6 +614,13 @@ open_files(void)
union_file = open_tmpfile("union_file");
}
+ if (iflag)
+ {
+ externs_file = fopen(externs_file_name, "w");
+ if (externs_file == 0)
+ open_error(externs_file_name);
+ }
+
output_file = fopen(output_file_name, "w");
if (output_file == 0)
open_error(output_file_name);