ckuusx.c
资源名称:cku197.tar.Z [点击查看]
上传用户:dufan58
上传日期:2007-01-05
资源大小:3407k
文件大小:192k
源码类别:
通讯/手机编程
开发平台:
Windows_Unix
- #include "ckcsym.h"
- /* C K U U S X -- "User Interface" common functions. */
- /*
- Author: Frank da Cruz <fdc@columbia.edu>,
- Columbia University Academic Information Systems, New York City.
- Copyright (C) 1985, 2000,
- Trustees of Columbia University in the City of New York.
- All rights reserved. See the C-Kermit COPYING.TXT file or the
- copyright text in the ckcmai.c module for disclaimer and permissions.
- */
- /*
- This module contains user interface functions needed by both the interactive
- user interface and the command-line-only user interface.
- */
- /* Includes */
- #include "ckcdeb.h"
- #include "ckcasc.h"
- #include "ckcker.h"
- #include "ckuusr.h"
- #include "ckcxla.h"
- #ifndef NOHTERMCAP
- #ifdef NOTERMCAP
- #define NOHTERMCAP
- #else
- #ifndef BSD44
- #define NOHTERMCAP
- #else
- #ifdef __bsdi__
- #define NOHTERMCAP
- #else
- #ifdef OPENBSD
- #define NOHTERMCAP
- #else
- #ifdef MACOSX
- #define NOHTERMCAP
- #endif /* MACOSX */
- #endif /* OPENBSD */
- #endif /* __bsdi__ */
- #endif /* BSD44 */
- #endif /* NOTERMCAP */
- #endif /* NOHTERMCAP */
- #ifndef NOTERMCAP
- #ifdef BSD44
- #ifndef NOHTERMCAP
- #include <termcap.h>
- #endif /* NOHTERMCAP */
- #endif /* BSD44 */
- #else /* !BSD44 */
- #ifdef linux
- #include <term.h>
- #endif /* linux */
- #endif /* NOTERMCAP */
- #ifdef OS2
- #include <string.h>
- _PROTOTYP(char * os2_gethostname, (void));
- #define getpid _getpid
- #endif /* OS2 */
- #ifdef BSD44
- #include <errno.h>
- #endif /* BSD44 */
- extern xx_strp xxstring;
- #ifdef OS2
- #include "ckcnet.h"
- #else /* OS2 */
- _PROTOTYP(int getlocalipaddr, (void));
- #ifndef NETCONN
- /*
- We should just pull in ckcnet.h here, but it causes a conflict with curses.h.
- */
- #ifdef TCPSOCKET
- #define NETCONN
- #else
- #ifdef SUNX25
- #define NETCONN
- #else
- #ifdef STRATUSX25
- #define NETCONN
- #else
- #ifdef IBMX25
- #define NETCONN
- #else
- #ifdef HPX25
- #define NETCONN
- #else
- #ifdef DECNET
- #define NETCONN
- #else
- #ifdef NPIPE
- #define NETCONN
- #else
- #ifdef CK_NETBIOS
- #define NETCONN
- #ifdef SUPERLAT
- #define NETCONN
- #else
- #endif /* SUPERLAT */
- #endif /* TCPSOCKET */
- #endif /* SUNX25 */
- #endif /* STRATUSX25 */
- #endif /* IBMX25 */
- #endif /* HPX25 */
- #endif /* DECNET */
- #endif /* NPIPE */
- #endif /* CK_NETBIOS */
- #endif /* NETCONN */
- #endif /* OS2 */
- #ifndef TCPSOCKET
- #ifdef MULTINET
- #define TCPSOCKET
- #endif /* MULTINET */
- #ifdef DEC_TCPIP
- #define TCPSOCKET
- #endif /* DEC_TCPIP */
- #ifdef WINTCP
- #define TCPSOCKET
- #endif /* WINTCP */
- #ifdef TCPWARE
- #define TCPSOCKET
- #endif /* TCPWARE */
- #endif /* TCPSOCKET */
- #ifdef OS2
- #ifdef NT
- #include <windows.h>
- #include <tapi.h>
- #include "ckntap.h"
- #else /* NT */
- #define INCL_VIO
- #include <os2.h>
- #endif /* NT */
- #ifdef COMMENT /* Would you believe */
- #undef COMMENT /* <os2.h> defines this ? */
- #endif /* COMMENT */
- #ifdef CK_NETBIOS
- #include "ckonbi.h"
- #endif /* CK_NETBIOS */
- #include "ckocon.h"
- extern ascreen commandscreen;
- #ifdef KUI
- #include "ikui.h"
- #endif /* KUI */
- #endif /* OS2 */
- #ifdef NT
- #include "cknwin.h"
- #endif /* NT */
- #ifdef OS2
- #include "ckowin.h"
- #endif /* OS2 */
- #ifdef CK_TAPI
- extern int tttapi;
- extern int tapipass;
- #endif /* CK_TAPI */
- #ifdef CK_KERBEROS
- #include "ckuath.h"
- #endif /* CK_KERBEROS */
- #ifndef WINTCP
- #include <signal.h>
- #endif /* WINTCP */
- #ifdef VMS
- #include <descrip.h>
- #include <ssdef.h>
- #include <stsdef.h>
- #ifndef OLD_VMS
- #include <lib$routines.h> /* Not for VAX C 2.3 */
- #else
- #include <libdef.h>
- #endif /* OLD_VMS */
- #ifdef WINTCP
- #include <signal.h>
- #endif /* WINTCP */
- #endif /* VMS */
- int tt_crd = 0; /* Carriage return display */
- int interrupted = 0; /* Interrupted from keyboard flag */
- static int fxd_inited = 0; /* Fullscreen stuff initialized */
- #ifdef DEBUG
- char debfil[CKMAXPATH+1]; /* Debugging log file name */
- #endif /* DEBUG */
- #ifdef TLOG
- char trafil[CKMAXPATH+1]; /* Transaction log file name */
- #endif /* TLOG */
- char sesfil[CKMAXPATH+1]; /* Session log file name */
- #ifdef CKLOGDIAL
- char diafil[CKMAXPATH+1]; /* Connection log file name */
- char cxlogbuf[CXLOGBUFL+1]; /* Connection log record buffer */
- int cx_active = 0; /* Connection is active */
- extern int dialog;
- #endif /* CKLOGDIAL */
- #ifdef DYNAMIC
- static char *cmdstr = NULL; /* Place to build generic command */
- #else
- #ifdef pdp11
- static char cmdstr[256];
- #else
- static char cmdstr[4096];
- #endif /* pdp11 */
- #endif /* DYNAMIC */
- #ifndef NOMSEND
- char fspec[CMDBL+4]; /* Filename string for v(filespec) */
- int fspeclen = CMDBL;
- #else
- char fspec[CKMAXPATH+4];
- int fspeclen = CKMAXPATH;
- #endif /* NOMSEND */
- char * rfspec = NULL;
- char * sfspec = NULL;
- char * srfspec = NULL;
- char * rrfspec = NULL;
- #ifdef CK_TTGWSIZE
- int xaskmore = 0; /* Whether to use more-prompting */
- #else
- int xaskmore = 1;
- #endif /* CK_TTGWSIZE */
- extern int saveask;
- int success = 1, /* Command success/failure flag */
- cmdlvl = 0, /* Command level */
- #ifndef NOSPL
- #endif /* NOSPL */
- action, /* Action selected on command line */
- #ifdef OS2
- sessft = XYFT_B, /* Session log file type */
- #else /* OS2 */
- sessft = XYFT_T, /* Session log file type */
- #endif /* OS2 */
- pflag = 1, /* Print prompt */
- msgflg = 1; /* Print informational messages */
- #ifdef CK_APC
- extern int apcactive;
- #endif /* CK_APC */
- /* External variables */
- extern int local, quiet, binary, network, what, parity, xitsta, escape,
- tlevel, bgset, backgrd, suspend, cmdint, nettype, seslog, dfloc;
- extern int cmd_rows, cmd_cols;
- extern char cmdfil[];
- #ifdef VMS
- extern int batch;
- #endif /* VMS */
- #ifdef datageneral /* 2/12/92 ENH */
- #include <sysid.h>
- extern int con_reads_mt, conint_ch, conint_avl;
- #endif /* datageneral */
- extern long speed;
- extern char ttname[], *dftty, *cmarg, **cmlist, *versio, myhost[];
- #ifndef NOCSETS
- extern int fcharset, tcharset;
- extern struct csinfo fcsinfo[], tcsinfo[];
- #endif /* NOCSETS */
- #ifdef NOXFER
- int fdispla = XYFD_N;
- #else /* NOXFER is not defined */
- #ifdef OS2 /* File transfer display type */
- int fdispla = XYFD_C; /* Curses (fullscreen) if we have it */
- #else
- #ifdef CK_CURSES
- int fdispla = XYFD_C;
- #else
- int fdispla = XYFD_S; /* Otherwise CRT */
- #endif /* CK_CURSES */
- #endif /* OS2 */
- extern struct ck_p ptab[];
- extern int protocol, xfrbel, xfrint;
- #ifdef STREAMING
- extern int streaming, streamok;
- #endif /* STREAMING */
- /* Used internally */
- _PROTOTYP( VOID screenc, (int, char, long, char *) );
- #ifdef CK_CURSES
- #ifndef DYNAMIC
- static char xtrmbuf[TRMBUFL]; /* tgetent() buffer */
- char * trmbuf = xtrmbuf;
- #else
- char * trmbuf = NULL;
- #endif /* DYNAMIC */
- _PROTOTYP( static VOID dpyinit, (void) );
- _PROTOTYP( static long shocps, (int, long, long) );
- _PROTOTYP( static long shoetl, (long, long, long, long) );
- #endif /* CK_CURSES */
- static int ft_win = 0; /* Fullscreen file transfer display window is active */
- /* Variables declared here */
- char pktfil[CKMAXPATH+1]; /* Packet log file name */
- #ifndef NOMSEND /* Multiple SEND */
- char *msfiles[MSENDMAX];
- #endif /* NOMSEND */
- #ifdef CK_TIMERS
- extern long rttdelay;
- extern int rttflg;
- #endif /* CK_TIMERS */
- extern int rcvtimo;
- #ifdef CK_RESEND
- extern int sendmode;
- extern long sendstart, rs_len;
- #endif /* CK_RESEND */
- #ifdef CK_PCT_BAR /* File transfer thermometer */
- int thermometer = 1; /* ON by default */
- #endif /* CK_PCT_BAR */
- #ifdef GFTIMER
- CKFLOAT gtv = -1.0, oldgtv = -1.0;
- #else
- #ifndef OS2
- static
- #endif /* OS2 */
- long gtv = -1L, oldgtv = -1L;
- #endif /* GFTIMER */
- #ifdef OS2
- extern unsigned char colorcmd;
- #endif /* OS2 */
- extern int server, bctu, rptflg, ebqflg, spsiz, urpsiz, wmax, czseen, cxseen,
- winlo, displa, timint, npad, ebq, bctr, rptq, atcapu, lpcapu,
- swcapu, wslotn, wslotr, rtimo, mypadn, sq, capas, rpsiz, tsecs,
- pktlog, lscapu, dest, srvdis, wslots, spackets, spktl, rpktl,
- retrans, wcur, numerrs, fsecs, whatru, crunched, timeouts,
- rpackets, fncnv, bye_active, discard, inserver;
- extern long filcnt, filrej, ffc, tfc, rptn, fsize, filcps, tfcps, cps, peakcps;
- long oldcps = 0L;
- extern CHAR *rdatap, padch, seol, ctlq, mypadc, eol, *epktmsg;
- extern char whoareu[];
- #ifdef IKSDB
- FILE * dbfp = NULL; /* File pointer to database file */
- int dbenabled = 1; /* Flag for database is enabled */
- extern int ikdbopen; /* Flag for database is open */
- unsigned long mydbseek = 0L; /* Seek pointer to my record */
- int mydbslot = 0; /* My slot number */
- unsigned long myflags = 0L; /* My flags */
- unsigned long myatype = 0L; /* My authorization type */
- unsigned long myamode = 0L; /* My authorization mode */
- unsigned long mystate = 0L; /* My state (SEND, RECEIVE, etc) */
- unsigned long mypid = 0L; /* My PID */
- unsigned long myip = 0L; /* My IP address */
- unsigned long peerip = 0L; /* My peer's IP address */
- unsigned long dbip = 0L; /* IP address in db record */
- unsigned long dbpid = 0L; /* PID in db record */
- unsigned long dbflags = 0L; /* Flags field in db record */
- unsigned long dblastused = 0L; /* Last in-use record in db */
- char dbrec[DB_RECL]; /* Database record buffer */
- char * dbdir = NULL; /* Database directory */
- char * dbfile = NULL; /* Database file full pathname */
- char myhexip[33] = { NUL, NUL }; /* My IP address in hex */
- char peerhexip[33] = { NUL, NUL }; /* Client's IP address in hex */
- #endif /* IKSDB */
- #ifdef GFTIMER
- extern CKFLOAT fpfsecs, fptsecs, fpxfsecs;
- #else
- extern long xfsecs;
- #endif /* GFTIMER */
- #endif /* NOXFER */
- #ifdef TCPSOCKET
- extern char myipaddr[];
- #endif /* TCPSOCKET */
- #ifndef NOICP
- #ifndef NOSPL
- extern struct mtab *mactab; /* For ON_EXIT macro. */
- extern int nmac;
- #endif /* NOSPL */
- #ifdef DCMDBUF
- extern char *cmdbuf; /* Command buffer */
- #else
- extern char cmdbuf[]; /* Command buffer */
- #endif /* DCMDBUF */
- extern int cmd_quoting;
- #endif /* NOICP */
- #ifndef NOCCTRAP
- #ifdef NT
- #include <setjmpex.h>
- #else /* NT */
- #include <setjmp.h>
- #endif /* NT */
- #include "ckcsig.h"
- extern ckjmpbuf cmjbuf;
- #endif /* NOCCTRAP */
- #ifndef NOXFER
- /* P R E S E T -- Reset global protocol variables */
- extern int recursive;
- #ifndef NOICP
- #ifdef CK_LABELED
- extern int g_lf_opts, lf_opts;
- #endif /* CK_LABELED */
- extern int g_matchdot;
- extern int g_binary, g_proto, g_displa, g_spath, g_rpath, g_fncnv;
- extern int g_recursive;
- extern int g_xfermode, xfermode;
- extern int g_urpsiz, g_spsizf, g_spsiz;
- extern int g_spsizr, g_spmax, g_wslotr, g_prefixing, g_fnact, g_fncact;
- extern int g_fnspath, g_fnrpath, g_skipbup;
- #ifndef NOSPL
- extern int g_pflg, pwflg, g_pcpt, pwcrypt;
- extern char * g_pswd, pwbuf[];
- #endif /* NOSPL */
- #ifdef PATTERNS
- extern int g_patterns, patterns;
- #endif /* PATTERNS */
- #endif /* NOICP */
- extern int spsizf, spsizr, spmax, prefixing, fncact, fnspath, fnrpath;
- extern int moving; /* SEND criteria */
- extern char sndafter[], sndbefore[], *sndexcept[], *rcvexcept[];
- extern long sndlarger, sndsmaller, calibrate, skipbup;
- extern int rmailf, rprintf;
- extern char optbuf[];
- #ifdef PIPESEND
- extern char * g_sfilter, * g_rfilter;
- extern char * sndfilter, * rcvfilter;
- #endif /* PIPESEND */
- VOID
- ftreset() {
- #ifndef NOICP
- int i;
- extern char * filefile;
- extern int reliable, xreliable, c_save, ss_save, slostart, urclear;
- extern int oopts, omode, oname, opath, kactive, autopath;
- extern char * snd_move; /* Directory to move sent files to */
- extern char * snd_rename; /* What to rename sent files to */
- extern char * rcv_move;
- extern char * rcv_rename;
- extern char * g_snd_move;
- extern char * g_snd_rename;
- extern char * g_rcv_move;
- extern char * g_rcv_rename;
- #ifdef CK_SPEED
- extern int f_ctlp;
- #ifdef COMMENT
- extern short s_ctlp[], ctlp[];
- #endif /* COMMENT */
- #endif /* CK_SPEED */
- #ifndef NOCSETS
- extern int fcs_save, tcs_save;
- #endif /* NOCSETS */
- /* Restore / reset per-command file-transfer switches */
- makestr(&snd_move,g_snd_move);
- makestr(&rcv_move,g_rcv_move);
- makestr(&snd_rename,g_snd_rename);
- makestr(&rcv_rename,g_rcv_rename);
- kactive = 0; /* Kermit protocol no longer active */
- oopts = -1; /* O-Packet Options */
- omode = -1; /* O-Packet Transfer Mode */
- oname = -1; /* O-Packet Filename Options */
- opath = -1; /* O-Packet Pathname Options */
- #ifdef COMMENT
- #ifdef CK_SPEED
- if (f_ctlp) {
- for (i = 0; i < 256; i++)
- ctlp[i] = s_ctlp[i];
- f_ctlp = 0;
- }
- #endif /* CK_SPEED */
- #endif /* COMMENT */
- calibrate = 0L; /* Calibration run */
- if (xreliable > -1)
- reliable = xreliable;
- urclear = 0;
- if (autopath) { /* SET RECEIVE PATHNAMES AUTO */
- fnrpath = PATH_AUTO;
- autopath = 0;
- }
- if (filefile) { /* File list */
- zclose(ZMFILE);
- makestr(&filefile,NULL);
- }
- if (c_save > -1) { /* Block Check Type */
- bctr = c_save;
- c_save = -1;
- }
- if (ss_save > -1) { /* Slow Start */
- slostart = ss_save;
- ss_save = -1;
- }
- #ifdef CK_LABELED
- if (g_lf_opts > -1) {
- lf_opts = g_lf_opts; /* Restore labeled transfer options */
- g_lf_opts = -1;
- }
- #endif /* CK_LABELED */
- #ifndef NOCSETS
- if (tcs_save > -1) { /* Character sets */
- tcharset = tcs_save;
- tcs_save = -1;
- }
- if (fcs_save > -1) {
- fcharset = fcs_save;
- fcs_save = -1;
- }
- setxlatype(tcharset,fcharset); /* Translation type */
- #endif /* NOCSETS */
- #ifdef NETCONN
- #ifndef NOSPL
- if (g_pswd) {
- ckstrncpy(pwbuf,g_pswd,PWBUFL);
- makestr(&g_pswd,NULL);
- }
- if (g_pflg > -1) {
- pwflg = g_pflg;
- g_pflg = -1;
- }
- if (g_pcpt > -1) {
- pwcrypt = g_pcpt;
- g_pcpt = -1;
- }
- #endif /* NOSPL */
- #endif /* NETCONN */
- if (g_binary > -1) { /* File type */
- binary = g_binary;
- g_binary = -1;
- }
- if (g_xfermode > -1) { /* Transfer mode */
- xfermode = g_xfermode;
- g_xfermode = -1;
- }
- #ifdef PATTERNS
- if (g_patterns > -1) { /* Filename patterns */
- patterns = g_patterns;
- g_patterns = -1;
- }
- #endif /* PATTERNS */
- if (g_matchdot > -1) {
- matchdot = g_matchdot;
- g_matchdot = -1;
- }
- if (saveask > -1) {
- xaskmore = saveask;
- saveask = -1;
- }
- if (g_proto > -1) { /* Protocol */
- protocol = g_proto;
- g_proto = -1;
- }
- if (g_urpsiz > -1) {
- urpsiz = g_urpsiz;
- debug(F101,"ftreset restoring urpsiz","",urpsiz);
- g_urpsiz = -1;
- }
- if (g_spsizf > -1) {
- spsizf = g_spsizf;
- debug(F101,"ftreset restoring spsizf","",spsizf);
- g_spsizf = -1;
- }
- if (g_spsiz > -1) {
- spsiz = g_spsiz;
- debug(F101,"ftreset restoring spsiz","",spsiz);
- g_spsiz = -1;
- }
- if (g_spsizr > -1) {
- spsizr = g_spsizr;
- debug(F101,"ftreset restoring spsizr","",spsizr);
- g_spsizr = -1;
- }
- if (g_spmax > -1) {
- spmax = g_spmax;
- g_spmax = -1;
- }
- if (g_wslotr > -1) {
- wslotr = g_wslotr;
- g_wslotr = -1;
- }
- if (g_prefixing > -1) {
- prefixing = g_prefixing;
- g_prefixing = -1;
- }
- if (g_fncact > -1) {
- fncact = g_fncact;
- g_fncact = -1;
- }
- if (g_fncnv > -1) {
- fncnv = g_fncnv;
- g_fncnv = -1;
- }
- if (g_fnspath > -1) {
- fnspath = g_fnspath;
- g_fnspath = -1;
- }
- if (g_fnrpath > -1) {
- fnrpath = g_fnrpath;
- g_fnrpath = -1;
- }
- if (g_skipbup > -1) {
- skipbup = g_skipbup;
- g_skipbup = -1;
- }
- recursive = 0; /* RECURSIVE can never be global */
- if (g_displa > -1) { /* File transfer display */
- fdispla = g_displa;
- g_displa = -1;
- }
- if (g_spath > -1) { /* Send pathnames */
- fnspath = g_spath;
- g_spath = -1;
- }
- if (g_rpath > -1) { /* Receive pathnames */
- fnrpath = g_rpath;
- g_rpath = -1;
- }
- if (g_fncnv > -1) { /* Filename conversion */
- fncnv = g_fncnv;
- g_fncnv = -1;
- }
- #ifdef PIPESEND
- if (g_sfilter) { /* Send filter */
- if (sndfilter) free(sndfilter);
- sndfilter = g_sfilter;
- g_sfilter = NULL;
- }
- if (g_rfilter) { /* Receive filter */
- if (rcvfilter) free(rcvfilter);
- rcvfilter = g_rfilter;
- g_rfilter = NULL;
- }
- #endif /* PIPESEND */
- #ifndef NOFRILLS
- rmailf = rprintf = 0; /* MAIL and PRINT modifiers for SEND */
- optbuf[0] = NUL; /* MAIL and PRINT options */
- #endif /* NOFRILLS */
- moving = 0; /* Reset delete-after-send indicator */
- sndafter[0] = NUL; /* Reset SEND selection switches */
- sndbefore[0] = NUL;
- for (i = 0; i < 8; i++) {
- if (sndexcept[i])
- free(sndexcept[i]);
- sndexcept[i] = NULL;
- if (rcvexcept[i])
- free(rcvexcept[i]);
- rcvexcept[i] = NULL;
- }
- sndlarger = -1L;
- sndsmaller = -1L;
- #ifdef GFTIMER
- gtv = -1.0;
- oldgtv = -1.0;
- #else
- gtv = -1L;
- oldgtv = -1L;
- #endif /* GFTIMER */
- #endif /* NOICP */
- }
- #endif /* NOXFER */
- /* C K _ E R R S T R -- Return message from most recent system error */
- char *
- ck_errstr() {
- #ifdef USE_STRERROR
- #ifndef CK_ANSILIBS
- /* Should have been declared in <string.h> */
- _PROTOTYP( char * strerror, (int) );
- #endif /* CK_ANSILIBS */
- return(strerror(errno));
- #else
- #ifdef VMS
- extern char * ckvmserrstr(unsigned long);
- return(ckvmserrstr(0L));
- #else
- #ifdef ATTSV
- #ifdef BSD44
- #ifdef __386BSD__
- #ifndef NDSYSERRLIST
- extern int sys_nerr;
- extern char *sys_errlist[];
- #endif /* NDSYSERRLIST */
- #else
- #ifndef __bsdi__
- #ifndef NDSYSERRLIST
- extern int sys_nerr;
- extern const char *const sys_errlist[];
- #endif /* NDSYSERRLIST */
- #endif /* __bsdi__ */
- #endif /* __386BSD__ */
- if (errno >= sys_nerr)
- return("Error number out of range");
- else
- return((char *) sys_errlist[errno]);
- #else /* !BSD44 */
- #ifndef NDSYSERRLIST
- extern int sys_nerr;
- extern char *sys_errlist[];
- #endif /* NDSYSERRLIST */
- if (errno >= sys_nerr)
- return("Error number out of range");
- else
- return((char *) sys_errlist[errno]);
- #endif /* BSD44 */
- #else /* !ATTSV */
- #ifdef BSD4
- #ifndef NDSYSERRLIST
- extern int sys_nerr;
- extern char *sys_errlist[];
- #endif /* NDSYSERRLIST */
- if (errno >= sys_nerr)
- return("Error number out of range");
- else
- return((char *) sys_errlist[errno]);
- #else
- #ifdef OS2
- #ifndef NDSYSERRLIST
- extern char *sys_errlist[];
- #endif /* NDSYSERRLIST */
- #ifdef NT
- extern int_sys_nerr;
- #endif /* NT */
- char *e;
- e = (errno > -1
- #ifdef NT
- && errno <= _sys_nerr
- #endif /* NT */
- ) ?
- #ifdef NT
- (char *) sys_errlist[errno]
- #else /* NT */
- /* I don't know how to get a CLIB error string in OS/2 */
- strerror(errno)
- #endif /* NT */
- : "";
- return(e ? e : "");
- #else /* OS2 */
- return("");
- #endif /* OS2 */
- #endif /* BSD4 */
- #endif /* ATTSV */
- #endif /* VMS */
- #endif /* USE_STRERROR */
- }
- #ifdef TCPSOCKET
- #ifdef NT
- extern int WSASafeToCancel;
- #endif /* NT */
- #endif /* TCPSOCKET */
- VOID
- setflow() {
- extern int flow, autoflow, mdmtyp, cxtype, cxflow[];
- #ifndef NODIAL
- extern int dialcapas, dialfc;
- extern MDMINF * modemp[];
- MDMINF * p = NULL;
- long bits = 0;
- #endif /* NODIAL */
- debug(F101,"setflow autoflow","",autoflow);
- /* #ifdef COMMENT */
- /* WHY WAS THIS COMMENTED OUT? */
- if (!autoflow) /* Only if FLOW is AUTO */
- return;
- /* #endif */ /* COMMENT */
- debug(F101,"setflow local","",local);
- debug(F101,"setflow network","",network);
- debug(F101,"setflow cxtype","",cxtype);
- if (network || !local || cxtype == CXT_DIRECT) {
- flow = cxflow[cxtype]; /* Set appropriate flow control */
- debug(F101,"setflow flow","",flow);
- return;
- }
- if (cxtype != CXT_MODEM) /* Connection type should be modem */
- return;
- #ifndef NODIAL
- bits = dialcapas; /* Capability bits */
- if (!bits) { /* No bits? */
- p = modemp[mdmtyp]; /* Look in modem info structure */
- if (p)
- bits = p->capas;
- }
- if (dialfc == FLO_AUTO) { /* If DIAL flow is AUTO */
- #ifdef CK_RTSCTS /* If we can do RTS/CTS flow control */
- if (bits & CKD_HW) /* and modem can do it too */
- flow = FLO_RTSC; /* then switch to RTS/CTS */
- else /* otherwise */
- flow = FLO_XONX; /* use Xon/Xoff. */
- #else
- #ifndef NEXT
- #ifndef IRIX
- flow = FLO_XONX; /* Use Xon/Xoff. */
- #endif /* IRIX */
- #endif /* NEXT */
- #endif /* CK_RTSCTS */
- }
- #endif /* NODIAL */
- debug(F101,"setflow modem flow","",flow);
- return;
- }
- #ifndef NOLOCAL
- #ifdef CK_TRIGGER
- /* A U T O E X I T C H K -- Check for CONNECT-mode trigger string */
- /*
- Returns -1 if trigger not found, or else the trigger index, 0 or greater.
- (Replace with fancier and more efficient matcher later...)
- NOTE: to prevent unnecessary function call overhead, call this way:
- x = tt_trigger[0] ? autoexitchk(c) : -1;
- */
- int
- #ifdef CK_ANSIC
- autoexitchk(CHAR c)
- #else
- autoexitchk(c) CHAR c;
- #endif /* CK_ANSIC */
- /* autoexitchk */ {
- extern CHAR * tt_trmatch[];
- extern char * tt_trigger[];
- int i, n;
- for (i = 0; i < TRIGGERS; i++) {
- if (!tt_trigger[i]) { /* No more triggers in list */
- break;
- } else if (*tt_trigger[i]) {
- if (!tt_trmatch[i]) /* Just starting? */
- tt_trmatch[i] = (CHAR *)tt_trigger[i]; /* Set match pointer */
- if (c == *tt_trmatch[i]) { /* Compare this character */
- tt_trmatch[i]++; /* It matches */
- if (!*tt_trmatch[i]) { /* End of match string? */
- tt_trmatch[i] = (CHAR *) tt_trigger[i]; /* Yes, rewind, */
- debug(F101,"autoexitchk",tt_trigger[i],i); /* log, */
- return(i); /* and return success */
- }
- } else /* No match */
- tt_trmatch[i] = (CHAR *) tt_trigger[i]; /* Rewind match string */
- } /* and go on the next match string */
- }
- return(-1); /* No match found */
- }
- #endif /* CK_TRIGGER */
- #ifndef NOSHOW
- /* S H O M D M -- Show modem signals */
- VOID
- shomdm() {
- /*
- Note use of "rn" to make sure this report prints right, even when
- called during CONNECT mode.
- */
- int y;
- y = ttgmdm();
- switch (y) {
- case -3: printf(
- "Modem signals unavailable in this version of Kermitrn");
- break;
- case -2: printf("No modem control for this devicern"); break;
- case -1: printf("Modem signals unavailablern"); break;
- default:
- #ifndef MAC
- printf(
- " Carrier Detect (CD): %srn",(y & BM_DCD) ? "On": "Off");
- printf(
- " Dataset Ready (DSR): %srn",(y & BM_DSR) ? "On": "Off");
- #endif /* MAC */
- printf(
- " Clear To Send (CTS): %srn",(y & BM_CTS) ? "On": "Off");
- #ifndef STRATUS
- #ifndef MAC
- printf(
- " Ring Indicator (RI): %srn",(y & BM_RNG) ? "On": "Off");
- #endif /* MAC */
- printf(
- " Data Terminal Ready (DTR): %srn",
- #ifdef NT
- "(unknown)"
- #else /* NT */
- (y & BM_DTR) ? "On": "Off"
- #endif /* NT */
- );
- #ifndef MAC
- printf(
- " Request To Send (RTS): %srn",
- #ifdef NT
- "(unknown)"
- #else /* NT */
- (y & BM_RTS) ? "On": "Off"
- #endif /* NT */
- );
- #endif /* MAC */
- #endif /* STRATUS */
- }
- #ifdef BETATEST
- #ifdef CK_TAPI
- if (tttapi && !tapipass) {
- LPDEVCFG lpDevCfg = NULL;
- LPCOMMCONFIG lpCommConfig = NULL;
- LPMODEMSETTINGS lpModemSettings = NULL;
- DCB * lpDCB = NULL;
- if (cktapiGetModemSettings(&lpDevCfg,&lpModemSettings,
- &lpCommConfig,&lpDCB)) {
- printf("n");
- cktapiDisplayModemSettings(lpDevCfg,lpModemSettings,
- lpCommConfig,lpDCB);
- }
- }
- #endif /* CK_TAPI */
- #endif /* BETATEST */
- }
- #endif /* NOSHOW */
- #endif /* NOLOCAL */
- #ifndef NOXFER
- /* S D E B U -- Record spar results in debugging log */
- VOID
- sdebu(len) int len; {
- debug(F111,"spar: data",(char *) rdatap,len);
- debug(F101," spsiz ","", spsiz);
- debug(F101," timint","",timint);
- debug(F101," npad ","", npad);
- debug(F101," padch ","", padch);
- debug(F101," seol ","", seol);
- debug(F101," ctlq ","", ctlq);
- debug(F101," ebq ","", ebq);
- debug(F101," ebqflg","",ebqflg);
- debug(F101," bctr ","", bctr);
- debug(F101," rptq ","", rptq);
- debug(F101," rptflg","",rptflg);
- debug(F101," lscapu","",lscapu);
- debug(F101," atcapu","",atcapu);
- debug(F101," lpcapu","",lpcapu);
- debug(F101," swcapu","",swcapu);
- debug(F101," wslotn","", wslotn);
- debug(F101," whatru","", whatru);
- }
- /* R D E B U -- Debugging display of rpar() values */
- VOID
- rdebu(d,len) CHAR *d; int len; {
- debug(F111,"rpar: data",d,len);
- debug(F101," rpsiz ","", xunchar(d[0]));
- debug(F101," rtimo ","", rtimo);
- debug(F101," mypadn","",mypadn);
- debug(F101," mypadc","",mypadc);
- debug(F101," eol ","", eol);
- debug(F101," ctlq ","", ctlq);
- debug(F101," sq ","", sq);
- debug(F101," ebq ","", ebq);
- debug(F101," ebqflg","",ebqflg);
- debug(F101," bctr ","", bctr);
- debug(F101," rptq ","", d[8]);
- debug(F101," rptflg","",rptflg);
- debug(F101," capas ","", capas);
- debug(F101," bits ","",d[capas]);
- debug(F101," lscapu","",lscapu);
- debug(F101," atcapu","",atcapu);
- debug(F101," lpcapu","",lpcapu);
- debug(F101," swcapu","",swcapu);
- debug(F101," wslotr","", wslotr);
- debug(F101," rpsiz(extended)","",rpsiz);
- }
- #ifdef COMMENT
- /* C H K E R R -- Decide whether to exit upon a protocol error */
- VOID
- chkerr() {
- if (backgrd && !server) fatal("Protocol error");
- }
- #endif /* COMMENT */
- #endif /* NOXFER */
- /* F A T A L -- Fatal error message */
- VOID
- fatal(msg) char *msg; {
- extern int initflg;
- if (!msg) msg = "";
- debug(F111,"fatal",msg,initflg);
- if (!initflg) /* In case called from prescan. */
- sysinit();
- #ifdef VMS
- if (strncmp(msg,"%CKERMIT",8))
- conol("%CKERMIT-E-FATAL, ");
- conoll(msg);
- #else /* !VMS */
- conoll(msg);
- #endif /* VMS */
- debug(F111,"fatal",msg,xitsta);
- tlog(F110,"Fatal:",msg,0L);
- #ifdef OS2
- if (xfrbel) bleep(BP_FAIL);
- sleep(1);
- if (xfrbel) bleep(BP_FAIL);
- #endif /* OS2 */
- doexit(BAD_EXIT,xitsta | 1); /* Exit indicating failure */
- }
- #ifndef NOXFER
- /* B L D L E N -- Make length-encoded copy of string */
- char *
- bldlen(str,dest) char *str, *dest; {
- int len;
- len = (int)strlen(str);
- if (len > 94)
- *dest = SP;
- else
- *dest = (char) tochar(len);
- strcpy(dest+1,str);
- return(dest+len+1);
- }
- /* S E T G E N -- Construct a generic command */
- /*
- Call with Generic command character followed by three string arguments.
- Trailing strings are allowed to be empty (""). Each string except the last
- non-empty string must be less than 95 characters long. The final nonempty
- string is allowed to be longer.
- */
- CHAR
- #ifdef CK_ANSIC
- setgen(char type, char * arg1, char * arg2, char * arg3)
- #else
- setgen(type,arg1,arg2,arg3) char type, *arg1, *arg2, *arg3;
- #endif /* CK_ANSIC */
- /* setgen */ {
- char *upstr, *cp;
- #ifdef DYNAMIC
- if (!cmdstr)
- if (!(cmdstr = malloc(MAXSP + 1)))
- fatal("setgen: can't allocate memory");
- #endif /* DYNAMIC */
- cp = cmdstr;
- *cp++ = type;
- *cp = NUL;
- if (!arg1) arg1 = "";
- if (!arg2) arg2 = "";
- if (!arg3) arg3 = "";
- if (*arg1 != NUL) {
- upstr = bldlen(arg1,cp);
- if (*arg2 != NUL) {
- upstr = bldlen(arg2,upstr);
- if (*arg3 != NUL) bldlen(arg3,upstr);
- }
- }
- cmarg = cmdstr;
- debug(F110,"setgen",cmarg,0);
- return('g');
- }
- #endif /* NOXFER */
- #ifndef NOMSEND
- static char *mgbufp = NULL;
- /* F N P A R S E -- */
- /*
- Argument is a character string containing one or more filespecs.
- This function breaks the string apart into an array of pointers, one
- to each filespec, and returns the number of filespecs. Used by server
- when it receives a GET command to allow it to process multiple file
- specifications in one transaction. Sets cmlist to point to a list of
- file pointers, exactly as if they were command line arguments.
- This version of fnparse treats spaces as filename separators. If your
- operating system allows spaces in filenames, you'll need a different
- separator.
- This version of fnparse mallocs a string buffer to contain the names. It
- cannot assume that the string that is pointed to by the argument is safe.
- */
- int
- fnparse(string) char *string; {
- char *p, *s, *q;
- int r = 0, x; /* Return code */
- #ifdef RECURSIVE
- debug(F111,"fnparse",string,recursive);
- #endif /* RECURSIVE */
- if (mgbufp) free(mgbufp); /* Free this from last time. */
- mgbufp = malloc((int)strlen(string)+2);
- if (!mgbufp) {
- debug(F100,"fnparse malloc error","",0);
- return(0);
- }
- #ifndef NOICP
- #ifndef NOSPL
- ckstrncpy(fspec,string,fspeclen); /* Make copy for v(filespec) */
- #endif /* NOSPL */
- #endif /* NOICP */
- s = string; /* Input string */
- p = q = mgbufp; /* Point to the copy */
- r = 0; /* Initialize our return code */
- while (*s == SP || *s == HT) /* Skip leading spaces and tabs */
- s++;
- for (x = strlen(s); /* Strip trailing spaces */
- (x > 1) && (s[x-1] == SP || s[x-1] == HT);
- x--)
- s[x-1] = NUL;
- while (1) { /* Loop through rest of string */
- if (*s == CMDQ) { /* Backslash (quote character)? */
- if ((x = xxesc(&s)) > -1) { /* Go interpret it. */
- *q++ = (char) x; /* Numeric backslash code, ok */
- } else { /* Just let it quote next char */
- s++; /* get past the backslash */
- *q++ = *s++; /* deposit next char */
- }
- continue;
- } else if (*s == SP || *s == NUL) { /* Unquoted space or NUL? */
- *q++ = NUL; /* End of output filename. */
- msfiles[r] = p; /* Add this filename to the list */
- debug(F111,"fnparse",msfiles[r],r);
- r++; /* Count it */
- if (*s == NUL) break; /* End of string? */
- while (*s == SP) s++; /* Skip repeated spaces */
- p = q; /* Start of next name */
- continue;
- } else *q++ = *s; /* Otherwise copy the character */
- s++; /* Next input character */
- }
- debug(F101,"fnparse r","",r);
- msfiles[r] = ""; /* Put empty string at end of list */
- cmlist = msfiles;
- return(r);
- }
- #endif /* NOMSEND */
- char * /* dbchr() for DEBUG SESSION */
- dbchr(c) int c; {
- static char s[8];
- char *cp = s;
- c &= 0xff;
- if (c & 0x80) { /* 8th bit on */
- *cp++ = '~';
- c &= 0x7f;
- }
- if (c < SP) { /* Control character */
- *cp++ = '^';
- *cp++ = (char) ctl(c);
- } else if (c == DEL) {
- *cp++ = '^';
- *cp++ = '?';
- } else { /* Printing character */
- *cp++ = (char) c;
- }
- *cp = ' '; /* Terminate string */
- cp = s; /* Return pointer to it */
- return(cp);
- }
- /* C K H O S T -- Get name of local host (where C-Kermit is running) */
- /*
- Call with pointer to buffer to put hostname in, and length of buffer.
- Copies hostname into buffer on success, puts null string in buffer on
- failure.
- */
- #ifdef BSD44
- #define BSD4
- #undef ATTSV
- #endif /* BSD44 */
- #ifdef SVORPOSIX
- #ifndef BSD44
- #ifndef apollo
- #include <sys/utsname.h>
- #endif /* apollo */
- #endif /* BSD44 */
- #else
- #ifdef BELLV10
- #include <utsname.h>
- #endif /* BELLV10 */
- #endif /* SVORPOSIX*/
- #ifdef CKSYSLOG
- extern char uidbuf[], * clienthost;
- #endif /* CKSYSLOG */
- VOID
- ckhost(vvbuf,vvlen) char * vvbuf; int vvlen; {
- #ifndef NOPUSH
- extern int nopush;
- #ifndef NOSERVER
- extern int en_hos;
- #endif /* NOSERVER */
- #endif /* NOPUSH */
- #ifdef pdp11
- *vvbuf = NUL;
- #else /* Everything else - rest of this routine */
- char *g;
- #ifdef VMS
- int x;
- #endif /* VMS */
- #ifdef SVORPOSIX
- #ifndef BSD44
- #ifndef _386BSD
- #ifndef APOLLOSR10
- struct utsname hname;
- #endif /* APOLLOSR10 */
- #endif /* _386BSD */
- #endif /* BSD44 */
- #endif /* SVORPOSIX */
- #ifdef datageneral
- int ac0 = (char *) vvbuf, ac1 = -1, ac2 = 0;
- #endif /* datageneral */
- #ifndef NOPUSH
- if (getenv("CK_NOPUSH")) { /* No shell access allowed */
- nopush = 1; /* on this host... */
- #ifndef NOSERVER
- en_hos = 0;
- #endif /* NOSERVER */
- }
- #endif /* NOPUSH */
- *vvbuf = NUL; /* How let's get our host name ... */
- #ifndef BELLV10 /* Does not have gethostname() */
- #ifndef OXOS
- #ifdef SVORPOSIX
- #ifdef APOLLOSR10
- ckstrncpy(vvbuf,"Apollo",vvlen);
- #else
- #ifdef BSD44
- if (gethostname(vvbuf,vvlen) < 0)
- *vvbuf = NUL;
- #else
- #ifdef _386BSD
- if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;
- #else
- #ifdef QNX
- #ifdef TCPSOCKET
- if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;
- #else
- if (uname(&hname) > -1) ckstrncpy(vvbuf,hname.nodename,vvlen);
- #endif /* TCPSOCKET */
- #else /* SVORPOSIX but not _386BSD or BSD44 */
- if (uname(&hname) > -1) ckstrncpy(vvbuf,hname.nodename,vvlen);
- #endif /* QNX */
- #endif /* _386BSD */
- #endif /* BSD44 */
- #endif /* APOLLOSR10 */
- #else /* !SVORPOSIX */
- #ifdef BSD4
- if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;
- #else /* !BSD4 */
- #ifdef VMS
- g = getenv("SYS$NODE");
- if (g) ckstrncpy(vvbuf,g,vvlen);
- x = (int)strlen(vvbuf);
- if (x > 1 && vvbuf[x-1] == ':' && vvbuf[x-2] == ':') vvbuf[x-2] = NUL;
- #else
- #ifdef datageneral
- if (sys($HNAME,&ac0,&ac1,&ac2) == 0) /* successful */
- vvlen = ac2 + 1; /* enh - have to add one */
- #else
- #ifdef OS2 /* OS/2 */
- g = os2_gethostname();
- if (g) ckstrncpy(vvbuf,g,vvlen);
- #else /* OS2 */
- #ifdef OSK
- #ifdef TCPSOCKET
- if (gethostname(vvbuf, vvlen) < 0) *vvbuf = NUL;
- #endif /* TCPSOCKET */
- #endif /* OSK */
- #endif /* OS2 */
- #endif /* datageneral */
- #endif /* VMS */
- #endif /* BSD4 */
- #endif /* SVORPOSIX */
- #else /* OXOS */
- /* If TCP/IP is not installed, gethostname() fails, use uname() */
- if (gethostname(vvbuf,vvlen) < 0) {
- if (uname(&hname) > -1)
- ckstrncpy(vvbuf,hname.nodename,vvlen);
- else
- *vvbuf = NUL;
- }
- #endif /* OXOS */
- #endif /* BELLV10 */
- if (*vvbuf == NUL) { /* If it's still empty */
- g = getenv("HOST"); /* try this */
- if (g) ckstrncpy(vvbuf,g,vvlen);
- }
- vvbuf[vvlen-1] = NUL; /* Make sure result is terminated. */
- #endif /* pdp11 */
- }
- #ifdef BSD44
- #undef BSD4
- #define ATTSV
- #endif /* BSD44 */
- /*
- A S K M O R E -- Poor person's "more".
- Returns 0 if no more, 1 if more wanted.
- */
- int
- askmore() {
- char c; int rv;
- #ifdef IKSD
- int cx;
- extern int timelimit;
- #endif /* IKSD */
- #ifdef NOICP
- return(1);
- #else
- if (!xaskmore)
- return(1);
- #ifdef VMS
- if (batch)
- return(1);
- #else
- #ifdef UNIX
- if (backgrd)
- return(1);
- #endif /* UNIX */
- #endif /* VMS */
- concb((char)escape); /* Force CBREAK mode. */
- rv = -1;
- while (rv < 0) {
- #ifndef OS2
- printf("more? ");
- #ifdef UNIX
- #ifdef NOSETBUF
- fflush(stdout);
- #endif /* NOSETBUF */
- #endif /* UNIX */
- #else
- printf("more? (Y or space-bar for yes, N for no) ");
- fflush(stdout);
- #endif /* OS2 */
- #ifdef IKSD
- if (inserver) {
- cx = cmdgetc(timelimit);
- if (cx < -1 && timelimit) {
- printf("n?IKS idle timeout - Goodbye.n");
- doexit(GOOD_EXIT,0);
- }
- c = (char) cx;
- } else
- #endif /* IKSD */
- c = (char) cmdgetc(0);
- switch (c) {
- /* Yes */
- case SP: case 'y': case 'Y': case 012: case 015:
- #ifdef OSK
- write(1, "