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