home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / dwnsrs59.zip / DOWNRPT1.C < prev    next >
Text File  |  1993-12-12  |  16KB  |  365 lines

  1.  
  2. /* ================================================================ */
  3. /*  Rob Hamerling's MAXIMUS download file scan and sort utility     */
  4. /*  -> DOWNRPT1.C                                                   */
  5. /*     Make: BBS-list, New-list, EMI-list                           */
  6. /* ================================================================ */
  7.  
  8. /* #define __DEBUG__ */
  9.  
  10. #define INCL_BASE
  11. #define INCL_NOPMAPI
  12. #include <os2.h>
  13.  
  14. #include <conio.h>
  15. #include <memory.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19.  
  20. #include "..\max\mstruct.h"
  21. #include "downsort.h"
  22. #include "downfpro.h"
  23.  
  24. /* --------------------------------------- */
  25. /* Produce the bulletin format of BBS-list */
  26. /* --------------------------------------- */
  27. void make_bbs(FILECHAIN * _HUGE *dm,
  28.               DOWNPATH  _HUGE *area,
  29.               LISTPARM  *ls)            /* list specs */
  30. {
  31.   FILE  *pf;                            /* report file handle */
  32.   char  outfile[MAXFN];                 /* file names */
  33.   USHORT k;                             /* counters */
  34.   ULONG  i,j,m,n,fc,fs;                 /* counters */
  35.   ULONG  akb;                           /* bytecount in KB */
  36.   FILECHAIN *cn, *fx;                   /* ptr to file info */
  37.   char  *p;                             /* pointer string in strsubw */
  38. #ifdef __DEBUG__
  39.   ULONG starttime,stoptime; */  /* timing of sorts */
  40. #endif
  41.  
  42.   sprintf(outfile,"%s.%s", ls->name, ls->ext);  /* build fname */
  43.   pf = fopen(outfile,WRITE);            /* output file */
  44.   if (pf != NULL) {                     /* successful open */
  45.     if (oper_mode == VERBOSE)
  46.       fprintf(stdout,MSG_SRT, file_total_count, area_total_count, outfile);
  47. #ifdef __DEBUG__
  48.     DosQuerySysInfo(QSV_MS_COUNT,       /* msecs since system start */
  49.                     QSV_MS_COUNT,       /* that's all! */
  50.                     (void *)&starttime, /* data buffer */
  51.                     sizeof(starttime)); /* data buffer length */
  52. #endif
  53.     psort(dm, 0, file_total_count-1, sort_new); /* sort on date */
  54. #ifdef __DEBUG__
  55.     DosQuerySysInfo(QSV_MS_COUNT,       /* msecs since system start */
  56.                   QSV_MS_COUNT,         /* that's all! */
  57.                   (void *)&stoptime,    /* data buffer */
  58.                   sizeof(stoptime));    /* data buffer length */
  59.     fprintf(stdout,"sort-duration = %lu msecs\n", stoptime-starttime); */
  60. #endif
  61.     fc = preproc_area(area, dm, ls);    /* #files, #bytes  */
  62.     n = rpt_count(dm, ls, &cn);         /* first 'n' to be proc'd */
  63.     if (n > 0   &&                      /* any files for this report */
  64.         (ls->sortflag == ALPHA  ||      /* re-sort first entries on name */
  65.          ls->sortflag == GROUP)) {      /* synonym for this list */
  66.       if (oper_mode == VERBOSE)
  67.         fprintf(stdout, MSG_RST, n);    /* re-sort msg */
  68.       psort(dm, 0, n-1, sort_gbl);      /* re-sort first 'n' entries */
  69.       }
  70.     if (oper_mode != QUIET)
  71.       fprintf(stdout, MSG_REP, outfile);
  72.     if (oper_mode == VERBOSE)
  73.       fprintf(stdout, MSG_REC);
  74.     ls->incl_fspec = "DOWNSORT.HDR";    /* header filename */
  75.     file_incl(pf, ls);                  /* include bbs-header file */
  76.     akb =  (count_bytes(area) + 512)/1024;
  77.     fprintf(pf,"\n%c(%s) Last %c%hu %s%cnewest of a total of"
  78.                " %c%lu%c files (%c%lu%c %cB)",
  79.                 O_CYAN,
  80.                 sys_date(today),
  81.                 O_YELLOW,
  82.                 (ls->listflag!=' ' || fc>ls->max_fil) ?
  83.                        ls->max_fil : (USHORT)fc,
  84.                 (ls->listflag==' ') ? EMPTY :
  85.                  ((ls->listflag=='D') ? DAYS :
  86.                   ((ls->listflag=='W') ? WEEKS : MONTHS)),
  87.                 O_CYAN,
  88.                 O_YELLOW,
  89.                 fc,
  90.                 O_CYAN,
  91.                 O_BRIGHT+O_MAGENTA,
  92.                 (akb < 9999) ? akb : (akb+512)/1024,
  93.                 O_CYAN,
  94.                 (akb < 9999) ? 'K' : 'M');
  95.  
  96.     if ( (ls->sortflag == ALPHA  ||     /* for filename-sorted list  */
  97.           ls->sortflag == GROUP)   &&   /* for filename-sorted list  */
  98.             cn != NULL             &&   /* new file available */
  99.             cn->wd.idate != 0) {        /* true date */
  100.       fprintf(pf,"\n%19sNewest: %c%s %c%8s",
  101.                     EMPTY, O_YELLOW, cn->fname,
  102.                     O_GREEN,f_date(cn->wd.date) );
  103.       fprintf(pf," %c(avail: %c%8s%c)",
  104.                     O_CYAN,O_GREEN,
  105.                     f_date(cn->cd.date),O_CYAN);
  106.       }
  107.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  108.                EMPTY, DF, DAYS_7, WK, DAYS_30, MO);
  109.     if (ls->exclflag != EXCLPRIV)
  110.       fprintf(pf,"\n\n%c(Your privilege-level may limit the number "
  111.                 "of files actually shown to you!)%c",O_RED,O_CYAN);
  112.     fprintf(pf,"\n\n%c%s       %c%s    %c%s   %c%s    %c%s\n\n",
  113.                 O_YELLOW,FN,
  114.                 O_BRIGHT+O_RED,AC,
  115.                 O_MAGENTA,SZ,
  116.                 O_GREEN,DT,
  117.                 O_CYAN,DS);
  118.     for (i=m=0; i<n; i++) {             /* first n array entries */
  119.       fx = dm[i];
  120.       if (rpt_coll(fx, ls, TRUE)) {     /* check if to be listed */
  121.         if (oper_mode==VERBOSE && (m%25)==0) {
  122.           fprintf(stdout, "%6lu\r",m);
  123.           fflush(stdout);
  124.           }
  125.         m++;                            /* actually be reported */
  126.         fprintf(pf,"%cL%c%c%-12.12s %c%-8.8s ",
  127.                     '\20',
  128.                     (fx->priv>SYSOP)?'S':priv_name[fx->priv-TWIT][0],
  129.                     O_YELLOW,
  130.                     fx->fname,
  131.                     O_RED+O_BRIGHT,
  132.                     fx->parea->name);
  133.         if (fx->wd.date.day > 0) {     /* file(date) present */
  134.           fs = (fx->size+512)/1024;  /* filesize in KB */
  135.           fprintf(pf,"%c%4lu%c %c%s%c %c",
  136.                     O_MAGENTA,
  137.                     (fs<=9999) ? fs  : (fs+512)/1024,
  138.                     (fs<=9999) ? 'K' : 'M',
  139.                     O_GREEN,
  140.                     f_date(fx->wd.date),
  141.                     file_age_ind(fx),   /* file age */
  142.                     O_CYAN);
  143.           }
  144.         else {                          /* file not found */
  145.           fprintf(pf,"%c%15s %c",
  146.                     O_MAGENTA,
  147.                     OFFLINE,
  148.                     O_CYAN);
  149.           }
  150.         if ((k=strsubw(fx->fdesc, &p, 41)) != 0) {  /* length            */
  151.           if (ls->wrapflag != WRAP) {   /* truncate                */
  152.             j = strlen(fx->fdesc);      /* total string length           */
  153.             k = (USHORT)min(41L, j);    /* shortest of l1 and j          */
  154.             }
  155.           fprintf(pf,"%-.*s\n", k, p);  /* (1st part of) string          */
  156.           while (k>0 && ls->wrapflag==WRAP) {  /* wrap requested   */
  157.             if ((k=strsubw(p+k, &p, 41-ls->desc_indent)) != 0) {
  158.               fprintf(pf,"%cL%c", '\20',
  159.                  (fx->priv>SYSOP)?'S':priv_name[fx->priv-TWIT][0]);
  160.               fprintf(pf,"%*s%-.*s\n",
  161.                   79-41+ls->desc_indent,EMPTY, k, p);   /*  more      */
  162.               }
  163.             }
  164.           }
  165.         }
  166.       }
  167.     if (oper_mode==VERBOSE)
  168.       fprintf(stdout, "%6lu\n",m);
  169.     signature(pf, today);               /* fingerprint                   */
  170.     ls->incl_fspec = "DOWNSORT.TRL";    /* trailer filename           */
  171.     file_incl(pf, ls);                  /* include bbs-trailer file      */
  172.     fclose(pf);                         /* finished with .BBS file       */
  173.     }
  174.   else                                  /* no output possible            */
  175.     fprintf(stderr, MSG_OPO, outfile, 0);
  176.   }
  177.  
  178. /* ------------------------------------------- */
  179. /* Produce the file-request format of NEW-list */
  180. /* ------------------------------------------- */
  181. void make_new(FILECHAIN * _HUGE *dm,
  182.               DOWNPATH  _HUGE *area,
  183.               LISTPARM  *ls)            /* list specs                   */
  184. {
  185.   FILE     *pf;                         /* file handle                   */
  186.   char     outfile[MAXFN];              /* file names                    */
  187.   ULONG    i,m,n,fc;                    /* counters                      */
  188.   ULONG    akb;                         /* bytecount in KB               */
  189.   FILECHAIN *cn, *fx;                   /* ptr to file info              */
  190.   char     aname[MAXANAME];             /* area code/name */
  191.  
  192.   sprintf(outfile,"%s.%s%c",
  193.           ls->name,
  194.           ls->ext,
  195.           priv_name[ls->priv - TWIT][0]);
  196.   pf = fopen(outfile,WRITE);            /* output file                   */
  197.   if (pf != NULL) {                     /* opened!                       */
  198.     if (oper_mode == VERBOSE)
  199.       fprintf(stdout, MSG_SRT, file_total_count, area_total_count, outfile);
  200.     psort(dm, 0, file_total_count-1, sort_new);
  201.     fc = preproc_area(area, dm, ls);    /* count file, bytes */
  202.     cn = NULL;                          /* no assigned */
  203.     n = rpt_count(dm, ls, &cn);         /* first 'n' to be proc'd */
  204.     if (n > 0) {                        /* any files for this report */
  205.       if  (ls->sortflag == ALPHA) {     /* resort first entries on name  */
  206.         if (oper_mode == VERBOSE)
  207.           fprintf(stdout, MSG_RST, n);  /* re-sort msg */
  208.         psort(dm, 0, n-1, sort_gbl);    /* sort first 'n' entries */
  209.         }
  210.       else if (ls->sortflag == GROUP) {  /* resort first entries on area */
  211.         if (oper_mode == VERBOSE)
  212.           fprintf(stdout, MSG_RST, n);  /* re-sort msg */
  213.         psort(dm, 0, n-1, sort_all);    /* sort first 'n' entries */
  214.         }
  215.       }
  216.     if (oper_mode != QUIET)
  217.       fprintf(stdout, MSG_REP, outfile);
  218.     if (oper_mode==VERBOSE)
  219.       fprintf(stdout, MSG_REC);
  220.     insert_title(pf, pre_title, 0);
  221.     block_title(pf, 20, EMPTY, list_title, ls);
  222.     file_incl(pf, ls);                  /* insert user-'logo'            */
  223.     insert_title(pf, sub_title, 0);
  224.     akb =  (count_bytes(area) + 512)/1024;
  225.     fprintf(pf,"\n(%s) Last %hu %snewest of a total of %lu files (%lu %cB)",
  226.                  sys_date(today),
  227.                 (ls->listflag!=' ' || fc>ls->max_fil) ?
  228.                        ls->max_fil : (USHORT)fc,
  229.                 (ls->listflag==' ') ? EMPTY :
  230.                  ((ls->listflag=='D') ? DAYS :
  231.                   ((ls->listflag=='W') ? WEEKS : MONTHS)),
  232.                  fc,
  233.                  (akb < 9999) ? akb : (akb-512)/1024,
  234.                  (akb < 9999) ? 'K' : 'M');
  235.     if (ls->exclflag != EXCLPRIV)
  236.       fprintf(pf,"\n%19s%s%s", EMPTY, MP, priv_name[ls->priv-TWIT]);
  237.     if ((ls->sortflag == ALPHA  ||      /* for filename-sorted list only */
  238.          ls->sortflag == GROUP) &&      /* synonym for ALPHA here */
  239.          cn != NULL             &&      /* newest file */
  240.          cn->wd.idate != 0) {           /* true date */
  241.       fprintf(pf,"\n%19sNewest: %s %8s",
  242.                  EMPTY, cn->fname, f_date(cn->wd.date));
  243.       fprintf(pf," (avail: %8s)",
  244.                  f_date(cn->cd.date));
  245.       }
  246.     fprintf(pf,"\n%19s%s %c%s, %c%s\n\n",
  247.                EMPTY, DF, DAYS_7, WK, DAYS_30, MO);
  248.     if (ls->sortflag != GROUP) {
  249.       fprintf(pf,"%s       %s    %s   %s    %s\n",FN,AC,SZ,DT,DS);
  250.       sep_line(pf, '─', 12, 8, 5, 9, 41, 0);
  251.       }
  252.     aname[0] = '\0';                    /* initial areaname is empty */
  253.     for (i=m=0; i<n; i++) {
  254.       fx = dm[i];                       /* copy pointer */
  255.       if (rpt_coll(fx, ls, TRUE)) {     /* check if to be listed */
  256.         if (oper_mode==VERBOSE && (m%25)==0) {
  257.           fprintf(stdout, "%6lu\r", m);
  258.           fflush(stdout);
  259.           }
  260.         ++m;                            /* actually listed               */
  261.         if (ls->sortflag == GROUP) {    /* areagroup */
  262.           if (strcmp(aname, fx->parea->name)) {  /* new area */
  263.             strcpy(aname, fx->parea->name);      /* remember */
  264.             fprintf(pf,"\n");           /* insert space */
  265.             sep_line(pf,'═', 79, 0);    /* separator line */
  266.             fprintf(pf," %s  -  %-.64s\n",
  267.                         aname,
  268.                         fx->parea->adesc);
  269.             sep_line(pf,'─', 79, 0);    /* separator line */
  270.             }
  271.           fprintf(pf,"%-12.12s %15s ",
  272.                       fx->fname,
  273.                       f_size_date(fx));
  274.           desc_part(pf, fx->fdesc, 50, 50-ls->desc_indent, ls);
  275.           }
  276.         else {
  277.           fprintf(pf,"%-12.12s %-8.8s %15s ",
  278.                       fx->fname,
  279.                       fx->parea->name,
  280.                       f_size_date(fx));
  281.           desc_part(pf, fx->fdesc, 41, 41-ls->desc_indent, ls);
  282.           }
  283.         }
  284.       }
  285.     if (oper_mode==VERBOSE)
  286.       fprintf(stdout,"%6lu\n",m);
  287.     signature(pf,today);                /* leave fingerprint             */
  288.     insert_title(pf, bot_title, 0);
  289.     fclose(pf);                         /* finished with .NEW file       */
  290.     }
  291.   else
  292.     fprintf(stderr, MSG_OPO, outfile, 0);
  293.   }
  294.  
  295. /* ------------------------------------------- */
  296. /* Produce the file-request format of EMI-list */
  297. /* This is a more compact variant of NEW-list. */
  298. /* File date, time and size are exact.         */
  299. /* ------------------------------------------- */
  300. void make_emi(FILECHAIN * _HUGE *dm,
  301.               DOWNPATH  _HUGE *area,
  302.               LISTPARM  *ls)            /* list specs                    */
  303. {
  304.   FILE     *pf;                         /* file handle                   */
  305.   char     outfile[MAXFN];              /* file names                    */
  306.   ULONG    i,m,n;                       /* counters                      */
  307.   FILECHAIN  *cn, *fx;                  /* ptr to file info              */
  308.  
  309.   sprintf(outfile,"%s.%s%c",
  310.           ls->name,
  311.           ls->ext,
  312.           priv_name[ls->priv-TWIT][0]);
  313.   pf = fopen(outfile,WRITE);            /* output file */
  314.   if (pf != NULL) {                     /* opened! */
  315.     if (oper_mode == VERBOSE)
  316.       fprintf(stdout,MSG_SRT,file_total_count,area_total_count,outfile);
  317.     psort(dm, 0, file_total_count-1, sort_new);
  318.     preproc_area(area, dm, ls);         /* count file, bytes */
  319.     cn = NULL;                          /* no assigned */
  320.     n = rpt_count(dm, ls, &cn);         /* first 'n' to be proc'd */
  321.     if (n > 0    &&                     /* resort first entries on name */
  322.         (ls->sortflag == ALPHA  ||      /* resort first entries on name */
  323.          ls->sortflag == GROUP)) {      /* synonym in EMI-list */
  324.       if (oper_mode == VERBOSE)
  325.         fprintf(stdout, MSG_RST, n);    /* re-sort msg */
  326.       psort(dm, 0, n-1, sort_gbl);      /* sort first 'n' entries */
  327.       }
  328.     if (oper_mode != QUIET)
  329.       fprintf(stdout, MSG_REP, outfile);
  330.     if (oper_mode==VERBOSE)
  331.       fprintf(stdout, MSG_REC);
  332.     file_incl(pf, ls);                  /* insert user text */
  333.     fprintf(pf,"\n(%s) Last %hu %semissions",
  334.                  sys_date(today),
  335.                  ls->max_fil,
  336.                 (ls->listflag==' ') ? EMPTY :
  337.                  ((ls->listflag=='D') ? DAYS :
  338.                   ((ls->listflag=='W') ? WEEKS : MONTHS)));
  339.     fprintf(pf,"\n\n--%s-- --%s--  -%s-  -%s-  ---%s---\n",
  340.                   FN,DT,TM,BY,DS);
  341.     for (i=m=0; i<n; i++) {
  342.       fx = dm[i];                       /* copy pointer to file info */
  343.       if (rpt_coll(fx, ls, TRUE)) {     /* check if to be listed */
  344.         if (oper_mode==VERBOSE && (m%25)==0)
  345.           fprintf(stdout, "%6lu\r",m);
  346.         ++m;                            /* file list-count               */
  347.         fprintf(pf,"%-12.12s %8.8s  %6.6s %8lu  ",
  348.               fx->fname,
  349.               f_date(fx->wd.date),
  350.               f_time(fx->wt.time),
  351.               fx->size);
  352.         desc_part(pf, fx->fdesc, 39, 66-ls->desc_indent, ls);
  353.         }
  354.       }
  355.     if (oper_mode==VERBOSE)
  356.       fprintf(stdout, "%6lu\n", m);
  357.     fprintf(pf,"\n-- List created with %s %c.%c%c by %s --\n\n",
  358.                 PROGNAME,VERSION,SUBVERS,SUFFIX,AUTHOR);
  359.     fclose(pf);                         /* finished with .EMI file       */
  360.     }
  361.   else
  362.     fprintf(stderr, MSG_OPO, outfile, 0);
  363.   }
  364.  
  365.