📄 ckuus5.c
字号:
strcpy(v->lv_value, line); /* Copy value into new node */ } else v->lv_value = NULL; delmac(list[i]); /* Delete the original macro */ } return(success = 1); localbad: printf("?Failure to allocate storage for local variables"); freelocal(cmdlvl); return(-9);}#endif /* NOSPL */#ifndef NOSPL/* D O O U T P U T -- Returns 0 on failure, 1 on success */intdooutput(s) char *s; { int x, xx, y, quote; /* Workers */ debug(F111,"dooutput s",s,(int)strlen(s));#ifndef NOLOCAL if (local) { /* Condition external line */ y = ttvt(speed,flow); if (y < 0) return(0); }#endif /* NOLOCAL */ if (!cmdgquo()) { /* COMMAND QUOTING OFF */ x = strlen(s); /* Just send the string literally */ xx = local ? ttol((CHAR *)s,x) : conxo(x,s); return(success = (xx == x) ? 1 : 0); } quote = 0; /* Initialize backslash (\) quote */ obn = 0; /* Reset count */ obp = obuf; /* and pointers */ while (x = *s++) { /* Loop through the string */ y = 0; /* Error code, 0 = no error. */ debug(F000,"dooutput","",x); if (quote) { /* This character is quoted */#ifndef NOKVERBS#define K_BUFLEN 30#define SEND_BUFLEN 255#define sendbufd(x) { sendbuf[sendndx++] = x;\ if (sendndx == SEND_BUFLEN) {dooutput(s); sendndx = 0;}} if (x == 'k' || x == 'K') { /* \k or \K */ extern struct keytab kverbs[]; extern int nkverbs; extern char * keydefptr; extern int keymac; extern int keymacx; int x, y, brace = 0; int pause; char * p, * b; char kbuf[K_BUFLEN + 1]; /* Key verb name buffer */ char sendbuf[SEND_BUFLEN +1]; int sendndx = 0; if (xxout(obuf,obn) < 0) /* Flush buffer */ goto outerr; debug(F100,"OUTPUT KVERB","",0); /* Send a KVERB */ { /* Have K verb? */ if (!*s) { break; }/* We assume that the verb name is {braced}, or it extends to the end of the string, s, or it ends with a space, control character, or backslash.*/ p = kbuf; /* Copy verb name into local buffer */ x = 0; while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) { if (brace && *s == '}') { break; } *p++ = *s++; } if (*s && !brace) /* If we broke because of \, etc, */ s--; /* back up so we get another look. */ brace = 0; *p = NUL; /* Terminate. */ p = kbuf; /* Point back to beginning */ debug(F110,"dooutput kverb",p,0); y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */ debug(F101,"dooutput lookup",0,y); if (y > -1) { if ( sendndx ) { dooutput( sendbuf ); sendndx = 0; } dokverb(VCMD,y); #ifndef NOSPL } else { /* Is it a macro? */ y = mxlook(mactab,p,nmac); if (y > -1) { cmpush(); keymac = 1; /* Flag for key macro active */ keymacx = y; /* Key macro index */ keydefptr = s; /* Where to resume next time */ debug(F111,"dooutput mxlook",keydefptr,y); parser(1); cmpop(); }#endif /* NOSPL */ } } quote = 0; continue; } else#endif /* NOKVERBS */ if (x == 'n' || x == 'N') { /* \n or \N */ if (xxout(obuf,obn) < 0) /* Flush buffer */ goto outerr; debug(F100,"OUTPUT NUL","",0); /* Send a NUL */ if (local) ttoc(NUL); else conoc(NUL); quote = 0; continue; } else if (x == 'b' || x == 'B') { /* \b or \B */ if (xxout(obuf,obn) < 0) /* Flush buffer first */ goto outerr; debug(F100,"OUTPUT BREAK","",0);#ifndef NOLOCAL ttsndb(); /* Send BREAK signal */#else if (local) ttoc(NUL); else conoc(NUL);#endif /* NOLOCAL */ quote = 0; /* Turn off quote flag */ continue; /* and not the b or B */#ifdef CK_LBRK } else if (x == 'l' || x == 'L') { /* \l or \L */ if (xxout(obuf,obn) < 0) /* Flush buffer first */ goto outerr; debug(F100,"OUTPUT Long BREAK","",0);#ifndef NOLOCAL ttsndlb(); /* Send Long BREAK signal */#else if (local) ttoc(NUL); else conoc(NUL);#endif /* NOLOCAL */ quote = 0; /* Turn off quote flag */ continue; /* and not the l or L */#endif /* CK_LBRK */ } else if (x == CMDQ) { /* Backslash itself */ debug(F100,"OUTPUT CMDQ","",0); xx = oboc(dopar(CMDQ)); /* Output the backslash. */ if (xx < 0) goto outerr; quote = 0; continue; } else { /* if \ not followed by b or B */ /* Note: Atari ST compiler won't allow macro call in "if ()" */ xx = oboc(dopar(CMDQ)); /* Output the backslash. */ if (xx < 0) goto outerr; quote = 0; /* Turn off quote flag */ } } else if (x == CMDQ) { /* This is the quote character */ quote = 1; /* Go back and get next character */ continue; /* which is quoted */ } xx = oboc(dopar((char)x)); /* Output this character */ debug(F111,"dooutput",obuf,obn); if (xx < 0) goto outerr; if (seslog && duplex) /* Log the character if log is on */ if (zchout(ZSFILE,(char)x) < 0) /* and connection is half duplex */ seslog = 0; if (x == '\015') { /* String contains carriage return */ int stuff = -1, stuff2 = -1; if (tnlm) { /* TERMINAL NEWLINE ON */ stuff = LF; /* Stuff LF */ }#ifdef TNCODE /* TELNET NEWLINE ON/OFF/RAW */ if (network && (ttnproto == NP_TELNET)) { switch (me_binary ? tn_b_nlm : tn_nlm) { /* NVT or BINARY */ case TNL_CR: break; case TNL_CRNUL: stuff2 = stuff; stuff = NUL; break; case TNL_CRLF: stuff2 = stuff; stuff = LF; break; } }#endif /* TNCODE */ if (stuff > -1) { /* Stuffing another character... */ xx = oboc(dopar((CHAR)stuff)); if (xx < 0) goto outerr; if (seslog && duplex) /* Log stuffed char if appropriate */ if (zchout(ZSFILE, (CHAR)stuff) < 0) seslog = 0; } if (stuff2 > -1) { /* Stuffing another character... */ xx = oboc(dopar((CHAR)stuff2)); if (xx < 0) goto outerr; if (seslog && duplex) /* Log stuffed char if appropriate */ if (zchout(ZSFILE, (CHAR)stuff2) < 0) seslog = 0; } if (xxout(obuf,obn) < 0) /* Flushing is required here! */ goto outerr; } } if (quote == 1) /* String ended with backslash */ xx = oboc(dopar(CMDQ)); if (obn > 0) /* OUTPUT done */ if (xxout(obuf,obn) < 0) /* Flush the buffer if necessary. */ goto outerr; return(1);outerr: /* OUTPUT command error handler */ if (msgflg) printf("OUTPUT error\n"); return(0);/* Remove "local" OUTPUT macro defininitions */#ifdef COMMENT/* No more macros ... */#undef oboc#undef obfls#endif /* COMMENT */}#endif /* NOSPL *//* Display version herald and initial prompt */VOIDherald() { int x = 0; if (noherald || bgset > 0 || (bgset != 0 && backgrd != 0)) x = 1; debug(F101,"herald","",backgrd); if (x == 0) {#ifdef datageneral printf("%s, for%s\n",versio,ckxsys);#else#ifdef OSK printf("%s, for%s\n",versio,ckxsys);#else printf("%s, for%s\n\r",versio,ckxsys);#endif /* OSK */#endif /* datageneral */ printf(" Copyright (C) 1985, 1996,\n"); printf(" Trustees of Columbia University in the City of New York.\n");#ifdef OS2 shoreg();#endif /* OS2 */ if (!quiet && !backgrd) { char *s = NULL; switch (binary) { case XYFT_T: s = "TEXT"; break;#ifdef VMS case XYFT_B: s = "BINARY FIXED"; break; case XYFT_I: s = "IMAGE"; break; case XYFT_L: s = "LABELED"; break; case XYFT_U: s = "BINARY UNDEF"; break;#else#ifdef MAC case XYFT_B: s = "BINARY"; break; case XYFT_M: s = "MACBINARY"; break;#else case XYFT_B: s = "BINARY"; break;#ifdef CK_LABELED case XYFT_L: s = "LABELED"; break;#endif /* CK_LABELED */#endif /* MAC */#endif /* VMS */ } if (s) printf("Default file-transfer mode is %s\n", s);#ifdef COMMENT#ifdef NT printf("\n"); printf("StartedFromDialer = %d\n",StartedFromDialer); printf("Window Handle = %ld\n",DialerHandle); printf("\n");#endif /* NT */#endif /* COMMENT */ printf("Type ? or HELP for help.\n"); } }}#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. *//* Returns -1 on failure, 0 on success. */intaddmac(nam,def) char *nam, *def; { /* Add a macro to the macro table */ int i, x, y, z, namlen, deflen; char * p = NULL, 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 (maclv
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -