X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=cbits%2Ffpstring.c;h=9e0b80921d3185c0977388887fd09830a1ab9a26;hb=6b1a36a595eddf1e124529646afdb75c76a9966d;hp=b8fc540403056163420f418e2a8cd5c40513dc08;hpb=3bdb7f5a1cf6de821f032f9507dd35433afd1d3d;p=haskell-directory.git diff --git a/cbits/fpstring.c b/cbits/fpstring.c index b8fc540..9e0b809 100644 --- a/cbits/fpstring.c +++ b/cbits/fpstring.c @@ -32,30 +32,30 @@ #include "fpstring.h" /* copy a string in reverse */ -void reverse(unsigned char *dest, unsigned char *from, int len) { - unsigned char *p, *q; - p = from + len - 1; - q = dest; - - while (p >= from) +void fps_reverse(unsigned char *q, unsigned char *p, unsigned long n) { + p += n-1; + while (n-- != 0) *q++ = *p--; } /* duplicate a string, interspersing the character through the elements of the duplicated string */ -void intersperse(unsigned char *dest, unsigned char *from, int len, char c) { - unsigned char *p, *q; - p = from; - q = dest; - while (p < from + len - 1) { - *q++ = *p++; +void fps_intersperse(unsigned char *q, + unsigned char *p, + unsigned long n, + unsigned char c) { + + while (n > 1) { + *q++ = *p++; *q++ = c; + n--; } - *q = *p; + if (n == 1) + *q = *p; } /* find maximum char in a packed string */ -unsigned char maximum(unsigned char *p, int len) { +unsigned char fps_maximum(unsigned char *p, unsigned long len) { unsigned char *q, c = *p; for (q = p; q < p + len; q++) if (*q > c) @@ -64,7 +64,7 @@ unsigned char maximum(unsigned char *p, int len) { } /* find minimum char in a packed string */ -unsigned char minimum(unsigned char *p, int len) { +unsigned char fps_minimum(unsigned char *p, unsigned long len) { unsigned char *q, c = *p; for (q = p; q < p + len; q++) if (*q < c) @@ -73,9 +73,9 @@ unsigned char minimum(unsigned char *p, int len) { } /* count the number of occurences of a char in a string */ -int count(unsigned char *p, int len, unsigned char w) { - int c; - for (c = 0; len--; ++p) +unsigned long fps_count(unsigned char *p, unsigned long len, unsigned char w) { + unsigned long c; + for (c = 0; len-- != 0; ++p) if (*p == w) ++c; return c;