summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/memchr.c50
-rw-r--r--firmware/common/memcmp.c48
-rw-r--r--firmware/common/memcpy.c14
-rw-r--r--firmware/common/memmove.c60
-rw-r--r--firmware/common/memset.c36
-rw-r--r--firmware/common/qsort.c252
-rw-r--r--firmware/common/strchr.c32
-rw-r--r--firmware/common/strcmp.c42
-rw-r--r--firmware/common/strcpy.c30
-rw-r--r--firmware/common/strlcat.c40
-rw-r--r--firmware/common/strlcpy.c38
-rw-r--r--firmware/common/strlen.c30
-rw-r--r--firmware/common/strnatcmp.c112
-rw-r--r--firmware/common/strncmp.c52
-rw-r--r--firmware/common/strrchr.c42
15 files changed, 439 insertions, 439 deletions
diff --git a/firmware/common/memchr.c b/firmware/common/memchr.c
index a7ff222a61..26bdb9eea3 100644
--- a/firmware/common/memchr.c
+++ b/firmware/common/memchr.c
@@ -1,28 +1,28 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<memchr>>---search for character in memory 3 <<memchr>>---search for character in memory
4 4
5INDEX 5INDEX
6 memchr 6 memchr
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>); 10 void * memchr(const void *<[s1]>, int <[c]>, size_t <[n]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 void * memchr(<[s1]>, <[c]>, <[n]>); 14 void * memchr(<[s1]>, <[c]>, <[n]>);
15 void *<[string]>; 15 void *<[string]>;
16 int *<[c]>; 16 int *<[c]>;
17 size_t *<[n]>; 17 size_t *<[n]>;
18 18
19DESCRIPTION 19DESCRIPTION
20 This function scans the first <[n]> bytes of the memory pointed 20 This function scans the first <[n]> bytes of the memory pointed
21 to by <[s1]> for the character <[c]> (converted to a char). 21 to by <[s1]> for the character <[c]> (converted to a char).
22 22
23RETURNS 23RETURNS
24 Returns a pointer to the matching byte, or a null pointer if 24 Returns a pointer to the matching byte, or a null pointer if
25 <[c]> does not occur in <[s1]>. 25 <[c]> does not occur in <[s1]>.
26 26
27PORTABILITY 27PORTABILITY
28<<memchr>> is ANSI C. 28<<memchr>> is ANSI C.
@@ -30,7 +30,7 @@ PORTABILITY
30<<memchr>> requires no supporting OS subroutines. 30<<memchr>> requires no supporting OS subroutines.
31 31
32QUICKREF 32QUICKREF
33 memchr ansi pure 33 memchr ansi pure
34*/ 34*/
35 35
36#include <string.h> 36#include <string.h>
@@ -59,8 +59,8 @@ QUICKREF
59 59
60void * 60void *
61_DEFUN (memchr, (s1, i, n), 61_DEFUN (memchr, (s1, i, n),
62 _CONST void *s1 _AND 62 _CONST void *s1 _AND
63 int i _AND size_t n) 63 int i _AND size_t n)
64{ 64{
65 _CONST unsigned char *s = (_CONST unsigned char *)s1; 65 _CONST unsigned char *s = (_CONST unsigned char *)s1;
66#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 66#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
@@ -69,9 +69,9 @@ _DEFUN (memchr, (s1, i, n),
69 while (n-- > 0) 69 while (n-- > 0)
70 { 70 {
71 if (*s == c) 71 if (*s == c)
72 { 72 {
73 return (void *)s; 73 return (void *)s;
74 } 74 }
75 s++; 75 s++;
76 } 76 }
77 77
@@ -89,15 +89,15 @@ _DEFUN (memchr, (s1, i, n),
89 89
90 aligned_addr = (unsigned long*)s; 90 aligned_addr = (unsigned long*)s;
91 while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE)) 91 while ((!DETECTCHAR (*aligned_addr, mask)) && (n>LBLOCKSIZE))
92 { 92 {
93 aligned_addr++; 93 aligned_addr++;
94 n -= LBLOCKSIZE; 94 n -= LBLOCKSIZE;
95 } 95 }
96 96
97 /* The block of bytes currently pointed to by aligned_addr 97 /* The block of bytes currently pointed to by aligned_addr
98 may contain the target character or there may be less than 98 may contain the target character or there may be less than
99 LBLOCKSIZE bytes left to search. We check the last few 99 LBLOCKSIZE bytes left to search. We check the last few
100 bytes using the bytewise search. */ 100 bytes using the bytewise search. */
101 101
102 s = (unsigned char*)aligned_addr; 102 s = (unsigned char*)aligned_addr;
103 } 103 }
@@ -105,9 +105,9 @@ _DEFUN (memchr, (s1, i, n),
105 while (n-- > 0) 105 while (n-- > 0)
106 { 106 {
107 if (*s == c) 107 if (*s == c)
108 { 108 {
109 return (void *)s; 109 return (void *)s;
110 } 110 }
111 s++; 111 s++;
112 } 112 }
113 113
diff --git a/firmware/common/memcmp.c b/firmware/common/memcmp.c
index 4a871fa601..1535fcf5b5 100644
--- a/firmware/common/memcmp.c
+++ b/firmware/common/memcmp.c
@@ -1,31 +1,31 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<memcmp>>---compare two memory areas 3 <<memcmp>>---compare two memory areas
4 4
5INDEX 5INDEX
6 memcmp 6 memcmp
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); 10 int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 int memcmp(<[s1]>, <[s2]>, <[n]>) 14 int memcmp(<[s1]>, <[s2]>, <[n]>)
15 void *<[s1]>; 15 void *<[s1]>;
16 void *<[s2]>; 16 void *<[s2]>;
17 size_t <[n]>; 17 size_t <[n]>;
18 18
19DESCRIPTION 19DESCRIPTION
20 This function compares not more than <[n]> characters of the 20 This function compares not more than <[n]> characters of the
21 object pointed to by <[s1]> with the object pointed to by <[s2]>. 21 object pointed to by <[s1]> with the object pointed to by <[s2]>.
22 22
23 23
24RETURNS 24RETURNS
25 The function returns an integer greater than, equal to or 25 The function returns an integer greater than, equal to or
26 less than zero according to whether the object pointed to by 26 less than zero according to whether the object pointed to by
27 <[s1]> is greater than, equal to or less than the object 27 <[s1]> is greater than, equal to or less than the object
28 pointed to by <[s2]>. 28 pointed to by <[s2]>.
29 29
30PORTABILITY 30PORTABILITY
31<<memcmp>> is ANSI C. 31<<memcmp>> is ANSI C.
@@ -33,7 +33,7 @@ PORTABILITY
33<<memcmp>> requires no supporting OS subroutines. 33<<memcmp>> requires no supporting OS subroutines.
34 34
35QUICKREF 35QUICKREF
36 memcmp ansi pure 36 memcmp ansi pure
37*/ 37*/
38 38
39#include <string.h> 39#include <string.h>
@@ -51,9 +51,9 @@ QUICKREF
51 51
52int 52int
53_DEFUN (memcmp, (m1, m2, n), 53_DEFUN (memcmp, (m1, m2, n),
54 _CONST _PTR m1 _AND 54 _CONST _PTR m1 _AND
55 _CONST _PTR m2 _AND 55 _CONST _PTR m2 _AND
56 size_t n) 56 size_t n)
57{ 57{
58#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 58#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
59 unsigned char *s1 = (unsigned char *) m1; 59 unsigned char *s1 = (unsigned char *) m1;
@@ -62,9 +62,9 @@ _DEFUN (memcmp, (m1, m2, n),
62 while (n--) 62 while (n--)
63 { 63 {
64 if (*s1 != *s2) 64 if (*s1 != *s2)
65 { 65 {
66 return *s1 - *s2; 66 return *s1 - *s2;
67 } 67 }
68 s1++; 68 s1++;
69 s2++; 69 s2++;
70 } 70 }
@@ -87,7 +87,7 @@ _DEFUN (memcmp, (m1, m2, n),
87 while (n >= LBLOCKSIZE) 87 while (n >= LBLOCKSIZE)
88 { 88 {
89 if (*a1 != *a2) 89 if (*a1 != *a2)
90 break; 90 break;
91 a1++; 91 a1++;
92 a2++; 92 a2++;
93 n -= LBLOCKSIZE; 93 n -= LBLOCKSIZE;
@@ -102,7 +102,7 @@ _DEFUN (memcmp, (m1, m2, n),
102 while (n--) 102 while (n--)
103 { 103 {
104 if (*s1 != *s2) 104 if (*s1 != *s2)
105 return *s1 - *s2; 105 return *s1 - *s2;
106 s1++; 106 s1++;
107 s2++; 107 s2++;
108 } 108 }
diff --git a/firmware/common/memcpy.c b/firmware/common/memcpy.c
index b77f27379d..a89ac3c557 100644
--- a/firmware/common/memcpy.c
+++ b/firmware/common/memcpy.c
@@ -30,7 +30,7 @@ PORTABILITY
30 30
31QUICKREF 31QUICKREF
32 memcpy ansi pure 32 memcpy ansi pure
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#include <_ansi.h> 36#include <_ansi.h>
@@ -51,15 +51,15 @@ QUICKREF
51 51
52_PTR 52_PTR
53_DEFUN (memcpy, (dst0, src0, len0), 53_DEFUN (memcpy, (dst0, src0, len0),
54 _PTR dst0 _AND 54 _PTR dst0 _AND
55 _CONST _PTR src0 _AND 55 _CONST _PTR src0 _AND
56 size_t len0) ICODE_ATTR; 56 size_t len0) ICODE_ATTR;
57 57
58_PTR 58_PTR
59_DEFUN (memcpy, (dst0, src0, len0), 59_DEFUN (memcpy, (dst0, src0, len0),
60 _PTR dst0 _AND 60 _PTR dst0 _AND
61 _CONST _PTR src0 _AND 61 _CONST _PTR src0 _AND
62 size_t len0) 62 size_t len0)
63{ 63{
64#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 64#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
65 char *dst = (char *) dst0; 65 char *dst = (char *) dst0;
diff --git a/firmware/common/memmove.c b/firmware/common/memmove.c
index 599cbc9c01..5f423964bb 100644
--- a/firmware/common/memmove.c
+++ b/firmware/common/memmove.c
@@ -1,30 +1,30 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<memmove>>---move possibly overlapping memory 3 <<memmove>>---move possibly overlapping memory
4 4
5INDEX 5INDEX
6 memmove 6 memmove
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); 10 void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 void *memmove(<[dst]>, <[src]>, <[length]>) 14 void *memmove(<[dst]>, <[src]>, <[length]>)
15 void *<[dst]>; 15 void *<[dst]>;
16 void *<[src]>; 16 void *<[src]>;
17 size_t <[length]>; 17 size_t <[length]>;
18 18
19DESCRIPTION 19DESCRIPTION
20 This function moves <[length]> characters from the block of 20 This function moves <[length]> characters from the block of
21 memory starting at <<*<[src]>>> to the memory starting at 21 memory starting at <<*<[src]>>> to the memory starting at
22 <<*<[dst]>>>. <<memmove>> reproduces the characters correctly 22 <<*<[dst]>>>. <<memmove>> reproduces the characters correctly
23 at <<*<[dst]>>> even if the two areas overlap. 23 at <<*<[dst]>>> even if the two areas overlap.
24 24
25 25
26RETURNS 26RETURNS
27 The function returns <[dst]> as passed. 27 The function returns <[dst]> as passed.
28 28
29PORTABILITY 29PORTABILITY
30<<memmove>> is ANSI C. 30<<memmove>> is ANSI C.
@@ -32,7 +32,7 @@ PORTABILITY
32<<memmove>> requires no supporting OS subroutines. 32<<memmove>> requires no supporting OS subroutines.
33 33
34QUICKREF 34QUICKREF
35 memmove ansi pure 35 memmove ansi pure
36*/ 36*/
37 37
38#include "config.h" 38#include "config.h"
@@ -54,15 +54,15 @@ QUICKREF
54 54
55_PTR 55_PTR
56_DEFUN (memmove, (dst_void, src_void, length), 56_DEFUN (memmove, (dst_void, src_void, length),
57 _PTR dst_void _AND 57 _PTR dst_void _AND
58 _CONST _PTR src_void _AND 58 _CONST _PTR src_void _AND
59 size_t length) ICODE_ATTR; 59 size_t length) ICODE_ATTR;
60 60
61_PTR 61_PTR
62_DEFUN (memmove, (dst_void, src_void, length), 62_DEFUN (memmove, (dst_void, src_void, length),
63 _PTR dst_void _AND 63 _PTR dst_void _AND
64 _CONST _PTR src_void _AND 64 _CONST _PTR src_void _AND
65 size_t length) 65 size_t length)
66{ 66{
67#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 67#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
68 char *dst = dst_void; 68 char *dst = dst_void;
@@ -74,16 +74,16 @@ _DEFUN (memmove, (dst_void, src_void, length),
74 src += length; 74 src += length;
75 dst += length; 75 dst += length;
76 while (length--) 76 while (length--)
77 { 77 {
78 *--dst = *--src; 78 *--dst = *--src;
79 } 79 }
80 } 80 }
81 else 81 else
82 { 82 {
83 while (length--) 83 while (length--)
84 { 84 {
85 *dst++ = *src++; 85 *dst++ = *src++;
86 } 86 }
87 } 87 }
88 88
89 return dst_void; 89 return dst_void;
@@ -100,9 +100,9 @@ _DEFUN (memmove, (dst_void, src_void, length),
100 src += len; 100 src += len;
101 dst += len; 101 dst += len;
102 while (len--) 102 while (len--)
103 { 103 {
104 *--dst = *--src; 104 *--dst = *--src;
105 } 105 }
106 } 106 }
107 else 107 else
108 { 108 {
diff --git a/firmware/common/memset.c b/firmware/common/memset.c
index c370191cda..6c4a66bf13 100644
--- a/firmware/common/memset.c
+++ b/firmware/common/memset.c
@@ -1,28 +1,28 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<memset>>---set an area of memory 3 <<memset>>---set an area of memory
4 4
5INDEX 5INDEX
6 memset 6 memset
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>); 10 void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 void *memset(<[dst]>, <[c]>, <[length]>) 14 void *memset(<[dst]>, <[c]>, <[length]>)
15 void *<[dst]>; 15 void *<[dst]>;
16 int <[c]>; 16 int <[c]>;
17 size_t <[length]>; 17 size_t <[length]>;
18 18
19DESCRIPTION 19DESCRIPTION
20 This function converts the argument <[c]> into an unsigned 20 This function converts the argument <[c]> into an unsigned
21 char and fills the first <[length]> characters of the array 21 char and fills the first <[length]> characters of the array
22 pointed to by <[dst]> to the value. 22 pointed to by <[dst]> to the value.
23 23
24RETURNS 24RETURNS
25 <<memset>> returns the value of <[m]>. 25 <<memset>> returns the value of <[m]>.
26 26
27PORTABILITY 27PORTABILITY
28<<memset>> is ANSI C. 28<<memset>> is ANSI C.
@@ -30,7 +30,7 @@ PORTABILITY
30 <<memset>> requires no supporting OS subroutines. 30 <<memset>> requires no supporting OS subroutines.
31 31
32QUICKREF 32QUICKREF
33 memset ansi pure 33 memset ansi pure
34*/ 34*/
35 35
36#include <string.h> 36#include <string.h>
@@ -41,9 +41,9 @@ QUICKREF
41 41
42_PTR 42_PTR
43_DEFUN (memset, (m, c, n), 43_DEFUN (memset, (m, c, n),
44 _PTR m _AND 44 _PTR m _AND
45 int c _AND 45 int c _AND
46 size_t n) 46 size_t n)
47{ 47{
48#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 48#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
49 char *s = (char *) m; 49 char *s = (char *) m;
@@ -78,7 +78,7 @@ _DEFUN (memset, (m, c, n),
78 { 78 {
79 buffer = 0; 79 buffer = 0;
80 for (i = 0; i < LBLOCKSIZE; i++) 80 for (i = 0; i < LBLOCKSIZE; i++)
81 buffer = (buffer << 8) | c; 81 buffer = (buffer << 8) | c;
82 } 82 }
83 83
84 while (n >= LBLOCKSIZE*4) 84 while (n >= LBLOCKSIZE*4)
diff --git a/firmware/common/qsort.c b/firmware/common/qsort.c
index b2071d447f..8c4d1ad511 100644
--- a/firmware/common/qsort.c
+++ b/firmware/common/qsort.c
@@ -3,20 +3,20 @@ FUNCTION
3<<qsort>>---sort an array 3<<qsort>>---sort an array
4 4
5INDEX 5INDEX
6 qsort 6 qsort
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <stdlib.h> 9 #include <stdlib.h>
10 void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>, 10 void qsort(void *<[base]>, size_t <[nmemb]>, size_t <[size]>,
11 int (*<[compar]>)(const void *, const void *) ); 11 int (*<[compar]>)(const void *, const void *) );
12 12
13TRAD_SYNOPSIS 13TRAD_SYNOPSIS
14 #include <stdlib.h> 14 #include <stdlib.h>
15 qsort(<[base]>, <[nmemb]>, <[size]>, <[compar]> ) 15 qsort(<[base]>, <[nmemb]>, <[size]>, <[compar]> )
16 char *<[base]>; 16 char *<[base]>;
17 size_t <[nmemb]>; 17 size_t <[nmemb]>;
18 size_t <[size]>; 18 size_t <[size]>;
19 int (*<[compar]>)(); 19 int (*<[compar]>)();
20 20
21DESCRIPTION 21DESCRIPTION
22<<qsort>> sorts an array (beginning at <[base]>) of <[nmemb]> objects. 22<<qsort>> sorts an array (beginning at <[base]>) of <[nmemb]> objects.
@@ -43,7 +43,7 @@ PORTABILITY
43 43
44/*- 44/*-
45 * Copyright (c) 1992, 1993 45 * Copyright (c) 1992, 1993
46 * The Regents of the University of California. All rights reserved. 46 * The Regents of the University of California. All rights reserved.
47 * 47 *
48 * Redistribution and use in source and binary forms, with or without 48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions 49 * modification, are permitted provided that the following conditions
@@ -55,8 +55,8 @@ PORTABILITY
55 * documentation and/or other materials provided with the distribution. 55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software 56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement: 57 * must display the following acknowledgement:
58 * This product includes software developed by the University of 58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors. 59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors 60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software 61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission. 62 * without specific prior written permission.
@@ -81,142 +81,142 @@ PORTABILITY
81#define inline 81#define inline
82#endif 82#endif
83 83
84static inline char *med3 _PARAMS((char *, char *, char *, int (*cmp)(const _PTR,const _PTR))); 84static inline char *med3 _PARAMS((char *, char *, char *, int (*cmp)(const _PTR,const _PTR)));
85static inline void swapfunc _PARAMS((char *, char *, int, int)); 85static inline void swapfunc _PARAMS((char *, char *, int, int));
86 86
87#define min(a, b) (a) < (b) ? a : b 87#define min(a, b) (a) < (b) ? a : b
88 88
89/* 89/*
90 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". 90 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
91 */ 91 */
92#define swapcode(TYPE, parmi, parmj, n) { \ 92#define swapcode(TYPE, parmi, parmj, n) { \
93 long i = (n) / sizeof (TYPE); \ 93 long i = (n) / sizeof (TYPE); \
94 register TYPE *pi = (TYPE *) (parmi); \ 94 register TYPE *pi = (TYPE *) (parmi); \
95 register TYPE *pj = (TYPE *) (parmj); \ 95 register TYPE *pj = (TYPE *) (parmj); \
96 do { \ 96 do { \
97 register TYPE t = *pi; \ 97 register TYPE t = *pi; \
98 *pi++ = *pj; \ 98 *pi++ = *pj; \
99 *pj++ = t; \ 99 *pj++ = t; \
100 } while (--i > 0); \ 100 } while (--i > 0); \
101} 101}
102 102
103#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ 103#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
104 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; 104 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
105 105
106static inline void 106static inline void
107_DEFUN(swapfunc, (a, b, n, swaptype), 107_DEFUN(swapfunc, (a, b, n, swaptype),
108 char *a _AND 108 char *a _AND
109 char *b _AND 109 char *b _AND
110 int n _AND 110 int n _AND
111 int swaptype) 111 int swaptype)
112{ 112{
113 if(swaptype <= 1) 113 if(swaptype <= 1)
114 swapcode(long, a, b, n) 114 swapcode(long, a, b, n)
115 else 115 else
116 swapcode(char, a, b, n) 116 swapcode(char, a, b, n)
117} 117}
118 118
119#define swap(a, b) \ 119#define swap(a, b) \
120 if (swaptype == 0) { \ 120 if (swaptype == 0) { \
121 long t = *(long *)(a); \ 121 long t = *(long *)(a); \
122 *(long *)(a) = *(long *)(b); \ 122 *(long *)(a) = *(long *)(b); \
123 *(long *)(b) = t; \ 123 *(long *)(b) = t; \
124 } else \ 124 } else \
125 swapfunc(a, b, es, swaptype) 125 swapfunc(a, b, es, swaptype)
126 126
127#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) 127#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
128 128
129static inline char * 129static inline char *
130_DEFUN(med3, (a, b, c, cmp), 130_DEFUN(med3, (a, b, c, cmp),
131 char *a _AND 131 char *a _AND
132 char *b _AND 132 char *b _AND
133 char *c _AND 133 char *c _AND
134 int (*cmp)(const _PTR,const _PTR)) 134 int (*cmp)(const _PTR,const _PTR))
135{ 135{
136 return cmp(a, b) < 0 ? 136 return cmp(a, b) < 0 ?
137 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) 137 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
138 :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); 138 :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
139} 139}
140 140
141void 141void
142_DEFUN(qsort, (a, n, es, cmp), 142_DEFUN(qsort, (a, n, es, cmp),
143 void *a _AND 143 void *a _AND
144 size_t n _AND 144 size_t n _AND
145 size_t es _AND 145 size_t es _AND
146 int (*cmp)(const _PTR,const _PTR)) 146 int (*cmp)(const _PTR,const _PTR))
147{ 147{
148 char *pa, *pb, *pc, *pd, *pl, *pm, *pn; 148 char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
149 int d, r, swaptype, swap_cnt; 149 int d, r, swaptype, swap_cnt;
150 150
151loop: SWAPINIT(a, es); 151loop: SWAPINIT(a, es);
152 swap_cnt = 0; 152 swap_cnt = 0;
153 if (n < 7) { 153 if (n < 7) {
154 for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) 154 for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es)
155 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; 155 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
156 pl -= es) 156 pl -= es)
157 swap(pl, pl - es); 157 swap(pl, pl - es);
158 return; 158 return;
159 } 159 }
160 pm = (char *) a + (n / 2) * es; 160 pm = (char *) a + (n / 2) * es;
161 if (n > 7) { 161 if (n > 7) {
162 pl = a; 162 pl = a;
163 pn = (char *) a + (n - 1) * es; 163 pn = (char *) a + (n - 1) * es;
164 if (n > 40) { 164 if (n > 40) {
165 d = (n / 8) * es; 165 d = (n / 8) * es;
166 pl = med3(pl, pl + d, pl + 2 * d, cmp); 166 pl = med3(pl, pl + d, pl + 2 * d, cmp);
167 pm = med3(pm - d, pm, pm + d, cmp); 167 pm = med3(pm - d, pm, pm + d, cmp);
168 pn = med3(pn - 2 * d, pn - d, pn, cmp); 168 pn = med3(pn - 2 * d, pn - d, pn, cmp);
169 } 169 }
170 pm = med3(pl, pm, pn, cmp); 170 pm = med3(pl, pm, pn, cmp);
171 } 171 }
172 swap(a, pm); 172 swap(a, pm);
173 pa = pb = (char *) a + es; 173 pa = pb = (char *) a + es;
174 174
175 pc = pd = (char *) a + (n - 1) * es; 175 pc = pd = (char *) a + (n - 1) * es;
176 for (;;) { 176 for (;;) {
177 while (pb <= pc && (r = cmp(pb, a)) <= 0) { 177 while (pb <= pc && (r = cmp(pb, a)) <= 0) {
178 if (r == 0) { 178 if (r == 0) {
179 swap_cnt = 1; 179 swap_cnt = 1;
180 swap(pa, pb); 180 swap(pa, pb);
181 pa += es; 181 pa += es;
182 } 182 }
183 pb += es; 183 pb += es;
184 } 184 }
185 while (pb <= pc && (r = cmp(pc, a)) >= 0) { 185 while (pb <= pc && (r = cmp(pc, a)) >= 0) {
186 if (r == 0) { 186 if (r == 0) {
187 swap_cnt = 1; 187 swap_cnt = 1;
188 swap(pc, pd); 188 swap(pc, pd);
189 pd -= es; 189 pd -= es;
190 } 190 }
191 pc -= es; 191 pc -= es;
192 } 192 }
193 if (pb > pc) 193 if (pb > pc)
194 break; 194 break;
195 swap(pb, pc); 195 swap(pb, pc);
196 swap_cnt = 1; 196 swap_cnt = 1;
197 pb += es; 197 pb += es;
198 pc -= es; 198 pc -= es;
199 } 199 }
200 if (swap_cnt == 0) { /* Switch to insertion sort */ 200 if (swap_cnt == 0) { /* Switch to insertion sort */
201 for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) 201 for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es)
202 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; 202 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
203 pl -= es) 203 pl -= es)
204 swap(pl, pl - es); 204 swap(pl, pl - es);
205 return; 205 return;
206 } 206 }
207 207
208 pn = (char *) a + n * es; 208 pn = (char *) a + n * es;
209 r = min(pa - (char *)a, pb - pa); 209 r = min(pa - (char *)a, pb - pa);
210 vecswap(a, pb - r, r); 210 vecswap(a, pb - r, r);
211 r = min((unsigned int)(pd - pc), pn - pd - es); 211 r = min((unsigned int)(pd - pc), pn - pd - es);
212 vecswap(pb, pn - r, r); 212 vecswap(pb, pn - r, r);
213 if ((unsigned int)(r = pb - pa) > es) 213 if ((unsigned int)(r = pb - pa) > es)
214 qsort(a, r / es, es, cmp); 214 qsort(a, r / es, es, cmp);
215 if ((unsigned int)(r = pd - pc) > es) { 215 if ((unsigned int)(r = pd - pc) > es) {
216 /* Iterate rather than recurse to save stack space */ 216 /* Iterate rather than recurse to save stack space */
217 a = pn - r; 217 a = pn - r;
218 n = r / es; 218 n = r / es;
219 goto loop; 219 goto loop;
220 } 220 }
221/* qsort(pn - r, r / es, es, cmp);*/ 221/* qsort(pn - r, r / es, es, cmp);*/
222} 222}
diff --git a/firmware/common/strchr.c b/firmware/common/strchr.c
index de4585f758..96acf5edf6 100644
--- a/firmware/common/strchr.c
+++ b/firmware/common/strchr.c
@@ -1,28 +1,28 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<strchr>>---search for character in string 3 <<strchr>>---search for character in string
4 4
5INDEX 5INDEX
6 strchr 6 strchr
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 char * strchr(const char *<[string]>, int <[c]>); 10 char * strchr(const char *<[string]>, int <[c]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 char * strchr(<[string]>, <[c]>); 14 char * strchr(<[string]>, <[c]>);
15 char *<[string]>; 15 char *<[string]>;
16 int *<[c]>; 16 int *<[c]>;
17 17
18DESCRIPTION 18DESCRIPTION
19 This function finds the first occurence of <[c]> (converted to 19 This function finds the first occurence of <[c]> (converted to
20 a char) in the string pointed to by <[string]> (including the 20 a char) in the string pointed to by <[string]> (including the
21 terminating null character). 21 terminating null character).
22 22
23RETURNS 23RETURNS
24 Returns a pointer to the located character, or a null pointer 24 Returns a pointer to the located character, or a null pointer
25 if <[c]> does not occur in <[string]>. 25 if <[c]> does not occur in <[string]>.
26 26
27PORTABILITY 27PORTABILITY
28<<strchr>> is ANSI C. 28<<strchr>> is ANSI C.
@@ -30,7 +30,7 @@ PORTABILITY
30<<strchr>> requires no supporting OS subroutines. 30<<strchr>> requires no supporting OS subroutines.
31 31
32QUICKREF 32QUICKREF
33 strchr ansi pure 33 strchr ansi pure
34*/ 34*/
35 35
36#include <string.h> 36#include <string.h>
@@ -59,8 +59,8 @@ QUICKREF
59 59
60char * 60char *
61_DEFUN (strchr, (s1, i), 61_DEFUN (strchr, (s1, i),
62 _CONST char *s1 _AND 62 _CONST char *s1 _AND
63 int i) 63 int i)
64{ 64{
65 _CONST unsigned char *s = (_CONST unsigned char *)s1; 65 _CONST unsigned char *s = (_CONST unsigned char *)s1;
66#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 66#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
diff --git a/firmware/common/strcmp.c b/firmware/common/strcmp.c
index 81d65272ec..bbbf4b174a 100644
--- a/firmware/common/strcmp.c
+++ b/firmware/common/strcmp.c
@@ -1,30 +1,30 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<strcmp>>---character string compare 3 <<strcmp>>---character string compare
4 4
5INDEX 5INDEX
6 strcmp 6 strcmp
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 int strcmp(const char *<[a]>, const char *<[b]>); 10 int strcmp(const char *<[a]>, const char *<[b]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 int strcmp(<[a]>, <[b]>) 14 int strcmp(<[a]>, <[b]>)
15 char *<[a]>; 15 char *<[a]>;
16 char *<[b]>; 16 char *<[b]>;
17 17
18DESCRIPTION 18DESCRIPTION
19 <<strcmp>> compares the string at <[a]> to 19 <<strcmp>> compares the string at <[a]> to
20 the string at <[b]>. 20 the string at <[b]>.
21 21
22RETURNS 22RETURNS
23 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, 23 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
24 <<strcmp>> returns a number greater than zero. If the two 24 <<strcmp>> returns a number greater than zero. If the two
25 strings match, <<strcmp>> returns zero. If <<*<[a]>>> 25 strings match, <<strcmp>> returns zero. If <<*<[a]>>>
26 sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a 26 sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a
27 number less than zero. 27 number less than zero.
28 28
29PORTABILITY 29PORTABILITY
30<<strcmp>> is ANSI C. 30<<strcmp>> is ANSI C.
@@ -32,7 +32,7 @@ PORTABILITY
32<<strcmp>> requires no supporting OS subroutines. 32<<strcmp>> requires no supporting OS subroutines.
33 33
34QUICKREF 34QUICKREF
35 strcmp ansi pure 35 strcmp ansi pure
36*/ 36*/
37 37
38#include <string.h> 38#include <string.h>
@@ -59,8 +59,8 @@ QUICKREF
59 59
60int 60int
61_DEFUN (strcmp, (s1, s2), 61_DEFUN (strcmp, (s1, s2),
62 _CONST char *s1 _AND 62 _CONST char *s1 _AND
63 _CONST char *s2) 63 _CONST char *s2)
64{ 64{
65#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 65#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
66 while (*s1 != '\0' && *s1 == *s2) 66 while (*s1 != '\0' && *s1 == *s2)
@@ -83,9 +83,9 @@ _DEFUN (strcmp, (s1, s2),
83 while (*a1 == *a2) 83 while (*a1 == *a2)
84 { 84 {
85 /* To get here, *a1 == *a2, thus if we find a null in *a1, 85 /* To get here, *a1 == *a2, thus if we find a null in *a1,
86 then the strings must be equal, so return zero. */ 86 then the strings must be equal, so return zero. */
87 if (DETECTNULL (*a1)) 87 if (DETECTNULL (*a1))
88 return 0; 88 return 0;
89 89
90 a1++; 90 a1++;
91 a2++; 91 a2++;
diff --git a/firmware/common/strcpy.c b/firmware/common/strcpy.c
index 0580d88cb8..077ae73cc6 100644
--- a/firmware/common/strcpy.c
+++ b/firmware/common/strcpy.c
@@ -1,27 +1,27 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<strcpy>>---copy string 3 <<strcpy>>---copy string
4 4
5INDEX 5INDEX
6 strcpy 6 strcpy
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 char *strcpy(char *<[dst]>, const char *<[src]>); 10 char *strcpy(char *<[dst]>, const char *<[src]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 char *strcpy(<[dst]>, <[src]>) 14 char *strcpy(<[dst]>, <[src]>)
15 char *<[dst]>; 15 char *<[dst]>;
16 char *<[src]>; 16 char *<[src]>;
17 17
18DESCRIPTION 18DESCRIPTION
19 <<strcpy>> copies the string pointed to by <[src]> 19 <<strcpy>> copies the string pointed to by <[src]>
20 (including the terminating null character) to the array 20 (including the terminating null character) to the array
21 pointed to by <[dst]>. 21 pointed to by <[dst]>.
22 22
23RETURNS 23RETURNS
24 This function returns the initial value of <[dst]>. 24 This function returns the initial value of <[dst]>.
25 25
26PORTABILITY 26PORTABILITY
27<<strcpy>> is ANSI C. 27<<strcpy>> is ANSI C.
@@ -29,7 +29,7 @@ PORTABILITY
29<<strcpy>> requires no supporting OS subroutines. 29<<strcpy>> requires no supporting OS subroutines.
30 30
31QUICKREF 31QUICKREF
32 strcpy ansi pure 32 strcpy ansi pure
33*/ 33*/
34 34
35#include <string.h> 35#include <string.h>
@@ -59,8 +59,8 @@ QUICKREF
59 59
60char* 60char*
61_DEFUN (strcpy, (dst0, src0), 61_DEFUN (strcpy, (dst0, src0),
62 char *dst0 _AND 62 char *dst0 _AND
63 _CONST char *src0) 63 _CONST char *src0)
64{ 64{
65#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 65#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
66 char *s = dst0; 66 char *s = dst0;
diff --git a/firmware/common/strlcat.c b/firmware/common/strlcat.c
index 0a113dd134..da0d253e79 100644
--- a/firmware/common/strlcat.c
+++ b/firmware/common/strlcat.c
@@ -29,28 +29,28 @@
29size_t 29size_t
30strlcat(char *dst, const char *src, size_t siz) 30strlcat(char *dst, const char *src, size_t siz)
31{ 31{
32 char *d = dst; 32 char *d = dst;
33 const char *s = src; 33 const char *s = src;
34 size_t n = siz; 34 size_t n = siz;
35 size_t dlen; 35 size_t dlen;
36 36
37 /* Find the end of dst and adjust bytes left but don't go past end */ 37 /* Find the end of dst and adjust bytes left but don't go past end */
38 while (n-- != 0 && *d != '\0') 38 while (n-- != 0 && *d != '\0')
39 d++; 39 d++;
40 dlen = d - dst; 40 dlen = d - dst;
41 n = siz - dlen; 41 n = siz - dlen;
42 42
43 if (n == 0) 43 if (n == 0)
44 return(dlen + strlen(s)); 44 return(dlen + strlen(s));
45 while (*s != '\0') { 45 while (*s != '\0') {
46 if (n != 1) { 46 if (n != 1) {
47 *d++ = *s; 47 *d++ = *s;
48 n--; 48 n--;
49 } 49 }
50 s++; 50 s++;
51 } 51 }
52 *d = '\0'; 52 *d = '\0';
53 53
54 return(dlen + (s - src)); /* count does not include NUL */ 54 return(dlen + (s - src)); /* count does not include NUL */
55} 55}
56 56
diff --git a/firmware/common/strlcpy.c b/firmware/common/strlcpy.c
index ac30ef01fe..6e06eb81d2 100644
--- a/firmware/common/strlcpy.c
+++ b/firmware/common/strlcpy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ 1/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -27,26 +27,26 @@
27size_t 27size_t
28strlcpy(char *dst, const char *src, size_t siz) 28strlcpy(char *dst, const char *src, size_t siz)
29{ 29{
30 char *d = dst; 30 char *d = dst;
31 const char *s = src; 31 const char *s = src;
32 size_t n = siz; 32 size_t n = siz;
33 33
34 /* Copy as many bytes as will fit */ 34 /* Copy as many bytes as will fit */
35 if (n != 0) { 35 if (n != 0) {
36 while (--n != 0) { 36 while (--n != 0) {
37 if ((*d++ = *s++) == '\0') 37 if ((*d++ = *s++) == '\0')
38 break; 38 break;
39 } 39 }
40 } 40 }
41 41
42 /* Not enough room in dst, add NUL and traverse rest of src */ 42 /* Not enough room in dst, add NUL and traverse rest of src */
43 if (n == 0) { 43 if (n == 0) {
44 if (siz != 0) 44 if (siz != 0)
45 *d = '\0'; /* NUL-terminate dst */ 45 *d = '\0'; /* NUL-terminate dst */
46 while (*s++) 46 while (*s++)
47 ; 47 ;
48 } 48 }
49 49
50 return(s - src - 1); /* count does not include NUL */ 50 return(s - src - 1); /* count does not include NUL */
51} 51}
52 52
diff --git a/firmware/common/strlen.c b/firmware/common/strlen.c
index 2e2c62eb75..4d33eafce6 100644
--- a/firmware/common/strlen.c
+++ b/firmware/common/strlen.c
@@ -1,26 +1,26 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<strlen>>---character string length 3 <<strlen>>---character string length
4 4
5INDEX 5INDEX
6 strlen 6 strlen
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 size_t strlen(const char *<[str]>); 10 size_t strlen(const char *<[str]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 size_t strlen(<[str]>) 14 size_t strlen(<[str]>)
15 char *<[src]>; 15 char *<[src]>;
16 16
17DESCRIPTION 17DESCRIPTION
18 The <<strlen>> function works out the length of the string 18 The <<strlen>> function works out the length of the string
19 starting at <<*<[str]>>> by counting chararacters until it 19 starting at <<*<[str]>>> by counting chararacters until it
20 reaches a <<NULL>> character. 20 reaches a <<NULL>> character.
21 21
22RETURNS 22RETURNS
23 <<strlen>> returns the character count. 23 <<strlen>> returns the character count.
24 24
25PORTABILITY 25PORTABILITY
26<<strlen>> is ANSI C. 26<<strlen>> is ANSI C.
@@ -28,7 +28,7 @@ PORTABILITY
28<<strlen>> requires no supporting OS subroutines. 28<<strlen>> requires no supporting OS subroutines.
29 29
30QUICKREF 30QUICKREF
31 strlen ansi pure 31 strlen ansi pure
32*/ 32*/
33 33
34#include "config.h" 34#include "config.h"
@@ -56,11 +56,11 @@ QUICKREF
56 56
57size_t 57size_t
58_DEFUN (strlen, (str), 58_DEFUN (strlen, (str),
59 _CONST char *str) ICODE_ATTR; 59 _CONST char *str) ICODE_ATTR;
60 60
61size_t 61size_t
62_DEFUN (strlen, (str), 62_DEFUN (strlen, (str),
63 _CONST char *str) 63 _CONST char *str)
64{ 64{
65#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 65#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
66 _CONST char *start = str; 66 _CONST char *start = str;
diff --git a/firmware/common/strnatcmp.c b/firmware/common/strnatcmp.c
index 93a649358f..0084ff3582 100644
--- a/firmware/common/strnatcmp.c
+++ b/firmware/common/strnatcmp.c
@@ -75,26 +75,26 @@ compare_right(char const *a, char const *b)
75 int ca, cb; 75 int ca, cb;
76 76
77 /* The longest run of digits wins. That aside, the greatest 77 /* The longest run of digits wins. That aside, the greatest
78 value wins, but we can't know that it will until we've scanned 78 value wins, but we can't know that it will until we've scanned
79 both numbers to know that they have the same magnitude, so we 79 both numbers to know that they have the same magnitude, so we
80 remember it in BIAS. */ 80 remember it in BIAS. */
81 for (;; a++, b++) { 81 for (;; a++, b++) {
82 ca = to_int(*a); 82 ca = to_int(*a);
83 cb = to_int(*b); 83 cb = to_int(*b);
84 if (!nat_isdigit(ca) && !nat_isdigit(cb)) 84 if (!nat_isdigit(ca) && !nat_isdigit(cb))
85 return bias; 85 return bias;
86 else if (!nat_isdigit(ca)) 86 else if (!nat_isdigit(ca))
87 return -1; 87 return -1;
88 else if (!nat_isdigit(cb)) 88 else if (!nat_isdigit(cb))
89 return +1; 89 return +1;
90 else if (ca < cb) { 90 else if (ca < cb) {
91 if (!bias) 91 if (!bias)
92 bias = -1; 92 bias = -1;
93 } else if (ca > cb) { 93 } else if (ca > cb) {
94 if (!bias) 94 if (!bias)
95 bias = +1; 95 bias = +1;
96 } else if (!ca && !cb) 96 } else if (!ca && !cb)
97 return bias; 97 return bias;
98 } 98 }
99 99
100 return 0; 100 return 0;
@@ -107,18 +107,18 @@ compare_left(char const *a, char const *b)
107 /* Compare two left-aligned numbers: the first to have a 107 /* Compare two left-aligned numbers: the first to have a
108 different value wins. */ 108 different value wins. */
109 for (;; a++, b++) { 109 for (;; a++, b++) {
110 if (!nat_isdigit(*a) && !nat_isdigit(*b)) 110 if (!nat_isdigit(*a) && !nat_isdigit(*b))
111 return 0; 111 return 0;
112 else if (!nat_isdigit(*a)) 112 else if (!nat_isdigit(*a))
113 return -1; 113 return -1;
114 else if (!nat_isdigit(*b)) 114 else if (!nat_isdigit(*b))
115 return +1; 115 return +1;
116 else if (*a < *b) 116 else if (*a < *b)
117 return -1; 117 return -1;
118 else if (*a > *b) 118 else if (*a > *b)
119 return +1; 119 return +1;
120 } 120 }
121 121
122 return 0; 122 return 0;
123} 123}
124 124
@@ -134,39 +134,39 @@ static int strnatcmp0(char const *a, char const *b, int fold_case)
134 ca = to_int(a[ai]); 134 ca = to_int(a[ai]);
135 cb = to_int(b[bi]); 135 cb = to_int(b[bi]);
136 136
137 /* process run of digits */ 137 /* process run of digits */
138 if (nat_isdigit(ca) && nat_isdigit(cb)) { 138 if (nat_isdigit(ca) && nat_isdigit(cb)) {
139 fractional = (ca == '0' || cb == '0'); 139 fractional = (ca == '0' || cb == '0');
140 140
141 if (fractional) { 141 if (fractional) {
142 if ((result = compare_left(a+ai, b+bi)) != 0) 142 if ((result = compare_left(a+ai, b+bi)) != 0)
143 return result; 143 return result;
144 } else { 144 } else {
145 if ((result = compare_right(a+ai, b+bi)) != 0) 145 if ((result = compare_right(a+ai, b+bi)) != 0)
146 return result; 146 return result;
147 } 147 }
148 } 148 }
149 149
150 if (!ca && !cb) { 150 if (!ca && !cb) {
151 /* The strings compare the same. Call str[case]cmp() to ensure 151 /* The strings compare the same. Call str[case]cmp() to ensure
152 consistent results. */ 152 consistent results. */
153 if(fold_case) 153 if(fold_case)
154 return strcasecmp(a,b); 154 return strcasecmp(a,b);
155 else 155 else
156 return strcmp(a,b); 156 return strcmp(a,b);
157 } 157 }
158 158
159 if (fold_case) { 159 if (fold_case) {
160 ca = nat_unify_case(ca); 160 ca = nat_unify_case(ca);
161 cb = nat_unify_case(cb); 161 cb = nat_unify_case(cb);
162 } 162 }
163 163
164 if (ca < cb) 164 if (ca < cb)
165 return -1; 165 return -1;
166 else if (ca > cb) 166 else if (ca > cb)
167 return +1; 167 return +1;
168 168
169 ++ai; ++bi; 169 ++ai; ++bi;
170 } 170 }
171} 171}
172 172
diff --git a/firmware/common/strncmp.c b/firmware/common/strncmp.c
index 9801b7d924..b1d8d9d43a 100644
--- a/firmware/common/strncmp.c
+++ b/firmware/common/strncmp.c
@@ -1,31 +1,31 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<strncmp>>---character string compare 3 <<strncmp>>---character string compare
4 4
5INDEX 5INDEX
6 strncmp 6 strncmp
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); 10 int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 int strncmp(<[a]>, <[b]>, <[length]>) 14 int strncmp(<[a]>, <[b]>, <[length]>)
15 char *<[a]>; 15 char *<[a]>;
16 char *<[b]>; 16 char *<[b]>;
17 size_t <[length]> 17 size_t <[length]>
18 18
19DESCRIPTION 19DESCRIPTION
20 <<strncmp>> compares up to <[length]> characters 20 <<strncmp>> compares up to <[length]> characters
21 from the string at <[a]> to the string at <[b]>. 21 from the string at <[a]> to the string at <[b]>.
22 22
23RETURNS 23RETURNS
24 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, 24 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,
25 <<strncmp>> returns a number greater than zero. If the two 25 <<strncmp>> returns a number greater than zero. If the two
26 strings are equivalent, <<strncmp>> returns zero. If <<*<[a]>>> 26 strings are equivalent, <<strncmp>> returns zero. If <<*<[a]>>>
27 sorts lexicographically before <<*<[b]>>>, <<strncmp>> returns a 27 sorts lexicographically before <<*<[b]>>>, <<strncmp>> returns a
28 number less than zero. 28 number less than zero.
29 29
30PORTABILITY 30PORTABILITY
31<<strncmp>> is ANSI C. 31<<strncmp>> is ANSI C.
@@ -33,7 +33,7 @@ PORTABILITY
33<<strncmp>> requires no supporting OS subroutines. 33<<strncmp>> requires no supporting OS subroutines.
34 34
35QUICKREF 35QUICKREF
36 strncmp ansi pure 36 strncmp ansi pure
37*/ 37*/
38 38
39#include <string.h> 39#include <string.h>
@@ -60,9 +60,9 @@ QUICKREF
60 60
61int 61int
62_DEFUN (strncmp, (s1, s2, n), 62_DEFUN (strncmp, (s1, s2, n),
63 _CONST char *s1 _AND 63 _CONST char *s1 _AND
64 _CONST char *s2 _AND 64 _CONST char *s2 _AND
65 size_t n) 65 size_t n)
66{ 66{
67#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 67#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
68 if (n == 0) 68 if (n == 0)
@@ -71,7 +71,7 @@ _DEFUN (strncmp, (s1, s2, n),
71 while (n-- != 0 && *s1 == *s2) 71 while (n-- != 0 && *s1 == *s2)
72 { 72 {
73 if (n == 0 || *s1 == '\0') 73 if (n == 0 || *s1 == '\0')
74 break; 74 break;
75 s1++; 75 s1++;
76 s2++; 76 s2++;
77 } 77 }
@@ -95,9 +95,9 @@ _DEFUN (strncmp, (s1, s2, n),
95 n -= sizeof (long); 95 n -= sizeof (long);
96 96
97 /* If we've run out of bytes or hit a null, return zero 97 /* If we've run out of bytes or hit a null, return zero
98 since we already know *a1 == *a2. */ 98 since we already know *a1 == *a2. */
99 if (n == 0 || DETECTNULL (*a1)) 99 if (n == 0 || DETECTNULL (*a1))
100 return 0; 100 return 0;
101 101
102 a1++; 102 a1++;
103 a2++; 103 a2++;
@@ -111,9 +111,9 @@ _DEFUN (strncmp, (s1, s2, n),
111 while (n-- > 0 && *s1 == *s2) 111 while (n-- > 0 && *s1 == *s2)
112 { 112 {
113 /* If we've run out of bytes or hit a null, return zero 113 /* If we've run out of bytes or hit a null, return zero
114 since we already know *s1 == *s2. */ 114 since we already know *s1 == *s2. */
115 if (n == 0 || *s1 == '\0') 115 if (n == 0 || *s1 == '\0')
116 return 0; 116 return 0;
117 s1++; 117 s1++;
118 s2++; 118 s2++;
119 } 119 }
diff --git a/firmware/common/strrchr.c b/firmware/common/strrchr.c
index 4f903afe2b..31b0d049b3 100644
--- a/firmware/common/strrchr.c
+++ b/firmware/common/strrchr.c
@@ -1,28 +1,28 @@
1/* 1/*
2FUNCTION 2FUNCTION
3 <<strrchr>>---reverse search for character in string 3 <<strrchr>>---reverse search for character in string
4 4
5INDEX 5INDEX
6 strrchr 6 strrchr
7 7
8ANSI_SYNOPSIS 8ANSI_SYNOPSIS
9 #include <string.h> 9 #include <string.h>
10 char * strrchr(const char *<[string]>, int <[c]>); 10 char * strrchr(const char *<[string]>, int <[c]>);
11 11
12TRAD_SYNOPSIS 12TRAD_SYNOPSIS
13 #include <string.h> 13 #include <string.h>
14 char * strrchr(<[string]>, <[c]>); 14 char * strrchr(<[string]>, <[c]>);
15 char *<[string]>; 15 char *<[string]>;
16 int *<[c]>; 16 int *<[c]>;
17 17
18DESCRIPTION 18DESCRIPTION
19 This function finds the last occurence of <[c]> (converted to 19 This function finds the last occurence of <[c]> (converted to
20 a char) in the string pointed to by <[string]> (including the 20 a char) in the string pointed to by <[string]> (including the
21 terminating null character). 21 terminating null character).
22 22
23RETURNS 23RETURNS
24 Returns a pointer to the located character, or a null pointer 24 Returns a pointer to the located character, or a null pointer
25 if <[c]> does not occur in <[string]>. 25 if <[c]> does not occur in <[string]>.
26 26
27PORTABILITY 27PORTABILITY
28<<strrchr>> is ANSI C. 28<<strrchr>> is ANSI C.
@@ -30,30 +30,30 @@ PORTABILITY
30<<strrchr>> requires no supporting OS subroutines. 30<<strrchr>> requires no supporting OS subroutines.
31 31
32QUICKREF 32QUICKREF
33 strrchr ansi pure 33 strrchr ansi pure
34*/ 34*/
35 35
36#include <string.h> 36#include <string.h>
37 37
38char * 38char *
39_DEFUN (strrchr, (s, i), 39_DEFUN (strrchr, (s, i),
40 _CONST char *s _AND 40 _CONST char *s _AND
41 int i) 41 int i)
42{ 42{
43 _CONST char *last = NULL; 43 _CONST char *last = NULL;
44 44
45 if (i) 45 if (i)
46 { 46 {
47 while ((s=strchr(s, i))) 47 while ((s=strchr(s, i)))
48 { 48 {
49 last = s; 49 last = s;
50 s++; 50 s++;
51 } 51 }
52 } 52 }
53 else 53 else
54 { 54 {
55 last = strchr(s, i); 55 last = strchr(s, i);
56 } 56 }
57 57
58 return (char *) last; 58 return (char *) last;
59} 59}