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

  1. /* ================================================================ */
  2. /*  Rob Hamerling's MAXIMUS download file scan and sort utility     */
  3. /*  -> DOWNRPT4.C                                                   */
  4. /*  -> Make GBL-list, ALL-list.                                     */
  5. /* ================================================================ */
  6.  
  7. #define INCL_BASE
  8. #include <os2.h>
  9.  
  10. #include <conio.h>
  11. #include <malloc.h>
  12. #include <memory.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. #include "..\max\mstruct.h"
  18. #include "downsort.h"
  19. #include "downfpro.h"
  20.  
  21. /* prototypes of local functions */
  22. /* ------------------------------------------- */
  23. /* Produce the file-request format of GBL-list */
  24. /* ------------------------------------------- */
  25. void make_gbl(struct  _filechain **dm,
  26.               struct  _downpath huge *area,
  27.               unsigned int  x)          // report privilege index
  28. {
  29.   FILE  *pf;                            // file handle
  30.   char  outfile[MAXFN];                 // file names
  31.   unsigned int i,j,fc;                  // counters
  32.   struct _filechain *cn;                // pointer to file-info
  33.  
  34.   sprintf(outfile,"%s.%s%c",
  35.           lp[P_GBL].name,
  36.           lp[P_GBL].ext,
  37.           priv_name[lp[P_GBL].priv[x]-TWIT][0]);
  38.   pf = fopen(outfile,WRITE);              // output file
  39.   if (pf == NULL)
  40.     printf(OPEN_FAIL, outfile, 0);      // no GBL list!
  41.   else {
  42.     if (oper_mode == VERBOSE)
  43.       printf(MSG_SRT,file_total_count,area_total_count,outfile);
  44.     switch(lp[P_GBL].sortflag) {
  45.       case ALPHA:     psort(dm,0,file_total_count-1,sort_gbl); break;
  46.       case TIMESTAMP: psort(dm,0,file_total_count-1,sort_new); break;
  47.       default: break;
  48.       }
  49.     fc = preproc_area(area, dm, lp[P_GBL].priv[x]);
  50.     cn = NULL;                          // no assigned
  51.     for (i=0; i<file_total_count; ++i)        // stop at end of files
  52.       if (dm[i]->priv <= lp[P_GBL].priv[x])   // check file-privilege
  53.         cn = new_acq(dm[i],cn);         // keep pointer to most recent
  54.     if (oper_mode != QUIET)
  55.       printf(MSG_REP, outfile);
  56.     if (oper_mode==VERBOSE)
  57.       printf(MSG_REC);
  58.     insert_title(pf, pre_title, 0);
  59.     block_title(pf, 20, list_title, P_GBL);
  60.     file_incl(pf,P_GBL);                // insert user-'logo'
  61.     insert_title(pf, sub_title, 0);
  62.     fprintf(pf,"\n(%s) Available: %u files (%lu MB)",
  63.                 sys_date(today),
  64.                 fc,
  65.                (count_bytes(area)/1024+512)/1024);
  66.     if (lp[P_GBL].exclflag != EXCLPRIV)
  67.       fprintf(pf,"\n%19s%s%s",
  68.                "", MP, priv_name[lp[P_GBL].priv[x]-TWIT]);
  69.     if (cn != NULL) {
  70.       fprintf(pf,"\n%19sNewest: %s %8s",
  71.                "",cn->fname,f_date(cn->wdate));
  72.       fprintf(pf," (avail: %8s)",f_date(cn->cdate));
  73.       }
  74.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  75.                "", DF, DAYS_7, WK, DAYS_30, MO);
  76.     fprintf(pf,"\n\n%s     %s  %s   %s    %s\n",FN,AC,SZ,DT,DS);
  77.     sep_line(pf, '─', 12, 4, 5, 9, 45, 0);
  78.     for (i=j=0; i<file_total_count; i++) {
  79.       if (dm[i]->priv <= lp[P_GBL].priv[x]) {   // within priv limit
  80.         if (oper_mode==VERBOSE && (j%25)==0)
  81.           cprintf("\r %5u",j);
  82.         if (dm[i]->fname[0] != '\0') {  // not a comment-entry
  83.           j++;
  84.           fprintf(pf,"%-12.12s %4.4s %15s ",
  85.                   dm[i]->fname,
  86.                   dm[i]->parea->name,
  87.                   f_size_date(dm[i]->size, dm[i]->wdate,
  88.                               dm[i]->cdate, dm[i]->ctime));
  89.           desc_part(pf, dm[i]->fdesc, 45, 45, P_GBL);  /* file description */
  90.           }
  91.         }
  92.       }
  93.     if (oper_mode==VERBOSE)
  94.       printf("\r %5u",j);
  95.     signature(pf,today);                // leave fingerprint
  96.     insert_title(pf, bot_lines, 0);
  97.     fclose(pf);                         // finished with .GBL file
  98.     }
  99.   }
  100.  
  101. /* ------------------------------------------------------- */
  102. /* Produce the file-request format of ALLfiles  (ALL-list) */
  103. /* ------------------------------------------------------- */
  104. void make_all(struct  _filechain **dm,
  105.               struct  _downpath huge *area,
  106.               unsigned int  x)
  107. {
  108.   FILE   *pf;                           // file handle
  109.   char   outfile[MAXFN];                // file names
  110.   char   ac[40];                        // area name
  111.   unsigned int i,j,n,fc;                // counters
  112.   struct _downpath huge *area2;         // copy of area-array for sort
  113.  
  114.   sprintf(outfile,"%s.%s%c",
  115.           lp[P_ALL].name,
  116.           lp[P_ALL].ext,
  117.           priv_name[lp[P_ALL].priv[x]-TWIT][0]);
  118.   pf = fopen(outfile,WRITE);            // output file
  119.   if (pf != NULL) {
  120.     if (oper_mode == VERBOSE)
  121.       printf(MSG_SRT,file_total_count,area_total_count,outfile);
  122.     switch(lp[P_ALL].sortflag) {
  123.       case ALPHA:     psort(dm,0,file_total_count-1,sort_all); break;
  124.       case TIMESTAMP: psort(dm,0,file_total_count-1,sort_al2); break;
  125.       case KEEPSEQ:   psort(dm,0,file_total_count-1,sort_akp); break;
  126.       default: break;
  127.       }
  128.  
  129.     fc = preproc_area(area, dm, lp[P_ALL].priv[x]);
  130.     if (oper_mode!=QUIET)
  131.       printf(MSG_REP, outfile);
  132.     if (oper_mode==VERBOSE)
  133.       printf(MSG_REC);
  134.     insert_title(pf, pre_title, 0);
  135.     block_title(pf, 20, list_title, P_ALL);
  136.     file_incl(pf, P_ALL);               // insert user-'logo'
  137.     insert_title(pf, sub_title, 0);
  138.     fprintf(pf,"\n(%s) Available: %u files in %u areas (%lu MB)\n",
  139.                sys_date(today),
  140.                fc,
  141.                count_areas(area, lp[P_ALL].priv[x]),
  142.                (count_bytes(area)/1024+512)/1024);
  143.     if (lp[P_ALL].exclflag != EXCLPRIV)
  144.       fprintf(pf,"%19s%s%s\n",
  145.                "",MP,priv_name[lp[P_ALL].priv[x]-TWIT]);
  146.     fprintf(pf,"%19s%s %c%s, %c%s\n",
  147.                "", DF, DAYS_7, WK, DAYS_30, MO);
  148.     ac[0] = '\0';                       // null area name
  149.     n=0;                                // file counter for SYSOP
  150.     for (i=0; i<file_total_count; i++) {    // all files
  151.       if (strcmp(ac,dm[i]->parea->name)) {  // new area collection
  152.         strcpy(ac,dm[i]->parea->name);      // set new
  153.         if (dm[i]->parea->file_count > 0) { // any listable files in area
  154.           fprintf(pf,"\n\n");
  155.           sep_line(pf, '═', 79, 0);
  156.           if (max_aname <= 3) {          /* short areanames */
  157.             fprintf(pf,"%s ║ %-.60s\n",
  158.                         strnblk(ac,3,FONT3,LINE1),dm[i]->parea->adesc);
  159.             fprintf(pf,"%s ║ Available: %u files (%lu.%lu MB)\n",
  160.                       strnblk(ac,3,FONT3,LINE2),
  161.                       dm[i]->parea->file_count,
  162.                       (dm[i]->parea->byte_count+52428L)/1048576L,  // mod 100K
  163.                       ((dm[i]->parea->byte_count+52429L)/104857L)%10); // frac
  164.             fprintf(pf,"%s ║",
  165.                         strnblk(ac,3,FONT3,LINE3));
  166.             if (lp[P_ALL].exclflag != EXCLPRIV)
  167.               fprintf(pf," Privilege: %-.9s\n",
  168.                         priv_name[dm[i]->parea->priv-TWIT]);   // area privilege
  169.             else
  170.               fprintf(pf,"\n");
  171.             fprintf(pf,"%s ║",strnblk(ac,3,FONT3,LINE4));
  172.             }
  173.           else {                        /* long areanames */
  174.             fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE1));
  175.             fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE2));
  176.             fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE3));
  177.             fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE4));
  178.             sep_line(pf, '─', 79, 0);
  179.             fprintf(pf," %-.78s\n", dm[i]->parea->adesc);
  180.             fprintf(pf," Available: %u files (%lu.%lu MB)\n",
  181.                      dm[i]->parea->file_count,
  182.                      (dm[i]->parea->byte_count+52428L)/1048576L,  // mod 100K
  183.                      ((dm[i]->parea->byte_count+52429L)/104857L)%10); // frac
  184.             if (lp[P_ALL].exclflag != EXCLPRIV)
  185.               fprintf(pf," Privilege: %-.9s\n",
  186.                         priv_name[dm[i]->parea->priv-TWIT]);   // area priv
  187.             }
  188.           if (dm[i]->parea->newest != NULL) {     // newest file
  189.             fprintf(pf," Newest: %s %8s ",
  190.                         dm[i]->parea->newest->fname,
  191.                         f_date(dm[i]->parea->newest->wdate));
  192.             fprintf(pf," (avail: %8s)",
  193.                         f_date(dm[i]->parea->newest->cdate));
  194.             }
  195.           fprintf(pf, "\n");
  196.           sep_line(pf, '─', 79, 0);
  197.           fprintf(pf,"%s      %s   %s    %s\n",FN,SZ,DT,DS);
  198.           sep_line(pf, '─', 12, 5, 9, 50, 0);
  199.           }
  200.         }
  201.       if (dm[i]->priv <= lp[P_ALL].priv[x]) {  // only upto max priv_level
  202.         if (oper_mode==VERBOSE && (n%25)==0)
  203.           cprintf("\r %5u",n);          // keep SYSOP awake
  204.         if (dm[i]->fname[0] != '\0') {  // filename present
  205.           ++n;                          // count only file entries
  206.           fprintf(pf,"%-12.12s %15s ",
  207.                      dm[i]->fname,
  208.                      f_size_date(dm[i]->size, dm[i]->wdate,
  209.                           dm[i]->cdate, dm[i]->ctime));
  210.           desc_part(pf, dm[i]->fdesc, 50, 50, P_ALL);  /* file descr. */
  211.           }
  212.         else if (lp[P_ALL].sortflag == KEEPSEQ) {  // '/K' specified
  213.           fprintf(pf, "%-s\n",
  214.             (strip_ava == 'Y') ? strava(dm[i]->fdesc) : dm[i]->fdesc);
  215.           }
  216.         }
  217.       }
  218.     if (oper_mode==VERBOSE)             // last value
  219.       printf("\r %5u",n);
  220.                                         // Area Summary report
  221. #ifndef __32BIT__
  222.     area2 = (struct _downpath huge *)halloc(area_total_count,
  223.                                        sizeof(struct _downpath));
  224. #else
  225.     area2 = (struct _downpath *)malloc(area_total_count *
  226.                                        sizeof(struct _downpath));
  227. #endif
  228.                                         // dup area-array for sorting!
  229.     if (area2 == NULL) {                // memory not obtained?
  230.       if (oper_mode!=QUIET)
  231.         printf("\nNot enough memory for summary report, skipped.");
  232.       }
  233.     else {
  234.       memmove(area2,area,area_total_count*sizeof(struct _downpath));
  235.       qsort(area2,area_total_count,sizeof(struct _downpath),sort_summ);
  236.       if (oper_mode==VERBOSE)
  237.         printf(MSG_REP, SUMM);
  238.       fprintf(pf,"\n\n");
  239.       sep_line(pf, '═', 79, 0);
  240.       block_title(pf, 12, SUMM, P_ALL);
  241.       sep_line(pf, '═', 79, 0);
  242.       fprintf(pf,"%-8s %-54s %5s %8s\n",AC,DS,FS,BY);
  243.       sep_line(pf, '─', 8, 54, 5, 9, 0);
  244.       for (j=0; j<area_total_count; j++)
  245.         if (area2[j].file_count) {
  246.           fprintf(pf,"%-8.8s %-54.54s %5u %8luK\n",
  247.                      area2[j].name,
  248.                      area2[j].adesc,
  249.                      area2[j].file_count,
  250.                      (area2[j].byte_count+512)/1024);
  251.           }
  252.       sep_line(pf, '─', 63, 5, 9, 0);
  253.       fprintf(pf,"%63s %5u %8luK\n","Total:",
  254.                  count_files(area2),
  255.                  (count_bytes(area2)+512)/1024);
  256. #ifndef __32BIT__
  257.       hfree(area2);                     // free copy of area array
  258. #else
  259.       free(area2);                      // free copy of area array
  260. #endif
  261.       }
  262.  
  263.     signature(pf,today);                // leave fingerprint
  264.     insert_title(pf, bot_lines, 0);
  265.     fclose(pf);                         // finished with .ALL file
  266.     }
  267.   else
  268.     printf(OPEN_FAIL, outfile, 0);      // open failed
  269.   }
  270.  
  271.