coar 99/12/01 12:34:18
Modified: htdocs/manual/mod mod_autoindex.html src CHANGES src/modules/standard mod_autoindex.c Log: Add a FoldersFirst keyword to the IndexOptions directive, which causes subdirectories to always appear first in FancyIndexed listings. Reviewed by: Ryan Bloom, Martin Kraemer, Jim Jagielski Revision Changes Path 1.32 +24 -8 apache-1.3/htdocs/manual/mod/mod_autoindex.html Index: mod_autoindex.html =================================================================== RCS file: /home/cvs/apache-1.3/htdocs/manual/mod/mod_autoindex.html,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- mod_autoindex.html 1999/05/13 18:25:45 1.31 +++ mod_autoindex.html 1999/12/01 20:33:48 1.32 @@ -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 <?INDEX {\tt IconHeight} index option> --> @@ -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> -<Directory /web/docs> <BR> -IndexOptions FancyIndexing <BR> -</Directory><BR> -<Directory /web/docs/spec> <BR> -IndexOptions ScanHTMLTitles <BR> +<BLOCKQUOTE><pre> +<Directory /web/docs> + IndexOptions FancyIndexing </Directory> -</CODE></BLOCKQUOTE> +<Directory /web/docs/spec> + IndexOptions ScanHTMLTitles +</Directory> +</pre></BLOCKQUOTE> then only <CODE>ScanHTMLTitles</CODE> will be set for the /web/docs/spec directory. </P> 1.1465 +4 -0 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.1464 retrieving revision 1.1465 diff -u -r1.1464 -r1.1465 --- CHANGES 1999/12/01 20:24:50 1.1464 +++ CHANGES 1999/12/01 20:33:58 1.1465 @@ -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] + *) BS2000: Use send() instead of write() in the core buff routines for better performance and fewer restrictions (max. transfer size) [Martin Kraemer] 1.111 +24 -0 apache-1.3/src/modules/standard/mod_autoindex.c Index: mod_autoindex.c =================================================================== RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v retrieving revision 1.110 retrieving revision 1.111 diff -u -r1.110 -r1.111 --- mod_autoindex.c 1999/06/05 15:48:12 1.110 +++ mod_autoindex.c 1999/12/01 20:34:10 1.111 @@ -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,