1 Patch to Apache2.0a-dev to add natural-order sorting to autoindexes of
7 $ patch -p4 ~/natsort-apache.diff
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
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
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.
58 +#include "apr_strnatcmp.h"
60 +#if defined(__GNUC__)
61 +# define UNUSED __attribute__((__unused__))
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)
76 + ca = a[ai]; cb = b[bi];
78 + /* skip over leading spaces or zeros */
79 + while (isspace(ca) || ca == '0')
82 + while (isspace(cb) || cb == '0')
85 + /* process run of digits */
86 + if (isdigit(ca) && isdigit(cb)) {
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. */
94 + if (!isdigit(ca) && !isdigit(cb))
96 + else if (!isdigit(ca))
98 + else if (!isdigit(cb))
100 + else if (ca < cb) {
103 + } else if (ca > cb) {
106 + } else if (!ca && !cb)
109 + ca = a[++ai]; cb = b[++bi];
117 + /* The strings compare the same. Perhaps the caller
118 + will want to call strcmp to break the tie. */
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
153 * Adapted to Apache by rst.
156 + * Natural sort ordering added by Martin Pool <mbp@humbug.org.au> in
159 #include "ap_config.h"
162 #include "http_main.h"
163 #include "util_script.h"
164 #include "apr_fnmatch.h"
165 +#include "apr_strnatcmp.h"
170 #define SUPPRESS_PREAMBLE 64
171 #define SUPPRESS_COLSORT 128
172 #define NO_OPTIONS 256
173 +#define NATURAL_ORDER 512
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";
192 + int ascending, natural;
196 @@ -1161,6 +1168,7 @@
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 @@
211 if (c1->lm > c2->lm) {
212 @@ -1496,13 +1505,19 @@
216 - result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
218 + result = strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
220 + result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
226 - return strcmp(c1->name, c2->name);
228 + return strnatcmp(c1->name, c2->name);
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
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);