home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
os2
/
dwnsrs57.zip
/
DOWNRPT4.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-18
|
12KB
|
280 lines
/* ================================================================ */
/* Rob Hamerling's MAXIMUS download file scan and sort utility */
/* -> DOWNRPT4.C */
/* -> Make GBL-list, ALL-list. */
/* ================================================================ */
#define INCL_BASE
#define INCL_NOPMAPI
#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 */
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) {
if (oper_mode == VERBOSE)
fprintf(stdout, 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)
fprintf(stdout, MSG_REP, outfile);
if (oper_mode==VERBOSE)
fprintf(stdout, 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, 8, 5, 9, 41, 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) {
fprintf(stdout, " %5u\r",j);
fflush(stdout);
}
if (dm[i]->fname[0] != '\0') { /* not a comment-entry */
j++;
fprintf(pf,"%-12.12s %8.8s %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, 41, 41, P_GBL); /* file descript. */
}
}
}
if (oper_mode==VERBOSE) {
fprintf(stdout, " %5u\n",j);
fflush(stdout);
}
signature(pf,today); /* leave fingerprint */
insert_title(pf, bot_lines, 0);
fclose(pf); /* finished with .GBL file */
}
else
fprintf(stderr, MSG_OPO, outfile, 0); /* no GBL list! */
}
/* ------------------------------------------------------- */
/* 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)
fprintf(stdout, 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)
fprintf(stdout, MSG_REP, outfile);
if (oper_mode==VERBOSE)
fprintf(stdout, 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, /*100K*/
((dm[i]->parea->byte_count+52429L)/104857L)%10);
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 priv*/
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, /* 100K*/
((dm[i]->parea->byte_count+52429L)/104857L)%10);
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_lvl*/
if (oper_mode==VERBOSE && (n%25)==0) {
fprintf(stdout, " %5u\r",n); /* keep SYSOP awake */
fflush(stdout);
}
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 */
fprintf(stdout, " %5u\n",n);
fflush(stdout);
}
/* 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)
fprintf(stderr, "Not enough memory for summary report, skipped.\n");
}
else {
memmove(area2,area,area_total_count*sizeof(struct _downpath));
qsort(area2,area_total_count,sizeof(struct _downpath),sort_summ);
if (oper_mode==VERBOSE)
fprintf(stdout, 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
fprintf(stderr, MSG_OPO, outfile, 0); /* open failed */
}