home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
os2
/
dwnsrs57.zip
/
DOWNRPT2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-18
|
22KB
|
510 lines
/* ================================================================ */
/* Rob Hamerling's MAXIMUS download file scan and sort utility */
/* -> DOWNRPT2.C */
/* -> Make all types of IPF-lists. */
/* ================================================================ */
#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"
/* IPF-tags */
static char AW[] = ":artwork align=center name='DOWNSORT.BMP'.";
static char CD[] = ":color fc=default.";
static char CG[] = ":cgraphic.";
static char CR[] = ":color fc=red.";
static char CY[] = ":color fc=yellow.";
static char DP[] = ":docprof toc='*3'.";
static char ED[] = ":euserdoc.\n";
static char EG[] = ":ecgraphic.";
static char EL[] = ":elines.\n";
static char ET[] = ":etable.\n";
static char H1[] = ":h1.";
static char H2[] = ":h2";
static char H3[] = ":h3";
static char OV[] = "Overview";
static char LI[] = ":lines align=center.";
static char LL[] = ":lines align=left.";
static char LP[] = ":lp.";
static char TB[] = ":table cols='12 15 38' frame=box rules=both.\n";
static char TI[] = ":title.";
static char UD[] = ":userdoc.";
/* prototypes of local functions */
void ipf_list_head(FILE *, struct _filechain **,
struct _downpath huge *, unsigned int, unsigned int);
void ipf_area_oview(FILE *,
struct _downpath huge *, unsigned int, unsigned int);
void ipf_area_head(FILE *, struct _filechain **,
unsigned int, unsigned int);
int ipf_file_entry(FILE *, struct _filechain **,
unsigned int, unsigned int);
int ip2_file_entry(FILE *, struct _filechain **,
unsigned int, unsigned int);
/* ------------------------------------------------------- */
/* Produce the file-request format of IPFfiles (IPF-list) */
/* ------------------------------------------------------- */
void make_ipf(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,l,pcnt,n,pmax; /* counters */
sprintf(outfile,"%s.%s%c",
lp[P_IPF].name,
lp[P_IPF].ext,
priv_name[lp[P_IPF].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);
ipf_list_head(pf, dm, area, P_IPF, x); /* sort + list header */
if (oper_mode!=QUIET)
fprintf(stdout, MSG_REP, outfile);
ipf_area_oview(pf, area, P_IPF, x); /* create area overview */
if (oper_mode==VERBOSE) /* keep operator awake */
fprintf(stdout, MSG_REC, outfile);
fprintf(pf,"%s%s\n",H1,"File List per Area");
fprintf(pf,"%s\n%s :hp8.%c:ehp8.%s, :hp8.%c:ehp8.%s\n%s\n",
LI, DF, DAYS_7, WK, DAYS_30, MO, EL);
ac[0] = '\0'; /* null area name */
l=n=0; /* init file counters */
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 files in this area */
if (l>0) /* have to close open list? */
fprintf(pf,":edl.\n"); /* close previous area-list */
ipf_area_head(pf, dm, P_IPF, i); /* create area header */
pcnt = l = 0; /* sub-counters this area */
}
}
if (dm[i]->priv <= lp[P_IPF].priv[x]) { /* only upto max priv_lvl*/
pmax = 1 + dm[i]->parea->file_count/lp[P_IPF].max_fil;
if ((l % lp[P_IPF].max_fil) == 0) { /* 'page' separations */
if (l == 0) { /* only for first entry */
if (dm[i]->parea->file_count > lp[P_IPF].max_fil) /* split */
fprintf(pf,":p.(part %d of %d)\n", ++pcnt, pmax);
}
else { /* only part 2 and up */
fprintf(pf,":edl.\n"); /* end of previous part */
++pcnt; /* increment part counter */
fprintf(pf,":p.Jump to: :link reftype=hd refid=%.8sP%d.\n"
"part %d of %d:elink.",
dm[i]->parea->name, pcnt, pcnt, pmax);
fprintf(pf,"\n%s id=%.8sP%d.%s - (part %d of %d)\n",
H3, dm[i]->parea->name, pcnt, ac, pcnt, pmax);
fprintf(pf,":p.%s (part %d of %d)\n",
stripf(dm[i]->parea->adesc), pcnt, pmax);
}
fprintf(pf,":dl tsize=20 compact.\n");
fprintf(pf,":hp6.:dthd.%s:ddhd.%s:ehp6.\n",FN,DS);
}
++l; /* listed lines (incl comments) */
n += ipf_file_entry(pf, dm, P_IPF, i); /* print entry */
if (dm[i]->fname[0] != '\0') /* filename present */
if (oper_mode==VERBOSE && (n%25)==0)
fprintf(stdout, " %5u\r",n); /* report progress */
}
}
fprintf(pf,":edl.\n"); /* end of file-list last area */
if (oper_mode==VERBOSE) /* last value */
fprintf(stdout," %5u\n", n);
fprintf(pf,"%s%s\n%s\n\n",H1,"Epilog",LI);
signature(pf,stripf(today)); /* leave fingerprint */
insert_title(pf, bot_lines, 1);
fprintf(pf, "%s%s", EL, ED);
stripf(NULL); /* let stripf free memory */
fclose(pf); /* finished with .IPF file */
}
else {
if (oper_mode!=QUIET)
fprintf(stderr, MSG_OPO, outfile, 0); /* open failed */
}
}
/* ------------------------------------------------------- */
/* Produce the file-request format of IP2-files (IPF-list) */
/* ------------------------------------------------------- */
void make_ip2(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,l,pcnt,n,pmax; /* counters */
sprintf(outfile,"%s.%s%c",
lp[P_IP2].name,
lp[P_IP2].ext,
priv_name[lp[P_IP2].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);
ipf_list_head(pf, dm, area, P_IP2, x); /* sort + list header */
if (oper_mode!=QUIET)
fprintf(stdout, MSG_REP, outfile);
ipf_area_oview(pf, area, P_IP2, x); /* create area overview */
if (oper_mode==VERBOSE) /* keep operator awake */
fprintf(stdout, MSG_REC, outfile);
fprintf(pf,"%s%s\n",H1,"File List per Area");
fprintf(pf,"%s\n%s :hp8.%c:ehp8.%s, :hp8.%c:ehp8.%s\n%s\n",
LI, DF, DAYS_7, WK, DAYS_30, MO, EL);
ac[0] = '\0'; /* null area name */
l = n = 0; /* init file counters */
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 files in this area */
if (l>0) /* have to close open list? */
fprintf(pf,ET); /* close previous table */
ipf_area_head(pf, dm, P_IP2, i); /* create area header */
pcnt = l = 0; /* init sub-counters this area */
}
}
if (dm[i]->priv <= lp[P_IP2].priv[x]) { /* only upto max priv_lvl*/
pmax = 1 + dm[i]->parea->file_count/lp[P_IP2].max_fil;
if ((l % lp[P_IP2].max_fil) == 0) { /* 'page' separations */
if (l == 0) { /* only for first entry */
if (dm[i]->parea->file_count > lp[P_IP2].max_fil) /* split */
fprintf(pf,":p.(part %d of %d)\n", ++pcnt, pmax);
}
else { /* only part 2 and up */
fprintf(pf,ET); /* end of previous table */
++pcnt; /* increment part counter */
fprintf(pf,":p.Jump to: :link reftype=hd refid=%.8sP%d.\n"
"part %d of %d:elink.",
dm[i]->parea->name, pcnt, pcnt, pmax);
fprintf(pf,"\n%s id=%.8sP%d.%s - (part %d of %d)\n",
H3, dm[i]->parea->name, pcnt, ac, pcnt, pmax);
fprintf(pf,":p.%s (part %d of %d)\n",
stripf(dm[i]->parea->adesc), pcnt, pmax);
}
/* fprintf(pf,":font facename=Helv size=10x8.\n"); */
fprintf(pf,TB);
}
++l; /* listed lines (incl comments) */
n += ip2_file_entry(pf, dm, P_IP2, i); /* print entry */
if (dm[i]->fname[0] != '\0') /* filename present */
if (oper_mode==VERBOSE && (n%25)==0)
fprintf(stdout, " %5u\r",n); /* report progress */
}
}
fprintf(pf,ET); /* end of table this area */
if (oper_mode==VERBOSE) /* last value */
fprintf(stdout, " %5u\n", n);
fprintf(pf,"%s%s\n%s\n\n",H1,"Epilog",LI);
signature(pf,stripf(today)); /* leave fingerprint */
insert_title(pf, bot_lines, 1);
fprintf(pf,"%s%s",EL,ED);
stripf(NULL); /* let stripf free memory */
fclose(pf); /* finished with .IPF file */
}
else {
if (oper_mode!=QUIET)
fprintf(stdout, MSG_OPO, outfile, 0); /* open failed */
}
}
/* ------------------------ */
/* generate IPF list header */
/* ------------------------ */
void ipf_list_head(FILE *pf,
FILECHAIN **dm,
DOWNPATH huge *area,
unsigned int P_ppp,
unsigned int x)
{
char s[MAXDESC]; /* work buffer */
switch(lp[P_ppp].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;
}
preproc_area(area, dm, lp[P_ppp].priv[x]);
fprintf(pf,"%s\n%s%s\n%s\n",UD,TI,stripf(list_title),DP);
fprintf(pf,"%s%s\n%s\n",H1,stripf(list_title),LI);
insert_title(pf, pre_title, 1);
fprintf(pf,"%s%s\n%s\n",EL,CG,CR);
block_title(pf, 20, list_title, P_ppp),
fprintf(pf,"%s\n%s\n",CD,EG);
file_incl(pf, P_ppp); /* insert user-'logo' */
fprintf(pf,"%s\n",LI);
insert_title(pf, sub_title, 1);
fprintf(pf,"%s%s%s%s%s\n",EL,H1,"About ",PROGNAME," program");
fprintf(pf,"\n%s\n",AW);
fprintf(pf,"\n%s\n%s Version %c.%c%c\n",
LI,PROGNAME,VERSION,SUBVERS,SUFFIX);
fprintf(pf,"\nby %s\n\n%s\n",AUTHOR, CITY);
sprintf(s,"\n%s\n%s\n",PHONE,FIDO);
fprintf(pf,"%s\n",stripf(s));
fprintf(pf,"%s",EL);
}
/* ------------------------------- */
/* generate IPF list area overview */
/* ------------------------------- */
void ipf_area_oview(FILE *pf,
struct _downpath huge *area,
unsigned int P_ppp,
unsigned int x)
{
char s[MAXDESC]; /* pointer to line buffer */
unsigned int j; /* counter */
DOWNPATH huge *area2; /* copy of area-array for sort */
if (oper_mode==VERBOSE)
fprintf(stdout, MSG_REP, OV);
#ifndef __32BIT__
area2 = (DOWNPATH *)halloc(area_total_count,
sizeof(DOWNPATH));
#else
area2 = (DOWNPATH *)malloc(area_total_count *
sizeof(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(DOWNPATH));
qsort(area2,area_total_count,sizeof(DOWNPATH),sort_summ);
fprintf(pf,"%s%s\n",H1,OV);
fprintf(pf,"%s\n%s\n",CG,CR);
block_title(pf, 8, OV, P_ppp);
fprintf(pf,"%s\n%s\n",CD,EG);
fprintf(pf,"%s\nlist creation date: %s\n",
LI,stripf(sys_date(today)));
if (lp[P_ppp].exclflag != EXCLPRIV)
fprintf(pf,"%s%s\n", MP, priv_name[lp[P_ppp].priv[x]-TWIT]);
fprintf(pf,"%s%s\n:hp2.\n%-8s %-35s %5s %8s\n",EL,CG,AC,DS,FS,BY);
sep_line(pf, '─', 44, 5, 9, 0);
for (j=0; j<area_total_count; j++) {
if (area2[j].file_count) {
fprintf(pf,":link reftype=hd refid=A$%.8s.%-8.8s:elink.",
area2[j].name,
area2[j].name);
sprintf(s," %-35.35s %5u %8luK",
area2[j].adesc,
area2[j].file_count,
(area2[j].byte_count+512)/1024);
fprintf(pf,"%s\n",stripf(s));
}
}
sep_line(pf, '─', 44, 5, 9, 0);
fprintf(pf,"%44s %5u %8luK\n:ehp2.\n%s\n",
"Total:",
count_files(area2),
(count_bytes(area2)+512)/1024,
EG);
#ifndef __32BIT__
hfree(area2); /* free copy of area array */
#else
free(area2); /* free copy of area array */
#endif
}
}
/* ------------------------- */
/* generate IPF area heading */
/* ------------------------- */
void ipf_area_head(FILE *pf,
struct _filechain **dm,
unsigned int P_ppp,
unsigned int i)
{
fprintf(pf,":p.Continue with filearea"
":link reftype=hd refid=A$%.8s. %s :elink.&colon. ",
dm[i]->parea->name,
dm[i]->parea->name);
fprintf(pf,"%-45.45s\n", stripf(dm[i]->parea->adesc));
fprintf(pf,"%s id=A$%.8s.%s - %s\n%s\n",
H2,
dm[i]->parea->name,
dm[i]->parea->name,
stripf(dm[i]->parea->adesc),CG);
if (max_aname <= 3) { /* short areanames */
fprintf(pf,"%s%s%s ║ :hp2.%s:ehp2.\n",
CR,
strnblk(dm[i]->parea->name,3,FONT3,LINE1),
CD,
stripf(dm[i]->parea->adesc));
fprintf(pf,"%s%s%s ║ :hp2.Available: "
"%u files (%lu.%lu MB):ehp2.\n",
CR, strnblk(dm[i]->parea->name,3,FONT3,LINE2), CD,
dm[i]->parea->file_count,
(dm[i]->parea->byte_count+52428L)/1048576L, /* round */
((dm[i]->parea->byte_count+52429L)/104857L)%10); /* fract */
fprintf(pf,"%s%s%s ║",CR,strnblk(dm[i]->parea->name,3,FONT3,LINE3),CD);
if (lp[P_ppp].exclflag != EXCLPRIV)
fprintf(pf," :hp2.Privilege: %-.9s:ehp2.\n",
priv_name[dm[i]->parea->priv-TWIT]); /* area priv */
else
fprintf(pf,"\n");
fprintf(pf,"%s%s%s ║",CR,strnblk(dm[i]->parea->name,3,FONT3,LINE4),CD);
}
else { /* long areanames */
fprintf(pf,"%s\n", CR);
fprintf(pf,"%s\n", strnblk(dm[i]->parea->name,8,FONT3,LINE1));
fprintf(pf,"%s\n", strnblk(dm[i]->parea->name,8,FONT3,LINE2));
fprintf(pf,"%s\n", strnblk(dm[i]->parea->name,8,FONT3,LINE3));
fprintf(pf,"%s\n", strnblk(dm[i]->parea->name,8,FONT3,LINE4));
fprintf(pf,"%s\n\n", CD);
fprintf(pf," :hp2.%s:ehp2.\n", stripf(dm[i]->parea->adesc));
fprintf(pf," :hp2.Available: %u files (%lu.%lu MB):ehp2.\n",
dm[i]->parea->file_count,
(dm[i]->parea->byte_count+52428L)/1048576L, /* MB */
((dm[i]->parea->byte_count+52429L)/104857L)%10); /* fract */
if (lp[P_ppp].exclflag != EXCLPRIV)
fprintf(pf," :hp2.Privilege: %-.9s:ehp2.\n",
priv_name[dm[i]->parea->priv-TWIT]); /* area priv */
}
if (dm[i]->parea->newest != NULL) { /* newest file */
fprintf(pf," :hp2.Newest:");
fprintf(pf," %s",stripf(dm[i]->parea->newest->fname));
fprintf(pf," %s",stripf(f_date(dm[i]->parea->newest->wdate)));
fprintf(pf," (avail: %s):ehp2.\n",
stripf(f_date(dm[i]->parea->newest->cdate)));
}
fprintf(pf,"%s\n",EG);
}
/* ----------------------- */
/* generate IPF file entry */
/* ----------------------- */
int ipf_file_entry(FILE *pf,
struct _filechain **dm,
unsigned int P_ppp,
unsigned int i)
{
int rc;
unsigned int k;
char ageflag, *strptr;
rc = 0;
if (dm[i]->fname[0] != '\0') { /* filename present */
fprintf(pf,":dt.:link refid=F$%u reftype=fn.%-s:elink.",
i, stripf(dm[i]->fname)); /* filename */
ageflag = file_age_ind(dm[i]->cdate,dm[i]->ctime); /* file age flag */
if (ageflag!=' ')
fprintf(pf,":hp8.%c:ehp8.", ageflag);
fprintf(pf,"\n:dd.");
k = strsubw(dm[i]->fdesc,&strptr,240);
if (k>0)
fprintf(pf, (dm[i]->size) ? "%s\n" : ":hp1.%s:ehp1.\n",
stripf(strptr)); /* description */
fprintf(pf,":fn id=F$%u.%s:efn.\n",
i, /* file number */
f_size_date(dm[i]->size,
dm[i]->wdate,
dm[i]->cdate,
dm[i]->ctime));
rc = 1; /* file entry printed */
}
else if(lp[P_ppp].sortflag == KEEPSEQ) /* '/K' specified */
fprintf(pf,"%s%s%-s%s%s",
LL, CY,
(strip_ava == 'Y') ? strava(dm[i]->fdesc) : dm[i]->fdesc,
CD, EL);
return(rc); /* report result */
}
/* ----------------------- */
/* generate IPF file entry */
/* ----------------------- */
int ip2_file_entry(FILE *pf,
struct _filechain **dm,
unsigned int P_ppp,
unsigned int i)
{
int rc;
rc = 0;
if (dm[i]->fname[0] != '\0') { /* filename present */
fprintf(pf,":row.:c.%s:c.%s",
stripf(dm[i]->fname), /* filename */
f_size_date(dm[i]->size, dm[i]->wdate,
dm[i]->cdate, dm[i]->ctime));
fprintf(pf, (dm[i]->size) ? ":c.%s\n" : ":c.:hp1.%s:ehp1.\n",
stripf(dm[i]->fdesc)); /* description */
rc = 1; /* file entry printed */
}
else if(lp[P_ppp].sortflag == KEEPSEQ) /* '/K' specified */
fprintf(pf,"%s%s%-s%s%s",
LL, CY,
(strip_ava == 'Y') ? strava(dm[i]->fdesc) : dm[i]->fdesc,
CD, EL);
return(rc); /* report result */
}
/* ---------------------------------------------------- */
/* function to 'neutralise' IPFC conflicting characters */
/* ---------------------------------------------------- */
char *stripf(char *s)
{
int i,j,k;
static char colon[] = "&colon.";
static char amp[] = "&.";
static char grave[] = "&rbl."; /* translated to required BLANK */
static int maxline = MAXDESC; /* length of work-buffer */
static char *t = NULL; /* pointer to work-buffer */
if (s == NULL && t != NULL) { /* no input-string */
free(t); /* free-up memory */
t = NULL; /* for next time use */
return(s);
}
if (t == NULL) /* no memory yet */
t = malloc(maxline); /* get it now */
if (t != NULL) {
for (i=j=0; s[i] && j<maxline-10; ++i) { /* keep some slack */
switch(s[i]) {
case ':': for (k=0; colon[k]; )
t[j++] = colon[k++];
break;
case '`': for (k=0; grave[k]; )
t[j++] = grave[k++];
break;
case '&': for (k=0; amp[k]; )
t[j++] = amp[k++];
break;
default: t[j++] = s[i];
break;
}
}
t[j] = '\0'; /* end of string */
return(t); /* pointer to converted line */
}
else
return(s); /* no conversion done */
}