diff options
| author | Anselm R Garbe <anselm@garbe.us> | 2010-04-17 11:12:54 +0100 |
|---|---|---|
| committer | Anselm R Garbe <anselm@garbe.us> | 2010-04-17 11:12:54 +0100 |
| commit | 75d42255f22a40935ced8b2e4c134996f8efebe2 (patch) | |
| tree | 23ed5b3c3503e596c7c001a6bcb481d98a23ad34 /util.c | |
| parent | dad75aa6ba9f9b50b5f6c656929092aad0963462 (diff) | |
| download | cic-75d42255f22a40935ced8b2e4c134996f8efebe2.tar.gz | |
applied anonymous cleanup patch, thanks anonymous!
Diffstat (limited to 'util.c')
| -rw-r--r-- | util.c | 43 |
1 files changed, 18 insertions, 25 deletions
@@ -47,35 +47,28 @@ strlcpy(char *to, const char *from, int l) { to[l-1] = '\0'; } -static void -eat(char **s, int (*p)(int), int r) { - char *q; - - for(q = *s; *q && p(*q) == r; q++) - ; - *s = q; +static char * +eat(char *s, int (*p)(int), int r) { + while(s != '\0' && p(*s) == r) + s++; + return s; } static char* -tok(char **s) { - char *p; - - eat(s, isspace, 1); - p = *s; - eat(s, isspace, 0); - if(**s) - *(*s)++ = '\0'; - return p; +skip(char *s, char c) { + while(*s != c && *s != '\0') + s++; + if (*s != '\0') + *s++ = '\0'; + return s; } -static char* -ctok(char **s, int c) { - char *p, *q; +static void +trim(char *s) { + char *e; - q = *s; - for(p = q; *p && *p != c; p++) - ; - if(*p) *p++ = '\0'; - *s = p; - return q; + e = s + strlen(s) - 1; + while (isspace(*e) && e > s) + e--; + *(e + 1) = '\0'; } |
