home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / DWNSRS56.ZIP / DOWNRPT3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-15  |  14.0 KB  |  331 lines

  1. /* ================================================================ */
  2. /*  Rob Hamerling's MAXIMUS download file scan and sort utility     */
  3. /*  -> DOWNRPT3.C                                                   */
  4. /*  -> Make SYSOP lists: ORP-list, DUP-list, OK-file, all FILES.BBS */
  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. /* prototypes of local functions */
  21.  
  22. int      dup_fil(struct _filechain **, unsigned int);
  23.  
  24. /* ------------------------- */
  25. /* Produce the ORPHAN report */
  26. /* ------------------------- */
  27. void make_orp(struct _filechain **dm,
  28.               struct  _downpath huge *area,
  29.               unsigned int  x)          // report privilege index
  30. {
  31.   FILE  *pf;                            // file handle
  32.   char  outfile[MAXFN];                 // file names
  33.   unsigned int i,j,fc;                  // counters
  34.  
  35.   sprintf(outfile,"%s.%s",lp[P_ORP].name,lp[P_ORP].ext);  // build filename
  36.   if (oper_mode==VERBOSE)
  37.     printf(MSG_SRT,file_total_count,area_total_count,outfile);
  38.   switch(lp[P_ORP].sortflag) {          // sort
  39.     case ALPHA:     psort(dm,0,file_total_count-1,sort_gbl); break;
  40.     case TIMESTAMP: psort(dm,0,file_total_count-1,sort_new); break;
  41.     default: break;
  42.     }
  43.  
  44.   fc = preproc_area(area, dm, lp[P_ORP].priv[x]); // files within priv
  45.   j = file_total_count - fc;            // calc orphans
  46.   if (j>0) {                            // yes, there are orphans
  47.     pf = fopen(outfile,WRITE);          // output file
  48.     if (pf != NULL) {                   // successful open
  49.       if (oper_mode != QUIET)
  50.         printf(MSG_REP, outfile);
  51.       if (oper_mode == VERBOSE)
  52.         printf(MSG_REC);
  53.       block_title(pf, 9, " Orphans ", P_ORP); // generate block title
  54.       fprintf(pf, "\n");
  55.       sep_line(pf, '═', 79, 0);         // separator line
  56.       fprintf(pf,"%s %s       %s    %-s\n", AC, FN, DT, FP);
  57.       sep_line(pf, '─', 4, 12, 9, 51, 0);
  58.       for (i=j=0; i<file_total_count; i++) {
  59.         if (dm[i]->priv >= HIDDEN) {    // report "hidden" and up
  60.           if (oper_mode==VERBOSE && (j%25)==0)
  61.             cprintf("\r %5u",j);
  62.           ++j;                          // list file-count
  63.           dm[i]->fdesc = ORPHAN;        // assign 'description'
  64.           fprintf(pf,"%4.4s %-12.12s %s  ",
  65.                       dm[i]->parea->name,
  66.                       dm[i]->fname,
  67.                       f_date(dm[i]->wdate));
  68.           desc_part(pf, dm[i]->parea->pname, 51, 51, P_ORP);
  69.           }
  70.         }
  71.       if (oper_mode==VERBOSE)
  72.         printf("\r %5u",j);             // total reported orphans
  73.       signature(pf,today);              // fingerprint
  74.       fclose(pf);                       // finished with .ORP file
  75.       }
  76.     else                                // no output possible
  77.       printf(OPEN_FAIL, outfile, 0);
  78.     }
  79.   }
  80.  
  81. /* ------------------ */
  82. /* Produce a DUP-list */
  83. /* ------------------ */
  84. void make_dup(struct _filechain **dm,
  85.               unsigned int x)           // list privilege index
  86. {
  87.   FILE  *pf;                            // file handle
  88.   char  outfile[MAXFN];                 // file names
  89.   unsigned int i,j;                     // counters
  90.  
  91.   sprintf(outfile,"%s.%s", lp[P_DUP].name, lp[P_DUP].ext);
  92.   pf = fopen(outfile,WRITE);              // output file
  93.   if (pf != NULL) {
  94.     if (oper_mode == VERBOSE)
  95.       printf(MSG_SRT,file_total_count,area_total_count,outfile);
  96.     psort(dm, 0, file_total_count-1, sort_gbl);  // filename sort
  97.     if (oper_mode != QUIET)
  98.       printf(MSG_REP, outfile);
  99.     if (oper_mode == VERBOSE)
  100.       printf(MSG_REC);
  101.     block_title(pf, 12, " Duplicates ", P_DUP);
  102.     if (lp[P_DUP].exclflag != EXCLPRIV)
  103.       fprintf(pf,"\n%s%s\n",
  104.                  MP, priv_name[lp[P_DUP].priv[x]-TWIT]);
  105.     fprintf(pf,"\n%s     %s  %s   %s    %s\n",FN,AC,SZ,DT,DS);
  106.     sep_line(pf, '─', 12, 4, 5, 9, 45,0 );
  107.     for (i=j=0; i<file_total_count; i++) {
  108.       if (dm[i]->priv <= lp[P_DUP].priv[x]  &&  // within priv limit and
  109.           dup_fil(dm, i)) {             // if duplicate
  110.         if (oper_mode==VERBOSE && (j%5)==0)
  111.           cprintf("\r %5u",j);          // display count by 5
  112.         if (dm[i]->fname[0] != '\0') {  // not a comment-entry
  113.           j++;                          // count duplicates
  114.           fprintf(pf,"%-12.12s %4.4s %15s ",
  115.                   dm[i]->fname,
  116.                   dm[i]->parea->name,
  117.                   f_size_date(dm[i]->size, dm[i]->wdate,
  118.                               dm[i]->cdate, dm[i]->ctime));
  119.           desc_part(pf, dm[i]->fdesc, 45, 45, P_DUP);  /* file descr. */
  120.           }
  121.         }
  122.       }
  123.     if (oper_mode==VERBOSE)
  124.       printf("\r %5u",j);
  125.     signature(pf,today);                // leave fingerprint
  126.     fclose(pf);                         // finished with .DUP file
  127.     }
  128.   else
  129.     printf(OPEN_FAIL, outfile, 0);
  130.   }
  131.  
  132. /* ---------------------------------------- */
  133. /* Test on duplicate filenames for GBL-list */
  134. /* Returns 0 if NOT equal, 1 if equal.      */
  135. /* ---------------------------------------- */
  136. int  dup_fil(struct  _filechain **dm,
  137.              unsigned int  k)           // index in dm
  138. {
  139.   char f1[9],f2[9];                     // filenames
  140.  
  141.   non_wild_init(8, f1, dm[k]->fname);   // filename of current entry
  142.   f1[8] = '\0';                         // end of string
  143.   if (k>0) {                            // not very first
  144.     non_wild_init(8, f2, dm[k-1]->fname);  // previous entry
  145.     f2[8] = '\0';                       // end of string
  146.     if (!strcmp(f1,f2))                 // equal
  147.       return(1);
  148.     }
  149.   if (k<file_total_count-1) {           // not very last
  150.     non_wild_init(8, f2, dm[k+1]->fname);  // next entry
  151.     f2[8] = '\0';                       // end of string
  152.     if (!strcmp(f1,f2))                 // equal
  153.       return(1);
  154.     }
  155.   return(0);                            // not equal
  156.   }
  157.  
  158. /* ---------------------------------------------------------------- */
  159. /* Produce the FILES.BBS files for all area's                       */
  160. /* Sort on name within priv-group, date or as in input FILES.BBS    */
  161. /* Call them FILESBBS.xx  (where 'xx' is a 2-character area-name).  */
  162. /* Put them in the directory indicated by AREA.DAT for 'listfile'.  */
  163. /* ---------------------------------------------------------------- */
  164. void make_fil(struct  _filechain **dm,
  165.               struct  _downpath huge *area,
  166.               unsigned int  x)
  167. {
  168.   FILE   *pf;                           // file handle
  169.   char   outfile[MAXPATH];              // file spec new FILES.bbs
  170.   char   oldfile[MAXPATH];              // file spec old FILES.bbs
  171.   char   ac[40];                        // area name
  172.   unsigned int i,j,m,fc;                // counters
  173.   int    c_priv;                        // privilege
  174.  
  175.   if (oper_mode == VERBOSE)
  176.     printf(MSG_SRT,file_total_count,area_total_count,"FILES.BBS-files");
  177.  
  178.   switch(lp[P_FIL].sortflag) {
  179.     case ALPHA:     psort(dm,0,file_total_count-1,sort_fil);  break;
  180.     case TIMESTAMP: psort(dm,0,file_total_count-1,sort_al2);  break;
  181.     case KEEPSEQ:   psort(dm,0,file_total_count-1,sort_akp);  break;
  182.     default: break;
  183.     }
  184.  
  185.   fc = preproc_area(area, dm, lp[P_FIL].priv[x]); // count files, bytes
  186.   if (oper_mode != QUIET)
  187.     printf(MSG_REP,"all FILES.BBS files");
  188.   pf = NULL;                            // no file open yet
  189.   ac[0] = '\0';                         // init with null-string
  190.   for (i=0; i<file_total_count; i++) {
  191.     if (strcmp(ac,dm[i]->parea->name)) {  // new area group
  192.       if (pf != NULL)                   // end of previous group
  193.         fclose(pf);                     // finished
  194.       strcpy(ac, dm[i]->parea->name);   // new area
  195.       c_priv = dm[i]->parea->priv;      // new AREA-priv
  196.                                         // generate new FILES.bbs
  197.       if (strlen(filesbbs_path) > 0) {  // FIL:path parameter specified
  198.         strcpy(outfile,filesbbs_path);  // copy path
  199.         strcat(outfile,lp[P_FIL].name); // add filename
  200.         strcat(outfile,DOT);            // add separator
  201.         strncat(outfile, ac, 3);        // max first 3 bytes of areaname
  202.         }
  203.       else if (strlen(dm[i]->parea->filesbbs) > 0) { // "ListFile" spec
  204.         strcpy(outfile,dm[i]->parea->filesbbs);
  205.         strcpy(oldfile,outfile);        // backup file
  206.         for (j=strlen(oldfile), m=1;
  207.                  (j-m)>0 && m<5 && outfile[j-m]!='.'; ++m); // search '.'
  208.         if (m>=5 || (j-m)<=0)           // no extension found:
  209.           m=0;                          // concat to end of name
  210.         strcpy(oldfile+j-m,DOT);        // add separator
  211.         strcat(oldfile,BAK);            // backup file extension
  212.         unlink(oldfile);                // erase old backup file
  213.         rename(outfile,oldfile);        // rename current to backup
  214.         }
  215.       else {                            // default directory
  216.         strcpy(outfile,dm[i]->parea->pname);  // path to download directory
  217.         strcat(outfile,lp[P_FIL].name); // add filename
  218.         strcat(outfile,DOT);            // add separator
  219.         strcpy(oldfile,outfile);        // backup file
  220.         strcat(oldfile,BAK);            // backup file extension
  221.         strcat(outfile,lp[P_FIL].ext);  // add BBS-extension
  222.         unlink(oldfile);                // erase old backup file
  223.         rename(outfile,oldfile);        // rename current to backup
  224.         }
  225.  
  226.       pf = fopen(outfile,WRITE);
  227.       if (pf != NULL) {
  228.         fprintf(pf,"-\f\n-%s ║ %-.60s\n",
  229.                   strnblk(ac,3,FONT3,LINE1),
  230.                   dm[i]->parea->adesc);
  231.         fprintf(pf,"-%s ║ Available: %u files (%lu.%lu MB)\n",
  232.                   strnblk(ac,3,FONT3,LINE2),
  233.                   dm[i]->parea->file_count,         // area filecount
  234.                   (dm[i]->parea->byte_count+52428L)/1048576L, // rounded to 100K
  235.                   ((dm[i]->parea->byte_count+52429L)/104857L)%10); // 100K frac
  236.         fprintf(pf,"-%s ║",
  237.                     strnblk(ac,3,FONT3,LINE3));
  238.         if (lp[P_FIL].exclflag != EXCLPRIV)
  239.           fprintf(pf," Privilege: %-.9s",
  240.                     priv_name[dm[i]->parea->priv-TWIT]);  // area privilege
  241.         fprintf(pf,"\n-%s ║ ",
  242.                     strnblk(ac,3,FONT3,LINE4));
  243.         if (dm[i]->parea->newest  != NULL) {              // newest file
  244.           fprintf(pf,"Newest: %s %8s",
  245.                     dm[i]->parea->newest->fname,
  246.                     f_date(dm[i]->parea->newest->wdate));
  247.           fprintf(pf," (avail: %8s)",
  248.                     f_date(dm[i]->parea->newest->cdate));
  249.           }
  250.         fprintf(pf,"\n-");
  251.         sep_line(pf, '─', 78, 0);
  252.         file_incl(pf,P_FIL);            // insert user-'logo'
  253.         fprintf(pf," %s      %s    %s     %s\n-",FN,SZ,DT,DS);
  254.         sep_line(pf, '─', 11, 7, 9, 48, 0);
  255.         }
  256.       else
  257.         printf(OPEN_FAIL, outfile, 0);
  258.       }                                 // endif
  259.     if (pf != NULL) {                   // check for open file
  260.       if (dm[i]->priv <= lp[P_FIL].priv[x]) {  // specified reporting level
  261.         if (dm[i]->priv > c_priv) {     // higher priv group within area
  262.           c_priv = dm[i]->priv;         // set new
  263.           fprintf(pf,"%c%c\n", '\20',
  264.                      (c_priv>SYSOP) ? 'S' : priv_name[c_priv-TWIT][0]);
  265.           }
  266.         if (dm[i]->fname[0] != '\0') {  // filename present
  267.           fprintf(pf,"%-12.12s ", dm[i]->fname); // filename
  268.           if (dm[i]->dl_b==1 || dm[i]->dl_t==1) {  // download flags
  269.             fprintf(pf,"/");
  270.             if (dm[i]->dl_b==1)         // free bytes flag
  271.               fprintf(pf,"b");
  272.             if (dm[i]->dl_t==1)         // free time flag
  273.               fprintf(pf,"t");
  274.             }
  275.           fprintf(pf," %-s\n", dm[i]->fdesc);  // description
  276.           }
  277.         else if(lp[P_FIL].sortflag == KEEPSEQ)  // '/K' specified
  278.           fprintf(pf,"%-s\n", dm[i]->fdesc);
  279.         }
  280.       }
  281.     }
  282.   if (pf != NULL)                       // end of last FILES.BBS
  283.     fclose(pf);                         // finished with FILES.bbs file
  284.   }                                     // end
  285.  
  286. /* ------------------------------ */
  287. /* Produce the BinkleyTerm OKFile */
  288. /* (area's in downpath sequence!) */
  289. /* ------------------------------ */
  290. void make_ok(struct  _filechain **dm,
  291.              struct  _downpath huge *area,
  292.              unsigned int  x)
  293. {
  294.   FILE   *pf;                           // file handle
  295.   char   outfile[MAXFN];                // file names
  296.   unsigned int i,j;                     // counters
  297.  
  298.   sprintf(outfile,"%s.%s%c",
  299.           lp[P_OK].name,
  300.           lp[P_OK].ext,
  301.           priv_name[lp[P_OK].priv[x]-TWIT][0]);
  302.   pf = fopen(outfile,WRITE);            // output file
  303.   if (pf != NULL) {
  304.     if (oper_mode != QUIET)
  305.       printf(MSG_REP, outfile);
  306.     file_incl(pf, P_OK);                // insert magic filenames
  307.     preproc_area(area, dm, lp[P_OK].priv[x]); // count files, bytes
  308.     if (lp[P_OK].longflag == LONGLIST) {   // LONG list requested
  309.       for (i=0; i<file_total_count; i++) {     // all files in chain
  310.         if (dm[i]->priv <= lp[P_OK].priv[x] && // check file privilege
  311.             dm[i]->fname[0] != '\0')           // filename present
  312.           fprintf(pf, "@%s %s%s\n",
  313.                       dm[i]->fname, dm[i]->parea->pname, dm[i]->fname);
  314.         }
  315.       }
  316.     else {
  317.       for (i=j=0; i<area_total_count; i++)  // all area's in array
  318.         if (area[i].priv <= lp[P_OK].priv[x] &&   // area privilege
  319.             area[i].file_count > 0)       // and at least 1 file
  320.           if (i<1 || strcmp(area[i].pname,area[j].pname)) { // not yet in
  321.             fprintf(pf, "%s*.*\n", area[i].pname);
  322.             j = i;                        // index of last 'printed'
  323.             }
  324.       }
  325.     fclose(pf);                         // finished with .ALL file
  326.     }
  327.   else
  328.     printf(OPEN_FAIL, outfile, 0);      // open failed
  329.   }
  330.  
  331.