You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1998/08/14 07:39:06 UTC

[contrib] dynamically size the index width in mod_autoindex

There's like a dozen patches that increase the constant width of the
mod_autoindex name entries... I wanted something dynamic.  Oh I took the
opportunity to do a little strength reduction, eliminating extra copies of
bytes and the such. 

Dean

Index: modules/standard/mod_autoindex.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v
retrieving revision 1.87
diff -u -r1.87 mod_autoindex.c
--- mod_autoindex.c	1998/08/06 17:30:56	1.87
+++ mod_autoindex.c	1998/08/14 05:29:05
@@ -865,15 +865,29 @@
 			       autoindex_config_rec * d, request_rec *r,
 			     int autoindex_opts, char keyid, char direction)
 {
-    int x, len;
+    int x;
     char *name = r->uri;
     char *tp;
     int static_columns = (autoindex_opts & SUPPRESS_COLSORT);
     pool *scratch = ap_make_sub_pool(r->pool);
+    int name_width;
+    char *name_scratch;
 
     if (name[0] == '\0')
 	name = "/";
 
+    name_width = 23;
+    for (x = 0; x < n; x++) {
+	int t = strlen(ar[x]->name);
+	if (t > name_width) {
+	    name_width = t;
+	}
+    }
+    ++name_width;
+    name_scratch = ap_palloc(r->pool, name_width + 1);
+    memset(name_scratch, ' ', name_width);
+    name_scratch[name_width] = 0;
+
     if (autoindex_opts & FANCY_INDEXING) {
 	ap_rputs("<PRE>", r);
 	if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
@@ -891,7 +905,7 @@
 	    ap_rputs("> ", r);
 	}
         emit_link(r, "Name", K_NAME, keyid, direction, static_columns);
-	ap_rputs("                   ", r);
+	ap_rputs(name_scratch + 4, r);
 	if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
             emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
                       static_columns);
@@ -912,7 +926,8 @@
     }
 
     for (x = 0; x < n; x++) {
-	char *anchor = NULL, *t = NULL, *t2 = NULL;
+	char *anchor, *t, *t2;
+	char *pad;
 
 	ap_clear_pool(scratch);
 
@@ -922,40 +937,21 @@
 	    if (t[0] == '\0') {
 		t = "/";
 	    }
-	    anchor = ap_pstrcat(scratch, "<A HREF=\"",
-				ap_escape_html(scratch,
-					       ap_os_escape_path(scratch, t,
-								 0)),
-				"\">", NULL);
-	    t2 = "Parent Directory</A>       ";
+	       /* 1234567890123456 */
+	    t2 = "Parent Directory";
+	    pad = name_scratch + 16;
+	    anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
 	}
 	else {
 	    t = ar[x]->name;
-	    len = strlen(t);
-	    if (len > 23) {
-		t2 = ap_pstrdup(scratch, t);
-		t2[21] = '.';
-		t2[22] = '.';
-		t2[23] = '\0';
-		t2 = ap_escape_html(scratch, t2);
-		t2 = ap_pstrcat(scratch, t2, "</A>", NULL);
-	    }
-	    else {
-		char buff[24] = "                       ";
-		t2 = ap_escape_html(scratch, t);
-		buff[23 - len] = '\0';
-		t2 = ap_pstrcat(scratch, t2, "</A>", buff, NULL);
-	    }
-	    anchor = ap_pstrcat(scratch, "<A HREF=\"",
-				ap_escape_html(scratch,
-					       ap_os_escape_path(scratch, t,
-								 0)),
-				"\">", NULL);
+	    pad = name_scratch + strlen(t);
+	    t2 = ap_escape_html(scratch, t);
+	    anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
 	}
 
 	if (autoindex_opts & FANCY_INDEXING) {
 	    if (autoindex_opts & ICONS_ARE_LINKS) {
-		ap_rputs(anchor, r);
+		ap_rvputs(r, "<A HREF=\"", anchor, "\">", NULL);
 	    }
 	    if ((ar[x]->icon) || d->default_icon) {
 		ap_rvputs(r, "<IMG SRC=\"",
@@ -974,7 +970,7 @@
 		ap_rputs("</A>", r);
 	    }
 
-	    ap_rvputs(r, " ", anchor, t2, NULL);
+	    ap_rvputs(r, " <A HREF=\"", anchor, "\">", t2, "</A>", pad, NULL);
 	    if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
 		if (ar[x]->lm != -1) {
 		    char time_str[MAX_STRING_LEN];
@@ -998,7 +994,7 @@
 	    }
 	}
 	else {
-	    ap_rvputs(r, "<LI> ", anchor, " ", t2, NULL);
+	    ap_rvputs(r, "<LI> <A HREF=\"", anchor, "\"> ", t2, "</A>", pad, NULL);
 	}
 	ap_rputc('\n', r);
     }



Re: [contrib] dynamically size the index width in mod_autoindex

Posted by Martin Kraemer <Ma...@mch.sni.de>.
On Thu, Aug 13, 1998 at 11:39:06PM -0700, Dean Gaudet wrote:
> There's like a dozen patches that increase the constant width of the
> mod_autoindex name entries... I wanted something dynamic.  Oh I took the
> opportunity to do a little strength reduction, eliminating extra copies of
> bytes and the such. 

Pleeze... Can you commit it? The fixed width for names (& descriptions)
has always annoyed me.  +1!

    Martin
-- 
| S I E M E N S |  <Ma...@mch.sni.de>  |      Siemens Nixdorf
| ------------- |   Voice: +49-89-636-46021     |  Informationssysteme AG
| N I X D O R F |   FAX:   +49-89-636-44994     |   81730 Munich, Germany
~~~~~~~~~~~~~~~~My opinions only, of course; pgp key available on request