]> git.draconx.ca Git - gob-dx.git/blobdiff - src/util.c
Release 1.0.2
[gob-dx.git] / src / util.c
index e47be5ef6110be81001f7c279afdb18571f843c9..ae169144f6cd3fcd698f01c2b58c879b47c89b74 100644 (file)
@@ -53,13 +53,13 @@ remove_sep(char *base)
 {
        char *p;
        char *s = g_strdup(base);
-       while((p=strchr(s,':')))
+       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 +76,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 +100,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;
 }