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

📄 ckuus5.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
#else		    printf("?Invalid: %s\n",cmdbuf);#endif /* NOSPL */#else		    printf("?Invalid: %s\n",cmdbuf);#endif /* COMMENT */		case -9:		/* Bad, error message already done */		    success = 0;		    debug(F110,"top-level cmkey failed",cmdbuf,0);		    if (pflag == 0)	/* if background, terminate */		      fatal("Kermit command error in background execution");		    cmini(ckxech);	/* (fall thru) */ 	    	case -3:		/* Empty command OK at top level */		    repars = 0;		/* Don't need to reparse. */		    continue;		/* Go back and get another command. */		default:		/* Command was successful. */#ifndef NOSPL		    debug(F101,"parser preparing to continue","",maclvl);#endif /* NOSPL */		    repars = 0;		/* Don't need to reparse. */		    continue;		/* Go back and get another command. */		}	}#ifndef NOSPL	debug(F101,"parser breaks out of while loop","",maclvl);	if (m && (cmdlvl < inlevel))  return((int) sstate);#endif /* NOSPL */    }/* Got an action command, return start state. */ #ifdef COMMENT    /* This is done in ckcpro.w instead, no need to do it twice. */    /* Interrupts off only if remote */    if (!local) connoi();#endif /* COMMENT */    return((int) sstate);}#ifndef NOSPL/* OUTPUT command */int					/* This could easily become a macro */#ifdef CK_ANSICxxout(char c)#elsexxout(c) char c; #endif /* CK_ANSIC *//* xxout */ {				/* Function to output a character. */    debug(F101,"xxout","",c);    if (local)				/* If in local mode */      return(ttoc(c));			/* then to the external line */    else return(conoc(c));		/* otherwise to the console. */}/* Returns 0 on failure, 1 on success */intdooutput(s) char *s; {    int x, y, quote;    if (local) {			/* Condition external line */	y = ttvt(speed,flow);	if (y < 0) return(0);    }    quote = 0;				/* Initialize backslash (\) quote */#ifdef COMMENT/* This is done automatically in ttopen() now... */#ifdef TNCODE    if (network && ttnproto == NP_TELNET) /* If telnet connection, */      if (!tn_init++) tn_ini();           /* initialize it if necessary */#endif /* TNCODE */#endif /* COMMENT */    while (x = *s++) {			/* Loop through the string */	y = 0;				/* Error code, 0 = no error. */	if (x == CMDQ) {		/* Look for \b or \B in string */            quote++;			/* Got \ */	    continue;			/* Get next character */	} else if (quote) {		/* This character is quoted */	    if (quote == 1 && (x == 'b' || x == 'B')) {	/* If \b or \B */		debug(F100,"OUTPUT BREAK","",0);		ttsndb();		/* send BREAK signal */		quote = 0;		/* Turn off quote flag */		continue;		/* and not the b or B */#ifdef CK_LBRK	    } else if (quote == 1 && (x == 'l' || x == 'L')) { /* \l or \L */		debug(F100,"OUTPUT Long BREAK","",0);		ttsndlb();		/* send Long BREAK signal */		quote = 0;		/* Turn off quote flag */		continue;		/* and not the l or L */#endif /* CK_LBRK */	    } else {			/* if \ not followed by b or B */		y = xxout(dopar(CMDQ));	/* output the backslash. */		quote = 0;		/* Turn off quote flag */	    }	} else quote = 0;		/* Turn off quote flag */	y = xxout(dopar((char)x));	/* Output this character */	if (y < 0) {	    printf("output error.\n");	    return(0);	}	if (x == '\015') {		/* User typed carriage return */	    if (tnlm			/* If TERMINAL NEWLINE-MODE is ON */#ifdef TNCODE		|| (network &&		/* Or we have a network connection */		    ttnproto == NP_TELNET && /* using TELNET protocol */		    tn_nlm		/* and TELNET NEWLINE-MODE is ON */		    )#endif /* TNCODE */		)	      xxout(dopar('\012'));	/* Send LF too (CR => CRLF) */	}	if (seslog && duplex)	  if (zchout(ZSFILE,(char)x) < 0) seslog = 0;    }    return(1);}#endif /* NOSPL *//* Display version herald and initial prompt */VOIDherald() {    int x = 0;    if (bgset > 0 || (bgset != 0 && backgrd != 0)) x = 1;    debug(F101,"herald","",backgrd);    if (x == 0)#ifdef datageneral      printf("%s,%s\nType ? or HELP for help\n",versio,ckxsys);#else      printf("%s,%s\n\rType ? or HELP for help\n",versio,ckxsys);#endif /* datageneral */}#ifndef NOSPL/*  M L O O K  --  Lookup the macro name in the macro table  */ /* Call this way:  v = mlook(table,word,n);    table - a 'struct mtab' table.   word  - the target string to look up in the table.   n     - the number of elements in the table.  The keyword table must be arranged in ascending alphabetical order, and all letters must be lowercase.  Returns the table index, 0 or greater, if the name was found, or:   -3 if nothing to look up (target was null),  -2 if ambiguous,  -1 if not found.  A match is successful if the target matches a keyword exactly, or if the target is a prefix of exactly one keyword.  It is ambiguous if the target matches two or more keywords from the table.*/intmlook(table,cmd,n) struct mtab table[]; char *cmd; int n; {     int i, v, cmdlen; /* Lowercase & get length of target, if it's null return code -3. */     if ((((cmdlen = lower(cmd))) == 0) || (n < 1)) return(-3); /* Not null, look it up */     for (i = 0; i < n-1; i++) {        if (!strcmp(table[i].kwd,cmd) ||           ((v = !strncmp(table[i].kwd,cmd,cmdlen)) &&             strncmp(table[i+1].kwd,cmd,cmdlen))) {                return(i);             }        if (v) return(-2);    }    /* Last (or only) element */     if (!strncmp(table[n-1].kwd,cmd,cmdlen)) {        return(n-1);    } else return(-1);}/* mxlook is like mlook, but an exact full-length match is required */intmxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {    int i, cmdlen;    if ((((cmdlen = lower(cmd))) == 0) || (n < 1)) return(-3);    for (i = 0; i < n; i++)      if (((int)strlen(table[i].kwd) == cmdlen) &&	  (!strncmp(table[i].kwd,cmd,cmdlen))) return(i);    return(-1);}/*  This routine is for the benefit of those compilers that can't handle  long string constants or continued lines within them.  Long predefined  macros like FOR, WHILE, and XIF have their contents broken up into  arrays of string pointers.  This routine concatenates them back into a  single string again, and then calls the real addmac() routine to enter  the definition into the macro table.*/intaddmmac(nam,s) char *nam, *s[]; {	/* Add a multiline macro definition */    int i, x, y; char *p;    x = 0;				/* Length counter */    for (i = 0; (y = (int)strlen(s[i])) > 0; i++) { /* Add up total length */    	debug(F111,"addmmac line",s[i],y);		x += y;    }    debug(F101,"addmmac lines","",i);    debug(F101,"addmmac loop exit","",y);    debug(F111,"addmmac length",nam,x);    if (x < 0) return(-1);    p = malloc(x+1);			/* Allocate space for all of it. */    if (!p) {	printf("?addmmac malloc error: %s\n",nam);	debug(F110,"addmmac malloc error",nam,0);	return(-1);    }    *p = '\0';				/* Start off with null string. */    for (i = 0; *s[i]; i++)		/* Concatenate them all together. */      strcat(p,s[i]);    y = (int)strlen(p);			/* Final precaution. */    debug(F111,"addmmac constructed string",p,y);    if (y == x) {	y = addmac(nam,p);		/* Add result to the macro table. */    } else {	debug(F100,"addmmac length mismatch","",0);	printf("\n!addmmac internal error!\n");	y = -1;    }    free(p);				/* Free the temporary copy. */    return(y);	}/* Here is the real addmac routine. */intaddmac(nam,def) char *nam, *def; {	/* Add a macro to the macro table */    int i, x, y, z, namlen, deflen;    char *p, c;    if (!nam) return(-1);    namlen = (int)strlen(nam);		/* Get argument lengths */    debug(F111,"addmac nam",nam,namlen);    if (!def) {				/* Watch out for null pointer */	deflen = 0;	debug(F111,"addmac def","(null pointer)",deflen);    } else {	deflen = (int)strlen(def);	debug(F111,"addmac def",def,deflen);    }    if (deflen < 0) return(-1);		/* strlen() failure, fail. */    if (namlen < 1) return(-1);		/* No name given, fail. */    if (*nam == CMDQ) nam++;		/* Backslash quote? */    if (*nam == '%') {			/* Yes, if it's a variable name, */	delmac(nam);			/* Delete any old value. */	if (!(c = *(nam + 1))) return(-1); /* Variable name letter or digit */	if (deflen < 1) {		/* Null definition */	    p = NULL;			/* Better not malloc or strcpy! */	} else {			/* A substantial definition */	    p = malloc(deflen + 1);	/* Allocate space for it */	    if (!p) {		printf("?addmac malloc error 2\n");		return(-1);	    } else strcpy(p,def);	/* Copy definition into new space */	}	/* Now p points to the definition, or is a null pointer */	if (p)	  debug(F110,"addmac p",p,0);	else	  debug(F110,"addmac p","(null pointer)",0);	if (c >= '0' && c <= '9') {	/* Digit variable */	    if (maclvl < 0) {		/* Are we calling or in a macro? */		g_var[c] = p;		/* No, it's a global "top level" one */		debug(F101,"addmac numeric global maclvl","",maclvl);	    } else {			/* Yes, it's a macro argument */		m_arg[maclvl][c - '0'] = p;		debug(F101,"addmac macro arg maclvl","",maclvl);	    }	} else {			/* It's a global variable */	    if (c < 33 || c > GVARS) return(-1);	    if (isupper(c)) c = tolower(c);	    g_var[c] = p;		/* Put pointer in global-var table */	    debug(F100,"addmac global","",0);	}	return(0);    } else if (*nam == '&') {		/* An array reference? */	char **q;	if ((y = arraynam(nam,&x,&z)) < 0) /* If syntax is bad */	  return(-1);			/* return -1. */	if (chkarray(x,z) < 0)		/* If array not declared or */	  return(-2);			/* subscript out of range, ret -2 */	delmac(nam);			/* Delete any current definition. */	x -= 96;			/* Convert name letter to index. */	if ((q = a_ptr[x]) == NULL)	/* If array not declared, */	  return(-3);			/* return -3. */	if (deflen > 0) {	    if ((p = malloc(deflen+1)) == NULL) { /* Allocate space */		printf("addmac macro error 7: %s\n",nam);		return(-4);		/* for new def, return -4 on fail. */	    }	    strcpy(p,def);		/* Copy definition into new space. */	} else p = NULL;	q[z] = p;			/* Store pointer to it. */	return(0);			/* Done. */    } else debug(F110,"addmac macro def",nam,0);/* Not a macro argument or a variable, so it's a macro definition */    lower(nam);				/* Lowercase the name */    if (mxlook(mactab,nam,nmac) > -1)	/* Look up, requiring exact match */      delmac(nam);			/* if it's there, delete it. */    debug(F111,"addmac table size",nam,nmac);    for (y = 0;				/* Find the alphabetical slot */	 y < MAC_MAX && mactab[y].kwd != NULL && strcmp(nam,mactab[y].kwd) > 0;	 y++) ;    if (y == MAC_MAX) {			/* No more room. */	debug(F101,"addmac table overflow","",y);	return(-1);    } else debug(F111,"addmac position",nam,y);    if (mactab[y].kwd != NULL) {	/* Must insert */	for (i = nmac; i > y; i--) {	/* Move the rest down one slot */	    mactab[i].kwd = mactab[i-1].kwd;	    mactab[i].mval = mactab[i-1].mval;	    mactab[i].flgs = mactab[i-1].flgs;	}    }    p = malloc(namlen + 1);		/* Allocate space for name */    if (!p) {	printf("?addmac malloc error 3: %s\n",nam);	return(-1);    }    strcpy(p,nam);			/* Copy name into new space */    mactab[y].kwd = p;			/* Add pointer to table */    if (deflen > 0) {			/* Same deal for definition */	p = malloc(deflen + 1);		/* but watch out for null pointer */	if (p == NULL) {	    printf("?addmac malloc error 5: %s\n", nam);	    free(mactab[y].kwd);	    mactab[y].kwd = NULL;	    return(-1);	} else strcpy(p,def);		/* Copy the definition */    } else p = NULL;    mactab[y].mval = p;    mactab[y].flgs = 0;    nmac++;				/* Count this macro */    return(y);}intdelmac(nam) char *nam; {		/* Delete the named macro */    int i, x, z;    char *p, c;    if (!nam) return(0);		/* Watch out for null pointer */    debug(F110,"delmac nam",nam,0);    if (*nam == CMDQ) nam++;    if (*nam == '%') {			/* If it's a variable name */	if (!(c = *(nam+1))) return(0);	/* Get variable name letter or digit */	p = (char *)0;			/* Initialize value pointer */	if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */	    p = m_arg[maclvl][c - '0'];	/* Get pointer from macro-arg table */	    m_arg[maclvl][c - '0'] = NULL; /* Zero the table pointer */	} else {			/* It's a global variable */	    if (c < 33 || c > GVARS) return(0);	    p = g_var[c];		/* Get pointer from global-var table */	    g_var[c] = NULL;		/* Zero the table entry */	}	if (p) {	    debug(F110,"delmac def",p,0);	    free(p);			/* Free the storage */	} else debug(F110,"delmac def","(null pointer)",0);	return(0);    }	        if (*nam == '&') {			/* An array reference? */	char **q;	if (arraynam(nam,&x,&z) < 0)	/* If syntax is bad */	  return(-1);			/* return -1. */	x -= 96;			/* Convert name to number. */	if ((q = a_ptr[x]) == NULL)	/* If array not declared, */	  return(-2);			/* return -2. */	if (z > a_dim[x])		/* If subscript out of range, */	  return(-3);			/* return -3. */	if (q[z]) {			/* If there is an old value, */	    debug(F110,"delman def",q[z],0);	    free(q[z]);			/* delete it. */	    q[z] = NULL;	} else debug(F110,"delmac def","(null pointer)",0);    }   /* Not a variable or an array, so it must be a macro. */    if ((x = mlook(mactab,nam,nmac)) < 0) { /* Look it up */	debug(F111,"delmac mlook",nam,x);	return(x);    }    if (mactab[x].kwd)			/* Free the storage for the name */      free(mactab[x].kwd);    if (mactab[x].mval)			/* and for the definition */      free(mactab[x].mval);    for (i = x; i < nmac; i++) {	/* Now move up the others. */	mactab[i].kwd = mactab[i+1].kwd;	mactab[i].mval = mactab[i+1].mval;	mactab[i].flgs = mactab[i+1].flgs;    }    nmac--;				/* One less macro */    mactab[nmac].kwd = NULL;		/* Delete last item from table */    mactab[nmac].mval = NULL;    mactab[nmac].flgs = 0;    return(0);}VOIDinitmac() {				/* Init macro & variable tables */    int i, j;    nmac = 0;				/* No macros */    for (i = 0; i < MAC_MAX; i++) {	/* Initialize the macro table */	mactab[i].kwd = NULL;	mactab[i].mval = NULL;	mactab[i].flgs = 0;    }    for (i = 0; i < MACLEVEL; i++) {	/* Init the macro argument tables */	mrval[i] = NULL;	for (j = 0; j < 10; j++) {	    m_arg[i][j] = NULL;	}    }    for (i = 0; i < GVARS; i++) {	/* And the global variables table */	g_var[i] = NULL;    }    for (i = 0; i < 26; i++) {		/* And the table of arrays */	a_ptr[i] = (char **) NULL;	/* Null pointer for each */	a_dim[i] = 0;			/* and a dimension of zero */    }}intpopclvl() {				/* Pop command level, return cmdlvl */    if (cmdlvl < 1) {			/* If we're already at top level */	cmdlvl = 0;			/* just make sure all the */	tlevel = -1;			/* stack pointers are set right */	maclvl = -1;			/* and return */    } else if (cmdstk[cmdlvl].src == CMD_TF) { /* Reading from TAKE file? */	if (tlevel > -1) {		/* Yes, */	    if (tfnam[tlevel]) {		free(tfnam[tlevel]);		tfnam[tlevel] = NULL;	    }	    fclose(tfile[tlevel--]);	/* close it and pop take level */	    cmdlvl--;			/* pop command level */	} else tlevel = -1;    } else if (cmdstk[cmdlvl].src == CMD_MD) { /* In a macro? */	if (maclvl > -1) {		/* Yes, */	    debug(F111,"popclvl before",macx[maclvl],maclvl);	    macp[maclvl] = "";		/* set macro pointer to null string */	    *cmdbuf = '\0';		/* clear the command buffer */	    if (mrval[maclvl+1]) {	/* Free any deeper return values. */		free(mrval[maclvl+1]);		mrval[maclvl+1] = NULL;	    }	    maclvl--;			/* pop macro level */	    cmdlvl--;			/* and command level */	    debug(F111,"popclvl after ",		  macx[maclvl] ? macx[maclvl] : "",maclvl);	} else maclvl = -1;    }#ifndef MAC    if (cmdlvl < 1) {			/* If back at top level */	conint(trap,stptrap);		/* Fix interrupts */	bgchk();			/* Check background status */	concb((char)escape);		/* Go into cbreak mode */    }#endif /* MAC */    return(cmdlvl < 1 ? 0 : cmdlvl);	/* Return command level */}#else /* No script programming language */int popclvl() {				/* Just close current take file. */    if (tlevel > -1) {			/* if any... */	if (tfnam[tlevel]) {

⌨️ 快捷键说明

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