home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
OSKBox.lzh
/
MAILBOX
/
CC
/
forward.c
< prev
next >
Wrap
Text File
|
1993-04-25
|
22KB
|
1,075 lines
#include <stdio.h>
#include <ctype.h>
#include <direct.h>
#include <setjmp.h>
#include <signal.h>
#include <modes.h>
#include <errno.h>
#include "mailbox.h"
#define MAXPATHS 6 /* maximum number of paths to mailbox */
#define MAXCALLS 4000 /* maximum number of calls to be forwarded */
#define TIMEOUT (5 * 60) /* maximum # of seconds to wait for response */
#define MAXBOX 30 /* maximum number of mailboxes */
#define ALARM ((1 << 31) + 60 * 256)
struct userstruct user;
char paths[MAXPATHS][80];
char fwdcalls[MAXCALLS][7];
int path_count = 0;
int call_count = 0;
int tnc_in, tnc_out, ctl_in, ctl_out;
jmp_buf disconnected;
int signalman(), quit = 0, interrupt = 0;
int start_fwd, sec;
char *priority = "*";
int bigmail;
char *fwdfile[MAXBOX];
int fwdsize[MAXBOX];
int cmpcall();
int bid_flag, ok_flag, hflag, debugflag;
int norev_flag, suck_flag;
extern struct dist_list *distboxes;
char *maildir = "MAIL/";
int maxtime; /* maximum # of seconds to forward */
main (argc, argv)
char *argv[];
{
int i;
char *cp;
char *port;
while (--argc > 0 && (++argv)[0][0]=='-') {
cp = argv[0] + 1;
while (*cp) switch (*cp++) {
case 'r':
norev_flag++;
continue;
case 's':
suck_flag++;
continue;
case 'd':
debugflag++;
continue;
case 'm':
maxtime = atoi (cp) * 60;
while (isdigit (*cp)) cp++;
continue;
case 'b':
bigmail = atoi (cp) * 60;
while (isdigit (*cp)) cp++;
continue;
case 'p':
priority = cp;
while (*cp) cp++;
continue;
case '?':
printf ("\n");
printf ("forward -- forward messages to packet BBS(s)\n");
printf ("\n");
printf ("form: forward [options] <port> <bbs> ...\n");
printf ("\n");
printf ("options are as follows:\n");
printf ("\n");
printf (" -r inhibit reverse forward prompt\n");
printf (" -s only force a reverse forward prompt (suck)\n");
printf (" -m<num> set the maximum connect time to <num> minutes\n");
printf (" -b<num> set the maximum message size to <num> bytes\n");
printf (" -p<str> set the priority string:\n");
printf (" '*' = any message\n");
printf (" 'P' = any non-bulletin message\n");
printf (" 'x' = any message of type 'x'\n");
exit (0);
default:
fprintf(stderr, "Unknown flag\n");
continue;
}
}
if (argc<=0) {
fprintf (stderr, "Insufficient arguments\n");
exit(0);
}
port = *argv++; argc--;
upper (port);
if (!argc) {
printf ("No port supplied.\n");
exit (0);
}
if (argc > MAXBOX) {
printf ("Too many mailboxes.\n");
exit (0);
}
for (i = 0; i < argc; i++) printf ("%d: %s\n", i, argv[i]);
chdir (HOME);
strcpy (user.uscall, "AUTOFW");
user.usopt = ISSUPER;
intercept (signalman);
read_dist_list ();
read_fwd_files (argc, argv);
if (suck_flag)
for (i = 0; i < argc; i++)
suck (argv[i], port, fwdfile[i], fwdsize[i]);
else
for ( ; *priority; priority++)
for (i = 0; i < argc; i++) {
if (*argv[i] != '*')
if (forward (argv[i], port, fwdfile[i], fwdsize[i]) < 0)
*argv[i] = '*'; /* error in forwarding, don't retry */
if (quit) {
printf ("quitting!\n");
break;
}
}
}
pass_prior (head)
struct msg_header *head;
{
if (*priority == '*')
return 1;
if (toupper (*priority) == 'P' && !bulletin (head))
return 1;
if (toupper (*priority) == head->mhtype)
return 1;
return 0;
}
find_call (target)
char *target;
{
int i, p1, p2, comp;
p1 = 0; p2 = call_count-1;
if (debugflag)
printf ("find_call (%s)\n", target);
while (p1 <= p2) {
i = p1 + ((p2 - p1) >> 1);
comp = cmpcall (target, fwdcalls[i]);
if (debugflag)
printf (" %d %d %d %s %d\n", p1, i, p2, fwdcalls[i], comp);
if (comp < 0)
p2 = i-1;
else if (comp > 0)
p1 = i+1;
else
break;
}
if (comp != 0) {
return -1;
}
while (i > 0 && cmpcall (target, fwdcalls[i-1]) == 0)
i--;
return (i);
}
test (head, mbox)
struct msg_header *head;
char *mbox;
{
int i;
char *target;
struct dist_list *dp;
char bbs[7];
if (!pass_prior (head)) {
return 0;
}
scanaddr (head->mhbbs, bbs, 7);
target = (*(head->mhbbs)) ? bbs : head->mhto;
if (debugflag)
{
printf ("test %d\n", head->mhnr);
printf ("target='%s'\n", target);
}
if ((i = find_call (target)) != -1)
for ( ; i < call_count && cmpcall (target, fwdcalls[i]) == 0; i++)
if (_cmpnam (target, fwdcalls[i], strlen (fwdcalls[i])) == 0)
goto found;
if (/* !bulletin (head) && */ *(head->mhbbs)) {
char *p, hfield[7];
int len;
p = head->mhbbs + scanaddr (head->mhbbs, hfield, 7);
while (len = scanaddr (p, hfield, 7)) {
if (debugflag)
printf (" hfield '%s'\n", hfield);
p += len;
if ((i = find_call (hfield)) != -1) {
for (dp = distboxes; dp; dp = dp->dlnext)
if (strcmp (hfield, dp->dlname) == 0) break;
if (dp) continue;
for ( ; i < call_count && cmpcall (hfield, fwdcalls[i]) == 0; i++)
if (_cmpnam (hfield, fwdcalls[i], strlen (fwdcalls[i])) == 0)
goto found;
}
}
}
return 0;
found:
for (dp = distboxes; dp; dp = dp->dlnext)
if (strcmp (bbs, dp->dlname) == 0) break;
if (dp) {
char w[10];
strcpy (w, mbox);
upper (w);
get_ssid (w);
for (i = 0; i < dp->dlcount; i++)
if (strcmp (w, dp->dlbbs[i]) == 0) break;
if ((1 << i) & head->mhdist)
return 0;
}
if (bigmail && head->mhsize > bigmail) {
return 0;
}
return 1;
}
forward (mbox, port, file, size)
char *mbox, *port, *file;
int size;
{
struct msg_header *head;
int i, flag;
char str[20], path[90];
read_fwd_file (mbox, file, size);
flag = 0;
open_mail ();
while ((head = next_mail (is_nforwarded, 0)) != NULL)
if (test (head, mbox)) {
flag = 1;
break;
}
if (!flag) {
close_mail ();
return 0;
}
if (!open_channel (port)) {
close_mail ();
return -1;
}
if (strcmp (port, "T7") == 0)
write_path (ctl_out, "W32\n");
flag = 0;
if (setjmp (disconnected)) {
flag = 1;
goto exit;
}
bid_flag = ok_flag = hflag = 0;
if (connect (mbox, path)) {
reset_mail (0);
get_prompt ();
if (ok_flag) {
sprintf (str, "%s\n", SID);
write_path (tnc_out, str);
get_prompt ();
}
start_fwd = tick();
while ((head = next_mail (is_nforwarded, 0)) != NULL && !quit)
{
if (test (head, mbox, port, path))
if (!send_msg (head, mbox, port, path))
flag = 1;
if (maxtime && (tick() - start_fwd) / sec > maxtime)
{
flag = 1;
break;
}
}
if (!flag && !quit && ok_flag && !norev_flag) {
if (setjmp (disconnected)) {
strcpy (user.uscall, "AUTOFW");
goto exit;
}
reverse (mbox);
strcpy (user.uscall, "AUTOFW");
}
disconnect ();
}
else
flag = 1;
exit:
close_channel (port);
close_mail (0);
return ((flag) ? -1 : 1);
}
suck (mbox, port, file, size)
char *mbox, *port, *file;
int size;
{
struct msg_header *head;
int i, flag;
char str[20], path[90];
read_fwd_file (mbox, file, size);
open_mail ();
if (!open_channel (port)) {
close_mail ();
return -1;
}
bid_flag = ok_flag = 0;
if (connect (mbox, path)) {
if (setjmp (disconnected)) {
strcpy (user.uscall, "AUTOFW");
goto exit;
}
get_prompt ();
if (ok_flag) {
sprintf (str, "%s\n", SID);
write_path (tnc_out, str);
get_prompt ();
}
reverse (mbox);
disconnect ();
}
exit:
close_channel (port);
close_mail (0);
return (1);
}
send_msg (head, mbox, port, path)
struct msg_header *head;
char *mbox, *port, *path;
{
char str[256], name[32], *p;
int f, len;
int time, date, tick;
short day;
struct fildes buffer;
struct dist_list *dp;
char bbs[7];
printf ("send_msg #%d\n", head->mhnr);
if ((f = open_msg (head)) < 0)
return 0;
p = str;
p += sprintf (p, "S%c %s", head->mhtype, head->mhto);
scanaddr (head->mhbbs, bbs, 7);
if (*(head->mhbbs))
if (hflag)
p+= sprintf (p, " @ %s", head->mhbbs);
else
p+= sprintf (p, " @ %s", bbs);
p += sprintf (p, " < %s", head->mhfrom);
if (head->mhbid[0] && bid_flag && head->mhtype != 'T')
p += sprintf (p, " $%s", head->mhbid);
p += sprintf (p, "\n");
write_path (tnc_out, str);
if (ok_flag) {
get_line (str);
p = str + scanword (str, name, 32);
if (strcmp (name, "OK") != 0) {
close (f);
get_prompt ();
log ("r %d %s %s", head->mhnr, mbox, p);
goto sent;
}
}
write_path (tnc_out, head->mhtit);
write_path (tnc_out, "\n");
if (!ok_flag) {
get_line (str);
get_line (str);
}
ztime (&head->mhtime, &head->mhdate, &day);
sprintf (str, "R:%02d%02d%02d/%02d%02dz @:%s.%s %s #:%d Z:%s\n",
(head->mhdate >> 16) % 100,
(head->mhdate >> 8) & 0xff,
head->mhdate & 0xff,
(head->mhtime >> 16) & 0xff,
(head->mhtime >> 8) & 0xff,
MYCALL, MYHADDR, MYQTH,
head->mhnr,
MYZIP);
write_path (tnc_out, str);
while ((len = read (f, str, 256)) > 0)
write (tnc_out, str, len);
close (f);
write_path (tnc_out, "\032\n");
get_prompt ();
log ("f %d %s %s", head->mhnr, port, path);
sent:
strcpy (str, mbox);
get_ssid (str);
reset_mail ();
head = next_mail (is_num, head->mhnr);
checkoff (head, "");
if (!checkoff (head, str))
if (bulletin (head))
head->mhstat = 'F';
else
head->mhstat = 'X';
update_mail ();
return 1;
}
get_prompt ()
{
char str[256];
char *f1, *f2, *f3, *f4, *p;
printf ("get_prompt\n");
while (1) {
get_line (str);
if (str[strlen (str) - 1] == '>')
return;
else if ((f1 = strchr (str, '[')) == str && (f2 = strrchr (f1, ']')) &&
(f3 = strchr (f1, '-')) && f3 < f2 && (f4 = strrchr (f1, '-')) &&
f4 > f3) {
ok_flag = 1;
for (p = f4 + 1; p < f2; p++)
switch (*p) {
case '$': bid_flag++; break;
case 'H': hflag++; break;
default: break;
}
}
else if ((f1 = strchr (str, '[')) == str && (f2 = strchr (f1, ']'))) {
*(f1+4) = '\0';
if (strcmp (f1+1, "MBL" == 0))
ok_flag = bid_flag = 1;
}
}
}
reverse (mbox)
{
char str[100], *p, w[40], mcall[9];
struct msg_header *head;
int date, time, tick;
short day;
int f;
int fromflag, makebid;
char type, to[7], from[7], bbs[39], bid[13];
strcpy (mcall, mbox);
get_ssid (mcall);
strcpy (user.uscall, mcall);
while (1) {
write_path (tnc_out, "F>\n");
get_line (str);
if (toupper (*str) != 'S') {
disconnect ();
return;
}
fromflag = 0;
makebid = 0;
bbs[0] = '\0';
bid[0] = '\0';
p = str;
p += scanword (p, w, 40);
type = (isalpha (w[1])) ? toupper (w[1]) : ' ';
strcpy (from, mcall);
p += scanword (p, w, 40);
if (! *w)
disconnect (); /* no addressee */
upper (w);
get_ssid (w);
strncpy (to, w, 7);
p += scanword (p, w, 40);
again:
while (*w) {
if (*w == '@') {
p += scanword (p, w, 40);
if (*w) {
upper (w);
get_ssid (w);
strncpy (bbs, w, 39);
p += scanword (p, w, 40);
goto again;
}
}
else if (*w == '<') {
p += scanword (p, w, 40);
if (*w) {
upper (w);
get_ssid (w);
if ((user.usopt & ISBBS) || (user.usopt & ISSUPER))
strncpy (from, w, 7);
p += scanword (p, w, 40);
fromflag++;
goto again;
}
}
else if (*w == '$') {
if (strlen (w) == 1) {
p += scanword (p, w, 40);
if (!*w)
makebid++;
}
else
strcpy (w, w+1);
if (*w) {
upper (w);
strncpy (bid, w, 13);
p += scanword (p, w, 40);
goto again;
}
}
}
if (type == 'T') {
bid[0] = '\0';
makebid = 0;
}
if (bid[0] && (head = find_bid (bid))) {
write_path (tnc_out, "NO - duplicate BID\n");
checkoff (head, mcall);
continue;
}
if ((head = new_mail (0)) == NULL) {
write_path (tnc_out, "WAIT - mail system is full\n");
continue;
}
head->mhtype = type;
strcpy (head->mhfrom, from);
strcpy (head->mhto, to);
strcpy (head->mhbbs, bbs);
strcpy (head->mhbid, bid);
if (ok_flag)
sprintf (str, "OK %d\n", head->mhnr);
else
sprintf (str, "Enter title of message:\n");
write_path (tnc_out, str);
get_line (str);
strncpy (head->mhtit, str, 81);
strcpy (w, maildir);
header_to_name (head, w + strlen (maildir));
if ((f = create (w, S_IWRITE, S_IREAD+S_IWRITE)) == -1) {
sprintf (str, "Error %d creating message file %s.\n", errno, w);
write_path (tnc_out, str);
continue;
}
if (!ok_flag) {
sprintf (str, "Enter the message, ^Z to end. It will be number %d\n",
head->mhnr);
write_path (tnc_out, str);
}
if (getfile (f))
write (f, "\n", 1);
head->mhsize = _gs_size (f);
close (f);
header_to_name (head, w);
head->mhstat = 'N';
if (makebid && !head->mhbid[0])
sprintf (head->mhbid, "%d_%s", head->mhnr, MYCALL);
checkoff (head, mcall);
update_mail ();
log_send (head, fromflag);
strcpy (w, "msgproc -q -b ");
sprintf (w + strlen (w), "%d", head->mhnr);
system (w);
}
}
getfile (f)
{
char line[300], *p;
int len, alarm, time = 0;
time = tick ();
while (1) {
if (_gs_rdy (ctl_in) > 0)
check_status ();
if ((len = _gs_rdy (tnc_in)) > 0) {
time = tick ();
alarm = alm_set (SIGINT, ALARM);
len = read (tnc_in, line, (len > 256) ? 256 : len);
alm_delete (alarm);
for (p = line; p - line < len; p++)
if (*p == '\032') {
write (f, line, p-line);
goto exit;
}
write (f, line, len);
}
else
sleep (3);
if ((tick() - time) / sec > TIMEOUT) {
printf ("TIMEOUT\n");
write_path (ctl_out, "D\n");
time = tick ();
}
}
exit:
return (p-line);
}
get_line (str)
char *str;
{
int len;
int time = 0;
int status_disp, data_disp, data_send, data_ack, tries, state;
time = tick ();
data_send = data_ack = -1;
while (1) {
if (data_send || data_ack) {
write_path (ctl_out, "L\n");
do read_path (ctl_in, str, 80); while (str[0] == '(');
printf ("status %s\n", str);
scan_status (str, &status_disp, &data_disp, &data_send,
&data_ack, &tries, &state);
if (state == 0 || quit)
longjmp (disconnected, 2);
if (data_send || data_ack)
time = tick ();
}
else if (_gs_rdy (ctl_in) > 0)
check_status ();
if (_gs_rdy (tnc_in) > 0) {
read_path (tnc_in, str, 256);
printf ("get_line: '%s'\n", str);
return;
}
sleep (3);
if ((tick() - time) / sec > TIMEOUT) {
printf ("TIMEOUT\n");
write_path (ctl_out, "D\n");
time = tick ();
}
}
}
disconnect ()
{
printf ("disconnect\n");
write_path (ctl_out, "D\n");
while (!check_disconnect ())
;
}
check_status ()
{
if (check_disconnect ())
longjmp (disconnected, 1);
}
check_disconnect ()
{
char str[80];
char *p, w[20];
int len;
read_path (ctl_in, str, 80);
printf ("%s\n", str);
p = str;
p += scanword (p, w, 20);
if (strcmp (w, "CHANNEL") == 0) {
p += scanword (p, w, 20);
if (strcmp (w, "NOT") == 0) {
p += scanword (p, w, 20);
return (strcmp (w, "CONNECTED") == 0);
}
else
return 0;
}
p += scanword (p, w, 20);
if (strcmp (w, "LINK") == 0) {
p += scanword (p, w, 20);
if (strcmp (w, "FAILURE") != 0)
return 0;
}
else if (strcmp (w, "DISCONNECTED") != 0)
return 0;
return 1;
}
connect (mbox, path)
char *mbox, *path;
{
int i;
char str[90];
if (path_count == 0) {
strcpy (path, mbox);
return (try_connect (mbox) == 1);
}
else
for (i = 0; i < path_count; i++) {
sprintf (str, "%s %s", mbox, paths[i]);
switch (try_connect (str)) {
case 0: break;
case 1: strcpy (path, str);
return 1;
case -1:return 0;
}
}
return 0;
}
try_connect (fpath)
char *fpath;
{
char str[95], w[20], *p;
int len;
int tries = 0;
printf ("try_connect %s\n", fpath);
for (p = fpath; *p; p++)
if (*p == '*') break;
if (*p)
return (netrom (fpath));
again: sprintf (str, "C %s\n", fpath);
write_path (ctl_out, str);
read_path (ctl_in, str, 95);
printf ("%s\n", str);
p = str + scanword (str, w, 20);
p += scanword (p, w, 20);
if (strcmp (w, "CONNECTED") == 0)
return 1;
else if (strcmp (w, "BUSY") == 0 || strcmp (w, "STATION") == 0) {
/*
scanword (fpath, w, 20); if (strcmp (w, "W0RLI") == 0) return -1;
if (++tries > 4) return -1;
sleep (60);
goto again;
*/
return -1;
}
else
return 0;
}
netrom (fpath)
char *fpath;
{
char w[20], digis[10][12], str[95], str2[256], *p;
int i, j, k, dcount, tries;
printf ("netrom %s\n", fpath);
p = fpath;
p += scanword (p, w, 10);
dcount = 0;
do {
p += scanword (p, digis[dcount], 12);
} while (digis[dcount++][0]);
strcpy (digis[dcount-1], w);
for (i = 0; i < dcount-1; i++)
if (digis[i][0] == '*') break;
sprintf (str, "C %s", (digis[i][0] == '*') ? digis[i] + 1 : digis[i]);
for (j = 0; j < i; j++) {
strcat (str, " ");
if (digis[j][0] == '*')
strcat (str, digis[j] + 1);
else
strcat (str, digis[j]);
}
strcat (str, "\n");
write_path (ctl_out, str);
read_path (ctl_in, str, 95);
printf (" %s\n", str);
p = str + scanword (str, w, 20);
p += scanword (p, w, 20);
if (strcmp (w, "CONNECTED") != 0)
return 0;
i++;
while (i < dcount) {
for (j = i; j < dcount-1; j++)
if (digis[j][0] == '*') break;
sprintf (str, "C %s", (digis[j][0] == '*') ? digis[j] + 1 : digis[j]);
for (k = i; k < j; k++) {
strcat (str, " ");
if (digis[k][0] == '*')
strcat (str, digis[k] + 1);
else
strcat (str, digis[k]);
}
if (strcmp (str, "C ") == 0)
strcpy (str, "BBS");
strcat (str, "\n");
tries = 0;
again: write_path (tnc_out, str);
get_line (str2);
p = str2 + scanword (str2, w, 20);
p += scanword (p, w, 20);
if (strcmp (w, "Busy") == 0) {
/*
if (strcmp (digis[dcount-1], "W0RLI") == 0) {disconnect(); return -1;}
if (++tries > 4) {
disconnect ();
return -1;
}
sleep (60);
goto again;
*/
disconnect (); return -1;
}
else if (strcmp (w, "Connected") != 0) {
disconnect ();
return 0;
}
i = j + 1;
if (i == dcount - 1 && strcmp (digis[j], "*") == 0)
break;
}
return 1;
}
open_channel (port)
char *port;
{
int hostcmd;
int i, pid;
char str[40];
strcpy (str, "/pipe/command.");
strcat (str, port);
if ((hostcmd = open (str, 2)) < 0)
return (0);
pid = getpid ();
sprintf (str, "o%d\n", pid);
write_path (hostcmd, str);
close (hostcmd);
sprintf (str, "/pipe/data_in.%d", pid);
for (i = 0; i < 10; i++) {
if ((tnc_in = open (str, 3)) != -1) break;
sleep (1);
}
if (tnc_in == -1)
return (0);
sprintf (str, "/pipe/data_out.%d", pid);
tnc_out = open (str, 3);
sprintf (str, "/pipe/ctl_in.%d", pid);
ctl_in = open (str, 3);
sprintf (str, "/pipe/ctl_out.%d", pid);
ctl_out = open (str, 3);
return (1);
}
close_channel (port)
char *port;
{
int hostcmd;
int i, j, pid;
char str[40];
strcpy (str, "/pipe/command.");
strcat (str, port);
if ((hostcmd = open (str, 2)) < 0)
return (0);
pid = getpid ();
sprintf (str, "c%d\n", pid);
write_path (hostcmd, str);
close (hostcmd);
sleep (5);
drain (tnc_in);
drain (tnc_out);
drain (ctl_in);
drain (ctl_out);
close (tnc_in);
close (tnc_out);
close (ctl_in);
close (ctl_out);
sprintf (str, "/pipe/data_in.%d", pid);
for (i = 0; i < 10; i++) {
if (access (str, 0) == -1) break;
sleep (1);
}
if (i == 10) return 0;
return (1);
}
drain (path)
{
int i, j;
char c;
while ((i = _gs_rdy (path)) > 0) {
for (j = 0; j < i; j++)
read (path, &c, 1);
sleep (1);
}
}
write_path (path, str)
char *str;
{
write (path, str, strlen (str));
if (path == tnc_out) writeln (1, str, strlen (str));
}
read_path (path, str, len)
char *str;
{
int i;
i = readln (path, str, len);
if (i)
str[i-1] = '\0';
return i;
}
read_fwd_file (mbox, file, size)
char *mbox, *file;
{
char str[80], w[7], *p, *p2;
int i, f, len;
printf ("read_fwd_file %s\n", mbox);
path_count = call_count = 0;
strcpy (str, mbox);
get_ssid (str);
strcpy (fwdcalls[call_count++], str);
for (p2 = file; p2 < file + size; p2 += strlen (p2) + 1) {
strcpy (str, p2);
p = str + scanword (str, w, 7);
if (strcmp (w, "VIA") == 0) {
while (isspace (*p))
p++;
if (path_count < MAXPATHS)
strcpy (paths[path_count++], p);
}
else if (*w && *w != '@' && *w != ';') {
get_ssid (w);
if (call_count < MAXCALLS)
strcpy (fwdcalls[call_count++], w);
}
}
qsort (fwdcalls, call_count, 7, cmpcall);
if (debugflag)
for (i = 0; i < call_count; i++) printf (" call %s\n", fwdcalls[i]);
}
read_fwd_files (argc, argv)
char *argv[];
{
char str[80], w[7], *p;
int i, f, len;
char *mbox;
for (i = 0; i < argc; i++) {
mbox = argv[i];
if (debugflag)
printf ("processing %s\n", mbox);
upper (mbox);
strcpy (str, mbox);
for (p = str; *p; p++)
if (*p == '-')
*p = '_';
strcat (str, ".fwd");
fwdfile[i] = (char *)malloc (1);
fwdsize[i] = read_file (str, &fwdfile[i], 0);
}
return (1);
}
read_file (name, pptr, size)
char *name, **pptr;
{
int f, fsize, tsize;
char *fptr, *p, line[80];
if (debugflag)
printf ("read_file (%s, %x(%x), %d)\n", name, pptr, *pptr, size);
if (*name == '/')
strcpy (line, name);
else
sprintf (line, "%s/%s", FWDIR, name);
if ((f = open (line, 1)) < 0)
return (size);
fsize = _gs_size (f);
fptr = (char *)malloc (size + fsize);
if (debugflag)
printf (" new ptr=%x size=%d\n", fptr, size);
if (size) movmem (*pptr, fptr, size);
read (f, fptr + size, fsize);
close (f);
for (p = fptr + size; p - fptr < size + fsize; p++) {
*p = toupper (*p);
if (*p == '\n')
*p = '\0';
}
free (*pptr);
*pptr = fptr;
tsize = size + fsize;
for (p = fptr + size; p - fptr < size + fsize; p += strlen (p) + 1) {
if (*p == '@') {
strcpy (line, p+1);
tsize = read_file (line, pptr, tsize);
p = *pptr + (p - fptr);
fptr = *pptr;
}
}
return (tsize);
}
signalman (signal)
{
switch (signal) {
case SIGQUIT:
quit = 1;
break;
case SIGINT:
interrupt = 1;
break;
default:
break;
}
}
tick ()
{
int time, date, i_tick;
short day;
_sysdate (3, &time, &date, &day, &i_tick);
sec = i_tick >> 16;
return (time * sec + (i_tick & 0xFFFF));
}
scan_status (s, a, b, c, d, x, f)
char *s;
int *a, *b, *c, *d, *x, *f;
{
char *p, w[20];
p = s;
p += scanword (p, w, 20);
*a = atoi (w);
p += scanword (p, w, 20);
*b = atoi (w);
p += scanword (p, w, 20);
*c = atoi (w);
p += scanword (p, w, 20);
*d = atoi (w);
p += scanword (p, w, 20);
*x = atoi (w);
p += scanword (p, w, 20);
*f = atoi (w);
}
cmpcall (c1, c2)
register char *c1, *c2;
{
while (*c1 == *c2) {
if (*c1 == '\0') return 0;
c1++;
c2++;
}
if (*c1 == '?' || *c1 == '*' || *c2 == '?' || *c2 == '*')
return 0;
else
return (*c1 - *c2);
}