/* GOB C Preprocessor
* Copyright (C) 1999-2000 the Free Software Foundation.
* Copyright (C) 2000 Eazel, Inc.
+ * Copyright (C) 2022 Nick Bowler
*
* Author: George Lebl
*
* USA.
*/
-#include "config.h"
+#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
error_print(int type, int line, const char *error)
{
const char *w = NULL;
+ const char *fname = NULL;
switch(type) {
case GOB_WARN:
w = "Warning:";
+ if (exit_on_warn)
+ got_error = TRUE;
break;
case GOB_ERROR:
w = "Error:";
default:
g_assert_not_reached();
}
- if(line > 0)
- fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
+ fname = filename;
+ if (fname == NULL)
+ fname = "gob2";
+ if (line > 0)
+ fprintf(stderr, "%s:%d: %s %s\n", fname, line, w, error);
else
- fprintf(stderr, "%s: %s %s\n", filename, w, error);
- if(exit_on_error &&
- (type == GOB_ERROR ||
- (type == GOB_WARN && exit_on_warn)))
+ fprintf(stderr, "%s: %s %s\n", fname, w, error);
+ if (exit_on_error && got_error)
exit(1);
}
{
char *p;
char *s = g_strdup(base);
+ char *q=s;
/* don't eat C++ :: thingies */
if (for_cpp && strstr (s, "::") != NULL)
return s;
- while((p = strchr(s, ':')))
- strcpy(p, p+1);
+ for(p=(char *)base;*p;p++){
+ if (*p!=':')
+ *q++=*p;
+ }
+ *q='\0';
return s;
}
if (for_cpp && strstr (s, "::") != NULL)
return s;
- while((p=strchr(s,':')))
- *p = r;
+ if (r == '\0') {
+ while ((p=strchr(s,':')) != NULL) {
+ char *t = p;
+ while (*t != '\0') {
+ *t = *(t+1);
+ t++;
+ }
+ }
+ } else {
+ while ((p=strchr(s,':')) != NULL)
+ *p = r;
+ }
if(*s == r) {
p = g_strdup(s+1);
g_free(s);
else
s = g_strconcat(pre, "_", name, NULL);
- g_strup(s);
+ gob_strup (s);
g_free(ns);
g_free(name);
init_type_hash ();
- gtype = g_hash_table_lookup (type_hash, type);
+ if(strncmp(type, "BOXED_", 6) == 0)
+ gtype = g_hash_table_lookup (type_hash, "BOXED");
+ else
+ gtype = g_hash_table_lookup (type_hash, type);
if (gtype == NULL ||
(simple_only &&
char *
get_type (const Type *t, gboolean postfix_to_stars)
{
- char *s;
+ char *ret, *s;
int i;
int extra;
GString *gs;
g_string_append_c (gs, '*');
g_string_append_c (gs, ' ');
}
-
- return g_string_free (gs, FALSE);
+ ret = gs->str;
+ g_string_free(gs, FALSE);
+ return ret;
+}
+
+#if HAVE_G_ASCII_STRCASECMP
+char *gob_strup(char *str)
+{
+ char *s;
+
+ for (s = str; *s; s++)
+ *s = g_ascii_toupper(*s);
+
+ return str;
}
+char *gob_strdown(char *str)
+{
+ char *s;
+
+ for (s = str; *s; s++)
+ *s = g_ascii_tolower(*s);
+
+ return str;
+}
+#endif
+
+char *
+gob_str_delete_quotes(char *str)
+{
+ char *p, *i;
+ p=i=str;
+ while(*p!='\0')
+ {
+ if(*p=='\"')
+ {
+ p++;
+ continue;
+ }
+ *i=*p;
+ p++; i++;
+ }
+ *i=*p;
+ return str;
+}
+
+char *
+make_me_type (const char *type, const char *alt)
+{
+ if (type == NULL)
+ return g_strdup (alt);
+ /* HACK! just in case someone made this
+ * work with 2.0.0 by using the TYPE
+ * macro directly */
+ if ((strstr (type, "_TYPE_") != NULL ||
+ strstr (type, "TYPE_") == type) &&
+ strchr (type, ':') == NULL)
+ return g_strdup (type);
+ return make_pre_macro (type, "TYPE");
+}