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;
{
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);
}
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))
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;
}
}
}
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;
}
}
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);
}
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);