httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodent of Unusual Size <Ken.C...@Golux.Com>
Subject [PATCH] (FancyIndexing) Always list subdirectories first
Date Wed, 01 Dec 1999 19:00:17 GMT
The attached patch adds a "FoldersFirst" keyword to the
existing IndexOptions directive.  The effect is that FancyIndexed
directory listings will always have subdirectories listed at
the top.  They'll be sorted within themselves according to
the current sort criteria, but they'll always be listed
first.

An odd bit of added functionality for 1.3, so I'm following
review-then-commit rules.  If it goes into 1.3 I'll take care
of putting it into 2.0 as well.
-- 
#ken    P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://ASFD.MeepZor.Com/>

Index: src/CHANGES
===================================================================
RCS file: /home/cvs/apache-1.3/src/CHANGES,v
retrieving revision 1.1463
diff -u -r1.1463 CHANGES
--- CHANGES     1999/11/30 15:51:59     1.1463
+++ CHANGES     1999/12/01 18:46:37
@@ -1,5 +1,9 @@
 Changes with Apache 1.3.10
 
+  *) Add IndexOptions FoldersFirst to allow fancy-indexed directory
+     listings to have the subdirectories always listed at the top.
+     [Ken Coar]
+
   *) If the compiler sanity check fails, force the verbose output
      for TestCompile so people can have a clue what the problem
      is. [Jim Jagielski]
Index: src/modules/standard/mod_autoindex.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v
retrieving revision 1.110
diff -u -r1.110 mod_autoindex.c
--- mod_autoindex.c     1999/06/05 15:48:12     1.110
+++ mod_autoindex.c     1999/12/01 18:46:58
@@ -95,6 +95,7 @@
 #define SUPPRESS_PREAMBLE 64
 #define SUPPRESS_COLSORT 128
 #define NO_OPTIONS 256
+#define FOLDERS_FIRST 512
 
 #define K_PAD 1
 #define K_NOPAD 0
@@ -400,6 +401,9 @@
         else if (!strcasecmp(w, "SuppressColumnSorting")) {
             option = SUPPRESS_COLSORT;
        }
+        else if (!strcasecmp(w, "FoldersFirst")) {
+            option = FOLDERS_FIRST;
+       }
        else if (!strcasecmp(w, "None")) {
            if (action != '\0') {
                return "Cannot combine '+' or '-' with 'None' keyword";
@@ -681,6 +685,8 @@
     time_t lm;
     struct ent *next;
     int ascending;
+    int isdir;
+    int checkdir;
     char key;
 };
 
@@ -1147,6 +1153,14 @@
     p->alt = NULL;
     p->desc = NULL;
     p->lm = -1;
+    p->isdir = 0;
+    /*
+     * It's obnoxious to have to include this in every entry, but the qsort()
+     * comparison routine only takes two arguments..  The alternative would
+     * add another function call to each invocation.  Let's use memory
+     * rather than CPU.
+     */
+    p->checkdir = ((d->opts & FOLDERS_FIRST) != 0);
     p->key = ap_toupper(keyid);
     p->ascending = (ap_toupper(direction) == D_ASCENDING);
 
@@ -1156,6 +1170,7 @@
        if (rr->finfo.st_mode != 0) {
            p->lm = rr->finfo.st_mtime;
            if (S_ISDIR(rr->finfo.st_mode)) {
+               p->isdir = 1;
                if (!(p->icon = find_icon(d, rr, 1))) {
                    p->icon = find_default_icon(d, "^^DIRECTORY^^");
                }
@@ -1449,6 +1464,15 @@
     }
     if (is_parent((*e2)->name)) {
         return 1;
+    }
+    /*
+     * Now see if one's a directory and one isn't, AND we're listing
+     * directories first.
+     */
+    if ((*e1)->checkdir) {
+       if ((*e1)->isdir != (*e2)->isdir) {
+           return (*e1)->isdir ? -1 : 1;
+       }
     }
     /*
      * All of our comparisons will be of the c1 entry against the c2 one,
Index: htdocs/manual/mod/mod_autoindex.html
===================================================================
RCS file: /home/cvs/apache-1.3/htdocs/manual/mod/mod_autoindex.html,v
retrieving revision 1.31
diff -u -r1.31 mod_autoindex.html
--- mod_autoindex.html  1999/05/13 18:25:45     1.31
+++ mod_autoindex.html  1999/12/01 18:46:24
@@ -545,7 +545,8 @@
  REL="Help"
 ><STRONG>Compatibility:</STRONG></A> '+/-' syntax and merging of multiple
  <SAMP>IndexOptions</SAMP> directives is only available with
- Apache 1.3.3 and later
+ Apache 1.3.3 and later; the <samp>FoldersFirst</samp> option is only
+ available with Apache 1.3.10 and later
 <P>
 
 The IndexOptions directive specifies the behavior of the directory indexing.
@@ -564,6 +565,21 @@
  is combined with any <SAMP>IndexOptions</SAMP> directive already
  specified for the current scope.</STRONG>
 </BLOCKQUOTE>
+<dt><a name="indexoptions:foldersfirst">FoldersFirst
+ (<i>Apache 1.3.10 and later</i>)</a></dt>
+<dd>
+If this option is enabled, subdirectories in a FancyIndexed listing
+will <i>always</i> appear first, followed by normal files in the
+directory.  The listing is basically broken into two components,
+the files and the subdirectories, and each is sorted separately and
+then displayed subdirectories-first.  For instance, if the sort order
+is descending by name, and <samp>FoldersFirst</samp> is enabled,
+subdirectory <samp>Zed</samp> will be listed before subdirectory
+<samp>Beta</samp>, which will be listed before normal files
+<samp>Gamma</samp> and <samp>Alpha</samp>.
+<b>This option only has an effect if
+<a href="#indexoptions:fancyindexing"><samp>FancyIndexing</samp></a>
+is also enabled.</b></dd>
 <DT><A NAME="indexoptions:iconheight">IconHeight[=pixels] (<EM>Apache 1.3
and later</EM>)</A>
 <DD>
 <!--%plaintext &lt;?INDEX {\tt IconHeight} index option&gt; -->
@@ -648,14 +664,14 @@
 The default is that no options are enabled. If multiple IndexOptions
 could apply to a directory, then the most specific one is taken complete;
 the options are not merged. For example:
-<BLOCKQUOTE><CODE>
-&lt;Directory /web/docs&gt; <BR>
-IndexOptions FancyIndexing <BR>
-&lt;/Directory&gt;<BR>
-&lt;Directory /web/docs/spec&gt; <BR>
-IndexOptions ScanHTMLTitles <BR>
+<BLOCKQUOTE><pre>
+&lt;Directory /web/docs&gt;
+    IndexOptions FancyIndexing
 &lt;/Directory&gt;
-</CODE></BLOCKQUOTE>
+&lt;Directory /web/docs/spec&gt;
+    IndexOptions ScanHTMLTitles
+&lt;/Directory&gt;
+</pre></BLOCKQUOTE>
 then only <CODE>ScanHTMLTitles</CODE> will be set for the /web/docs/spec
 directory.
 </P>

Mime
View raw message