- {
- int i;
- for (i = 0; i < file_names_count; i++)
- if (0 == strcmp (file_names[i], file_name))
- warn (_("conflicting outputs to file %s"), quote (file_name));
- }
- file_names = xnrealloc (file_names, ++file_names_count, sizeof *file_names);
- file_names[file_names_count-1] = xstrdup (file_name);
+ bool conflict = false;
+ if (STREQ (*file_name, grammar_file))
+ {
+ complain (NULL, complaint, _("refusing to overwrite the input file %s"),
+ quote (*file_name));
+ conflict = true;
+ }
+ else
+ {
+ int i;
+ 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 (generated_files[i].name));
+ conflict = true;
+ }
+ }
+ if (conflict)
+ {
+ free (*file_name);
+ *file_name = strdup ("/dev/null");
+ }
+ else
+ {
+ 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;
+ }
+}
+
+void
+unlink_generated_sources (void)
+{
+ int i;
+ for (i = 0; i < generated_files_size; i++)
+ if (generated_files[i].is_source)
+ /* Ignore errors. The file might not even exist. */
+ unlink (generated_files[i].name);