home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
com
/
bbs
/
downsrt
/
source
/
downrpt2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-19
|
24KB
|
517 lines
/* ================================================================ */
/* Rob Hamerling's MAXIMUS download file scan and sort utility */
/* -> Functions for creating a ALL- and IPF-lists. */
/* ================================================================ */
// #define DEBUG_MODE
#define INCL_BASE
#include <os2.h>
#include <conio.h>
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "downsort.h"
char sum_title[] = " Summary ";
char oview_title[] = "Overview";
#define MAXLIST 250
/* ------------------------------------------------------- */
/* Produce the file-request format of ALLfiles (ALL-list) */
/* ------------------------------------------------------- */
void make_all(dm,area,r_priv)
struct _filechain **dm; // pointer to file-sort array
struct _downpath *area; // pointer to downpath array
int r_priv; // maximum report privilege
{
FILE *pf; // file handle
char outfile[MAXFN]; // file names
char ac[40]; // area name
char *strptr; // pointer to a string
USHORT i,j,k,n; // counters
ULONG ab_count; // byte count per area
struct _filechain *ca,*cb,*cn; // pointer to file-info
struct _downpath *area2; // copy of area-array for sort
sprintf(outfile,"%s.%s%c",
lp[P_ALL].name,lp[P_ALL].ext,priv_name[r_priv-TWIT][0]);
pf = fopen(outfile,"w"); // output file
if (pf != NULL) {
if (oper_mode!=QUIET)
printf(MSG_SRT,file_count,area_count,outfile);
if (lp[P_ALL].sortflag == ALPHA)
psort(dm,0,file_count-1,sort_all);
else if (lp[P_ALL].sortflag == TIMESTAMP)
psort(dm,0,file_count-1,sort_al2);
else if (lp[P_ALL].sortflag == KEEPSEQ)
psort(dm,0,file_count-1,sort_akp);
if (oper_mode==VERBOSE)
printf(MSG_REC,outfile);
for (i=0; i<MAXTIT && pre_title[i]!=NULL; ++i)
fprintf(pf,"%s\n",pre_title[i]);
for (i=0; i<title_lines[lp[P_ALL].tfont]; ++i) // whole title
fprintf(pf,"%s\n",strnblk(list_title,20,lp[P_ALL].tfont,i));
if (lp[P_ALL].incl_fspec != NULL)
file_incl(pf,lp[P_ALL].incl_fspec); // insert user-'logo'
for (i=0; i<MAXTIT && sub_title[i]!=NULL; ++i)
fprintf(pf,"%s\n",sub_title[i]);
ac[0] = '\0'; // null area name
for (i=0; i<file_count; i++) { // all files
ca = dm[i]; // pointer to fileinfo
if (strcmp(ac,ca->parea->name)) { // new area collection
strcpy(ac,ca->parea->name); // set new
ab_count = 0L; // init area byte count
cb = ca; // copy pointer first file
j=k=0; // zero index and counter
while (!strcmp(ac,cb->parea->name) && // stop at end of area
i+j<file_count) { // or at end of files
if (cb->priv <= r_priv) { // check file-privilege
k++; // presentable file count
ab_count += cb->size; // effective area byte count
} // endif
++j; // next file-entry
if (i+j<file_count) // stop at end of files
cb = dm[i+j]; // ptr to next file
} // endfor
ca->parea->file_count = k; // store for summary
ca->parea->byte_count = ab_count; // store for summary
}
}
fprintf(pf,"\n(%s) Available: %u files in %u areas (%lu MB)",
sys_date(today),
count_files(dm, r_priv),
count_areas(area, r_priv),
(count_bytes(dm, r_priv)/1024+512)/1024);
if (lp[P_ALL].exclflag != EXCLPRIV)
fprintf(pf,"\n%19sMaximum privilege shown: %s",
"",priv_name[r_priv-TWIT]);
fprintf(pf,"\n%19sDate flag: new on this system since:"
" %c = week, %c = month.","",DAYS_7,DAYS_30);
ac[0] = '\0'; // null area name
n=0; // file counter for SYSOP
for (i=0; i<file_count; i++) { // all files
ca = dm[i]; // pointer to fileinfo
if (strcmp(ac,ca->parea->name)) { // new area collection
strcpy(ac,ca->parea->name); // set new
cb = ca; // copy pointer first file
cn = NULL; // not assigned
j=k=0; // zero index and count
while (!strcmp(ac,cb->parea->name) && // stop at end of area
i+j < file_count) { // or at end of files
if (cb->priv <= r_priv) // check file-privilege
cn = new_acq(cb,cn); // keep pointer to most recent
++j; // next file-entry
if (i+j<file_count) // stop at end of files
cb = dm[i+j]; // ptr to next file
} // endfor
if (ca->parea->file_count > 0) { // any listable files in area
fprintf(pf,"\n\n\n%-.39s%-.40s",HD,HD);
fprintf(pf,"\n%s ║ %-.60s",
strnblk(ac,2,FONT3,LINE1),ca->parea->adesc);
fprintf(pf,"\n%s ║ Available: %u files (%lu.%lu MB)",
strnblk(ac,2,FONT3,LINE2),
ca->parea->file_count,
(ca->parea->byte_count+52428L)/1048576L, // mod 100K
((ca->parea->byte_count+52429L)/104857L)%10); // frac
fprintf(pf,"\n%s ║",
strnblk(ac,2,FONT3,LINE3));
if (lp[P_ALL].exclflag != EXCLPRIV)
fprintf(pf," Privilege: %-.9s",
priv_name[ca->parea->priv-TWIT]); // area privilege
fprintf(pf,"\n%s ║ ",strnblk(ac,2,FONT3,LINE4));
if (cn != NULL) { // newest file
fprintf(pf,"Newest: %s %8s ", cn->fname, f_date(cn->wdate));
fprintf(pf," (avail: %8s)", f_date(cn->cdate));
}
fprintf(pf,"\n%-.39s%-.40s",HS,HS);
fprintf(pf,"\n%s %s %s %s",FN,SZ,DT,DS);
fprintf(pf,"\n%-.12s %-.5s %-.8s %-.25s%-.25s",HS,HS,HS,HS,HS);
} // endif
} // endif
if (ca->priv <= r_priv) { // only upto max priv_level
if (oper_mode==VERBOSE && (n%25)==0)
cprintf("\r %5u",n); // keep SYSOP awake
++n;
k = strsubw(ca->fdesc,&strptr,50);
if (k>0 && lp[P_ALL].wrapflag == TRUNC) // default: wrap
k = 50;
fprintf(pf,"\n%-12.12s %4ldK %s%c %-.*s",
ca->fname,
(ca->size+1023)/1024, // round-up for list only
f_date(ca->wdate),
file_age_ind(ca->cdate,ca->ctime), // file age indicator
k,(k>0)?strptr:""); // (part of) description
if (lp[P_ALL].wrapflag != TRUNC)
while (k>0) {
k = strsubw(strptr+k,&strptr,50);
if (k>0)
fprintf(pf,"\n%-29.29s%-.*s","",k,strptr); // remainder
} // endwhile
} // endif
} // endfor
if (oper_mode==VERBOSE) // last value
printf("\r %5u",n);
// Area Summary report
area2 = (struct _downpath *)calloc(area_count,sizeof(struct _downpath));
// dup area-array for sorting!
if (area2 == NULL) { // memory not obtained?
if (oper_mode!=QUIET)
printf("\nNot enough memory for summary report, skipped.");
}
else {
memcpy(area2,area,area_count*sizeof(struct _downpath)); // copy array
qsort(area2,area_count,sizeof(struct _downpath),sort_summ);
if (oper_mode==VERBOSE)
printf("\nWriting Area-Summary");
fprintf(pf,"\n\n\n%-.39s%-.40s\n",HD,HD);
for (i=0; i<title_lines[lp[P_ALL].tfont]; ++i)
fprintf(pf," %s\n",strnblk(sum_title,12,lp[P_ALL].tfont,i));
fprintf(pf,"%-.39s%-.40s",HD,HD);
fprintf(pf,"\n%s %-58s %5s %8s\n%4.4s %29.29s%29.29s %5.5s %9.9s",
AC,DS,"Files","Bytes",HS,HS,HS,HS,HS);
k = 0;
ab_count = 0L;
for (j=0; j<area_count; j++)
if (area2[j].file_count) {
fprintf(pf,"\n %2.2s %-58.58s %5u %8luK",
area2[j].name,
area2[j].adesc,
area2[j].file_count,
(area2[j].byte_count+512)/1024);
k += area2[j].file_count; // actual filecount
ab_count += area2[j].byte_count; // actual bytecount
} // endif
fprintf(pf,"\n%32.32s%31.31s %5.5s %9.9s",HS,HS,HS,HS,HS);
fprintf(pf,"\n%63s %5u %8luK","Total:",k,(ab_count+512)/1024);
free(area2); // free copy of area array
}
signature(pf,today); // leave fingerprint
for (i=0; i<MAXTIT && bot_lines[i]!=NULL; ++i)
fprintf(pf,"%s\n",bot_lines[i]);
fclose(pf); // finished with .ALL file
}
else
printf(OPEN_FAIL,outfile);
}
/* ------------------------------------------------------- */
/* Produce the file-request format of IPFfiles (IPF-list) */
/* ------------------------------------------------------- */
void make_ipf(dm,area,r_priv)
struct _filechain **dm; // pointer to file-sort array
struct _downpath *area; // pointer to downpath array
int r_priv; // maximum report privilege
{
FILE *pf; // file handle
char outfile[MAXFN]; // file names
char ac[40]; // area name
char *strptr; // pointer to a string
USHORT i,j,k,l,pcnt,pmax,n; // counters
ULONG ab_count; // byte count per area
struct _filechain *ca,*cb,*cn; // pointer to file-info
// struct _downpath *area2; // copy of area-array for sort
char *s; // pointer to line buffer
char ac_str[6]; // for area-code manipulation
char ageflag; // file ages character
/* IPF-tags */
static char CD[] = ":color fc=default.";
static char CG[] = ":cgraphic.";
static char CR[] = ":color fc=red.";
static char DP[] = ":docprof toc='*3'.";
static char ED[] = ":euserdoc.";
static char EG[] = ":ecgraphic.";
static char EL[] = ":elines.";
static char H1[] = ":h1";
static char H2[] = ":h2";
static char H3[] = ":h3";
static char LI[] = ":lines align=center.";
static char LL[] = ":lines align=left.";
static char TI[] = ":title.";
static char UD[] = ":userdoc.";
sprintf(outfile,"%s.%s%c",
lp[P_IPF].name,lp[P_IPF].ext,priv_name[r_priv-TWIT][0]);
pf = fopen(outfile,"w"); // output file
if (pf != NULL) {
if ((s = malloc(255)) == NULL) { // obtain formatting buffer
if (oper_mode!=QUIET)
printf("\nNot enough memory for IPF-list, skipped.");
}
else {
if (oper_mode!=QUIET)
printf(MSG_SRT,file_count,area_count,outfile);
if (lp[P_IPF].sortflag == ALPHA)
psort(dm,0,file_count-1,sort_all);
else if (lp[P_IPF].sortflag == TIMESTAMP)
psort(dm,0,file_count-1,sort_al2);
else if (lp[P_IPF].sortflag == KEEPSEQ)
psort(dm,0,file_count-1,sort_akp);
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);
for (i=0; i<MAXTIT && pre_title[i]!=NULL; ++i)
fprintf(pf,"%s\n",stripf(pre_title[i]));
fprintf(pf,"%s\n%s\n%s\n",EL,CG,CR);
for (i=0; i<title_lines[lp[P_IPF].tfont]; ++i) // whole title
fprintf(pf,"%s\n",strnblk(list_title,20,lp[P_IPF].tfont,i));
fprintf(pf,"%s\n%s\n",CD,EG);
if (lp[P_IPF].incl_fspec != NULL)
file_incl(pf,lp[P_IPF].incl_fspec); // insert user-'logo'
fprintf(pf,"%s\n",LI);
for (i=0; i<MAXTIT && sub_title[i]!=NULL; ++i)
fprintf(pf,"%s\n",stripf(sub_title[i]));
fprintf(pf,"%s\n%s%s%s%s\n",EL,H1,".About ",PROGNAME," program");
fprintf(pf,"\n%s\n",":artwork align=center name='DOWNSORT.BMP'.");
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\n",EL);
ac[0] = '\0'; // null area name
for (i=0; i<file_count; i++) { // all files
ca = dm[i]; // pointer to fileinfo
if (strcmp(ac,ca->parea->name)) { // new area collection
strcpy(ac,ca->parea->name); // set new
ab_count = 0L; // init area byte count
cb = ca; // copy pointer first file
j=k=0; // zero index and counter
while (!strcmp(ac,cb->parea->name) && // stop at end of area
i+j<file_count) { // or at end of files
if (cb->priv <= r_priv) { // check file-privilege
k++; // presentable file count
ab_count += cb->size; // effective area byte count
} // endif
++j; // next file-entry
if (i+j<file_count) // stop at end of files
cb = dm[i+j]; // ptr to next file
} // endfor
ca->parea->file_count = k; // store for overview
ca->parea->byte_count = ab_count; // store for overview
}
}
/* first an area overview */
if (oper_mode==VERBOSE)
printf("\nWriting %s",oview_title);
fprintf(pf,"%s.%s\n",H1,oview_title);
fprintf(pf,"%s\n%s\n",CG,CR);
for (i=0; i<title_lines[lp[P_IPF].tfont]; ++i)
fprintf(pf," %s\n",strnblk(oview_title,12,lp[P_IPF].tfont,i));
fprintf(pf,"%s\n%s\n",CD,EG);
fprintf(pf,"%s\nlist creation date: %s\n",
LI,stripf(sys_date(today)));
if (lp[P_IPF].exclflag != EXCLPRIV)
fprintf(pf,"maximum privilege shown: %s\n",
priv_name[r_priv-TWIT]);
fprintf(pf,"%s\n%s\n:hp2.\n%s %-39s %5s %8s\n\n",
EL,CG,AC,DS,"Files","Bytes");
k = 0;
ab_count = 0L;
for (j=0; j<area_count; j++) {
if (area[j].file_count) {
sprintf(ac_str,"%2.2s",area[j].name);
if (ac_str[0] == ' ')
ac_str[0]='0';
fprintf(pf,":link reftype=hd refid=A$%s. %-.2s :elink.",
ac_str,area[j].name);
sprintf(s," %-39.39s %5u %8luK",
area[j].adesc,
area[j].file_count,
(area[j].byte_count+512)/1024);
fprintf(pf,"%s\n",stripf(s));
k += area[j].file_count; // total filecount
ab_count += area[j].byte_count; // total bytecount
} // endif
}
fprintf(pf,"%25.25s%19.19s %5.5s %9.9s\n",HS,HS,HS,HS,HS);
fprintf(pf,"%44s %5u %8luK\n:ehp2.\n%s\n",
"Total:",k,(ab_count+512)/1024,EG);
/* now the detailed file information per area */
fprintf(pf,"%s%s\n",H1,".File List per Area");
if (oper_mode==VERBOSE) // keep operator awake
printf(MSG_REC,outfile);
fprintf(pf,"%s\ndate flag: new on this system since: "
":hp8.%c:ehp8. = one week, "
":hp8.%c:ehp8. = one month.\n%s\n",
LI,DAYS_7,DAYS_30,EL);
ac[0] = '\0'; // null area name
l=n=0; // init file counters
for (i=0; i<file_count; i++) { // all files
ca = dm[i]; // pointer to fileinfo
if (strcmp(ac,ca->parea->name)) { // new area collection
strcpy(ac,ca->parea->name); // set new
cb = ca; // copy pointer first file
cn = NULL; // not assigned
j=0; // zero index and count
while (!strcmp(ac,cb->parea->name) && // stop at end of area
i+j < file_count) { // or at end of files
if (cb->priv <= r_priv) // check file-privilege
cn = new_acq(cb,cn); // keep pointer to most recent
++j; // next file-entry
if (i+j<file_count) // stop at end of files
cb = dm[i+j]; // ptr to next file
} // endfor
if (ca->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
sprintf(ac_str,"%2.2s",ac);
if (ac_str[0] == ' ')
ac_str[0]='0';
fprintf(pf,":p.Continue with filearea"
":link reftype=hd refid=A$%s. %-.2s :elink.&colon. ",
ac_str, ca->parea->name);
fprintf(pf,"%-45.45s\n", stripf(ca->parea->adesc));
fprintf(pf,"%s id=A$%s.%s - %s\n%s\n",
H2,ac_str,ac,stripf(ca->parea->adesc),CG);
fprintf(pf,"%s%s%s ║ :hp2.%s:ehp2.\n",
CR, strnblk(ac,2,FONT3,LINE1), CD,
stripf(ca->parea->adesc));
fprintf(pf,"%s%s%s ║ :hp2.Available: "
"%u files (%lu.%lu MB):ehp2.\n",
CR, strnblk(ac,2,FONT3,LINE2), CD,
ca->parea->file_count,
(ca->parea->byte_count+52428L)/1048576L, // round
((ca->parea->byte_count+52429L)/104857L)%10); // fract
fprintf(pf,"%s%s%s ║",CR,strnblk(ac,2,FONT3,LINE3),CD);
if (lp[P_IPF].exclflag != EXCLPRIV)
fprintf(pf," :hp2.Privilege: %-.9s:ehp2.",
priv_name[ca->parea->priv-TWIT]); // area priv
fprintf(pf,"\n%s%s%s ║ ",CR,strnblk(ac,2,FONT3,LINE4),CD);
if (cn != NULL) { // newest file
fprintf(pf,":hp2.Newest:");
fprintf(pf," %s",stripf(cn->fname));
fprintf(pf," %s",stripf(f_date(cn->wdate)));
fprintf(pf," (avail: %s):ehp2.",stripf(f_date(cn->cdate)));
}
fprintf(pf,"\n%s\n",EG);
pcnt = l = 0; // sub-counters this area
} // endif
} // endif
if (ca->priv <= r_priv) { // only upto max priv_level
if (oper_mode==VERBOSE && (n%25)==0)
cprintf("\r %5u",n); // report progress
pmax = 1 + ca->parea->file_count/MAXLIST;
if ((l % MAXLIST) == 0) { // first and every MAXLIST entries
if (l == 0) { // only for first entry
if (ca->parea->file_count > MAXLIST) // for splitted list
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=%sP%d.\n"
"part %d of %d:elink.",
ac_str, pcnt, pcnt, pmax);
fprintf(pf,"\n%s id=%sP%d.%s - (part %d of %d)\n",
H3, ac_str, pcnt, ac, pcnt, pmax);
fprintf(pf,":p.%s (part %d of %d)\n",
stripf(ca->parea->adesc), pcnt, pmax);
}
fprintf(pf,":dl tsize=20 compact.\n");
fprintf(pf,":hp6.:dthd.%s:ddhd.%s:ehp6.\n",FN,DS);
}
n++; // total file counter
l++; // listed file counter
fprintf(pf,":dt.:link refid=F$%u reftype=fn.%-s:elink.",
i,stripf(ca->fname)); // filename
ageflag = file_age_ind(ca->cdate,ca->ctime); // file age flag
k = strsubw(ca->fdesc,&strptr,240);
if (ageflag!=' ')
fprintf(pf,":hp8.%c:ehp8.", ageflag);
fprintf(pf,"\n:dd.");
if (k>0)
fprintf(pf,"%s\n",stripf(strptr)); // description
fprintf(pf,":fn id=F$%u.%4ldK %s:efn.\n",
i, // file number
(ca->size+1023)/1024, // round-up for list only
stripf(f_date(ca->wdate))); // file-(lastwrite-)date
} // endif
} // endfor
fprintf(pf,":edl.\n"); // end of file-list this area
if (oper_mode==VERBOSE) // last value
printf("\r %5u",n);
// Area Summary report
fprintf(pf,"%s%s\n%s\n\n",H1,".Epilog",LI);
signature(pf,stripf(today)); // leave fingerprint
for (i=0; i<MAXTIT && bot_lines[i]!=NULL; ++i)
fprintf(pf,"%s\n",stripf(bot_lines[i]));
fprintf(pf,"%s\n%s\n",EL,ED);
stripf(NULL); // let stripf free memory
free(s); // free formatting buffer
}
fclose(pf); // finished with .IPF file
}
else {
if (oper_mode!=QUIET)
printf(OPEN_FAIL,outfile); // warn SYSOP
}
}
/* ---------------------------------------------------- */
/* function to 'neutralise' IPFC conflicting characters */
/* ---------------------------------------------------- */
char *stripf(s)
char *s; // string pointer
{
int i,j,k;
static char colon[] = "&colon.";
static char amp[] = "&.";
static char grave[] = "&rbl."; // translated to required BLANK
static int maxline = 255; // 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
}