home *** CD-ROM | disk | FTP | other *** search
- /* XMSG Message utility program for XBBS */
- /* Copyright (c) 1989/90 by M. Kimes...all rights reserved */
-
- /* NOTE: This doesn't share yet... */
-
- #include "msgg.h"
- #include "stdlib.h"
-
- void cdecl deinit(void);
- int pascal free_buf(char bufnum);
- char * pascal lstrip(char *a);
- char * pascal rstrip(char *a);
- char * pascal stripcr (char *a);
- int pascal set_buf (FILE *fp,char bufnum);
- int pascal free_bufs (void);
- void pascal kill_junk (word number1);
- void pascal readconfig(void);
- void pascal domsg(word,char,char);
- int pascal checkfile(char *);
- void pascal trim(word,word);
- void pascal days(word,word);
- ulong pascal diffdays(struct date *);
- int cdecl breakhandler(void);
- char * pascal stristr (char *t, char *s);
- char * pascal unpack_msg (char **hold);
- char * pascal pack_msg (char *hold,struct _xmsg *msg);
-
- struct ffblk f;
- struct _config conf;
- unsigned int huge *lastarray=NULL;
- char killbackups;
- char dontanalyze=1;
- char dontpack=0;
- char didbreak=0;
- struct _xmsg msg;
- char messpath[80]="";
- char il[256];
- char argarray[12][128];
- char fromname[36];
- char toname[36];
- char subj[64];
- char partial;
- char matchany;
- char verbose=0;
- word compress_size;
- char uncompress;
- word textsize;
- word codesize;
-
- #define NUMBUFS 5
-
- char *buf[NUMBUFS]={NULL,NULL,NULL,NULL,NULL};
-
- #define MYBUFSIZE 16384
-
- extern unsigned _Cdecl _stklen = 6144; /* Stack length */
-
-
-
-
- void cdecl main (int argc,char *argv[]) {
-
- FILE *fp;
- word register x;
- word register y;
- word number1;
- word number2;
- word numdays=0;
- word buffer=0;
- char private=0;
- word trimto=0;
- char tempstring[30]="";
- char mainarg;
- char *p;
- char templine[256]="";
-
- fprintf(stderr,"\n\n\x1b[0;1;37mXMSG (XBBS message base handler) copyright (c) 1989/90 by M. Kimes\n");
- fprintf(stderr,"Compiled: %s %s",__DATE__,__TIME__);
-
- *conf.messpath=0;
- conf.nolmrs=0;
- readconfig();
- if(conf.nolmrs) {
- lastarray=(unsigned int huge*)malloc(conf.nolmrs * sizeof(word));
- if (lastarray==NULL) {
- printf("\nOOM for LMRs\n");
- exit(1);
- }
- }
- ctrlbrk(breakhandler);
- atexit(deinit);
- strncpy(messpath,conf.messpath,79);
- messpath[79]=0;
-
- if(argc<2) goto BadArgs;
- if(toupper(argv[1][1])=='A') {
- if((fp=fopen(&argv[1][2],"rt"))==NULL) {
- printf("\nUnable to open action file %s\n",&argv[1][2]);
- goto BadArgs;
- }
- goto StartHere;
- }
- if (argc<4) goto BadArgs;
- number1=(word)atol(argv[2]);
- number2=(word)atol(argv[3]);
-
- for (x=0;x<argc;x++) {
- strupr(argv[x]);
- }
-
- if (!strcmp(argv[1],"-P")) {
- if (argc>4) {
- x=4;
- goto StartHere;
- }
- }
- if (!strcmp(argv[1],"-D")) {
- if (argc<5) goto BadArgs;
- numdays=(word)atol(argv[4]);
- if (!numdays) goto BadArgs;
- if (argc>5) {
- x=5;
- goto StartHere;
- }
- }
- if (!strcmp(argv[1],"-T")) {
- if (argc<5) goto BadArgs;
- trimto=(word)atol(argv[4]);
- if (!trimto) goto BadArgs;
- if (argc>5) {
- x=5;
- goto StartHere;
- }
- }
- if (!strcmp(argv[1],"-R")) {
- if (argc>4) {
- x=4;
- if (!strcmp(argv[4],"PRIVATE")) {
- private=1;
- x=5;
- }
- goto StartHere;
- }
- }
- if (!strcmp(argv[1],"-K")) {
- if(argc>4) {
- x=4;
- goto StartHere;
- }
- }
- mainarg=toupper(argv[1][1]);
- goto DoIt;
-
-
- BadArgs:
-
- if (argc>1) {
- fprintf(stderr,"\n\x7 Error in command line: `");
- for (x=1;x<argc;x++) {
- fprintf(stderr,"%s ",argv[x]);
- }
- fprintf(stderr,"'\n");
- }
- fprintf(stderr,"\nUsages:\n"
- "\nXMSG -A<actionfile> Performs commands listed in <actionfile>"
- "\nXMSG -P [LoBd#] [HiBd#] (options) Packs out deleted messages"
- "\nXMSG -T [LoBd#] [HiBd#] [#mess] (options) Trim to specified #"
- "\nXMSG -D [LoBd#] [HiBd#] [#days] (options) Delete older than # days"
- "\nXMSG -R [LoBd#] [HiBd#] (PRIVATE) (options) Deletes received messages"
- "\nXMSG -K [LoBd#] [HiBd#] (options) Kills junk msgs by (option) criteria"
- "\n\nNote: when passing an argument, like the F option below, that requires"
- "\ntwo words as one argument, use quotes to surround both the option and"
- "\nits following argument, like XMSG -K 30 30 \"FHector Plasmic\"\n"
- "\n[Any Key]: ");
- getch();
- fprintf(stderr,"\r\x1b[K"
- "\n Options (separated by a space if more than one used):\n"
- "B (delete backups)\n"
- "V (verify deleted messages present before packing)\n"
- "M<Drive:\\Path\\> (alternate message base path)\n"
- "N<#LMRs> (Number of LMR pointers (must match w/ HeadEdit.CFG))\n"
- "D (don't pack this pass--Valid for -T, -K and -D)\n"
- "H<buffer> (if board(s) exceed this number, packing will take place to [#mess])\n"
- "F<fromname> (-Kill Junk criterion)\n"
- "T<toname> (-Kill Junk criterion)\n"
- "S<subject> (-Kill Junk criterion)\n"
- "P (partial subject match causes Junk to be -Killed)\n"
- "! (provide verbose info)\n"
- "C<#bytes> (compress while packing if msg>#bytes)\n"
- "U (uncompress while packing)\n"
- "A (any match (F, T or S) causes Junk to be -Killed)\n"
- "\nActionfile lines are command lines without the leading - on the first argument.\n"
- "There should be one 'command line' per line terminated by cr/lf.\n"
- "Lines beginning with ; are comments.\n"
- "\nXMSG is sensitive to the order of its arguments.\n");
- exit(2);
-
- StartHere:
-
- mainarg=toupper(argv[1][1]);
- if(toupper(argv[1][1])=='A') {
- numdays=0;
- trimto=0;
- private=0;
- if(!fgets(il,256,fp)) {
- fclose(fp);
- fprintf(stderr,"\nXMSG Action file complete.\n");
- exit(0);
- }
- il[255]=0;
- strcpy(templine,stripcr(il));
- if(il[strlen(il)-1]=='\n') il[strlen(il)-1]=0;
- if(*il==0 || *il==';') goto StartHere;
- p=strtok(il," ");
- x=0;
- while(p) {
- strcpy(argarray[x],strupr(p));
- *argarray[x+1]=0;
- x++;
- p=strtok(0," ");
- }
- argc=x;
- mainarg=toupper(*argarray[0]);
- number1=(word)atol(argarray[1]);
- number2=(word)atol(argarray[2]);
- if (mainarg=='K') {
- if(argc>3) {
- x=3;
- goto ParseOpts;
- }
- }
- if (mainarg=='P') {
- if (argc>3) {
- x=3;
- goto ParseOpts;
- }
- }
- if (mainarg=='D') {
- if (argc<4) goto BadLine;
- numdays=(word)atol(argarray[3]);
- if (!numdays) goto BadLine;
- if (argc>4) {
- x=4;
- goto ParseOpts;
- }
- }
- if (mainarg=='T') {
- if (argc<4) goto BadLine;
- trimto=(word)atol(argarray[3]);
- if (!trimto) goto BadLine;
- if (argc>4) {
- x=4;
- goto ParseOpts;
- }
- }
- if (mainarg=='R') {
- if (argc>3) {
- x=3;
- if (!strcmp(argarray[3],"PRIVATE")) {
- private++;
- x=4;
- }
- goto ParseOpts;
- }
- }
- BadLine:
- fprintf(stderr,"\nUnknown action line %s\n",il);
- goto StartHere;
- }
- else {
- strcpy(argarray[0],&argv[1][1]);
- for(y=1;y<argc;y++) {
- strcpy(argarray[y],argv[y+1]);
- }
- argc--;
- x--;
- }
-
- ParseOpts:
- killbackups=0;
- dontanalyze=1;
- dontpack=0;
- buffer=0;
- *fromname=0;
- *toname=0;
- *subj=0;
- partial=0;
- matchany=0;
- compress_size=0;
- uncompress=0;
- for (;x<argc;x++) {
- switch ((int)toupper(*argarray[x])) {
- case 'C': compress_size=(word)atol(&argarray[x][1]);
- if(compress_size<1024)compress_size=1024;
- uncompress=0;
- break;
- case 'U': uncompress=1;
- compress_size=0;
- break;
- case 'B': killbackups=1;
- break;
- case 'V': dontanalyze=0;
- break;
- case 'M': strncpy(messpath,&argarray[x][1],79);
- messpath[79]=0;
- if(messpath[strlen(messpath)-1]!='\\') strcat(messpath,"\\");
- break;
- case 'N': if(lastarray==NULL) {
- conf.nolmrs=(word)atol(&argarray[x][1]);
- lastarray=(unsigned int huge*)malloc(conf.nolmrs * sizeof(word));
- if (lastarray==NULL) {
- if(!conf.nolmrs) fprintf(stderr,"\nGotta have some LMRs\n");
- else fprintf(stderr,"\nOOM for LMRs\n");
- exit(1);
- }
- }
- else {
- fprintf(stderr,"\n\x1b[0;2;31m Respecification of # LMRs ignored\n"
- "Rerun with separate action file/command line to respecify\n"
- "Note: CONFIG.BBS setting always overrides if present.\n");
- }
- break;
- case 'D': dontpack=1;
- break;
- case 'H': buffer=(word)atol(&argarray[x][1]);
- break;
- case 'F': strncpy(fromname,&argarray[x][1],36);
- fromname[35]=0;
- break;
- case 'T': strncpy(toname,&argarray[x][1],36);
- toname[35]=0;
- break;
- case 'S': strncpy(subj,&argarray[x][1],64);
- subj[63]=0;
- break;
- case 'P': partial=1;
- break;
- case 'A': matchany=1;
- break;
- case '!': verbose=1;
- break;
- default: fprintf(stderr,"\n\x7Never heard of `%s'\n",argarray[x]);
- break;
- }
- }
-
- if(uncompress && !dontpack) {
- printf("\n\x1b[0;1;31m Uncompressing msgs...");
- }
- if (compress_size && !dontpack) {
- printf("\n\x1b[0;1;31m Compressing msgs of %u bytes or larger...",compress_size);
- }
- if (killbackups)
- printf("\n\x1b[0;1;31m Killing backups...");
- if (!dontanalyze)
- printf("\n\x1b[0;1;36m Checking for deleted messages before packing...");
- if(dontpack) {
- if(mainarg=='K' || mainarg=='T' || mainarg=='D') printf("\n\x1b[0;1;36m Not packing this pass...");
- else fprintf(stderr,"\n\x1b[0;2;31mD(on't pack) not valid for -%c...ignored...",mainarg);
- }
- if((*fromname || *toname || *subj) && mainarg!='K') {
- fprintf(stderr,"\n\x1b[0;2;31mJunk killing fields not valid for -%c...ignored...",mainarg);
- }
- if(mainarg=='K' && (!*fromname && !*toname && !subj)) {
- fprintf(stderr,"\n\x1b[0;1;31mNo junk fields to check...");
- goto StartHere;
- }
- if(buffer) {
- if(mainarg=='T') printf("\n\x1b[0;1;36m Won't trim if under %u msgs...",buffer);
- else fprintf(stderr,"\n\x1b[0;2;31mH not valid for -%c...ignored...",mainarg);
- }
-
- if(verbose && *templine) printf("\nAction line: `%s'\n",templine);
-
- if(*messpath && conf.nolmrs) goto DoIt;
- else {
- fprintf(stderr,"\n\nYou must pass M and N options if you don't have a valid\n"
- "XBBS CONFIG.BBS in the default directory!\n\n");
- if(toupper(argv[1][1])!='A') goto BadArgs;
- goto StartHere;
- }
-
- DoIt:
-
- if (number2<number1) {
- fprintf(stderr,"\nHi/low conflict: High area %u, low area %u\n",number1,number2);
- if(toupper(argv[1][1])!='A') goto BadArgs;
- goto StartHere;
- }
-
- switch ((int)mainarg) {
- case 'P': printf("\nPacking boards #%u to %u...\n",number1,number2);
- for (x=number1;x<number2+1;x++) {
- domsg(x, 0, 0);
- if (didbreak) break;
- }
- break;
- case 'D': printf("\nDeleting messages in boards #%u to %u older than %u days...\n",number1,number2,numdays);
- for (x=number1;x<number2+1;x++) {
- days(x, numdays);
- if (didbreak) break;
- }
- break;
- case 'T': printf("\nTrimming boards #%u to %u to %u messages...\n",number1,number2,trimto);
- for (x=number1;x<number2+1;x++) {
- if(buffer) {
-
- char filename[133];
-
- sprintf(filename,"%sXDATA.%03x",messpath,x);
- if(!findfirst(filename,&f,0)) {
- if ((word)(f.ff_fsize/(long)sizeof(struct _xmsg))<buffer) {
- printf("\r\x1b[KSkipping #%u this time (%u msgs)\n",x,(word)(f.ff_fsize/(long)sizeof(struct _xmsg)));
- continue;
- }
- }
- }
- trim(x, trimto);
- if (didbreak) break;
- }
- break;
- case 'R': if (private) strcpy(tempstring,"PRIVATE");
- else strcpy(tempstring,"");
- printf("\nPacking out received %s messages in boards #%u to %u...\n",tempstring,number1,number2);
- for (x=number1;x<number2+1;x++) {
- domsg(x,1,private);
- if (didbreak) break;
- }
- break;
- case 'K': printf("\nKilling junk messages in boards #%u to %u",number1,number2);
- if(verbose) printf("\n From: `%s'\nTo: `%s'\nSubj: `%s'",fromname,toname,subj);
- for(x=number1;x<number2+1;x++) {
- kill_junk(number1);
- if(didbreak) break;
- }
- break;
- }
- if (didbreak) {
- fprintf(stderr,"\nStopping in response to user break.\n");
- fclose(fp);
- exit(0);
- }
- printf("\n");
-
- if(toupper(argv[1][1])!='A') {
- fclose(fp);
- exit(0);
- }
- goto StartHere;
- }
-
-
- void cdecl deinit (void) {
-
- fcloseall();
- free_bufs();
- }
-
-
- int cdecl breakhandler (void) {
-
- didbreak=1;
- fprintf(stderr,"\nOk, I'll stop as soon as it's safe. Please wait...\n");
- return 1;
-
- }
-
-
- void pascal trim (word number1,word number2) {
-
- word register x;
- char newfile[124];
- struct _xmsg msg;
- FILE *nf;
- ulong sizefile;
- struct date dos_date;
- struct ffblk ft;
- char atleastone=0;
- long pos;
-
- sprintf(newfile,"%sXDATA.%03x",messpath,number1);
-
- if (checkfile(newfile)!=0) {
- printf("\r\x1b[KNo messages in board #%u.",number1);
- return;
- }
- sizefile=f.ff_fsize;
-
- if(!(nf=fopen(newfile,"r+b"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message base.\x1b[0;2;37m\n");
- return;
- }
- if ((word)(sizefile/(long)sizeof(struct _xmsg))<=number2) {
- printf("\r\x1b[K%u message(s) in board #%u...trimming unnecessary.",(word)(sizefile/sizeof(msg)),number1);
- fclose(nf);
- return;
- }
- set_buf(nf,0);
- printf("\r\x1b[KTrimming...");
-
- x=0;
- while (x<((word)((sizefile/(long)sizeof(struct _xmsg))-(long)number2))) {
-
- int temp;
-
- pos=ftell(nf);
- fseek(nf,0L,SEEK_CUR);
- temp=fread (&msg,(int)sizeof(struct _xmsg),1,nf);
- if (ferror(nf) || temp!=1) {
- perror("");
- break;
- }
- if (!(msg.m_attr & MSGKEEP)) {
- msg.m_attr=(msg.m_attr | ((word)MSGDELETED));
- atleastone=1;
- fseek(nf,pos,SEEK_SET);
- fwrite(&msg,sizeof(struct _xmsg),1,nf);
- }
- x++;
- }
- fclose(nf);
- free_buf(0);
- if(atleastone) {
- dontanalyze=1;
- if(!dontpack)domsg(number1,0,0);
- }
- else printf("\r\x1b[KMsgs marked KEEP circumvent trimming...");
- }
-
-
- void pascal kill_junk (word number1) {
-
- word register x;
- char newfile[124];
- struct _xmsg msg;
- FILE *nf;
- ulong sizefile;
- struct date dos_date;
- struct ffblk ft;
- char atleastone=0;
- long pos;
- word hit=0;
- word miss=0;
-
- sprintf(newfile,"%sXDATA.%03x",messpath,number1);
-
- if (checkfile(newfile)!=0) {
- printf("\r\x1b[KNo messages in board #%u.",number1);
- return;
- }
- sizefile=f.ff_fsize;
-
- if(!(nf=fopen(newfile,"r+b"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message base.\x1b[0;2;37m\n");
- return;
- }
- printf("\r\x1b[KKilling junk...");
- set_buf(nf,0);
-
- rewind(nf);
- x=0;
- while (x<((word)((sizefile/(long)sizeof(struct _xmsg))))) {
-
- int temp;
-
- pos=ftell(nf);
- fseek(nf,0L,SEEK_CUR);
- temp=fread (&msg,(int)sizeof(struct _xmsg),1,nf);
- if (ferror(nf) || temp!=1) {
- perror("");
- break;
- }
-
- hit=miss=0;
- if(*fromname) {
- if(!stricmp(fromname,msg.from)) hit++;
- else miss++;
- }
- if(*toname) {
- if(!stricmp(toname,msg.to)) hit++;
- else miss++;
- }
- if(*subj) {
- if(!partial) {
- if(!stricmp(subj,msg.subj)) hit++;
- else miss++;
- }
- else {
- if(!stristr(msg.subj,subj)) hit++;
- else miss++;
- }
- }
-
- if((matchany && hit) || !miss) {
- if (!(msg.m_attr & MSGKEEP)) {
- msg.m_attr=(msg.m_attr | ((word)MSGDELETED));
- atleastone=1;
- fseek(nf,pos,SEEK_SET);
- fwrite(&msg,sizeof(struct _xmsg),1,nf);
- if(verbose) {
- printf("\n Kill: #%u\nFrom: `%s'\nTo: `%s'\nSubj: `%s'",msg.from,msg.to,msg.subj);
- }
- }
- }
-
- x++;
- }
-
- fclose(nf);
- free_buf(0);
- if(atleastone) {
- dontanalyze=1;
- if(!dontpack)domsg(number1,0,0);
- }
- }
-
-
-
- void pascal days (word number1,word number2) {
-
- word register x;
- char newfile[124];
- struct _xmsg msg;
- FILE *nf;
- ulong sizefile;
- struct date dos_date;
- struct ffblk ft;
- char gotone=0;
- long pos;
-
- sprintf(newfile,"%sXDATA.%03x",messpath,number1);
-
- if (checkfile(newfile)!=0) {
- printf("\r\x1b[KNo messages in board #%u.",number1);
- return;
- }
- sizefile=f.ff_fsize;
-
- if(!(nf=fopen(newfile,"r+b"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message base.\x1b[0;2;37m\n");
- fclose(nf);
- return;
- }
- rewind(nf);
- set_buf(nf,0);
-
- printf("\r\x1b[KPurging...");
-
- for(x=0;x<(word)(sizefile/(long)sizeof(struct _xmsg));x++) {
-
- int temp;
-
- pos=ftell(nf);
- fseek(nf,0L,SEEK_CUR);
- temp=fread (&msg,sizeof(struct _xmsg),1,nf);
- if (ferror(nf) || temp!=1) {
- perror("");
- break;
- }
- dos_date.da_year=(int)msg.indate[0]+1989;
- dos_date.da_mon=(int)msg.indate[1];
- dos_date.da_day=(int)msg.indate[2];
- if ((word)diffdays(&dos_date)>number2) {
- if (!(msg.m_attr & MSGKEEP)) {
- msg.m_attr=(msg.m_attr | ((word)MSGDELETED));
- fseek(nf,pos,SEEK_SET);
- fwrite(&msg,sizeof(struct _xmsg),1,nf);
- gotone=1;
- }
- }
- }
-
- fclose(nf);
- free_buf(0);
- dontanalyze=1;
- if (gotone) {
- if(!dontpack) domsg(number1,0,0);
- }
- else printf("\r\x1b[KDidn't find any old ones...");
-
- }
-
-
-
- void pascal domsg (number,received,private)
-
- word number;
- char received;
- char private;
-
- {
-
- word register x;
- char buffer[133];
- char textname[129];
- char filename[129];
- char newtext[129];
- char newfile[129];
- char msgname[129];
- char noback=0;
- char packit=0;
- word lastlast;
- struct _xmsg msg;
- word wassize;
- word huge *lastread;
- word huge *holdlast;
- FILE *fp;
- FILE *pf;
- FILE *nf;
- FILE *fn;
- FILE *us;
- word register z;
- char *message;
- ulong sizefile;
- struct date dos_date;
- struct ffblk ft;
- long pos;
- ulong laststart,isstart; /* Used to prevent carbons from expanding */
- word lastlen,islen; /* the msg text for each header */
- struct dfree drivefree;
-
- isstart=laststart=0;
- islen=lastlen=0;
-
- sprintf(filename,"%sXDBAK.%03x",messpath,number);
- sprintf(textname,"%sXTBAK.%03x",messpath,number);
- sprintf(newfile,"%sXDATA.%03x",messpath,number);
- sprintf(newtext,"%sXTEXT.%03x",messpath,number);
-
- if (findfirst(newfile,&f,0)) {
- printf("\r\x1b[KNo messages in board #%u.",number);
- return;
- }
-
- unlink(filename); /* Get rid of backups before checking drive space */
- unlink(textname);
-
- getdfree((toupper(*messpath)-'@'),&drivefree);
- if (((long)drivefree.df_avail*((long)drivefree.df_bsec*(long)drivefree.df_sclus)) < f.ff_fsize) {
- printf("\nNot enough free drive space to safely pack area #%u.\n",number);
- return;
- }
-
- sizefile=f.ff_fsize/(long)sizeof(struct _xmsg);
- wassize=(word)sizefile;
-
- if (!dontanalyze) {
-
- if(!(nf=fopen(newfile,"rb"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message base.\x1b[0;2;37m\n");
- return;
- }
-
- if(verbose) {
- printf("\nArea %u contains %u messages before packing.\n",number,sizefile);
- }
-
- set_buf(nf,0);
- printf("\r\x1b[KAnalyzing #%u...",number);
- rewind(nf);
- for(x=0;x<(word)sizefile;x++) {
- fread (&msg,sizeof(struct _xmsg),1,nf);
- if ((msg.m_attr & MSGDELETED)!=0) {
- packit++;
- break;
- }
- if (msg.m_attr & MSGKEEP) continue;
- if (((msg.attr & MSGREAD) && received && !private) || (((msg.attr & MSGPRIVATE) && private && received && (msg.attr & MSGREAD)))) {
- packit++;
- break;
- }
- }
- fclose(nf);
- free_buf(0);
-
- if (!packit) {
- printf("\r\x1b[K#%u doesn't need packing.",number);
- return;
- }
- }
-
- remove(filename);
- remove(textname);
- rename(newfile,filename);
- rename(newtext,textname);
-
- if(!(fp=fopen(filename,"rb"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message base.\x1b[0;2;37m\n");
- return;
- }
- if(!(pf=fopen(textname,"rb"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message file.\x1b[0;2;37m\n");
- fclose(fp);
- return;
- }
- if(!(nf=fopen(newfile,"ab"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message base.\x1b[0;2;37m\n");
- fclose(fp);
- fclose(pf);
- return;
- }
- if(!(fn=fopen(newtext,"ab"))) {
- fprintf(stderr,"\n\x1b[0;1;31mUnable to open message file.\x1b[0;2;37m\n");
- fclose(fp);
- fclose(pf);
- fclose(nf);
- return;
- }
-
- holdlast=(word huge *)farmalloc((long)(sizeof(word)*(word)sizefile+1L));
- if (holdlast==NULL) {
- fprintf(stderr,"\nOut of memory.\n");
- exit(3);
- }
- lastread=holdlast;
-
- printf("\r\x1b[K%u message(s) in board #%u. Packing...",(word)sizefile,number);
-
- set_buf(fp,0);
- set_buf(pf,1);
- set_buf(nf,2);
- set_buf(fn,3);
- for(x=0;x<(word)sizefile;x++) {
- fread (&msg,sizeof(struct _xmsg),1,fp);
- if (!(msg.m_attr & MSGKEEP)) if (((msg.attr & MSGREAD) && received && !private) || (((msg.attr & MSGPRIVATE) && private && received && (msg.attr & MSGREAD)))) continue;
- if(!msg.length)continue;
- if ((msg.m_attr & MSGDELETED)==0) {
- if(msg.length!=lastlen || msg.start!=laststart) {
- laststart=msg.start;
- lastlen=msg.length;
- message=calloc(msg.length+1,sizeof(char));
- if (message==NULL) {
- fprintf(stderr,"\nAllocation error...aborting...\n");
- exit(2);
- }
-
- fseek(pf,msg.start,SEEK_SET);
- fread(message,msg.length,1,pf);
- msg.start=ftell(fn);
-
- if(!(msg.m_attr & MSGTREATED) && !(msg.m_attr & MSGPACKED)) {
-
- char *tempo;
-
- tempo=message;
- while (*tempo) { /* Strip linefeeds and soft cr's FAST */
- if(*tempo=='\x8d' || *tempo=='\n') {
- if(*tempo=='\n')
- memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)message));
- else {
- if(*(tempo-1)==' ' && tempo>message)
- memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)message));
- else *tempo=' ';
- }
- }
- tempo++;
- }
- msg.m_attr = (msg.m_attr | MSGTREATED); /* Reads quicker */
- }
-
- if(compress_size) {
- if(!(msg.m_attr & MSGPACKED) && (strlen(message)>compress_size)) {
-
- char *tempo;
-
- tempo=message;
- if(msg.length>65100) {
- msg.length=65100;
- message[65099]=0;
- msg.attr = msg.attr | MSGORPHAN;
- }
- message=pack_msg(message,&msg);
- if(!message) {
- message=tempo;
- msg.attr = msg.attr | MSGORPHAN;
- }
- else {
- free(tempo);
- msg.m_attr = msg.m_attr | MSGPACKED;
- }
- }
- }
- else if(uncompress) {
- if(msg.m_attr & MSGPACKED) {
- message=unpack_msg(&message);
- if(message==NULL) {
- message=calloc(msg.length+1,sizeof(char));
- if (message==NULL) {
- fprintf(stderr,"\nAllocation error...aborting...\n");
- exit(2);
- }
- fseek(pf,msg.start,SEEK_SET);
- fread(message,msg.length,1,pf);
- msg.start=ftell(fn);
- msg.attr = msg.attr | MSGORPHAN;
- }
- else {
- msg.length=strlen(message)+1;
- msg.m_attr = msg.m_attr & (~MSGPACKED);
- }
- }
- }
-
- if(message) {
- fwrite(message,msg.length,1,fn);
- free(message);
- }
- islen=msg.length;
- isstart=msg.start;
- }
- else {
- msg.length=islen;
- msg.start=isstart;
- }
- fwrite(&msg,sizeof(struct _xmsg),1,nf);
- *lastread=x+1;
- lastread++;
- }
- if (feof(fp)!=0) break;
- }
-
- if (!noback) for (x=0;x<10;x++) printf(BACKSPACE);
- else printf("\r\x1b[K");
-
- *lastread=0;
-
- fclose(nf);
- free_buf(2);
-
- if(findfirst(newfile,&f,0)) sizefile=0;
- else sizefile=f.ff_fsize/(long)sizeof(struct _xmsg);
-
- lastread=holdlast;
-
- if (number<(conf.nolmrs+1) && (word)sizefile<wassize) {
- printf("\r\x1b[KAdjusting Last Message Pointers... ");
- sprintf(buffer,"%sLASTREAD.BBS",messpath);
- if(findfirst(buffer,&ft,0)) {
- fprintf(stderr,"\nCan't find %s\n",buffer);
- }
- else {
- if ((us=fopen(buffer,"r+b"))==NULL) {
- printf("\nUnable to open %s\n",buffer);
- }
- else {
- rewind(us);
- set_buf(us,4);
- for (x=0;x<(word)(ft.ff_fsize/(long)(conf.nolmrs*sizeof(word)));x++) {
- printf("\b\b\b\b\b%-5u",x+1);
- lastread=holdlast;
- z=(word)sizefile;
- pos=ftell(us);
- if(fseek(us,0L,SEEK_CUR)) perror("SEEK1");
- if(feof(us)) {
- fprintf(stderr,"\nLMR mismatch USERS.BBS -> LASTREAD.BBS\nRun XUSER and pack your User Database\n");
- break;
- }
- if (fread ((void *)lastarray,(conf.nolmrs * sizeof(word)),1,us)!=1) {
- perror("READ");
- continue;
- }
- if (!lastarray[number-1]) continue;
- if (!sizefile) {
- lastarray[number-1]=0;
- if (fseek(us,(long)pos,SEEK_SET)) perror("SEEK2");
- if (fwrite((void *)lastarray,(conf.nolmrs * sizeof(word)),1,us)!=1) perror("WRITE");
- }
- else if(lastarray[number-1]>wassize) {
- lastarray[number-1]=(word)sizefile;
- if (fseek(us,(long)pos,SEEK_SET)) perror("SEEK2");
- if (fwrite((void *)lastarray,(conf.nolmrs * sizeof(word)),1,us)!=1) perror("WRITE");
- }
- else {
- lastlast=lastarray[number-1];
- while(z) {
- if (lastread[z]<=lastarray[number-1] && lastread[z]!=0) {
- lastarray[number-1]=(z+1);
- break;
- }
- z--;
- }
- if(!z) lastarray[number-1]=0;
- if(lastarray[number-1]!=lastlast) {
- if (fseek(us,(long)pos,SEEK_SET)) perror("SEEK2");
- if (fwrite((void *)lastarray,(conf.nolmrs * sizeof(word)),1,us)!=1) perror("WRITE");
- }
- }
- }
- }
- printf("\r\x1b[K");
- fclose(us);
- free_buf(4);
- }
- }
-
- Alldone:
-
- fclose(fp);
- fclose(pf);
- fclose(fn);
- free_buf(0);
- free_buf(1);
- free_buf(3);
-
- if (findfirst(newfile,&f,0)) f.ff_fsize=0;
- printf("\r\x1b[K%u message(s) in board #%u after packing.",(word)(f.ff_fsize/sizeof(msg)),number);
- if (killbackups!=0) {
- remove(filename);
- remove(textname);
- }
- if(verbose) printf("\n");
- if (f.ff_fsize==0) {
- printf("\r\x1b[K Deleting empty message base.");
- remove(newfile);
- remove(newtext);
- }
- farfree((word far *)holdlast);
-
- }
-
-
-
- int pascal checkfile (char *a) {
-
- return(findfirst(a,&f,0));
-
- }
-
-
- void pascal readconfig (void) {
-
- FILE *fp;
- struct ffblk f;
-
- if(findfirst("config.bbs",&f,0)) {
- fprintf(stderr,"\n'CONFIG.BBS' not found\n");
- return;
- }
- if(!(fp=fopen("config.bbs","rb"))) {
- perror("\nCONFIG.BBS ERROR");
- exit(2);
- }
- rewind(fp);
- fread(&conf,sizeof(conf),1,fp);
- fclose(fp);
- }
-
-
-
- ulong pascal diffdays (struct date *then) { /* Duh...but seems to work */
-
- ulong numdays=0;
- ulong today=0;
- int register x;
- struct date dos_date;
- char month[13]={
- 0,31,28,31,30,31,30,31,31,30,31,30,31
- };
-
- getdate(&dos_date);
- for (x=1987;x<dos_date.da_year;x++) numdays=numdays+365;
- for (x=1;x<dos_date.da_mon;x++) numdays=numdays+month[x];
- today=numdays+dos_date.da_day;
- numdays=0;
- for (x=1987;x<then->da_year;x++) numdays=numdays+365;
- for (x=1;x<then->da_mon;x++) numdays=numdays+month[x];
- numdays=numdays+then->da_day;
- return (today-numdays);
-
- }
-
-
- char * pascal stristr (char *t, char *s) {
-
- char *t1;
- char *s1;
-
- while(*t) {
- t1=t;
- s1=s;
- while(*s1) {
- if (toupper(*s1)!=toupper(*t)) break;
- else {
- s1++;
- t++;
- }
- }
- if (!*s1) return t1;
- t=t1+1;
- }
- return NULL;
- }
-
-
- char * pascal stripcr (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && (a[x-1]=='\n' || a[x-1]=='\r')) a[--x]=0;
- return a;
-
- }
-
-
-
- char * pascal rstrip (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && a && a[x-1]==' ') a[--x]=0;
- return a;
- }
-
-
-
- char * pascal lstrip (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && *a==' ') memmove (a,(a+1),x--);
- return (a);
- }
-
-
- /* Tried this stuff, but it didn't seem to increase speed. */
-
-
- int pascal set_buf (FILE *fp,char bufnum) {
-
-
- /*
- if(bufnum>NUMBUFS-1) return 2;
- free_buf(bufnum);
- buf[bufnum]=(char *)malloc(MYBUFSIZE);
- if(!buf[bufnum]) return 1;
- if(setvbuf((FILE *)fp,(char *)buf[bufnum],(int)_IOFBF,(size_t)MYBUFSIZE)) printf("\nBuffer failure.\n");
- */
- return 0;
- }
-
-
- int pascal free_bufs () {
-
- return 0;
- /*
-
- char register x;
-
- for(x=0;x<NUMBUFS;x++) {
- free_buf(x);
- }
- return 0;
- */
- }
-
- int pascal free_buf (char bufnum) {
-
-
- /*
- if(bufnum>NUMBUFS-1) return 1;
- if(buf[bufnum]) {
- free(buf[bufnum]);
- buf[bufnum]=NULL;
- }
- */
- return 0;
- }