home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
BOUT
/
BT2404SC.ZIP
/
MISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-28
|
38KB
|
1,650 lines
/*
** Henry Clark 1:124/6120 made changes here 7/28/90
*/
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Vince Perriello */
/* with code from several authors */
/* */
/* */
/* Miscellaneous routines used by BinkleyTerm */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.240. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:132/491, 1:141/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n132.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <dos.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <conio.h>
#include <process.h>
#include <io.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef OS_2
#define INCL_DOSPROCESS
#endif
#ifdef __TURBOC__
#include "tc_utime.h"
#include <mem.h>
#else
#include <sys/utime.h>
#include <memory.h>
#endif
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "vfossil.h"
#include "externs.h"
#include "prototyp.h"
#include "defines.h"
#ifdef OS_2
#ifdef Snoop
#include "snserver.h"
static HSNOOP hsnoop=(HSNOOP)NULL;
#endif /* Snoop */
#endif /* OS_2 */
static char newstring[200];
static void fill_in_status (void);
static int find_addr (char *, ADDR *, char *);
int dexists (filename)
char *filename;
{
struct FILEINFO dta;
return (!dfind (&dta, filename, 0));
}
int dfind (dta, name, times)
struct FILEINFO *dta;
char *name;
int times;
{
#ifndef OS_2
union REGS r;
r.x.dx = (unsigned int) dta;
r.h.ah = 0x1a;
(void) intdos (&r, &r);
r.x.bx = 0;
r.x.cx = ~0x08;
r.x.dx = (unsigned int) name;
r.x.si = 0;
r.x.di = 0;
if (times == 0)
{
r.h.ah = 0x4e;
(void) intdos (&r, &r);
dta->nill = '\0';
if (r.x.cflag != 0)
{
dta->name[0] = '\0';
return (1);
}
return (0);
}
else
{
r.h.ah = 0x4f;
(void) intdos (&r, &r);
dta->nill = '\0';
if (r.x.cflag != 0)
{
dta->name[0] = '\0';
return (1);
}
return (0);
}
#else
int retval;
if (times == 0)
{
retval = dir_findfirst(name, 0x37, dta);
/* dta->nill = '\0'; */
if (retval)
{
/* dta->name[0] = '\0'; */
return (1);
}
else
return (0);
}
else
{
retval = dir_findnext(dta);
/* dta->nill = '\0'; */
if (retval)
{
/* dta->name[0] = '\0'; */
return (1);
}
else
return (0);
}
#endif
}
int set_baud (baudrate, log)
unsigned baudrate;
int log;
{
register int i;
if (baudrate > max_baud.rate_value)
baudrate = max_baud.rate_value;
for (i = 0; btypes[i].rate_value; i++)
{
if (btypes[i].rate_value == baudrate)
{
if (baud != i) /* same as what we have? */
{
if (log && !un_attended)
status_line (msgtxt[M_SETTING_BAUD], baudrate);
baud = i; /* need this for ALT-B */
MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
cur_baud = baudrate;
}
if (un_attended && fullscreen)
{
sb_move (settingswin, SET_PORT_ROW, SET_COL);
(void) sprintf (junk, "%-5u Com%d", baudrate, port_ptr + 1);
sb_puts (settingswin, (unsigned char *) junk);
sb_show ();
}
return (1);
}
}
return (0);
}
static char *specifiers = "!*+:# >";
static struct tm *tp;
static time_t ltime;
/*
** Henry Clark 1:124/6120 made changes here 7/28/90
*/
void _cdecl status_line (char *fmt,...)
{
va_list arg_ptr;
#ifdef Snoop
char tmp[255];
#define e_input tmp
#endif /* Snoop */
va_start (arg_ptr, fmt);
(void) vsprintf (e_input, fmt, arg_ptr);
(void) time (<ime);
tp = localtime (<ime);
if ((!fullscreen) || (!un_attended))
{
if ((e_input[0] != '>') || debugging_log)
{
(void) printf ("\n%c %02i %03s %02i:%02i:%02i BINK %s", e_input[0],
tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
&e_input[1]);
}
}
else
{
if ((e_input[0] != '>') || debugging_log)
{
(void) sprintf (stat_line, stat_str, e_input[0],
tp->tm_hour, tp->tm_min, tp->tm_sec, &e_input[1]);
fill_in_status ();
#ifdef OS_2
#ifdef Snoop
if(hsnoop)
SnoopWrite(hsnoop, stat_line);
#endif /* Snoop */
#endif /* OS_2 */
}
}
if ((status_log != NULL) &&
((strchr (specifiers, e_input[0]) - strchr (specifiers, '!')) <= loglevel))
{
(void) fprintf (status_log, "%c %02i %s %02i:%02i:%02i BINK %s\n", e_input[0],
tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
&e_input[1]);
if (immed_update)
{
(void) fflush (status_log);
(void) real_flush (fileno (status_log));
need_update = 0;
}
else
{
need_update = 1;
}
}
va_end (arg_ptr);
}
/*--------------------------------------------------------------------------*/
/* THROUGHPUT */
/* Print throughput message at end of transfer */
/*--------------------------------------------------------------------------*/
void throughput (opt, bytes)
int opt;
unsigned long bytes;
{
static long started = 0L;
static long elapsed;
static long cps;
if (!opt)
started = time (NULL);
else if (started)
{
elapsed = time (NULL);
/* The next line tests for day wrap without the date rolling over */
if (elapsed < started)
elapsed += 86400L;
elapsed -= started;
if (elapsed == 0L)
elapsed = 1L;
cps = (long) (bytes / (unsigned long) elapsed);
started = (cps * 1000L) / ((long) cur_baud);
status_line ((char *) msgtxt[M_CPS_MESSAGE], cps, bytes, started);
}
} /* throughput */
static void fill_in_status ()
{
(void) time (<ime);
tp = localtime (<ime);
if (fullscreen)
{
sb_scrl (callwin, 1);
sb_move (callwin, SB_ROWS - 15, 2);
sb_puts (callwin, (unsigned char *) stat_line);
sb_move (settingswin, SET_TIME_ROW, SET_TIME_COL);
(void) sprintf (junk, "%s %s %02d @ %02d:%02d",
wkday[tp->tm_wday], mtext[tp->tm_mon], tp->tm_mday,
tp->tm_hour, tp->tm_min);
sb_puts (settingswin, (unsigned char *) junk);
sb_show ();
}
}
void clear_statusline ()
{
if (fullscreen)
sb_fillc (callwin, ' ');
}
int got_error (string1, string2)
char *string1, *string2;
{
#ifdef __TURBOC__
/* Since TurboC doesn't handle errno correctly, zero it and ignore. */
errno = 0;
status_line ("%s, %s %s %s", msgtxt[M_ERROR], msgtxt[M_CANT], string1, string2);
#else
if (errno == 0x18)
errno = 0;
if (errno != 0)
{
status_line ("%s %d, %s %s %s", msgtxt[M_ERROR], errno, msgtxt[M_CANT], string1, string2);
errno = 0;
return (1);
}
#endif
return (0);
}
void set_xy (string)
char *string;
{
WRITE_ANSI ('\r');
WRITE_ANSI ('\n');
scr_printf (string);
locate_x = wherex ();
locate_y = wherey ();
}
void message (string)
char *string;
{
if (string != NULL)
{
status_line (" %s", string);
}
}
/*
** Henry Clark 1:124/6120 made changes here 7/28/90
*/
void _cdecl time_release ()
{
if (need_update)
{
(void) fflush (status_log);
(void) real_flush (fileno (status_log));
need_update = 0;
}
#ifdef OS_2
DosSleep (1L);
#else
dos_break_off (); /* Turn off ^C trapping */
if (have_dv)
{
dv_pause ();
}
else if (have_mos)
{
mos_pause ();
}
else if (have_ddos)
{
ddos_pause ();
}
else if (have_tv)
{
tv_pause ();
}
else if (have_ml)
{
ml_pause ();
}
else
{
/* The idea for this code came from Holger Schurig */
msdos_pause ();
}
#endif /* OS_2 */
}
char *fancy_str (string)
char *string;
{
register int flag = 0;
char *s;
s = string;
while (*string)
{
if (isalpha (*string)) /* If alphabetic, */
{
if (flag) /* already saw one? */
*string = tolower (*string); /* Yes, lowercase it */
else
{
flag = 1; /* first one, flag it */
*string = toupper (*string); /* Uppercase it */
}
}
else /* if not alphabetic */ flag = 0; /* reset alpha flag */
string++;
}
return (s);
}
void timer (interval)
int interval;
{
long timeout, timerset ();
timeout = timerset ((unsigned int) (interval * 10));
while (!timeup (timeout))
time_release ();
}
void big_pause (secs)
int secs;
{
long timeout, timerset ();
timeout = timerset ((unsigned int) (secs * 100));
while (!timeup (timeout))
{
if (CHAR_AVAIL ())
break;
time_release ();
}
}
int com_getc (t)
int t;
{
long t1;
extern long timerset ();
if (!CHAR_AVAIL ())
{
t1 = timerset ((unsigned int) (t * 100));
while (!CHAR_AVAIL ())
{
if (timeup (t1))
{
return (EOF);
}
/*
* This should work because we only do TIMED_READ when we have
* carrier
*/
if (!CARRIER)
{
return (EOF);
}
time_release ();
}
}
return ((unsigned int)(MODEM_IN ()) & 0x00ff);
}
/* Z F R E E -- Return total number of free bytes on drive specified */
#ifdef OS_2
long zfree (char *path)
{
int drive;
FSALLOCATE dt;
if (!path || !*path)
drive = 0;
else
drive = tolower (*path) - 'a' + 1;
DosQFSInfo (drive, 1, (char far *) &dt, sizeof (FSALLOCATE));
return ( dt.cSectorUnit * dt.cUnitAvail * dt.cbSector);
}
#else /* OS_2 */
long zfree (drive)
char *drive;
{
union REGS r;
unsigned char driveno;
long stat;
if (drive[0] != '\0' && drive[1] == ':')
{
driveno = (unsigned char) (islower (*drive) ? toupper (*drive) : *drive);
driveno = (unsigned char) (driveno - 'A' + 1);
}
else driveno = 0; /* Default drive */
r.x.ax = 0x3600; /* get free space */
r.h.dl = driveno; /* on this drive */
(void) int86 (0x21, &r, &r); /* go do it */
if (r.x.ax == 0xffff) /* error return?? */
return (0);
stat = (long) r.x.bx /* bx = clusters avail */
* (long) r.x.ax /* ax = sectors/clust */
* (long) r.x.cx; /* cx = bytes/sector */
return (stat);
}
#endif /* OS_2 */
void scr_printf (string)
char *string;
{
if (string != NULL)
#ifdef OS_2
VioWrtTTY (string, (USHORT) strlen (string), (HVIO) 0L);
#else
while (*string != 0)
WRITE_ANSI (*string++);
#endif
}
void send_can ()
{
int i;
CLEAR_OUTBOUND ();
CLEAR_INBOUND ();
for (i = 0; i < 10; i++)
SENDBYTE (CAN);
for (i = 0; i < 10; i++)
SENDBYTE (BS);
}
void invent_pkt_name (string)
char string[];
{
struct tm *tp;
time_t ltime;
(void) time (<ime);
tp = localtime (<ime);
(void) sprintf (string, "%02i%02i%02i%02i.pkt",
tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
}
static char *suffixes[8] = {
"SU", "MO", "TU", "WE", "TH", "FR", "SA", NULL
};
int is_user (p)
char *p;
{
char *q, *r;
int i, j;
if (cur_event < 0)
return (0);
q = strchr (p, '.');
if (q != NULL)
{
++q;
for (i = 0; i < 6; i++)
{
r = &(e_ptrs[cur_event]->err_extent[i][0]);
for (j = 0; j < 3; j++)
{
if ((tolower (q[j]) != tolower (r[j])) && (q[j] != '?'))
break;
}
if (j == 3)
user_exits[i] = 1;
}
}
return (0);
}
int is_arcmail (p, n)
char *p;
int n;
{
int i;
char c[128];
if (!isdigit (p[n]))
{
return (is_user (p));
}
(void) strcpy (c, p);
(void) strupr (c);
for (i = n - 11; i < n - 3; i++)
{
if ((!isdigit (c[i])) && ((c[i] > 'F') || (c[i] < 'A')))
return (is_user (p));
}
for (i = 0; i < 7; i++)
{
if (strnicmp (&c[n - 2], suffixes[i], 2) == 0)
break;
}
if (i >= 7)
{
return (is_user (p));
}
got_arcmail = 1;
return (1);
}
int get_number (target)
char *target;
{
ADDR gaddr;
int k;
(void) fgets (target, 100, stdin);
k = (int) strlen (target);
if (k == 1)
return (0);
target[--k] = '\0'; /* no '\n' */
if (!isdigit (target[0]) && target[0] != '\"')
{
fidouser (target, &gaddr);
if ((gaddr.Net != -1) && (gaddr.Node != -1) && (gaddr.Zone != -1))
{
sprintf (target, "%s", Full_Addr_Str (&gaddr));
}
else return (0); /* Gotta have addr */
}
return (1);
}
void gong ()
{
long t, timerset ();
int i;
if (!gong_allowed)
return;
for (i = 0; i < 15; i++)
{
WRITE_ANSI ('\07'); /* Bell code */
t = timerset (100); /* 1 second */
while (!timeup (t))
{
if (KEYPRESS ()) /* If key pressed, */
{
(void) READKB (); /* Throw it away */
return; /* And get out */
}
}
}
}
char *skip_blanks (string)
char *string;
{
while (*string && isspace (*string))
++string;
return (string);
}
char *skip_to_blank (string)
char *string;
{
while (*string && (!isspace (*string)))
++string;
return (string);
}
#ifdef DEBUG
void show_debug_name (string)
char *string;
{
int x, y;
static char *filler = " ";
x = wherex ();
y = wherey ();
gotoxy (40, 0);
scr_printf (string);
scr_printf (&filler[strlen (string)]);
gotoxy (x, y);
}
#endif
int parse (input, list)
char *input;
struct parse_list list[];
{
int i;
for (i = 0; list[i].p_length; i++)
{
if (strnicmp (input, list[i].p_string, (unsigned int) list[i].p_length) == 0)
return (++i);
}
return (-1);
}
void change_prompt ()
{
char *s;
if (newstring[0])
{
(void) putenv (newstring);
return;
}
(void) strcpy (newstring, "PROMPT=[");
(void) strcat (newstring, xfer_id);
#ifdef OVERLAYS
(void) strcat (newstring, "-Overlay");
#endif
(void) strcat (newstring, " Shell]$_");
s = getenv ("PROMPT");
if (s)
{
(void) strcat (newstring, s);
}
else
{
(void) strcat (newstring, "$P$G");
}
(void) putenv (newstring);
}
void update_files (t)
int t;
{
char s[10];
if (un_attended && fullscreen)
{
if (t)
{
++hist.files_out;
}
else
{
++hist.files_in;
}
sb_move (historywin, HIST_FILE_ROW, HIST_COL);
(void) sprintf (s, "%d/%d", hist.files_in, hist.files_out);
sb_puts (historywin, (unsigned char *) s);
sb_show ();
}
}
static char *last_str[] = {
" None ",
" WaZOO ",
" FTS-0001",
" BBS ",
" Ext Mail"
};
void last_type (n, taddr)
int n;
ADDR *taddr;
{
int i;
char *p;
char j[20];
if (fullscreen)
sb_move (historywin, HIST_LAST_ROW, HIST_COL2);
if ((n == 1) || (n == 2))
{
if ((taddr->Zone != -1000) && (taddr->Net > 0))
{
(void) sprintf (j, "%s", Full_Addr_Str (taddr));
if ((p = strchr (j, '@')) != NULL)
*p = '\0';
for (i = (int) strlen (j); i < 13; i++)
j[i] = ' ';
j[i] = '\0';
hist.last_zone = taddr->Zone;
hist.last_net = taddr->Net;
hist.last_node = taddr->Node;
}
else
{
(void) strcpy (j, " FTS-0001");
}
if (fullscreen)
sb_puts (historywin, (unsigned char *) j);
}
else
{
if ((n < 0) || (n > 4))
n = 0;
if (fullscreen)
sb_puts (historywin, (unsigned char *) last_str[n]);
}
hist.last_caller = n;
}
/*--------------------------------------------------------------------------*/
/* CHECK_NETFILE -- find out if the file we've got is a netfile. */
/*--------------------------------------------------------------------------*/
char *check_netfile (fname)
char *fname;
{
register char *p;
register int n;
p = fname;
n = (int) strlen (p) - 1;
if ((p[n] == 't') && (p[n - 1] == 'k') && (p[n - 2] == 'p') && (p[n - 3] == '.'))
{
got_packet = 1;
got_mail = 1;
p = msgtxt[M_MAIL_PACKET];
}
else if (is_arcmail (p, n))
{
got_mail = 1;
p = msgtxt[M_COMPRESSED_MAIL];
}
else
{
/* Don't set 'got_mail' if it's a .REQ file */
if ((p[n] != 'q') || (p[n - 1] != 'e') || (p[n - 2] != 'r') || (p[n - 3] != '.'))
got_mail = 1;
p = msgtxt[M_NET_FILE];
}
return (p);
}
/*--------------------------------------------------------------------------*/
/* UNIQUE_NAME */
/* Increments the suffix of a filename as necessary to make the name unique */
/*--------------------------------------------------------------------------*/
void unique_name (fname)
char *fname;
{
static char suffix[] = ".001";
register char *p;
register int n;
if (dexists (fname))
{ /* If file already exists... */
p = fname;
while (*p && *p != '.')
p++; /* ...find the extension, if
* any */
for (n = 0; n < 4; n++) /* ...fill it out if
* neccessary */
if (!*p)
{
*p = suffix[n];
*(++p) = '\0';
}
else p++;
while (dexists (fname)) /* ...If 'file.ext' exists
* suffix++ */
{
p = fname + strlen (fname) - 1;
for (n = 3; n--;)
{
if (!isdigit (*p))
*p = '0';
if (++(*p) <= '9')
break;
else *p-- = '0';
} /* for */
} /* while */
} /* if exist */
} /* unique_name */
int got_ESC ()
{
while (KEYPRESS ())
{
screen_blank = 0;
if (fullscreen && un_attended)
sb_show ();
if (READKB () == 27) /* ESC pressed? */
{
while (KEYPRESS ())
(void) READKB ();
return (1);
}
}
return (0);
}
long cost_of_call (s, e)
long s, e;
{
long a;
a = e - s;
a = (a + 59) / 60;
return (a * newnodedes.RealCost);
}
void screen_clear ()
{
register int r;
unsigned int far *q;
if (!vfossil_installed)
scr_printf ("\033[H\033[2J");
else
{
for (r = 0; r <= SB_ROWS; r++)
{
q = (unsigned int far *) blanks;
#ifndef OS_2
(void) VioWrtCellStr (q, SB_COLS * 2, r, 0, 0);
#else
(void) VioWrtCellStr ((PCH) q, (USHORT) (SB_COLS * 2), (USHORT) r, (USHORT) 0, (HVIO) 0L);
#endif
}
gotoxy (0, 0);
}
}
void clear_eol ()
{
int x, y;
unsigned int far *q;
if (!vfossil_installed)
(void) printf ("\033[K");
else
{
x = wherex();
y = wherey();
q = (unsigned int far *) blanks;
#ifndef OS_2
(void) VioWrtCellStr (q, (SB_COLS - (unsigned) x) * 2, y, x, 0);
#else
(void) VioWrtCellStr ((PCH) q, (USHORT) ((SB_COLS - x) * 2), (USHORT) y, (USHORT) x, (HVIO) 0L);
#endif
}
}
void log_product (product, version, subversion)
int product;
int version;
int subversion;
{
switch (product)
{
case isBITBRAIN :
case isFIDO :
case isSPARK :
case isSEA :
case isSlick :
case isHENK :
case isTABBIE :
case isWOLF :
case isQMM :
case isFD :
case isGSPOINT :
case isBGMAIL :
case isCROSSBOW :
case isDBRIDGE :
case isDAISY :
case isPOLAR :
case isTHEBOX :
case isWARLOCK :
case isTCOMM :
case isBANANNA :
case isAPPLE :
case isCHAMELEON:
case isMAJIK :
case isDOMAIN :
case isLESROBOT :
case isROSE :
case isPARAGON :
case isBINKST :
case isSTARNET :
case isQUICKBBS :
case isPBBS :
case isTRAPDOOR :
case isWELMAT :
case isTIMS :
case isISIS :
status_line ("%s %s %s %d.%02d", msgtxt[M_REMOTE_USES],
prodcode[product], msgtxt[M_VERSION], version, subversion);
break;
case isOPUS:
status_line ("%s Opus %s %d.%02d", msgtxt[M_REMOTE_USES],
msgtxt[M_VERSION], version,
(subversion == 48) ? 0 : subversion);
break;
default:
status_line ("%s %s '%02x' %s %d.%02d", msgtxt[M_REMOTE_USES],
msgtxt[M_PROGRAM], product,
msgtxt[M_VERSION], version, subversion);
break;
}
return;
}
int next_minute ()
{
int hours, mins, secs, ths;
/* Get the DOS time */
dostime (&hours, &mins, &secs, &ths);
return ((60 - (secs % 60)) * 100 + 1);
}
void can_Janus (p)
char *p;
{
J_TYPESP j;
janus_OK = 0;
for (j = j_top; j != NULL; j = j->next)
{
if (strnicmp (p, j->j_match, strlen (j->j_match)) == 0)
{
janus_OK = 1;
break;
}
}
}
int check_failed (fname, theirname, info, ourname)
char *fname, *theirname, *info, *ourname;
{
FILE *abortlog;
char linebuf[64];
char *p, *badname;
int ret;
ret = 0;
if ((abortlog = fopen (fname, read_ascii)) == NULL)
{
(void) got_error (msgtxt[M_OPEN_MSG], fname);
}
else
{
while (!feof (abortlog))
{
linebuf[0] = '\0';
if (!fgets ((p = linebuf), 64, abortlog))
break;
while (*p >= ' ')
++p;
*p = '\0';
p = strchr (linebuf, ' ');
*p = '\0';
if (!stricmp (linebuf, theirname))
{
p = strchr ((badname = ++p), ' ');
*p = '\0';
if (!stricmp (++p, info))
{
strcpy (ourname, badname);
ret = 1;
break;
}
}
}
fclose (abortlog);
}
return (ret);
}
void add_abort (fname, rname, cname, cpath, info)
char *fname, *rname, *cname, *cpath, *info;
{
FILE *abortlog;
char namebuf[100];
strcpy (namebuf, cpath);
strcat (namebuf, "BadWaZOO.001");
unique_name (namebuf);
rename (cname, namebuf);
if ((abortlog = fopen (fname, "at")) == NULL)
{
(void) got_error (msgtxt[M_OPEN_MSG], fname);
unlink (namebuf);
}
else
{
fprintf (abortlog, "%s %s %s\n", rname, namebuf + strlen (cpath), info);
fclose (abortlog);
}
}
void remove_abort (fname, rname)
char *fname, *rname;
{
FILE *abortlog, *newlog;
char namebuf[100];
char linebuf[100];
char *p;
int c;
if (!dexists (fname))
return;
if ((abortlog = fopen (fname, read_ascii)) == NULL)
{
(void) got_error (msgtxt[M_OPEN_MSG], fname);
}
else
{
strcpy (namebuf, fname);
strcpy (namebuf + strlen (namebuf) - 1, "TMP");
c = 0;
if ((newlog = fopen (namebuf, write_ascii)) == NULL)
{
(void) got_error (msgtxt[M_OPEN_MSG], namebuf);
fclose (abortlog);
}
else
{
while (!feof (abortlog))
{
linebuf[0] = '\0';
if (!fgets (linebuf, 64, abortlog))
break;
p = linebuf;
while (*p > ' ')
++p;
*p = '\0';
if (stricmp (linebuf, rname))
{
*p = ' ';
fputs (linebuf, newlog);
++c;
}
}
fclose (abortlog);
fclose (newlog);
unlink (fname);
if (c)
rename (namebuf, fname);
else unlink (namebuf);
}
}
}
/*
* The next routine is used in the count down timer during file
* transfers, and were provided by Jon Sabol, along with the other code that
* calls these routines.
*/
void elapse_time ()
{
time_t ltime;
long eh;
long em;
long es;
if (fullscreen && (un_attended || doing_poll))
{
time (<ime);
if (ltime < etm)
ltime += 86400L;
eh = (ltime - etm) / 3600L;
em = ((ltime - etm) / 60L) - (eh * 60L);
es = (ltime - etm) - (eh * 3600L) - (em * 60L);
sb_move (settingswin, SET_TASK_ROW, SET_TIME_COL);
sprintf (junk, "%s: %02ld:%02ld:%02ld", msgtxt[M_ELAPSED], eh, em, es);
sb_puts (settingswin, junk);
sb_show ();
}
}
static int find_addr (node, addr, d)
char *node;
ADDR *addr;
char *d;
{
int ret;
ret = 1;
if (alias[0].Node == -1)
addr->Zone = 0;
else
addr->Zone = alias[0].Zone;
addr->Net = 0;
addr->Node = 0;
addr->Point = 0;
addr->Domain = NULL;
d[0] = '\0';
if ((ret = sscanf (node, "%d:%d/%d.%d@%s",
&(addr->Zone), &(addr->Net), &(addr->Node), &(addr->Point), d)) < 3)
{
if (alias[0].Node == -1)
addr->Zone = 0;
else
addr->Zone = alias[0].Zone;
if ((ret = sscanf (node, "%d/%d.%d@%s",
&(addr->Net), &(addr->Node), &(addr->Point), d)) < 2)
{
addr->Net = alias[0].Net;
if (sscanf (node, "%d.%d@%s",
&(addr->Node), &(addr->Point), d) < 1)
{
ret = 0;
}
else if (ret == 1)
{
(void) sscanf (node, "%d@%s",
&(addr->Node), d);
}
}
else if (ret == 2)
{
(void) sscanf (node, "%d/%d@%s",
&(addr->Net), &(addr->Node), d);
}
}
else if (ret == 3)
{
(void) sscanf (node, "%d:%d/%d@%s",
&(addr->Zone), &(addr->Net), &(addr->Node), d);
}
return (ret);
}
int parse_address (node, addr)
char *node;
ADDR *addr;
{
int ret;
char d[100];
ret = find_addr (node, addr, d);
if (d[0] != '\0')
{
addr->Domain = add_domain (d);
}
return (ret);
}
int find_address (node, addr)
char *node;
ADDR *addr;
{
int ret;
char d[100];
char *p;
d[0] = '\0';
p = skip_blanks (node);
if (!isdigit (*p))
{
fidouser (p, addr);
if ((addr->Net == -1) || (addr->Node == -1) || (addr->Zone == -1))
{
ret = 0;
}
else
{
ret = 1;
}
}
else
{
ret = find_addr (p, addr, d);
}
if (d[0] != '\0')
{
addr->Domain = find_domain (d);
}
return (ret);
}
char *add_domain (d)
char *d;
{
char *p;
int i;
for (i = 0; (p = domain_name[i]) != NULL; i++)
{
if (strnicmp (d, p, strlen (p)) == 0)
return (p);
}
if (i >= 49)
return (NULL);
domain_name[i] = strdup (d);
return (domain_name[i]);
}
char *find_domain (d)
char *d;
{
char *p, *q, *s;
char c;
int i, j, k;
j = strlen (d);
/* First see if we can find the whole domain name at the right */
for (i = 0; (p = domain_name[i]) != NULL; i++)
{
k = strlen (p);
if (k > j)
continue;
q = &(d[j - k]);
if (strnicmp (q, p, k) == 0)
{
return (p);
}
}
/* Ok, now see if we can find the abbreviated name at the right */
for (i = 0; (p = domain_abbrev[i]) != NULL; i++)
{
k = strlen (p);
if (k > j)
continue;
q = &(d[j - k]);
if (strnicmp (q, p, k) == 0)
{
return (domain_name[i]);
}
}
/* If there is a period in it, see if we can match the abbreviated name
just before the period */
if ((s = strrchr (d, '.')) != NULL)
{
c = *s;
*s = '\0';
j = strlen (d);
for (i = 0; (p = domain_abbrev[i]) != NULL; i++)
{
k = strlen (p);
if (k > j)
continue;
q = &(d[j - k]);
if (strnicmp (q, p, k) == 0)
{
*s = c;
return (domain_name[i]);
}
}
*s = c;
}
return (NULL);
}
char addr_str[100];
char *Hex_Addr_Str (a)
ADDR *a;
{
sprintf (addr_str, "%04x%04x", a->Net, a->Node);
return (addr_str);
}
char *Full_Addr_Str (a)
ADDR *a;
{
char t1[10];
char t2[30];
char t3[10];
char t4[50];
if (a->Zone && !no_zones)
sprintf (t1, "%u:", a->Zone);
else
t1[0] = '\0';
sprintf (t2, "%u/%u", a->Net, a->Node);
if (a->Point)
sprintf (t3, ".%u", a->Point);
else
t3[0] = '\0';
if (a->Domain != NULL)
sprintf (t4, "@%s", a->Domain);
else
t4[0] = '\0';
strcpy (addr_str, t1);
strcat (addr_str, t2);
strcat (addr_str, t3);
strcat (addr_str, t4);
return (addr_str);
}
unsigned int crc_block(ptr, count)
unsigned char *ptr;
int count;
{
unsigned int crc;
int i;
for (crc = 0, i = 0; i < count; i++, ptr++)
{
crc = xcrc (crc, (byte) *ptr);
}
return (crc & 0xFFFF);
}
void Data_Check (xtmp, mode)
XMDATAP xtmp;
int mode;
{
int i;
unsigned char cs;
unsigned char *cp;
unsigned int cs1;
/* If we are in checksum mode, just do it */
if (mode == CHECKSUM)
{
cp = xtmp->data_bytes;
cs = 0;
for (i = 0; i < 128; i++)
{
cs += *cp++;
}
xtmp->data_check[0] = cs;
}
/* If we are in CRC mode, run the characters through the CRC calculator */
else
{
cs1 = crc_block (xtmp->data_bytes, 128);
xtmp->data_check[0] = (unsigned char) (cs1 >> 8);
xtmp->data_check[1] = (unsigned char) (cs1 & 0xff);
}
}
static int buff_bytes = 0;
FILE *buff_fopen (fname, fmode)
char *fname;
char *fmode;
{
buff_bytes = 0;
return (fopen (fname, fmode));
}
int buff_fwrite (buff, size1, size2, fp)
char *buff;
int size1;
int size2;
FILE *fp;
{
if ((buff_bytes + (size1 * size2)) > WAZOOMAX)
{
(void) fwrite (Secbuf, 1, buff_bytes, fp);
buff_bytes = 0;
}
memcpy (Secbuf + buff_bytes, buff, size1 * size2);
buff_bytes += size1 * size2;
return (size1 * size2);
}
int buff_fclose (fp)
FILE *fp;
{
(void) fwrite (Secbuf, 1, buff_bytes, fp);
buff_bytes = 0;
return (fclose (fp));
}
long buff_fseek (fp, a, b)
FILE *fp;
long a;
int b;
{
(void) fwrite (Secbuf, 1, buff_bytes, fp);
buff_bytes = 0;
return (fseek (fp, a, b));
}
#ifdef OS_2
void set_prior (int pclass)
{
char *s;
static USHORT regular = 0;
static USHORT janus = 0;
static USHORT modem = 0;
USHORT priority;
switch (pclass)
{
case 2:
if (regular)
priority = regular;
else
{
s = getenv("REGULARPRIORITY");
if (s)
priority = regular = atoi(s);
else
priority = regular = 2;
}
break;
case 3:
if (janus)
priority = janus;
else
{
s = getenv("JANUSPRIORITY");
if (s)
priority = janus = atoi(s);
else
priority = janus = 3;
}
break;
case 4:
if (modem)
priority = modem;
else
{
s = getenv("MODEMPRIORITY");
if (s)
priority = modem = atoi(s);
else
priority = modem = 4;
}
break;
default:
priority = 2;
break;
}
(void) DosSetPrty ((USHORT) 1, priority, (SHORT) 31, (USHORT) 0);
}
#ifdef Snoop
#pragma check_stack(off)
static int far pascal _loadds mesgfunc(int error, char far *mesg)
{
if(!error)
status_line(":%Fs", mesg);
else
status_line("!SYS%04u : %Fs", error, mesg);
return(0);
}
#pragma check_stack()
void snoop_open(char *pipename)
{
static char *pipe = NULL;
if(pipe)
free(pipe);
if(pipename)
pipe = strdup(pipename);
SnoopOpen(pipe, &hsnoop, xfer_id, (PFNSN)mesgfunc);
}
void snoop_close(void)
{
if(hsnoop)
SnoopClose(hsnoop);
hsnoop = (HSNOOP)NULL;
}
#endif /* Snoop */
#else /* OS_2 */
void set_prior (int pclass)
{
return;
pclass = 5;
}
#endif /* OS_2 */