home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / dwnsrs59.zip / DOWNRPT4.C < prev    next >
C/C++ Source or Header  |  1993-12-18  |  14KB  |  335 lines

  1.  
  2. /* ================================================================ */
  3. /*  Rob Hamerling's MAXIMUS download file scan and sort utility     */
  4. /*  -> DOWNRPT4.C                                                   */
  5. /*  -> Make GBL-list, ALL-list.                                     */
  6. /* ================================================================ */
  7.  
  8. #define INCL_BASE
  9. #define INCL_NOPMAPI
  10. #include <os2.h>
  11.  
  12. #include <conio.h>
  13. #include <malloc.h>
  14. #include <memory.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18.  
  19. #include "..\max\mstruct.h"
  20. #include "downsort.h"
  21. #include "downfpro.h"
  22.  
  23. /* prototypes of local functions */
  24. /* ------------------------------------------- */
  25. /* Produce the file-request format of GBL-list */
  26. /* ------------------------------------------- */
  27. void make_gbl(FILECHAIN * _HUGE *dm,
  28.               DOWNPATH  _HUGE *area,
  29.               LISTPARM  *ls)            /* report privilege index */
  30. {
  31.   FILE   *pf;                           /* file handle */
  32.   char   outfile[MAXFN];                /* file names */
  33.   ULONG  i,j,fc;                        /* counters */
  34.   ULONG  akb;                           /* bytecount in KB */
  35.   FILECHAIN *cn;                        /* pointer to info of spec. file */
  36.   FILECHAIN *fx;                        /* pointer to file info */
  37.  
  38.   sprintf(outfile,"%s.%s%c",
  39.           ls->name,
  40.           ls->ext,
  41.           priv_name[ls->priv-TWIT][0]);
  42.   pf = fopen(outfile,WRITE);            /* output file */
  43.   if (pf != NULL) {
  44.     if (oper_mode == VERBOSE)
  45.       fprintf(stdout, MSG_SRT, file_total_count, area_total_count, outfile);
  46.     switch(ls->sortflag) {
  47.       case ALPHA:
  48.       case GROUP:     psort(dm,0,file_total_count-1,sort_gbl); break;
  49.       case TIMESTAMP: psort(dm,0,file_total_count-1,sort_new); break;
  50.       default: break;
  51.       }
  52.     fc = preproc_area(area, dm, ls);
  53.     cn = NULL;                          /* no assigned */
  54.     for (i=0; i<file_total_count; ++i) {   /* stop at end of files */
  55.       fx = dm[i];                       /* copy pointer to file info */
  56.       if (rpt_coll(fx, ls, TRUE))       /* check if to be listed */
  57.         cn = new_acq(fx, cn);           /* keep pointer to most recent */
  58.       }
  59.     if (oper_mode != QUIET)
  60.       fprintf(stdout, MSG_REP, outfile);
  61.     if (oper_mode==VERBOSE)
  62.       fprintf(stdout, MSG_REC);
  63.     insert_title(pf, pre_title, 0);
  64.     block_title(pf, 20, EMPTY, list_title, ls);
  65.     file_incl(pf, ls);                  /* insert user-'logo' */
  66.     insert_title(pf, sub_title, 0);
  67.     akb = (count_bytes(area) + 512)/1024;    /* KBytes total */
  68.     fprintf(pf,"\n(%s) Available: %lu files (%lu %cB)",
  69.                   sys_date(today),
  70.                   fc,
  71.                   (akb < 9999) ? akb : (akb + 512)/1024,
  72.                   (akb < 9999) ? 'K' : 'M');
  73.     if (ls->exclflag != EXCLPRIV)
  74.       fprintf(pf,"\n%19s%s%s",
  75.                EMPTY, MP, priv_name[ls->priv-TWIT]);
  76.     if (cn != NULL  &&
  77.         cn->wd.idate != 0) {            /* true date */
  78.       fprintf(pf,"\n%19sNewest: %s %8s",
  79.                EMPTY,cn->fname,f_date(cn->wd.date));
  80.       fprintf(pf," (avail: %8s)",f_date(cn->cd.date));
  81.       }
  82.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  83.                EMPTY, DF, DAYS_7, WK, DAYS_30, MO);
  84.     fprintf(pf,"\n\n%s       %s    %s   %s    %s\n",FN,AC,SZ,DT,DS);
  85.     sep_line(pf, '─', 12, 8, 5, 9, 41, 0);
  86.     for (i=j=0; i<file_total_count; i++) {
  87.       fx = dm[i];                       /* copy pointer to file info */
  88.       if (rpt_coll(fx, ls, TRUE)) {     /* check if to be listed */
  89.         if (oper_mode==VERBOSE && (j%25)==0) {
  90.           fprintf(stdout, "%6lu\r", j);
  91.           fflush(stdout);
  92.           }
  93.         if (fx->fname[0] != '\0') {  /* not a comment-entry */
  94.           j++;
  95.           fprintf(pf,"%-12.12s %-8.8s %15s ",
  96.                   fx->fname,
  97.                   fx->parea->name,
  98.                   f_size_date(fx));
  99.           desc_part(pf, fx->fdesc, 41, 41-ls->desc_indent, ls);
  100.           }
  101.         }
  102.       }
  103.     if (oper_mode==VERBOSE)
  104.       fprintf(stdout, "%6lu\n", j);
  105.     signature(pf,today);                /* leave fingerprint */
  106.     insert_title(pf, bot_title, 0);
  107.     fclose(pf);                         /* finished with .GBL file */
  108.     }
  109.   else
  110.     fprintf(stderr, MSG_OPO, outfile, 0);      /* no GBL list! */
  111.   }
  112.  
  113. /* ------------------------------------------------------- */
  114. /* Produce the file-request format of ALLfiles  (ALL-list) */
  115. /* ------------------------------------------------------- */
  116. void make_all(FILECHAIN * _HUGE *dm,
  117.               DOWNPATH  _HUGE *area,
  118.               LISTPARM  *ls)
  119. {
  120.   FILE     *pf;                         /* file handle */
  121.   char     outfile[MAXFN];              /* file names */
  122.   char     ac[40];                      /* area name */
  123.   ULONG    i, j, n, fc;                 /* counters */
  124.   USHORT   k;                           /* counters */
  125.   ULONG    akb;                         /* bytecount in KB */
  126.   ULONG    lock;                        /* MAX lock pattern */
  127.   DOWNPATH _HUGE *area2;                /* copy of area-array for sort */
  128.   FILECHAIN *fx, *cn;                   /* pointer to file info */
  129.  
  130.   sprintf(outfile,"%s.%s%c",
  131.           ls->name,
  132.           ls->ext,
  133.           priv_name[ls->priv-TWIT][0]);
  134.   pf = fopen(outfile,WRITE);            /* output file */
  135.   if (pf != NULL) {
  136.     if (oper_mode == VERBOSE)
  137.       fprintf(stdout, MSG_SRT, file_total_count, area_total_count, outfile);
  138.     if (ls->listflag != ' ') {          /* limited by period */
  139.       psort(dm, 0, file_total_count-1, sort_new);
  140.       cn = NULL;                        /* no newest assigned yet */
  141.       n = rpt_count(dm, ls, &cn);       /* first 'n' to be proc'd */
  142.       if (n>0 && oper_mode == VERBOSE)
  143.         fprintf(stdout, MSG_RST, n);  /* re-sort msg */
  144.       }
  145.     else                                /* really all files */
  146.       n = file_total_count;             /* set list-count */
  147.     if (n > 0) {
  148.       switch(ls->sortflag) {
  149.         case ALPHA:
  150.         case GROUP:     psort(dm, 0, n-1, sort_all); break;
  151.         case TIMESTAMP: psort(dm, 0, n-1, sort_al2); break;
  152.         case KEEPSEQ:   psort(dm, 0, n-1, sort_akp); break;
  153.         default: break;
  154.         }
  155.       }
  156.     fc = preproc_area(area, dm, ls);
  157.     if (oper_mode!=QUIET)
  158.       fprintf(stdout, MSG_REP, outfile);
  159.     if (oper_mode==VERBOSE)
  160.       fprintf(stdout, MSG_REC);
  161.     insert_title(pf, pre_title, 0);
  162.     block_title(pf, 20, EMPTY, list_title, ls);
  163.     file_incl(pf, ls);                  /* insert user-'logo' */
  164.     insert_title(pf, sub_title, 0);
  165.     akb = (count_bytes(area) + 512)/1024;    /* KBytes total */
  166.     if (ls->listflag != ' ')            /* limited by period */
  167.       fprintf(pf,"\n(%s) Last %hu %snewest of a total of %lu files (%lu %cB)\n",
  168.                    sys_date(today),
  169.                   (ls->listflag!=' ' || fc>ls->max_fil) ?
  170.                          ls->max_fil : (USHORT)fc,
  171.                   (ls->listflag==' ') ? EMPTY :
  172.                    ((ls->listflag=='D') ? DAYS :
  173.                     ((ls->listflag=='W') ? WEEKS : MONTHS)),
  174.                    fc,
  175.                    (akb < 9999) ? akb : (akb-512)/1024,
  176.                    (akb < 9999) ? 'K' : 'M');
  177.     else
  178.       fprintf(pf,"\n(%s) Available: %lu files in %hu areas (%lu %cB)\n",
  179.                  sys_date(today),
  180.                  fc,
  181.                  count_areas(area, ls->priv),
  182.                  (akb < 9999) ? akb : (akb + 512)/1024,
  183.                  (akb < 9999) ? 'K' : 'M');
  184.     if (ls->exclflag != EXCLPRIV)
  185.       fprintf(pf,"%19s%s%s\n", EMPTY, MP, priv_name[ls->priv-TWIT]);
  186.     fprintf(pf,"%19s%s %c%s, %c%s\n",
  187.                EMPTY, DF, DAYS_7, WK, DAYS_30, MO);
  188.     ac[0] = '\0';                       /* null area name */
  189.     j = 0;                              /* count listed files */
  190.     for (i=0; i<n; i++) {               /* all files to be listed */
  191.       fx = dm[i];                       /* copy pointer to file info */
  192.       if (rpt_coll(fx, ls, TRUE)) {     /* check if to be listed */
  193.         if (strcmp(ac,fx->parea->name)) {  /* new area */
  194.           strcpy(ac, fx->parea->name);  /* store new areaname */
  195.           if (fx->parea->file_count > 0) { /* any listable files in area */
  196.             fprintf(pf,"\n\n");
  197.             sep_line(pf, '═', 79, 0);
  198.             akb = (fx->parea->byte_count + 512)/1024;
  199.             if (max_aname <= 3) {       /* short areanames */
  200.               fprintf(pf,"%s ║ %-.60s\n",
  201.                           strnblk(ac,3,ls->tfont,LINE1),fx->parea->adesc);
  202.               fprintf(pf,"%s ║ Available: %lu files (%lu %cB)\n",
  203.                         strnblk(ac,3,ls->tfont,LINE2),
  204.                         fx->parea->file_count,
  205.                         (akb < 9999) ? akb : (akb + 512)/1024,
  206.                         (akb < 9999) ? 'K' : 'M');
  207.               fprintf(pf,"%s ║",
  208.                           strnblk(ac,3,ls->tfont,LINE3));
  209.               if (ls->exclflag != EXCLPRIV) {
  210.                 fprintf(pf," Privilege: %-.9s",
  211.                           priv_name[fx->parea->priv-TWIT]); /* area priv */
  212.                 lock = fx->parea->filelock;       /* get lock */
  213.                 if (lock!=0) {
  214.                   fprintf(pf,"%c",'/');   /* locks */
  215.                   for (k=0; k<32; k++) {
  216.                     if (lock & 0x00000001)
  217.                       fprintf(pf,"%c",(k<8)?('1'+k):('A'+k-8));
  218.                     lock >>= 1;
  219.                     }
  220.                   }
  221.                 fprintf(pf, "\n");
  222.                 }
  223.               else
  224.                 fprintf(pf,"\n");
  225.               fprintf(pf,"%s ║",strnblk(ac,3,ls->tfont,LINE4));
  226.               }
  227.             else {                      /* long areanames */
  228.               block_title(pf, 8, EMPTY, ac, ls);
  229.               sep_line(pf, '─', 79, 0);
  230.               fprintf(pf," %-.78s\n", fx->parea->adesc);
  231.               fprintf(pf," Available: %lu files (%lu %cB)\n",
  232.                        fx->parea->file_count,
  233.                        (akb < 9999) ? akb : (akb + 512)/1024,
  234.                        (akb < 9999) ? 'K' : 'M');
  235.               if (ls->exclflag != EXCLPRIV) {
  236.                 fprintf(pf," Privilege: %-.9s",
  237.                           priv_name[fx->parea->priv-TWIT]); /* area priv */
  238.                 lock = fx->parea->filelock;       /* get lock */
  239.                 if (lock!=0) {
  240.                   fprintf(pf,"/");      /* locks follow */
  241.                   for (k=0; k<32; k++) {
  242.                     if (lock & 0x00000001)
  243.                       fprintf(pf,"%c",(k<8)?('1'+k):('A'+k-8));
  244.                     lock >>= 1;
  245.                     }
  246.                   }
  247.                 fprintf(pf, "\n");
  248.                 }
  249.               }
  250.             if (fx->parea->newest != NULL  &&    /* newest file */
  251.                 fx->parea->newest->wd.idate != 0) {  /* true date */
  252.               fprintf(pf," Newest: %s %8s ",
  253.                           fx->parea->newest->fname,
  254.                           f_date(fx->parea->newest->wd.date));
  255.               fprintf(pf," (avail: %8s)",
  256.                           f_date(fx->parea->newest->cd.date));
  257.               }
  258.             fprintf(pf, "\n");
  259.             sep_line(pf, '─', 79, 0);
  260.             fprintf(pf,"%s      %s   %s    %s\n",FN,SZ,DT,DS);
  261.             sep_line(pf, '─', 12, 5, 9, 50, 0);
  262.             }
  263.           }
  264.         if (fx->parea->file_count > 0) { /* any listable files in area */
  265.           if (fx->fname[0] != '\0') {   /* filename present */
  266.             ++j;                        /* count only file entries */
  267.             if (oper_mode==VERBOSE && (j%25)==0) {
  268.               fprintf(stdout, "%6lu\r", j);  /* keep SYSOP awake */
  269.               fflush(stdout);
  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 if (ls->sortflag == KEEPSEQ) {  /* '/K' specified */
  277.             fprintf(pf, "%-s\n",
  278.               (strip_ava == 'Y') ? strava(fx->fdesc) : fx->fdesc);
  279.             }
  280.           }
  281.         }
  282.       }
  283.     if (oper_mode==VERBOSE)             /* last value */
  284.       fprintf(stdout, "%6lu\n", j);
  285.                                         /* Area Summary report */
  286. #ifndef __32BIT__
  287.     area2 = (DOWNPATH huge *)halloc(area_total_count, sizeof(DOWNPATH));
  288. #else
  289.     area2 = (DOWNPATH *)malloc(area_total_count * sizeof(DOWNPATH));
  290. #endif
  291.                                         /* dup area-array for sorting! */
  292.     if (area2 == NULL) {                /* memory not obtained? */
  293.       if (oper_mode!=QUIET)
  294.         fprintf(stderr, "Not enough memory for summary report, skipped.\n");
  295.       }
  296.     else {
  297.       for (j=0; j<area_total_count; j++)
  298.         memmove(&area2[j],&area[j],sizeof(DOWNPATH));
  299.       qsort(area2, area_total_count, sizeof(DOWNPATH), sort_summ);
  300.       if (oper_mode==VERBOSE)
  301.         fprintf(stdout, MSG_REP, SUMM);
  302.       fprintf(pf,"\n\n");
  303.       sep_line(pf, '═', 79, 0);
  304.       block_title(pf, 12, EMPTY, SUMM, ls);
  305.       sep_line(pf, '═', 79, 0);
  306.       fprintf(pf,"%-8s %-54s %5s %8s\n",AC,DS,FS,BY);
  307.       sep_line(pf, '─', 8, 54, 5, 9, 0);
  308.       for (j=0; j<area_total_count; j++)
  309.         if (area2[j].file_count) {
  310.           fprintf(pf,"%-8.8s %-54.54s %5lu %8luK\n",
  311.                      area2[j].name,
  312.                      area2[j].adesc,
  313.                      area2[j].file_count,
  314.                      (area2[j].byte_count+512)/1024);
  315.           }
  316.       sep_line(pf, '─', 63, 5, 9, 0);
  317.       fprintf(pf,"%63s %5lu %8luK\n","Total:",
  318.                  count_files(area2),
  319.                  (count_bytes(area2)+512)/1024);
  320. #ifndef __32BIT__
  321.       hfree(area2);                     /* free copy of area array */
  322. #else
  323.       free(area2);                      /* free copy of area array */
  324. #endif
  325.       }
  326.  
  327.     signature(pf,today);                /* leave fingerprint */
  328.     insert_title(pf, bot_title, 0);
  329.     fclose(pf);                         /* finished with .ALL file */
  330.     }
  331.   else
  332.     fprintf(stderr, MSG_OPO, outfile, 0);      /* open failed */
  333.   }
  334.  
  335.