[package] update ndisc6 (#3779)
[openwrt/svn-archive/archive.git] / ipv6 / ndisc / patches / 110-strverscmp.patch
1 diff -urN ndisc6-0.9.8/rdnssd/Makefile.am ndisc6-0.9.8.new/rdnssd/Makefile.am
2 --- ndisc6-0.9.8/rdnssd/Makefile.am 2008-05-01 14:52:28.000000000 +0200
3 +++ ndisc6-0.9.8.new/rdnssd/Makefile.am 2009-04-17 15:47:51.000000000 +0200
4 @@ -27,7 +27,8 @@
5 # rdnssd
6 rdnssd_SOURCES = rdnssd.c rdnssd.h \
7 icmp.c \
8 - netlink.c
9 + netlink.c \
10 + strverscmp.c
11 rdnssd_LDADD = $(LIBRT) \
12 @top_builddir@/compat/libcompat.a
13
14 diff -urN ndisc6-0.9.8/rdnssd/Makefile.in ndisc6-0.9.8.new/rdnssd/Makefile.in
15 --- ndisc6-0.9.8/rdnssd/Makefile.in 2008-05-01 14:52:45.000000000 +0200
16 +++ ndisc6-0.9.8.new/rdnssd/Makefile.in 2009-04-17 15:47:39.000000000 +0200
17 @@ -58,7 +58,7 @@
18 am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(confdir)"
19 sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
20 PROGRAMS = $(sbin_PROGRAMS)
21 -am_rdnssd_OBJECTS = rdnssd.$(OBJEXT) icmp.$(OBJEXT) netlink.$(OBJEXT)
22 +am_rdnssd_OBJECTS = rdnssd.$(OBJEXT) icmp.$(OBJEXT) netlink.$(OBJEXT) strverscmp.$(OBJEXT)
23 rdnssd_OBJECTS = $(am_rdnssd_OBJECTS)
24 am__DEPENDENCIES_1 =
25 rdnssd_DEPENDENCIES = $(am__DEPENDENCIES_1) \
26 @@ -211,7 +211,8 @@
27 # rdnssd
28 rdnssd_SOURCES = rdnssd.c rdnssd.h \
29 icmp.c \
30 - netlink.c
31 + netlink.c \
32 + strverscmp.c
33
34 rdnssd_LDADD = $(LIBRT) \
35 @top_builddir@/compat/libcompat.a
36 @@ -334,6 +335,7 @@
37
38 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/icmp.Po@am__quote@
39 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netlink.Po@am__quote@
40 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strverscmp.Po@am__quote@
41 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rdnssd.Po@am__quote@
42
43 .c.o:
44 diff -urN ndisc6-0.9.8/rdnssd/strverscmp.c ndisc6-0.9.8.new/rdnssd/strverscmp.c
45 --- ndisc6-0.9.8/rdnssd/strverscmp.c 1970-01-01 01:00:00.000000000 +0100
46 +++ ndisc6-0.9.8.new/rdnssd/strverscmp.c 2009-04-17 15:46:24.000000000 +0200
47 @@ -0,0 +1,131 @@
48 +/* Compare strings while treating digits characters numerically.
49 + Copyright (C) 1997, 2000, 2002, 2004 Free Software Foundation, Inc.
50 + This file is part of the GNU C Library.
51 + Contributed by Jean-Fran├žois Bignolles <bignolle@ecoledoc.ibp.fr>, 1997.
52 +
53 + This program is free software; you can redistribute it and/or modify
54 + it under the terms of the GNU General Public License as published by
55 + the Free Software Foundation; either version 2, or (at your option)
56 + any later version.
57 +
58 + This program is distributed in the hope that it will be useful,
59 + but WITHOUT ANY WARRANTY; without even the implied warranty of
60 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61 + GNU General Public License for more details.
62 +
63 + You should have received a copy of the GNU General Public License along
64 + with this program; if not, write to the Free Software Foundation,
65 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
66 +
67 +#ifdef HAVE_CONFIG_H
68 +# include <config.h>
69 +#endif
70 +
71 +#include <string.h>
72 +#include <ctype.h>
73 +
74 +/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
75 + fractional parts, S_Z: idem but with leading Zeroes only */
76 +#define S_N 0x0
77 +#define S_I 0x4
78 +#define S_F 0x8
79 +#define S_Z 0xC
80 +
81 +/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
82 +#define CMP 2
83 +#define LEN 3
84 +
85 +
86 +/* ISDIGIT differs from isdigit, as follows:
87 + - Its arg may be any int or unsigned int; it need not be an unsigned char.
88 + - It's guaranteed to evaluate its argument exactly once.
89 + - It's typically faster.
90 + POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
91 + ISDIGIT_LOCALE unless it's important to use the locale's definition
92 + of `digit' even when the host does not conform to POSIX. */
93 +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
94 +
95 +#undef __strverscmp
96 +#undef strverscmp
97 +
98 +#ifndef weak_alias
99 +# define __strverscmp strverscmp
100 +#endif
101 +
102 +/* Compare S1 and S2 as strings holding indices/version numbers,
103 + returning less than, equal to or greater than zero if S1 is less than,
104 + equal to or greater than S2 (for more info, see the texinfo doc).
105 +*/
106 +
107 +int
108 +__strverscmp (const char *s1, const char *s2)
109 +{
110 + const unsigned char *p1 = (const unsigned char *) s1;
111 + const unsigned char *p2 = (const unsigned char *) s2;
112 + unsigned char c1, c2;
113 + int state;
114 + int diff;
115 +
116 + /* Symbol(s) 0 [1-9] others (padding)
117 + Transition (10) 0 (01) d (00) x (11) - */
118 + static const unsigned int next_state[] =
119 + {
120 + /* state x d 0 - */
121 + /* S_N */ S_N, S_I, S_Z, S_N,
122 + /* S_I */ S_N, S_I, S_I, S_I,
123 + /* S_F */ S_N, S_F, S_F, S_F,
124 + /* S_Z */ S_N, S_F, S_Z, S_Z
125 + };
126 +
127 + static const int result_type[] =
128 + {
129 + /* state x/x x/d x/0 x/- d/x d/d d/0 d/-
130 + 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
131 +
132 + /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
133 + CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
134 + /* S_I */ CMP, -1, -1, CMP, 1, LEN, LEN, CMP,
135 + 1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
136 + /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
137 + CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
138 + /* S_Z */ CMP, 1, 1, CMP, -1, CMP, CMP, CMP,
139 + -1, CMP, CMP, CMP
140 + };
141 +
142 + if (p1 == p2)
143 + return 0;
144 +
145 + c1 = *p1++;
146 + c2 = *p2++;
147 + /* Hint: '0' is a digit too. */
148 + state = S_N | ((c1 == '0') + (ISDIGIT (c1) != 0));
149 +
150 + while ((diff = c1 - c2) == 0 && c1 != '\0')
151 + {
152 + state = next_state[state];
153 + c1 = *p1++;
154 + c2 = *p2++;
155 + state |= (c1 == '0') + (ISDIGIT (c1) != 0);
156 + }
157 +
158 + state = result_type[state << 2 | ((c2 == '0') + (ISDIGIT (c2) != 0))];
159 +
160 + switch (state)
161 + {
162 + case CMP:
163 + return diff;
164 +
165 + case LEN:
166 + while (ISDIGIT (*p1++))
167 + if (!ISDIGIT (*p2++))
168 + return 1;
169 +
170 + return ISDIGIT (*p2) ? -1 : diff;
171 +
172 + default:
173 + return state;
174 + }
175 +}
176 +#ifdef weak_alias
177 +weak_alias (__strverscmp, strverscmp)
178 +#endif