]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
Linux SDL/GLX: allow loading the icon from .xpm at runtime (darkplaces-icon.xpm)...
[xonotic/darkplaces.git] / common.c
index b52b0bfaf9cf5529d107c381f632f78977a196cc..028014bc7420a96b24d7cf232b73f497af7a4cb8 100644 (file)
--- a/common.c
+++ b/common.c
@@ -2228,3 +2228,31 @@ void FindFraction(double val, int *num, int *denom, int denomMax)
                }
        }
 }
+
+// decodes an XPM from C syntax
+char **XPM_DecodeString(const char *in)
+{
+       static char *tokens[257];
+       static char lines[257][512];
+       size_t line = 0;
+
+       // skip until "{" token
+       while(COM_ParseToken_QuakeC(&in, false) && strcmp(com_token, "{"));
+
+       // now, read in succession: string, comma-or-}
+       while(COM_ParseToken_QuakeC(&in, false))
+       {
+               tokens[line] = lines[line];
+               strlcpy(lines[line++], com_token, sizeof(lines[0]));
+               if(!COM_ParseToken_QuakeC(&in, false))
+                       return NULL;
+               if(!strcmp(com_token, "}"))
+                       break;
+               if(strcmp(com_token, ","))
+                       return NULL;
+               if(line >= sizeof(tokens) / sizeof(tokens[0]))
+                       return NULL;
+       }
+
+       return tokens;
+}