home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / DWNSRS56.ZIP / DOWNRPT1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-17  |  14.7 KB  |  337 lines

  1. /* ================================================================ */
  2. /*  Rob Hamerling's MAXIMUS download file scan and sort utility     */
  3. /*  -> DOWNRPT1.C                                                   */
  4. /*     Make: BBS-list, New-list, EMI-list                           */
  5. /* ================================================================ */
  6.  
  7. #define INCL_BASE
  8. #include <os2.h>
  9.  
  10. #include <conio.h>
  11. #include <memory.h>
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. #include "..\max\mstruct.h"
  17. #include "downsort.h"
  18. #include "downfpro.h"
  19.  
  20.  
  21. /* function prototypes of local functions */
  22.  
  23. short int file_age(struct _filechain *);
  24.  
  25.  
  26. /* --------------------------------------- */
  27. /* Produce the bulletin format of BBS-list */
  28. /* --------------------------------------- */
  29. void make_bbs(struct  _filechain **dm,
  30.               struct  _downpath huge *area,
  31.               unsigned int  x)          // report privilege index
  32. {
  33.   FILE  *pf;                            // report file handle
  34.   char  outfile[MAXFN];                 // file names
  35.   unsigned int i,j,n,fc;                // counters
  36.   struct _filechain *cn;                // ptr to newest
  37.   short int max_age;                    // allowed file age in days
  38.  
  39.   sprintf(outfile,"%s.%s",lp[P_BBS].name,lp[P_BBS].ext);  // build filename
  40.   pf = fopen(outfile,WRITE);            // output file
  41.   if (pf != NULL) {                     // successful open
  42.     if (oper_mode == VERBOSE)
  43.       printf(MSG_SRT, file_total_count, area_total_count, outfile);
  44.     psort(dm, 0, file_total_count-1, sort_new); // sort on date
  45.     fc = preproc_area(area, dm, lp[P_BBS].priv[x]); // count files, bytes
  46.     cn = NULL;                          // none assigned
  47.     if (lp[P_BBS].listflag == ' ') {    // limited by number of entries
  48.       n = lp[P_BBS].max_fil;            // max files to be listed
  49.       if (n > fc)                       // more req'd than within priv
  50.         n = fc;                         // new request-limit
  51.       for (i=j=0; j<n && i<file_total_count; ++i)  // scan limits
  52.         if (dm[i]->priv <= lp[P_BBS].priv[x]) { // check file-privilege
  53.           ++j;                          // count within priv
  54.           cn = new_acq(dm[i],cn);       // most recent within priv
  55.           }
  56.       }
  57.     else {                              // limited by age
  58.       max_age = lp[P_BBS].max_fil *
  59.                     ((lp[P_BBS].listflag == 'W') ? 7 :
  60.                      ((lp[P_BBS].listflag == 'M') ? 30 : 1));
  61.       for (i=n=0; file_age(dm[i]) <= max_age &&
  62.                   i<file_total_count; ++i)  // get report limit
  63.         if (dm[i]->priv <= lp[P_BBS].priv[x]) { // check file-privilege
  64.           ++n;                          // count within priv and age
  65.           cn = new_acq(dm[i],cn);       // most recent within priv
  66.           }
  67.       }
  68.     if (lp[P_BBS].sortflag == ALPHA) {  // re-sort first entries on name
  69.       if (oper_mode == VERBOSE)
  70.         printf(MSG_RST, n);             // re-sort msg
  71.       psort(dm, 0, i-1, sort_gbl);      // re-sort first 'i' entries
  72.       }
  73.     if (oper_mode != QUIET)
  74.       printf(MSG_REP, outfile);
  75.     if (oper_mode == VERBOSE)
  76.       printf(MSG_REC);
  77.     lp[P_BBS].incl_fspec = "DOWNSORT.HDR"; // header filename
  78.     file_incl(pf, P_BBS);               // include bbs-header file
  79.  
  80.     fprintf(pf,"\n%c(%s) Last %c%u %s%cnewest of a total of"
  81.                " %c%u%c files (%c%lu%c MB)",
  82.                 O_CYAN, sys_date(today),
  83.                 O_YELLOW, lp[P_BBS].max_fil,
  84.                 (lp[P_BBS].listflag==' ') ? EMPTY :
  85.                  ((lp[P_BBS].listflag=='D') ? DAYS :
  86.                   ((lp[P_BBS].listflag=='W') ? WEEKS : MONTHS)),
  87.                 O_CYAN,
  88.                 O_YELLOW, fc, O_CYAN,
  89.                 O_BRIGHT+O_MAGENTA,
  90.                 (count_bytes(area)/1024+512)/1024,O_CYAN);
  91.  
  92.     if (lp[P_BBS].sortflag == ALPHA &&      // for filename-sorted list only
  93.                         cn != NULL)  {      // new file available
  94.       fprintf(pf,"\n%19sNewest: %c%s %c%8s",
  95.                     "", O_YELLOW, cn->fname,
  96.                     O_GREEN,f_date(cn->wdate) );
  97.       fprintf(pf," %c(avail: %c%8s%c)",
  98.                     O_CYAN,O_GREEN,
  99.                     f_date(cn->cdate),O_CYAN);
  100.       }
  101.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  102.                "", DF, DAYS_7, WK, DAYS_30, MO);
  103.     if (lp[P_BBS].exclflag != EXCLPRIV)
  104.       fprintf(pf,"\n\n%c(Your privilege-level may limit the number "
  105.                 "of files actually shown to you!)%c",O_RED,O_CYAN);
  106.     fprintf(pf,"\n\n%c%s     %c%s  %c%s   %c%s    %c%s\n\n",
  107.                 O_YELLOW,FN,
  108.                 O_BRIGHT+O_RED,AC,
  109.                 O_MAGENTA,SZ,
  110.                 O_GREEN,DT,
  111.                 O_CYAN,DS);
  112.     for (i=j=0; j<n && i<file_total_count; i++) {
  113.       if (dm[i]->priv <= lp[P_BBS].priv[x]) {  // limit to report priv.
  114.         if (oper_mode==VERBOSE && (j%25)==0)
  115.           cprintf("\r %5u",j);
  116.         ++j;                            // list file-count
  117.         fprintf(pf,"%cL%c%c%-12.12s %c%4.4s %c%4ldK %c%s%c %c",
  118.                     '\20',
  119.                     (dm[i]->priv>SYSOP)?'S':priv_name[dm[i]->priv-TWIT][0],
  120.                     O_YELLOW,dm[i]->fname,
  121.                     O_RED+O_BRIGHT,dm[i]->parea->name,
  122.                     O_MAGENTA,(dm[i]->size+1023)/1024,
  123.                     O_GREEN,f_date(dm[i]->wdate),
  124.                     file_age_ind(dm[i]->cdate,dm[i]->ctime),  // file age
  125.                     O_CYAN);
  126.         desc_part(pf, dm[i]->fdesc, 45, 45, P_BBS);  /* file description */
  127.         }
  128.       }
  129.     if (oper_mode==VERBOSE)
  130.       printf("\r %5u",j);
  131.     signature(pf,today);                // fingerprint
  132.     lp[P_BBS].incl_fspec = "DOWNSORT.TRL"; // trailer filename
  133.     file_incl(pf, P_BBS);               // include bbs-trailer file
  134.     fclose(pf);                         // finished with .BBS file
  135.     }
  136.   else                                  // no output possible
  137.     printf(OPEN_FAIL, outfile, 0);
  138.   }
  139.  
  140. /* ------------------------------------------- */
  141. /* Produce the file-request format of NEW-list */
  142. /* ------------------------------------------- */
  143. void make_new(struct  _filechain **dm,
  144.               struct  _downpath huge *area,
  145.               unsigned int x)           // report priv index
  146. {
  147.   FILE  *pf;                            // file handle
  148.   char  outfile[MAXFN];                 // file names
  149.   unsigned int i,j,n,fc;                // counters
  150.   struct _filechain *cn;                // ptr to newest
  151.   short int max_age;                    // allowed file age in days
  152.  
  153.   sprintf(outfile,"%s.%s%c",
  154.           lp[P_NEW].name,
  155.           lp[P_NEW].ext,
  156.           priv_name[lp[P_NEW].priv[x]-TWIT][0]);
  157.   pf = fopen(outfile,WRITE);            // output file
  158.   if (pf != NULL) {                     // opened!
  159.     if (oper_mode == VERBOSE)
  160.       printf(MSG_SRT,file_total_count,area_total_count,outfile);
  161.     psort(dm, 0, file_total_count-1, sort_new);
  162.     fc = preproc_area(area, dm, lp[P_NEW].priv[x]); // count file, bytes
  163.     cn = NULL;                          // no assigned
  164.     if (lp[P_NEW].listflag == ' ') {    // limited by number of entries
  165.       n = lp[P_NEW].max_fil;            // take maximum files to be listed
  166.       if (n > fc)                       // more req'd than within priv
  167.         n = fc;                         // new request-limit
  168.       for (i=j=0; j<n && i<file_total_count; ++i)  // scan limits
  169.         if (dm[i]->priv <= lp[P_NEW].priv[x]) { // check file-privilege
  170.           ++j;                          // count within priv.
  171.           cn = new_acq(dm[i],cn);       // most recent within priv.
  172.           }
  173.       }
  174.     else {                              // limited by age
  175.       max_age = lp[P_NEW].max_fil *
  176.                     ((lp[P_NEW].listflag == 'W') ? 7 :
  177.                      ((lp[P_NEW].listflag == 'M') ? 30 : 1));
  178.       for (i=n=0; file_age(dm[i]) <= max_age &&
  179.                   i<file_total_count; ++i)  // get report limit
  180.         if (dm[i]->priv <= lp[P_NEW].priv[x]) { // check file-privilege
  181.           ++n;                          // count within priv and age
  182.           cn = new_acq(dm[i],cn);       // most recent within priv
  183.           }
  184.       }
  185.     if (lp[P_NEW].sortflag == ALPHA) {  // resort first entries on name
  186.       if (oper_mode == VERBOSE)
  187.         printf(MSG_RST, n);             // re-sort msg
  188.       psort(dm, 0, i-1, sort_gbl);      // sort first 'i' entries
  189.       }
  190.     if (oper_mode != QUIET)
  191.       printf(MSG_REP, outfile);
  192.     if (oper_mode==VERBOSE)
  193.       printf(MSG_REC);
  194.     insert_title(pf, pre_title, 0);
  195.     block_title(pf, 20, list_title, P_NEW);
  196.     file_incl(pf, P_NEW);               // insert user-'logo'
  197.     insert_title(pf, sub_title, 0);
  198.     fprintf(pf,"\n(%s) Last %u %snewest of a total of %u files (%lu MB)",
  199.                  sys_date(today),
  200.                  lp[P_NEW].max_fil,
  201.                 (lp[P_NEW].listflag==' ') ? EMPTY :
  202.                  ((lp[P_NEW].listflag=='D') ? DAYS :
  203.                   ((lp[P_NEW].listflag=='W') ? WEEKS : MONTHS)),
  204.                  fc, (count_bytes(area)/1024+512)/1024);
  205.     if (lp[P_NEW].exclflag != EXCLPRIV)
  206.       fprintf(pf,"\n%19s%s%s",
  207.                "",MP,priv_name[lp[P_NEW].priv[x]-TWIT]);
  208.     if (lp[P_NEW].sortflag == ALPHA &&  // for filename-sorted list only
  209.                  cn != NULL) {          // newest file
  210.       fprintf(pf,"\n%19sNewest: %s dd %8s",
  211.                  "", cn->fname, f_date(cn->wdate));
  212.       fprintf(pf," (avail: %8s)",
  213.                  f_date(cn->cdate));
  214.       }
  215.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  216.                "", DF, DAYS_7, WK, DAYS_30, MO);
  217.     fprintf(pf,"\n\n%s     %s  %s   %s    %s\n",FN,AC,SZ,DT,DS);
  218.     sep_line(pf, '─', 12, 4, 5, 9, 45, 0);
  219.     for (i=j=0; j<n && i<file_total_count; i++) {
  220.       if (dm[i]->priv <= lp[P_NEW].priv[x]) {   // only upto max priv_level
  221.         if (oper_mode==VERBOSE && (j%25)==0)
  222.           cprintf("\r %5u",j);
  223.         ++j;                            // file list-count
  224.         fprintf(pf,"%-12.12s %4.4s %15s ",
  225.               dm[i]->fname,
  226.               dm[i]->parea->name,
  227.               f_size_date(dm[i]->size, dm[i]->wdate,
  228.                           dm[i]->cdate, dm[i]->ctime));
  229.         desc_part(pf, dm[i]->fdesc, 45, 45, P_NEW);  /* file descr. */
  230.         }
  231.       }
  232.     if (oper_mode==VERBOSE)
  233.       printf("\r %5u",j);
  234.     signature(pf,today);                // leave fingerprint
  235.     insert_title(pf, bot_lines, 0);
  236.     fclose(pf);                         // finished with .NEW file
  237.     }
  238.   else
  239.     printf(OPEN_FAIL, outfile, 0);
  240.   }
  241.  
  242. /* ------------------------------------------- */
  243. /* Produce the file-request format of EMI-list */
  244. /* This is a more compact variant of NEW-list. */
  245. /* File date, time and size are exact.         */
  246. /* ------------------------------------------- */
  247. void make_emi(struct  _filechain **dm,
  248.               struct  _downpath huge *area,
  249.               unsigned int x)           // report priv index
  250. {
  251.   FILE  *pf;                            // file handle
  252.   char  outfile[MAXFN];                 // file names
  253.   unsigned int i,j,n,fc;                // counters
  254.   struct _filechain *cn;                // ptr to newest
  255.   short int max_age;                    // allowed file age in days
  256.  
  257.   sprintf(outfile,"%s.%s%c",
  258.           lp[P_EMI].name,
  259.           lp[P_EMI].ext,
  260.           priv_name[lp[P_EMI].priv[x]-TWIT][0]);
  261.   pf = fopen(outfile,WRITE);            // output file
  262.   if (pf != NULL) {                     // opened!
  263.     if (oper_mode == VERBOSE)
  264.       printf(MSG_SRT,file_total_count,area_total_count,outfile);
  265.     psort(dm, 0, file_total_count-1, sort_new);
  266.     fc = preproc_area(area, dm, lp[P_EMI].priv[x]); // count file, bytes
  267.     cn = NULL;                          // no assigned
  268.     if (lp[P_EMI].listflag == ' ') {    // limited by number of entries
  269.       n = lp[P_EMI].max_fil;            // take maximum files to be listed
  270.       if (n > fc)                       // more req'd than within priv
  271.         n = fc;                         // new request-limit
  272.       for (i=j=0; j<n && i<file_total_count; ++i)  // scan limits
  273.         if (dm[i]->priv <= lp[P_EMI].priv[x]) { // check file-privilege
  274.           ++j;                          // count within priv.
  275.           cn = new_acq(dm[i],cn);       // most recent within priv.
  276.           }
  277.       }
  278.     else {                              // limited by age
  279.       max_age = lp[P_EMI].max_fil *
  280.                     ((lp[P_EMI].listflag == 'W') ? 7 :
  281.                      ((lp[P_EMI].listflag == 'M') ? 30 : 1));
  282.       for (i=n=0; file_age(dm[i]) <= max_age &&
  283.                   i<file_total_count; ++i)  // get report limit
  284.         if (dm[i]->priv <= lp[P_EMI].priv[x]) { // check file-privilege
  285.           ++n;                          // count within priv and age
  286.           cn = new_acq(dm[i],cn);       // most recent within priv
  287.           }
  288.       }
  289.     if (lp[P_EMI].sortflag == ALPHA) {  // resort first entries on name
  290.       if (oper_mode == VERBOSE)
  291.         printf(MSG_RST, n);             // re-sort msg
  292.       psort(dm, 0, i-1, sort_gbl);      // sort first 'i' entries
  293.       }
  294.     if (oper_mode != QUIET)
  295.       printf(MSG_REP, outfile);
  296.     if (oper_mode==VERBOSE)
  297.       printf(MSG_REC);
  298.     file_incl(pf, P_EMI);               // insert user text
  299.     fprintf(pf,"\n(%s) Last %u %semissions",
  300.                  sys_date(today),
  301.                  lp[P_EMI].max_fil,
  302.                 (lp[P_EMI].listflag==' ') ? EMPTY :
  303.                  ((lp[P_EMI].listflag=='D') ? DAYS :
  304.                   ((lp[P_EMI].listflag=='W') ? WEEKS : MONTHS)));
  305.     fprintf(pf,"\n\n--%s-- --%s--  -%s-  -%s-  ---%s---\n",
  306.                   FN,DT,TM,BY,DS);
  307.     for (i=j=0; j<n && i<file_total_count; i++) {
  308.       if (dm[i]->priv <= lp[P_EMI].priv[x]) {   // only upto max priv_level
  309.         if (oper_mode==VERBOSE && (j%25)==0)
  310.           cprintf("\r %5u",j);
  311.         ++j;                            // file list-count
  312.         fprintf(pf,"%-12.12s %8.8s  %6.6s %8u  ",
  313.               dm[i]->fname,
  314.               f_date(dm[i]->wdate),
  315.               f_time(dm[i]->wtime),
  316.               dm[i]->size);
  317.         desc_part(pf, dm[i]->fdesc, 39, 66, P_EMI);  /* file descr. */
  318.         }
  319.       }
  320.     if (oper_mode==VERBOSE)
  321.       printf("\r %5u",j);
  322.     fprintf(pf,"\n-- List created with %s %c.%c%c by %s --\n\n",
  323.                 PROGNAME,VERSION,SUBVERS,SUFFIX,AUTHOR);
  324.     fclose(pf);                         // finished with .EMI file
  325.     }
  326.   else
  327.     printf(OPEN_FAIL, outfile, 0);
  328.   }
  329.  
  330. /* ------------------------------------ */
  331. /* Calculate file-age in number of days */
  332. /* ------------------------------------ */
  333. short int file_age(struct _filechain *f)
  334. {
  335.   return((short int)((time(NULL) - file_time(f->cdate,f->ctime))/86400));
  336.   }
  337.