home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / f / flist24.zip / FLIST.C next >
Text File  |  1993-01-10  |  33KB  |  1,037 lines

  1. /*
  2.  
  3. FLIST -- Generates file lists based on privilege levels and keys
  4.  
  5. Version 2.4   (1/10/93)
  6.  
  7. Written by Bob Quinlan of Austin, Texas, USA
  8. Sysop of Red October at 512-834-2593 (1:382/111)
  9. Special thanks to David Powers for suggestions and code.
  10.  
  11. Copyright 1993 by Bob Quinlan
  12.  
  13. Compatible with Maximus 2.00 and 2.01
  14.  
  15.  
  16. This program generates a list of files that a user with a particular
  17. privilege level and set of keys could access.  It is intended to make
  18. the procedure independent of changes to the structure of your file
  19. areas.  Instead of specifying which areas should be included you just
  20. specify what sort of user you want the list to apply to.
  21.  
  22. You can also create lists of new files.  Just use /D to specify how many
  23. days of files you want to list.
  24.  
  25.     /Afile      Area file.  You can use this to specify a path to
  26.                 AREA.DAT or to refer to another file (although it must
  27.                 follow the AREA.DAT format).  The filename must be
  28.                 included along with the path.  Defaults to AREA.DAT in
  29.                 the current directory.
  30.  
  31.     /B          Include barricaded areas.  If this switch is not
  32.                 included no barricaded areas will be included.
  33.  
  34.     /C          Include comments from the FILES.BBS file lists.  By
  35.                 default only files and their descriptions are included.
  36.  
  37.                 Using this switch has one side-effect!  Normally area
  38.                 headers are only generated for areas that have files in
  39.                 them.  /C will cause them to be generated for any area
  40.                 that has comments as well.  Do not use /C if you only
  41.                 want areas that have files in them to appear!  (I
  42.                 recommend not using /C with /D so that you don't show
  43.                 lots of apparently empty file areas.)
  44.  
  45.     /Ddays      Days.  Excludes all files more than this many days old.
  46.                 Use this switch to create lists of new files.
  47.  
  48.     /Ffile      Output file.  The pathname of the file you want the file
  49.                 list written to.  Defaults to FLIST.TXT in the current
  50.                 area.
  51.  
  52.     /HAfile     Area header file.  The contents of this file will be
  53.                 added to the report for each area header.  There are
  54.                 several sequences you can embed in the file that have
  55.                 special meanings.  All of the codes explained under /HS
  56.                 are allowed except for %C and %B.
  57.  
  58.                 If no area header file is specified a default header
  59.                 will be used.
  60.  
  61.     /HBfile     Beginning header file.  The contents of this file will
  62.                 be added to the beginning of the report.  There are
  63.                 several sequences you can embed in the file that have
  64.                 special meanings.  The codes %D, %T, and %A (explained
  65.                 under /HS) are allowed.
  66.  
  67.     /HEfile     End header file.  The contents of this file will be
  68.                 added to the end of the report.  There are several
  69.                 sequences you can embed in the file that have special
  70.                 meanings.  The codes %F, %S, %D, %T, and %A (explained
  71.                 under /HS) are allowed.
  72.  
  73.     /HSfile     Area summary header file.  The contents of this file
  74.                 will be added to the report after each area.  There are
  75.                 several sequences you can embed in the file that have
  76.                 special meanings:
  77.  
  78.                     %N will be replaced with the area name.
  79.                     %I will be replaced with the area information.
  80.                     %C will be replaced with the area file count.
  81.                     %B will be replaced with the area file size total (bytes).
  82.                     %F will be replaced with the overall file count.
  83.                     %S will be replaced with the overall file size total.
  84.                     %D will be replaced with the report date.
  85.                     %T will be replaced with the report time.
  86.                     %A will be replaced with the age of the files
  87.                        included in the report.  Do not use this except
  88.                        with the /D command line parameter!
  89.  
  90.                     Any of these may be followed by an L, R, or C
  91.                     immediately followed by a number.  These will left,
  92.                     right, or center justify the value in a field of the
  93.                     specified width.
  94.  
  95.                     You can also follow any of the above with an NF or
  96.                     with an Fx.  NF stands for "no fill" and has no
  97.                     effect (see examples).  Fx stands for "fill" and
  98.                     will cause the entire field to be replaced by an
  99.                     equivalent number of the character 'x'.  This is
  100.                     useful when drawing boxes.
  101.  
  102.     /Kkeys      Keys to use for access to locked areas.  Keys are
  103.                 represented by 1-8 and A-X.  An asterisk (*) turns on
  104.                 all of the keys.  Multiple keys can be specified in one
  105.                 /K argument (such as /K12B).
  106.  
  107.     /N          No-wrap.  Leave long description lines intact.  The
  108.                 default is to wrap them.
  109.  
  110.     /O          Include offline files.  By default files that are listed
  111.                 but not present are not included in the list.
  112.  
  113.     /Ppriv      Privilege to use for access to areas.  Only the first
  114.                 letter of the level name is required.  Legal values are:
  115.                     Twit
  116.                     Disgrace
  117.                     Limited
  118.                     Normal
  119.                     Worthy
  120.                     Privil
  121.                     Favored
  122.                     Extra
  123.                     Clerk
  124.                     AsstSysop
  125.                     Sysop
  126.                     Hidden
  127.                 Defaults to Normal.
  128.  
  129.     /T          Truncate long description lines.  The default is to wrap
  130.                 them.
  131.  
  132.     /Vcount     Volume.  'count' is the number of files each dot stands
  133.                 for in the progress indicator.  Zero will turn off all
  134.                 progress displays.
  135.  
  136.     /Wcolumn    Wrap column.  Sets line wrapping to the specified column
  137.                 relative to the left margin.
  138.  
  139. Let me show you an example of how to use the %N and %I parameters in an
  140. area header file (defined with the /HA switch).  The purpose of those
  141. parameters is to let you build boxes that will conform to the size of
  142. the text produced by %N and %I.  Here is an example of a simple header
  143. box using these parameters:
  144.  
  145. ┌──%NF───┬──%IF───┐
  146. │  %NNF  │  %INF  │
  147. └──%NF───┴──%IF───┘
  148.  
  149. Note that the characters following the %NF and %IF look like a part of
  150. the regular text, but are actually the characters that will be used to
  151. fill out the parameters to the desired length.
  152.  
  153. This will expand to something that looks like this:
  154.  
  155. ┌───────┬───────────────────────────────────────────┐
  156. │  MAX  │  Maximus BBS files and related utilities  │
  157. └───────┴───────────────────────────────────────────┘
  158.  
  159. Now you can see why the apparently useless NF modifier can be useful. It
  160. pads out the shorter embedded codes so that they visually match those in
  161. the surrounding lines.  The following would produce exactly the same
  162. result as the previous example, but it is a lot harder to figure out how
  163. everything will match up:
  164.  
  165. ┌──%NF───┬──%IF───┐
  166. │  %N  │  %I  │
  167. └──%NF───┴──%IF───┘
  168.  
  169. Here is an example using fixed width fields.  This also right justifies
  170. the area name and left justifies the area information:
  171.  
  172. ┌─%NR9F──┬─%IL50F──┐
  173. │ %NR9NF │ %IL50NF │
  174. └─%NR9F──┴─%IL50F──┘
  175.  
  176. Which will expand to something that looks like this:
  177.  
  178. ┌───────────┬────────────────────────────────────────────────────┐
  179. │       MAX │ Maximus BBS files and related utilities            │
  180. └───────────┴────────────────────────────────────────────────────┘
  181.  
  182.  
  183. FLIST returns the following ERRORLEVELS:
  184.     0 = success
  185.     1 = bad command line parameter
  186.     2 = unable to open AREA.DAT
  187.     3 = unable to open header file
  188.     4 = unable to open output file
  189.     5 = not enough memory to run
  190.     6 = string overflow processing header
  191.  
  192. NOTICE:  You may use, copy, and distribute this program freely as long
  193. as you insure that both the executable and the documentation (.DOC)
  194. files are included in the distribution package.  The source code does
  195. not need to be included.  You may modify this program and document, so
  196. long as reasonable credit is given to the original author if a
  197. substantial portion of the original remains intact.  The author is not
  198. responsible for any losses which may occur either directly or indirectly
  199. as a result of using this program.
  200.  
  201. This program uses the Maximus structures written by Scott J. Dudley.
  202.  
  203. HISTORY:
  204. Version 2.4   (1/10/93) -- Added the /HS option to allow customized area
  205.                            summary headers in the report.  Added new
  206.                            embedded variables for total and area file
  207.                            counts and file sizes.  Fixed a bug that
  208.                            occurred when inappropriate replacement codes
  209.                            were used in a header.
  210. Version 2.3   (1/10/93) -- Added /W parameter to allow line-wrapping to
  211.                            different lengths.  List "offline" as the
  212.                            size for offline file entries.
  213. Version 2.2  (11/04/92) -- Fixed minor date offsets caused by default
  214.                            timezone and daylight savings adjustments.
  215.                            Added the /V switch to limit screen output.
  216.                            /V0 replaces the /Q switch.
  217. Version 2.1   (8/26/92) -- Added the /Q switch to eliminate the progress
  218.                            display.  Now returns different errorlevels
  219.                            for each possible error.  Fixed problem with
  220.                            headers before comments.
  221. Version 2.0   (8/23/92) -- Added more error checking.
  222. Version 1.9   (8/22/92) -- Added a progress display.  Fixed a memory
  223.                            corruption bug.
  224. Version 1.8   (8/20/92) -- Added fixed width fields with left, right,
  225.                            and centered justification for embedded
  226.                            variables.  Changed the previous codes for
  227.                            embedded variables!  Removed built-in help to
  228.                            reduce memory requirements.
  229. Version 1.7   (8/10/92) -- Added embedded variables to the begin and end
  230.                            headers.  Note: This eliminated the automatic
  231.                            file age comment that used to be included for
  232.                            newfile lists.
  233. Version 1.6   (8/10/92) -- Added the /HA option to allow customized area
  234.                            headers in the report.  This is an expansion
  235.                            of an idea and code by David Powers.
  236. Version 1.5   (8/09/92) -- Added the /HB and /HE options to allow
  237.                            customized beginning and end text in the
  238.                            report.  Added /? help option to print the
  239.                            parameter list.  Added a clearer explanation
  240.                            of /C's effect on area headers.
  241. Version 1.4   (8/07/92) -- Added the /C option to include file list
  242.                            comments.  Added code to recognize free
  243.                            switches so they do not show up in the
  244.                            descriptions.  Fixed error if first entry in
  245.                            AREA.DAT did not include a file area.
  246. Version 1.3   (8/06/92) -- Read the file list filename from AREA.DAT
  247.                            instead of assuming FILES.BBS.
  248. Version 1.2   (8/02/92) -- Added days header for new files list.
  249. Version 1.1   (7/30/92) -- Added file age cutoff.
  250. Version 1.0   (6/30/92) -- Original release.  Written in Borland C.
  251.  
  252. Large memory model
  253. */
  254.  
  255.  
  256. #include <ctype.h>
  257. #include <dos.h>
  258. #include <fcntl.h>
  259. #include <io.h>
  260. #include <share.h>
  261. #include <stdio.h>
  262. #include <stdlib.h>
  263. #include <string.h>
  264. #include <sys\stat.h>
  265. #include <time.h>
  266. #include <mstruct.h>  /*  Maximus structures by Scott J. Dudley  */
  267.  
  268.  
  269. #define VERSION     "2.4"
  270. #define DATE        "1/10/93"
  271.  
  272. #define MAXWIDTH    79
  273. #define MAXPATH     128
  274. #define MAXLINE     256
  275. #define MAXDESC     4096
  276.  
  277. #define DEFINDENT   30
  278.  
  279. #ifndef FALSE
  280.     #define FALSE 0
  281.     #define TRUE 1
  282. #endif
  283.  
  284.  
  285. struct _arealist
  286. {
  287.     char    name[40];
  288.     char    info[80];
  289.     char    path[80];
  290.     char    filesbbs[80];
  291.     sword   priv;
  292.     dword   locks;
  293.     byte    barricade;
  294.     struct _arealist *next;
  295. };
  296.  
  297.  
  298. typedef struct _arealist __arealist;
  299. typedef struct _area __area;
  300.  
  301.  
  302. void process_args(int argc, char *argv[]);
  303. sword get_priv(char priv);
  304. dword get_keys(char *key_list);
  305. __arealist *read_areas(void);
  306. void process_header(char type, char *hfile, char *name, char *info, FILE *out);
  307. void process_entry(char *entry, char *path, char *name, char *info,
  308.     int *header, FILE *out);
  309.  
  310.  
  311. char    areafile[MAXPATH] = {"area.dat"};
  312. char    hareafile[MAXPATH] = {""};
  313. char    hbeginfile[MAXPATH] = {""};
  314. char    hendfile[MAXPATH] = {""};
  315. char    hsummaryfile[MAXPATH] = {""};
  316. char    outfile[MAXPATH] = {"flist.txt"};
  317. sword   priv = NORMAL;
  318. dword   keys = 0x00000000;
  319. int     barricade = FALSE;
  320. int     comment = FALSE;
  321. long    days = -1L;
  322. int     offline = FALSE;
  323. int     wrap = DEFINDENT;
  324. int     volume = 1;
  325. int     vloop;
  326. long    age = -1L;
  327. int     total_count = 0;
  328. int     area_count;
  329. long    total_bytes = 0L;
  330. long    area_bytes;
  331.  
  332.  
  333. int main(int argc, char *argv[])
  334. {
  335.  
  336.     char        filespath[MAXPATH];
  337.  
  338.     int         header;
  339.  
  340.     FILE        *out;
  341.     FILE        *files;
  342.  
  343.     __arealist  *areas;
  344.     __arealist  *cur;
  345.     __arealist  *prev;
  346.  
  347.     char        line[MAXDESC];
  348.  
  349.  
  350.     printf("FLIST %s -- Copyright 1993 by Bob Quinlan (%s)\n\n", VERSION, DATE);
  351.     printf("Special thanks to David Powers for suggestions and code.\n\n");
  352.  
  353.     process_args(argc, argv);
  354.  
  355.     areas = read_areas();
  356.  
  357.     if ((out = _fsopen(outfile, "wt", SH_DENYWR)) == NULL)
  358.     {
  359.         fprintf(stderr, "Unable to open %s\n", outfile);
  360.         exit(4);
  361.     }
  362.  
  363.     if (hbeginfile[0] != '\0')
  364.     {
  365.         process_header('b', hbeginfile, NULL, NULL, out);
  366.     }
  367.  
  368.     cur = areas;
  369.     while (cur != NULL)
  370.     {
  371.         if ((priv >= (cur->priv)) && (((~keys)&(cur->locks)) == 0) &&
  372.             ((cur->barricade == 0) || (barricade)))
  373.         {
  374.             if (volume)
  375.             {
  376.                 vloop = -1;
  377.                 printf("%s -- %s", cur->name, cur->info);
  378.             }
  379.             strcpy(filespath, cur->filesbbs);
  380.             if (filespath[0] == '\0')
  381.             {
  382.                 strcpy(filespath, cur->path);
  383.                 strcat(filespath, "files.bbs");
  384.             }
  385.             if ((files = _fsopen(filespath, "rt", SH_DENYNONE)) != NULL)
  386.             {
  387.                 area_count = 0;
  388.                 area_bytes = 0L;
  389.                 header = FALSE;
  390.                 while (fgets(line, MAXDESC, files) != NULL)
  391.                 {
  392.                     process_entry(line, cur->path, cur->name, cur->info,
  393.                         &header, out);
  394.                     if (volume)
  395.                     {
  396.                         if ((vloop = (vloop+1)%volume) == 0)
  397.                         {
  398.                             printf(".");
  399.                         }
  400.                     }
  401.                 }
  402.                 fclose(files);
  403.                 if (header)
  404.                 {
  405.                     if (hsummaryfile[0] != '\0')
  406.                     {
  407.                         process_header('s', hsummaryfile, cur->name,
  408.                             cur->info, out);
  409.                     }
  410.                 }
  411.             }
  412.             if (volume)
  413.             {
  414.                 printf("\n");
  415.             }
  416.         }
  417.         /*  Increment to next link and free previous link  */
  418.         prev = cur;
  419.         cur = cur->next;
  420.         free(prev);
  421.     }
  422.  
  423.     if (hendfile[0] != '\0')
  424.     {
  425.         process_header('e', hendfile, NULL, NULL, out);
  426.     }
  427.  
  428.     fclose(out);
  429.  
  430.     return 0;
  431. }
  432.  
  433.  
  434. void process_args(int argc, char *argv[])
  435. {
  436.     int i;
  437.  
  438.     for (i = 1; i < argc; i++)
  439.     {
  440.         if ((argv[i][0] == '/') || (argv[i][0] == '-'))
  441.         {
  442.             switch (tolower(argv[i][1]))
  443.             {
  444.                 case 'a':  /*  area.dat  */
  445.                     strncpy(areafile, argv[i]+2, MAXPATH);
  446.                     break;
  447.                 case 'b':  /*  include barricaded areas  */
  448.                     barricade = TRUE;
  449.                     break;
  450.                 case 'c':  /*  include file list comment lines  */
  451.                     comment = TRUE;
  452.                     break;
  453.                 case 'd':  /*  days (of file date)  */
  454.                     days = atol(argv[i]+2);
  455.                     age = time(NULL)-(days*24*60*60);
  456.                     break;
  457.                 case 'f':  /*  output file  */
  458.                     strncpy(outfile, argv[i]+2, MAXPATH);
  459.                     break;
  460.                 case 'h':  /*  headers  */
  461.                     switch(tolower(argv[i][2]))
  462.                     {
  463.                         case 'a':
  464.                             strncpy(hareafile, argv[i]+3, MAXPATH);
  465.                             break;
  466.                         case 'b':
  467.                             strncpy(hbeginfile, argv[i]+3, MAXPATH);
  468.                             break;
  469.                         case 'e':
  470.                             strncpy(hendfile, argv[i]+3, MAXPATH);
  471.                             break;
  472.                         case 's':
  473.                             strncpy(hsummaryfile, argv[i]+3, MAXPATH);
  474.                             break;
  475.                         default:
  476.                             fprintf(stderr, "Unknown switch: %s\n", argv[i]);
  477.                             exit(1);
  478.                             break;
  479.                     }
  480.                     break;
  481.                 case 'k':  /*  keys  */
  482.                     keys |= get_keys(argv[i]+2);
  483.                     break;
  484.                 case 'n':  /*  no-wrap  */
  485.                     wrap = -1;
  486.                     break;
  487.                 case 'o':  /*  offline files allowed  */
  488.                     offline = TRUE;
  489.                     break;
  490.                 case 'p':  /*  privilege  */
  491.                     priv = get_priv(argv[i][2]);
  492.                     if (priv < TWIT)
  493.                     {
  494.                         priv = TWIT;
  495.                         fprintf(stderr, "Invalid privilege: %c\n", argv[i][2]);
  496.                     }
  497.                     break;
  498.                 case 't':  /*  truncate lines  */
  499.                     wrap = -2;
  500.                     break;
  501.                 case 'v':  /*  volume  */
  502.                     volume = max(atoi(argv[i]+2), 0);
  503.                     break;
  504.                 case 'w':  /*  wrap column  */
  505.                     wrap = min(max(atoi(argv[i]+2), 0),
  506.                         MAXWIDTH-((MAXWIDTH-DEFINDENT)/2));
  507.                     break;
  508.                 default:
  509.                     fprintf(stderr, "Unknown switch: %s\n", argv[i]);
  510.                     exit(1);
  511.                     break;
  512.             }
  513.         }
  514.         else
  515.         {
  516.             fprintf(stderr, "Not a switch: %s\n", argv[i]);
  517.             exit(1);
  518.         }
  519.     }
  520. }
  521.  
  522.  
  523. sword get_priv(char priv)
  524. {
  525.     char    priv_name[] = {"tdlnwpfecash"};
  526.     sword   priv_code[] =
  527.             {
  528.                 TWIT,
  529.                 DISGRACE,
  530.                 LIMITED,
  531.                 NORMAL,
  532.                 WORTHY,
  533.                 PRIVIL,
  534.                 FAVORED,
  535.                 EXTRA,
  536.                 CLERK,
  537.                 ASSTSYSOP,
  538.                 SYSOP,
  539.                 HIDDEN
  540.             };
  541.  
  542.     char    *where;
  543.  
  544.     where = strchr(priv_name, tolower(priv));
  545.     if (where == NULL)
  546.     {
  547.         return TWIT-1;
  548.     }
  549.  
  550.     return priv_code[(int)(where-priv_name)];
  551. }
  552.  
  553.  
  554. dword get_keys(char *key_list)
  555. {
  556.     char    *key;
  557.     dword   mask = 0x00000000;
  558.     int     keylen;
  559.     int     i;
  560.  
  561.     key = strupr(strdup(key_list));
  562.  
  563.     keylen = strlen(key);
  564.     for (i = 0; i < keylen; i++)
  565.     {
  566.         if (key[i] == '*')
  567.         {
  568.             mask = 0xFFFFFFFFL;
  569.             break;
  570.         }
  571.         else if ((key[i] >= '1') && (key[i] <= '8'))
  572.         {
  573.             mask |= 0x00000001L<<(key[i]-'1');
  574.         }
  575.         else if ((key[i] >= 'A') && (key[i] <= 'X'))
  576.         {
  577.             mask |= 0x00000100L<<(key[i]-'A');
  578.         }
  579.     }
  580.  
  581.     free(key);
  582.  
  583.     return mask;
  584. }
  585.  
  586.  
  587. __arealist *read_areas(void)
  588. {
  589.     FILE        *areadat;
  590.     __area      area;
  591.     __arealist  *tmp;
  592.     __arealist  *first;
  593.     __arealist  *cur = NULL;
  594.     dword       slen;
  595.     dword       offset = 0;
  596.  
  597.     if ((areadat = _fsopen(areafile, "rb", SH_DENYNONE)) == NULL)
  598.     {
  599.         fprintf(stderr, "Unable to open %s\n", areafile);
  600.         exit(2);
  601.     }
  602.  
  603.     while (fread(&area, sizeof(__area), 1, areadat) > 0)
  604.     {
  605.         if (offset == 0)
  606.         {
  607.             slen = (dword)(area.struct_len);
  608.         }
  609.         if (area.filepath[0] != '\0')
  610.         {
  611.             if ((tmp = (__arealist *)malloc(sizeof(__arealist))) == NULL)
  612.             {
  613.                 fprintf(stderr, "Out of memory!\n");
  614.                 exit(5);
  615.             }
  616.             if (cur == NULL)
  617.             {
  618.                 first = tmp;
  619.             }
  620.             else
  621.             {
  622.                 cur->next = tmp;
  623.             }
  624.             cur = tmp;
  625.             strcpy(cur->name, (char *)area.name);
  626.             strcpy(cur->info, (char *)area.fileinfo);
  627.             strcpy(cur->path, (char *)area.filepath);
  628.             strcpy(cur->filesbbs, (char *)area.filesbbs);
  629.             cur->priv = area.filepriv;
  630.             cur->locks = area.filelock;
  631.             cur->barricade = (area.filebar[0] != '\0');
  632.         }
  633.         offset += slen;
  634.         if (fseek(areadat, offset, SEEK_SET) != 0)
  635.         {
  636.             break;
  637.         }
  638.     }
  639.  
  640.     cur->next = NULL;
  641.     fclose(areadat);
  642.  
  643.     return first;
  644. }
  645.  
  646.  
  647. void process_header(char type, char *hfile, char *name, char *info, FILE *out)
  648. {
  649.     FILE    *h;
  650.     char    buf[MAXLINE];
  651.     char    tbuf[MAXLINE];
  652.     char    filler[MAXLINE];
  653.     int     flen;
  654.     char    *param;
  655.     int     plen;
  656.     int     fwidth;
  657.     char    *stopper;
  658.     char    c;
  659.     int     j, k;
  660.  
  661.     if ((h = _fsopen(hfile, "rt", SH_DENYNONE)) == NULL)
  662.     {
  663.         fprintf(stderr, "Unable to open %s\n", hfile);
  664.         exit(3);
  665.     }
  666.     /*  Read data from the header file  */
  667.     while (fgets(buf, MAXLINE, h) != NULL)
  668.     {
  669.         /*  Process special replacement characters  */
  670.         param = buf;
  671.         while ((param = strchr(param, '%')) != NULL)
  672.         {
  673.             filler[0] = '\0';
  674.             plen = 2;
  675.             /*  Check the basic parameter type  */
  676.             switch (tolower(param[1]))
  677.             {
  678.                 case 'a':  /*  age  */
  679.                     if (days != -1L)
  680.                     {
  681.                         ltoa(days, filler, 10);
  682.                     }
  683.                     break;
  684.                 case 'd':  /*  date  */
  685.                     _strdate(filler);
  686.                     break;
  687.                 case 't':  /*  time  */
  688.                     _strtime(filler);
  689.                     break;
  690.             }
  691.             /*  Do not allow totals in beginning headers  */
  692.             if (type != 'b')
  693.             {
  694.                 switch (tolower(param[1]))
  695.                 {
  696.                     case 'f':  /*  total file count  */
  697.                         itoa(total_count, filler, 10);
  698.                         break;
  699.                     case 's':  /*  file size total  */
  700.                         ltoa(total_bytes, filler, 10);
  701.                         break;
  702.                 }
  703.             }
  704.             /*  Only allow area name and information in area and summary headers  */
  705.             if ((type == 'a') || (type == 's'))
  706.             {
  707.                 switch (tolower(param[1]))
  708.                 {
  709.                     case 'n':  /*  name  */
  710.                         strcpy(filler, name);
  711.                         break;
  712.                     case 'i':  /*  information  */
  713.                         strcpy(filler, info);
  714.                         break;
  715.                 }
  716.             }
  717.             /*  Only allow area count and area bytes in summary headers  */
  718.             if (type == 's')
  719.             {
  720.                 switch (tolower(param[1]))
  721.                 {
  722.                     case 'c':  /*  area file count  */
  723.                         itoa(area_count, filler, 10);
  724.                         break;
  725.                     case 'b':  /*  area file size total (bytes)  */
  726.                         ltoa(area_bytes, filler, 10);
  727.                         break;
  728.                 }
  729.             }
  730.  
  731.             /*  If any replacements were found...  */
  732.             if (filler[0] != '\0')
  733.             {
  734.                 /*  Process width values if present  */
  735.                 c = tolower(param[plen]);
  736.                 if (strchr("lrc", c) != NULL)
  737.                 {
  738.                     ++plen;
  739.                     /*  Convert the width value and find where it stops  */
  740.                     fwidth = (int)strtol(param+plen, &stopper, 10);
  741.                     plen += (int)(stopper-(param+plen));
  742.                     /*  If the field is wider than the filler string...  */
  743.                     if (fwidth >= MAXLINE)
  744.                     {
  745.                         fprintf(stderr, "Width %d too wide!  Ignored.\n",
  746.                             fwidth);
  747.                     }
  748.                     /*  If the field is wider than the current data...  */
  749.                     else if (strlen(filler) < fwidth)
  750.                     {
  751.                         switch (c)
  752.                         {
  753.                             case 'l':  /*  left justify  */
  754.                                 /*  Pad on the right  */
  755.                                 for (j = strlen(filler); j < fwidth; j++)
  756.                                 {
  757.                                     filler[j] = ' ';
  758.                                 }
  759.                                 break;
  760.                             case 'r':  /*  right justify  */
  761.                                 flen = strlen(filler);
  762.                                 /*  Shift the string right  */
  763.                                 for (j = 1; j <= flen; j++)
  764.                                 {
  765.                                     filler[fwidth-j] = filler[flen-j];
  766.                                 }
  767.                                 /*  Pad on the left  */
  768.                                 for (j = 0; j < fwidth-flen; j++)
  769.                                 {
  770.                                     filler[j] = ' ';
  771.                                 }
  772.                                 break;
  773.                             case 'c':  /*  center  */
  774.                                 flen = strlen(filler);
  775.                                 /*  Pad on the right  */
  776.                                 k = (fwidth-flen+1)/2;
  777.                                 for (j = 1; j <= k; j++)
  778.                                 {
  779.                                     filler[fwidth-j] = ' ';
  780.                                 }
  781.                                 /*  Shift the string to center  */
  782.                                 for (j = 1; j <= flen; j++)
  783.                                 {
  784.                                     filler[fwidth-k-j] = filler[flen-j];
  785.                                 }
  786.                                 /*  Pad on the left  */
  787.                                 k = (fwidth-flen)/2;
  788.                                 for (j = 0; j < k; j++)
  789.                                 {
  790.                                     filler[j] = ' ';
  791.                                 }
  792.                                 break;
  793.                         }
  794.                         /*  Terminate the adjusted string  */
  795.                         filler[fwidth] = '\0';
  796.                     }
  797.                 }
  798.  
  799.                 /*  Process fill character if present  */
  800.                 if (tolower(param[plen]) == 'f')
  801.                 {
  802.                     strset(filler, param[++plen]);
  803.                     ++plen;
  804.                 }
  805.                 /*  Skip "no fill" parameter if present  */
  806.                 else if (strncmpi(param+plen, "nf", 2) == 0)
  807.                 {
  808.                     plen += 2;
  809.                 }
  810.  
  811.                 /*  Perform the replacment  */
  812.                 if ((strlen(buf)+strlen(filler)-plen) >= MAXLINE)
  813.                 {
  814.                     fprintf(stderr, "String overflow!\n");
  815.                     exit(6);
  816.                 }
  817.                 param[0] = '\0';
  818.                 strcpy(tbuf, buf);
  819.                 strcat(tbuf, filler);
  820.                 strcat(tbuf, param+plen);
  821.                 strcpy(buf, tbuf);
  822.                 param = param+strlen(filler);
  823.             }
  824.             else
  825.             {
  826.                 param++;
  827.             }
  828.         }
  829.  
  830.         /*  Output header  */
  831.         fputs(buf, out);
  832.     }
  833.  
  834.     fclose(h);
  835. }
  836.  
  837.  
  838. void process_entry(char *entry, char *path, char *name, char *info,
  839.       int *header, FILE *out)
  840. {
  841.     char    filepath[MAXPATH];
  842.     int     file;
  843.  
  844.     long            fsize;
  845.     struct ftime    ftimep;
  846.     struct tm         ftm;
  847.     int             fdata;
  848.  
  849.     char    line[MAXDESC];
  850.     char    fill[MAXWIDTH+1];
  851.     char    extra[MAXWIDTH+1];
  852.     char    *descrip;
  853.     char    *end;
  854.     char    *ch;
  855.     int     length;
  856.     int     nameline;
  857.     int     i;
  858.  
  859.     strcpy(line, entry);
  860.  
  861.     /*  Trim newline  */
  862.     end = strchr(line, '\n');
  863.     if (end != NULL)
  864.     {
  865.         end[0] = '\0';
  866.     }
  867.     else
  868.     {
  869.         end = strchr(line, '\0');
  870.     }
  871.  
  872.     /*  Check for comment lines  */
  873.     if (strchr(" -", line[0]) != NULL)
  874.     {
  875.         if (comment)
  876.         {
  877.             /*  Output area header if not already done  */
  878.             if (!(*header))
  879.             {
  880.                 if (hareafile[0] != '\0')
  881.                 {
  882.                     process_header('a', hareafile, name, info, out);
  883.                 }
  884.                 else
  885.                 {
  886.                     fprintf(out, "\n\n    Area %s -- %s\n\n", name, info);
  887.                 }
  888.                 *header = TRUE;
  889.             }
  890.  
  891.             /*  Output comment line  */
  892.             fprintf(out, "%s\n", line);
  893.         }
  894.     }
  895.     else
  896.     {
  897.         total_count++;
  898.         area_count++;
  899.         /*  Parse into filename and description, skipping switches  */
  900.         descrip = line;
  901.         do
  902.         {
  903.             ch = strpbrk(descrip, " \t");
  904.             if (ch == NULL)
  905.             {
  906.                 descrip = end;
  907.             }
  908.             else
  909.             {
  910.                 ch[0] = '\0';
  911.                 i = strspn(++ch, " \t");
  912.                 descrip = ch+i;
  913.             }
  914.         } while (descrip[0] == '/');
  915.  
  916.         /*  Get file size and date  */
  917.         strcpy(filepath, path);
  918.         strcat(filepath, line);
  919.         if ((file = sopen(filepath, O_RDONLY, SH_DENYNONE)) == -1)
  920.         {
  921.             if (offline)
  922.             {
  923.                 fdata = FALSE;
  924.             }
  925.             else
  926.             {
  927.                 return;
  928.             }
  929.         }
  930.         else
  931.         {
  932.             fsize = filelength(file);
  933.             getftime(file, &ftimep);
  934.             close(file);
  935.             total_bytes += fsize;
  936.             area_bytes += fsize;
  937.             fdata = TRUE;
  938.  
  939.             timezone = 0L;
  940.             daylight = 0;
  941.             memset(&ftm, 0, sizeof(struct tm));
  942.             ftm.tm_sec = ftimep.ft_tsec*2;
  943.             ftm.tm_min = ftimep.ft_min;
  944.             ftm.tm_hour = ftimep.ft_hour;
  945.             ftm.tm_mday = ftimep.ft_day;
  946.             ftm.tm_mon = ftimep.ft_month-1;
  947.             ftm.tm_year = ftimep.ft_year+80;
  948.             if (mktime(&ftm) < age)
  949.             {
  950.                 return;
  951.             }
  952.         }
  953.  
  954.         /*  Output area header if not already done  */
  955.         if (!(*header))
  956.         {
  957.             if (hareafile[0] != '\0')
  958.             {
  959.                 process_header('a', hareafile, name, info, out);
  960.             }
  961.             else
  962.             {
  963.                 fprintf(out, "\n\n    Area %s -- %s\n\n", name, info);
  964.             }
  965.             *header = TRUE;
  966.         }
  967.  
  968.         /*  Output file entry  */
  969.         if (fdata)
  970.         {
  971.             fprintf(out, "%-12s %7lu %2.2u-%2.2u-%2.2u", line,
  972.                 fsize, ftimep.ft_month, ftimep.ft_day,
  973.                 (ftimep.ft_year+80)%100);
  974.         }
  975.         else
  976.         {
  977.             fprintf(out, "%-12s offline         ", line);
  978.         }
  979.         /*  Output description  */
  980.         switch (wrap)
  981.         {
  982.             case -2:  /*  truncate  */
  983.                 descrip[MAXWIDTH-DEFINDENT] = '\0';
  984.                 fprintf(out, " %s\n", descrip);
  985.                 break;
  986.             case -1:  /*  no-wrap  */
  987.                 fprintf(out, " %s\n", descrip);
  988.                 break;
  989.             default:  /*  wrap  */
  990.                 length = MAXWIDTH-DEFINDENT;
  991.                 strcpy(fill, " ");
  992.                 nameline = TRUE;
  993.                 /*  Set initial length  */
  994.                 while (strlen(descrip) > length)
  995.                 {
  996.                     for (i = length; i > length/2; i--)
  997.                     {
  998.                         if (strchr(" \t", descrip[i]) != NULL)
  999.                         {
  1000.                             break;
  1001.                         }
  1002.                     }
  1003.                     /*  If there are no breaks...  */
  1004.                     if (i == length/2)
  1005.                     {
  1006.                         strncpy(extra, descrip, length);
  1007.                         extra[length] = '\0';
  1008.                         fprintf(out, "%s%s\n", fill, extra);
  1009.                         descrip += length;
  1010.                     }
  1011.                     else
  1012.                     {
  1013.                         descrip[i++] = '\0';
  1014.                         fprintf(out, "%s%s\n", fill, descrip);
  1015.                         descrip += i;
  1016.                         while (strchr(" \t", descrip[0]) != NULL)
  1017.                         {
  1018.                             descrip++;
  1019.                         }
  1020.                     }
  1021.                     if (nameline == TRUE)
  1022.                     {
  1023.                         /*  Recalculate length  */
  1024.                         length = MAXWIDTH-wrap;
  1025.                         memset(fill, ' ', wrap);
  1026.                         fill[wrap] = '\0';
  1027.                         nameline = FALSE;
  1028.                     }
  1029.                 }
  1030.                 fprintf(out, "%s%s\n", fill, descrip);
  1031.                 break;
  1032.         }
  1033.     }
  1034. }
  1035.  
  1036.  
  1037.