home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / contrib / patches / 1.2 / IndexWidth.patch < prev    next >
Encoding:
Text File  |  1998-06-11  |  27.7 KB  |  985 lines

  1. Title: Variable-length fields in FancyIndexing output in mod_dir.
  2. Submitter: Ken Coar <Coar@DECUS.Org>
  3. Date: Tue Jan  7 12:22:27 EST 1997
  4. Patch built against: Apache 1.2b4
  5.  
  6.     This patch provides the IndexNameWidth and IndexDescWidth directives
  7.     to control the width of the filename and description fields,
  8.     respectively, in FancyIndexed generated directory indices.  These
  9.     directives can appear in any configuration file in which the
  10.     IndexOptions directive is available.
  11.  
  12.     The module and directive documentation pages are also patched to
  13.     reflect the new directives and their explanations.
  14.  
  15.     To apply the patch, cd to the Apache source directory and use the
  16.     command
  17.  
  18.     patch -c -s -b + + + -d ../htdocs/manual/mod < [patch-file]
  19.  
  20.     [Adjust the command appropriately if you've moved your manual
  21.     pages.]
  22.  
  23.     BEWARE if you're not patching the 1.2b4 distribution!  Caveat
  24.     emptor!
  25.  
  26.     #ken    :-)}
  27.  
  28. Index: mod_dir.c
  29. ===================================================================
  30. *** 1.1    1996/12/31 12:37:02
  31. --- mod_dir.c    1997/01/05 18:39:55
  32. ***************
  33. *** 82,87 ****
  34. --- 82,92 ----
  35.   #define SUPPRESS_SIZE 16
  36.   #define SUPPRESS_DESC 32
  37.   
  38. + #define DEFAULT_NAME_WIDTH 23
  39. + #define DEFAULT_DESC_WIDTH 23
  40. + #define LAST_MOD_WIDTH 17
  41. + #define SIZE_WIDTH SEND_SIZE_CHARS + 2
  42.   struct item {
  43.       char *type;
  44.       char *apply_to;
  45. ***************
  46. *** 95,101 ****
  47.       char *index_names;
  48.     
  49.       array_header *icon_list, *alt_list, *desc_list, *ign_list;
  50. !     array_header *hdr_list, *rdme_list, *opts_list;
  51.     
  52.   } dir_config_rec;
  53.   
  54. --- 100,106 ----
  55.       char *index_names;
  56.     
  57.       array_header *icon_list, *alt_list, *desc_list, *ign_list;
  58. !     array_header *hdr_list, *rdme_list, *opts_list, *nw_list, *dw_list;
  59.     
  60.   } dir_config_rec;
  61.   
  62. ***************
  63. *** 173,178 ****
  64. --- 178,220 ----
  65.       return NULL;
  66.   }
  67.   
  68. + /*
  69. + ** This routine adds the value of the read IndexNameWidth directive to the
  70. + ** appropriate directory entry.  This value controls the width of the filename
  71. + ** field in FancyIndexed generated indices.
  72. + */
  73. + const char *add_name_width (cmd_parms *cmd, void *d, char *cwidth) {
  74. +     int width = atoi (cwidth);
  75. +     push_item
  76. +     (
  77. +         ((dir_config_rec *) d)->nw_list,
  78. +         (char *) width,
  79. +         NULL,
  80. +         cmd->path,
  81. +         NULL
  82. +     );
  83. +     return NULL;
  84. + }
  85. + /*
  86. + ** Like its brother add_name_width above, this routine adds the value of the
  87. + ** just-read IndexDescWidth directive to the appropriate directory entry.
  88. + ** This controls the width of the description field in FancyIndexed generated
  89. + ** indices.
  90. + */
  91. + const char *add_desc_width (cmd_parms *cmd, void *d, char *cwidth) {
  92. +     push_item
  93. +     (
  94. +         ((dir_config_rec *) d)->dw_list,
  95. +         (char *) atoi (cwidth),
  96. +         NULL,
  97. +         cmd->path,
  98. +         NULL
  99. +     );
  100. +     return NULL;
  101. + }
  102.   
  103.   const char *add_opts_int(cmd_parms *cmd, void *d, int opts) {
  104.       push_item(((dir_config_rec *)d)->opts_list, (char*)opts, NULL,
  105. ***************
  106. *** 241,246 ****
  107. --- 283,304 ----
  108.   { "DirectoryIndex", set_string_slot,
  109.       (void*)XtOffsetOf(dir_config_rec, index_names),
  110.       DIR_CMD_PERMS, RAW_ARGS, NULL },
  111. + {
  112. +     "IndexNameWidth",
  113. +     add_name_width,
  114. +     NULL,
  115. +     DIR_CMD_PERMS,
  116. +     TAKE1,
  117. +     "width of filename field in generated indices"
  118. + },
  119. + {
  120. +     "IndexDescWidth",
  121. +     add_desc_width,
  122. +     NULL,
  123. +     DIR_CMD_PERMS,
  124. +     TAKE1,
  125. +     "width of description field in generated indices"
  126. + },
  127.   { NULL }
  128.   };
  129.   
  130. ***************
  131. *** 257,262 ****
  132. --- 315,322 ----
  133.       new->hdr_list = make_array (p, 4, sizeof (struct item));
  134.       new->rdme_list = make_array (p, 4, sizeof (struct item));
  135.       new->opts_list = make_array (p, 4, sizeof (struct item));
  136. +     new->nw_list = make_array (p, 4, sizeof (struct item));
  137. +     new->dw_list = make_array (p, 4, sizeof (struct item));
  138.       
  139.       return (void *)new;
  140.   }
  141. ***************
  142. *** 277,282 ****
  143. --- 337,344 ----
  144.       new->icon_list = append_arrays (p, add->icon_list, base->icon_list);
  145.       new->rdme_list = append_arrays (p, add->rdme_list, base->rdme_list);
  146.       new->opts_list = append_arrays (p, add->opts_list, base->opts_list);
  147. +     new->nw_list = append_arrays (p, add->nw_list, base->nw_list);
  148. +     new->dw_list = append_arrays (p, add->dw_list, base->dw_list);
  149.       
  150.       return new;
  151.   }
  152. ***************
  153. *** 382,401 ****
  154.       return 0;
  155.   }
  156.   
  157. ! int find_opts(dir_config_rec *d, request_rec *r) {
  158. !     char *path = r->filename;
  159. !     array_header *list = d->opts_list;
  160. !     struct item *items = (struct item *)list->elts;
  161.       int i;
  162.   
  163.       for (i = 0; i < list->nelts; ++i) {
  164.           struct item *p = &items[i];
  165.       
  166. !         if(!strcmp_match(path,p->apply_path))
  167.               return (int)p->type;
  168.       }
  169.       return 0;
  170.   }
  171.   
  172.   /*****************************************************************
  173.    *
  174. --- 444,504 ----
  175.       return 0;
  176.   }
  177.   
  178. ! /*
  179. ! ** This routine looks through the array of options settings for one applying
  180. ! ** to the specified path, returning the value if found or zero otherwise.
  181. ! */
  182. ! int find_opts (dir_config_rec *d, request_rec *r) {
  183. !     int value;
  184. !     value = find_int (r->filename, d->opts_list);
  185. !     return value;
  186. ! }
  187. ! /*
  188. ! ** This routine scans the specified item array for a matching path, and
  189. ! ** returns the integer value from the item when one is found.  If none is
  190. ! ** found, we return zero.
  191. ! */
  192. ! int find_int (char *path, array_header *list) {
  193. !     struct item *items;
  194.       int i;
  195.   
  196. +     if (list == NULL) {
  197. +     return 0;
  198. +     };
  199. +     items = (struct item *)list->elts;
  200. +     if (items == NULL) {
  201. +     return 0;
  202. +     };
  203.       for (i = 0; i < list->nelts; ++i) {
  204.           struct item *p = &items[i];
  205.       
  206. !         if(!strcmp_match (path, p->apply_path))
  207.               return (int)p->type;
  208.       }
  209.       return 0;
  210.   }
  211. + /*
  212. + ** This routine looks through the list of user-defined widths for the file
  213. + ** name until it finds one that applies to the specified path.  If none is
  214. + ** found, it returns zero, which means `use the default width.'
  215. + */
  216. + int find_name_width (dir_config_rec *d, request_rec *r) {
  217. +     int value;
  218. +     value = find_int (r->filename, d->nw_list);
  219. +     return value;
  220. + }
  221. + /*
  222. + ** This routine is the same as its brother find_name_width above, except that
  223. + ** it looks for a value for the width of the description field for this path.
  224. + */
  225. + int find_desc_width (dir_config_rec *d, request_rec *r) {
  226. +     return find_int (r->filename, d->dw_list);
  227. + }
  228.   
  229.   /*****************************************************************
  230.    *
  231. ***************
  232. *** 417,426 ****
  233.           if(stat(fn,&finfo) == -1)
  234.               return 0;
  235.           plaintext=1;
  236. !         if(rule) rputs("<HR>\n", r);
  237. !         rputs("<PRE>\n", r);
  238.       }
  239. !     else if (rule) rputs("<HR>\n", r);
  240.       if(!(f = pfopen(r->pool,fn,"r")))
  241.           return 0;
  242.       if (!plaintext)
  243. --- 520,529 ----
  244.           if(stat(fn,&finfo) == -1)
  245.               return 0;
  246.           plaintext=1;
  247. !         if (rule) rputs ("  <HR>\n", r);
  248. !         rputs ("  <PRE>\n", r);
  249.       }
  250. !     else if (rule) rputs("  <HR>\n", r);
  251.       if(!(f = pfopen(r->pool,fn,"r")))
  252.           return 0;
  253.       if (!plaintext)
  254. ***************
  255. *** 452,458 ****
  256.       }
  257.       pfclose(r->pool, f);
  258.       if(plaintext)
  259. !         rputs("</PRE>\n", r);
  260.       return 1;
  261.   }
  262.   
  263. --- 555,561 ----
  264.       }
  265.       pfclose(r->pool, f);
  266.       if(plaintext)
  267. !         rputs("  </PRE>\n", r);
  268.       return 1;
  269.   }
  270.   
  271. ***************
  272. *** 535,646 ****
  273.       return(p);
  274.   }
  275.   
  276. ! char *terminate_description(dir_config_rec *d, char *desc, int dir_opts) {
  277. !     int maxsize = 23;
  278. !     register int x;
  279. !     
  280. !     if(dir_opts & SUPPRESS_LAST_MOD) maxsize += 17;
  281. !     if(dir_opts & SUPPRESS_SIZE) maxsize += 7;
  282. !     for(x=0;desc[x] && maxsize;x++) {
  283. !         if(desc[x] == '<') {
  284. !             while(desc[x] != '>') {
  285. !                 if(!desc[x]) {
  286. !                     maxsize = 0;
  287. !                     break;
  288. !                 }
  289. !                 ++x;
  290. !             }
  291. !         }
  292. !         else --maxsize;
  293. !     }
  294. !     if(!maxsize) {
  295. !         desc[x-1] = '>';    /* Grump. */
  296. !     desc[x] = '\0';        /* Double Grump! */
  297. !     }
  298. !     return desc;
  299.   }
  300.   
  301.   void output_directories(struct ent **ar, int n,
  302. !             dir_config_rec *d, request_rec *r, int dir_opts)
  303.   {
  304.       int x, len;
  305.       char *name = r->uri;
  306.       char *tp;
  307.       pool *scratch = make_sub_pool (r->pool);
  308.       
  309.       if(name[0] == '\0') name = "/";
  310.   
  311.       if(dir_opts & FANCY_INDEXING) {
  312. !         rputs("<PRE>", r);
  313.           if((tp = find_default_icon(d,"^^BLANKICON^^")))
  314. !             rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
  315. !            "\" ALT=\"     \"> ", NULL);
  316. !         rputs("Name                   ", r);
  317.           if(!(dir_opts & SUPPRESS_LAST_MOD))
  318. !             rputs("Last modified     ", r);
  319.           if(!(dir_opts & SUPPRESS_SIZE))
  320. !             rputs("Size  ", r);
  321. !         if(!(dir_opts & SUPPRESS_DESC))
  322. !             rputs("Description", r);
  323. !         rputs("\n<HR>\n", r);
  324.       }
  325.       else {
  326. !         rputs("<UL>", r);
  327.       }
  328.           
  329. !     for(x=0;x<n;x++) {
  330.       char *anchor = NULL, *t = NULL, *t2 = NULL;
  331.       
  332.       clear_pool (scratch);
  333.       
  334. !         if((!strcmp(ar[x]->name,"../")) || (!strcmp(ar[x]->name,".."))) {
  335.               char *t = make_full_path (scratch, name, "../");
  336. !             getparents(t);
  337. !             if(t[0] == '\0') t = "/";
  338. !         anchor = pstrcat (scratch, "<A HREF=\"",
  339. !                   escape_html(scratch, os_escape_path(scratch, t, 0)),
  340. !                   "\">", NULL);
  341. !         t2 = "Parent Directory</A>       ";
  342.           }
  343.           else {
  344.           t = ar[x]->name;
  345. !         len = strlen(t);
  346. !             if(len > 23) {
  347. !         t2 = pstrdup(scratch, t);
  348. !         t2[21] = '.';
  349. !         t2[22] = '.';
  350. !                 t2[23] = '\0';
  351. !         t2 = escape_html(scratch, t2);
  352. !         t2 = pstrcat(scratch, t2, "</A>", NULL);
  353. !             } else 
  354. !         {
  355. !         char buff[24]="                       ";
  356. !         t2 = escape_html(scratch, t);
  357. !         buff[23-len] = '\0';
  358. !         t2 = pstrcat(scratch, t2, "</A>", buff, NULL);
  359. !         }
  360. !         anchor = pstrcat (scratch, "<A HREF=\"",
  361. !                   escape_html(scratch, os_escape_path(scratch, t, 0)),
  362. !                   "\">", NULL);
  363.           }
  364.   
  365. !         if(dir_opts & FANCY_INDEXING) {
  366. !             if(dir_opts & ICONS_ARE_LINKS)
  367. !                 rputs(anchor, r);
  368. !             if((ar[x]->icon) || d->default_icon) {
  369. !                 rvputs(r, "<IMG SRC=\"", 
  370. !                escape_html(scratch, ar[x]->icon ?
  371. !                    ar[x]->icon : d->default_icon),
  372. !                "\" ALT=\"[", (ar[x]->alt ? ar[x]->alt : "   "),
  373. !                "]\">", NULL);
  374.               }
  375. !             if(dir_opts & ICONS_ARE_LINKS) 
  376. !                 rputs("</A>", r);
  377.   
  378. !             rvputs(r," ", anchor, t2, NULL);
  379. !             if(!(dir_opts & SUPPRESS_LAST_MOD)) {
  380. !                 if(ar[x]->lm != -1) {
  381.               char time[MAX_STRING_LEN];
  382.                       struct tm *ts = localtime(&ar[x]->lm);
  383.                       strftime(time,MAX_STRING_LEN,"%d-%b-%y %H:%M  ",ts);
  384. --- 638,845 ----
  385.       return(p);
  386.   }
  387.   
  388. ! /*
  389. ! ** This routine sizes the specified text into the output buffer.  If the text
  390. ! ** is larger than the specified maximum width, it is truncated and the tail
  391. ! ** end is replaced with the overflow text (as much as will fit).  The suffix
  392. ! ** buffer is filled with enough spaces to reach the specified width whn added
  393. ! ** to the output buffer.  Naturally, the assumption is made that the buffers
  394. ! ** are at least as wide as the maximum width plus one.  We use the suffix
  395. ! ** buffer as a work area before finally filling it with the right number of
  396. ! ** spaces.
  397. ! */
  398. ! void *size_field
  399. !     (
  400. !         char *buffer,        /* Buffer into which text is to be sized */
  401. !         char *suffix,        /* Preallocated working/suffix buffer */
  402. !         int width,            /* Maximum width of text in buffer */
  403. !         char *contents,        /* Text to be inserted */
  404. !         char *overflow        /* Suffix if text is too long */
  405. !     ) {
  406. !     int content_len = strlen (contents);
  407. !     int overflow_len = strlen (overflow);
  408. !     int actual_len = (content_len < width) ? content_len : width;
  409. !     int suffix_len = (width < overflow_len) ? width : overflow_len;
  410. !     strcpy (buffer, contents);
  411. !     if (content_len > width) {
  412. !     int i;
  413. !     char *s1 = overflow;
  414. !     char *s2;
  415. !     s2 = &buffer[width-suffix_len];
  416. !     for (i = 0; i < suffix_len; i++) {
  417. !         *s2++ = *s1++;
  418. !     };
  419. !     *s2 = '\0';
  420. !     };
  421. !     /*
  422. !     ** At this point, the output buffer contains the (possibly truncated) input
  423. !     ** string.  Put the right number of blanks into the suffix buffer.
  424. !     */
  425. !     sprintf (suffix, "%*s", (width - actual_len), "");
  426. !     return NULL;
  427.   }
  428.   
  429.   void output_directories(struct ent **ar, int n,
  430. !             dir_config_rec *d, request_rec *r, int dir_opts,
  431. !             int name_width, int desc_width)
  432.   {
  433.       int x, len;
  434. +     int nwidth = name_width;
  435. +     int dwidth = desc_width;
  436. +     int total_width;
  437.       char *name = r->uri;
  438.       char *tp;
  439. +     char *name_buff, *space_buff;
  440.       pool *scratch = make_sub_pool (r->pool);
  441.       
  442. +     if (nwidth == 0) {
  443. +     nwidth = DEFAULT_NAME_WIDTH;
  444. +     };
  445. +     /*
  446. +      * Figure out how wide the description can be.  If we're suppressing any
  447. +      * of the other fields, add their widths to this.
  448. +      */
  449. +     if (dwidth == 0) {
  450. +     dwidth = DEFAULT_DESC_WIDTH;
  451. +     if (dir_opts & SUPPRESS_LAST_MOD) dwidth += 17;
  452. +     if (dir_opts & SUPPRESS_SIZE) dwidth += 7;
  453. +     };
  454. +     /*
  455. +      * Make sure we allocate space for the largest resizable item we'll need.
  456. +      * This is static for the duration of the request, so we allocate it from
  457. +      * the request pool rather than the subpool.
  458. +      */
  459. +     len = (nwidth > dwidth) ? nwidth : dwidth;
  460. +     name_buff = (char *) palloc (r->pool, len + 5);
  461. +     space_buff = (char *) palloc (r->pool, len + 5);
  462.       if(name[0] == '\0') name = "/";
  463.   
  464.       if(dir_opts & FANCY_INDEXING) {
  465. !         rputs ("  <PRE", r);
  466. !     total_width = nwidth;
  467. !     if (! (dir_opts & SUPPRESS_LAST_MOD)) {
  468. !         total_width += LAST_MOD_WIDTH;
  469. !     };
  470. !     if (! (dir_opts & SUPPRESS_SIZE)) {
  471. !         total_width += SIZE_WIDTH;
  472. !     };
  473. !     if (! (dir_opts & SUPPRESS_DESC)) {
  474. !         total_width += dwidth;
  475. !     };
  476. !     if (total_width > 80) {
  477. !         sprintf (name_buff, " WIDTH=%d", total_width);
  478. !         rputs (name_buff, r);
  479. !     };
  480. !         rputs (">", r);
  481.           if((tp = find_default_icon(d,"^^BLANKICON^^")))
  482. !             rvputs
  483. !         (
  484. !             r,
  485. !             "<IMG SRC=\"",
  486. !             escape_html (scratch, tp),
  487. !             "\" ALT=\"     \"> ",
  488. !             NULL
  489. !         );
  490. !     size_field (name_buff, space_buff, nwidth, "Name", "..");
  491. !     rvputs (r, name_buff, space_buff, " ", NULL);
  492.           if(!(dir_opts & SUPPRESS_LAST_MOD))
  493. !             rputs ("Last modified    ", r);
  494.           if(!(dir_opts & SUPPRESS_SIZE))
  495. !             rputs (" Size  ", r);
  496. !         if (!(dir_opts & SUPPRESS_DESC)) {
  497. !         size_field (name_buff, space_buff, dwidth, "Description", "..");
  498. !             rputs (name_buff, r);
  499. !     };
  500. !         rputs("\n  <HR>\n", r);
  501.       }
  502.       else {
  503. !         rputs("  <UL>\n", r);
  504.       }
  505.           
  506. !     for (x = 0; x < n; x++) {
  507.       char *anchor = NULL, *t = NULL, *t2 = NULL;
  508.       
  509.       clear_pool (scratch);
  510.       
  511. !         if ((!strcmp (ar[x]->name, "../")) || (!strcmp (ar[x]->name, ".."))) {
  512.               char *t = make_full_path (scratch, name, "../");
  513. !             getparents (t);
  514. !             if (t[0] == '\0') t = "/";
  515. !         anchor = pstrcat
  516. !             (
  517. !                 scratch,
  518. !                 "<A HREF=\"",
  519. !                 escape_html
  520. !                 (
  521. !                     scratch,
  522. !                     os_escape_path (scratch, t, 0)
  523. !                 ),
  524. !                 "\">",
  525. !                 NULL
  526. !             );
  527. !         if (dir_opts & FANCY_INDEXING) {
  528. !         size_field
  529. !             (
  530. !             name_buff,
  531. !             space_buff,
  532. !             nwidth,
  533. !             "Parent Directory",
  534. !             ".."
  535. !             );
  536. !         t2 = name_buff;
  537. !         } else {
  538. !         t2 = "Parent Directory";
  539. !         space_buff[0] = '\0';
  540. !         };
  541.           }
  542.           else {
  543.           t = ar[x]->name;
  544. !         len = strlen (t);
  545. !         t2 = escape_html (scratch, t);
  546. !         anchor = pstrcat
  547. !             (
  548. !                 scratch,
  549. !                 "<A HREF=\"",
  550. !                 escape_html
  551. !                 (
  552. !                     scratch,
  553. !                     os_escape_path (scratch, t, 0)
  554. !                 ),
  555. !                 "\">",
  556. !                 NULL
  557. !             );
  558.           }
  559.   
  560. !         if (dir_opts & FANCY_INDEXING) {
  561. !             if (dir_opts & ICONS_ARE_LINKS)
  562. !                 rputs (anchor, r);
  563. !             if ((ar[x]->icon) || d->default_icon) {
  564. !                 rvputs
  565. !             (
  566. !             r,
  567. !             "  <IMG SRC=\"",
  568. !             escape_html
  569. !                 (
  570. !                 scratch,
  571. !                 ar[x]->icon ? ar[x]->icon : d->default_icon
  572. !                 ),
  573. !             "\" ALT=\"[",
  574. !             (ar[x]->alt ? ar[x]->alt : "   "),
  575. !             "]\">",
  576. !             NULL
  577. !             );
  578.               }
  579. !             if (dir_opts & ICONS_ARE_LINKS) 
  580. !                 rputs ("</A>", r);
  581.   
  582. !             size_field (name_buff, space_buff, nwidth, t2, "..");
  583. !         rvputs (r, " ", anchor, name_buff, "</A>", space_buff, " ", NULL);
  584. !             if (!(dir_opts & SUPPRESS_LAST_MOD)) {
  585. !                 if (ar[x]->lm != -1) {
  586.               char time[MAX_STRING_LEN];
  587.                       struct tm *ts = localtime(&ar[x]->lm);
  588.                       strftime(time,MAX_STRING_LEN,"%d-%b-%y %H:%M  ",ts);
  589. ***************
  590. *** 647,679 ****
  591.               rputs(time, r);
  592.                   }
  593.                   else {
  594. !                     rputs("                 ", r);
  595.                   }
  596.               }
  597. !             if(!(dir_opts & SUPPRESS_SIZE)) {
  598. !                 send_size(ar[x]->size,r);
  599. !                 rputs("  ", r);
  600.               }
  601.               if(!(dir_opts & SUPPRESS_DESC)) {
  602. !                 if(ar[x]->desc) {
  603. !                     rputs(terminate_description(d, ar[x]->desc, dir_opts), r);
  604.                   }
  605.               }
  606.           }
  607.           else
  608. !             rvputs(r, "<LI> ", anchor," ", t2, NULL);
  609. !         rputc('\n', r);
  610.       }
  611.       if(dir_opts & FANCY_INDEXING) {
  612. !         rputs("</PRE>", r);
  613.       }
  614.       else {
  615. !         rputs("</UL>", r);
  616.       }
  617.   }
  618.   
  619.   
  620. ! int dsortf(struct ent **s1,struct ent **s2)
  621.   {
  622.       return(strcmp((*s1)->name,(*s2)->name));
  623.   }
  624. --- 846,886 ----
  625.               rputs(time, r);
  626.                   }
  627.                   else {
  628. !                     rputs ("                 ", r);
  629.                   }
  630.               }
  631. !             if (!(dir_opts & SUPPRESS_SIZE)) {
  632. !                 send_size (ar[x]->size, r);
  633. !                 rputs ("  ", r);
  634.               }
  635.               if(!(dir_opts & SUPPRESS_DESC)) {
  636. !                 if (ar[x]->desc) {
  637. !             size_field
  638. !             (
  639. !                 name_buff,
  640. !                 space_buff,
  641. !                 dwidth,
  642. !                 ar[x]->desc,
  643. !                 ".."
  644. !             );
  645. !                     rputs (name_buff, r);
  646.                   }
  647.               }
  648.           }
  649.           else
  650. !             rvputs (r, "   <LI> ", anchor," ", t2, "</A>", NULL);
  651. !         rputc ('\n', r);
  652.       }
  653.       if(dir_opts & FANCY_INDEXING) {
  654. !         rputs ("  </PRE>\n", r);
  655.       }
  656.       else {
  657. !         rputs ("  </UL>\n", r);
  658.       }
  659.   }
  660.   
  661.   
  662. ! int dsortf (struct ent **s1, struct ent **s2)
  663.   {
  664.       return(strcmp((*s1)->name,(*s2)->name));
  665.   }
  666. ***************
  667. *** 692,697 ****
  668. --- 899,906 ----
  669.       struct ent **ar = NULL;
  670.       char *tmp;
  671.       int dir_opts = find_opts(dir_conf, r);
  672. +     int name_width = find_name_width (dir_conf, r);
  673. +     int desc_width = find_desc_width (dir_conf, r);
  674.   
  675.       if(!(d=opendir(name))) return FORBIDDEN;
  676.   
  677. ***************
  678. *** 712,722 ****
  679.       while (title_endp > title_name && *title_endp == '/')
  680.       *title_endp-- = '\0';
  681.       
  682. !     rvputs(r, "<HEAD><TITLE>Index of ", title_name, "</TITLE></HEAD><BODY>\n",
  683. !        NULL);
  684.   
  685.       if((!(tmp = find_header(dir_conf,r))) || (!(insert_readme(name,tmp,0,r))))
  686. !         rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
  687.   
  688.       /* 
  689.        * Since we don't know how many dir. entries there are, put them into a 
  690. --- 921,940 ----
  691.       while (title_endp > title_name && *title_endp == '/')
  692.       *title_endp-- = '\0';
  693.       
  694. !     rvputs
  695. !     (
  696. !         r,
  697. !         "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n",
  698. !         "<HTML>\n",
  699. !         " <HEAD>\n",
  700. !         "  <TITLE>Index of ", title_name, "</TITLE>\n",
  701. !         " </HEAD>\n",
  702. !         " <BODY>\n",
  703. !         NULL
  704. !     );
  705.   
  706.       if((!(tmp = find_header(dir_conf,r))) || (!(insert_readme(name,tmp,0,r))))
  707. !         rvputs(r, "  <H1>Index of ", title_name, "</H1>\n", NULL);
  708.   
  709.       /* 
  710.        * Since we don't know how many dir. entries there are, put them into a 
  711. ***************
  712. *** 746,752 ****
  713.             (int (*)(const void *,const void *))dsortf);
  714.   #endif
  715.       }
  716. !     output_directories(ar, num_ent, dir_conf, r, dir_opts);
  717.       closedir(d);
  718.   
  719.       if (dir_opts & FANCY_INDEXING)
  720. --- 964,979 ----
  721.             (int (*)(const void *,const void *))dsortf);
  722.   #endif
  723.       }
  724. !     output_directories
  725. !     (
  726. !         ar,
  727. !         num_ent,
  728. !         dir_conf,
  729. !         r,
  730. !         dir_opts,
  731. !         name_width,
  732. !         desc_width
  733. !     );
  734.       closedir(d);
  735.   
  736.       if (dir_opts & FANCY_INDEXING)
  737. ***************
  738. *** 753,762 ****
  739.           if((tmp = find_readme(dir_conf, r)))
  740.               insert_readme(name,tmp,1,r);
  741.       else {
  742. !         rputs("</UL>", r);
  743.       }
  744.   
  745. !     rputs("</BODY>", r);
  746.       return 0;
  747.   }
  748.   
  749. --- 980,989 ----
  750.           if((tmp = find_readme(dir_conf, r)))
  751.               insert_readme(name,tmp,1,r);
  752.       else {
  753. !         rputs("  </UL>", r);
  754.       }
  755.   
  756. !     rvputs (r, " </BODY>\n", "</HTML>\n", NULL);
  757.       return 0;
  758.   }
  759.   
  760. Index: util_script.h
  761. ===================================================================
  762. *** 1.1    1997/01/01 01:49:37
  763. --- util_script.h    1997/01/02 12:22:53
  764. ***************
  765. *** 65,70 ****
  766. --- 65,74 ----
  767.   void add_common_vars(request_rec *r);
  768.   #define scan_script_header(a1,a2) scan_script_header_err(a1,a2,NULL)
  769.   int scan_script_header_err(request_rec *r, FILE *f, char *buffer);
  770. + /*
  771. +  * Define the canonical width of the output from the send_size () routine.
  772. +  */
  773. + #define SEND_SIZE_CHARS 5
  774.   void send_size(size_t size, request_rec *r);
  775.   void call_exec (request_rec *r, char *argv0, char **env, int shellcmd);
  776.   
  777. Index: util_script.c
  778. ===================================================================
  779. *** 1.1    1997/01/01 04:28:30
  780. --- util_script.c    1997/01/02 12:24:54
  781. ***************
  782. *** 376,397 ****
  783.       }
  784.   }
  785.   
  786. ! void send_size(size_t size, request_rec *r) {
  787.       char ss[20];
  788.   
  789. !     if(size == -1) 
  790. !         strcpy(ss, "    -");
  791. !     else if(!size) 
  792. !         strcpy(ss, "   0k");
  793. !     else if(size < 1024) 
  794. !         strcpy(ss, "   1k");
  795. !     else if(size < 1048576)
  796. !         sprintf(ss, "%4dk", (size + 512) / 1024);
  797. !     else if(size < 103809024)
  798. !     sprintf(ss, "%4.1fM", size / 1048576.0);
  799.       else
  800. !         sprintf(ss, "%4dM", (size + 524288) / 1048576);
  801. !     rputs(ss, r);
  802.   }
  803.   
  804.   #ifdef __EMX__
  805. --- 376,410 ----
  806.       }
  807.   }
  808.   
  809. ! /*
  810. ! ** This routine converts the specified value into an abbreviated character
  811. ! ** representation (e.g., in kilo- or mega-units).  The result is emitted to
  812. ! ** the output stream.  The size of the output is fixed; if this routine is
  813. ! ** changed to output more or fewer characters, be sure to update the
  814. ! ** SEND_SIZE_CHARS definition in util_script.h, which makes this width
  815. ! ** available to calling routines that want to line things up.
  816. ! */
  817. ! #define SIZE_1K 1024
  818. ! #define SIZE_1M (SIZE_1K * SIZE_1K)
  819. ! #define SIZE_500K (SIZE_1M / 2)
  820. ! #define SIZE_1G (SIZE_1M * SIZE_1K)
  821. ! #define SIZE_500M (SIZE_1G / 2)
  822. ! void send_size (size_t size, request_rec *r) {
  823.       char ss[20];
  824.   
  825. !     if (size == -1) 
  826. !         strcpy (ss, "    -");
  827. !     else if (!size) 
  828. !         strcpy (ss, "   0k");
  829. !     else if (size < SIZE_1K) 
  830. !         strcpy (ss, "   1k");
  831. !     else if (size < SIZE_1M)
  832. !         sprintf (ss, "%4dk", (size + 512) / SIZE_1K);
  833. !     else if (size < (SIZE_1M * 100))
  834. !     sprintf (ss, "%4.1fM", ((float) size / (float) SIZE_1M));
  835.       else
  836. !         sprintf (ss, "%4dM", (size + SIZE_500K) / SIZE_1M);
  837. !     rputs (ss, r);
  838.   }
  839.   
  840.   #ifdef __EMX__
  841.  
  842. Index: mod_dir.html
  843. ===================================================================
  844. *** 1.1    1997/01/05 18:42:12
  845. --- mod_dir.html    1997/01/05 23:08:42
  846. ***************
  847. *** 39,45 ****
  848. --- 39,47 ----
  849.   <li><A HREF="#directoryindex">DirectoryIndex</A>
  850.   <li><A HREF="#fancyindexing">FancyIndexing</A>
  851.   <li><A HREF="#headername">HeaderName</A>
  852. + <li><A HREF="#indexdescwidth">IndexDescWidth</A>
  853.   <li><A HREF="#indexignore">IndexIgnore</A>
  854. + <li><A HREF="#indexnamewidth">IndexNameWidth</A>
  855.   <li><A HREF="#indexoptions">IndexOptions</A>
  856.   <li><A HREF="#readmename">ReadmeName</A>
  857.   </menu>
  858. ***************
  859. *** 207,212 ****
  860. --- 209,254 ----
  861.   
  862.   <p>See also <A HREF="#readmename">ReadmeName</A>.<p><hr>
  863.   
  864. + <A NAME="indexdescwidth">
  865. +  <H2>IndexDescWidth</H2>
  866. + </A>
  867. + <!--%plaintext <?INDEX {\tt IndexDescWidth} directive> -->
  868. + <STRONG>Syntax:</STRONG> IndexDescWidth <EM>number</EM>
  869. + <BR>
  870. + <STRONG>Context:</STRONG> server config, virtual host, directory, .htaccess
  871. + <BR>
  872. + <STRONG>Override:</STRONG> Indexes
  873. + <BR>
  874. + <STRONG>Status:</STRONG> Base
  875. + <BR>
  876. + <STRONG>Module:</STRONG> mod_dir
  877. + <P>
  878. + The IndexDescWidth sets a specific width for the description field in
  879. + FancyIndexed directory listings.  By default, the width of this field
  880. + depends upon what other options are selected; SuppressLastModified and
  881. + SuppressSize will cause more space to be available for the description.
  882. + Using IndexDescWidth overrides this adjustment and allocates the
  883. + specified number of columns for the descriptive text.
  884. + <EM>Number</EM> is a decimal number
  885. + indicating exactly how wide the field should be.
  886. + Descriptions which are too long will be truncated.
  887. + Example:
  888. + <BLOCKQUOTE>
  889. +  <CODE>
  890. +   IndexDescWidth 32
  891. +  </CODE>
  892. + </BLOCKQUOTE>
  893. + </P>
  894. + <P>
  895. + See also
  896. + <A HREF="#adddescription">AddDescription</A>,
  897. + <A HREF="#indexnamewidth">IndexNameWidth</A>,
  898. + <A HREF="#indexoptions">IndexOptions</A>,
  899. + and
  900. + <A HREF="#fancyindexing">FancyIndexing</A>.
  901. + </P>
  902. + <HR>
  903.   <A name="indexignore"><h2>IndexIgnore</h2></A>
  904.   <!--%plaintext <?INDEX {\tt IndexIgnore} directive> -->
  905.   <strong>Syntax:</strong> IndexIgnore <em>file file ...</em><br>
  906. ***************
  907. *** 224,229 ****
  908. --- 266,309 ----
  909.   IndexIgnore README .htaccess *~
  910.   </code></blockquote><p><hr>
  911.   
  912. + <A NAME="indexnamewidth">
  913. +  <H2>IndexNameWidth</H2>
  914. + </A>
  915. + <!--%plaintext <?INDEX {\tt IndexNameWidth} directive> -->
  916. + <STRONG>Syntax:</STRONG> IndexNameWidth <EM>number</EM>
  917. + <BR>
  918. + <STRONG>Context:</STRONG> server config, virtual host, directory, .htaccess
  919. + <BR>
  920. + <STRONG>Override:</STRONG> Indexes
  921. + <BR>
  922. + <STRONG>Status:</STRONG> Base
  923. + <BR>
  924. + <STRONG>Module:</STRONG> mod_dir
  925. + <P>
  926. + The IndexNameWidth sets a specific width for the filename field in
  927. + FancyIndexed directory listings.  By default, this field is 23 columns
  928. + wide.  Using IndexNameWidth overrides this default width and allocates the
  929. + specified number of columns for the filename.
  930. + <EM>Number</EM> is a decimal number
  931. + indicating how wide the field should be.  Filenames which are longer
  932. + than this value will be truncated and "<SAMP>..</SAMP>"
  933. + substituted for the overflow.
  934. + Example:
  935. + <BLOCKQUOTE>
  936. +  <CODE>
  937. +   IndexNameWidth 32
  938. +  </CODE>
  939. + </BLOCKQUOTE>
  940. + </P>
  941. + <P>
  942. + See also
  943. + <A HREF="#indexdescwidth">IndexDescWidth</A>,
  944. + <A HREF="#indexoptions">IndexOptions</A>,
  945. + and
  946. + <A HREF="#fancyindexing">FancyIndexing</A>.
  947. + </P>
  948. + <HR>
  949.   <A name="indexoptions"><h2>IndexOptions</h2></A>
  950.   <!--%plaintext <?INDEX {\tt IndexOptions} directive> -->
  951.   <strong>Syntax:</strong> IndexOptions <em>option option ...</em><br>
  952.  
  953. Index: directives.html
  954. ===================================================================
  955. *** 1.1    1997/01/05 22:46:43
  956. --- directives.html    1997/01/05 23:07:57
  957. ***************
  958. *** 78,84 ****
  959. --- 78,86 ----
  960.   <li><A HREF="mod_imap.html#imapbase">ImapBase</A>
  961.   <li><A HREF="mod_imap.html#imapdefault">ImapDefault</A>
  962.   <li><A HREF="mod_imap.html#imapmenu">ImapMenu</A>
  963. + <li><A HREF="mod_dir.html#indexdescwidth">IndexDescWidth</A>
  964.   <li><A HREF="mod_dir.html#indexignore">IndexIgnore</A>
  965. + <li><A HREF="mod_dir.html#indexnamewidth">IndexNameWidth</A>
  966.   <li><A HREF="mod_dir.html#indexoptions">IndexOptions</A>
  967.   <li><A HREF="core.html#keepalive">KeepAlive</A>
  968.   <li><A HREF="core.html#keepalivetimeout">KeepAliveTimeout</A>
  969.