From 50a6ca39ad4ed01922aa4f755f0ca579788226cf Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 6 May 2010 21:04:40 +0000 Subject: Move c/h files implementing/defining standard library stuff into a new libc directory, also standard'ify some parts of the code base (almost entirely #include fixes). This is to a) to cleanup firmware/common and firmware/include a bit, but also b) for Rockbox as an application which should use the host system's c library and headers, separating makes it easy to exclude our files from the build. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25850 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/atoi.c | 57 --------- firmware/common/config.c | 28 +++++ firmware/common/ctype.c | 22 ---- firmware/common/dircache.c | 2 +- firmware/common/errno.c | 1 - firmware/common/format.c | 227 +++++++++++++++++++++++++++++++++ firmware/common/memchr.c | 116 ----------------- firmware/common/memcmp.c | 113 ----------------- firmware/common/memcpy.c | 117 ----------------- firmware/common/memmove.c | 147 ---------------------- firmware/common/memset.c | 109 ---------------- firmware/common/qsort.c | 222 -------------------------------- firmware/common/random.c | 119 ------------------ firmware/common/sprintf.c | 299 -------------------------------------------- firmware/common/sscanf.c | 282 ----------------------------------------- firmware/common/strcat.c | 14 --- firmware/common/strchr.c | 108 ---------------- firmware/common/strcmp.c | 106 ---------------- firmware/common/strcpy.c | 99 --------------- firmware/common/strlcat.c | 1 - firmware/common/strlcpy.c | 1 - firmware/common/strlen.c | 93 -------------- firmware/common/strncmp.c | 122 ------------------ firmware/common/strrchr.c | 59 --------- firmware/common/strstr.c | 38 ------ firmware/common/strtok.c | 63 ---------- firmware/common/timefuncs.c | 37 ------ 27 files changed, 256 insertions(+), 2346 deletions(-) delete mode 100644 firmware/common/atoi.c create mode 100644 firmware/common/config.c delete mode 100644 firmware/common/ctype.c delete mode 100644 firmware/common/errno.c create mode 100644 firmware/common/format.c delete mode 100644 firmware/common/memchr.c delete mode 100644 firmware/common/memcmp.c delete mode 100644 firmware/common/memcpy.c delete mode 100644 firmware/common/memmove.c delete mode 100644 firmware/common/memset.c delete mode 100644 firmware/common/qsort.c delete mode 100644 firmware/common/random.c delete mode 100644 firmware/common/sprintf.c delete mode 100644 firmware/common/sscanf.c delete mode 100644 firmware/common/strcat.c delete mode 100644 firmware/common/strchr.c delete mode 100644 firmware/common/strcmp.c delete mode 100644 firmware/common/strcpy.c delete mode 100644 firmware/common/strlen.c delete mode 100644 firmware/common/strncmp.c delete mode 100644 firmware/common/strrchr.c delete mode 100644 firmware/common/strstr.c delete mode 100644 firmware/common/strtok.c (limited to 'firmware/common') diff --git a/firmware/common/atoi.c b/firmware/common/atoi.c deleted file mode 100644 index 3393839b27..0000000000 --- a/firmware/common/atoi.c +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Gary Czvitkovicz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include -#include "ctype.h" - -int atoi (const char *str) -{ - int value = 0; - int sign = 1; - - while (isspace(*str)) - { - str++; - } - - if ('-' == *str) - { - sign = -1; - str++; - } - else if ('+' == *str) - { - str++; - } - - while ('0' == *str) - { - str++; - } - - while (isdigit(*str)) - { - value = (value * 10) + (*str - '0'); - str++; - } - - return value * sign; -} diff --git a/firmware/common/config.c b/firmware/common/config.c new file mode 100644 index 0000000000..5245d34135 --- /dev/null +++ b/firmware/common/config.c @@ -0,0 +1,28 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +/** + * This file is only there to depend on config.h. + * Use this if non-C stuff depends on config.h (e.g. language generation) + * See apps/apps.make + **/ +#include "config.h" diff --git a/firmware/common/ctype.c b/firmware/common/ctype.c deleted file mode 100644 index 6e9b4eb601..0000000000 --- a/firmware/common/ctype.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -const unsigned char _ctype_[257]={ - 0, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _S|_B, _P, _P, _P, _P, _P, _P, _P, - _P, _P, _P, _P, _P, _P, _P, _P, - _N, _N, _N, _N, _N, _N, _N, _N, - _N, _N, _P, _P, _P, _P, _P, _P, - _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _P, _P, _P, _P, _P, - _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _P, _P, _P, _P, _C -}; - diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 225ed1aff1..e642296a35 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -27,7 +27,7 @@ #include #include -#include +#include "string-extra.h" #include #include #include "debug.h" diff --git a/firmware/common/errno.c b/firmware/common/errno.c deleted file mode 100644 index 6e7bb62b51..0000000000 --- a/firmware/common/errno.c +++ /dev/null @@ -1 +0,0 @@ -int errno; diff --git a/firmware/common/format.c b/firmware/common/format.c new file mode 100644 index 0000000000..987af417da --- /dev/null +++ b/firmware/common/format.c @@ -0,0 +1,227 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Gary Czvitkovicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#include +#include +#include +#include +#include "file.h" + +static const char hexdigit[] = "0123456789ABCDEF"; + +int format( + /* call 'push()' for each output letter */ + int (*push)(void *userp, unsigned char data), + void *userp, + const char *fmt, + va_list ap) +{ + char *str; + char tmpbuf[12], pad; + int ch, width, val, sign, precision; + long lval, lsign; + unsigned int uval; + unsigned long ulval; + bool ok = true; + + tmpbuf[sizeof tmpbuf - 1] = '\0'; + + while ((ch = *fmt++) != '\0' && ok) + { + if (ch == '%') + { + ch = *fmt++; + pad = ' '; + if (ch == '0') + pad = '0'; + + width = 0; + while (ch >= '0' && ch <= '9') + { + width = 10*width + ch - '0'; + ch = *fmt++; + } + + precision = 0; + if(ch == '.') + { + ch = *fmt++; + while (ch >= '0' && ch <= '9') + { + precision = 10*precision + ch - '0'; + ch = *fmt++; + } + } else { + precision = INT_MAX; + } + + str = tmpbuf + sizeof tmpbuf - 1; + switch (ch) + { + case 'c': + *--str = va_arg (ap, int); + break; + + case 's': + str = va_arg (ap, char*); + break; + + case 'd': + val = sign = va_arg (ap, int); + if (val < 0) + val = -val; + do + { + *--str = (val % 10) + '0'; + val /= 10; + } + while (val > 0); + if (sign < 0) + *--str = '-'; + break; + + case 'u': + uval = va_arg(ap, unsigned int); + do + { + *--str = (uval % 10) + '0'; + uval /= 10; + } + while (uval > 0); + break; + + case 'x': + case 'X': + pad='0'; + uval = va_arg (ap, int); + do + { + *--str = hexdigit[uval & 0xf]; + uval >>= 4; + } + while (uval); + break; + + case 'l': + ch = *fmt++; + switch(ch) { + case 'x': + case 'X': + pad='0'; + ulval = va_arg (ap, long); + do + { + *--str = hexdigit[ulval & 0xf]; + ulval >>= 4; + } + while (ulval); + break; + case 'd': + lval = lsign = va_arg (ap, long); + if (lval < 0) + lval = -lval; + do + { + *--str = (lval % 10) + '0'; + lval /= 10; + } + while (lval > 0); + if (lsign < 0) + *--str = '-'; + break; + + case 'u': + ulval = va_arg(ap, unsigned long); + do + { + *--str = (ulval % 10) + '0'; + ulval /= 10; + } + while (ulval > 0); + break; + + default: + *--str = 'l'; + *--str = ch; + } + + break; + + default: + *--str = ch; + break; + } + + if (width > 0) + { + width -= strlen (str); + while (width-- > 0 && ok) + ok=push(userp, pad); + } + while (*str != '\0' && ok && precision--) + ok=push(userp, *str++); + } + else + ok=push(userp, ch); + } + return ok; /* true means good */ +} + +struct for_fprintf { + int fd; /* where to store it */ + int bytes; /* amount stored */ +}; + +static int fprfunc(void *pr, unsigned char letter) +{ + struct for_fprintf *fpr = (struct for_fprintf *)pr; + int rc = write(fpr->fd, &letter, 1); + + if(rc > 0) { + fpr->bytes++; /* count them */ + return true; /* we are ok */ + } + + return false; /* failure */ +} + + +int fdprintf(int fd, const char *fmt, ...) +{ + bool ok; + va_list ap; + struct for_fprintf fpr; + + fpr.fd=fd; + fpr.bytes=0; + + va_start(ap, fmt); + ok = format(fprfunc, &fpr, fmt, ap); + va_end(ap); + + return fpr.bytes; /* return 0 on error */ +} + +int vuprintf(int (*push)(void *userp, unsigned char data), void *userp, const char *fmt, va_list ap) +{ + return format(push, userp, fmt, ap); +} diff --git a/firmware/common/memchr.c b/firmware/common/memchr.c deleted file mode 100644 index 26bdb9eea3..0000000000 --- a/firmware/common/memchr.c +++ /dev/null @@ -1,116 +0,0 @@ -/* -FUNCTION - <>---search for character in memory - -INDEX - memchr - -ANSI_SYNOPSIS - #include - void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>); - -TRAD_SYNOPSIS - #include - void * memchr(<[s1]>, <[c]>, <[n]>); - void *<[string]>; - int *<[c]>; - size_t *<[n]>; - -DESCRIPTION - This function scans the first <[n]> bytes of the memory pointed - to by <[s1]> for the character <[c]> (converted to a char). - -RETURNS - Returns a pointer to the matching byte, or a null pointer if - <[c]> does not occur in <[s1]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memchr ansi pure -*/ - -#include -#include - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) - -void * -_DEFUN (memchr, (s1, i, n), - _CONST void *s1 _AND - int i _AND size_t n) -{ - _CONST unsigned char *s = (_CONST unsigned char *)s1; -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char c = (unsigned char)i; - - while (n-- > 0) - { - if (*s == c) - { - return (void *)s; - } - s++; - } - - return NULL; -#else - unsigned char c = (unsigned char)i; - unsigned long mask,j; - unsigned long *aligned_addr; - - if (!UNALIGNED (s)) - { - mask = 0; - for (j = 0; j < LBLOCKSIZE; j++) - mask = (mask << 8) | c; - - aligned_addr = (unsigned long*)s; - while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE)) - { - aligned_addr++; - n -= LBLOCKSIZE; - } - - /* The block of bytes currently pointed to by aligned_addr - may contain the target character or there may be less than - LBLOCKSIZE bytes left to search. We check the last few - bytes using the bytewise search. */ - - s = (unsigned char*)aligned_addr; - } - - while (n-- > 0) - { - if (*s == c) - { - return (void *)s; - } - s++; - } - - return NULL; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/memcmp.c b/firmware/common/memcmp.c deleted file mode 100644 index 1535fcf5b5..0000000000 --- a/firmware/common/memcmp.c +++ /dev/null @@ -1,113 +0,0 @@ -/* -FUNCTION - <>---compare two memory areas - -INDEX - memcmp - -ANSI_SYNOPSIS - #include - int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); - -TRAD_SYNOPSIS - #include - int memcmp(<[s1]>, <[s2]>, <[n]>) - void *<[s1]>; - void *<[s2]>; - size_t <[n]>; - -DESCRIPTION - This function compares not more than <[n]> characters of the - object pointed to by <[s1]> with the object pointed to by <[s2]>. - - -RETURNS - The function returns an integer greater than, equal to or - less than zero according to whether the object pointed to by - <[s1]> is greater than, equal to or less than the object - pointed to by <[s2]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memcmp ansi pure -*/ - -#include - - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -int -_DEFUN (memcmp, (m1, m2, n), - _CONST _PTR m1 _AND - _CONST _PTR m2 _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char *s1 = (unsigned char *) m1; - unsigned char *s2 = (unsigned char *) m2; - - while (n--) - { - if (*s1 != *s2) - { - return *s1 - *s2; - } - s1++; - s2++; - } - return 0; -#else - unsigned char *s1 = (unsigned char *) m1; - unsigned char *s2 = (unsigned char *) m2; - unsigned long *a1; - unsigned long *a2; - - /* If the size is too small, or either pointer is unaligned, - then we punt to the byte compare loop. Hopefully this will - not turn up in inner loops. */ - if (!TOO_SMALL(n) && !UNALIGNED(s1,s2)) - { - /* Otherwise, load and compare the blocks of memory one - word at a time. */ - a1 = (unsigned long*) s1; - a2 = (unsigned long*) s2; - while (n >= LBLOCKSIZE) - { - if (*a1 != *a2) - break; - a1++; - a2++; - n -= LBLOCKSIZE; - } - - /* check m mod LBLOCKSIZE remaining characters */ - - s1 = (unsigned char*)a1; - s2 = (unsigned char*)a2; - } - - while (n--) - { - if (*s1 != *s2) - return *s1 - *s2; - s1++; - s2++; - } - - return 0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} - diff --git a/firmware/common/memcpy.c b/firmware/common/memcpy.c deleted file mode 100644 index a89ac3c557..0000000000 --- a/firmware/common/memcpy.c +++ /dev/null @@ -1,117 +0,0 @@ -/* -FUNCTION - <>---copy memory regions - -ANSI_SYNOPSIS - #include - void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); - -TRAD_SYNOPSIS - void *memcpy(<[out]>, <[in]>, <[n]> - void *<[out]>; - void *<[in]>; - size_t <[n]>; - -DESCRIPTION - This function copies <[n]> bytes from the memory region - pointed to by <[in]> to the memory region pointed to by - <[out]>. - - If the regions overlap, the behavior is undefined. - -RETURNS - <> returns a pointer to the first byte of the <[out]> - region. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memcpy ansi pure - */ - -#include "config.h" -#include <_ansi.h> -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - -_PTR -_DEFUN (memcpy, (dst0, src0, len0), - _PTR dst0 _AND - _CONST _PTR src0 _AND - size_t len0) ICODE_ATTR; - -_PTR -_DEFUN (memcpy, (dst0, src0, len0), - _PTR dst0 _AND - _CONST _PTR src0 _AND - size_t len0) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dst = (char *) dst0; - char *src = (char *) src0; - - _PTR save = dst0; - - while (len0--) - { - *dst++ = *src++; - } - - return save; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - unsigned int len = len0; - - /* If the size is small, or either SRC or DST is unaligned, - then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* Copy 4X long words at a time if possible. */ - while (len >= BIGBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - len -= (unsigned int)BIGBLOCKSIZE; - } - - /* Copy one long word at a time if possible. */ - while (len >= LITTLEBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - len -= LITTLEBLOCKSIZE; - } - - /* Pick up any residual with a byte copier. */ - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (len--) - *dst++ = *src++; - - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/memmove.c b/firmware/common/memmove.c deleted file mode 100644 index 5f423964bb..0000000000 --- a/firmware/common/memmove.c +++ /dev/null @@ -1,147 +0,0 @@ -/* -FUNCTION - <>---move possibly overlapping memory - -INDEX - memmove - -ANSI_SYNOPSIS - #include - void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - void *memmove(<[dst]>, <[src]>, <[length]>) - void *<[dst]>; - void *<[src]>; - size_t <[length]>; - -DESCRIPTION - This function moves <[length]> characters from the block of - memory starting at <<*<[src]>>> to the memory starting at - <<*<[dst]>>>. <> reproduces the characters correctly - at <<*<[dst]>>> even if the two areas overlap. - - -RETURNS - The function returns <[dst]> as passed. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memmove ansi pure -*/ - -#include "config.h" -#include <_ansi.h> -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - -_PTR -_DEFUN (memmove, (dst_void, src_void, length), - _PTR dst_void _AND - _CONST _PTR src_void _AND - size_t length) ICODE_ATTR; - -_PTR -_DEFUN (memmove, (dst_void, src_void, length), - _PTR dst_void _AND - _CONST _PTR src_void _AND - size_t length) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dst = dst_void; - _CONST char *src = src_void; - - if (src < dst && dst < src + length) - { - /* Have to copy backwards */ - src += length; - dst += length; - while (length--) - { - *--dst = *--src; - } - } - else - { - while (length--) - { - *dst++ = *src++; - } - } - - return dst_void; -#else - char *dst = dst_void; - _CONST char *src = src_void; - long *aligned_dst; - _CONST long *aligned_src; - unsigned int len = length; - - if (src < dst && dst < src + len) - { - /* Destructive overlap...have to copy backwards */ - src += len; - dst += len; - while (len--) - { - *--dst = *--src; - } - } - else - { - /* Use optimizing algorithm for a non-destructive copy to closely - match memcpy. If the size is small or either SRC or DST is unaligned, - then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* Copy 4X long words at a time if possible. */ - while (len >= BIGBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - len -= BIGBLOCKSIZE; - } - - /* Copy one long word at a time if possible. */ - while (len >= LITTLEBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - len -= LITTLEBLOCKSIZE; - } - - /* Pick up any residual with a byte copier. */ - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (len--) - { - *dst++ = *src++; - } - } - - return dst_void; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/memset.c b/firmware/common/memset.c deleted file mode 100644 index 6c4a66bf13..0000000000 --- a/firmware/common/memset.c +++ /dev/null @@ -1,109 +0,0 @@ -/* -FUNCTION - <>---set an area of memory - -INDEX - memset - -ANSI_SYNOPSIS - #include - void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - void *memset(<[dst]>, <[c]>, <[length]>) - void *<[dst]>; - int <[c]>; - size_t <[length]>; - -DESCRIPTION - This function converts the argument <[c]> into an unsigned - char and fills the first <[length]> characters of the array - pointed to by <[dst]> to the value. - -RETURNS - <> returns the value of <[m]>. - -PORTABILITY -<> is ANSI C. - - <> requires no supporting OS subroutines. - -QUICKREF - memset ansi pure -*/ - -#include - -#define LBLOCKSIZE (sizeof(long)) -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -_PTR -_DEFUN (memset, (m, c, n), - _PTR m _AND - int c _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *s = (char *) m; - - while (n-- != 0) - { - *s++ = (char) c; - } - - return m; -#else - char *s = (char *) m; - unsigned int i; - unsigned long buffer; - unsigned long *aligned_addr; - - if (!TOO_SMALL (n) && !UNALIGNED (m)) - { - /* If we get this far, we know that n is large and m is word-aligned. */ - - aligned_addr = (unsigned long*)m; - - /* Store C into each char sized location in BUFFER so that - we can set large blocks quickly. */ - c &= 0xff; - if (LBLOCKSIZE == 4) - { - buffer = (c << 8) | c; - buffer |= (buffer << 16); - } - else - { - buffer = 0; - for (i = 0; i < LBLOCKSIZE; i++) - buffer = (buffer << 8) | c; - } - - while (n >= LBLOCKSIZE*4) - { - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - *aligned_addr++ = buffer; - n -= 4*LBLOCKSIZE; - } - - while (n >= LBLOCKSIZE) - { - *aligned_addr++ = buffer; - n -= LBLOCKSIZE; - } - /* Pick up the remainder with a bytewise loop. */ - s = (char*)aligned_addr; - } - - while (n--) - { - *s++ = (char)c; - } - - return m; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/qsort.c b/firmware/common/qsort.c deleted file mode 100644 index 8c4d1ad511..0000000000 --- a/firmware/common/qsort.c +++ /dev/null @@ -1,222 +0,0 @@ -/* -FUNCTION -<>---sort an array - -INDEX - qsort - -ANSI_SYNOPSIS - #include - void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, - int (*<[compar]>)(const void *, const void *) ); - -TRAD_SYNOPSIS - #include - qsort(<[base]>, <[nmemb]>, <[size]>, <[compar]> ) - char *<[base]>; - size_t <[nmemb]>; - size_t <[size]>; - int (*<[compar]>)(); - -DESCRIPTION -<> sorts an array (beginning at <[base]>) of <[nmemb]> objects. -<[size]> describes the size of each element of the array. - -You must supply a pointer to a comparison function, using the argument -shown as <[compar]>. (This permits sorting objects of unknown -properties.) Define the comparison function to accept two arguments, -each a pointer to an element of the array starting at <[base]>. The -result of <<(*<[compar]>)>> must be negative if the first argument is -less than the second, zero if the two arguments match, and positive if -the first argument is greater than the second (where ``less than'' and -``greater than'' refer to whatever arbitrary ordering is appropriate). - -The array is sorted in place; that is, when <> returns, the -array elements beginning at <[base]> have been reordered. - -RETURNS -<> does not return a result. - -PORTABILITY -<> is required by ANSI (without specifying the sorting algorithm). -*/ - -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <_ansi.h> -#include - -#ifndef __GNUC__ -#define inline -#endif - -static inline char *med3 _PARAMS((char *, char *, char *, int (*cmp)(const _PTR,const _PTR))); -static inline void swapfunc _PARAMS((char *, char *, int, int)); - -#define min(a, b) (a) < (b) ? a : b - -/* - * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". - */ -#define swapcode(TYPE, parmi, parmj, n) { \ - long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ - do { \ - register TYPE t = *pi; \ - *pi++ = *pj; \ - *pj++ = t; \ - } while (--i > 0); \ -} - -#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; - -static inline void -_DEFUN(swapfunc, (a, b, n, swaptype), - char *a _AND - char *b _AND - int n _AND - int swaptype) -{ - if(swaptype <= 1) - swapcode(long, a, b, n) - else - swapcode(char, a, b, n) -} - -#define swap(a, b) \ - if (swaptype == 0) { \ - long t = *(long *)(a); \ - *(long *)(a) = *(long *)(b); \ - *(long *)(b) = t; \ - } else \ - swapfunc(a, b, es, swaptype) - -#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) - -static inline char * -_DEFUN(med3, (a, b, c, cmp), - char *a _AND - char *b _AND - char *c _AND - int (*cmp)(const _PTR,const _PTR)) -{ - return cmp(a, b) < 0 ? - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); -} - -void -_DEFUN(qsort, (a, n, es, cmp), - void *a _AND - size_t n _AND - size_t es _AND - int (*cmp)(const _PTR,const _PTR)) -{ - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; - -loop: SWAPINIT(a, es); - swap_cnt = 0; - if (n < 7) { - for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - pm = (char *) a + (n / 2) * es; - if (n > 7) { - pl = a; - pn = (char *) a + (n - 1) * es; - if (n > 40) { - d = (n / 8) * es; - pl = med3(pl, pl + d, pl + 2 * d, cmp); - pm = med3(pm - d, pm, pm + d, cmp); - pn = med3(pn - 2 * d, pn - d, pn, cmp); - } - pm = med3(pl, pm, pn, cmp); - } - swap(a, pm); - pa = pb = (char *) a + es; - - pc = pd = (char *) a + (n - 1) * es; - for (;;) { - while (pb <= pc && (r = cmp(pb, a)) <= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pa, pb); - pa += es; - } - pb += es; - } - while (pb <= pc && (r = cmp(pc, a)) >= 0) { - if (r == 0) { - swap_cnt = 1; - swap(pc, pd); - pd -= es; - } - pc -= es; - } - if (pb > pc) - break; - swap(pb, pc); - swap_cnt = 1; - pb += es; - pc -= es; - } - if (swap_cnt == 0) { /* Switch to insertion sort */ - for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); - return; - } - - pn = (char *) a + n * es; - r = min(pa - (char *)a, pb - pa); - vecswap(a, pb - r, r); - r = min((unsigned int)(pd - pc), pn - pd - es); - vecswap(pb, pn - r, r); - if ((unsigned int)(r = pb - pa) > es) - qsort(a, r / es, es, cmp); - if ((unsigned int)(r = pd - pc) > es) { - /* Iterate rather than recurse to save stack space */ - a = pn - r; - n = r / es; - goto loop; - } -/* qsort(pn - r, r / es, es, cmp);*/ -} diff --git a/firmware/common/random.c b/firmware/common/random.c deleted file mode 100644 index f3efe89351..0000000000 --- a/firmware/common/random.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - A C-program for MT19937, with initialization improved 2002/2/10. - Coded by Takuji Nishimura and Makoto Matsumoto. - This is a faster version by taking Shawn Cokus's optimization, - Matthe Bellew's simplification. - - Before using, initialize the state by using srand(seed). - - Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Any feedback is very welcome. - http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html - email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) -*/ - -/* - Adapted to Rockbox by Jens Arnold -*/ - -#include - -/* Period parameters */ -#define N 624 -#define M 397 -#define MATRIX_A 0x9908b0dfUL /* constant vector a */ -#define UMASK 0x80000000UL /* most significant w-r bits */ -#define LMASK 0x7fffffffUL /* least significant r bits */ -#define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) ) -#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL)) - -static unsigned long state[N]; /* the array for the state vector */ -static int left = 0; -static unsigned long *next; - -/* initializes state[N] with a seed */ -void srand(unsigned int seed) -{ - unsigned long x = seed & 0xffffffffUL; - unsigned long *s = state; - int j; - - for (*s++ = x, j = 1; j < N; j++) { - x = (1812433253UL * (x ^ (x >> 30)) + j) & 0xffffffffUL; - *s++ = x; - /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ - /* In the previous versions, MSBs of the seed affect */ - /* only MSBs of the array state[]. */ - /* 2002/01/09 modified by Makoto Matsumoto */ - } - left = 1; -} - -static void next_state(void) -{ - unsigned long *p = state; - int j; - - /* if srand() has not been called, */ - /* a default initial seed is used */ - if (left < 0) - srand(5489UL); - - left = N; - next = state; - - for (j = N - M + 1; --j; p++) - *p = p[M] ^ TWIST(p[0], p[1]); - - for (j = M; --j; p++) - *p = p[M-N] ^ TWIST(p[0], p[1]); - - *p = p[M-N] ^ TWIST(p[0], state[0]); -} - -/* generates a random number on [0,RAND_MAX]-interval */ -int rand(void) -{ - unsigned long y; - - if (--left <= 0) - next_state(); - y = *next++; - - /* Tempering */ - y ^= (y >> 11); - y ^= (y << 7) & 0x9d2c5680UL; - y ^= (y << 15) & 0xefc60000UL; - y ^= (y >> 18); - - return ((unsigned int)y) >> 1; -} diff --git a/firmware/common/sprintf.c b/firmware/common/sprintf.c deleted file mode 100644 index 35f977a0a3..0000000000 --- a/firmware/common/sprintf.c +++ /dev/null @@ -1,299 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Gary Czvitkovicz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -/* - * Minimal printf and snprintf formatting functions - * - * These support %c %s %d and %x - * Field width and zero-padding flag only - */ - -#include -#include -#include -#include - -#include "file.h" /* for write(), used in fprintf() */ -#include "sprintf.h" /* to allow the simulator magic */ - -static const char hexdigit[] = "0123456789ABCDEF"; - -static int format( - /* call 'push()' for each output letter */ - int (*push)(void *userp, unsigned char data), - void *userp, - const char *fmt, - va_list ap) -{ - char *str; - char tmpbuf[12], pad; - int ch, width, val, sign, precision; - long lval, lsign; - unsigned int uval; - unsigned long ulval; - bool ok = true; - - tmpbuf[sizeof tmpbuf - 1] = '\0'; - - while ((ch = *fmt++) != '\0' && ok) - { - if (ch == '%') - { - ch = *fmt++; - pad = ' '; - if (ch == '0') - pad = '0'; - - width = 0; - while (ch >= '0' && ch <= '9') - { - width = 10*width + ch - '0'; - ch = *fmt++; - } - - precision = 0; - if(ch == '.') - { - ch = *fmt++; - while (ch >= '0' && ch <= '9') - { - precision = 10*precision + ch - '0'; - ch = *fmt++; - } - } else { - precision = INT_MAX; - } - - str = tmpbuf + sizeof tmpbuf - 1; - switch (ch) - { - case 'c': - *--str = va_arg (ap, int); - break; - - case 's': - str = va_arg (ap, char*); - break; - - case 'd': - val = sign = va_arg (ap, int); - if (val < 0) - val = -val; - do - { - *--str = (val % 10) + '0'; - val /= 10; - } - while (val > 0); - if (sign < 0) - *--str = '-'; - break; - - case 'u': - uval = va_arg(ap, unsigned int); - do - { - *--str = (uval % 10) + '0'; - uval /= 10; - } - while (uval > 0); - break; - - case 'x': - case 'X': - pad='0'; - uval = va_arg (ap, int); - do - { - *--str = hexdigit[uval & 0xf]; - uval >>= 4; - } - while (uval); - break; - - case 'l': - ch = *fmt++; - switch(ch) { - case 'x': - case 'X': - pad='0'; - ulval = va_arg (ap, long); - do - { - *--str = hexdigit[ulval & 0xf]; - ulval >>= 4; - } - while (ulval); - break; - case 'd': - lval = lsign = va_arg (ap, long); - if (lval < 0) - lval = -lval; - do - { - *--str = (lval % 10) + '0'; - lval /= 10; - } - while (lval > 0); - if (lsign < 0) - *--str = '-'; - break; - - case 'u': - ulval = va_arg(ap, unsigned long); - do - { - *--str = (ulval % 10) + '0'; - ulval /= 10; - } - while (ulval > 0); - break; - - default: - *--str = 'l'; - *--str = ch; - } - - break; - - default: - *--str = ch; - break; - } - - if (width > 0) - { - width -= strlen (str); - while (width-- > 0 && ok) - ok=push(userp, pad); - } - while (*str != '\0' && ok && precision--) - ok=push(userp, *str++); - } - else - ok=push(userp, ch); - } - return ok; /* true means good */ -} - -#if !defined(SIMULATOR) || !defined(linux) -/* ALSA library requires a more advanced snprintf, so let's not - override it in simulator for Linux. Note that Cygwin requires - our snprintf or it produces garbled output after a while. */ - -struct for_snprintf { - unsigned char *ptr; /* where to store it */ - int bytes; /* amount already stored */ - int max; /* max amount to store */ -}; - -static int sprfunc(void *ptr, unsigned char letter) -{ - struct for_snprintf *pr = (struct for_snprintf *)ptr; - if(pr->bytes < pr->max) { - *pr->ptr = letter; - pr->ptr++; - pr->bytes++; - return true; - } - return false; /* filled buffer */ -} - - -int snprintf(char *buf, size_t size, const char *fmt, ...) -{ - bool ok; - va_list ap; - struct for_snprintf pr; - - pr.ptr = (unsigned char *)buf; - pr.bytes = 0; - pr.max = size; - - va_start(ap, fmt); - ok = format(sprfunc, &pr, fmt, ap); - va_end(ap); - - /* make sure it ends with a trailing zero */ - pr.ptr[(pr.bytes < pr.max) ? 0 : -1] = '\0'; - - return pr.bytes; -} - -int vsnprintf(char *buf, int size, const char *fmt, va_list ap) -{ - bool ok; - struct for_snprintf pr; - - pr.ptr = (unsigned char *)buf; - pr.bytes = 0; - pr.max = size; - - ok = format(sprfunc, &pr, fmt, ap); - - /* make sure it ends with a trailing zero */ - pr.ptr[(pr.bytes < pr.max) ? 0 : -1] = '\0'; - - return pr.bytes; -} - -#endif /* Linux SIMULATOR */ - -struct for_fprintf { - int fd; /* where to store it */ - int bytes; /* amount stored */ -}; - -static int fprfunc(void *pr, unsigned char letter) -{ - struct for_fprintf *fpr = (struct for_fprintf *)pr; - int rc = write(fpr->fd, &letter, 1); - - if(rc > 0) { - fpr->bytes++; /* count them */ - return true; /* we are ok */ - } - - return false; /* failure */ -} - - -int fdprintf(int fd, const char *fmt, ...) -{ - bool ok; - va_list ap; - struct for_fprintf fpr; - - fpr.fd=fd; - fpr.bytes=0; - - va_start(ap, fmt); - ok = format(fprfunc, &fpr, fmt, ap); - va_end(ap); - - return fpr.bytes; /* return 0 on error */ -} - -int vuprintf(int (*push)(void *userp, unsigned char data), void *userp, const char *fmt, va_list ap) -{ - return format(push, userp, fmt, ap); -} - diff --git a/firmware/common/sscanf.c b/firmware/common/sscanf.c deleted file mode 100644 index 5fbe81f3e0..0000000000 --- a/firmware/common/sscanf.c +++ /dev/null @@ -1,282 +0,0 @@ -#include -#include -#include - -static inline bool isspace(char c) -{ - return (c == ' ') || (c == '\t') || (c == '\n'); -} - -static inline bool isdigit(char c) -{ - return (c >= '0') && (c <= '9'); -} - -static inline bool isxdigit(char c) -{ - return ((c >= '0') && (c <= '9')) - || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')); -} - -static int parse_dec(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - long *vp) -{ - long v = 0; - int n = 0; - int minus = 0; - char ch; - - if ((*peek)(userp) == '-') - { - (*pop)(userp); - n++; - minus = 1; - } - - ch = (*peek)(userp); - if (!isdigit(ch)) - return -1; - - do - { - v = v * 10 + ch - '0'; - (*pop)(userp); - n++; - ch = (*peek)(userp); - } while (isdigit(ch)); - - *vp = minus ? -v : v; - return n; -} - -static int parse_chars(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - char *vp, - bool fake) -{ - int n = 0; - - char *pt=vp; - - while (!isspace((*peek)(userp))) - { - if(fake==false) - *(pt++) = (*peek)(userp); - - n++; - (*pop)(userp); - } - - if(fake==false) - (*pt)='\0'; - - return n; -} - -static int parse_hex(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - unsigned long *vp) -{ - unsigned long v = 0; - int n = 0; - char ch; - - ch = (*peek)(userp); - if (!isxdigit(ch)) - return -1; - - do - { - if (ch >= 'a') - ch = ch - 'a' + 10; - else if (ch >= 'A') - ch = ch - 'A' + 10; - else - ch = ch - '0'; - v = v * 16 + ch; - (*pop)(userp); - n++; - ch = (*peek)(userp); - } while (isxdigit(ch)); - - *vp = v; - return n; -} - -static int skip_spaces(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp) -{ - int n = 0; - while (isspace((*peek)(userp))) { - n++; - (*pop)(userp); - } - return n; -} - -static int scan(int (*peek)(void *userp), - void (*pop)(void *userp), - void *userp, - const char *fmt, - va_list ap) -{ - char ch; - int n = 0; - int n_chars = 0; - int r; - long lval; - bool skip=false; - unsigned long ulval; - - while ((ch = *fmt++) != '\0') - { - bool literal = false; - - if (ch == '%') - { - ch = *fmt++; - - if(ch== '*') /* We should process this, but not store it in an arguement */ - { - ch=*fmt++; - skip=true; - } - else - { - skip=false; - } - - switch (ch) - { - case 'x': - n_chars += skip_spaces(peek, pop, userp); - if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, unsigned int *)) = ulval; - n++; - } - n_chars += r; - } - else - return n; - break; - case 'd': - n_chars += skip_spaces(peek, pop, userp); - if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, int *)) = lval; - n++; - } - n_chars += r; - } - else - return n; - break; - case 'n': - if(skip==false) - { - *(va_arg(ap, int *)) = n_chars; - n++; - } - break; - case 'l': - n_chars += skip_spaces(peek, pop, userp); - ch = *fmt++; - switch (ch) - { - case 'x': - if ((r = parse_hex(peek, pop, userp, &ulval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, unsigned long *)) = ulval; - n++; - } - n_chars += r; - } - else - return n; - break; - case 'd': - if ((r = parse_dec(peek, pop, userp, &lval)) >= 0) - { - if(skip==false) - { - *(va_arg(ap, long *)) = lval; - n++; - } - n_chars += r; - } - else - return n; - break; - case '\0': - return n; - default: - literal = true; - break; - } - break; - case 's': - n_chars += skip_spaces(peek, pop, userp); - n_chars += parse_chars(peek,pop, userp,skip?0:va_arg(ap, char *), skip ); - if(skip==false) - { - n++; - } - break; - case '\0': - return n; - default: - literal = true; - break; - } - } else - literal = true; - - if (literal) - { - n_chars += skip_spaces(peek, pop, userp); - if ((*peek)(userp) != ch) - continue; - else - { - (*pop)(userp); - n_chars++; - } - } - } - return n; -} - -static int sspeek(void *userp) -{ - return **((char **)userp); -} - -static void sspop(void *userp) -{ - (*((char **)userp))++; -} - -int sscanf(const char *s, const char *fmt, ...) -{ - int r; - va_list ap; - const char *p; - - p = s; - va_start(ap, fmt); - r = scan(sspeek, sspop, &p, fmt, ap); - va_end(ap); - return r; -} diff --git a/firmware/common/strcat.c b/firmware/common/strcat.c deleted file mode 100644 index 221529519c..0000000000 --- a/firmware/common/strcat.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -char *strcat(char *s1, - const char *s2) -{ - char *s = s1; - - while (*s1) - s1++; - - while ((*s1++ = *s2++)) - ; - return s; -} diff --git a/firmware/common/strchr.c b/firmware/common/strchr.c deleted file mode 100644 index 96acf5edf6..0000000000 --- a/firmware/common/strchr.c +++ /dev/null @@ -1,108 +0,0 @@ -/* -FUNCTION - <>---search for character in string - -INDEX - strchr - -ANSI_SYNOPSIS - #include - char * strchr(const char *<[string]>, int <[c]>); - -TRAD_SYNOPSIS - #include - char * strchr(<[string]>, <[c]>); - char *<[string]>; - int *<[c]>; - -DESCRIPTION - This function finds the first occurence of <[c]> (converted to - a char) in the string pointed to by <[string]> (including the - terminating null character). - -RETURNS - Returns a pointer to the located character, or a null pointer - if <[c]> does not occur in <[string]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strchr ansi pure -*/ - -#include -#include - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) - -char * -_DEFUN (strchr, (s1, i), - _CONST char *s1 _AND - int i) -{ - _CONST unsigned char *s = (_CONST unsigned char *)s1; -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - unsigned char c = (unsigned int)i; - - while (*s && *s != c) - { - s++; - } - - if (*s != c) - { - s = NULL; - } - - return (char *) s; -#else - unsigned char c = (unsigned char)i; - unsigned long mask,j; - unsigned long *aligned_addr; - - if (!UNALIGNED (s)) - { - mask = 0; - for (j = 0; j < LBLOCKSIZE; j++) - mask = (mask << 8) | c; - - aligned_addr = (unsigned long*)s; - while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask)) - aligned_addr++; - - /* The block of bytes currently pointed to by aligned_addr - contains either a null or the target char, or both. We - catch it using the bytewise search. */ - - s = (unsigned char*)aligned_addr; - } - - while (*s && *s != c) - s++; - if (*s == c) - return (char *)s; - return NULL; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strcmp.c b/firmware/common/strcmp.c deleted file mode 100644 index bbbf4b174a..0000000000 --- a/firmware/common/strcmp.c +++ /dev/null @@ -1,106 +0,0 @@ -/* -FUNCTION - <>---character string compare - -INDEX - strcmp - -ANSI_SYNOPSIS - #include - int strcmp(const char *<[a]>, const char *<[b]>); - -TRAD_SYNOPSIS - #include - int strcmp(<[a]>, <[b]>) - char *<[a]>; - char *<[b]>; - -DESCRIPTION - <> compares the string at <[a]> to - the string at <[b]>. - -RETURNS - If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, - <> returns a number greater than zero. If the two - strings match, <> returns zero. If <<*<[a]>>> - sorts lexicographically before <<*<[b]>>>, <> returns a - number less than zero. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strcmp ansi pure -*/ - -#include -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -int -_DEFUN (strcmp, (s1, s2), - _CONST char *s1 _AND - _CONST char *s2) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - while (*s1 != '\0' && *s1 == *s2) - { - s1++; - s2++; - } - - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#else - unsigned long *a1; - unsigned long *a2; - - /* If s1 or s2 are unaligned, then compare bytes. */ - if (!UNALIGNED (s1, s2)) - { - /* If s1 and s2 are word-aligned, compare them a word at a time. */ - a1 = (unsigned long*)s1; - a2 = (unsigned long*)s2; - while (*a1 == *a2) - { - /* To get here, *a1 == *a2, thus if we find a null in *a1, - then the strings must be equal, so return zero. */ - if (DETECTNULL (*a1)) - return 0; - - a1++; - a2++; - } - - /* A difference was detected in last few bytes of s1, so search bytewise */ - s1 = (char*)a1; - s2 = (char*)a2; - } - - while (*s1 != '\0' && *s1 == *s2) - { - s1++; - s2++; - } - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strcpy.c b/firmware/common/strcpy.c deleted file mode 100644 index 077ae73cc6..0000000000 --- a/firmware/common/strcpy.c +++ /dev/null @@ -1,99 +0,0 @@ -/* -FUNCTION - <>---copy string - -INDEX - strcpy - -ANSI_SYNOPSIS - #include - char *strcpy(char *<[dst]>, const char *<[src]>); - -TRAD_SYNOPSIS - #include - char *strcpy(<[dst]>, <[src]>) - char *<[dst]>; - char *<[src]>; - -DESCRIPTION - <> copies the string pointed to by <[src]> - (including the terminating null character) to the array - pointed to by <[dst]>. - -RETURNS - This function returns the initial value of <[dst]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strcpy ansi pure -*/ - -#include -#include - -/*SUPPRESS 560*/ -/*SUPPRESS 530*/ - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -char* -_DEFUN (strcpy, (dst0, src0), - char *dst0 _AND - _CONST char *src0) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *s = dst0; - - while ((*dst0++ = *src0++)) - ; - - return s; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - - /* If SRC or DEST is unaligned, then copy bytes. */ - if (!UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* SRC and DEST are both "long int" aligned, try to do "long int" - sized copies. */ - while (!DETECTNULL(*aligned_src)) - { - *aligned_dst++ = *aligned_src++; - } - - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while ((*dst++ = *src++)) - ; - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strlcat.c b/firmware/common/strlcat.c index da0d253e79..783ea4daba 100644 --- a/firmware/common/strlcat.c +++ b/firmware/common/strlcat.c @@ -16,7 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include /* diff --git a/firmware/common/strlcpy.c b/firmware/common/strlcpy.c index 6e06eb81d2..e320649140 100644 --- a/firmware/common/strlcpy.c +++ b/firmware/common/strlcpy.c @@ -16,7 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include #include /* diff --git a/firmware/common/strlen.c b/firmware/common/strlen.c deleted file mode 100644 index 4d33eafce6..0000000000 --- a/firmware/common/strlen.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -FUNCTION - <>---character string length - -INDEX - strlen - -ANSI_SYNOPSIS - #include - size_t strlen(const char *<[str]>); - -TRAD_SYNOPSIS - #include - size_t strlen(<[str]>) - char *<[src]>; - -DESCRIPTION - The <> function works out the length of the string - starting at <<*<[str]>>> by counting chararacters until it - reaches a <> character. - -RETURNS - <> returns the character count. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strlen ansi pure -*/ - -#include "config.h" -#include <_ansi.h> -#include -#include - -#define LBLOCKSIZE (sizeof (long)) -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -size_t -_DEFUN (strlen, (str), - _CONST char *str) ICODE_ATTR; - -size_t -_DEFUN (strlen, (str), - _CONST char *str) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - _CONST char *start = str; - - while (*str) - str++; - - return str - start; -#else - _CONST char *start = str; - unsigned long *aligned_addr; - - if (!UNALIGNED (str)) - { - /* If the string is word-aligned, we can check for the presence of - a null in each word-sized block. */ - aligned_addr = (unsigned long*)str; - while (!DETECTNULL (*aligned_addr)) - aligned_addr++; - - /* Once a null is detected, we check each byte in that block for a - precise position of the null. */ - str = (char*)aligned_addr; - } - - while (*str) - str++; - return str - start; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strncmp.c b/firmware/common/strncmp.c deleted file mode 100644 index b1d8d9d43a..0000000000 --- a/firmware/common/strncmp.c +++ /dev/null @@ -1,122 +0,0 @@ -/* -FUNCTION - <>---character string compare - -INDEX - strncmp - -ANSI_SYNOPSIS - #include - int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - int strncmp(<[a]>, <[b]>, <[length]>) - char *<[a]>; - char *<[b]>; - size_t <[length]> - -DESCRIPTION - <> compares up to <[length]> characters - from the string at <[a]> to the string at <[b]>. - -RETURNS - If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, - <> returns a number greater than zero. If the two - strings are equivalent, <> returns zero. If <<*<[a]>>> - sorts lexicographically before <<*<[b]>>>, <> returns a - number less than zero. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strncmp ansi pure -*/ - -#include -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -int -_DEFUN (strncmp, (s1, s2, n), - _CONST char *s1 _AND - _CONST char *s2 _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - if (n == 0) - return 0; - - while (n-- != 0 && *s1 == *s2) - { - if (n == 0 || *s1 == '\0') - break; - s1++; - s2++; - } - - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#else - unsigned long *a1; - unsigned long *a2; - - if (n == 0) - return 0; - - /* If s1 or s2 are unaligned, then compare bytes. */ - if (!UNALIGNED (s1, s2)) - { - /* If s1 and s2 are word-aligned, compare them a word at a time. */ - a1 = (unsigned long*)s1; - a2 = (unsigned long*)s2; - while (n >= sizeof (long) && *a1 == *a2) - { - n -= sizeof (long); - - /* If we've run out of bytes or hit a null, return zero - since we already know *a1 == *a2. */ - if (n == 0 || DETECTNULL (*a1)) - return 0; - - a1++; - a2++; - } - - /* A difference was detected in last few bytes of s1, so search bytewise */ - s1 = (char*)a1; - s2 = (char*)a2; - } - - while (n-- > 0 && *s1 == *s2) - { - /* If we've run out of bytes or hit a null, return zero - since we already know *s1 == *s2. */ - if (n == 0 || *s1 == '\0') - return 0; - s1++; - s2++; - } - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -#endif /* not PREFER_SIZE_OVER_SPEED */ -} diff --git a/firmware/common/strrchr.c b/firmware/common/strrchr.c deleted file mode 100644 index 31b0d049b3..0000000000 --- a/firmware/common/strrchr.c +++ /dev/null @@ -1,59 +0,0 @@ -/* -FUNCTION - <>---reverse search for character in string - -INDEX - strrchr - -ANSI_SYNOPSIS - #include - char * strrchr(const char *<[string]>, int <[c]>); - -TRAD_SYNOPSIS - #include - char * strrchr(<[string]>, <[c]>); - char *<[string]>; - int *<[c]>; - -DESCRIPTION - This function finds the last occurence of <[c]> (converted to - a char) in the string pointed to by <[string]> (including the - terminating null character). - -RETURNS - Returns a pointer to the located character, or a null pointer - if <[c]> does not occur in <[string]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strrchr ansi pure -*/ - -#include - -char * -_DEFUN (strrchr, (s, i), - _CONST char *s _AND - int i) -{ - _CONST char *last = NULL; - - if (i) - { - while ((s=strchr(s, i))) - { - last = s; - s++; - } - } - else - { - last = strchr(s, i); - } - - return (char *) last; -} diff --git a/firmware/common/strstr.c b/firmware/common/strstr.c deleted file mode 100644 index 73fab1cc63..0000000000 --- a/firmware/common/strstr.c +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id: $ - * - * Copyright (C) 1991, 1992 Linus Torvalds - * (from linux/lib/string.c) - * - ****************************************************************************/ - -#include - -/** - * strstr - Find the first substring in a %NUL terminated string - * @s1: The string to be searched - * @s2: The string to search for - */ -char *strstr(const char *s1, const char *s2) -{ - int l1, l2; - - l2 = strlen(s2); - if (!l2) - return (char *)s1; - l1 = strlen(s1); - while (l1 >= l2) { - l1--; - if (!memcmp(s1, s2, l2)) - return (char *)s1; - s1++; - } - return NULL; -} - diff --git a/firmware/common/strtok.c b/firmware/common/strtok.c deleted file mode 100644 index 9e2eddf599..0000000000 --- a/firmware/common/strtok.c +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Daniel Stenberg - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. * - ****************************************************************************/ - -#include "config.h" - -#ifndef HAVE_STRTOK_R -#include -#include - -char * -strtok_r(char *ptr, const char *sep, char **end) -{ - if (!ptr) - /* we got NULL input so then we get our last position instead */ - ptr = *end; - - /* pass all letters that are including in the separator string */ - while (*ptr && strchr(sep, *ptr)) - ++ptr; - - if (*ptr) { - /* so this is where the next piece of string starts */ - char *start = ptr; - - /* set the end pointer to the first byte after the start */ - *end = start + 1; - - /* scan through the string to find where it ends, it ends on a - null byte or a character that exists in the separator string */ - while (**end && !strchr(sep, **end)) - ++*end; - - if (**end) { - /* the end is not a null byte */ - **end = '\0'; /* zero terminate it! */ - ++*end; /* advance last pointer to beyond the null byte */ - } - - return start; /* return the position where the string starts */ - } - - /* we ended up on a null byte, there are no more strings to find! */ - return NULL; -} - -#endif /* this was only compiled if strtok_r wasn't present */ diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c index e423e016fd..42babbd8e3 100644 --- a/firmware/common/timefuncs.c +++ b/firmware/common/timefuncs.c @@ -103,43 +103,6 @@ int set_time(const struct tm *tm) #endif /* RTC */ } -#if CONFIG_RTC -/* mktime() code taken from lynx-2.8.5 source, written - by Philippe De Muyter */ -time_t mktime(struct tm *t) -{ - short month, year; - time_t result; - static int m_to_d[12] = - {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - - month = t->tm_mon; - year = t->tm_year + month / 12 + 1900; - month %= 12; - if (month < 0) - { - year -= 1; - month += 12; - } - result = (year - 1970) * 365 + (year - 1969) / 4 + m_to_d[month]; - result = (year - 1970) * 365 + m_to_d[month]; - if (month <= 1) - year -= 1; - result += (year - 1968) / 4; - result -= (year - 1900) / 100; - result += (year - 1600) / 400; - result += t->tm_mday; - result -= 1; - result *= 24; - result += t->tm_hour; - result *= 60; - result += t->tm_min; - result *= 60; - result += t->tm_sec; - return(result); -} -#endif - void set_day_of_week(struct tm *tm) { int y=tm->tm_year+1900; -- cgit v1.2.3