]> git.draconx.ca Git - gob-dx.git/blobdiff - src/util.c
Release 1.0.4
[gob-dx.git] / src / util.c
index ae169144f6cd3fcd698f01c2b58c879b47c89b74..37abe55cfe3b9243ef61449f435503d3fa27f158 100644 (file)
 #include "util.h"
 
 void
-print_error(gboolean is_warn, char *error, int line)
+error_print(int type, int line, const char *error)
 {
-       char *w;
-       if(is_warn)
+       char *w = NULL;
+
+       switch(type) {
+       case GOB_WARN:
                w = "Warning:";
-       else {
+               break;
+       case GOB_ERROR:
                w = "Error:";
                got_error = TRUE;
+               break;
+       default:
+               g_assert_not_reached();
        }
-       if(line>0)
+       if(line > 0)
                fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
        else
                fprintf(stderr, "%s: %s %s\n", filename, w, error);
-       if((!is_warn || exit_on_warn) && exit_on_error)
+       if(exit_on_error &&
+          (type == GOB_ERROR ||
+           (type == GOB_WARN && exit_on_warn)))
                exit(1);
 }
 
+void
+error_printf(int type, int line, const char *error, ...)
+{
+       va_list ap;
+       char *s;
+
+       va_start(ap, error);
+       s = g_strdup_vprintf(error, ap);
+       va_end(ap);
+
+       error_print(type, line, s);
+
+       g_free(s);
+}
+
 char *
 remove_sep(char *base)
 {
        char *p;
        char *s = g_strdup(base);
        while((p = strchr(s, ':')))
-               strcpy(p,p+1);
+               strcpy(p, p+1);
        return s;
 }