Commit 82198ed5 authored by Paul Eggert's avatar Paul Eggert
Browse files

etags ‘fatal’ function is now printf-like

* lib-src/etags.c (fatal): Now printf-like.  All callers changed.
Also, now static; not clear why it needed to be extern.
(verror): New function, with most of the old contents of ‘error’.
(fatal, error): Use it.
parent 641350b2
...@@ -361,8 +361,9 @@ static void analyze_regex (char *); ...@@ -361,8 +361,9 @@ static void analyze_regex (char *);
static void free_regexps (void); static void free_regexps (void);
static void regex_tag_multiline (void); static void regex_tag_multiline (void);
static void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); static void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
static void verror (char const *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
static _Noreturn void suggest_asking_for_help (void); static _Noreturn void suggest_asking_for_help (void);
_Noreturn void fatal (const char *, const char *); static _Noreturn void fatal (char const *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
static _Noreturn void pfatal (const char *); static _Noreturn void pfatal (const char *);
static void add_node (node *, node **); static void add_node (node *, node **);
...@@ -1091,7 +1092,7 @@ main (int argc, char **argv) ...@@ -1091,7 +1092,7 @@ main (int argc, char **argv)
++current_arg; ++current_arg;
++file_count; ++file_count;
if (parsing_stdin) if (parsing_stdin)
fatal ("cannot parse standard input more than once", (char *)NULL); fatal ("cannot parse standard input more than once");
parsing_stdin = true; parsing_stdin = true;
break; break;
...@@ -1255,8 +1256,8 @@ main (int argc, char **argv) ...@@ -1255,8 +1256,8 @@ main (int argc, char **argv)
if (streq (this_file, "-")) if (streq (this_file, "-"))
{ {
if (parsing_stdin) if (parsing_stdin)
fatal ("cannot parse standard input AND read file names from it", fatal ("cannot parse standard input "
(char *)NULL); "AND read file names from it");
while (readline_internal (&filename_lb, stdin, "-") > 0) while (readline_internal (&filename_lb, stdin, "-") > 0)
process_file_name (filename_lb.buffer, lang); process_file_name (filename_lb.buffer, lang);
} }
...@@ -1324,7 +1325,7 @@ main (int argc, char **argv) ...@@ -1324,7 +1325,7 @@ main (int argc, char **argv)
z = stpcpy (z, tagfile); z = stpcpy (z, tagfile);
strcpy (z, ";rm OTAGS"); strcpy (z, ";rm OTAGS");
if (system (cmd) != EXIT_SUCCESS) if (system (cmd) != EXIT_SUCCESS)
fatal ("failed to execute shell command", (char *)NULL); fatal ("failed to execute shell command");
} }
free (cmd); free (cmd);
append_to_tagfile = true; append_to_tagfile = true;
...@@ -6351,10 +6352,13 @@ skip_name (char *cp) ...@@ -6351,10 +6352,13 @@ skip_name (char *cp)
} }
/* Print error message and exit. */ /* Print error message and exit. */
void static void
fatal (const char *s1, const char *s2) fatal (char const *format, ...)
{ {
error (s1, s2); va_list ap;
va_start (ap, format);
verror (format, ap);
va_end (ap);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
...@@ -6379,10 +6383,16 @@ error (const char *format, ...) ...@@ -6379,10 +6383,16 @@ error (const char *format, ...)
{ {
va_list ap; va_list ap;
va_start (ap, format); va_start (ap, format);
verror (format, ap);
va_end (ap);
}
static void
verror (char const *format, va_list ap)
{
fprintf (stderr, "%s: ", progname); fprintf (stderr, "%s: ", progname);
vfprintf (stderr, format, ap); vfprintf (stderr, format, ap);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
va_end (ap);
} }
/* Return a newly-allocated string whose contents /* Return a newly-allocated string whose contents
...@@ -6673,7 +6683,7 @@ xmalloc (size_t size) ...@@ -6673,7 +6683,7 @@ xmalloc (size_t size)
{ {
void *result = malloc (size); void *result = malloc (size);
if (result == NULL) if (result == NULL)
fatal ("virtual memory exhausted", (char *)NULL); fatal ("virtual memory exhausted");
return result; return result;
} }
...@@ -6682,7 +6692,7 @@ xrealloc (void *ptr, size_t size) ...@@ -6682,7 +6692,7 @@ xrealloc (void *ptr, size_t size)
{ {
void *result = realloc (ptr, size); void *result = realloc (ptr, size);
if (result == NULL) if (result == NULL)
fatal ("virtual memory exhausted", (char *)NULL); fatal ("virtual memory exhausted");
return result; return result;
} }
......
Markdown is supported
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