From: dgaudet Date: Mon, 24 Apr 2000 04:03:39 +0000 (+0000) Subject: Add `IndexOptions +VersionSort', to nicely sort filenames X-Git-Tag: APACHE_2_0_ALPHA_3~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89d7e6030301c357d1b53ee158537c969626b64c;p=thirdparty%2Fapache%2Fhttpd.git Add `IndexOptions +VersionSort', to nicely sort filenames containing version numbers. Submitted by: Martin Pool git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85021 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/conf/httpd-std.conf b/docs/conf/httpd-std.conf index b2e7ffda906..a0e1aee1a44 100644 --- a/docs/conf/httpd-std.conf +++ b/docs/conf/httpd-std.conf @@ -539,10 +539,11 @@ ScriptAlias /cgi-bin/ "@@ServerRoot@@/cgi-bin/" # Directives controlling the display of server-generated directory listings. # -# -# FancyIndexing is whether you want fancy directory indexing or standard -# -IndexOptions FancyIndexing +# FancyIndexing is whether you want fancy directory indexing or standard. +# VersionSort is whether files containing version numbers should be +# compared in the natural way, so that `apache-1.3.9.tar' is placed before +# `apache-1.3.12.tar'. +IndexOptions FancyIndexing VersionSort # # AddIcon* directives tell the server which icon to show for different diff --git a/docs/manual/mod/mod_autoindex.html b/docs/manual/mod/mod_autoindex.html index b39ed5c0f8b..7fc9b6616a3 100644 --- a/docs/manual/mod/mod_autoindex.html +++ b/docs/manual/mod/mod_autoindex.html @@ -632,6 +632,31 @@ The NameWidth keyword allows you to specify the width of the filename column in bytes. If the keyword value is '*', then the column is automatically sized to the length of the longest filename in the display. +
VersionSort (Apache 2.0a3 and later) +
+The VersionSort keyword causes files containing version numbers to +sort in a natural way. Strings are sorted as usual, except that +substrings of digits in the name and description are compared +according to their numeric value. + +For example: +
+foo-1.7
+foo-1.7.2
+foo-1.7.12
+foo-1.8.2
+foo-1.8.2a
+foo-1.12
+
+ +If the number starts with a zero, then it is considered to be a + fraction: +
+foo-1.001
+foo-1.002
+foo-1.030
+foo-1.04
+
ScanHTMLTitles
This enables the extraction of the title from HTML documents for fancy diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index cb5c24fa50e..edc07355f15 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -63,7 +63,8 @@ * 3/23/93 * * Adapted to Apache by rst. - */ + * + * Version sort added by Martin Pool . */ #include "ap_config.h" #include "httpd.h" @@ -75,6 +76,7 @@ #include "http_main.h" #include "util_script.h" #include "apr_fnmatch.h" +#include "apr_strnatcmp.h" #ifdef HAVE_STRING_H #include #endif @@ -100,6 +102,7 @@ module MODULE_VAR_EXPORT autoindex_module; #define SUPPRESS_PREAMBLE 64 #define SUPPRESS_COLSORT 128 #define NO_OPTIONS 256 +#define VERSION_SORT 512 #define K_PAD 1 #define K_NOPAD 0 @@ -405,6 +408,9 @@ static const char *add_opts(cmd_parms *cmd, void *d, const char *optstr) else if (!strcasecmp(w, "SuppressColumnSorting")) { option = SUPPRESS_COLSORT; } + else if (!strcasecmp(w, "VersionSort")) { + option = VERSION_SORT; + } else if (!strcasecmp(w, "None")) { if (action != '\0') { return "Cannot combine '+' or '-' with 'None' keyword"; @@ -685,7 +691,7 @@ struct ent { off_t size; ap_time_t lm; struct ent *next; - int ascending; + int ascending, version_sort; char key; }; @@ -1162,6 +1168,7 @@ static struct ent *make_autoindex_entry(char *name, int autoindex_opts, p->lm = -1; p->key = ap_toupper(keyid); p->ascending = (ap_toupper(direction) == D_ASCENDING); + p->version_sort = autoindex_opts & VERSION_SORT; if (autoindex_opts & FANCY_INDEXING) { request_rec *rr = ap_sub_req_lookup_file(name, r); @@ -1479,6 +1486,7 @@ static int dsortf(struct ent **e1, struct ent **e2) c1 = *e2; c2 = *e1; } + switch (c1->key) { case K_LAST_MOD: if (c1->lm > c2->lm) { @@ -1497,13 +1505,19 @@ static int dsortf(struct ent **e1, struct ent **e2) } break; case K_DESC: - result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : ""); + if (c1->version_sort) + result = strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : ""); + else + result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : ""); if (result) { return result; } break; } - return strcmp(c1->name, c2->name); + if (c1->version_sort) + return strnatcmp(c1->name, c2->name); + else + return strcmp(c1->name, c2->name); }