home *** CD-ROM | disk | FTP | other *** search
- /* ================================================================ */
- /* Rob Hamerling's MAXIMUS download file scan and sort utility */
- /* -> DOWNRPT3.C */
- /* -> Make SYSOP lists: ORP-list, DUP-list, OK-file, all FILES.BBS */
- /* ================================================================ */
-
- #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"
-
- /* prototypes of local functions */
-
- int dup_fil(struct _filechain **, unsigned int);
-
- /* ------------------------- */
- /* Produce the ORPHAN report */
- /* ------------------------- */
- void make_orp(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
-
- sprintf(outfile,"%s.%s",lp[P_ORP].name,lp[P_ORP].ext); // build filename
- if (oper_mode==VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,outfile);
- switch(lp[P_ORP].sortflag) { // sort
- 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_ORP].priv[x]); // files within priv
- j = file_total_count - fc; // calc orphans
- if (j>0) { // yes, there are orphans
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) { // successful open
- if (oper_mode != QUIET)
- printf(MSG_REP, outfile);
- if (oper_mode == VERBOSE)
- printf(MSG_REC);
- block_title(pf, 9, " Orphans ", P_ORP); // generate block title
- fprintf(pf, "\n");
- sep_line(pf, '═', 79, 0); // separator line
- fprintf(pf,"%s %s %s %-s\n", AC, FN, DT, FP);
- sep_line(pf, '─', 4, 12, 9, 51, 0);
- for (i=j=0; i<file_total_count; i++) {
- if (dm[i]->priv >= HIDDEN) { // report "hidden" and up
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- ++j; // list file-count
- dm[i]->fdesc = ORPHAN; // assign 'description'
- fprintf(pf,"%4.4s %-12.12s %s ",
- dm[i]->parea->name,
- dm[i]->fname,
- f_date(dm[i]->wdate));
- desc_part(pf, dm[i]->parea->pname, 51, 51, P_ORP);
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j); // total reported orphans
- signature(pf,today); // fingerprint
- fclose(pf); // finished with .ORP file
- }
- else // no output possible
- printf(OPEN_FAIL, outfile, 0);
- }
- }
-
- /* ------------------ */
- /* Produce a DUP-list */
- /* ------------------ */
- void make_dup(struct _filechain **dm,
- unsigned int x) // list privilege index
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- unsigned int i,j; // counters
-
- sprintf(outfile,"%s.%s", lp[P_DUP].name, lp[P_DUP].ext);
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) {
- if (oper_mode == VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,outfile);
- psort(dm, 0, file_total_count-1, sort_gbl); // filename sort
- if (oper_mode != QUIET)
- printf(MSG_REP, outfile);
- if (oper_mode == VERBOSE)
- printf(MSG_REC);
- block_title(pf, 12, " Duplicates ", P_DUP);
- if (lp[P_DUP].exclflag != EXCLPRIV)
- fprintf(pf,"\n%s%s\n",
- MP, priv_name[lp[P_DUP].priv[x]-TWIT]);
- fprintf(pf,"\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_DUP].priv[x] && // within priv limit and
- dup_fil(dm, i)) { // if duplicate
- if (oper_mode==VERBOSE && (j%5)==0)
- cprintf("\r %5u",j); // display count by 5
- if (dm[i]->fname[0] != '\0') { // not a comment-entry
- j++; // count duplicates
- 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_DUP); /* file descr. */
- }
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- signature(pf,today); // leave fingerprint
- fclose(pf); // finished with .DUP file
- }
- else
- printf(OPEN_FAIL, outfile, 0);
- }
-
- /* ---------------------------------------- */
- /* Test on duplicate filenames for GBL-list */
- /* Returns 0 if NOT equal, 1 if equal. */
- /* ---------------------------------------- */
- int dup_fil(struct _filechain **dm,
- unsigned int k) // index in dm
- {
- char f1[9],f2[9]; // filenames
-
- non_wild_init(8, f1, dm[k]->fname); // filename of current entry
- f1[8] = '\0'; // end of string
- if (k>0) { // not very first
- non_wild_init(8, f2, dm[k-1]->fname); // previous entry
- f2[8] = '\0'; // end of string
- if (!strcmp(f1,f2)) // equal
- return(1);
- }
- if (k<file_total_count-1) { // not very last
- non_wild_init(8, f2, dm[k+1]->fname); // next entry
- f2[8] = '\0'; // end of string
- if (!strcmp(f1,f2)) // equal
- return(1);
- }
- return(0); // not equal
- }
-
- /* ---------------------------------------------------------------- */
- /* Produce the FILES.BBS files for all area's */
- /* Sort on name within priv-group, date or as in input FILES.BBS */
- /* Call them FILESBBS.xx (where 'xx' is a 2-character area-name). */
- /* Put them in the directory indicated by AREA.DAT for 'listfile'. */
- /* ---------------------------------------------------------------- */
- void make_fil(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x)
- {
- FILE *pf; // file handle
- char outfile[MAXPATH]; // file spec new FILES.bbs
- char oldfile[MAXPATH]; // file spec old FILES.bbs
- char ac[40]; // area name
- unsigned int i,j,m,fc; // counters
- int c_priv; // privilege
-
- if (oper_mode == VERBOSE)
- printf(MSG_SRT,file_total_count,area_total_count,"FILES.BBS-files");
-
- switch(lp[P_FIL].sortflag) {
- case ALPHA: psort(dm,0,file_total_count-1,sort_fil); 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_FIL].priv[x]); // count files, bytes
- if (oper_mode != QUIET)
- printf(MSG_REP,"all FILES.BBS files");
- pf = NULL; // no file open yet
- ac[0] = '\0'; // init with null-string
- for (i=0; i<file_total_count; i++) {
- if (strcmp(ac,dm[i]->parea->name)) { // new area group
- if (pf != NULL) // end of previous group
- fclose(pf); // finished
- strcpy(ac, dm[i]->parea->name); // new area
- c_priv = dm[i]->parea->priv; // new AREA-priv
- // generate new FILES.bbs
- if (strlen(filesbbs_path) > 0) { // FIL:path parameter specified
- strcpy(outfile,filesbbs_path); // copy path
- strcat(outfile,lp[P_FIL].name); // add filename
- strcat(outfile,DOT); // add separator
- strncat(outfile, ac, 3); // max first 3 bytes of areaname
- }
- else if (strlen(dm[i]->parea->filesbbs) > 0) { // "ListFile" spec
- strcpy(outfile,dm[i]->parea->filesbbs);
- strcpy(oldfile,outfile); // backup file
- for (j=strlen(oldfile), m=1;
- (j-m)>0 && m<5 && outfile[j-m]!='.'; ++m); // search '.'
- if (m>=5 || (j-m)<=0) // no extension found:
- m=0; // concat to end of name
- strcpy(oldfile+j-m,DOT); // add separator
- strcat(oldfile,BAK); // backup file extension
- unlink(oldfile); // erase old backup file
- rename(outfile,oldfile); // rename current to backup
- }
- else { // default directory
- strcpy(outfile,dm[i]->parea->pname); // path to download directory
- strcat(outfile,lp[P_FIL].name); // add filename
- strcat(outfile,DOT); // add separator
- strcpy(oldfile,outfile); // backup file
- strcat(oldfile,BAK); // backup file extension
- strcat(outfile,lp[P_FIL].ext); // add BBS-extension
- unlink(oldfile); // erase old backup file
- rename(outfile,oldfile); // rename current to backup
- }
-
- pf = fopen(outfile,WRITE);
- if (pf != NULL) {
- fprintf(pf,"-\f\n-%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, // area filecount
- (dm[i]->parea->byte_count+52428L)/1048576L, // rounded to 100K
- ((dm[i]->parea->byte_count+52429L)/104857L)%10); // 100K frac
- fprintf(pf,"-%s ║",
- strnblk(ac,3,FONT3,LINE3));
- if (lp[P_FIL].exclflag != EXCLPRIV)
- fprintf(pf," Privilege: %-.9s",
- priv_name[dm[i]->parea->priv-TWIT]); // area privilege
- fprintf(pf,"\n-%s ║ ",
- strnblk(ac,3,FONT3,LINE4));
- 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, '─', 78, 0);
- file_incl(pf,P_FIL); // insert user-'logo'
- fprintf(pf," %s %s %s %s\n-",FN,SZ,DT,DS);
- sep_line(pf, '─', 11, 7, 9, 48, 0);
- }
- else
- printf(OPEN_FAIL, outfile, 0);
- } // endif
- if (pf != NULL) { // check for open file
- if (dm[i]->priv <= lp[P_FIL].priv[x]) { // specified reporting level
- if (dm[i]->priv > c_priv) { // higher priv group within area
- c_priv = dm[i]->priv; // set new
- fprintf(pf,"%c%c\n", '\20',
- (c_priv>SYSOP) ? 'S' : priv_name[c_priv-TWIT][0]);
- }
- if (dm[i]->fname[0] != '\0') { // filename present
- fprintf(pf,"%-12.12s ", dm[i]->fname); // filename
- if (dm[i]->dl_b==1 || dm[i]->dl_t==1) { // download flags
- fprintf(pf,"/");
- if (dm[i]->dl_b==1) // free bytes flag
- fprintf(pf,"b");
- if (dm[i]->dl_t==1) // free time flag
- fprintf(pf,"t");
- }
- fprintf(pf," %-s\n", dm[i]->fdesc); // description
- }
- else if(lp[P_FIL].sortflag == KEEPSEQ) // '/K' specified
- fprintf(pf,"%-s\n", dm[i]->fdesc);
- }
- }
- }
- if (pf != NULL) // end of last FILES.BBS
- fclose(pf); // finished with FILES.bbs file
- } // end
-
- /* ------------------------------ */
- /* Produce the BinkleyTerm OKFile */
- /* (area's in downpath sequence!) */
- /* ------------------------------ */
- void make_ok(struct _filechain **dm,
- struct _downpath huge *area,
- unsigned int x)
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- unsigned int i,j; // counters
-
- sprintf(outfile,"%s.%s%c",
- lp[P_OK].name,
- lp[P_OK].ext,
- priv_name[lp[P_OK].priv[x]-TWIT][0]);
- pf = fopen(outfile,WRITE); // output file
- if (pf != NULL) {
- if (oper_mode != QUIET)
- printf(MSG_REP, outfile);
- file_incl(pf, P_OK); // insert magic filenames
- preproc_area(area, dm, lp[P_OK].priv[x]); // count files, bytes
- if (lp[P_OK].longflag == LONGLIST) { // LONG list requested
- for (i=0; i<file_total_count; i++) { // all files in chain
- if (dm[i]->priv <= lp[P_OK].priv[x] && // check file privilege
- dm[i]->fname[0] != '\0') // filename present
- fprintf(pf, "@%s %s%s\n",
- dm[i]->fname, dm[i]->parea->pname, dm[i]->fname);
- }
- }
- else {
- for (i=j=0; i<area_total_count; i++) // all area's in array
- if (area[i].priv <= lp[P_OK].priv[x] && // area privilege
- area[i].file_count > 0) // and at least 1 file
- if (i<1 || strcmp(area[i].pname,area[j].pname)) { // not yet in
- fprintf(pf, "%s*.*\n", area[i].pname);
- j = i; // index of last 'printed'
- }
- }
- fclose(pf); // finished with .ALL file
- }
- else
- printf(OPEN_FAIL, outfile, 0); // open failed
- }
-
-