+int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix)
+{
+ int argc, commentprefixlength;
+ char *tokenbufend;
+ const char *l;
+ argc = 0;
+ tokenbufend = tokenbuf + tokenbufsize;
+ l = *text;
+ commentprefixlength = 0;
+ if (commentprefix)
+ commentprefixlength = strlen(commentprefix);
+ while (*l && *l != '\n')
+ {
+ if (*l > ' ')
+ {
+ if (commentprefixlength && !strncmp(l, commentprefix, commentprefixlength))
+ {
+ while (*l && *l != '\n')
+ l++;
+ break;
+ }
+ if (argc >= maxargc)
+ return -1;
+ argv[argc++] = tokenbuf;
+ if (*l == '"')
+ {
+ l++;
+ while (*l && *l != '"')
+ {
+ if (tokenbuf >= tokenbufend)
+ return -1;
+ *tokenbuf++ = *l++;
+ }
+ if (*l == '"')
+ l++;
+ }
+ else
+ {
+ while (*l > ' ')
+ {
+ if (tokenbuf >= tokenbufend)
+ return -1;
+ *tokenbuf++ = *l++;
+ }
+ }
+ if (tokenbuf >= tokenbufend)
+ return -1;
+ *tokenbuf++ = 0;
+ }
+ else
+ l++;
+ }
+ if (*l == '\n')
+ l++;
+ *text = l;
+ return argc;
+}
+