home *** CD-ROM | disk | FTP | other *** search
- /* MakeArc copyright (c) 1992 by M. Kimes -- All Rights Reserved */
- /* Version 3.02 You can use this freely. Check with me before */
- /* releasing modified executables or source, please (I'll probably */
- /* allow it). Exceptions: Strict translation to foreign languages */
- /* and ports to other platforms (non-MS/DOS) -- go for it. */
- /* Corrections, bug reports, etc. welcome. Flames ignored by a */
- /* master. */
-
- /* The only real change between 2.05 and 3.00 is that 3.00 compiles */
- /* under MSC 6.0a */
- /* The only change between 3.00 and 3.01 is the addition of the */
- /* DUFUS verb to satisfy know-nothing bitchers */
- /* 3.01 to 3.02 fixes real bug in attach messages */
-
- #include <time.h>
- #include <dos.h>
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <io.h>
- #include <fcntl.h>
- #include <ctype.h>
- #include <process.h>
- #include <string.h>
- #include <share.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
-
- typedef unsigned int _word;
-
- /* Message header */
-
- struct _msg {
- char from[36];
- char to[36];
- char subj[72];
- char date[20]; /* <--Did you notice the length of that? */
- _word times;
- _word dest;
- _word orig;
- _word cost;
- _word orig_net;
- _word dest_net;
- int msg_filler[4]; /* Differs by implementation; the heck with it */
- _word reply;
- _word attr;
- _word up;
- };
-
- /* Message attributes */
-
- #define MSGPRIVATE 0x0001
- #define MSGCRASH 0x0002
- #define MSGREAD 0x0004
- #define MSGSENT 0x0008
- #define MSGFILE 0x0010
- #define MSGFWD 0x0020
- #define MSGORPHAN 0x0040
- #define MSGKILL 0x0080
- #define MSGLOCAL 0x0100
- #define MSGXX1 0x0200
- #define MSGXX2 0x0400
- #define MSGFRQ 0x0800
- #define MSGRRQ 0x1000
- #define MSGCPT 0x2000
- #define MSGARQ 0x4000
- #define MSGURQ 0x8000
-
- /* Global flags and variables, w/ defaults */
-
- unsigned char msgattach=0; /* Make *.MSG attaches? */
- _word myzone=0; /* For our address */
- _word mynet=0; /* " */
- _word mynode=0; /* " */
- _word mypoint=0; /* " */
- char configfile[133]="MAKEARC.CFG"; /* Config file to read */
- char root[128]=""; /* 'Root' outbound dir */
- char outbound[133]=""; /* Extended outbound dir */
- char netdir[128]=""; /* Net msg directory if *.MSG attaches */
- char arccmd[133]=""; /* Default archive command */
- unsigned char alltype=0; /* Default mail type */
- unsigned char didbreak=0; /* CTRL-BREAK flag */
- char schedtag[128]=""; /* Schedule tag */
- _word lines=0; /* For debug info */
- unsigned char debug=0; /* debug on? */
- unsigned char more=0; /* more on? */
- unsigned char usingbink=0; /* Use BINKLEY.CFG? */
- _word rzone=0; /* For routing */
- _word rnet=0; /* " */
- _word rnode=0; /* " */
- _word rpoint=0; /* " */
- char dufus = 0; /* for idiots */
-
- /* Function definitions */
-
- char * _fastcall day_string(void);
- char _fastcall spawnit (char *a);
- char _fastcall check_4flo (_word zone,_word net,_word node,_word point);
- char * _fastcall stristr (char *t, char *s);
- void _cdecl deinit(void);
- void _fastcall say_error (long lastpos,FILE *fp);
- int _fastcall makearc (char *arcfile,char *pktfile,char *origpkt,char *outbound);
- _word _fastcall makeflo(_word zone,_word net,_word node,_word point,char *sendfile,char type);
- _word _fastcall makemessage (_word zone,_word net,_word node,_word point,char *sendfile,char type);
- void _fastcall next_name(char *);
- void _fastcall make_poll (char *line,long lastpos,FILE *fp);
- FILE * _fastcall analyze(char *);
- char * _fastcall arcname(_word,_word);
- char * _fastcall filename(_word,_word);
- char * _fastcall fidodate(void);
- char * _fastcall lstrip(char *);
- char * _fastcall rstrip(char *);
- char * _fastcall stripcr(char *);
- void _fastcall moveit (struct FILEFINDBUF *f, char *myoutbound, char *outbound, char type, char archive,_word net,_word node,_word fromzone);
- void _fastcall move_prep(char *line,long lastpos,FILE *fp);
- void _fastcall change_mail(char *line,long lastpos,FILE *fp);
- long _fastcall make_msgid(void);
- char * _fastcall find_sched(FILE *fp,char *schedtag,int wholefile);
- char * _fastcall skip_white(char *);
- char * _fastcall skip_nonwhite(char *);
- char * _fastcall to_delim(char *,char *);
-
- /* ID stuff */
-
- #define MAKEVER "3.02"
-
- #define PID_ID "MA 3.02"
-
- #define BETA yep
-
-
-
-
-
-
- void _cdecl main (int argc,char *argv[]) {
-
- FILE *fp;
- struct find_t f,d;
- time_t t,starttime;
- char s[133],s2[133],pktfile[133],arcfile[133],origpkt[13];
- _word hisnode,hisnet,hiszone=0,hispoint=0;
- char *p,*pp;
- char new,type=0,lastlevel=0;
- char temp[34];
- long t_counter=0,lastpos;
- char tempcmd[80]="";
- char doingnet,doingdomain,doingzone;
- int founddir,rc;
-
- /* Big, ugly main() function. What do you expect from an amateur ex-BASIC
- programmer, anyway? */
-
- starttime = time(NULL); /* For length-of-run timer */
-
- /* Display program title and copyright info */
-
- fprintf(stderr,"\n\nMAKEARC v%s %s %s copyright (c) 1990-92 by M. Kimes",
- MAKEVER,__DATE__,__TIME__);
-
- #ifdef BETA
- fprintf(stderr," -- Beta");
- #endif
-
- fprintf(stderr,"\n");
-
- /* Nothing on command line--let 'em know help is available. */
-
- if(argc == 1)
- fprintf(stderr,"I archive packets and make attaches for them. ? for help.\n");
-
- /* First arg is ? so give 'em the help and stop */
-
- if(argc > 1 && *argv[1] == '?') {
- fprintf(stderr,"\nGimme a config file, default MAKEARC.CFG. A schedule tag is optional.\n"
- "If environment variable MAKECFG is set, I'll use that value to find the config\n"
- "file instead. If MAKESCHD is set, I'll use that value for a schedule tag.\n"
- "Examples: (assumes environment variables not used)\n"
- "MAKEARC (defaults to MAKEARC.CFG, no schedule tag)\n"
- "MAKEARC ALTMAKE.CFG (defaults to no schedule tag)\n"
- "MAKEARC MAKEARC2.CFG MAILTIME (config file MAKEARC2.CFG, schedule tag MAILTIME)\n"
- "MAKEARC MAKEIT.CFG AFTERMAIL D (startup with debug on)\n"
- "MAKEARC MAKE2.CFG BEFOREMAIL M (startup with more info on)\n"
- "\nYou probably shouldn't use points *at all* when dealing with the outbound.\n"
- "You should not route Crash mail.\n\n"
- "In the configuration file, list the following:\n"
- "SCHED <any_text> (A schedule tag, not required unless you use them)\n"
- "ADDRESS <zone:net/node[.point]> (Your address--use point only if\n"
- " your mailer understands it)\n"
- "OUTBOUND <main outbound directory>\n"
- "NETDIR <netmail directory> (use with MSG below)\n"
- "MSG (means create *.MSG attaches instead of *.FLO attaches)\n"
- "FLO (opposite of MSG, default)\n"
- " [Any Key]");
- getch();
- fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b"
- "ARCCMD <default archive command>\n"
- "ALLTYPE <default mail type: Crash, Hold, etc.>\n"
- "ROUTE <address> (routes all following mail to <address> until\n"
- " next ROUTE command (ROUTE 0:0/0 cancels))\n"
- "DOMAIN <main outbound dir> <type> <arc cmd>\n"
- " (Do a pass through outbound directories. Arguments are optional.\n"
- " Defaults will be used if not present. Note that giving an outbound\n"
- " directory here performs an implicit OUTBOUND command)\n"
- "ZONE <zone#>: <mail type> <arc cmd> (Do a pass through <zone#>)\n"
- "NET <zone#>:<net#>/ <mail type> <arc cmd> (do a pass through <net#>)\n"
- "MOVE <zone#> <address> <mail type> (move mail from <zone#> to another)\n"
- "CHANGE <address> <mail type> (change all mail to <address> to <mail type>)\n"
-
- /*
- Commented this out; too much damn trouble.
- Code (doesn't work) is still there.
- */
-
-
- /*
- " (alternate: CHANGE ALL [<ZONE> <#>] <type> (change all mail to <type>)\n"
- */
-
- "POLL <address> [<password>] (force a call to <address> by creating *.CLO)\n"
- "SPAWN <string> (spawn <string>...use COMMAND.COM /c for batch files)\n"
- "IFERRORLEVEL <!<>=> <#> <command> (process <command> if last ERRORLEVEL\n"
- " from SPAWN command satisfies compare)\n"
- "<zone#>:<net#>/<node#> <mail type: Crash, Hold, etc.> <archive command>\n"
- " [Any Key]");
- getch();
- fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b"
- "END (means stop now and do pass through your zone)\n"
- "BREAK (means don't do pass through your zone--stop NOW)\n"
- "GOTO <schedtag> (jump to schedule tag <schedtag>)\n"
- "IFINTIME <hh:mm:ss> <hh:mm:ss> <command> (process <command> if in timeframe)\n"
- "IFDOW <#> <command> (process <command> if <#>=day of week (1-7 from Sunday))\n"
- "IFDOM <#> <command> (process <command> if <#>=day of month (1-31))\n"
- "IFMON <#> <command> (process <command> if <#>=month (1-12))\n"
- "DEBUG (means get verbose, show *everything*)\n"
- "MORE (means more info, but don't get totally ridiculous)\n"
- "DUFUS (aw, you're not one of THOSE, are you?)\n");
- exit(0);
- }
-
- /* Use command line arguments if available */
-
- if(argc > 1) strcpy(configfile,argv[1]);
- if(argc > 2) strcpy(schedtag,argv[2]);
- if(argc > 3 && toupper(*argv[3]) == 'D') debug = 1;
- if(argc > 3 && toupper(*argv[3]) == 'M') more = 1;
-
- /* Try to find our environment variables (overrides command line) */
-
- p = getenv("MAKECFG");
- if(*p && p) strcpy(configfile,getenv("MAKECFG"));
- p = getenv("MAKESCHD");
- if(*p && p) strcpy(schedtag,getenv("MAKESCHD"));
-
- if(_dos_findfirst(configfile,0,&f)) {
-
- /* Couldn't find configfile; look for BINKLEY environment variable
- and then BINKLEY.CFG */
-
- if(getenv("BINKLEY")) {
- strcpy(configfile,getenv("BINKLEY"));
- if(configfile[strlen(configfile) - 1] == '\\')
- configfile[strlen(configfile) - 1] = 0;
- strcat(configfile,"\\BINKLEY.CFG");
- }
- else strcpy(configfile,"BINKLEY.CFG");
- }
-
- if(stristr(configfile,"BINKLEY.CFG"))
- usingbink = 1; /* Look for APPLICATIONs */
-
- fp = analyze(configfile); /* Open file, find schedule tag, etc. */
-
- atexit(deinit); /* Removes marker file */
-
- fclose(fopen("MAKEARC.RUN","w")); /* Marker file; "I'm running!" */
-
- while(!feof(fp)) { /* Process config file--main loop */
- lastpos = ftell(fp);
- strcpy(outbound,root); /* Reset outbound variable */
- doingnet = doingzone = doingdomain = 0; /* Reset special condition flags */
- if(!hiszone) hiszone = myzone;
- if(!fgets(s,133,fp)) goto DoneWithFile;
- lines++; /* Line counter for error msgs */
- if(debug) printf("%u. %s",lines,s); /* Display line if debug on */
- if(p = (strchr(s,';'))) *p = 0; /* Lose trailing comments */
- stripcr(s); /* Lose cr/lf */
- lstrip(s); /* Lose leading spaces */
- rstrip(s); /* Lose trailing spaces */
- if(!*s || *s == ';') continue; /* Skip blank or comment lines */
- while(p = (strchr(s,'\t'))) *p = ' '; /* Get rid of tabs */
- lstrip(s); /* Strip extraneous spaces */
- rstrip(s);
- p = s;
-
- /* This label used to merge back into the stream after IFERRORLEVEL */
- /* Get over your goto aversion, willya? */
-
- AfterERRORLEVEL:
-
- if(!strnicmp(p,"OUTBOUND ",9) || !strnicmp(p,"HOLD ",5)) {
- if(toupper(*p) == 'O') p += 9; /* Main outbound directory */
- else p += 5;
- lstrip(p);
- while(pp = (strchr(p,'/'))) *pp = '\\'; /* Convert slashes to backslashes */
- strncpy(outbound,p,80);
- outbound[79] = 0;
- if(outbound[strlen(outbound) - 1] == '\\')
- outbound[strlen(outbound)-1]=0;
- strcpy(root,outbound);
- p = strrchr(root,'\\');
- if(p) {
- p++;
- printf("Current Domain: `%s'\n",p);
- }
- if(debug || more) printf("Outbound dir=`%s'\n",root);
- continue;
- }
-
- else if(!strnicmp(p,"NETDIR ",7) || !strnicmp(p,"NETMAIL ",8)) {
- if(toupper(p[7])=='L') p+=8; /* Net directory (w/ MSG) */
- else p+=7;
- lstrip(p);
- while(pp=(strchr(p,'/'))) *pp='\\'; /* Convert slashes to backslashes */
- strncpy(netdir,p,80);
- netdir[79]=0;
- if(netdir[strlen(netdir)-1]=='\\') netdir[strlen(netdir)-1]=0;
- if(debug || more)printf("Net dir=`%s'\n",netdir);
- continue;
- }
-
- else if(!strnicmp(p,"ADDRESS ",8)) { /* Our address */
- p+=8;
- lstrip(p);
- p=strtok(p,":");
- if(!p) {
- fprintf(stderr,"\nMissing Zone\n");
- say_error(lastpos,fp);
- continue;
- }
- myzone=(unsigned int)atol(p);
- if(!myzone) {
- fprintf(stderr,"\nZero Zone\n");
- say_error(lastpos,fp);
- continue;
- }
- p=strtok(0,"/");
- if(!p) {
- fprintf(stderr,"\nMissing Net\n");
- say_error(lastpos,fp);
- continue;
- }
- mynet=(unsigned int)atol(p);
- if(!mynet) {
- fprintf(stderr,"\nZero Net\n");
- say_error(lastpos,fp);
- continue;
- }
- p=strtok(0,".@ ");
- if(!p) {
- fprintf(stderr,"\nMissing Node\n");
- say_error(lastpos,fp);
- continue;
- }
- mynode=(unsigned int)atol(p);
- p=strtok(0,"@ ");
- if(!p) mypoint=0;
- else mypoint=(unsigned int)atol(p);
- if(debug || more) {
- if(mypoint)printf("Address=`%u:%u/%01u.%01u'\n",myzone,mynet,mynode,mypoint);
- else printf("Address=`%u:%u/%01u'\n",myzone,mynet,mynode);
- }
- continue;
- }
-
- else if(usingbink) { /* Check for Binkley.cfg APPLICATIONs */
- if(strnicmp(p,"APPLICATION MAKEARC ",20)) continue; /* Not ours */
- p+=20;
- lstrip(p);
- }
-
- else if(!stricmp(p,"DUFUS")) { /* ijit alert */
- dufus = 1;
- printf("Duhhh...Dufus detected at your keyboard.\n");
- continue;
- }
-
- else if(!stricmp(p,"MORE")) { /* Toggle more */
- more=1-more;
- if(debug) printf("More ON\n");
- else printf("More OFF\n");
- continue;
- }
-
- else if(!stricmp(p,"DEBUG")) { /* Toggle debug */
- debug=1-debug;
- if(debug) printf("Debug ON\n");
- else printf("Debug OFF\n");
- continue;
- }
-
- else if(!strnicmp(p,"POLL ",5)) { /* Create empty poll *.CLO file */
- p+=5;
- make_poll(p,lastpos,fp);
- continue;
- }
-
- else if(!strnicmp(p,"SCHED ",6)) continue; /* Skip schedule tags */
-
- else if(!strnicmp(p,"ARCCMD ",7)) { /* Default archiver command */
- p+=7;
- lstrip(p);
- strncpy(arccmd,p,80);
- arccmd[79]=0;
- strcpy(tempcmd,arccmd);
- if(debug || more)printf("Archiver command=`%s <arcname> <pktname>'\n",arccmd);
- continue;
- }
-
- else if(!stricmp(p,"MSG")) { /* Make MSG attaches instead of FLO */
- msgattach=1;
- if(debug || more)printf("Making *.MSG attaches\n");
- continue;
- }
-
- else if(!stricmp(p,"FLO")) { /* Opposite of MSG */
- msgattach=0;
- if(debug || more)printf("Making *.?LO attaches\n");
- continue;
- }
-
- else if(!strnicmp(p,"ALLTYPE ",8)) { /* Default mail type */
- p+=8;
- lstrip(p);
- alltype=toupper(*p);
- if(debug || more)printf("Default mail type=`%c'\n",alltype);
- continue;
- }
-
- else if(!strnicmp(p,"SPAWN ",6)) { /* Do external command */
- p+=6;
- lstrip(p);
- printf("SPAWNing `%s'\n",p);
- lastlevel=spawnit(p);
- continue;
- }
-
- else if(!strnicmp(p,"IFERRORLEVEL ",13)) { /* Respond to ERRORLEVEL */
-
- char oper;
- char level;
-
- p+=13;
- lstrip(p);
- oper=*p;
- p++;
- lstrip(p);
- level=(char)atoi(p);
- p=skip_nonwhite(p);
- lstrip(p);
- if(oper=='!' && lastlevel!=level) {
- printf("ERRORLEVEL match...\n");
- goto AfterERRORLEVEL;
- }
- else if(oper=='>' && lastlevel>level) {
- printf("ERRORLEVEL match...\n");
- goto AfterERRORLEVEL;
- }
- else if(oper=='<' && lastlevel<level) {
- printf("ERRORLEVEL match...\n");
- goto AfterERRORLEVEL;
- }
- else if(lastlevel==level) {
- printf("ERRORLEVEL match...\n");
- goto AfterERRORLEVEL;
- }
- if(debug || more) printf("ERRORLEVEL didn't match...\n");
- continue;
- }
-
- else if(!strnicmp(p,"IFINTIME ",9)) {
-
- long tt1,tt2,tt3;
- struct tm *tt;
-
- p+=9;
- lstrip(p);
- tt1=(atol(p) * 3600L);
- p=to_delim(p,":");
- if(*p==':')p++;
- tt1+=(atol(p) * 60L);
- p=to_delim(p,":");
- if(*p==':')p++;
- tt1+=atol(p);
- p=skip_nonwhite(p);
- lstrip(p);
- tt2=(atol(p) * 3600L);
- p=to_delim(p,":");
- if(*p==':')p++;
- tt2+=(atol(p) * 60L);
- p=to_delim(p,":");
- if(*p==':')p++;
- tt2+=atol(p);
- p=skip_nonwhite(p);
- lstrip(p);
- tt3=time(NULL);
- tt=localtime(&tt3);
- tt3=(long)tt->tm_hour * 3600L;
- tt3+=(long)tt->tm_min * 60L;
- tt3+=(long)tt->tm_sec;
- if (tt3<tt1 || tt3>tt2) continue; /* Not in timeframe */
- goto AfterERRORLEVEL;
- }
-
- else if(!strnicmp(p,"IFDOW ",6)) { /* If day of week (1-7) from Sun */
-
- struct tm *tt;
- long tl;
- int dow;
-
- p+=6;
- lstrip(p);
- dow=atoi(p);
- p=skip_nonwhite(p);
- lstrip(p);
- tl=time(NULL);
- tt=localtime(&tl);
- if(tt->tm_wday+1 != dow) continue; /* Not right day of week */
- goto AfterERRORLEVEL;
- }
-
- else if(!strnicmp(p,"IFMONTH ",8)) { /* If month (1-12) */
-
- struct tm *tt;
- long tl;
- int mon;
-
- p+=8;
- lstrip(p);
- mon=atoi(p);
- p=skip_nonwhite(p);
- lstrip(p);
- tl=time(NULL);
- tt=localtime(&tl);
- if(tt->tm_mon+1 != mon) continue; /* Not right month */
- goto AfterERRORLEVEL;
- }
-
- else if(!strnicmp(p,"IFDOM ",6)) { /* If day of month (1-31) */
-
- struct tm *tt;
- long tl;
- int dom;
-
- p+=6;
- lstrip(p);
- dom=atoi(p);
- p=skip_nonwhite(p);
- lstrip(p);
- tl=time(NULL);
- tt=localtime(&tl);
- if(tt->tm_mday != dom) continue; /* Not right day of month */
- goto AfterERRORLEVEL;
- }
-
- /* Have pity; break up the if...else if chain */
-
- if(!stricmp(p,"BREAK")) { /* No global pass through our zone */
- if(debug || more) printf("BREAK encountered.\n");
- break;
- }
-
- else if(!stricmp(p,"END")) { /* Global then end */
- if(debug || more) printf("END encountered.\n");
- goto DoneWithFile;
- }
-
- else if(!strnicmp(p,"GOTO ",5)) { /* Jump to a schedule tag */
- p+=5;
- lstrip(p);
- printf("Branching to SCHED tag `%s'\n",p);
- if(!find_sched(fp,p,1)) exit(10);
- continue;
- }
-
- else if(!strnicmp(p,"ROUTE ",6)) { /* Misdirect mail :-) */
- p+=6;
- p=strtok(p,":");
- if(!p) {
- fprintf(stderr,"\nMissing Zone\n");
- say_error(lastpos,fp);
- continue;
- }
- p=skip_white(p);
- rzone=(unsigned int)atol(p);
- p=strtok(0,"/");
- if(!p) {
- fprintf(stderr,"\nMissing Net\n");
- say_error(lastpos,fp);
- continue;
- }
- rnet=(unsigned int)atol(p);
- p=strtok(0,".;\n");
- if(!p) {
- fprintf(stderr,"\nMissing Node\n");
- say_error(lastpos,fp);
- continue;
- }
- rnode=(unsigned int)atol(p);
- p=strtok(0,";\n");
- if(!p) rpoint=0;
- else rpoint=(unsigned int)atol(p);
- if(rzone && !rnet) rzone=0;
- if(debug || more) {
- if(!rpoint)printf("Route To=`%u:%u/%01u.%01u'\n",rzone,rnet,rnode,rpoint);
- else printf("Route To=`%u:%u/%01u'\n",rzone,rnet,rnode);
- }
- continue;
- }
-
- else if(!strnicmp(p,"MOVE ",5)) { /* Move mail from outbound->outbound */
- p+=5;
- lstrip(p);
- move_prep(p,lastpos,fp);
- continue;
- }
-
- else if(!strnicmp(p,"CHANGE ",6)) { /* Change mail's type */
- p+=6;
- lstrip(p);
- change_mail(p,lastpos,fp);
- continue;
- }
-
- else if(!strnicmp(p,"DOMAIN",6)) { /* Make pass through a domain */
-
- char *ppp;
-
- p+=6;
- lstrip(p);
- if(*p) {
- ppp=skip_nonwhite(p);
- if(*ppp) {
- *ppp=0;
- ppp++;
- ppp=skip_white(ppp);
- }
- while(pp=(strchr(p,'/')))
- *pp='\\'; /* Convert slashes to backslashes */
- strncpy(outbound,p,80);
- outbound[79]=0;
- if(outbound[strlen(outbound)-1]=='\\')
- outbound[strlen(outbound)-1]=0;
- strcpy(root,outbound);
- if(debug || more) printf("Outbound dir=`%s'\n",root);
- if(*ppp) {
- type=toupper(*ppp);
- ppp=skip_nonwhite(ppp);
- ppp=skip_white(ppp);
- if(*ppp) {
- strcpy(arccmd,ppp);
- }
- else strcpy(arccmd,tempcmd);
- }
- else {
- type=alltype;
- strcpy(arccmd,tempcmd);
- }
- }
- else {
- type=alltype;
- strcpy(arccmd,tempcmd);
- }
- p=strrchr(root,'\\');
- if(p)p++;
- else p="Current";
- printf("Domain `%s'",p);
- if(rzone) printf(" -=> %u:%u.%u",rzone,rnet,rnode);
- printf("\n");
- doingdomain=1;
- }
-
- else {
- if(!strnicmp(p,"NET ",4)) { /* Make a pass through a whole net */
- doingnet=1;
- p+=4;
- lstrip(p);
- }
-
- else if(!strnicmp(p,"ZONE ",5)) { /* Do a global pass through a zone */
- p+=5;
- lstrip(p);
- doingzone=1;
- }
-
- /* Otherwise it's a full address to send to */
-
- p=strtok(p,":");
- if(!p) {
- fprintf(stderr,"\nMissing Zone\n");
- say_error(lastpos,fp);
- continue;
- }
- hiszone=(unsigned int)atol(p);
- if(!hiszone) {
- fprintf(stderr,"\nZero Zone\n");
- say_error(lastpos,fp);
- continue;
- }
- if(!doingzone) {
- p=strtok(0,"/");
- if(!p) {
- fprintf(stderr,"\nMissing Net\n");
- say_error(lastpos,fp);
- continue;
- }
- hisnet=(unsigned int)atol(p);
- if(!hisnet) {
- fprintf(stderr,"\nZero Net\n");
- say_error(lastpos,fp);
- continue;
- }
- if(!doingnet) {
- p=strtok(0," ;");
- if(!p) {
- fprintf(stderr,"\nMissing Node\n");
- say_error(lastpos,fp);
- continue;
- }
- hisnode=(unsigned int)atol(p);
- if(strchr(p,'.')) {
- p=strchr(p,'.');
- p++;
- hispoint=(unsigned int)atol(p);
- }
- else hispoint=0;
- }
- else {
- hisnode=0;
- hispoint=0;
- }
- }
- else {
- hisnet=0;
- hisnode=0;
- hispoint=0;
- }
- p=strtok(0," ;");
- if(p) {
- type=toupper(*p);
- }
- else type=alltype;
- p=strtok(0,";\n");
- if(p) {
- lstrip(p);
- rstrip(p);
- strcpy(arccmd,p);
- }
- else strcpy(arccmd,tempcmd);
-
- if(!doingnet && !doingzone) {
- sprintf(s,"%s\\%04x%04x.?UT",outbound,hisnet,hisnode); /* Find just this one guy for now */
- if(!hispoint)printf("%u:%u/%01u",hiszone,hisnet,hisnode); /* Tell console */
- else printf("%u:%u/%01u.%01u",hiszone,hisnet,hisnode,hispoint);
- }
- else if(doingnet) {
- sprintf(s,"%s\\%04x*.?UT",outbound,hisnet); /* Find anyone in net */
- printf("Net %u:%u",hiszone,hisnet);
- }
- else {
- sprintf(outbound,"%s.%03x",root,hiszone);
- sprintf(s,"%s\\*.?UT",outbound);
- printf("Zone %u (%s)",hiszone,outbound);
- }
- if(rzone) printf(" -=> %u:%u/%u",rzone,rnet,rnode);
- printf("\n");
- }
-
- /* The following label is used to goto for the default pass through
- the default zone (unless BREAK is encountered) at termination. */
-
- OneMoreTime:
-
- if(doingdomain) sprintf(s2,"%s.*",root); /* Special find-the-outbound */
- else strcpy(s2,outbound); /* code. */
- do {
- founddir=_dos_findfirst(s2,16,&d);
- } while(!founddir && !(d.attrib & 16));
-
- if(founddir && !doingdomain) { /* No outbound directory? Uh oh... */
- fprintf(stderr,"\nOutbound directory %s doesn't seem to exist.\n",s2);
- }
-
- while(!founddir) { /* Loop once for anything but DOMAIN */
- p=strrchr(d.name,'.');
- if(p) sprintf(outbound,"%s%s",root,p);
- else strcpy(outbound,root);
-
- if(doingdomain) { /* Get zone # from outbound extension */
- hiszone=0;
- sprintf(s,"%s\\*.?UT",outbound); /* Setup to find any pkt in zone */
- p=strrchr(outbound,'.');
- if(p) {
- p++;
- strncpy(temp,p,3);
- hiszone=(_word)strtol(temp,&p,16);
- }
- if(!hiszone)hiszone=myzone;
- printf(" Zone %u",hiszone); /* and display it */
- if(rzone) printf(" -=> %u:%u/%u",rzone,rnet,rnode);
- printf("\n");
- if(debug || more) printf(" Outbound: `%s'\n",outbound);
- }
-
- while(!_dos_findfirst(s,0,&f)) { /* Never leave one after processing */
- if(didbreak) { /* CTRL-BREAK pressed; outta here */
- if(fp)fclose(fp);
- fprintf(stderr,"\nExitting in response to user break.\x1b[0m\n");
- exit(99);
- }
- if(hiszone!=myzone) sprintf(outbound,"%s.%03x",root,hiszone);
- strcpy(pktfile,f.name);
- strcpy(origpkt,strupr(pktfile));
- strncpy(temp,pktfile,4);
- temp[4]=0;
- p=temp;
- hisnet=(_word)strtol(temp,&p,16);
- strncpy(temp,&pktfile[4],4);
- temp[4]=0;
- p=temp;
- hisnode=(_word)strtol(temp,&p,16);
- sprintf(pktfile,"%s\\%s",outbound,f.name);
- if(rzone) {
- strcpy(arcfile,arcname(rnet,rnode));
- }
- else {
- strcpy(arcfile,arcname(hisnet,hisnode));
- }
- strcat(arcfile,".*");
- t=time(NULL);
- ltoa(t,temp,36);
- sprintf(s2,"%s\\%6.6s%02hx.PKT",outbound,temp,(char)t_counter++);
- rename(pktfile,s2);
- strcpy(pktfile,s2);
- if(rzone && rzone!=myzone) {
- sprintf(outbound,"%s.%03x",root,rzone);
- }
- sprintf(s2,"%s\\%s",outbound,arcfile);
- if(_dos_findfirst(s2,0,&f)) {
- if(rzone) {
- sprintf(arcfile,"%s\\%s.%s1",outbound,arcname(rnet,rnode),day_string());
- }
- else {
- sprintf(arcfile,"%s\\%s.%s1",outbound,arcname(hisnet,hisnode),day_string());
- }
- new=1;
- }
- else {
- sprintf(arcfile,"%s\\%s",outbound,f.name);
- new=0;
- if(f.size==0L) { /* Just a marker file */
- new=1;
- unlink(arcfile);
- p=strrchr(arcfile,'.');
- if(!p) { /* Invalid filename */
- strcat(arcfile,".");
- strcat(arcfile,day_string());
- strcat(arcfile,"1");
- }
- else {
- arcfile[strlen(arcfile)-1]++;
- if(!isdigit(arcfile[strlen(arcfile)-1])) {
- next_name(p); /* Inc filename */
- }
- }
- }
- }
- if(new)printf("Making ");
- else printf("Adding to ");
- if(hispoint)printf("archive %s for %u:%u/%01u.%01u...\n",arcfile,hiszone,hisnet,hisnode,hispoint);
- else printf("archive %s for %u:%u/%01u...\n",arcfile,hiszone,hisnet,hisnode);
- if(rzone) {
- if(rpoint)printf("Routing it to %u:%u/%01u\n",rzone,rnet,rnode,rpoint);
- else printf("Routing it to %u:%u/%01u\n",rzone,rnet,rnode);
- }
- rc=makearc(arcfile,pktfile,origpkt,outbound);
- if(!rc) { /* Archiver error */
- MakeFloAnyway:
- if(new) {
- p=strrchr(origpkt,'.');
- if(!p)p=".F";
- strcpy(s2,&p[1]);
- if(toupper(*s2)=='O') *s2='F';
- if(type) *s2=type;
- else if (alltype) *s2=alltype;
- if(msgattach) {
- if(rzone) makemessage(rzone,rnet,rnode,rpoint,arcfile,*s2);
- else makemessage(hiszone,hisnet,hisnode,hispoint,arcfile,*s2);
- }
- else {
- if(rzone) makeflo(rzone,rnet,rnode,rpoint,arcfile,*s2);
- else makeflo(hiszone,hisnet,hisnode,hispoint,arcfile,*s2);
- }
- }
- else if(!msgattach) { /* Quick&dirty check for orphaned archives (Flow files only) */
- if(rzone) new=check_4flo(rzone,rnet,rnode,rpoint);
- else new=check_4flo(hiszone,hisnet,hisnode,hispoint);
- if(new) goto MakeFloAnyway;
- }
- }
- else if(rc<0) {
- fprintf(stderr,"Rename failed!\n");
- break; /* Rename error; avoid fatal embrace */
- }
- }
- do { /* Loop through all outbound dirs if DOMAIN */
- founddir=_dos_findnext(&d);
- } while(!founddir && !(d.attrib & 16));
- }
- if(!fp) break;
- if(feof(fp)) { /* End of file...implicit END */
- DoneWithFile: /* Terminate on END or big error */
- fclose(fp);
- fp=NULL;
- sprintf(s,"%s\\*.?UT",outbound); /* Find everybody left */
- strcpy(arccmd,tempcmd);
- type=alltype;
- hiszone=myzone;
- doingnet=doingzone=doingdomain=0;
- printf("Default pass through default zone (%s)...\n",root);
- strcpy(outbound,root);
- goto OneMoreTime;
- }
- }
- if(fp) fclose(fp);
-
- /* Display time of run */
-
- lastpos=(time(NULL)-starttime)/60L;
- printf("Run time: %ld minutes %ld seconds\n",lastpos,(time(NULL)-starttime)-(lastpos*60L));
- }
-
-
-
- void _cdecl deinit (void) {
-
- unlink("MAKEARC.RUN"); /* Get rid of marker file */
- }
-
-
-
- void _fastcall say_error (long lastpos,FILE *fp) {
-
- char s[256];
-
- /* Give some info on obvious error encountered in config file */
-
- fseek(fp,lastpos,SEEK_SET);
- if(!fgets(s,256,fp)) return;
- stripcr(s);
- fprintf(stderr,"ERROR line #%u: `%s'\n\n",lines,s);
- }
-
-
-
- char * _fastcall arcname (_word net,_word node) {
-
- /* Return outbound-style archive (bundle) filename */
-
- static char name[9];
-
- sprintf(name,"%04x%04x",mynet-net,mynode-node);
- return name;
- }
-
-
- char * _fastcall filename (_word net,_word node) {
-
- /* Return outbound-style filename */
-
- static char name[9];
-
- sprintf(name,"%04x%04x",net,node);
- return name;
- }
-
-
- void _fastcall next_name (char *p) {
-
- /* Increment archive name extension */
-
- strupr(p);
- if(!strncmp(p,".MO",3)) strcpy(p,".TU1");
- else if(!strncmp(p,".TU",3)) strcpy(p,".WE1");
- else if(!strncmp(p,".WE",3)) strcpy(p,".TH1");
- else if(!strncmp(p,".TH",3)) strcpy(p,".FR1");
- else if(!strncmp(p,".FR",3)) strcpy(p,".SA1");
- else if(!strncmp(p,".SA",3)) strcpy(p,".SU1");
- else strcpy(p,".MO1");
- }
-
-
-
- char * _fastcall fidodate (void) { /* THIS IS THE RIGHT WAY, DAMMIT!!! */
-
- static char fdate[21];
- time_t tt;
-
- /* Sample output: '26 Jul 89 06:23:47' */
-
- tt = time(NULL);
- // strftime(fdate,20,"%d %b %y %H:%M:%S",localtime(&tt));
- strftime (fdate, 21, "%a %d %b %y %H:%M", localtime(&tt)); //seadate
- return(fdate);
- }
-
-
-
- FILE * _fastcall analyze (char *file) {
-
- int handle;
- static FILE *pf;
-
- /* Opens config file, finds starting sched if any, returns handle */
-
- handle=sopen(file,O_RDONLY | O_TEXT,SH_DENYWR);
- if(handle==-1) goto OpenError;
-
- pf=fdopen(handle,"rt");
- if(pf==NULL) {
- OpenError:
- fprintf(stderr,"\nCan't open control file \'%s\'\n",file);
- exit(5);
- }
- printf("\nReading control file \'%s\'...\n",file);
-
- if(*schedtag) {
- if(find_sched(pf,schedtag,0)) {
- printf("Processing schedule tag '%s'\n",schedtag);
- *schedtag=0;
- }
- else exit(10);
- }
- return (pf);
- }
-
-
- _word _fastcall makeflo (_word zone,_word net,_word node,_word point,char *sendfile,char type) {
-
- int handle;
- char s[133];
- char tries=0;
- int x;
-
- /* Create a .?LO file */
-
- if(type=='N' || type=='O') type='F';
- sprintf(s,"%s\\%04x%04x.%cLO",outbound,net,node,type);
- printf("Creating/appending flow attach `%s'...\n",s);
- ReTry:
- handle=sopen(s,O_RDWR | O_BINARY | O_APPEND, SH_DENYWR);
- if(handle==-1) handle=creat(s,S_IWRITE);
- if(handle==-1) {
- if(tries++ < 9) {
- if(debug) printf("Can't access %s; retry #%hu\n",s,tries);
- goto ReTry;
- }
- fprintf(stderr,"\nCouldn't open `%s' (errno=%d)\n",s,errno);
- return 1;
- }
- lseek(handle,0L,SEEK_END);
- sprintf(s,"#%s\r\n",sendfile);
- x=strlen(s);
- if(write(handle,(void *)s,(unsigned int)x)<x) {
- close(handle);
- fprintf(stderr,"\nProblem writing to flow file...\n");
- return 1;
- }
- close(handle);
- return 0;
- }
-
-
-
- char _fastcall check_4flo (_word zone,_word net,_word node,_word point) {
-
- char s[133];
- struct find_t f;
-
- /* Quick and crude check for orphaned bundles */
-
- sprintf(s,"%s\\%04x%04x.?LO",outbound,net,node);
- if(_dos_findfirst(s,0,&f)) {
- Orphan:
- if(debug || more) printf("Apparently orphaned bundle...\n");
- return 1;
- }
- if(f.size==0L) goto Orphan;
- return 0;
- }
-
-
-
- _word _fastcall makemessage (_word zone,_word net,_word node,_word point,char *sendfile,char type) {
-
- int handle;
- struct find_t f;
- static _word x=1;
- char s[133];
- register _word y;
- struct _msg msg;
- char tries=0;
-
- /* Make *.MSG attach */
-
- memset(&msg,0,sizeof(struct _msg));
- msg.attr = MSGLOCAL | MSGKILL | MSGFILE;
- strncpy(msg.subj,sendfile,72);
- msg.subj[71]=0;
- msg.dest=node;
- msg.dest_net=net;
- msg.orig=mynode;
- msg.orig_net=mynet;
- strcpy(msg.date,fidodate());
- strcpy(msg.from,"Attach Message");
- strcpy(msg.to,"Mail Processor");
- for(y=0;y<4;y++) msg.msg_filler[y]=0;
- msg.reply=0;
- msg.up=0;
- msg.times=0;
- msg.cost=0;
- sprintf(s,"%s\\%u.MSG",netdir,x);
- fprintf(stderr,"Creating damn file attach msg `%s'...\n",s);
- ReTry:
- while(!_dos_findfirst(s,0,&f)) {
- x++;
- if(!x) {
- fprintf(stderr,"\nDamn Msg directory is full\n");
- exit(1);
- }
- sprintf(s,"%s\\%u.MSG",netdir,x);
- }
- handle=creat(s,S_IWRITE);
- if(handle==-1) {
- if(tries++<9) {
- if(debug) printf("Can't create %s; retry #%hu\n",s,tries);
- goto ReTry;
- }
- fprintf(stderr,"\nCouldn't open `%s'\n",s);
- exit(2);
- }
- setmode(handle,O_BINARY);
-
- write(handle,&msg,sizeof(struct _msg));
-
- sprintf(s,"\01MSGID: %u:%u/%01u.%01u %08x\r",myzone,mynet,mynode,mypoint,make_msgid());
- write(handle,s,strlen(s)); /* MSGID kludge */
-
- sprintf(s,"\01MSGTO: %u:%u/%01u.%01u\r",zone,net,node,point);
- write(handle,s,strlen(s)); /* MSGTO kludge */
-
- /* 09/15/90 FLAGS info updated to sorta match that given by Odinn Sorenson */
- /* 12/03/90 FLAGS info updated to match (maybe) FSC-0053 */
-
- write(handle,"\01FLAGS TFS XMA",14); /* FIL? */
- if(type=='H') write(handle," HLD",4);
- if(type=='C') write(handle," CRA",4); /* IMM? */
- /* if(type=='N' || type=='F' || type=='O') write(handle," NRM",4); */ /* ???? */
- if(type=='D') write(handle," DIR",4);
- write(handle,"\r",1);
-
- if(mypoint) { /* Barforama stuff for backward (and I do mean backward) */
- sprintf(s,"\01FMPT %01u\r",mypoint); /* compatibility */
- write(handle,s,strlen(s));
- } /* FMPT kludge */
-
- if(point) {
- sprintf(s,"\01TOPT %01u\r",point);
- write(handle,s,strlen(s));
- } /* TOPT kludge */
-
- if(zone!=myzone) {
- y=sprintf(s,"\01INTL %u:%u/%01u %u:%u/%01u\r",zone,net,node,myzone,mynet,mynode);
- write(handle,s,y);
- } /* INTL kludge */
-
- sprintf(s,"\01PID: %s\r",PID_ID);
- write(handle,s,strlen(s)); /* PID kludge just for the hell of it */
- write(handle,"\0",1); /* Null-terminate (couldn't hoit) */
-
- close(handle);
-
- return 0;
- }
-
-
- int _fastcall makearc (char *arcfile,char *pktfile,char *origpkt, char *outbound) {
-
- char level;
- char s[177];
- struct find_t f;
-
- /* Create/add to a bundle */
-
- if(stricmp(arccmd,"DON'T_ARCHIVE")) { /* Kludge for not archiving w/ *.MSG attaches */
- sprintf(s,"%s %s %s",arccmd,arcfile,pktfile);
- if(debug || more) printf("To DOS: %s\n",s);
- level=spawnit(s);
- if(_dos_findfirst(arcfile,0,&f)) {
- ArchiverError:
- fprintf(stderr,"\nArchive attempt failed!\n");
- origpkt[strlen(origpkt)-1]='!';
- printf("Renaming %s to %s\\%s\n",pktfile,outbound,origpkt);
- sprintf(s,"%s\\%s",outbound,origpkt);
- if(rename(pktfile,s)) return -1;
- return 1;
- }
- else if (f.size==0L) goto ArchiverError;
- if(!_dos_findfirst(pktfile,0,&f)) {
- printf("Archiver didn't kill packet.\n");
- if(!level) {
- printf(" I will...\n");
- unlink(pktfile);
- }
- else {
- origpkt[strlen(origpkt)-1]='!';
- printf("Renaming %s to %s\\%s...\n",pktfile,outbound,origpkt);
- sprintf(s,"%s\\%s",outbound,origpkt);
- if(rename(pktfile,s)) return -1;
- return 1;
- }
- }
- return 0;
- }
-
- strcpy(arcfile,pktfile); /* Now attach msg will reference bare
- packet name, not an archive */
- return 0;
- }
-
-
- char * _fastcall day_string (void) { /* to keep the retardos happy
- without medication */
-
- char *days[7] = {"MO","TU","WE","TH","FR","SA","SU"};
- time_t t;
- struct tm *tt;
-
-
- if(!dufus) return days[0];
- t = time(NULL);
- tt = localtime(&t);
- return days[tt->tm_wday];
- }
-