📄 ckuus5.c
字号:
sesfil[];#ifndef NOFRILLSextern int rmailf, rprintf; /* REMOTE MAIL & PRINT items */extern char optbuf[];#endif /* NOFRILLS */char *homdir = ""; /* Pointer to home directory string */char numbuf[20]; /* Buffer for numeric strings. */int noinit = 0; /* Flag for skipping init file */#ifndef NOSPL_PROTOTYP( VOID freelocal, (int) );_PROTOTYP( static long expon, (long, long) );_PROTOTYP( static long gcd, (long, long) );_PROTOTYP( static long fact, (long) );int /* Initialize macro data structures. */macini() { /* Allocate mactab and preset the first element. */ int i; if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX))) return(-1); mactab[0].kwd = NULL; mactab[0].mval = NULL; mactab[0].flgs = 0; for (i = 0; i < MACLEVEL; i++) localhead[i] = NULL; return(0);}#endif /* NOSPL *//* C M D I N I -- Initialize the interactive command parser */ static int cmdinited = 0;VOIDcmdini() { int i, x, y, z, n;#ifndef NOSPL/* On stack to allow recursion!*/ char vnambuf[VNAML]; /* Buffer for variable names */#endif /* NOSPL */ if (cmdinited) return;#ifndef NOSETKEY /* Allocate & initialize the keymap */ if (!(keymap = (KEY *) malloc(sizeof(KEY)*KMSIZE))) fatal("cmdini: no memory for keymap"); if (!(macrotab = (MACRO *) malloc(sizeof(MACRO)*KMSIZE))) fatal("cmdini: no memory for macrotab"); for (i = 0; i < KMSIZE; i++) { keymap[i] = (KEY) i; macrotab[i] = NULL; }#endif /* NOSETKEY */#ifndef NOSPL if (!inpbuf) { if (!(inpbuf = (char *) malloc(INPBUFSIZ+1))) fatal("cmdini: no memory for INPUT buffer"); } for (x = 0; x < INPBUFSIZ; x++) inpbuf[x] = NUL; inpbp = inpbuf; inbufsize = INPBUFSIZ;#endif /* NOSPL */#ifdef DCMDBUF if (cmsetup() < 0) fatal("Can't allocate command buffers!");#ifndef NOSPL 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 (!kermrc) if (!(kermrc = (char *) malloc(KERMRCL+1))) fatal("cmdini: no memory for kermrc");#endif /* NOSPL */ if (!(line = malloc(LINBUFSIZ))) fatal("cmdini: no memory for line"); if (!(tmpbuf = malloc(LINBUFSIZ))) fatal("cmdini: no memory for tmpbuf");#ifdef CK_APC if (!(apcbuf = malloc(APCBUFLEN))) fatal("cmdini: no memory for apcbuf");#endif /* CK_APC */#endif /* DCMDBUF */#ifdef CK_MINPUT { /* Initialize MINPUT pointers */ int i; extern char *ms[]; for (i = 0; i < MINPMAX; i++) ms[i] = NULL; }#endif /* CK_MINPUT */#ifndef NOSPL if (macini() < 0) 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;#endif /* NOSPL */#ifdef AMIGA if (tlevel < 0) concb(escape);#endif /* AMIGA */#ifndef NOSPL cmdlvl = 0; /* Initialize the command stack */ 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;#ifdef NT/* We tell the difference between Windows NT and 95 at runtime. */ if (isWin95())#ifdef NOSPL ckprompt = "K-95> "; /* Default prompt for Windows 95 */#else ckprompt = "[\\v(dir)] K-95> ";#endif /* NOSPL */#endif /* NT */ cmsetp(ckprompt);#ifndef NOSPL initmac(); /* Initialize macro table *//* Add one-line macros */ addmac("ibm-linemode",m_ibm); /* Add built-in macros. */ 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 *//* Add multiline macros */ addmmac("_forx",for_def); /* FOR macro. */ addmmac("_xif",xif_def); /* XIF macro. */ addmmac("_while",whil_def); /* WHILE macro. */ addmmac("_switx",sw_def); /* SWITCH macro. *//* Predefine the macro argument vector */ strcpy(vnambuf,"\\&_[10]"); /* Macro argument vector */ y = arraynam(vnambuf,&x,&z); /* goes in array \&_[] */ if (y > -1) { dclarray((char)x,z); /* Declare the array */ for (i = 0; i < 10; i++) { /* Fill it */ sprintf(vnambuf,"\\&_[%d]",i); /* with NULL pointers */ addmac(vnambuf,NULL); } } *vnambuf = NUL;/* Fill in command line argument vector */ sprintf(vnambuf,"\\&@[%d]",xargs); /* Command line argument vector */ y = arraynam(vnambuf,&x,&z); /* goes in array \&@[] */ if (y > -1) { dclarray((char)x,z); /* Declare the array */ for (i = 0; i < xargs; i++) { /* Fill it */ sprintf(vnambuf,"\\&@[%d]",i); addmac(vnambuf,xargv[i]); } } *vnambuf = NUL;#endif /* NOSPL */#ifdef CK_TTGWSIZ#ifdef OS2 ttgcwsz();#else /* OS2 */ if (ttgwsiz() > 0) { if (tt_rows > 0 && tt_cols > 0) { cmd_rows = tt_rows; cmd_cols = tt_cols; } }#endif /* OS2 */#endif /* CK_TTGWSIZ *//* Get our home directory now. This needed in lots of places. */ homdir = zhome(); cmdinited = 1;}VOIDdoinit() {#ifdef OS2 char * ptr = 0; extern int initvik;#endif /* OS2 */ if (!cmdinited) cmdini();#ifdef MAC return; /* Mac Kermit has no init file */#else /* !MAC */#ifdef OS2 keymapinit(); keynaminit();#ifdef OS2MOUSE mousemapinit(-1,-1);#endif /* OS2MOUSE */ initvik = 1;#endif /* OS2 *//* If skipping init file ('-Y' on Kermit command line), return now. */ if (noinit) { kermrc[0] = '\0'; inidir[0] = '\0'; /* But returning from here results in inidir[] never being set to anything. Instead it should be set to wherever the init file *would* have been executed from. So this bit of code should be removed, and then we should sprinkle "if (noinit)" tests throughout the following code until we have set inidir[], and then return without actually taking the init file.*/ return; }#ifdef OS2/* The -y init file must be fully specified or in the current directory. KERMRC is looked for via INIT, DPATH and PATH in that order. Finally, our own executable file path is taken and the .EXE suffix is replaced by .INI and this is tried as the initialization file.*/ if (rcflag) { strcpy(line, kermrc); } else { char * env = 0;#ifdef NT env = getenv("K95.INI");#else env = getenv("K2.INI");#endif /* NT */ if (!env) env = getenv("CKERMIT.INI"); if (!env) env = getenv("CKERMIT_INI"); line[0] = '\0'; if (env) strcpy(line,env); if (line[0] == 0) _searchenv(kermrc,"INIT",line); if (line[0] == 0) _searchenv(kermrc,"DPATH",line); if (line[0] == 0) _searchenv(kermrc,"PATH",line); if (line[0] == 0) { char *pgmptr = GetLoadPath(); if (pgmptr) { lp = strrchr(pgmptr, '.'); strncpy(line, pgmptr, lp - pgmptr); strcpy(line + (lp - pgmptr), ".ini"); } } } if ((tfile[0] = fopen(line,"r")) != NULL) { tlevel = 0; tfline[tlevel] = 0; if (tfnam[tlevel] = malloc(strlen(line)+1)) strcpy(tfnam[tlevel],line);#ifndef NOSPL cmdlvl++; cmdstk[cmdlvl].src = CMD_TF; cmdstk[cmdlvl].lvl = tlevel; cmdstk[cmdlvl].ccflgs = 0; ifcmd[cmdlvl] = 0; iftest[cmdlvl] = 0; count[cmdlvl] = count[cmdlvl-1]; /* Inherit from previous level */ intime[cmdlvl] = intime[cmdlvl-1]; inpcas[cmdlvl] = inpcas[cmdlvl-1]; takerr[cmdlvl] = takerr[cmdlvl-1]; merror[cmdlvl] = merror[cmdlvl-1];#endif /* NOSPL */ debug(F110,"doinit init file",line,0); } else { debug(F100,"doinit no init file","",0); } strncpy(kermrc,line,KERMRCL); /* XXXX */ for (ptr = kermrc; *ptr; ptr++) /* Convert backslashes to slashes */ if (*ptr == '\\') *ptr = '/';#else /* not OS2 */ lp = line; lp[0] = '\0';#ifdef GEMDOS zkermini(line, rcflag, kermrc);#else#ifdef VMS zkermini(line,LINBUFSIZ,kermrc);#else /* not VMS */ if (rcflag) { /* If init file name from cmd line */ strcpy(lp,kermrc); /* use it, */ } else { /* otherwise... */#ifdef CK_INI_A /* If we've a system-wide init file */ /* And it takes precedence over the user's... */ strncpy(lp,CK_SYSINI,KERMRCL); /* Use it */ if (zchki(lp) < 0) { /* (if it exists...) */#endif /* CK_INI_A */ line[0] = NUL; if (homdir) { /* Home directory for init file. */ strcpy(lp,homdir);#ifdef STRATUS strcat(lp,">"); /* VOS separates dirs with >'s */#else if (lp[0] == '/') strcat(lp,"/");#endif /* STRATUS */ } strcat(lp,kermrc); /* Append the default file name */#ifdef CK_INI_A }#endif /* CK_INI_A */ }#ifdef CK_INI_B /* System-wide init defined? */ /* But user's ini file takes precedence */ if (zchki(lp) < 0) /* If user doesn't have her own, */ strncpy(lp,CK_SYSINI,KERMRCL); /* use system-wide one. */#endif /* CK_INI_B */#endif /* VMS */#endif /* GEMDOS */#ifdef AMIGA reqoff(); /* Disable requestors */#endif /* AMIGA */ debug(F110,"ini file is",line,0); if ((tfile[0] = fopen(line,"r")) != NULL) { /* Try to open init file. */ tlevel = 0; tfline[tlevel] = 0; if (tfnam[tlevel] = malloc(strlen(line)+1)) strcpy(tfnam[tlevel],line); strncpy(kermrc,line,KERMRCL); /* XXXX */#ifndef NOSPL cmdlvl++; ifcmd[cmdlvl] = 0; iftest[cmdlvl] = 0; count[cmdlvl] = count[cmdlvl-1]; /* Inherit from previous level */ intime[cmdlvl] = intime[cmdlvl-1]; inpcas[cmdlvl] = inpcas[cmdlvl-1]; takerr[cmdlvl] = takerr[cmdlvl-1]; merror[cmdlvl] = merror[cmdlvl-1]; debug(F101,"open ok","",cmdlvl); cmdstk[cmdlvl].src = CMD_TF; cmdstk[cmdlvl].lvl = tlevel; cmdstk[cmdlvl].ccflgs = 0;#endif /* NOSPL */ debug(F110,"init file",line,0); }#ifdef datageneral/* If CKERMIT.INI not found in home directory, look in searchlist */ if (homdir && (tlevel < 0)) { strcpy(lp,kermrc); if ((tfile[0] = fopen(line,"r")) != NULL) { tlevel = 0; tfline[tlevel] = 0; if (tfnam[tlevel] = malloc(strlen(line)+1)) strcpy(tfnam[tlevel],line);#ifndef NOSPL cmdlvl++; cmdstk[cmdlvl].src = CMD_TF; cmdstk[cmdlvl].lvl = tlevel; cmdstk[cmdlvl].ccflgs = 0; ifcmd[cmdlvl] = 0; iftest[cmdlvl] = 0; count[cmdlvl] = count[cmdlvl-1]; /* Inherit from previous level */ intime[cmdlvl] = intime[cmdlvl-1]; inpcas[cmdlvl] = inpcas[cmdlvl-1]; takerr[cmdlvl] = takerr[cmdlvl-1]; merror[cmdlvl] = merror[cmdlvl-1];#endif /* NOSPL */ } }#endif /* datageneral */#ifdef AMIGA /* Amiga... */ reqpop(); /* Restore requestors */#endif /* AMIGA */#endif /* OS2 */#endif /* MAC */ /* Assign value to inidir */ strcpy(inidir, kermrc); { int x; x = strlen(inidir); if (x > 0) { int i; for (i = x - 1; i > 0; i-- ) { if (inidir[i] ==#ifdef MAC '/'#else#ifdef UNIX '/'#else#ifdef OSK '/'#else#ifdef STRATUS '>'#else#ifdef VMS ']' || inidir[i] == ':'#else#ifdef datageneral ':'#else#ifdef OS2 '/' || inidir[i+1] == '\\'#else#ifdef AMIGA '/' || inidir[i+1] == ':'#endif /* AMIGA */#endif /* OS2 */#endif /* datageneral */#endif /* VMS */#endif /* STRATUS */#endif /* OSK */#endif /* UNIX */#endif /* MAC */ ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -