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

📄 ckuus6.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#include "ckcsym.h"#ifndef NOICP /*  C K U U S 6 --  "User Interface" for Unix Kermit (Part 6)  *//*  Author: Frank da Cruz (fdc@columbia.edu),  Columbia University Academic Information Systems, New York City.  Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New  York.  The C-Kermit software may not be, in whole or in part, licensed or  sold for profit as a software product itself, nor may it be included in or  distributed with commercial products or otherwise distributed by commercial  concerns to their clients or customers without written permission of the  Office of Kermit Development and Distribution, Columbia University.  This  copyright notice must not be removed, altered, or obscured.*//* Includes */ #include "ckcdeb.h"#include "ckcasc.h"#include "ckcker.h"#include "ckuusr.h"#include "ckcxla.h"#include "ckcnet.h"			/* Network symbols */#include <signal.h> #ifdef datageneral#define fgets(stringbuf,max,fd) dg_fgets(stringbuf,max,fd)#endif /* datageneral *//* External Kermit Variables, see ckmain.c for description. */ extern xx_strp xxstring;extern int size, rpsiz, urpsiz, local, stdinf, sndsrc, xitsta,  displa, binary, parity, escape, flow, cmd_rows,  turn, duplex, nfils, ckxech, pktlog, seslog, tralog, stdouf,  turnch, dfloc, keep, maxrps, warn, cnflg, tlevel, pflag, msgflg,  mdmtyp, zincnt, fblksiz, frecl, frecfm, atcapr, atdiso, verwho, quiet;extern int repars, techo, network; #ifdef CK_IFROextern int remonly;#endif /* CK_IFRO */#ifdef OS2extern int StartedFromDialer ;#ifndef NT#define INCL_NOPM#define INCL_VIO			/* Needed for ckocon.h */#include <os2.h> #undef COMMENT#else #define APIRET ULONG#include <windows.h>#endif /* NT */#include "ckocon.h"#endif /* OS2 */extern long vernum, speed;extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;extern char *dialv, *loginv, *for_def[], *whil_def[], *xif_def[], *sw_def[];extern char *ckxsys, *ckzsys, *cmarg, *cmarg2;extern char *DIRCMD, *PWDCMD, *DELCMD, *WHOCMD, ttname[], filnam[];extern CHAR sstate;extern char *zinptr;#ifndef NOMSEND				/* Multiple SEND */extern char *msfiles[];#endif /* NOMSEND */extern char fspec[];			/* Most recent filespec */#ifdef CK_TMPDIRextern int f_tmpdir;			/* Directory changed temporarily */extern char savdir[];			/* For saving current directory */extern char * dldir;#endif /* CK_TMPDIR *//* Declarations from cmd package */ #ifdef DCMDBUFextern char *cmdbuf, *atmbuf;		/* Command buffers */#elseextern char cmdbuf[], atmbuf[];		/* Command buffers */#endif /* DCMDBUF */#ifndef NOPUSHextern int nopush ;#endif /* NOPUSH */#ifndef NOSPLextern struct mtab *mactab;extern int nmac;extern long ck_alarm;extern char alrm_date[], alrm_time[];extern int x_ifnum;#endif /* NOSPL *//* Declarations from ck?fio.c module */ extern int backgrd;			/* Kermit executing in background */ #ifdef COMMENT/*  These must be on stack!*/#ifndef NOSPLextern char vnambuf[];			/* Buffer for variable names */extern char *vnp;			/* Pointer to same */#endif /* NOSPL */#endif /* COMMENT */extern char psave[];			/* For saving & restoring prompt */extern char *tp;			/* Temporary buffer */int readblock = 4096;			/* READ buffer size */CHAR * readbuf = NULL;			/* Pointer to read buffer */int readsize = 0;			/* Number of chars actually read *//* Keyword tables specific to this module *//* Modem signal table */struct keytab mstab[] = {#ifdef COMMENT/* The forms preceded by backslash are for MS-DOS Kermit compatibility. *//* But... \dsr doesn't work because \d = decimal constant introducer */    "\\cd",  BM_DCD, CM_INV,		/* Carrier Detect */    "\\cts", BM_CTS, CM_INV,		/* Clear To Send  */    "\\dsr", BM_DSR, CM_INV,		/* Data Set Ready */    "\\ri",  BM_RNG, CM_INV,		/* Ring Indicator */#endif /* COMMENT */    "cd",    BM_DCD, 0,			/* Carrier Detect */    "cts",   BM_CTS, 0,			/* Clear To Send  */    "dsr",   BM_DSR, 0,			/* Data Set Ready */    "ri",    BM_RNG, 0			/* Ring Indicator */};int nms = (sizeof(mstab) / sizeof(struct keytab));#ifndef NOSPLstruct keytab opntab[] = {#ifndef NOPUSH    "!read",  XYFZ_Y, 0,    "!write", XYFZ_X, 0,#endif /* NOPUSH */    "append", XYFZ_A, 0,    "read",   XYFZ_O, 0,    "write",  XYFZ_N, 0};int nopn = (sizeof(opntab) / sizeof(struct keytab));struct keytab iftab[] = {		/* IF commands */    "<",          XXIFLT, 0,    "=",          XXIFAE, 0,    ">",          XXIFGT, 0,    "alarm",      XXIFAL, 0,    "background", XXIFBG, 0,    "count",      XXIFCO, 0,    "defined",    XXIFDE, 0,#ifdef CK_TMPDIR    "directory",  XXIFDI, 0,#endif /* CK_TMPDIR */#ifdef COMMENT    "eof",        XXIFEO, 0,#endif /* COMMENT */    "emulation",  XXIFEM, 0,    "equal",      XXIFEQ, 0,    "error",      XXIFFA, CM_INV,    "exist",      XXIFEX, 0,    "failure",    XXIFFA, 0,    "false",      XXIFNT, 0,    "foreground", XXIFFG, 0,    "llt",        XXIFLL, 0,    "lgt",        XXIFLG, 0,#ifdef OS2    "terminal-macro", XXIFTM, CM_INV,#endif /* OS2 */#ifdef ZFCDAT    "newer",      XXIFNE, 0,#endif /* ZFCDAT */    "not",        XXIFNO, 0,    "ok",         XXIFSU, CM_INV,    "numeric",    XXIFNU, 0,    "remote-only",XXIFRO, 0,    "started-from-dialer",XXIFSD, CM_INV,    "success",    XXIFSU, 0,    "true",       XXIFTR, 0};int nif = (sizeof(iftab) / sizeof(struct keytab));#endif /* NOSPL *//* Variables and symbols local to this module */ #ifndef NODIAL _PROTOTYP(static int ddcvt, (char *, FILE *, int) );_PROTOTYP(static int dncvt, (int, int) );_PROTOTYP(char * getdname, (void) );char *dialnum = (char *)0;		/* Remember DIAL number for REDIAL */int dirline = 0;			/* Dial directory line number */extern char * dialdir[];		/* Dial directory file names */extern int dialdpy;			/* DIAL DISPLAY on/off */extern int ndialdir;			/* How many dial directories */#ifdef NETCONNextern int nnetdir;			/* How many network directories */#endif /* NETCONN */extern int ntollfree;			/* Toll-free call info */extern char *dialtfc[];extern int tttapi;extern int dialatmo;extern char * dialnpr, * dialsfx;extern char * diallcc;			/* Dial local country code */extern char * diallac;			/* Dial local area code */extern char * dialixp, * dialixs;extern char * dialldp, * diallds, * dialtfp;extern char * dialpxx, * dialpxi, * dialpxo;extern int dialcnf;			/* DIAL CONFIRMATION */int dialsrt = 1;			/* DIAL SORT ON */int dialrstr = 6;			/* DIAL RESTRICTION */extern int dialsta;			/* Dial status */int dialrtr = 0,			/* Dial retries */    dialint = 10;			/* Dial retry interval */extern long dialcapas;			/* Modem capabilities */extern int dialcvt;			/* DIAL CONVERT-DIRECTORY */#endif /* NODIAL */#ifndef NOSPLint ifc,				/* IF case */    not = 0,				/* Flag for IF NOT */    ifargs;				/* Count of IF condition words */char ifcond[100];			/* IF condition text */char *ifcp;				/* Pointer to IF condition text */#ifdef DCMDBUFextern int *ifcmd, *count, *iftest, *intime, *inpcas, *takerr, *merror;#elseextern int ifcmd[];			/* Last command was IF */extern int iftest[];			/* Last IF was true */extern int count[];			/* For IF COUNT, one for each cmdlvl */extern int intime[];extern int inpcas[];extern int takerr[];extern int merror[];#endif /* DCMDBUF */#elseextern int takerr[];#endif /* NOSPL */#ifdef DCMDBUFextern char *line;			/* Character buffer for anything */extern char *tmpbuf;#elseextern char line[], tmpbuf[];#endif /* DCMDBUF */extern char *lp;			/* Pointer to line buffer */int cwdf = 0;				/* CWD has been done */#ifndef NOSERVER/* Flags for ENABLE/DISABLE */extern int en_cwd, en_cpy, en_del, en_dir, en_fin,    en_get, en_hos, en_ren, en_sen, en_set, en_spa, en_typ, en_who, en_bye,   en_asg, en_que, en_ret, en_mai, en_pri;#endif /* NOSERVER */extern FILE *tfile[];			/* File pointers for TAKE command */extern char *tfnam[];			/* Names of TAKE files */extern int tfline[];			/* TAKE-file line number */extern int success;			/* Command success/failure flag */#ifndef NOSPLextern int maclvl;			/* Macro to execute */extern char *macx[];			/* Index of current macro */extern char *mrval[];			/* Macro return value */extern char *macp[];			/* Pointer to macro */extern int macargc[];			/* ARGC from macro invocation */extern char *m_arg[MACLEVEL][NARGS];	/* Stack of macro arguments */extern char *g_var[];			/* Global variables %a, %b, etc */ #ifdef DCMDBUFextern struct cmdptr *cmdstk;		/* The command stack itself */#elseextern struct cmdptr cmdstk[];		/* The command stack itself */#endif /* DCMDBUF */extern int cmdlvl;			/* Current position in command stack */#endif /* NOSPL */#define xsystem(s) zsyscmd(s)static int x, y, z = 0;static char *s, *p;#ifdef OS2_PROTOTYP( int os2settitle, (char *, int) );#endif /* OS2 */extern struct keytab yesno[];extern int nyesno;#ifndef NOSPL/* Do the ASK, ASKQ, GETOK, and READ commands */intdoask(cx) int cx; {    extern int cmflgs;#ifdef CK_RECALL    int sv_recall;    extern int on_recall;#endif /* CK_RECALL */    char vnambuf[VNAML];		/* Buffer for variable names */    char *vnp = NULL;			/* Pointer to same */    if (cx != XXGOK && cx != XXRDBL) {	/* Get variable name */	if ((y = cmfld("Variable name","",&s,NULL)) < 0) {	    if (y == -3) {		printf("?Variable name required\n");		return(-9);	    } else return(y);	}	strcpy(vnambuf,s);		/* Make a copy. */	vnp = vnambuf;	if (vnambuf[0] == CMDQ &&	    (vnambuf[1] == '%' || vnambuf[1] == '&'))	  vnp++;	y = 0;	if (*vnp == '%' || *vnp == '&') {	    if ((y = parsevar(vnp,&x,&z)) < 0)	      return(y);	}    }    if (cx == XXREA || cx == XXRDBL) {	/* READ or READBLOCK command */	if ((y = cmcfm()) < 0)		/* Get confirmation */	  return(y);	if (chkfn(ZRFILE) < 1) {	/* File open? */	    printf("?Read file not open\n");	    return(0);	}	if (!(s = (char *)readbuf)) {		/* Where to read into. */	    printf("?Oops, no READ buffer!\n");	    return(0);	}#ifdef BINREAD	if (cx == XXRDBL) {		/* READBLOCK */	    y = zxin(ZRFILE, s, readblock);	    if (y < 1) {		zclose(ZRFILE);		/* close the file, */		return(success = 0);	    }	    readsize = y;	    printf("READBLOCK %d\n",y);	} else#endif /* BINREAD */	  {	    y = zsinl(ZRFILE, s, readblock); /* Read a line. */	    debug(F111,"read zsinl",s,y);	    if (y < 0) {		/* On EOF or other error, */		zclose(ZRFILE);		/* close the file, */		delmac(vnp);		/* delete the variable, */		return(success = 0);	/* and return failure. */	    } else {			/* Read was OK. */		readsize = (int) strlen(s);		success = (addmac(vnp,s) < 0 ? 0 : 1); /* Define variable */		debug(F111,"read addmac",vnp,success);		return(success);	/* Return success. */	    }	}    }    /* ASK, ASKQ, or GETOK */    if ((y = cmtxt("Prompt, enclose in { braces } to preserve\n\leading and trailing spaces, precede question mark with backslash (\\).",		   cx == XXGOK ? "{ Yes or no? }" : "",		   &p,NULL)) < 0) {	return(y);    }#ifdef VMS/*  In VMS, whenever a TAKE file or macro is active, we had to restore the   original console modes or else Ctrl-C/Ctrl-Y would not work.  But here we  go interactive again, so we have to temporarily put them back.*/    if (cmdlvl > 0)      concb((char)escape);#endif /* VMS */          cmsavp(psave,PROMPTL);		/* Save old prompt */    cmsetp(brstrip(p));			/* Make new prompt */reprompt:    if (cx == XXASKQ) {			/* For ASKQ, */	concb((char)escape);		/* put console in cbreak mode */	cmini(0);			/* and no-echo mode. */    } else {				/* For others, regular echoing. */	cmini(ckxech);    }    x = -1;				/* This means to reparse. */    cmflgs = 0;    if (pflag) prompt(xxstring);	/* Issue prompt. */reparse:    cmres();    if (cx == XXGOK) {#ifdef CK_RECALL	sv_recall = on_recall;	on_recall = 0;#endif /* CK_RECALL */	x = cmkey(yesno,nyesno,"","",xxstring);	/* GETOK uses keyword table */	if (x < 0) {			/* Parse error */	    if (x == -3) {		/* No answer? */		printf("Please respond Yes or No\n"); /* Make them answer */		cmini(ckxech);		goto reprompt;	    } else if (x == -1) {		goto reparse;	    } else	      goto reprompt;	}	if (cmcfm() < 0)		/* Get confirmation */	  goto reparse;	cmsetp(psave);			/* Restore prompt */#ifdef VMS	if (cmdlvl > 0)			/* In VMS and not at top level, */	  conres();			/*  restore console again. */#endif /* VMS */#ifdef CK_RECALL	on_recall = sv_recall;#endif /* CK_RECALL */	return(x);			/* Return success or failure */    } else if (cx == XXGETC) {		/* GETC */	char tmp[2];	x = coninc(0);			/* Just read one character */	if (x > -1) {	    printf("\r\n");	    tmp[0] = (char) (x & 0xff);	    tmp[1] = NUL;	    y = addmac(vnp,tmp);	/* Add it to the macro table. */	    debug(F111,"getc addmac",vnp,y);	    cmsetp(psave);		/* Restore old prompt. */	} else y = -1;	return(success = y < 0 ? 0 : 1);    } else {				/* ASK or ASKQ */#ifdef CK_RECALL	sv_recall = on_recall;	on_recall = 0;#endif /* CK_RECALL */	y = cmdgquo();			/* Get current quoting */	cmdsquo(0);			/* Turn off quoting */	while (x == -1) {		/* Prompt till they answer */	    x = cmtxt("Please respond.","",&s,NULL);	    debug(F111,"ASK cmtxt",s,x);	    cmres();	}	cmdsquo(y);			/* Restore previous quoting */#ifdef CK_RECALL	on_recall = sv_recall;#endif /* CK_RECALL */	if (cx == XXASKQ)		/* ASKQ must echo CRLF here */	  printf("\r\n");	if (x < 0) {			/* If cmtxt parse error, */	    cmsetp(psave);		/* restore original prompt */#ifdef VMS	    if (cmdlvl > 0)		/* In VMS and not at top level, */	      conres();			/*  restore console again. */#endif /* VMS */	    return(x);			/* and return cmtxt's error code. */	}	if (*s == NUL) {		/* If user typed a bare CR, */	    cmsetp(psave);		/* Restore old prompt, */	    delmac(vnp);		/* delete variable if it exists, */#ifdef VMS	    if (cmdlvl > 0)		/* In VMS and not at top level, */	      conres();			/*  restore console again. */#endif /* VMS */	    return(success = 1);	/* and return. */	}	y = addmac(vnp,s);		/* Add it to the macro table. */	debug(F111,"ask addmac",vnp,y);	cmsetp(psave);			/* Restore old prompt. */#ifdef VMS	if (cmdlvl > 0)			/* In VMS and not at top level, */	  conres();			/*  restore console again. */#endif /* VMS */	return(success = y < 0 ? 0 : 1);    }}#endif /* NOSPL */#ifndef NOSPLintdoincr(cx) int cx; {			/* INCREMENT, DECREMENT */    char vnambuf[VNAML+1];		/* Buffer for variable names */    if ((y = cmfld("Variable name","",&s,NULL)) < 0) {

⌨️ 快捷键说明

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