home *** CD-ROM | disk | FTP | other *** search
- /* ================================================================ */
- /* Rob Hamerling's MAXIMUS download file scan and sort utility */
- /* -> Functions for creating file reports (the mainlines of them). */
- /* ================================================================ */
-
- // #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"
-
- /* ------------------------- */
- /* Produce the ORPHAN report */
- /* ------------------------- */
- void make_orp(dm)
- struct _filechain **dm; // pointer to file-sort array
- {
- static char orp_title[] = " Orphans ";
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- USHORT i,j,k; // counters
- char *strptr; // pointer to a string
- struct _filechain *ca; // pointer to file-info
-
- sprintf(outfile,"%s.%s",lp[P_ORP].name,lp[P_ORP].ext); // build filename
- if (oper_mode==VERBOSE)
- printf(MSG_SRT,file_count,area_count,outfile);
- if (lp[P_ORP].sortflag == ALPHA) // sort on name
- psort(dm,0,file_count-1,sort_gbl);
- else if (lp[P_ORP].sortflag == TIMESTAMP) // sort on date
- psort(dm,0,file_count-1,sort_new);
-
- j = file_count - count_files(dm, SYSOP); // calc orphans in array
- if (j>0) { // yes, there are orphans
- if (oper_mode == VERBOSE)
- printf("\n%d Orphans detected",j); // console message
- pf = fopen(outfile,"w"); // output file
- if (pf != NULL) { // successful open
- if (oper_mode == VERBOSE)
- printf("\nCreating Orphan-report: %s",outfile);
- for (i=0; i<title_lines[lp[P_ORP].tfont]; ++i) // whole title
- fprintf(pf,"%s\n",strnblk(orp_title,13,lp[P_ORP].tfont,i));
- fprintf(pf,"%-.39s%-.40s",HD,HD);
- fprintf(pf,"\n%s %s %s %-s",AC,FN,DT,FP);
- fprintf(pf,"\n%4.4s %-12.12s %-8.8s %-.26s%-.26s",HS,HS,HS,HS,HS);
- for (i=0; i<file_count; i++) {
- ca = dm[i]; // pointer to file information
- if (ca->priv >= HIDDEN) { // report "hidden" and up
- ca->fdesc = ORPHAN; // assign 'description'
- k = strsubw(ca->parea->pname,&strptr,52);
- fprintf(pf,"\n %2.2s %-12.12s %s %-.*s",
- ca->parea->name,
- ca->fname,
- f_date(ca->wdate),
- k,(k>0)?strptr:""); // (part of) path-name
- while (k>0) {
- k = strsubw(strptr+k,&strptr,52);
- if (k>0)
- fprintf(pf,"\n%-27.27s%-.*s",
- "",k,strptr); // remainder of path-name
- }
- }
- }
- signature(pf,today); // fingerprint
- fclose(pf); // finished with .ORP file
- }
- else // no output possible
- printf(OPEN_FAIL,outfile);
- }
- }
-
- /* --------------------------------------- */
- /* Produce the bulletin format of BBS-list */
- /* --------------------------------------- */
- void make_bbs(dm,m,r_priv)
- struct _filechain **dm; // pointer to file-sort array
- USHORT m; // maximum file lines
- int r_priv; // maximum report privilege
- {
- FILE *pf; // report file handle
- char outfile[MAXFN]; // file names
- USHORT i,j,k,n; // counters
- char *strptr; // pointer to a string
- struct _filechain *ca,*cn; // current and newest file ptr
-
- sprintf(outfile,"%s.%s",lp[P_BBS].name,lp[P_BBS].ext); // build filename
- pf = fopen(outfile,"w"); // output file
- if (pf != NULL) { // successful open
- if (oper_mode!=QUIET)
- printf(MSG_SRT, file_count, area_count, outfile);
- psort(dm,0,file_count-1,sort_new);
- n = m; // take maximum files to be listed
- cn = NULL; // not assigned
- for (i=j=0; j<n && i<file_count; i++) // stop when req'd # reached
- if (dm[i]->priv <= r_priv) { // check file-privilege
- j++; // presentable file count
- cn = new_acq(dm[i],cn); // keep pointer to most recent
- } // within privilege
- if (n > j) // more req'd than within priv
- n = j; // new request-limit
- if (lp[P_BBS].sortflag == ALPHA) { // resort first entries on name
- if (oper_mode == VERBOSE)
- printf(MSG_RST,i); // re-sort msg
- psort(dm,0,i-1,sort_gbl); // sort first 'i' entries
- }
-
- if (oper_mode==VERBOSE)
- printf(MSG_REC,outfile);
- strcpy(outfile,PROGNAME); // build headerfilename
- strcat(outfile,".HDR");
- file_incl(pf, outfile); // include bbs headerfile
- fprintf(pf,"\n%c(%s) %c%u%c most recent of a total of"
- " %c%u%c files (%c%lu%c MB)",
- O_CYAN,sys_date(today),
- O_YELLOW,n,O_CYAN,
- O_YELLOW,count_files(dm, r_priv),O_CYAN,
- O_BRIGHT+O_MAGENTA,
- (count_bytes(dm, r_priv)/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%19sDate flag: new on this system since:"
- " %c = week, %c = month.","",DAYS_7,DAYS_30);
- 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",
- 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_count; i++) {
- ca = dm[i]; // pointer to file information
- if (ca->priv <= r_priv) { // limit to report privilege
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- j++; // list file-count
- k = strsubw(ca->fdesc,&strptr,47);
- if (k>0 && lp[P_BBS].wrapflag != WRAP) // default: trunc
- k = 47;
- fprintf(pf,"\n%cL%c%c%-12.12s %c%2.2s "
- "%c%4ldK %c%s%c %c%-.*s",
- '\20',priv_name[ca->priv-TWIT][0],
- O_YELLOW,ca->fname,
- O_RED+O_BRIGHT,ca->parea->name,
- O_MAGENTA,(ca->size+1023)/1024, // roundup for list only
- O_GREEN,f_date(ca->wdate),
- file_age_ind(ca->cdate,ca->ctime), // file age indicator
- O_CYAN,k,(k>0)?strptr:""); // (part of) description
- if (lp[P_BBS].wrapflag == WRAP)
- while (k>0) {
- k = strsubw(strptr+k,&strptr,47);
- if (k>0)
- fprintf(pf,"\n%-32.32s%-.*s",
- "",k,strptr); // remainder
- }
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- signature(pf,today); // fingerprint
- strcpy(outfile,PROGNAME); // build trailerfilename
- strcat(outfile,".TRL");
- file_incl(pf, outfile); // include bbs trailerfile
- fclose(pf); // finished with .BBS file
- }
- else // no output possible
- printf(OPEN_FAIL,outfile);
- }
-
- /* ------------------------------------------- */
- /* Produce the file-request format of NEW-list */
- /* ------------------------------------------- */
- void make_new(dm,m,r_priv)
- struct _filechain **dm; // pointer to file-sort array
- USHORT m; // max files to be listed
- int r_priv; // maximum report privilege
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- USHORT i,j,k,n; // counters
- char *strptr; // pointer to a string
- struct _filechain *ca,*cn; // pointer to file-info
-
- sprintf(outfile,"%s.%s%c",
- lp[P_NEW].name,lp[P_NEW].ext,priv_name[r_priv-TWIT][0]);
- pf = fopen(outfile,"w"); // output file
- if (pf != NULL) { // opened!
- if (oper_mode!=QUIET)
- printf(MSG_SRT,file_count,area_count,outfile);
- psort(dm,0,file_count-1,sort_new);
- n = m; // take maximum files to be listed
- cn = NULL; // no assigned
- for (i=j=0; j<n && i<file_count; i++) { // stop when req'd # reached
- if (dm[i]->priv <= r_priv) { // check file-privilege
- j++; // presentable file count
- cn = new_acq(dm[i],cn); // keep pointer to most recent
- }
- }
- if (n > j) // more req'd than within priv
- n = j; // new request-limit
- if (lp[P_NEW].sortflag == ALPHA) { // resort first entries on name
- if (oper_mode==VERBOSE)
- printf(MSG_RST,i); // re-sort msg
- psort(dm,0,i-1,sort_gbl); // sort first 'i' entries
- }
-
- 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_NEW].tfont]; ++i)
- fprintf(pf,"%s\n",strnblk(list_title,20,lp[P_NEW].tfont,i));
- if (lp[P_NEW].incl_fspec != NULL)
- file_incl(pf,lp[P_NEW].incl_fspec); // insert user-'logo'
- for (i=0; i<MAXTIT && sub_title[i]!=NULL; ++i)
- fprintf(pf,"%s\n",sub_title[i]);
- fprintf(pf,"\n(%s) %u most recent of a total of %u files (%lu MB)",
- sys_date(today),
- n,
- count_files(dm, r_priv),
- (count_bytes(dm, r_priv)/1024+512)/1024);
- if (lp[P_NEW].exclflag != EXCLPRIV)
- fprintf(pf,"\n%19sMaximum privilege shown: %s",
- "",priv_name[r_priv-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%19sDate flag: new on this system since:"
- " %c = week, %c = month.","",DAYS_7,DAYS_30);
- fprintf(pf,"\n\n%s %s %s %s %s",FN,AC,SZ,DT,DS);
- fprintf(pf,"\n%-.12s ── %-.5s %-.8s %-.23s%-.24s",HS,HS,HS,HS,HS);
- for (i=j=0; j<n && i<file_count; i++) {
- ca = dm[i]; // pointer to file information
- if (ca->priv <= r_priv) { // only upto max priv_level
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- j++; // file list-count
- k = strsubw(ca->fdesc,&strptr,47);
- if (k>0 && lp[P_NEW].wrapflag != WRAP) // default: TRUNC
- k = 47;
- fprintf(pf,"\n%-12.12s %2.2s %4ldK %s%c %-.*s",
- ca->fname,
- ca->parea->name,
- (ca->size+1023)/1024, // roundup 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_NEW].wrapflag == WRAP)
- while (k>0) {
- k = strsubw(strptr+k,&strptr,47);
- if (k>0)
- fprintf(pf,"\n%-32.32s%-.*s",
- "",k,strptr); // remainder
- }
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- 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 .NEW file
- }
- else
- printf(OPEN_FAIL,outfile);
- }
-
- /* ------------------------------------------- */
- /* Produce the file-request format of GBL-list */
- /* ------------------------------------------- */
- void make_gbl(dm,r_priv)
- struct _filechain **dm; // pointer to file-sort array
- int r_priv; // maximum report privilege
- {
- FILE *pf; // file handle
- char outfile[MAXFN]; // file names
- USHORT i,j,k; // counters
- char *strptr; // pointer to a string
- struct _filechain *ca,*cn; // pointer to file-info
-
- sprintf(outfile,"%s.%s%c",
- lp[P_GBL].name,lp[P_GBL].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_GBL].sortflag == ALPHA)
- psort(dm,0,file_count-1,sort_gbl); // filename sort
- else if (lp[P_GBL].sortflag == TIMESTAMP)
- psort(dm,0,file_count-1,sort_new); // filedate sort
- cn = NULL; // no assigned
- for (i=k=0; i<file_count; ++i) { // stop at end of files
- if (dm[i]->priv <= r_priv) { // check file-privilege
- k++; // presentable file count
- cn = new_acq(dm[i],cn); // keep pointer to most recent
- } // endif
- } // endfor
- 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_GBL].tfont]; ++i) // whole title
- fprintf(pf,"%s\n",strnblk(list_title,20,lp[P_GBL].tfont,i));
- if (lp[P_GBL].incl_fspec != NULL)
- file_incl(pf,lp[P_GBL].incl_fspec); // insert user-'logo'
- for (i=0; i<MAXTIT && sub_title[i]!=NULL; ++i)
- fprintf(pf,"%s\n",sub_title[i]);
- fprintf(pf,"\n(%s) Available: %u files (%lu MB)",
- sys_date(today),
- count_files(dm, r_priv),
- (count_bytes(dm, r_priv)/1024+512)/1024);
- if (lp[P_GBL].exclflag != EXCLPRIV)
- fprintf(pf,"\n%19sMaximum privilege shown: %s",
- "",priv_name[r_priv-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%19sDate flag: new on this system since:"
- " %c = week, %c = month.","",DAYS_7,DAYS_30);
- fprintf(pf,"\n\n%s %s %s %s %s\n",FN,AC,SZ,DT,DS);
- fprintf(pf,"%-.12s ── %-.5s %-.8s %-.23s%-.24s",HS,HS,HS,HS,HS);
- for (i=j=0; i<file_count; i++) {
- ca = dm[i]; // pointer to file information
- if (ca->priv <= r_priv) { // within priv limit
- if (oper_mode==VERBOSE && (j%25)==0)
- cprintf("\r %5u",j);
- j++;
- k = strsubw(ca->fdesc,&strptr,47);
- if (k>0 && lp[P_GBL].wrapflag == TRUNC) // default: wrap!
- k = 47;
- fprintf(pf,"\n%-12.12s %2.2s %4ldK %s%c %-.*s",
- ca->fname,
- ca->parea->name,
- (ca->size+1023)/1024, // roundup 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_GBL].wrapflag != TRUNC) {
- while (k>0) {
- k = strsubw(strptr+k,&strptr,47);
- if (k>0)
- fprintf(pf,"\n%-32.32s%-.*s",
- "",k,strptr); // remainder
- }
- }
- }
- }
- if (oper_mode==VERBOSE)
- printf("\r %5u",j);
- 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 .GBL file
- }
- else
- printf(OPEN_FAIL,outfile);
- }
-
- /* ---------------------------------------------------------------- */
- /* 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(dm,r_priv)
- struct _filechain **dm; // pointer to file-sort array
- int r_priv; // maximum report privilege
- {
- 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
- USHORT i,j,k,m; // counters
- ULONG ab_count; // byte count per area
- struct _filechain *ca,*cb,*cn; // pointer to file-info
- int c_priv; // privilege
-
- if (oper_mode!=QUIET)
- printf(MSG_SRT,file_count,area_count,"FILES.BBS-files");
- if (lp[P_FIL].sortflag == ALPHA)
- psort(dm,0,file_count-1,sort_fil); // filename within priv-group
- else if (lp[P_FIL].sortflag == TIMESTAMP)
- psort(dm,0,file_count-1,sort_al2); // filedate within area
- else if (lp[P_FIL].sortflag == KEEPSEQ)
- psort(dm,0,file_count-1,sort_akp); // seq. of FILES.BBS per area
-
- if (oper_mode==VERBOSE)
- printf("\nWriting all FILES.BBS files");
- pf = NULL; // no file open yet
- strcpy(ac,""); // initial area name
-
- for (i=0; i<file_count; i++) {
- ca = dm[i]; // pointer to fileinfo
- if (strcmp(ac,ca->parea->name)) { // new area group
- if (pf != NULL) { // end of previous group
- fprintf(pf,"\n"); // extra blank line at end
- fclose(pf); // finished
- }
- strcpy(ac,ca->parea->name); // new area-name
- c_priv = ca->parea->priv; // new AREA-priv
- ab_count = 0L; // init area byte count
- cb = ca; // copy pointer (first file)
- cn = NULL; // not assigned
- for (j=k=0; i+j<file_count && // stop at end of files
- !strcmp(ac,cb->parea->name); ) { // or at end of area
- if (cb->priv <= r_priv) { // within area privilege
- ++k; // update included file count
- ab_count += cb->size; // effective area byte count
- cn = new_acq(cb,cn); // keep pointer to most recent
- } // endif
- ++j; // next file-entry
- if (i+j<file_count) // stop at end of files
- cb = dm[i+j]; // ptr to next file
- } // endfor
-
- // generate new FILES.bbs
- if (strlen(filesbbs_path) > 0) { // FIL:path specified
- strcpy(outfile,filesbbs_path); // copy path
- strcat(outfile,lp[P_FIL].name); // add filename
- strcat(outfile,"."); // add separator
- strncat(outfile,((ac[0]==' ') ? &ac[1] : ac),2); // add ext
- }
- else if (strlen(ca->parea->filesbbs) > 0) { // "ListFile" spec
- strcpy(outfile,ca->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,"."); // 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,ca->parea->pname); // path to download directory
- strcat(outfile,lp[P_FIL].name); // add filename
- strcat(outfile,"."); // 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,"w");
- if (pf != NULL) {
- fprintf(pf,"\f\n-%s ║ %-.60s\n",
- strnblk(ac,2,FONT3,LINE1),ca->parea->adesc);
- fprintf(pf,"-%s ║ Available: %u files (%lu.%lu MB)\n",
- strnblk(ac,2,FONT3,LINE2),k,
- (ab_count+52428L)/1048576L, // rounded to 100K
- ((ab_count+52429L)/104857L)%10); // 100K fraction
- fprintf(pf,"-%s ║",
- strnblk(ac,2,FONT3,LINE3));
- if (lp[P_FIL].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%-.39s\n",HS,HS);
- if (lp[P_FIL].incl_fspec != NULL)
- file_incl(pf,lp[P_FIL].incl_fspec); // insert user-'logo'
- fprintf(pf," %s %s %s %s\n",FN,SZ,DT,DS);
- fprintf(pf,"-%-.11s %-.7s %-.8s %-.25s%-.23s\n",HS,HS,HS,HS,HS);
- }
- else
- printf(OPEN_FAIL,outfile);
- } // endif
- if (pf != NULL) { // check for open file
- if (ca->priv <= r_priv) { // specified reporting level
- if (ca->priv > c_priv) { // higher priv group within area
- c_priv = ca->priv; // set new
- fprintf(pf,"%c%c\n",'\20',priv_name[ca->priv-TWIT][0]);
- fprintf(pf,"- Following files are classified %s:\n",
- priv_name[ca->priv-TWIT]);
- }
- fprintf(pf,"%-12.12s %-s\n",
- ca->fname, // name
- ca->fdesc); // description
- } // endif
- } // endif
- } // endfor
- if (pf != NULL) // end of last FILES.BBS
- fclose(pf); // finished with FILES.bbs file
- } // end
-
-