You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by dg...@locus.apache.org on 2000/04/24 06:03:39 UTC

cvs commit: apache-2.0/src/modules/standard mod_autoindex.c

dgaudet     00/04/23 21:03:39

  Modified:    conf     httpd.conf-dist
               htdocs/manual/mod mod_autoindex.html
               src      CHANGES
               src/lib/apr/lib Makefile.in
               src/modules/standard mod_autoindex.c
  Log:
  Add `IndexOptions +VersionSort', to nicely sort filenames
  containing version numbers.
  
  Submitted by:	Martin Pool <mb...@linuxcare.com.au>
  
  Revision  Changes    Path
  1.10      +5 -4      apache-2.0/conf/httpd.conf-dist
  
  Index: httpd.conf-dist
  ===================================================================
  RCS file: /home/cvs/apache-2.0/conf/httpd.conf-dist,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- httpd.conf-dist	2000/04/22 00:51:02	1.9
  +++ httpd.conf-dist	2000/04/24 04:03:37	1.10
  @@ -539,10 +539,11 @@
   # 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
  
  
  
  1.34      +25 -0     apache-2.0/htdocs/manual/mod/mod_autoindex.html
  
  Index: mod_autoindex.html
  ===================================================================
  RCS file: /home/cvs/apache-2.0/htdocs/manual/mod/mod_autoindex.html,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- mod_autoindex.html	1999/12/01 22:10:32	1.33
  +++ mod_autoindex.html	2000/04/24 04:03:38	1.34
  @@ -632,6 +632,31 @@
   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
  
  
  
  1.80      +3 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- CHANGES	2000/04/23 12:24:11	1.79
  +++ CHANGES	2000/04/24 04:03:38	1.80
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0a3-dev
   
  +  *) mod_autoindex: Add `IndexOptions +VersionSort', to nicely sort filenames
  +     containing version numbers. [Martin Pool]
  +
     *) ap_open(..,APR_OS_DEFAULT,..) uses perms 0666 instead of 0777 on
        Unix; access_log and error_log now created with these perms; non-
        Unix is unaffected [Jeff Trawick]
  
  
  
  1.14      +2 -1      apache-2.0/src/lib/apr/lib/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/lib/Makefile.in,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Makefile.in	2000/04/23 00:59:58	1.13
  +++ Makefile.in	2000/04/24 04:03:38	1.14
  @@ -24,7 +24,8 @@
   	apr_signal.o \
   	apr_snprintf.o \
   	apr_tables.o \
  -	apr_getpass.o
  +	apr_getpass.o \
  +	apr_strnatcmp.o
   
   .c.o:
   	$(CC) $(CFLAGS) -c $(INCLUDES) $<
  
  
  
  1.29      +18 -4     apache-2.0/src/modules/standard/mod_autoindex.c
  
  Index: mod_autoindex.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_autoindex.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- mod_autoindex.c	2000/04/14 15:59:08	1.28
  +++ mod_autoindex.c	2000/04/24 04:03:39	1.29
  @@ -63,7 +63,8 @@
    * 3/23/93
    * 
    * Adapted to Apache by rst.
  - */
  + *
  + * Version sort added by Martin Pool <mb...@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 @@
   #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 @@
           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 @@
       off_t size;
       ap_time_t lm;
       struct ent *next;
  -    int ascending;
  +    int ascending, version_sort;
       char key;
   };
   
  @@ -1162,6 +1168,7 @@
       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 @@
           c1 = *e2;
           c2 = *e1;
       }
  +
       switch (c1->key) {
       case K_LAST_MOD:
   	if (c1->lm > c2->lm) {
  @@ -1497,13 +1505,19 @@
           }
           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);
   }