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

📄 ckuus6.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifndef NOICP /*  C K U U S 6 --  "User Interface" for Unix Kermit (Part 6)  *//*  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 "ckcxla.h"#include "ckcnet.h"			/* Network symbols */ #ifdef datageneral#define fgets(stringbuf,max,fd) dg_fgets(stringbuf,max,fd)#endif /* datageneral */#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 Kermit Variables, see ckmain.c for description. */ extern int size, rpsiz, urpsiz, local, stdinf, sndsrc, xitsta,  displa, binary, parity, escape, xargc, flow,  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, terror, techo; extern long vernum, speed;extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;extern char *dialv, *loginv, *for_def[], *whil_def[], *xif_def[];extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv;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 *//* Declarations from cmd package */ #ifdef DCMDBUFextern char *cmdbuf, *atmbuf;		/* Command buffers */#elseextern char cmdbuf[], atmbuf[];		/* Command buffers */#endif /* DCMDBUF */#ifndef NOSPLextern struct mtab *mactab;extern int nmac;#endif /* NOSPL *//* Declarations from ck?fio.c module */ extern int backgrd, bgset;		/* 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 tmpbuf[], *tp;		/* Temporary buffer *//* 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,    "background", XXIFBG, 0,    "count",      XXIFCO, 0,    "defined",    XXIFDE, 0,#ifdef COMMENT    "eof",        XXIFEO, 0,#endif /* COMMENT */    "equal",      XXIFEQ, 0,    "error",      XXIFFA, CM_INV,    "exist",      XXIFEX, 0,    "failure",    XXIFFA, 0,    "foreground", XXIFFG, 0,    "llt",        XXIFLL, 0,    "lgt",        XXIFLG, 0,    "not",        XXIFNO, 0,    "numeric",    XXIFNU, 0,    "success",    XXIFSU, 0};int nif = (sizeof(iftab) / sizeof(struct keytab));#endif /* NOSPL *//* Variables and symbols local to this module */ #ifndef NODIAL char *dialnum = (char *)0;		/* Remember DIAL number for REDIAL */extern char * dialdir;			/* Dial directory file name */extern FILE * dialfd;			/* Dial directory file descriptor */#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;#elseextern int ifcmd[];			/* Last command was IF */extern int iftest[];			/* Last IF was true */extern int count[];			/* For IF COUNT, one for each cmdlvl */#endif /* DCMDBUF */#endif /* NOSPL */#ifdef DCMDBUFextern char *line;			/* Character buffer for anything */#elseextern char line[];#endif /* DCMDBUF */extern char *lp;			/* Pointer to line buffer */int cwdf = 0;				/* CWD has been done */extern int en_cwd, en_del, en_dir, en_fin, /* Flags for ENABLE/DISABLE */   en_get, en_hos, en_sen, en_set, en_spa, en_typ, en_who, en_bye;extern FILE *tfile[];			/* File pointers for TAKE command */extern char *tfnam[];			/* Names of TAKE files */extern int success;			/* Command success/failure flag */#ifndef NOSPLextern int				/* SET INPUT parameters. */  incase; extern 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;/*  X X S T R C M P  --  Caseless string comparison  *//*  Call with pointers to the two strings, s1 and s2, and a length, n.  Compares up to n characters of the two strings and returns:    1 if s1 > t1    0 if s1 = s2   -1 if s1 < t1*/intxxstrcmp(s1,s2,n) char *s1, *s2; int n; { /* Caseless string comparison. */    char t1, t2;			    if (!s1) s1 = "";			/* Watch out for null pointers. */    if (!s2) s2 = "";    while (n--) {	t1 = *s1++;			/* Get next character from each. */	if (isupper(t1)) t1 = tolower(t1);	t2 = *s2++;	if (isupper(t2)) t2 = tolower(t2);	if (t1 < t2) return(-1);	/* s1 < s2 */	if (t1 > t2) return(1);		/* s1 > s2 */    }    return(0);				/* They're equal */}#ifndef NOSPL/* Do the ASK, ASKQ, GETOK, and READ commands */#ifndef NOFRILLS   extern struct keytab yesno[];   extern int nyesno;#endif /* NOFRILLS */intdoask(cx) int cx; {    if (cx != XXGOK) {			/* 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(line,s);			/* Make a copy. */	lp = line;	if ((y = parsevar(s,&x,&z)) < 0)  /* Check to make sure it's a */	  return(y);			  /* variable name. */    }    if (cx == XXREA) {			/* READ command */	if ((y = cmcfm()) < 0)		/* Get confirmation */	  return(y);	if (chkfn(ZRFILE) < 1) {	/* File open? */	    printf("?Read file not open\n");	    return(0);	}	s = line+VNAML+1;		/* Where to read into. */	y = zsinl(ZRFILE, s, LINBUFSIZ - VNAML - 1); /* Read a line. */	debug(F111,"read zsinl",s,y);	if (y < 0) {			/* On EOF or other error, */	    zclose(ZRFILE);		/* close the file, */	    delmac(lp);			/* delete the variable, */	    return(success = 0);	/* and return failure. */	} else {			/* Read was OK. */	    success = (addmac(lp,s) < 0 ? 0 : 1); /* Define the variable */            debug(F111,"read addmac",lp,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,xxstring)) < 0) return(y);    cmsavp(psave,80);			/* Save old prompt */    if (*p == '{') {			/* New prompt enclosed in braces? */	x = (int)strlen(p) - 1;		/* Yes, strip them. */	if (p[x] == '}') {	    p[x] = NUL;	    p++;	}    }    cmsetp(p);				/* Make new prompt */    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. */reprompt:    if (pflag) prompt(xxstring);	/* Issue prompt. */    if (cx == XXGOK) {#ifndef NOFRILLS	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;	}	if ((y = cmcfm()) < 0)		/* Get confirmation */	  goto reprompt;	cmsetp(psave);			/* Restore prompt */	return(x);			/* Return success or failure */#else	;#endif /* NOFRILLS */    } else {				/* ASK or ASKQ */	while (x == -1) {		/* Prompt till they answer */	    x = cmtxt("Please respond.\n\ Type \\? to include a question mark in your response.","",&s,NULL);	    debug(F111," cmtxt",s,x);	}	if (cx == XXASKQ)		/* ASKQ must echo CRLF here */	  printf("\r\n");	if (x < 0) {			/* If cmtxt parse error, */	    cmsetp(psave);		/* restore original prompt */	    return(x);			/* and return cmtxt's error code. */	}	if (*s == NUL) {		/* If user typed a bare CR, */	    cmsetp(psave);		/* Restore old prompt, */	    delmac(lp);			/* delete variable if it exists, */	    return(success = 1);	/* and return. */	}	y = addmac(lp,s);		/* Add it to the macro table. */	debug(F111,"ask addmac",lp,y);	cmsetp(psave);			/* Restore old prompt. */	return(success = y < 0 ? 0 : 1);    }}#endif /* NOSPL */#ifndef NOSPLintdoincr(cx) int cx; {			/* INCREMENT, DECREMENT */    char vnambuf[VNAML];		/* Buffer for variable names */    if ((y = cmfld("Variable name","",&s,NULL)) < 0) {	if (y == -3) {	    printf("?Variable name required\n");	    return(-9);	} else return(y);    }    if (*s != CMDQ) {        *vnambuf = CMDQ;	strncpy(vnambuf+1,s,VNAML-1);    } else strncpy(vnambuf,s,VNAML);    if ((y = parsevar(vnambuf,&x,&z)) < 0)      return(y);    if ((y = cmnum("by amount","1",10,&x,xxstring)) < 0) return(y);    if ((y = cmcfm()) < 0) return(y);    z = (cx == XXINC ? 1 : 0);		/* Increment or decrement? */    if (incvar(vnambuf,x,z,&y) < 0) {	printf("?Variable %s not defined or not numeric\n",vnambuf);	return(success = 0);    }    return(success = 1);}#endif /* NOSPL *//* Do the (_)DEFINE and (_)ASSIGN commands */#ifndef NOSPLintdodef(cx) int cx; {    char vnambuf[VNAML];		/* Buffer for variable names */    char *vnp;				/* Pointer to same */    if (cx == XXDFX || cx == XXASX)       y = cmfld("Macro or variable name","",&s,xxstring); /* eval var name */    else       y = cmfld("Macro or variable name","",&s,NULL);     /* don't evaluate */    if (y < 0) {	if (y == -3) {	    printf("?Variable name required\n");	    return(-9);	} else return(y);    }    debug(F110,"dodef",s,0);    strcpy(vnambuf,s);    vnp = vnambuf;    if (vnambuf[0] == CMDQ && (vnambuf[1] == '%' || vnambuf[1] == '&')) vnp++;    if (*vnp == '%' || *vnp == '&') {	if ((y = parsevar(vnp,&x,&z)) < 0) return(y);	debug(F101,"dodef","",x);	if (y == 1) {			/* Simple variable */	    if ((y = cmtxt("Definition of variable","",&s,NULL)) < 0)	      return(y);	    debug(F110,"xxdef var name",vnp,0);	    debug(F110,"xxdef var def",s,0);	} else if (y == 2) {		/* Array element */	    if ((y = arraynam(s,&x,&z)) < 0) return(y);	    if (x == 96) {		printf("?Argument vector array is read-only\n");		return(-9);	    }	    if (chkarray(x,z) < 0) return(-2);	    if ((y = cmtxt("Definition of array element","",&s,NULL)) < 0)	      return(y);	    debug(F110,"xxdef array ref",vnp,0);	    debug(F110,"xxdef array def",s,0);	}    } else {				/* Macro */	if ((y = cmtxt("Definition of macro","",&s,NULL)) < 0) return(y);	debug(F110,"xxdef macro name",vnp,0);	debug(F110,"xxdef macro def",s,0);	if (*s == '{') {		/* Allow macro def to be bracketed. */	    s++;			/* If it is, remove the brackets. */	    y = (int)strlen(s);		/* FOR command depends on this! */	    if (y > 0 && s[y-1] == '}') s[y-1] = NUL;	}    }    if (*s == NUL) {			/* No arg given, undefine */	delmac(vnp);			/* silently... */	return(success = 1);		/* even if it doesn't exist... */    }     /* Defining a new macro or variable */    if (cx == XXASS || cx == XXASX) {	/* ASSIGN rather than DEFINE? */	int t;	t = LINBUFSIZ-1;	lp = line;			/* If so, expand its value now */	xxstring(s,&lp,&t);	s = line;    }    debug(F111,"calling addmac",s,(int)strlen(s));    y = addmac(vnp,s);			/* Add it to the appropriate table. */    if (y < 0) {	printf("?%s failed\n",(cx == XXASS || cx == XXASX) ?	       "ASSIGN" : "DEFINE");	return(success = 0);    }    return(success = 1);}#endif /* NOSPL */#ifndef NODIALextern struct keytab partab[];/*   L U D I A L  --  Lookup up dialing directory entry.     Call with string to look up and file descriptor of open dialing directory

⌨️ 快捷键说明

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