]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Add `IndexOptions +VersionSort', to nicely sort filenames
authordgaudet <dgaudet@unknown>
Mon, 24 Apr 2000 04:03:39 +0000 (04:03 +0000)
committerdgaudet <dgaudet@unknown>
Mon, 24 Apr 2000 04:03:39 +0000 (04:03 +0000)
containing version numbers.

Submitted by: Martin Pool <mbp@linuxcare.com.au>

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85021 13f79535-47bb-0310-9956-ffa450edef68

docs/conf/httpd-std.conf
docs/manual/mod/mod_autoindex.html
modules/generators/mod_autoindex.c

index b2e7ffda906a5458c506531e3535df0657d2f670..a0e1aee1a44ca5fbce5a5739c4dbffe8d7988c95 100644 (file)
@@ -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
index b39ed5c0f8bdad029a253dacacc5183e25321a4f..7fc9b6616a35aebad110f80353484e4b3c10c8b9 100644 (file)
@@ -632,6 +632,31 @@ The NameWidth keyword allows you to specify the width of the
 filename column in bytes.  If the keyword value is '<SAMP>*</SAMP>',
 then the column is automatically sized to the length of the longest
 filename in the display.
+<DT><A NAME="indexoptions:versionsort">VersionSort (<EM>Apache 2.0a3 and later</EM>)</A>
+<DD>
+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:
+<BLOCKQUOTE><pre>
+foo-1.7
+foo-1.7.2
+foo-1.7.12
+foo-1.8.2
+foo-1.8.2a
+foo-1.12
+</pre></BLOCKQUOTE>
+
+If the number starts with a zero, then it is considered to be a
+       fraction:
+<BLOCKQUOTE><pre>
+foo-1.001
+foo-1.002
+foo-1.030
+foo-1.04
+</pre></BLOCKQUOTE>
 <DT><A NAME="indexoptions:scanhtmltitles">ScanHTMLTitles</A>
 <DD><!--%plaintext &lt;?INDEX {\tt ScanHTMLTitles} index option&gt; -->
 This enables the extraction of the title from HTML documents for fancy
index cb5c24fa50e1177456682b1d477754001bae1e28..edc07355f151060fed7d02cef72aaadac1ec4f46 100644 (file)
@@ -63,7 +63,8 @@
  * 3/23/93
  * 
  * Adapted to Apache by rst.
- */
+ *
+ * Version sort added by Martin Pool <mbp@humbug.org.au>. */
 
 #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 <string.h>
 #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);
 }