modified: src1/input.c
[GalaxyCodeBases.git] / c_cpp / lib / natsort / natsort-apache.diff
blob6bd5dba85cb5ce28ccf1bee72e64c2a82407fb2a
1 Patch to Apache2.0a-dev to add natural-order sorting to autoindexes of
2 directories.
4 Apply this patch with
6 $ cd apache-2.0
7 $ patch -p4 ~/natsort-apache.diff
9 --
10 Martin Pool
14 diff --recursive -u -N /home/mbp/apache-2.0-orig/src/lib/apr/lib/Makefile.in /home/mbp/apache-2.0/src/lib/apr/lib/Makefile.in
15 --- /home/mbp/apache-2.0-orig/src/lib/apr/lib/Makefile.in Mon Dec 20 15:02:30 1999
16 +++ /home/mbp/apache-2.0/src/lib/apr/lib/Makefile.in Sat Mar 11 01:50:49 2000
17 @@ -25,7 +25,8 @@
18 apr_slack.o \
19 apr_snprintf.o \
20 apr_tables.o \
21 - apr_getpass.o
22 + apr_getpass.o \
23 + apr_strnatcmp.o
25 .c.o:
26 $(CC) $(CFLAGS) -c $(INCLUDES) $<
27 diff --recursive -u -N /home/mbp/apache-2.0-orig/src/lib/apr/lib/apr_strnatcmp.c /home/mbp/apache-2.0/src/lib/apr/lib/apr_strnatcmp.c
28 --- /home/mbp/apache-2.0-orig/src/lib/apr/lib/apr_strnatcmp.c Wed Dec 31 19:00:00 1969
29 +++ /home/mbp/apache-2.0/src/lib/apr/lib/apr_strnatcmp.c Sat Mar 11 01:55:07 2000
30 @@ -0,0 +1,116 @@
31 +/* -*- mode: c; c-file-style: "k&r" -*-
33 + strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
34 + Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
36 + This software is provided 'as-is', without any express or implied
37 + warranty. In no event will the authors be held liable for any damages
38 + arising from the use of this software.
40 + Permission is granted to anyone to use this software for any purpose,
41 + including commercial applications, and to alter it and redistribute it
42 + freely, subject to the following restrictions:
44 + 1. The origin of this software must not be misrepresented; you must not
45 + claim that you wrote the original software. If you use this software
46 + in a product, an acknowledgment in the product documentation would be
47 + appreciated but is not required.
48 + 2. Altered source versions must be plainly marked as such, and must not be
49 + misrepresented as being the original software.
50 + 3. This notice may not be removed or altered from any source distribution.
51 +*/
53 +#include <ctype.h>
54 +#include <string.h>
55 +#include <assert.h>
56 +#include <stdio.h>
58 +#include "apr_strnatcmp.h"
60 +#if defined(__GNUC__)
61 +# define UNUSED __attribute__((__unused__))
62 +#endif
64 +static char const *version UNUSED =
65 + "strnatcmp.c,v 1.4";
68 +static int strnatcmp0(char const *a, char const *b, int fold_case)
70 + int ai, bi;
71 + char ca, cb;
73 + assert(a && b);
74 + ai = bi = 0;
75 + while (1) {
76 + ca = a[ai]; cb = b[bi];
78 + /* skip over leading spaces or zeros */
79 + while (isspace(ca) || ca == '0')
80 + ca = a[++ai];
82 + while (isspace(cb) || cb == '0')
83 + cb = b[++bi];
85 + /* process run of digits */
86 + if (isdigit(ca) && isdigit(cb)) {
87 + int bias = 0;
88 + /* The longest run of digits (stripping off leading
89 + zeros) wins. That aside, the greatest value wins,
90 + but we can't know that it will until we've scanned
91 + both numbers to know that they have the same
92 + magnitude, so we remember it in BIAS. */
93 + while (1) {
94 + if (!isdigit(ca) && !isdigit(cb))
95 + goto done_number;
96 + else if (!isdigit(ca))
97 + return -1;
98 + else if (!isdigit(cb))
99 + return +1;
100 + else if (ca < cb) {
101 + if (!bias)
102 + bias = -1;
103 + } else if (ca > cb) {
104 + if (!bias)
105 + bias = +1;
106 + } else if (!ca && !cb)
107 + return bias;
109 + ca = a[++ai]; cb = b[++bi];
111 + done_number:
112 + if (bias)
113 + return bias;
116 + if (!ca && !cb) {
117 + /* The strings compare the same. Perhaps the caller
118 + will want to call strcmp to break the tie. */
119 + return 0;
122 + if (fold_case) {
123 + ca = toupper(ca);
124 + cb = toupper(cb);
127 + if (ca < cb)
128 + return -1;
129 + else if (ca > cb)
130 + return +1;
132 + ++ai; ++bi;
138 +int strnatcmp(char const *a, char const *b) {
139 + return strnatcmp0(a, b, 0);
143 +/* Compare, recognizing numeric string and ignoring case. */
144 +int strnatcasecmp(char const *a, char const *b) {
145 + return strnatcmp0(a, b, 1);
148 --- /home/mbp/apache-2.0-orig/src/modules/standard/mod_autoindex.c Thu Mar 9 19:07:11 2000
149 +++ /home/mbp/apache-2.0/src/modules/standard/mod_autoindex.c Sat Mar 11 02:55:31 2000
150 @@ -62,7 +62,9 @@
151 * 3/23/93
153 * Adapted to Apache by rst.
154 - */
156 + * Natural sort ordering added by Martin Pool <mbp@humbug.org.au> in
157 + * March 2000. */
159 #include "ap_config.h"
160 #include "httpd.h"
161 @@ -74,6 +76,7 @@
162 #include "http_main.h"
163 #include "util_script.h"
164 #include "apr_fnmatch.h"
165 +#include "apr_strnatcmp.h"
166 #ifdef HAVE_STRING_H
167 #include <string.h>
168 #endif
169 @@ -99,6 +102,7 @@
170 #define SUPPRESS_PREAMBLE 64
171 #define SUPPRESS_COLSORT 128
172 #define NO_OPTIONS 256
173 +#define NATURAL_ORDER 512
175 #define K_PAD 1
176 #define K_NOPAD 0
177 @@ -404,6 +408,9 @@
178 else if (!strcasecmp(w, "SuppressColumnSorting")) {
179 option = SUPPRESS_COLSORT;
181 + else if (!strcasecmp(w, "NaturalOrder")) {
182 + option = NATURAL_ORDER;
184 else if (!strcasecmp(w, "None")) {
185 if (action != '\0') {
186 return "Cannot combine '+' or '-' with 'None' keyword";
187 @@ -684,7 +691,7 @@
188 off_t size;
189 ap_time_t lm;
190 struct ent *next;
191 - int ascending;
192 + int ascending, natural;
193 char key;
196 @@ -1161,6 +1168,7 @@
197 p->lm = -1;
198 p->key = ap_toupper(keyid);
199 p->ascending = (ap_toupper(direction) == D_ASCENDING);
200 + p->natural = autoindex_opts & NATURAL_ORDER;
202 if (autoindex_opts & FANCY_INDEXING) {
203 request_rec *rr = ap_sub_req_lookup_file(name, r);
204 @@ -1478,6 +1486,7 @@
205 c1 = *e2;
206 c2 = *e1;
209 switch (c1->key) {
210 case K_LAST_MOD:
211 if (c1->lm > c2->lm) {
212 @@ -1496,13 +1505,19 @@
214 break;
215 case K_DESC:
216 - result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
217 + if (c1->natural)
218 + result = strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
219 + else
220 + result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
221 if (result) {
222 return result;
224 break;
226 - return strcmp(c1->name, c2->name);
227 + if (c1->natural)
228 + return strnatcmp(c1->name, c2->name);
229 + else
230 + return strcmp(c1->name, c2->name);
234 diff --recursive -u -N /home/mbp/apache-2.0-orig/src/lib/apr/include/apr_strnatcmp.h /home/mbp/apache-2.0/src/lib/apr/include/apr_strnatcmp.h
235 --- /home/mbp/apache-2.0-orig/src/lib/apr/include/apr_strnatcmp.h Wed Dec 31 19:00:00 1969
236 +++ /home/mbp/apache-2.0/src/lib/apr/include/apr_strnatcmp.h Sat Mar 4 22:05:56 2000
237 @@ -0,0 +1,24 @@
238 +/* -*- mode: c; c-file-style: "k&r" -*-
240 + strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
241 + Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
243 + This software is provided 'as-is', without any express or implied
244 + warranty. In no event will the authors be held liable for any damages
245 + arising from the use of this software.
247 + Permission is granted to anyone to use this software for any purpose,
248 + including commercial applications, and to alter it and redistribute it
249 + freely, subject to the following restrictions:
251 + 1. The origin of this software must not be misrepresented; you must not
252 + claim that you wrote the original software. If you use this software
253 + in a product, an acknowledgment in the product documentation would be
254 + appreciated but is not required.
255 + 2. Altered source versions must be plainly marked as such, and must not be
256 + misrepresented as being the original software.
257 + 3. This notice may not be removed or altered from any source distribution.
260 +int strnatcmp(char const *a, char const *b);
261 +int strnatcasecmp(char const *a, char const *b);