diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-10-07 23:37:03 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-10-07 23:37:03 +0000 |
commit | fbb4007ac88656122f9319dea4563a3a4fd40e82 (patch) | |
tree | ca4265ac43d139b3fd02ba32bfe6d5e12cadb65c /libc | |
parent | b8f03a94957c913fa0d8588c41b0332b49310ff0 (diff) |
Update and simplification.
Diffstat (limited to 'libc')
-rw-r--r-- | libc/string/.indent.pro | 33 | ||||
-rw-r--r-- | libc/string/Makefile | 7 | ||||
-rw-r--r-- | libc/string/config.c | 126 | ||||
-rw-r--r-- | libc/string/strcasecmp.c | 27 | ||||
-rw-r--r-- | libc/string/strcspn.c | 19 | ||||
-rw-r--r-- | libc/string/string.c | 392 | ||||
-rw-r--r-- | libc/string/strncasecmp.c | 30 | ||||
-rw-r--r-- | libc/string/strpbrk.c | 16 | ||||
-rw-r--r-- | libc/string/strsep.c | 25 | ||||
-rw-r--r-- | libc/string/strspn.c | 34 | ||||
-rw-r--r-- | libc/string/strstr.c | 156 | ||||
-rw-r--r-- | libc/string/strtok.c | 58 |
12 files changed, 434 insertions, 489 deletions
diff --git a/libc/string/.indent.pro b/libc/string/.indent.pro new file mode 100644 index 000000000..492ecf1c7 --- /dev/null +++ b/libc/string/.indent.pro @@ -0,0 +1,33 @@ +--blank-lines-after-declarations +--blank-lines-after-procedures +--break-before-boolean-operator +--no-blank-lines-after-commas +--braces-on-if-line +--braces-on-struct-decl-line +--comment-indentation25 +--declaration-comment-column25 +--no-comment-delimiters-on-blank-lines +--cuddle-else +--continuation-indentation4 +--case-indentation0 +--else-endif-column33 +--space-after-cast +--line-comments-indentation0 +--declaration-indentation1 +--dont-format-first-column-comments +--dont-format-comments +--honour-newlines +--indent-level4 +/* changed from 0 to 4 */ +--parameter-indentation4 +--line-length78 /* changed from 75 */ +--continue-at-parentheses +--no-space-after-function-call-names +--dont-break-procedure-type +--dont-star-comments +--leave-optional-blank-lines +--dont-space-special-semicolon +--tab-size4 +/* additions by Mark */ +--case-brace-indentation0 +--leave-preprocessor-space diff --git a/libc/string/Makefile b/libc/string/Makefile index 3d2e3d2de..d8d65fa3d 100644 --- a/libc/string/Makefile +++ b/libc/string/Makefile @@ -27,11 +27,10 @@ LIBC=$(TOPDIR)libc.a MSRC=string.c MOBJ=strlen.o strcat.o strcpy.o strcmp.o strncat.o strncpy.o strncmp.o \ strchr.o strrchr.o strdup.o memcpy.o memccpy.o memset.o \ - memmove.o + memmove.o memcmp.o memchr.o CSRC=strpbrk.c strsep.c strstr.c strtok.c strcspn.c \ - config.c memcmp.c memchr.c strspn.c strcasecmp.c \ - strncasecmp.c + config.c strspn.c strcasecmp.c strncasecmp.c COBJS=$(patsubst %.c,%.o, $(CSRC)) all: $(MOBJ) $(COBJS) $(LIBC) @@ -42,8 +41,6 @@ $(LIBC): $(MOBJ) $(COBJS) $(MOBJ): $(MSRC) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o -memcmp.o: memcopy.h - clean: rm -f *.[oa] *~ core diff --git a/libc/string/config.c b/libc/string/config.c index 58716b922..dad9a723e 100644 --- a/libc/string/config.c +++ b/libc/string/config.c @@ -17,76 +17,72 @@ static char *args[16]; static char cfgbuf[128]; -static char * -ws(char **buf) +static char *ws(char **buf) { - char *b = *buf; - char *p; - - /* eat ws */ - while (*b && - (*b == ' ' || - *b == '\n' || - *b == '\t')) b++; - p = b; - - /* find the end */ - while (*p && - !(*p == ' ' || - *p == '\n' || - *p == '\t')) p++; - *p = 0; - *buf = p+1; - return b; + char *b = *buf; + char *p; + + /* eat ws */ + while (*b && (*b == ' ' || *b == '\n' || *b == '\t')) + b++; + p = b; + + /* find the end */ + while (*p && !(*p == ' ' || *p == '\n' || *p == '\t')) + p++; + *p = 0; + *buf = p + 1; + return b; } -char ** -cfgread(FILE *fp) +char **cfgread(FILE * fp) { - char *ebuf; - char *p; - int i; - - if (!fp) { - errno = EIO; - return (void *)0; - } - - while (fgets(cfgbuf, sizeof(cfgbuf), fp)) { - - /* ship comment lines */ - if (cfgbuf[0] == '#') continue; - - ebuf = cfgbuf + strlen(cfgbuf); - - p = cfgbuf; - for (i = 0; i < 16 && p < ebuf; i++) { - args[i] = ws(&p); - } - args[i] = (void *)0; - - /* return if we found something */ - if (strlen(args[0])) return args; - } - return (void *)0; + char *ebuf; + char *p; + int i; + + if (!fp) { + errno = EIO; + return (void *) 0; + } + + while (fgets(cfgbuf, sizeof(cfgbuf), fp)) { + + /* ship comment lines */ + if (cfgbuf[0] == '#') + continue; + + ebuf = cfgbuf + strlen(cfgbuf); + + p = cfgbuf; + for (i = 0; i < 16 && p < ebuf; i++) { + args[i] = ws(&p); + } + args[i] = (void *) 0; + + /* return if we found something */ + if (strlen(args[0])) + return args; + } + return (void *) 0; } -char ** -cfgfind(FILE *fp, char *var) +char **cfgfind(FILE * fp, char *var) { - char **ret; - char search[80]; - - if (!fp || !var) { - errno = EIO; - return (void *)0; - } - - strncpy(search, var, sizeof(search)); - - fseek(fp, 0, SEEK_SET); - while ((ret = cfgread(fp))) { - if (!strcmp(ret[0], search)) return ret; - } - return (void *)0; + char **ret; + char search[80]; + + if (!fp || !var) { + errno = EIO; + return (void *) 0; + } + + strncpy(search, var, sizeof(search)); + + fseek(fp, 0, SEEK_SET); + while ((ret = cfgread(fp))) { + if (!strcmp(ret[0], search)) + return ret; + } + return (void *) 0; } diff --git a/libc/string/strcasecmp.c b/libc/string/strcasecmp.c index c6144ff23..0ec81f641 100644 --- a/libc/string/strcasecmp.c +++ b/libc/string/strcasecmp.c @@ -6,21 +6,16 @@ #include <string.h> #include <ctype.h> -int -strcasecmp(s, d) -const char *s; -const char *d; +int strcasecmp( const char *s, const char *d) { - for(;;) - { - if( *s != *d ) - { - if( tolower(*s) != tolower(*d) ) - return *s - *d; - } - else if( *s == '\0' ) break; - s++; d++; - } - return 0; + for (;;) { + if (*s != *d) { + if (tolower(*s) != tolower(*d)) + return *s - *d; + } else if (*s == '\0') + break; + s++; + d++; + } + return 0; } - diff --git a/libc/string/strcspn.c b/libc/string/strcspn.c index 3630a1333..d30195db1 100644 --- a/libc/string/strcspn.c +++ b/libc/string/strcspn.c @@ -33,18 +33,15 @@ /* Return the length of the maximum initial segment of S which contains no characters from REJECT. */ -size_t -strcspn (s, reject) - const char *s; - const char *reject; +size_t strcspn( const char *s, const char *reject) { - size_t count = 0; + size_t count = 0; - while (*s != '\0') - if (strchr (reject, *s++) == NULL) - ++count; - else - return count; + while (*s != '\0') + if (strchr(reject, *s++) == NULL) + ++count; + else + return count; - return count; + return count; } diff --git a/libc/string/string.c b/libc/string/string.c index 1777ce03c..eb5c17709 100644 --- a/libc/string/string.c +++ b/libc/string/string.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk> * This file is part of the Linux-8086 C library and is distributed * under the GNU Library General Public License. @@ -6,321 +7,280 @@ #include <string.h> #include <malloc.h> -/* This is a basic string package; it includes the most used functions - - strlen strcat strcpy strcmp strncat strncpy strncmp strchr strrchr strdup - memcpy memccpy memset memmove - - These functions are in seperate files. - strpbrk.o strsep.o strstr.o strtok.o strcspn.o - strspn.o strcasecmp.o strncasecmp.o - */ - /********************** Function strlen ************************************/ #ifdef L_strlen -size_t strlen(const char * str) +size_t strlen(const char *str) { - register char * p =(char *) str; - while(*p) p++; - return p-str; + register char *ptr = (char *) str; + + while (*ptr) + ptr++; + return (ptr - str); } #endif /********************** Function strcat ************************************/ #ifdef L_strcat -char * strcat(char *d, const char * s) +char *strcat(char *dst, const char *src) { - (void) strcpy(d+strlen(d), s); - return d; + strcpy(dst + strlen(dst), src); + return dst; } #endif /********************** Function strcpy ************************************/ #ifdef L_strcpy -char * strcpy( char *d, const char * s) +char *strcpy(char *dst, const char *src) { - /* This is probably the quickest on an 8086 but a CPU with a cache will - * prefer to do this in one pass */ - return memcpy(d, s, strlen(s)+1); + register char *ptr = dst; + + while (*src) + *dst++ = *src++; + *dst = '\0'; + + return ptr; } #endif /********************** Function strcmp ************************************/ #ifdef L_strcmp -int strcmp(const char *d, const char * s) +int strcmp(const char *s1, const char *s2) { - register const unsigned char *s1 = (const unsigned char *) d; - register const unsigned char *s2 = (const unsigned char *) s; - unsigned register char c1, c2; - - do - { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0') - return c1 - c2; - } - while (c1 == c2); - - return c1 - c2; + unsigned register char c1, c2; + + do { + c1 = (unsigned char) *s1++; + c2 = (unsigned char) *s2++; + if (c1 == '\0') + return c1 - c2; + } + while (c1 == c2); + + return c1 - c2; } #endif /********************** Function strncat ************************************/ #ifdef L_strncat -char * strncat( char *d, const char *s, size_t l) +char *strncat(char *dst, const char *src, size_t len) { - register char *s1=d+strlen(d), *s2; - - s2 = memchr(s, 0, l); - if( s2 ) - memcpy(s1, s, s2-s+1); - else - { - memcpy(s1, s, l); - s1[l] = '\0'; - } - return d; + register char *s1 = dst + strlen(dst), *s2; + + s2 = memchr(src, 0, len); + if (s2) { + memcpy(s1, src, s2 - src + 1); + } else { + memcpy(s1, src, len); + s1[len] = '\0'; + } + return dst; } #endif /********************** Function strncpy ************************************/ #ifdef L_strncpy -char * strncpy ( char *s1, const char *s2, size_t n) +char *strncpy(char *dst, const char *src, size_t len) { - register char c; - char *s = s1; - - --s1; - - if (n >= 4) - { - size_t n4 = n >> 2; - - for (;;) - { - c = *s2++; - *++s1 = c; - if (c == '\0') - break; - c = *s2++; - *++s1 = c; - if (c == '\0') - break; - c = *s2++; - *++s1 = c; - if (c == '\0') - break; - c = *s2++; - *++s1 = c; - if (c == '\0') - break; - if (--n4 == 0) - goto last_chars; + char *ptr = dst; + + while (len--) { + if (*src) + *dst++ = *src++; + else + *dst++ = '\0'; } - n = n - (s1 - s) - 1; - if (n == 0) - return s; - goto zero_fill; - } - -last_chars: - n &= 3; - if (n == 0) - return s; - - do - { - c = *s2++; - *++s1 = c; - if (--n == 0) - return s; - } - while (c != '\0'); - -zero_fill: - do - *++s1 = '\0'; - while (--n > 0); - - return s; + + return ptr; } #endif /********************** Function strncmp ************************************/ #ifdef L_strncmp -int strncmp (const char *s1, const char *s2, size_t n) +int strncmp(const char *s1, const char *s2, size_t len) { - unsigned register char c1 = '\0'; - unsigned register char c2 = '\0'; - - if (n >= 4) - { - size_t n4 = n >> 2; - do - { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - } while (--n4 > 0); - n &= 3; - } - - while (n > 0) - { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - n--; - } + unsigned register char c1 = '\0'; + unsigned register char c2 = '\0'; + + while (len > 0) { + c1 = (unsigned char) *s1++; + c2 = (unsigned char) *s2++; + if (c1 == '\0' || c1 != c2) + return c1 - c2; + len--; + } - return c1 - c2; + return c1 - c2; } #endif /********************** Function strchr ************************************/ #ifdef L_strchr -char * -strchr(s, c) -const char * s; -int c; +char *strchr(const char *str, int c) { - register char ch; - for(;;) - { - if( (ch= *s) == c ) return (char*)s; - if( ch == 0 ) return 0; - s++; - } + register char ch; + + do { + if ((ch = *str) == c) + return (char *) str; + str++; + } + while (ch); + + return 0; } #endif /********************** Function strrchr ************************************/ #ifdef L_strrchr -char * strrchr(s, c) -const char * s; -int c; +char *strrchr(const char *str, int c) { - register char * prev = 0; - register char * p = (char*)s; - /* For null it's just like strlen */ - if( c == '\0' ) return p+strlen(p); - - /* everything else just step along the string. */ - while( (p=strchr(p, c)) != 0 ) - { - prev = p; p++; - } - return prev; + register char *prev = 0; + register char *ptr = (char *) str; + + /* For null it's just like strlen */ + if (c == '\0') + return ptr + strlen(ptr); + + /* everything else just step along the string. */ + while ((ptr = strchr(ptr, c)) != 0) { + prev = ptr; + ptr++; + } + return prev; } #endif /********************** Function strdup ************************************/ #ifdef L_strdup -char * strdup(s) -const char * s; +char *strdup(const char *str) { - register size_t len; - register char * p; - - len = strlen(s)+1; - p = (char *) malloc(len); - if(p) memcpy(p, s, len); /* Faster than strcpy */ - return p; + register size_t len; + register char *dst; + + len = strlen(str) + 1; + dst = (char *) malloc(len); + if (dst) + memcpy(dst, str, len); + return dst; } #endif /********************** Function memcpy ************************************/ #ifdef L_memcpy -void * -memcpy(d, s, l) -void *d; -const void *s; -size_t l; +void *memcpy(void *dst, const void *src, size_t len) { - register char *s1=d, *s2=(char *)s; - for( ; l>0; l--) *((unsigned char*)s1++) = *((unsigned char*)s2++); - return d; + register char *a = dst; + register const char *b = src; + + while (len--) + *a++ = *b++; + + return dst; } #endif /********************** Function memccpy ************************************/ #ifdef L_memccpy -void * memccpy(d, s, c, l) /* Do we need a fast one ? */ -void *d; -const void *s; -int c; -size_t l; +void *memccpy(void *dst, const void *src, int c, size_t len) { - register char *s1=d, *s2=(char*)s; - while(l-- > 0) - if((*s1++ = *s2++) == c ) - return s1; - return 0; + register char *a = dst; + register const char *b = src; + + while (len--) { + if ((*a++ = *b++) == c) + return a; + } + + return 0; } #endif /********************** Function memset ************************************/ #ifdef L_memset -void * memset(str, c, l) -void * str; -int c; -size_t l; +void *memset(void *str, int c, size_t len) { - register char *s1=str; - while(l-->0) *s1++ = c; - return str; + register char *a = str; + + while (len--) + *a++ = c; + + return str; } #endif /********************** Function memmove ************************************/ #ifdef L_memmove -void * -memmove(d, s, l) -void *d; -const void *s; -size_t l; +void *memmove(void *dst, const void *src, size_t len) { - register char *s1=d, *s2=(char*)s; - /* This bit of sneakyness c/o Glibc, it assumes the test is unsigned */ - if( s1-s2 >= l ) return memcpy(d,s,l); - - /* This reverse copy only used if we absolutly have to */ - s1+=l; s2+=l; - while(l-- >0) - *(--s1) = *(--s2); - return d; + register char *s1 = dst, *s2 = (char *) src; + + /* This bit of sneakyness c/o Glibc, it assumes the test is unsigned */ + if (s1 - s2 >= len) + return memcpy(dst, src, len); + + /* This reverse copy only used if we absolutly have to */ + s1 += len; + s2 += len; + while (len-- > 0) + *(--s1) = *(--s2); + return dst; } #endif +/********************** Function memchr ************************************/ -/********************** THE END ********************************************/ +#ifdef L_memchr +void *memchr(const void *str, int c, size_t len) +{ + register unsigned char *ptr = (unsigned char *) str; + + while (len--) { + if (*ptr == (unsigned char) c) + return ptr; + ptr++; + } + + return 0; +} +#endif + +/********************** Function memcmp ************************************/ + +#ifdef L_memcmp +int memcmp(const void *s1, const void *s2, size_t len) +{ + unsigned register char c1 = '\0'; + unsigned register char c2 = '\0'; + + register char *str1 = (char *) s1; + register char *str2 = (char *) s2; + + while (len > 0) { + c1 = (unsigned char) *str1++; + c2 = (unsigned char) *str2++; + if (c1 == '\0' || c1 != c2) + return c1 - c2; + len--; + } + + return c1 - c2; +} +#endif + + +/********************** THE END ********************************************/ diff --git a/libc/string/strncasecmp.c b/libc/string/strncasecmp.c index c55f259d4..ba73e6f09 100644 --- a/libc/string/strncasecmp.c +++ b/libc/string/strncasecmp.c @@ -6,23 +6,17 @@ #include <string.h> #include <ctype.h> -int -strncasecmp(s, d, l) -const char *s; -const char *d; -size_t l; +int strncasecmp( const char *s, const char *d, size_t l) { - while(l>0) - { - if( *s != *d ) - { - if( tolower(*s) != tolower(*d) ) - return *s - *d; - } - else - if( *s == '\0' ) return 0; - s++; d++; l--; - } - return 0; + while (l > 0) { + if (*s != *d) { + if (tolower(*s) != tolower(*d)) + return *s - *d; + } else if (*s == '\0') + return 0; + s++; + d++; + l--; + } + return 0; } - diff --git a/libc/string/strpbrk.c b/libc/string/strpbrk.c index 7e6b1a4a2..fe2ec229d 100644 --- a/libc/string/strpbrk.c +++ b/libc/string/strpbrk.c @@ -7,15 +7,13 @@ /* This uses strchr, strchr should be in assembler */ -char *strpbrk(str, set) -register const char *str; -const char *set; +char *strpbrk( const char *str, const char *set) { - while (*str != '\0') - if (strchr(set, *str) == 0) - ++str; - else - return (char *) str; + while (*str != '\0') + if (strchr(set, *str) == 0) + ++str; + else + return (char *) str; - return 0; + return 0; } diff --git a/libc/string/strsep.c b/libc/string/strsep.c index f4fdf503e..797807a91 100644 --- a/libc/string/strsep.c +++ b/libc/string/strsep.c @@ -19,21 +19,16 @@ Cambridge, MA 02139, USA. */ #include <string.h> -char * -strsep(pp, delim) -char **pp; -const char *delim; +char *strsep( char **pp, const char *delim) { - char *p, *q; + char *p, *q; - if (!(p = *pp)) - return 0; - if ((q = strpbrk (p, delim))) - { - *pp = q + 1; - *q = '\0'; - } - else - *pp = 0; - return p; + if (!(p = *pp)) + return 0; + if ((q = strpbrk(p, delim))) { + *pp = q + 1; + *q = '\0'; + } else + *pp = 0; + return p; } diff --git a/libc/string/strspn.c b/libc/string/strspn.c index 5f64a6f75..70b510a7f 100644 --- a/libc/string/strspn.c +++ b/libc/string/strspn.c @@ -22,25 +22,21 @@ /* Return the length of the maximum initial segment of S which contains only characters in ACCEPT. */ -size_t -strspn (s, accept) - const char *s; - const char *accept; +size_t strspn( const char *s, const char *accept) { - const char *p; - const char *a; - size_t count = 0; - - for (p = s; *p != '\0'; ++p) - { - for (a = accept; *a != '\0'; ++a) - if (*p == *a) - break; - if (*a == '\0') - return count; - else - ++count; - } + const char *p; + const char *a; + size_t count = 0; + + for (p = s; *p != '\0'; ++p) { + for (a = accept; *a != '\0'; ++a) + if (*p == *a) + break; + if (*a == '\0') + return count; + else + ++count; + } - return count; + return count; } diff --git a/libc/string/strstr.c b/libc/string/strstr.c index 03d6c8e5f..b1890559b 100644 --- a/libc/string/strstr.c +++ b/libc/string/strstr.c @@ -38,88 +38,80 @@ typedef unsigned chartype; #undef strstr -char * -strstr (phaystack, pneedle) - const char *phaystack; - const char *pneedle; +char *strstr( const char *phaystack, const char *pneedle) { - register const unsigned char *haystack, *needle; - register chartype b, c; - - haystack = (const unsigned char *) phaystack; - needle = (const unsigned char *) pneedle; - - b = *needle; - if (b != '\0') - { - haystack--; /* possible ANSI violation */ - do - { - c = *++haystack; - if (c == '\0') - goto ret0; + register const unsigned char *haystack, *needle; + register chartype b, c; + + haystack = (const unsigned char *) phaystack; + needle = (const unsigned char *) pneedle; + + b = *needle; + if (b != '\0') { + haystack--; /* possible ANSI violation */ + do { + c = *++haystack; + if (c == '\0') + goto ret0; + } + while (c != b); + + c = *++needle; + if (c == '\0') + goto foundneedle; + ++needle; + goto jin; + + for (;;) { + register chartype a; + register const unsigned char *rhaystack, *rneedle; + + do { + a = *++haystack; + if (a == '\0') + goto ret0; + if (a == b) + break; + a = *++haystack; + if (a == '\0') + goto ret0; + shloop:} + while (a != b); + + jin:a = *++haystack; + if (a == '\0') + goto ret0; + + if (a != c) + goto shloop; + + rhaystack = haystack-- + 1; + rneedle = needle; + a = *rneedle; + + if (*rhaystack == a) + do { + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = *++needle; + if (*rhaystack != a) + break; + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = *++needle; + } + while (*rhaystack == a); + + needle = rneedle; /* took the register-poor approach */ + + if (a == '\0') + break; + } } - while (c != b); - - c = *++needle; - if (c == '\0') - goto foundneedle; - ++needle; - goto jin; - - for (;;) - { - register chartype a; - register const unsigned char *rhaystack, *rneedle; - - do - { - a = *++haystack; - if (a == '\0') - goto ret0; - if (a == b) - break; - a = *++haystack; - if (a == '\0') - goto ret0; -shloop: } - while (a != b); - -jin: a = *++haystack; - if (a == '\0') - goto ret0; - - if (a != c) - goto shloop; - - rhaystack = haystack-- + 1; - rneedle = needle; - a = *rneedle; - - if (*rhaystack == a) - do - { - if (a == '\0') - goto foundneedle; - ++rhaystack; - a = *++needle; - if (*rhaystack != a) - break; - if (a == '\0') - goto foundneedle; - ++rhaystack; - a = *++needle; - } - while (*rhaystack == a); - - needle = rneedle; /* took the register-poor approach */ - - if (a == '\0') - break; - } - } -foundneedle: - return (char*) haystack; -ret0: - return 0; + foundneedle: + return (char *) haystack; + ret0: + return 0; } diff --git a/libc/string/strtok.c b/libc/string/strtok.c index c23c5b85e..51bc6038a 100644 --- a/libc/string/strtok.c +++ b/libc/string/strtok.c @@ -30,42 +30,34 @@ static char *olds = 0; x = strtok(NULL, "="); // x = NULL // s = "abc\0-def\0" */ -char * -strtok(s, delim) -register char *s; -register const char *delim; +char *strtok( register char *s, register const char *delim) { - char *token; + char *token; - if (s == 0) - { - if (olds == 0) - { - return 0; + if (s == 0) { + if (olds == 0) { + return 0; + } else + s = olds; } - else - s = olds; - } - /* Scan leading delimiters. */ - s += strspn(s, delim); - if (*s == '\0') - { - olds = 0; - return 0; - } + /* Scan leading delimiters. */ + s += strspn(s, delim); + if (*s == '\0') { + olds = 0; + return 0; + } - /* Find the end of the token. */ - token = s; - s = strpbrk(token, delim); - if (s == 0) - /* This token finishes the string. */ - olds = 0; - else - { - /* Terminate the token and make OLDS point past it. */ - *s = '\0'; - olds = s + 1; - } - return token; + /* Find the end of the token. */ + token = s; + s = strpbrk(token, delim); + if (s == 0) + /* This token finishes the string. */ + olds = 0; + else { + /* Terminate the token and make OLDS point past it. */ + *s = '\0'; + olds = s + 1; + } + return token; } |