home *** CD-ROM | disk | FTP | other *** search
- /* ================================================================ */
- /* Rob Hamerling's MAXIMUS download file scan and sort utility */
- /* -> DOWNRPT1.C */
- /* Make: BBS-list, New-list, EMI-list */
- /* ================================================================ */
-
- #define INCL_BASE
- #include <os2.h>
-
- #include <conio.h>
- #include <memory.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "..\max\mstruct.h"
- #include "downsort.h"
- #include "downfpro.h"
-
-
- /* function prototypes of local functions */
-
- short int file_age(struct _filechain *);
-
-
- /* --------------------------------------- */
- /* Produce the bulletin format of BBS-list */
- /* --------------------------------------- */
- void make_bbs(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x) // report privilege index
- {
- FILE *pf; // report file handle
- char outfile[MAXFN]; // file names
- unsigned int i,j,n,fc; // counters
- struct _filechain *cn; // ptr to newest
- short int max_age; // allowed file age in days
-
- sprintf(outfile,"%s.%s",lp[P_BBS].name,lp[P_BBS].ext); // build filename
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) { // successful open
- if (oper_mode == VERBOSE)
- printf(MSG_SRT, file_total_count, area_total_count, outfile);
- psort(dm, 0, file_total_count-1, sort_new); // sort on date
- fc = preproc_area(area, dm, lp[P_BBS].priv[x]); // count files, bytes
- cn = NULL; // none assigned
- if (lp[P_BBS].listflag == ' ') { // limited by number of entries
- n = lp[P_BBS].max_fil; // max files to be listed
- if (n > fc) // more req'd than within priv
- n = fc; // new request-limit
- for (i=j=0; j<n && i<file_total_count; ++i) // scan limits
- if (dm[i]->priv <= lp[P_BBS].priv[x]) { // check file-privilege
- ++j; // count within priv
- cn = new_acq(dm[i],cn); // most recent within priv
- }
- }
- else { // limited by age
- max_age = lp[P_BBS].max_fil *
- ((lp[P_BBS].listflag == 'W') ? 7 :
- ((lp[P_BBS].listflag == 'M') ? 30 : 1));
- for (i=n=0; file_age(dm[i]) <= max_age &&
- i<file_total_count; ++i) // get report limit
- if (dm[i]->priv <= lp[P_BBS].priv[x]) { // check file-privilege
- ++n; // count within priv and age
- cn = new_acq(dm[i],cn); // most recent within priv
- }
- }
- if (lp[P_BBS].sortflag == ALPHA) { // re-sort first entries on name
- if (oper_mode == VERBOSE)
- printf(MSG_RST, n); // re-sort msg
- psort(dm, 0, i-1, sort_gbl); // re-sort first 'i' entries
- }
- if (oper_mode != QUIET)
- printf(MSG_REP, outfile);
- if (oper_mode == VERBOSE)
- printf(MSG_REC);
- lp[P_BBS].incl_fspec = "DOWNSORT.HDR"; // header filename
- file_incl(pf, P_BBS); // include bbs-header file
-
- fprintf(pf,"\n%c(%s) Last %c%u %s%cnewest of a total of"
- " %c%u%c files (%c%lu%c MB)",
- O_CYAN, sys_date(today),
- O_YELLOW, lp[P_BBS].max_fil,
- (lp[P_BBS].listflag==' ') ? EMPTY :
- ((lp[P_BBS].listflag=='D') ? DAYS :
- ((lp[P_BBS].listflag=='W') ? WEEKS : MONTHS)),
- O_CYAN,
- O_YELLOW, fc, O_CYAN,
- O_BRIGHT+O_MAGENTA,
- (count_bytes(area)/1024+512)/1024,O_CYAN);
-
- if (lp[P_BBS].sortflag == ALPHA && // for filename-sorted list only
- cn != NULL) { // new file available
- fprintf(pf,"\n%19sNewest: %c%s %c%8s",
- "", O_YELLOW, cn->fname,
- O_GREEN,f_date(cn->wdate) );
- fprintf(pf," %c(avail: %c%8s%c)",
- O_CYAN,O_GREEN,
- f_date(cn->cdate),O_CYAN);
- }
- fprintf(pf,"\n%19s%s %c%s, %c%s",
- "", DF, DAYS_7, WK, DAYS_30, MO);
- if (lp[P_BBS].exclflag != EXCLPRIV)
- fprintf(pf,"\n\n%c(Your privilege-level may limit the number "
- "of files actually shown to you!)%c",O_RED,O_CYAN);
- fprintf(pf,"\n\n%c%s %c%s %c%s %c%s %c%s\n\n",
- O_YELLOW,FN,
- O_BRIGHT+O_RED,AC,
- O_MAGENTA,SZ,
- O_GREEN,DT,
- O_CYAN,DS);
- for (i=j=0; j<n && i<file_total_count; i++) {
- if (dm[i]->priv <= lp[P_BBS].priv[x]) { // limit to report priv.
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- ++j; // list file-count
- fprintf(pf,"%cL%c%c%-12.12s %c%4.4s %c%4ldK %c%s%c %c",
- '\20',
- (dm[i]->priv>SYSOP)?'S':priv_name[dm[i]->priv-TWIT][0],
- O_YELLOW,dm[i]->fname,
- O_RED+O_BRIGHT,dm[i]->parea->name,
- O_MAGENTA,(dm[i]->size+1023)/1024,
- O_GREEN,f_date(dm[i]->wdate),
- file_age_ind(dm[i]->cdate,dm[i]->ctime), // file age
- O_CYAN);
- desc_part(pf, dm[i]->fdesc, 45, 45, P_BBS); /* file description */
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- signature(pf,today); // fingerprint
- lp[P_BBS].incl_fspec = "DOWNSORT.TRL"; // trailer filename
- file_incl(pf, P_BBS); // include bbs-trailer file
- fclose(pf); // finished with .BBS file
- }
- else // no output possible
- printf(OPEN_FAIL, outfile, 0);
- }
-
- /* ------------------------------------------- */
- /* Produce the file-request format of NEW-list */
- /* ------------------------------------------- */
- void make_new(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x) // report priv index
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- unsigned int i,j,n,fc; // counters
- struct _filechain *cn; // ptr to newest
- short int max_age; // allowed file age in days
-
- sprintf(outfile,"%s.%s%c",
- lp[P_NEW].name,
- lp[P_NEW].ext,
- priv_name[lp[P_NEW].priv[x]-TWIT][0]);
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) { // opened!
- if (oper_mode == VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,outfile);
- psort(dm, 0, file_total_count-1, sort_new);
- fc = preproc_area(area, dm, lp[P_NEW].priv[x]); // count file, bytes
- cn = NULL; // no assigned
- if (lp[P_NEW].listflag == ' ') { // limited by number of entries
- n = lp[P_NEW].max_fil; // take maximum files to be listed
- if (n > fc) // more req'd than within priv
- n = fc; // new request-limit
- for (i=j=0; j<n && i<file_total_count; ++i) // scan limits
- if (dm[i]->priv <= lp[P_NEW].priv[x]) { // check file-privilege
- ++j; // count within priv.
- cn = new_acq(dm[i],cn); // most recent within priv.
- }
- }
- else { // limited by age
- max_age = lp[P_NEW].max_fil *
- ((lp[P_NEW].listflag == 'W') ? 7 :
- ((lp[P_NEW].listflag == 'M') ? 30 : 1));
- for (i=n=0; file_age(dm[i]) <= max_age &&
- i<file_total_count; ++i) // get report limit
- if (dm[i]->priv <= lp[P_NEW].priv[x]) { // check file-privilege
- ++n; // count within priv and age
- cn = new_acq(dm[i],cn); // most recent within priv
- }
- }
- if (lp[P_NEW].sortflag == ALPHA) { // resort first entries on name
- if (oper_mode == VERBOSE)
- printf(MSG_RST, n); // re-sort msg
- psort(dm, 0, i-1, sort_gbl); // sort first 'i' entries
- }
- 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_NEW);
- file_incl(pf, P_NEW); // insert user-'logo'
- insert_title(pf, sub_title, 0);
- fprintf(pf,"\n(%s) Last %u %snewest of a total of %u files (%lu MB)",
- sys_date(today),
- lp[P_NEW].max_fil,
- (lp[P_NEW].listflag==' ') ? EMPTY :
- ((lp[P_NEW].listflag=='D') ? DAYS :
- ((lp[P_NEW].listflag=='W') ? WEEKS : MONTHS)),
- fc, (count_bytes(area)/1024+512)/1024);
- if (lp[P_NEW].exclflag != EXCLPRIV)
- fprintf(pf,"\n%19s%s%s",
- "",MP,priv_name[lp[P_NEW].priv[x]-TWIT]);
- if (lp[P_NEW].sortflag == ALPHA && // for filename-sorted list only
- cn != NULL) { // newest file
- fprintf(pf,"\n%19sNewest: %s dd %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; j<n && i<file_total_count; i++) {
- if (dm[i]->priv <= lp[P_NEW].priv[x]) { // only upto max priv_level
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- ++j; // file list-count
- 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_NEW); /* file descr. */
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- signature(pf,today); // leave fingerprint
- insert_title(pf, bot_lines, 0);
- fclose(pf); // finished with .NEW file
- }
- else
- printf(OPEN_FAIL, outfile, 0);
- }
-
- /* ------------------------------------------- */
- /* Produce the file-request format of EMI-list */
- /* This is a more compact variant of NEW-list. */
- /* File date, time and size are exact. */
- /* ------------------------------------------- */
- void make_emi(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x) // report priv index
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- unsigned int i,j,n,fc; // counters
- struct _filechain *cn; // ptr to newest
- short int max_age; // allowed file age in days
-
- sprintf(outfile,"%s.%s%c",
- lp[P_EMI].name,
- lp[P_EMI].ext,
- priv_name[lp[P_EMI].priv[x]-TWIT][0]);
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) { // opened!
- if (oper_mode == VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,outfile);
- psort(dm, 0, file_total_count-1, sort_new);
- fc = preproc_area(area, dm, lp[P_EMI].priv[x]); // count file, bytes
- cn = NULL; // no assigned
- if (lp[P_EMI].listflag == ' ') { // limited by number of entries
- n = lp[P_EMI].max_fil; // take maximum files to be listed
- if (n > fc) // more req'd than within priv
- n = fc; // new request-limit
- for (i=j=0; j<n && i<file_total_count; ++i) // scan limits
- if (dm[i]->priv <= lp[P_EMI].priv[x]) { // check file-privilege
- ++j; // count within priv.
- cn = new_acq(dm[i],cn); // most recent within priv.
- }
- }
- else { // limited by age
- max_age = lp[P_EMI].max_fil *
- ((lp[P_EMI].listflag == 'W') ? 7 :
- ((lp[P_EMI].listflag == 'M') ? 30 : 1));
- for (i=n=0; file_age(dm[i]) <= max_age &&
- i<file_total_count; ++i) // get report limit
- if (dm[i]->priv <= lp[P_EMI].priv[x]) { // check file-privilege
- ++n; // count within priv and age
- cn = new_acq(dm[i],cn); // most recent within priv
- }
- }
- if (lp[P_EMI].sortflag == ALPHA) { // resort first entries on name
- if (oper_mode == VERBOSE)
- printf(MSG_RST, n); // re-sort msg
- psort(dm, 0, i-1, sort_gbl); // sort first 'i' entries
- }
- if (oper_mode != QUIET)
- printf(MSG_REP, outfile);
- if (oper_mode==VERBOSE)
- printf(MSG_REC);
- file_incl(pf, P_EMI); // insert user text
- fprintf(pf,"\n(%s) Last %u %semissions",
- sys_date(today),
- lp[P_EMI].max_fil,
- (lp[P_EMI].listflag==' ') ? EMPTY :
- ((lp[P_EMI].listflag=='D') ? DAYS :
- ((lp[P_EMI].listflag=='W') ? WEEKS : MONTHS)));
- fprintf(pf,"\n\n--%s-- --%s-- -%s- -%s- ---%s---\n",
- FN,DT,TM,BY,DS);
- for (i=j=0; j<n && i<file_total_count; i++) {
- if (dm[i]->priv <= lp[P_EMI].priv[x]) { // only upto max priv_level
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- ++j; // file list-count
- fprintf(pf,"%-12.12s %8.8s %6.6s %8u ",
- dm[i]->fname,
- f_date(dm[i]->wdate),
- f_time(dm[i]->wtime),
- dm[i]->size);
- desc_part(pf, dm[i]->fdesc, 39, 66, P_EMI); /* file descr. */
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- fprintf(pf,"\n-- List created with %s %c.%c%c by %s --\n\n",
- PROGNAME,VERSION,SUBVERS,SUFFIX,AUTHOR);
- fclose(pf); // finished with .EMI file
- }
- else
- printf(OPEN_FAIL, outfile, 0);
- }
-
- /* ------------------------------------ */
- /* Calculate file-age in number of days */
- /* ------------------------------------ */
- short int file_age(struct _filechain *f)
- {
- return((short int)((time(NULL) - file_time(f->cdate,f->ctime))/86400));
- }
-