📄 ckuus5.c
字号:
#ifdef USE_LUCACHE x = lookup(cmdtab,"if",ncmd,&y); lucmd[lusize] = "if"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(iftab,"not",nif,&y); lucmd[lusize] = "not"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = iftab; if (++lusize > LUCACHE) return; x = lookup(vartab,"cmdlevel",nvars,&y); lucmd[lusize] = "cmdlevel"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = vartab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"goto",ncmd,&y); lucmd[lusize] = "goto"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(iftab,">",nif,&y); lucmd[lusize] = ">"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = iftab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"incr",ncmd,&y); lucmd[lusize] = "incr"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"def",ncmd,&y); lucmd[lusize] = "def"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"_assign",ncmd,&y); lucmd[lusize] = "_assign"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"echo",ncmd,&y); lucmd[lusize] = "echo"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(fnctab,"eval",nfuncs,&y); lucmd[lusize] = "eval"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = fnctab; if (++lusize > LUCACHE) return; x = lookup(fnctab,"lit",nfuncs,&y); lucmd[lusize] = "lit"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = fnctab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"do",ncmd,&y); lucmd[lusize] = "do"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"_getargs",ncmd,&y); lucmd[lusize] = "_getargs"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(iftab,"<",nif,&y); lucmd[lusize] = "<"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = iftab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"_putargs",ncmd,&y); lucmd[lusize] = "_putargs"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"asg",ncmd,&y); lucmd[lusize] = "asg"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab; if (++lusize > LUCACHE) return; x = lookup(cmdtab,"else",ncmd,&y); lucmd[lusize] = "else"; luval[lusize] = x; luidx[lusize] = y; lutab[lusize] = cmdtab;#endif /* USE_LUCACHE */}VOIDcmdini() { int i = 0, x = 0, y = 0, z = 0, skip = 0; char * p;#ifdef TTSPDLIST long * ss = NULL; extern int nspd; extern struct keytab * spdtab;#endif /* TTSPDLIST */#ifndef NOSPL/* On stack to allow recursion!*/ char vnambuf[VNAML]; /* Buffer for variable names */#endif /* NOSPL */ if (cmdinited) /* Already initialized */ return; /* Don't do it again */ for (i = 0; i < CMDSTKL; i++) /* Prompt strings for each */ prstring[i] = NULL; /* command level */#ifndef NOCSETS p = getenv("K_CHARSET"); /* Set default file character set */ if (p) { /* from environment */ x = lookup(fcstab,p,nfilc,&y); if (x > -1) fcharset = x; }#endif /* NOCSETS */ p = getenv("K_INFO_DIRECTORY"); /* Find Kermit info directory */ if (p && *p && strlen(p) <= CKMAXPATH) makestr(&k_info_dir,p); if (!k_info_dir) { p = getenv("K_INFO_DIR"); if (p && *p && strlen(p) <= CKMAXPATH) makestr(&k_info_dir,p); }#ifdef UNIX if (k_info_dir) { /* Look for Kermit docs directory */ if (zchki(k_info_dir) == -2) { char xbuf[CKMAXPATH+32], *s = ""; if (ckrchar(k_info_dir) != '/') s = "/"; ckmakmsg(xbuf,CKMAXPATH+32,k_info_dir,s,"ckubwr.txt",NULL); if (zchki(xbuf) < 0) makestr(&k_info_dir,NULL); } } if (!k_info_dir) { char xbuf[CKMAXPATH+32]; int i; for (i = 0; *(txtdir[i]); i++) { ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"ckubwr.txt",NULL,NULL); if (zchki(xbuf) > 0) { makestr(&k_info_dir,txtdir[i]); debug(F110,"k_info_dir 1",k_info_dir,0); break; } ckmakmsg(xbuf,CKMAXPATH+32, txtdir[i],"kermit/","ckubwr.txt",NULL); if (zchki(xbuf) > 0) { ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"kermit/",NULL,NULL); makestr(&k_info_dir,xbuf); debug(F110,"k_info_dir 2",k_info_dir,0); break; } ckmakmsg(xbuf,CKMAXPATH+32, txtdir[i],"ckermit/","ckubwr.txt",NULL); if (zchki(xbuf) > 0) { ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"ckermit/",NULL,NULL); makestr(&k_info_dir,xbuf); debug(F110,"k_info_dir 3",k_info_dir,0); break; } } if (k_info_dir) { /* Make sure it ends with "/" */ if (ckrchar(k_info_dir) != '/') { char xbuf[CKMAXPATH+32]; ckmakmsg(xbuf,CKMAXPATH+32,k_info_dir,"/",NULL,NULL); makestr(&k_info_dir,xbuf); } } }#else#ifdef OS2 { char xdir[CKMAXPATH+8], *s = ""; extern char startupdir[]; xdir[0] = NUL; if (ckrchar(startupdir) != '/') s = "/"; if (strlen(s) + strlen(startupdir) + 5 < CKMAXPATH + 8 ) ckmakmsg(xdir,CKMAXPATH+8,s,startupdir,"DOC/",NULL); makestr(&k_info_dir,xdir); }#endif /* OS2 */#endif /* UNIX */#ifdef TTSPDLIST if (!spdtab && (ss = ttspdlist())) { /* Get speed list if necessary */ int j, k, m = 0, n; /* Create sorted keyword table */ char buf[16]; char * p; if ((spdtab = (struct keytab *) malloc(sizeof(struct keytab) * ss[0]))) { for (i = 1; i <= ss[0]; i++) { /* ss[0] = number of elements */ if (ss[i] < 1L) break; /* Shouldn't happen */ buf[0] = NUL; /* Make string */ sprintf(buf,"%ld",ss[i]); /* SAFE */ if (ss[i] == 8880L) ckstrncpy(buf,"75/1200",sizeof(buf)); if (ss[i] == 134L) ckstrncat(buf,".5",16); n = strlen(buf); if ((n > 0) && (p = (char *)malloc(n+1))) { if (m > 0) { /* Have at least one in list */ for (j = 0; /* Find slot */ j < m && strcmp(buf,spdtab[j].kwd) > 0; j++ ) ; if (j < m) { /* Must insert */ for (k = m-1; k >= j; k--) { /* Move others down */ spdtab[k+1].kwd = spdtab[k].kwd; spdtab[k+1].flgs = spdtab[k].flgs; spdtab[k+1].kwval = spdtab[k].kwval; } } } else /* First one */ j = 0; ckstrncpy(p,buf,n+1); /* Add new speed */ spdtab[j].kwd = p; spdtab[j].flgs = 0; spdtab[j].kwval = (int) ss[i] / 10; m++; /* Count this one */ } } } nspd = m; }#endif /* TTSPDLIST */#ifndef NOSPL /* Allocate INPUT command buffer */ if (!inpbuf) { if (!(inpbuf = (char *) malloc(INPBUFSIZ+1))) fatal("cmdini: no memory for INPUT buffer"); } for (x = 0; x < INPBUFSIZ; x++) /* Initialize it */ inpbuf[x] = NUL; inpbp = inpbuf; /* Initialize pointer */ inbufsize = INPBUFSIZ; /* and size. */#endif /* NOSPL */#ifdef DCMDBUF if (cmsetup() < 0) fatal("Can't allocate command buffers!");#ifndef NOSPL /* Allocate command stack allowing command parser to call itself */ 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"); if (!(intime = (int *) malloc(sizeof(int)*CMDSTKL))) fatal("cmdini: no memory for intime"); if (!(inpcas = (int *) malloc(sizeof(int)*CMDSTKL))) fatal("cmdini: no memory for inpcas"); if (!(takerr = (int *) malloc(sizeof(int)*CMDSTKL))) fatal("cmdini: no memory for takerr"); if (!(merror = (int *) malloc(sizeof(int)*CMDSTKL))) fatal("cmdini: no memory for merror"); if (!(xquiet = (int *) malloc(sizeof(int)*CMDSTKL))) fatal("cmdini: no memory for xquiet"); if (!kermrc) if (!(kermrc = (char *) malloc(KERMRCL+1))) fatal("cmdini: no memory for kermrc");#ifdef CK_APC/* Application Program Command buffer */ if (!(apcbuf = malloc(APCBUFLEN + 1))) fatal("cmdini: no memory for apcbuf");#endif /* CK_APC */#endif /* NOSPL *//* line[] and tmpbuf[] are the two string buffers used by the command parser */ if (!(line = malloc(LINBUFSIZ + 1))) fatal("cmdini: no memory for line"); if (!(tmpbuf = malloc(LINBUFSIZ + 1))) fatal("cmdini: no memory for tmpbuf");#endif /* DCMDBUF */#ifndef NOSPL#ifdef CK_MINPUT { /* Initialize MINPUT pointers */ int i; extern char *ms[]; for (i = 0; i < MINPMAX; i++) ms[i] = NULL; }#endif /* CK_MINPUT */ if (macini() < 0) /* Allocate macro buffers */ fatal("Can't allocate macro buffers!"); ifcmd[0] = 0; /* Command-level related variables. */ iftest[0] = 0; /* Initialize variables at top level */ count[0] = 0; /* of stack... */ intime[0] = 0; inpcas[0] = 0; takerr[0] = 0; merror[0] = 0; xquiet[0] = quiet;#endif /* NOSPL */#ifndef NOSPL cmdlvl = 0; /* Initialize the command stack */ xcmdsrc = CMD_KB; cmdstk[cmdlvl].src = CMD_KB; /* Source is console */ cmdstk[cmdlvl].lvl = 0; /* Level is 0 */ cmdstk[cmdlvl].ccflgs = 0; /* No flags */#endif /* NOSPL */ tlevel = -1; /* Take file level = keyboard */ for (i = 0; i < MAXTAKE; i++) /* Initialize command file names */ tfnam[i] = NULL; cmsetp(ckprompt); /* Set up C-Kermit's prompt */ /* Can't set IKSD prompt here since */ /* we do not yet know if we are IKSD */#ifndef NOSPL initmac(); /* Initialize macro table *//* Predefine built-in one-line macros */ addmac("ibm-linemode",m_ibm); /* IBM-LINEMODE */ addmac("fatal",m_fat); /* FATAL macro */ y = addmac("fast",m_fast); /* FAST macro */ addmac("cautious",m_cautious); /* CAUTIOUS macro */ addmac("robust",m_robust); /* ROBUST macro */#ifdef OS2 addmac("manual",m_manual); /* MANUAL macro */#endif /* OS2 */#ifdef VMS addmac("purge",m_purge); /* PURGE macro */#endif /* VMS *//* Predefine built-in multiline macros; these are top-level commands that are implemented internally as macros. NOTE: When adding a new one of these, remember to update the END and RETURN commands to account for it, or else END and RETURN from within it won't work right.*/ x = addmmac("_forx",for_def); /* FOR macro */ if (x > -1) mactab[x].flgs = CM_INV; x = addmmac("_forz",foz_def); /* Other FOR macro */ if (x > -1) mactab[x].flgs = CM_INV; x = addmmac("_xif",xif_def); /* XIF macro */ if (x > -1) mactab[x].flgs = CM_INV; x = addmmac("_while",whil_def); /* WHILE macro */ if (x > -1) mactab[x].flgs = CM_INV; x = addmmac("_switx",sw_def); /* SWITCH macro */ if (x > -1) mactab[x].flgs = CM_INV;/* Fill in command-line argument vector */ sprintf(vnambuf,"\\&@[%d]",xargs); /* SAFE */ if (inserver) { /* But hidden in IKSD */ y = -1; xargs = 0; } else y = arraynam(vnambuf,&x,&z); /* goes in array \&@[] */ tmpbuf[0] = NUL; if (y > -1) { int j = -1; int yy = 0; dclarray((char)x,z); /* Declare the array */#ifndef NOTAKEARGS /* Macro argument vector */ sprintf(vnambuf,"\\&_[%d]",z); /* SAFE */ yy = arraynam(vnambuf,&x,&z); /* goes in array \&_[] */ if (yy > -1) /* Name is OK */ dclarray((char)x,z); /* Declare the array */#endif /* NOTAKEARGS */ skip = 0; for (i = 0; i < xargs; i++) { /* Fill the arrays */ sprintf(vnambuf,"\\&@[%d]",i); /* SAFE */ addmac(vnambuf,xargv[i]); if (cfilef && i == 0) continue;#ifdef KERBANG if (skip) { j = 0; skip = 0; continue; }#endif /* KERBANG */ if (j < 0 && /* Assign items after "=" or "--"*/ (!strcmp(xargv[i],"=") || !strcmp(xargv[i],"--")) ) { j = 0; /* to \%1..\%9 */#ifdef KERBANG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -