From ea99d6e6a02a06bd63e788393fd42cde5cb1fa71 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 4 Dec 2013 10:26:46 +0100 Subject: [PATCH] output: record what generated files are source or report files * src/files.h, src/files.c (output_file_name_check): Take an additional argument to record whether a file is a source or report file. * src/files.c (generated_file): New. (file_names, file_names_count): Replace with... (generated_files, generated_files_size): these. * src/scan-skel.l: Adjust. --- src/files.c | 40 +++++++++++++++++++++++++--------------- src/files.h | 7 ++++++- src/scan-skel.l | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/files.c b/src/files.c index 76aa7fe3..46868365 100644 --- a/src/files.c +++ b/src/files.c @@ -51,8 +51,17 @@ char *spec_defines_file = NULL; /* for --defines. */ char *parser_file_name; /* All computed output file names. */ -static char **file_names = NULL; -static int file_names_count = 0; +typedef struct generated_file +{ + /** File name. */ + char *name; + /** Whether is a generated source file (e.g., *.c, *.java...), as + opposed to the report file (e.g., *.output). When late errors + are detected, generated source files are removed. */ + bool is_source; +} generated_file; +static generated_file *generated_files = NULL; +static int generated_files_size = 0; uniqstr grammar_file = NULL; uniqstr current_file = NULL; @@ -332,21 +341,21 @@ compute_output_file_names (void) { if (! spec_graph_file) spec_graph_file = concat2 (all_but_tab_ext, ".dot"); - output_file_name_check (&spec_graph_file); + output_file_name_check (&spec_graph_file, false); } if (xml_flag) { if (! spec_xml_file) spec_xml_file = concat2 (all_but_tab_ext, ".xml"); - output_file_name_check (&spec_xml_file); + output_file_name_check (&spec_xml_file, false); } if (report_flag) { if (!spec_verbose_file) spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT); - output_file_name_check (&spec_verbose_file); + output_file_name_check (&spec_verbose_file, false); } free (all_but_tab_ext); @@ -355,7 +364,7 @@ compute_output_file_names (void) } void -output_file_name_check (char **file_name) +output_file_name_check (char **file_name, bool source) { bool conflict = false; if (STREQ (*file_name, grammar_file)) @@ -367,11 +376,11 @@ output_file_name_check (char **file_name) else { int i; - for (i = 0; i < file_names_count; i++) - if (STREQ (file_names[i], *file_name)) + for (i = 0; i < generated_files_size; i++) + if (STREQ (generated_files[i].name, *file_name)) { complain (NULL, Wother, _("conflicting outputs to file %s"), - quote (*file_name)); + quote (generated_files[i].name)); conflict = true; } } @@ -382,9 +391,10 @@ output_file_name_check (char **file_name) } else { - file_names = xnrealloc (file_names, ++file_names_count, - sizeof *file_names); - file_names[file_names_count-1] = xstrdup (*file_name); + generated_files = xnrealloc (generated_files, ++generated_files_size, + sizeof *generated_files); + generated_files[generated_files_size-1].name = xstrdup (*file_name); + generated_files[generated_files_size-1].is_source = source; } } @@ -400,8 +410,8 @@ output_file_names_free (void) free (dir_prefix); { int i; - for (i = 0; i < file_names_count; i++) - free (file_names[i]); + for (i = 0; i < generated_files_size; i++) + free (generated_files[i].name); } - free (file_names); + free (generated_files); } diff --git a/src/files.h b/src/files.h index ebe5037c..94833f71 100644 --- a/src/files.h +++ b/src/files.h @@ -63,7 +63,12 @@ extern char *all_but_ext; void compute_output_file_names (void); void output_file_names_free (void); -void output_file_name_check (char **file_name); + +/** Record that we generate file \a file_name. + * \param source whether this is a source file (*c, *.java...) + * as opposed to a report (*.output, *.dot...). + */ +void output_file_name_check (char **file_name, bool source); FILE *xfopen (const char *name, char const *mode); void xfclose (FILE *ptr); diff --git a/src/scan-skel.l b/src/scan-skel.l index 48c5e46a..129b8899 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -244,7 +244,7 @@ at_output (int argc, char *argv[], char **out_namep, int *out_linenop) xfclose (yyout); } *out_namep = xstrdup (argv[1]); - output_file_name_check (out_namep); + output_file_name_check (out_namep, true); /* If there were errors, do not generate the output. */ yyout = xfopen (complaint_status ? "/dev/null" : *out_namep, "w"); *out_linenop = 1; -- 2.47.2