X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/509cf0693fc440c71bdd3e71ea8947a6b4eb0bcf..c9d96fcfcf9b74099775a3a260eccdfdc31474c7:/src/util.c diff --git a/src/util.c b/src/util.c index e47be5e..acc112e 100644 --- a/src/util.c +++ b/src/util.c @@ -31,35 +31,58 @@ #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) +remove_sep(const char *base) { char *p; char *s = g_strdup(base); - while((p=strchr(s,':'))) - strcpy(p,p+1); + while((p = strchr(s, ':'))) + strcpy(p, p+1); return s; } char * -replace_sep(char *base, char r) +replace_sep(const char *base, char r) { char *p; char *s = g_strdup(base); @@ -76,7 +99,7 @@ replace_sep(char *base, char r) /*separate the namespace part and then replace rest of separators with r*/ void -separns_replace_sep(char *base, char **ns, char **name, char r) +separns_replace_sep(const char *base, char **ns, char **name, char r) { char *p; char *s = g_strdup(base); @@ -100,21 +123,35 @@ separns_replace_sep(char *base, char **ns, char **name, char r) /* make a macro with some prefix before the name but after namespace */ char * -make_pre_macro(char *base, char *pre) +make_pre_macro(const char *base, const char *pre) { - char *s1,*s2; + char *ns, *name; char *s; + char **v = NULL; + + if(strchr(base, ' ')) { + int i; + v = g_strsplit(base, " ", 0); + for(i = 0; v[i] != NULL; i++) { + if(*v[i] && strcmp(v[i], "const") != 0) { + base = v[i]; + break; + } + } + } - separns_replace_sep(base,&s1,&s2,'_'); - if(s1) - s = g_strconcat(s1,"_",pre,"_",s2,NULL); + separns_replace_sep(base, &ns, &name, '_'); + if(ns) + s = g_strconcat(ns, "_", pre, "_", name,NULL); else - s = g_strconcat(pre,"_",s2,NULL); + s = g_strconcat(pre, "_", name, NULL); g_strup(s); - g_free(s1); - g_free(s2); + g_free(ns); + g_free(name); + + g_strfreev(v); return s; } @@ -240,12 +277,12 @@ setup_special_array(Class *c, gboolean *special_array) } /* get the id without the first underscore, but only if we're removing them */ -char * -get_real_id(char *id) +const char * +get_real_id(const char *id) { - if(!no_kill_underscores && - id[0] == '_' && - id[1] != '\0') + if( ! no_kill_underscores && + id[0] == '_' && + id[1] != '\0') return &id[1]; else return id;