X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftools.c;h=f001ffb7e4cfa8e5adf5856009bfbf69aef79adb;hb=abeb8adc38f9d55fcb6cb3d076f57239b0a9a4d5;hp=83c4d45e0499c7961cbfadf7f419b2a274c8211c;hpb=d96f96eef3dfd036a06a52740b69ba10cede6d30;p=citadel.git diff --git a/webcit/tools.c b/webcit/tools.c index 83c4d45e0..f001ffb7e 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -73,30 +73,36 @@ int num_tokens(char *source, char tok) } /* - * extract_token() - a smarter string tokenizer + * extract_token() - a string tokenizer */ -void extract_token(char *dest, char *source, int parmnum, char separator) +void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen) { - int i; - int len; - int curr_parm; + char *d; /* dest */ + const char *s; /* source */ + int count = 0; + int len = 0; strcpy(dest, ""); - len = 0; - curr_parm = 0; - if (strlen(source) == 0) { - return; + /* Locate desired parameter */ + s = source; + while (count < parmnum) { + /* End of string, bail! */ + if (!*s) { + s = NULL; + break; + } + if (*s == separator) { + count++; + } + s++; } + if (!s) return; /* Parameter not found */ - for (i = 0; i < strlen(source); ++i) { - if (source[i] == separator) { - ++curr_parm; - } else if (curr_parm == parmnum) { - dest[len + 1] = 0; - dest[len++] = source[i]; - } + for (d = dest; *s && *s != separator && ++len= 2) { - extract_token(histr, setstr, 1, ':'); + extract_token(histr, setstr, 1, ':', sizeof histr); if (!strcmp(histr, "*")) { - snprintf(histr, sizeof histr, "%ld", - LONG_MAX); + snprintf(histr, sizeof histr, "%ld", LONG_MAX); } - } else { + } + else { strcpy(histr, lostr); } lo = atol(lostr); hi = atol(histr); - if ((msgnum >= lo) && (msgnum <= hi)) - return (1); + if ((msgnum >= lo) && (msgnum <= hi)) return(1); } - return (0); + return(0); } + /* * Strip a boundarized substring out of a string (for example, remove * parentheses and anything inside them).