]> git.refcnt.org Git - colorize.git/blobdiff - colorize.c
Add vfprintf_diag and macro
[colorize.git] / colorize.c
index 6cd51f773db27fe494f6f1ed4aefaed206799258..3b80c9e9ab5382a5c7164f8f31216d277f12991c 100644 (file)
@@ -43,9 +43,6 @@
 
 #define streq(s1, s2) (strcmp (s1, s2) == 0)
 
-#define vfprintf_fail(fmt, ...) vfprintf_name(true,  fmt, __VA_ARGS__)
-#define vfprintf_diag(fmt, ...) vfprintf_name(false, fmt, __VA_ARGS__)
-
 #if DEBUG
 # define xmalloc(size)        malloc_wrap_debug(size,        __FILE__, __LINE__)
 # define xcalloc(nmemb, size) calloc_wrap_debug(nmemb, size, __FILE__, __LINE__)
@@ -199,7 +196,8 @@ static void *realloc_wrap_debug (void *, size_t, const char *, unsigned int);
 static void free_wrap (void **);
 static char *strdup_wrap (const char *);
 static char *str_concat (const char *, const char *);
-static void vfprintf_name (bool, const char *, ...);
+static void vfprintf_diag (const char *, ...);
+static void vfprintf_fail (const char *, ...);
 static void stack_var (void ***, unsigned int *, unsigned int, void *);
 static void release_var (void **, unsigned int, void **);
 
@@ -974,17 +972,25 @@ str_concat (const char *str1, const char *str2)
     return str;
 }
 
+#define DO_VFPRINTF(fmt)                    \
+    va_list ap;                             \
+    fprintf (stderr, "%s: ", program_name); \
+    va_start (ap, fmt);                     \
+    vfprintf (stderr, fmt, ap);             \
+    va_end (ap);                            \
+    fprintf (stderr, "\n");                 \
+
+static void
+vfprintf_diag (const char *fmt, ...)
+{
+    DO_VFPRINTF (fmt);
+}
+
 static void
-vfprintf_name (bool fatal, const char *fmt, ...)
+vfprintf_fail (const char *fmt, ...)
 {
-    va_list ap;
-    fprintf (stderr, "%s: ", program_name);
-    va_start (ap, fmt);
-    vfprintf (stderr, fmt, ap);
-    va_end (ap);
-    fprintf (stderr, "\n");
-    if (fatal)
-      exit (EXIT_FAILURE);
+    DO_VFPRINTF (fmt);
+    exit (EXIT_FAILURE);
 }
 
 static void