⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckuus5.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifndef NOICP/*  C K U U S 5 --  "User Interface" for Unix Kermit, part 5  */ /*  Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),  Columbia University Center for Computing Activities.  First released January 1985.  Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New  York.  Permission is granted to any individual or institution to use this  software as long as it is not sold for profit.  This copyright notice must be  retained.  This software may not be included in commercial products without  written permission of Columbia University.*//* Includes */#include "ckcdeb.h"#include "ckcasc.h"#include "ckcker.h"#include "ckuusr.h"#include "ckcnet.h"#ifndef NOCSETS#include "ckcxla.h"#endif /* NOCSETS */#ifdef MAC#include "ckmasm.h"#endif /* MAC *//* For formatted screens, "more?" prompting, etc. */#define SCRNLEN 21			/* Screen length */#define SCRNWID 79			/* Screen width */#ifdef FT18#define isxdigit(c) isdigit(c)#endif /* FT18 */#ifdef MAC				/* Internal MAC file routines */#define feof mac_feof#define rewind mac_rewind#define fgets mac_fgets#define fopen mac_fopen#define fclose mac_fcloseint mac_feof();void mac_rewind();char *mac_fgets();FILE *mac_fopen();int mac_fclose();#endif /* MAC *//* External variables */extern int carrier, cdtimo, local, backgrd, bgset, sosi, suspend,  displa, binary, deblog, escape, xargs, flow, cmdmsk,  duplex, ckxech, pktlog, seslog, tralog, what,  keep, warn, tlevel, cwdf, nfuncs, unkcs, msgflg,  mdmtyp, zincnt, cmask, rcflag, success, xitsta, pflag, lf_opts, tnlm, tn_nlm;extern char *ccntab[];#ifndef NOFRILLSextern int en_cwd, en_del, en_dir, en_fin, en_bye,  en_get, en_hos, en_sen, en_set, en_spa, en_typ, en_who;#endif /* NOFRILLS */extern long vernum;extern int srvtim, srvdis, incase, inecho, intime, insilence, nvars, verwho;extern char *protv, *fnsv, *cmdv, *userv, *ckxv, *ckzv, *ckzsys, *xlav, *cknetv, *clcmds;extern char *connv, *dialv, *loginv, *nvlook();#ifndef NOSCRIPTextern int secho;#endif /* NOSCRIPT */#ifndef NODIALextern int nmdm;extern struct keytab mdmtab[];#endif /* NODIAL */#ifdef NETCONNextern int tn_init, network, ttnproto;#endif /* NETCONN */#ifdef OS2extern int tt_type, tt_arrow, tt_keypad, tt_wrap;#endif /* OS2 */extern int tt_crd;#ifndef NOCSETSextern int language, nfilc, tcsr, tcsl;extern struct keytab fcstab[];#ifndef MACextern struct keytab ttcstab[];#endif /* MAC */#endif /* NOCSETS */extern int atcapr,  atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,  attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso; extern long speed;extern char *DIRCMD, *PWDCMD, *DELCMD;#ifndef NOXMITextern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw;extern char xmitbuf[];#endif /* NOXMIT */extern char **xargv, *versio, *ckxsys, *dftty, *cmarg, *lp;#ifdef DCMDBUFextern char *cmdbuf, *atmbuf;		/* Command buffers */#ifndef NOSPLextern char *savbuf;			/* Command buffers */#endif /* NOSPL */#elseextern char cmdbuf[], atmbuf[];		/* Command buffers */#ifndef NOSPLextern char savbuf[];			/* Command buffers */#endif /* NOSPL */#endif /* DCMDBUF */extern char toktab[], ttname[], psave[];extern CHAR sstate;extern int cmflgs, techo, terror, repars, ncmd;extern struct keytab cmdtab[];#ifndef MAC#ifndef NOSETKEYKEY *keymap;MACRO *macrotab;#endif /* NOSETKEY */#endif /* MAC */#ifndef NOSPLextern struct mtab *mactab;extern struct keytab vartab[], fnctab[];extern int cmdlvl, maclvl, nmac, mecho, merror;#endif /* NOSPL */FILE *tfile[MAXTAKE];			/* TAKE file stack */char *tfnam[MAXTAKE];#ifndef NOSPL/* Local declarations */int nulcmd = 0;			/* Flag for next cmd to be ignored *//* Definitions for built-in macros *//* First, the single line macros, installed with addmac()... *//* IBM-LINEMODE macro */char *m_ibm = "set parity mark, set dupl half, set handsh xon, set flow none";/* FATAL macro */char *m_fat = "if def \\%1 echo \\%1, if not = \\v(local) 0 hangup, stop 1";#ifdef COMMENT/*  Long macro definitions were formerly done like this.  But some compilers  cannot handle continued string constants, others cannot handle string  constants that are this long.  So these definitions have been broken up  into pieces and put into arrays, see below.*/char *m_forx = "if def _floop ass \\%9 \\fdef(_floop),else def \\%9,\ass _floop { _getargs,\define \\\\\\%1 \\%2,:top,if \\%5 \\\\\\%1 \\%3 goto bot,\\\%6,:inc, incr \\\\\\%1 \\%4,goto top,:bot,_putargs,return},\def break goto bot, def continue goto inc,\do _floop \\%1 \\%2 \\%3 \\%4 { \\%5 },assign _floop \\fcont(\\%9)";char *m_while = "if def _wloop ass \\%9 \\fdef(_wloop),\ass _wloop {_getargs,:wtest,\\%1,\\%2,goto wtest,:wbot,_putargs,return},\def break goto wbot, def continue goto wtest,\do _wloop,assign _wloop \\fcont(\\%9)";char *m_xif = "ass \\%9 \\fdef(_ify),ass _ify {_getargs, \\%1, _putargs},\do _ify,ass _ify \\fcont(\\%9)";#endif /* COMMENT *//* Now the multiline macros, defined with addmmac()... *//* FOR macro */char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,","define \\\\\\%1 \\%2,:top,if \\%5 \\\\\\%1 \\%3 goto bot,","\\%6,:inc,incr \\\\\\%1 \\%4,goto top,:bot,_putargs},","def break goto bot, def continue goto inc,","do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",""};#ifdef COMMENT/*  This one didn't work right.  When an interior loop finished executing,  the definition of the enclosing loop was restored, but the new definition  could be in a different location in memory, so its macro execution pointer  could (and usually was) pointing at garbage.*/char *old_for_def[] = { "if def _floop ass \\%9 \\fdef(_floop),else def \\%9,","ass _floop { _getargs,","define \\\\\\%1 \\%2,:top,if \\%5 \\\\\\%1 \\%3 goto bot,","\\%6,:inc, incr \\\\\\%1 \\%4,goto top,:bot,_putargs,return},","def break goto bot, def continue goto inc,","do _floop \\%1 \\%2 \\%3 \\%4 { \\%5 },assign _floop \\fcont(\\%9)",""};#endif /* COMMENT *//* WHILE macro */char *whil_def[] = { "_assign _whi\\v(cmdlevel) {_getargs,",":wtest,\\%1,\\%2,goto wtest,:wbot,_putargs},","def break goto wbot, def continue goto wtest,","do _whi\\v(cmdlevel),_assign _whi\\v(cmdlevel)",""};#ifdef COMMENT/*  Same deal as FOR loop...*/char *old_whil_def[] = { "if def _wloop asg \\%9 \\fdef(_wloop),","asg _wloop {_getargs,:wtest,\\%1,\\%2,goto wtest,:wbot,_putargs,return},","def break goto wbot, def continue goto wtest,","do _wloop,assign _wloop \\fcont(\\%9)",""};#endif /* COMMENT *//* XIF macro */char *xif_def[] = {"_assign _if\\v(cmdlevel) {_getargs,\\%1,_putargs},","do _if\\v(cmdlevel),_assign _if\\v(cmdlevel)",""};#ifdef COMMENT/* Same deal */char *old_xif_def[] = {"asg \\%9 \\fdef(_ify),ass _ify {_getargs, \\%1, _putargs},","do _ify,ass _ify \\fcont(\\%9)",""};#endif /* COMMENT *//* Variables declared here for use by other ckuus*.c modules *//* Space is allocated here to save room in ckuusr.c */#ifdef DCMDBUFstruct cmdptr *cmdstk;int *ifcmd, *count, *iftest;#elsestruct cmdptr cmdstk[CMDSTKL];int ifcmd[CMDSTKL], count[CMDSTKL], iftest[CMDSTKL];#endif /* DCMDBUF */char *m_arg[MACLEVEL][NARGS];char *g_var[GVARS], *macp[MACLEVEL], *mrval[MACLEVEL];int macargc[MACLEVEL];char *macx[MACLEVEL];extern char varnam[];char **a_ptr[27];			/* Array pointers, for arrays a-z */int a_dim[27];				/* Dimensions for each array */char inpbuf[INPBUFSIZ] = { NUL };	/* Buffer for INPUT and REINPUT */char inpbufa[2] = { NUL, NUL };		/* Null terminators for INPUT buffer */char inchar[2] = { NUL, NUL };		/* Last character that was INPUT */int  incount = 0;			/* INPUT character count */char lblbuf[50];			/* Buffer for labels */#endif /* NOSPL */#ifdef DCMDBUFchar *line;				/* Character buffer for anything */#elsechar line[LINBUFSIZ];#endif /* DCMDBUF */#ifdef CK_CURSES#ifndef TRMBUFL#define TRMBUFL 1024#endif /* TRMBUFL */#ifdef DCMDBUFchar *trmbuf;				/* Character buffer for termcap */#elsechar trmbuf[TRMBUFL];#endif /* DCMDBUF */#endif /* CK_CURSES */extern char pktfil[],#ifdef DEBUG  debfil[],#endif /* DEBUG */#ifdef TLOG  trafil[],#endif /* TLOG */  sesfil[],  cmdstr[];#ifndef NOFRILLSextern int rmailf, rprintf;		/* REMOTE MAIL & PRINT items */extern char optbuf[];#endif /* NOFRILLS */char *homdir = "";			/* Pointer to home directory string */char tmpbuf[50], *tp;			/* Temporary buffer */char numbuf[20];			/* Buffer for numeric strings. */char kermrc[100];			/* Name of initialization file */int noinit = 0;				/* Flag for skipping init file */#ifndef NOSPL_PROTOTYP( static long expon, (long, long) );_PROTOTYP( static long gcd, (long, long) );_PROTOTYP( static long fact, (long) );int					/* Initialize macro data structures. */macini() {            /* Allocate mactab and preset the first element. */    if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX)))	return(-1);    mactab[0].kwd = NULL;    mactab[0].mval = NULL;    mactab[0].flgs = 0;    return(0);}#endif /* NOSPL *//*  C M D I N I  --  Initialize the interactive command parser  */ VOIDcmdini() {    int i, x, y, z;#ifndef NOSPL/*  On stack in case of recursion!*/    char vnambuf[VNAML];		/* Buffer for variable names */#endif /* NOSPL */#ifndef MAC#ifndef NOSETKEY			/* Allocate & initialize the keymap */    if (!(keymap = (KEY *) malloc(sizeof(KEY)*KMSIZE)))      fatal("cmdini: no memory for keymap");    if (!(macrotab = (MACRO *) malloc(sizeof(MACRO)*KMSIZE)))      fatal("cmdini: no memory for macrotab");    for ( i = 0; i < KMSIZE; i++ ) {	keymap[i] = i;	macrotab[i] = NULL;    }#ifdef OS2    keymapinit();#endif /* OS2 */#endif /* NOSETKEY */#endif /* MAC */#ifdef DCMDBUF    if (cmsetup() < 0) fatal("Can't allocate command buffers!");#ifndef NOSPL    if (!(cmdstk = (struct cmdptr *) malloc(sizeof(struct cmdptr)*CMDSTKL)))	fatal("cmdini: no memory for cmdstk");    if (!(ifcmd = (int *) malloc(sizeof(int)*CMDSTKL)))	fatal("cmdini: no memory for ifcmd");    if (!(count = (int *) malloc(sizeof(int)*CMDSTKL)))	fatal("cmdini: no memory for count");    if (!(iftest = (int *) malloc(sizeof(int)*CMDSTKL)))	fatal("cmdini: no memory for iftest");#endif /* NOSPL */#ifdef CK_CURSES/*  Termcap buffer for fullscreen display, UNIX only.  VMS does it another way.  The fullscreen display is not supported on AOS/VS or OS-9, etc, yet, and  the Mac has its own built-in fullscreen display.*/#ifdef UNIX    if (!(trmbuf = malloc(TRMBUFL+1)))	fatal("cmdini: no memory for termcap buffer");#endif /* UNIX */#endif /* CK_CURSES */    if (!(line = malloc(LINBUFSIZ)))	fatal("cmdini: no memory for line");#endif /* DCMDBUF */#ifndef NOSPL    if (macini() < 0) fatal("Can't allocate macro buffers!");#endif /* NOSPL */#ifdef AMIGA    if (tlevel < 0)          concb(escape);#endif /* AMIGA */#ifndef NOSPL    cmdlvl = 0;				/* Start at command level 0 */    cmdstk[cmdlvl].src = CMD_KB;    cmdstk[cmdlvl].lvl = 0;#endif /* NOSPL */    tlevel = -1;			/* Take file level = keyboard */    for (i = 0; i < MAXTAKE; i++)	/* Initialize command file names */      tfnam[i] = NULL;#ifdef MAC     cmsetp("Mac-Kermit>");		/* Set default prompt */#else    cmsetp("C-Kermit>");		/* Set default prompt */#endif /* MAC */#ifndef NOSPL    initmac();				/* Initialize macro table *//* Add one-line macros */    addmac("ibm-linemode",m_ibm);	/* Add built-in macros. */    addmac("fatal",m_fat);		/* FATAL macro. *//* Add multiline macros */    addmmac("_forx",for_def);		/* FOR macro. */    addmmac("_xif",xif_def);		/* XIF macro. */    addmmac("_while",whil_def);		/* WHILE macro. *//* Fill in command line argument vector */    sprintf(vnambuf,"\\&@[%d]",xargs); 	/* Command line argument vector */    y = arraynam(vnambuf,&x,&z);	/* goes in array \&@[] */    if (y > -1) {	dclarray((char)x,z);		/* Declare the array */	for (i = 0; i < xargs; i++) {	/* Fill it */	    sprintf(vnambuf,"\\&@[%d]",i);	    addmac(vnambuf,xargv[i]);	}    }    *vnambuf = NUL;#endif /* NOSPL *//* Get our home directory now.  This needed in lots of places. */    homdir = zhome();/* If skipping init file ('-Y' on Kermit command line), return now. */    if (noinit) return;#ifdef OS2/*  The -y init file must be fully specified or in the current directory.  KERMRC is looked for via INIT, PATH and DPATH in that order.  Finally, our  own executable file path is taken and the .EXE suffix is replaced by .INI  and this is tried as initialization file.*/    if (rcflag) {	strcpy(line, kermrc);    } else {	_searchenv(kermrc,"INIT",line);	if (line[0] == 0)	  _searchenv(kermrc,"PATH",line);	if (line[0] == 0)	  _searchenv(kermrc,"DPATH",line);	if (line[0] == 0) {	    char *pgmptr = GetLoadPath();	    if (pgmptr) {	      lp = strrchr(pgmptr, '.');	      strncpy(line, pgmptr, lp - pgmptr);	      strcpy(line + (lp - pgmptr), ".ini");	    }	}    }    if ((tfile[0] = fopen(line,"r")) != NULL) {        tlevel = 0;	if (tfnam[tlevel] = malloc(strlen(line)+1))	  strcpy(tfnam[tlevel],line);#ifndef NOSPL	cmdlvl++;	cmdstk[cmdlvl].src = CMD_TF;	cmdstk[cmdlvl].lvl = tlevel;	ifcmd[cmdlvl] = 0;	iftest[cmdlvl] = 0;	count[cmdlvl] = 0;#endif /* NOSPL */        debug(F110,"init file",line,0);    } else {        debug(F100,"no init file","",0);    }#else /* not OS2 */    lp = line;    lp[0] = '\0';#ifdef GEMDOS    zkermini(line,rcflag, kermrc);#else#ifdef VMS    zkermini(line,LINBUFSIZ,kermrc);#else /* not VMS */    if (rcflag) {			/* If init file name from cmd line */	strcpy(lp,kermrc);		/* use it */    } else {				/* otherwise */	if (homdir) {			/* look in home directory for it */	    strcpy(lp,homdir);	    if (lp[0] == '/') strcat(lp,"/");	}	strcat(lp,kermrc);		/* and use the default name */    }#endif /* VMS */#endif /* GEMDOS */#ifdef AMIGA    reqoff();				/* disable requestors */#endif /* AMIGA */    debug(F110,"ini file is",line,0);    if ((tfile[0] = fopen(line,"r")) != NULL) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -