home *** CD-ROM | disk | FTP | other *** search
- /* ================================================================ */
- /* Rob Hamerling's MAXIMUS download file scan and sort utility */
- /* -> DOWNRPT4.C */
- /* -> Make GBL-list, ALL-list. */
- /* ================================================================ */
-
- #define INCL_BASE
- #include <os2.h>
-
- #include <conio.h>
- #include <malloc.h>
- #include <memory.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "..\max\mstruct.h"
- #include "downsort.h"
- #include "downfpro.h"
-
- /* prototypes of local functions */
- /* ------------------------------------------- */
- /* Produce the file-request format of GBL-list */
- /* ------------------------------------------- */
- void make_gbl(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x) // report privilege index
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- unsigned int i,j,fc; // counters
- struct _filechain *cn; // pointer to file-info
-
- sprintf(outfile,"%s.%s%c",
- lp[P_GBL].name,
- lp[P_GBL].ext,
- priv_name[lp[P_GBL].priv[x]-TWIT][0]);
- pf = fopen(outfile,WRITE); // output file
- if (pf == NULL)
- printf(OPEN_FAIL, outfile, 0); // no GBL list!
- else {
- if (oper_mode == VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,outfile);
- switch(lp[P_GBL].sortflag) {
- case ALPHA: psort(dm,0,file_total_count-1,sort_gbl); break;
- case TIMESTAMP: psort(dm,0,file_total_count-1,sort_new); break;
- default: break;
- }
- fc = preproc_area(area, dm, lp[P_GBL].priv[x]);
- cn = NULL; // no assigned
- for (i=0; i<file_total_count; ++i) // stop at end of files
- if (dm[i]->priv <= lp[P_GBL].priv[x]) // check file-privilege
- cn = new_acq(dm[i],cn); // keep pointer to most recent
- if (oper_mode != QUIET)
- printf(MSG_REP, outfile);
- if (oper_mode==VERBOSE)
- printf(MSG_REC);
- insert_title(pf, pre_title, 0);
- block_title(pf, 20, list_title, P_GBL);
- file_incl(pf,P_GBL); // insert user-'logo'
- insert_title(pf, sub_title, 0);
- fprintf(pf,"\n(%s) Available: %u files (%lu MB)",
- sys_date(today),
- fc,
- (count_bytes(area)/1024+512)/1024);
- if (lp[P_GBL].exclflag != EXCLPRIV)
- fprintf(pf,"\n%19s%s%s",
- "", MP, priv_name[lp[P_GBL].priv[x]-TWIT]);
- if (cn != NULL) {
- fprintf(pf,"\n%19sNewest: %s %8s",
- "",cn->fname,f_date(cn->wdate));
- fprintf(pf," (avail: %8s)",f_date(cn->cdate));
- }
- fprintf(pf,"\n%19s%s %c%s, %c%s",
- "", DF, DAYS_7, WK, DAYS_30, MO);
- fprintf(pf,"\n\n%s %s %s %s %s\n",FN,AC,SZ,DT,DS);
- sep_line(pf, '─', 12, 4, 5, 9, 45, 0);
- for (i=j=0; i<file_total_count; i++) {
- if (dm[i]->priv <= lp[P_GBL].priv[x]) { // within priv limit
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- if (dm[i]->fname[0] != '\0') { // not a comment-entry
- j++;
- fprintf(pf,"%-12.12s %4.4s %15s ",
- dm[i]->fname,
- dm[i]->parea->name,
- f_size_date(dm[i]->size, dm[i]->wdate,
- dm[i]->cdate, dm[i]->ctime));
- desc_part(pf, dm[i]->fdesc, 45, 45, P_GBL); /* file description */
- }
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- signature(pf,today); // leave fingerprint
- insert_title(pf, bot_lines, 0);
- fclose(pf); // finished with .GBL file
- }
- }
-
- /* ------------------------------------------------------- */
- /* Produce the file-request format of ALLfiles (ALL-list) */
- /* ------------------------------------------------------- */
- void make_all(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x)
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- char ac[40]; // area name
- unsigned int i,j,n,fc; // counters
- struct _downpath huge *area2; // copy of area-array for sort
-
- sprintf(outfile,"%s.%s%c",
- lp[P_ALL].name,
- lp[P_ALL].ext,
- priv_name[lp[P_ALL].priv[x]-TWIT][0]);
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) {
- if (oper_mode == VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,outfile);
- switch(lp[P_ALL].sortflag) {
- case ALPHA: psort(dm,0,file_total_count-1,sort_all); break;
- case TIMESTAMP: psort(dm,0,file_total_count-1,sort_al2); break;
- case KEEPSEQ: psort(dm,0,file_total_count-1,sort_akp); break;
- default: break;
- }
-
- fc = preproc_area(area, dm, lp[P_ALL].priv[x]);
- if (oper_mode!=QUIET)
- printf(MSG_REP, outfile);
- if (oper_mode==VERBOSE)
- printf(MSG_REC);
- insert_title(pf, pre_title, 0);
- block_title(pf, 20, list_title, P_ALL);
- file_incl(pf, P_ALL); // insert user-'logo'
- insert_title(pf, sub_title, 0);
- fprintf(pf,"\n(%s) Available: %u files in %u areas (%lu MB)\n",
- sys_date(today),
- fc,
- count_areas(area, lp[P_ALL].priv[x]),
- (count_bytes(area)/1024+512)/1024);
- if (lp[P_ALL].exclflag != EXCLPRIV)
- fprintf(pf,"%19s%s%s\n",
- "",MP,priv_name[lp[P_ALL].priv[x]-TWIT]);
- fprintf(pf,"%19s%s %c%s, %c%s\n",
- "", DF, DAYS_7, WK, DAYS_30, MO);
- ac[0] = '\0'; // null area name
- n=0; // file counter for SYSOP
- for (i=0; i<file_total_count; i++) { // all files
- if (strcmp(ac,dm[i]->parea->name)) { // new area collection
- strcpy(ac,dm[i]->parea->name); // set new
- if (dm[i]->parea->file_count > 0) { // any listable files in area
- fprintf(pf,"\n\n");
- sep_line(pf, '═', 79, 0);
- if (max_aname <= 3) { /* short areanames */
- fprintf(pf,"%s ║ %-.60s\n",
- strnblk(ac,3,FONT3,LINE1),dm[i]->parea->adesc);
- fprintf(pf,"%s ║ Available: %u files (%lu.%lu MB)\n",
- strnblk(ac,3,FONT3,LINE2),
- dm[i]->parea->file_count,
- (dm[i]->parea->byte_count+52428L)/1048576L, // mod 100K
- ((dm[i]->parea->byte_count+52429L)/104857L)%10); // frac
- fprintf(pf,"%s ║",
- strnblk(ac,3,FONT3,LINE3));
- if (lp[P_ALL].exclflag != EXCLPRIV)
- fprintf(pf," Privilege: %-.9s\n",
- priv_name[dm[i]->parea->priv-TWIT]); // area privilege
- else
- fprintf(pf,"\n");
- fprintf(pf,"%s ║",strnblk(ac,3,FONT3,LINE4));
- }
- else { /* long areanames */
- fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE1));
- fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE2));
- fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE3));
- fprintf(pf,"%s\n", strnblk(ac,8,FONT3,LINE4));
- sep_line(pf, '─', 79, 0);
- fprintf(pf," %-.78s\n", dm[i]->parea->adesc);
- fprintf(pf," Available: %u files (%lu.%lu MB)\n",
- dm[i]->parea->file_count,
- (dm[i]->parea->byte_count+52428L)/1048576L, // mod 100K
- ((dm[i]->parea->byte_count+52429L)/104857L)%10); // frac
- if (lp[P_ALL].exclflag != EXCLPRIV)
- fprintf(pf," Privilege: %-.9s\n",
- priv_name[dm[i]->parea->priv-TWIT]); // area priv
- }
- if (dm[i]->parea->newest != NULL) { // newest file
- fprintf(pf," Newest: %s %8s ",
- dm[i]->parea->newest->fname,
- f_date(dm[i]->parea->newest->wdate));
- fprintf(pf," (avail: %8s)",
- f_date(dm[i]->parea->newest->cdate));
- }
- fprintf(pf, "\n");
- sep_line(pf, '─', 79, 0);
- fprintf(pf,"%s %s %s %s\n",FN,SZ,DT,DS);
- sep_line(pf, '─', 12, 5, 9, 50, 0);
- }
- }
- if (dm[i]->priv <= lp[P_ALL].priv[x]) { // only upto max priv_level
- if (oper_mode==VERBOSE && (n%25)==0)
- cprintf("\r %5u",n); // keep SYSOP awake
- if (dm[i]->fname[0] != '\0') { // filename present
- ++n; // count only file entries
- fprintf(pf,"%-12.12s %15s ",
- dm[i]->fname,
- f_size_date(dm[i]->size, dm[i]->wdate,
- dm[i]->cdate, dm[i]->ctime));
- desc_part(pf, dm[i]->fdesc, 50, 50, P_ALL); /* file descr. */
- }
- else if (lp[P_ALL].sortflag == KEEPSEQ) { // '/K' specified
- fprintf(pf, "%-s\n",
- (strip_ava == 'Y') ? strava(dm[i]->fdesc) : dm[i]->fdesc);
- }
- }
- }
- if (oper_mode==VERBOSE) // last value
- printf("\r %5u",n);
- // Area Summary report
- #ifndef __32BIT__
- area2 = (struct _downpath huge *)halloc(area_total_count,
- sizeof(struct _downpath));
- #else
- area2 = (struct _downpath *)malloc(area_total_count *
- sizeof(struct _downpath));
- #endif
- // dup area-array for sorting!
- if (area2 == NULL) { // memory not obtained?
- if (oper_mode!=QUIET)
- printf("\nNot enough memory for summary report, skipped.");
- }
- else {
- memmove(area2,area,area_total_count*sizeof(struct _downpath));
- qsort(area2,area_total_count,sizeof(struct _downpath),sort_summ);
- if (oper_mode==VERBOSE)
- printf(MSG_REP, SUMM);
- fprintf(pf,"\n\n");
- sep_line(pf, '═', 79, 0);
- block_title(pf, 12, SUMM, P_ALL);
- sep_line(pf, '═', 79, 0);
- fprintf(pf,"%-8s %-54s %5s %8s\n",AC,DS,FS,BY);
- sep_line(pf, '─', 8, 54, 5, 9, 0);
- for (j=0; j<area_total_count; j++)
- if (area2[j].file_count) {
- fprintf(pf,"%-8.8s %-54.54s %5u %8luK\n",
- area2[j].name,
- area2[j].adesc,
- area2[j].file_count,
- (area2[j].byte_count+512)/1024);
- }
- sep_line(pf, '─', 63, 5, 9, 0);
- fprintf(pf,"%63s %5u %8luK\n","Total:",
- count_files(area2),
- (count_bytes(area2)+512)/1024);
- #ifndef __32BIT__
- hfree(area2); // free copy of area array
- #else
- free(area2); // free copy of area array
- #endif
- }
-
- signature(pf,today); // leave fingerprint
- insert_title(pf, bot_lines, 0);
- fclose(pf); // finished with .ALL file
- }
- else
- printf(OPEN_FAIL, outfile, 0); // open failed
- }
-
-