diff options
author | Eduardo Chappa <echappa@gmx.com> | 2013-02-03 00:59:38 -0700 |
---|---|---|
committer | Eduardo Chappa <echappa@gmx.com> | 2013-02-03 00:59:38 -0700 |
commit | 094ca96844842928810f14844413109fc6cdd890 (patch) | |
tree | e60efbb980f38ba9308ccb4fb2b77b87bbc115f3 /imap/src/ansilib | |
download | alpine-094ca96844842928810f14844413109fc6cdd890.tar.xz |
Initial Alpine Version
Diffstat (limited to 'imap/src/ansilib')
-rw-r--r-- | imap/src/ansilib/memmove.c | 40 | ||||
-rw-r--r-- | imap/src/ansilib/memmove2.c | 49 | ||||
-rw-r--r-- | imap/src/ansilib/memset.c | 40 | ||||
-rw-r--r-- | imap/src/ansilib/strpbrk.c | 40 | ||||
-rw-r--r-- | imap/src/ansilib/strstr.c | 45 | ||||
-rw-r--r-- | imap/src/ansilib/strtok.c | 67 | ||||
-rw-r--r-- | imap/src/ansilib/strtoul.c | 73 |
7 files changed, 354 insertions, 0 deletions
diff --git a/imap/src/ansilib/memmove.c b/imap/src/ansilib/memmove.c new file mode 100644 index 00000000..85453bd0 --- /dev/null +++ b/imap/src/ansilib/memmove.c @@ -0,0 +1,40 @@ +/* ======================================================================== + * Copyright 1988-2006 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: Memory move + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 1 August 1988 + * Last Edited: 30 August 2006 + */ + +/* Copy memory block + * Accepts: destination pointer + * source pointer + * length + * Returns: destination pointer + */ + +void *memmove (void *s,void *ct,size_t n) +{ + bcopy (ct,s,n); /* they should have this one */ + return s; +} diff --git a/imap/src/ansilib/memmove2.c b/imap/src/ansilib/memmove2.c new file mode 100644 index 00000000..52532e21 --- /dev/null +++ b/imap/src/ansilib/memmove2.c @@ -0,0 +1,49 @@ +/* ======================================================================== + * Copyright 1988-2006 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: Memory move when no bcopy() + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 11 May 1989 + * Last Edited: 30 August 2006 + */ + +/* Copy memory block + * Accepts: destination pointer + * source pointer + * length + * Returns: destination pointer + */ + +void *memmove (void *s,void *ct,size_t n) +{ + char *dp,*sp; + int i; + unsigned long dest = (unsigned long) s; + unsigned long src = (unsigned long) ct; + if (((dest < src) && ((dest + n) < src)) || + ((dest > src) && ((src + n) < dest))) return (void *) memcpy (s,ct,n); + dp = (char *) s; + sp = (char *) ct; + if (dest < src) for (i = 0; i < n; ++i) dp[i] = sp[i]; + else if (dest > src) for (i = n - 1; i >= 0; --i) dp[i] = sp[i]; + return s; +} diff --git a/imap/src/ansilib/memset.c b/imap/src/ansilib/memset.c new file mode 100644 index 00000000..fce66806 --- /dev/null +++ b/imap/src/ansilib/memset.c @@ -0,0 +1,40 @@ +/* ======================================================================== + * Copyright 1988-2006 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: Set memory + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * + * Date: 11 May 1989 + * Last Edited: 30 August 2006 + */ + +/* Set a block of memory + * Accepts: destination pointer + * value to set + * length + * Returns: destination pointer + */ + +void *memset (void *s,int c,size_t n) +{ + if (c) while (n) s[--n] = c; /* this way if non-zero */ + else bzero (s,n); /* they should have this one */ + return s; +} diff --git a/imap/src/ansilib/strpbrk.c b/imap/src/ansilib/strpbrk.c new file mode 100644 index 00000000..d63f7627 --- /dev/null +++ b/imap/src/ansilib/strpbrk.c @@ -0,0 +1,40 @@ +/* ======================================================================== + * Copyright 1988-2006 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: String search for break character + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * + * Date: 11 May 1989 + * Last Edited: 30 August 2006 + */ + +/* Return pointer to first occurance in string of any delimiter + * Accepts: source pointer + * vector of delimiters pointer + * Returns: pointer to delimiter or NIL if not found + */ + +char *strpbrk (char *cs,char *ct) +{ + char *s; + /* search for delimiter until end of string */ + for (; *cs; cs++) for (s = ct; *s; s++) if (*s == *cs) return cs; + return NIL; /* not found */ +} diff --git a/imap/src/ansilib/strstr.c b/imap/src/ansilib/strstr.c new file mode 100644 index 00000000..5c02569a --- /dev/null +++ b/imap/src/ansilib/strstr.c @@ -0,0 +1,45 @@ +/* ======================================================================== + * Copyright 1988-2006 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: Substring search + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * + * Date: 11 May 1989 + * Last Edited: 30 August 2006 + */ + +/* Return pointer to first occurance in string of a substring + * Accepts: source pointer + * substring pointer + * Returns: pointer to substring in source or NIL if not found + */ + +char *strstr (char *cs,char *ct) +{ + char *s; + char *t; + while (cs = strchr (cs,*ct)) {/* for each occurance of the first character */ + /* see if remainder of string matches */ + for (s = cs + 1, t = ct + 1; *t && *s == *t; s++, t++); + if (!*t) return cs; /* if ran out of substring then have match */ + cs++; /* try from next character */ + } + return NIL; /* not found */ +} diff --git a/imap/src/ansilib/strtok.c b/imap/src/ansilib/strtok.c new file mode 100644 index 00000000..973ba4e7 --- /dev/null +++ b/imap/src/ansilib/strtok.c @@ -0,0 +1,67 @@ +/* ======================================================================== + * Copyright 1988-2007 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: String return successive tokens + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * + * Date: 11 May 1989 + * Last Edited: 30 January 2007 + */ + +/* Find token in string + * Accepts: source pointer or NIL to use previous source + * vector of token delimiters pointer + * Returns: pointer to next token + */ + +static char *state = NIL; /* string to locate tokens */ + +char *strtok (char *s,char *ct) +{ + return strtok_r (s,ct,&state);/* jacket into reentrant routine */ +} + + +/* Find token in string (reentrant) + * Accepts: source pointer or NIL to use previous source + * vector of token delimiters pointer + * returned state pointer + * Returns: pointer to next token + */ + +char *strtok_r (char *s,char *ct,char **r) +{ + char *t,*ts; + if (!s) s = *r; /* use previous token if none specified */ + *r = NIL; /* default to no returned state */ + if (!(s && *s)) return NIL; /* no tokens left */ + /* find any leading delimiters */ + do for (t = ct, ts = NIL; *t; t++) if (*t == *s) { + if (*(ts = ++s)) break; /* yes, restart search if more in string */ + return NIL; /* else no more tokens */ + } while (ts); /* continue until no more leading delimiters */ + /* can we find a new delimiter? */ + for (ts = s; *ts; ts++) for (t = ct; *t; t++) if (*t == *ts) { + *ts++ = '\0'; /* yes, tie off token at that point */ + *r = ts; /* save subsequent tokens for future call */ + return s; /* return our token */ + } + return s; /* return final token */ +} diff --git a/imap/src/ansilib/strtoul.c b/imap/src/ansilib/strtoul.c new file mode 100644 index 00000000..0646b637 --- /dev/null +++ b/imap/src/ansilib/strtoul.c @@ -0,0 +1,73 @@ +/* ======================================================================== + * Copyright 1988-2006 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * + * ======================================================================== + */ + +/* + * Program: String to unsigned long + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * + * Date: 14 February 1995 + * Last Edited: 30 August 2006 + */ + +/* + * Turn a string unsigned long into the real thing + * Accepts: source string + * pointer to place to return end pointer + * base + * Returns: parsed unsigned long integer, end pointer is updated + */ + +unsigned long strtoul (char *t,char **endp,int base) +{ + unsigned long value = 0; /* the accumulated value */ + int negative = 0; /* this a negative number? */ + unsigned char c,*s = t; + if (base && (base < 2 || base > 36)) { + errno = EINVAL; /* insist upon valid base */ + return value; + } + while (isspace (*s)) s++; /* skip leading whitespace */ + switch (*s) { /* check for leading sign char */ + case '-': + negative = 1; /* yes, negative #. fall into '+' */ + case '+': + s++; /* skip the sign character */ + } + if (!base) { /* base not specified? */ + if (*s != '0') base = 10; /* must be decimal if doesn't start with 0 */ + /* starts with 0x? */ + else if (tolower (*++s) == 'x') { + base = 16; /* yes, is hex */ + s++; /* skip the x */ + } + else base = 8; /* ...or octal */ + } + do { /* convert to numeric form if digit */ + if (isdigit (*s)) c = *s - '0'; + /* alphabetic conversion */ + else if (isalpha (*s)) c = *s - (isupper (*s) ? 'A' : 'a') + 10; + else break; /* else no way it's valid */ + if (c >= base) break; /* digit out of range for base? */ + value = value * base + c; /* accumulate the digit */ + } while (*++s); /* loop until non-numeric character */ + if (tolower (*s) == 'l') s++; /* ignore 'l' or 'L' marker */ + if (endp) *endp = s; /* save users endp to after number */ + /* negate number if needed */ + return negative ? -value : value; +} |