home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / old / ckermit5a188 / ckuus5.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  102KB  |  3,809 lines

  1. #ifndef NOICP
  2.  
  3. /*  C K U U S 5 --  "User Interface" for Unix Kermit, part 5  */
  4.  
  5. /*
  6.   Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  7.   Columbia University Center for Computing Activities.
  8.   First released January 1985.
  9.   Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
  10.   York.  Permission is granted to any individual or institution to use this
  11.   software as long as it is not sold for profit.  This copyright notice must be
  12.   retained.  This software may not be included in commercial products without
  13.   written permission of Columbia University.
  14. */
  15.  
  16. /* Includes */
  17.  
  18. #include "ckcdeb.h"
  19. #include "ckcasc.h"
  20. #include "ckcker.h"
  21. #include "ckuusr.h"
  22. #include "ckcnet.h"
  23. #ifndef NOCSETS
  24. #include "ckcxla.h"
  25. #endif /* NOCSETS */
  26. #ifdef MAC
  27. #include "ckmasm.h"
  28. #endif /* MAC */
  29.  
  30. /* For formatted screens, "more?" prompting, etc. */
  31.  
  32. #define SCRNLEN 21            /* Screen length */
  33. #define SCRNWID 79            /* Screen width */
  34.  
  35. #ifdef FT18
  36. #define isxdigit(c) isdigit(c)
  37. #endif /* FT18 */
  38.  
  39. #ifdef MAC                /* Internal MAC file routines */
  40. #define feof mac_feof
  41. #define rewind mac_rewind
  42. #define fgets mac_fgets
  43. #define fopen mac_fopen
  44. #define fclose mac_fclose
  45.  
  46. int mac_feof();
  47. void mac_rewind();
  48. char *mac_fgets();
  49. FILE *mac_fopen();
  50. int mac_fclose();
  51. #endif /* MAC */
  52.  
  53. /* External variables */
  54.  
  55. extern int carrier, cdtimo, local, backgrd, bgset, sosi, suspend,
  56.   displa, binary, deblog, escape, xargs, flow, cmdmsk,
  57.   duplex, ckxech, pktlog, seslog, tralog, what,
  58.   keep, warn, tlevel, cwdf, nfuncs, unkcs, msgflg,
  59.   mdmtyp, zincnt, cmask, rcflag, success, xitsta, pflag, lf_opts, tnlm, tn_nlm;
  60.  
  61. extern char *ccntab[];
  62.  
  63. #ifndef NOFRILLS
  64. extern int en_cwd, en_del, en_dir, en_fin, en_bye,
  65.   en_get, en_hos, en_sen, en_set, en_spa, en_typ, en_who;
  66. #endif /* NOFRILLS */
  67. extern long vernum;
  68. extern int srvtim, srvdis, inecho, insilence, nvars, verwho;
  69. extern char *protv, *fnsv, *cmdv, *userv, *ckxv, *ckzv, *ckzsys, *xlav,
  70.  *cknetv, *clcmds;
  71. extern char *connv, *dialv, *loginv, *nvlook();
  72.  
  73. #ifndef NOSCRIPT
  74. extern int secho;
  75. #endif /* NOSCRIPT */
  76.  
  77. #ifndef NODIAL
  78. extern int nmdm;
  79. extern struct keytab mdmtab[];
  80. #endif /* NODIAL */
  81.  
  82. #ifdef NETCONN
  83. extern int tn_init, network, ttnproto;
  84. #endif /* NETCONN */
  85.  
  86. #ifdef OS2
  87. extern int tt_type, tt_arrow, tt_keypad, tt_wrap, tt_answer;
  88. #endif /* OS2 */
  89. extern int tt_crd;
  90.  
  91. #ifndef NOCSETS
  92. extern int language, nfilc, tcsr, tcsl;
  93. extern struct keytab fcstab[];
  94. extern struct csinfo fcsinfo[];
  95. #ifndef MAC
  96. extern struct keytab ttcstab[];
  97. #endif /* MAC */
  98. #endif /* NOCSETS */
  99.  
  100. extern int atcapr,
  101.   atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,
  102.   attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso; 
  103.  
  104. extern long speed;
  105.  
  106. extern char *DIRCMD, *PWDCMD, *DELCMD;
  107. #ifndef NOXMIT
  108. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw;
  109. extern char xmitbuf[];
  110. #endif /* NOXMIT */
  111.  
  112. extern char **xargv, *versio, *ckxsys, *dftty, *cmarg, *lp;
  113.  
  114. #ifdef DCMDBUF
  115. extern char *cmdbuf, *atmbuf;        /* Command buffers */
  116. #ifndef NOSPL
  117. extern char *savbuf;            /* Command buffers */
  118. #endif /* NOSPL */
  119. #else
  120. extern char cmdbuf[], atmbuf[];        /* Command buffers */
  121. #ifndef NOSPL
  122. extern char savbuf[];            /* Command buffers */
  123. #endif /* NOSPL */
  124. #endif /* DCMDBUF */
  125.  
  126. extern char toktab[], ttname[], psave[];
  127. extern CHAR sstate;
  128. extern int cmflgs, techo, repars, ncmd;
  129. extern struct keytab cmdtab[];
  130.  
  131. #ifndef MAC
  132. #ifndef NOSETKEY
  133. KEY *keymap;
  134. MACRO *macrotab;
  135. #endif /* NOSETKEY */
  136. #endif /* MAC */
  137.  
  138. #ifndef NOSPL
  139. extern struct mtab *mactab;
  140. extern struct keytab vartab[], fnctab[];
  141. extern int cmdlvl, maclvl, nmac, mecho;
  142. #endif /* NOSPL */
  143.  
  144. FILE *tfile[MAXTAKE];            /* TAKE file stack */
  145. char *tfnam[MAXTAKE];
  146.  
  147. #ifndef NOSPL
  148. /* Local declarations */
  149.  
  150. int nulcmd = 0;            /* Flag for next cmd to be ignored */
  151.  
  152. /* Definitions for built-in macros */
  153.  
  154. /* First, the single line macros, installed with addmac()... */
  155.  
  156. /* IBM-LINEMODE macro */
  157. char *m_ibm = "set parity mark, set dupl half, set handsh xon, set flow none";
  158.  
  159. /* FATAL macro */
  160. char *m_fat = "if def \\%1 echo \\%1, if not = \\v(local) 0 hangup, stop 1";
  161.  
  162. #ifdef COMMENT
  163. /*
  164.   Long macro definitions were formerly done like this.  But some compilers
  165.   cannot handle continued string constants, others cannot handle string
  166.   constants that are this long.  So these definitions have been broken up
  167.   into pieces and put into arrays, see below.
  168. */
  169. char *m_forx = "if def _floop ass \\%9 \\fdef(_floop),else def \\%9,\
  170. ass _floop { _getargs,\
  171. define \\\\\\%1 \\%2,:top,if \\%5 \\\\\\%1 \\%3 goto bot,\
  172. \\%6,:inc, incr \\\\\\%1 \\%4,goto top,:bot,_putargs,return},\
  173. def break goto bot, def continue goto inc,\
  174. do _floop \\%1 \\%2 \\%3 \\%4 { \\%5 },assign _floop \\fcont(\\%9)";
  175.  
  176. char *m_while = "if def _wloop ass \\%9 \\fdef(_wloop),\
  177. ass _wloop {_getargs,:wtest,\\%1,\\%2,goto wtest,:wbot,_putargs,return},\
  178. def break goto wbot, def continue goto wtest,\
  179. do _wloop,assign _wloop \\fcont(\\%9)";
  180.  
  181. char *m_xif = "ass \\%9 \\fdef(_ify),ass _ify {_getargs, \\%1, _putargs},\
  182. do _ify,ass _ify \\fcont(\\%9)";
  183. #endif /* COMMENT */
  184.  
  185. /* Now the multiline macros, defined with addmmac()... */
  186.  
  187. /* FOR macro */
  188. char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
  189. "define \\\\\\%1 \\%2,:top,if \\%5 \\\\\\%1 \\%3 goto bot,",
  190. "\\%6,:inc,incr \\\\\\%1 \\%4,goto top,:bot,_putargs},",
  191. "def break goto bot, def continue goto inc,",
  192. "do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
  193. ""};
  194. #ifdef COMMENT
  195. /*
  196.   This one didn't work right.  When an interior loop finished executing,
  197.   the definition of the enclosing loop was restored, but the new definition
  198.   could be in a different location in memory, so its macro execution pointer
  199.   could (and usually was) pointing at garbage.
  200. */
  201. char *old_for_def[] = { "if def _floop ass \\%9 \\fdef(_floop),else def \\%9,",
  202. "ass _floop { _getargs,",
  203. "define \\\\\\%1 \\%2,:top,if \\%5 \\\\\\%1 \\%3 goto bot,",
  204. "\\%6,:inc, incr \\\\\\%1 \\%4,goto top,:bot,_putargs,return},",
  205. "def break goto bot, def continue goto inc,",
  206. "do _floop \\%1 \\%2 \\%3 \\%4 { \\%5 },assign _floop \\fcont(\\%9)",
  207. ""};
  208. #endif /* COMMENT */
  209.  
  210. /* WHILE macro */
  211. char *whil_def[] = { "_assign _whi\\v(cmdlevel) {_getargs,",
  212. ":wtest,\\%1,\\%2,goto wtest,:wbot,_putargs},",
  213. "def break goto wbot, def continue goto wtest,",
  214. "do _whi\\v(cmdlevel),_assign _whi\\v(cmdlevel)",
  215. ""};
  216. #ifdef COMMENT
  217. /*
  218.   Same deal as FOR loop...
  219. */
  220. char *old_whil_def[] = { "if def _wloop asg \\%9 \\fdef(_wloop),",
  221. "asg _wloop {_getargs,:wtest,\\%1,\\%2,goto wtest,:wbot,_putargs,return},",
  222. "def break goto wbot, def continue goto wtest,",
  223. "do _wloop,assign _wloop \\fcont(\\%9)",
  224. ""};
  225. #endif /* COMMENT */
  226.  
  227. /* XIF macro */
  228. char *xif_def[] = {
  229. "_assign _if\\v(cmdlevel) {_getargs,\\%1,_putargs},",
  230. "do _if\\v(cmdlevel),_assign _if\\v(cmdlevel)",
  231. ""};
  232. #ifdef COMMENT
  233. /* Same deal */
  234. char *old_xif_def[] = {
  235. "asg \\%9 \\fdef(_ify),ass _ify {_getargs, \\%1, _putargs},",
  236. "do _ify,ass _ify \\fcont(\\%9)",
  237. ""};
  238. #endif /* COMMENT */
  239.  
  240. /* Variables declared here for use by other ckuus*.c modules */
  241. /* Space is allocated here to save room in ckuusr.c */
  242.  
  243. #ifdef DCMDBUF
  244. struct cmdptr *cmdstk;
  245. int *ifcmd, *count, *iftest, *intime, *incase, *terror, *merror;
  246. #else
  247. struct cmdptr cmdstk[CMDSTKL];
  248. int ifcmd[CMDSTKL], count[CMDSTKL], iftest[CMDSTKL], intime[CMDSTKL],
  249.   incase[CMDSTKL], terror[CMDSTKL], merror[CMDSTKL];
  250. #endif /* DCMDBUF */
  251.  
  252. char *m_arg[MACLEVEL][NARGS];
  253. char *g_var[GVARS], *macp[MACLEVEL], *mrval[MACLEVEL];
  254. int macargc[MACLEVEL];
  255. char *macx[MACLEVEL];
  256. extern char varnam[];
  257.  
  258. char **a_ptr[27];            /* Array pointers, for arrays a-z */
  259. int a_dim[27];                /* Dimensions for each array */
  260.  
  261. char inpbuf[INPBUFSIZ] = { NUL };    /* Buffer for INPUT and REINPUT */
  262. char inpbufa[2] = { NUL, NUL };        /* Null terminators for INPUT buffer */
  263. char inchar[2] = { NUL, NUL };        /* Last character that was INPUT */
  264. int  incount = 0;            /* INPUT character count */
  265.  
  266. char lblbuf[50];            /* Buffer for labels */
  267. #else
  268. int terror[MAXTAKE];
  269. #endif /* NOSPL */
  270.  
  271. #ifdef DCMDBUF
  272. char *line;                /* Character buffer for anything */
  273. #else
  274. char line[LINBUFSIZ];
  275. #endif /* DCMDBUF */
  276.  
  277. #ifdef CK_CURSES
  278. #ifndef TRMBUFL
  279. #define TRMBUFL 1024
  280. #endif /* TRMBUFL */
  281. #ifdef DCMDBUF
  282. char *trmbuf;                /* Character buffer for termcap */
  283. #else
  284. char trmbuf[TRMBUFL];
  285. #endif /* DCMDBUF */
  286. #endif /* CK_CURSES */
  287.  
  288. extern char pktfil[],
  289. #ifdef DEBUG
  290.   debfil[],
  291. #endif /* DEBUG */
  292. #ifdef TLOG
  293.   trafil[],
  294. #endif /* TLOG */
  295.   sesfil[],
  296.   cmdstr[];
  297. #ifndef NOFRILLS
  298. extern int rmailf, rprintf;        /* REMOTE MAIL & PRINT items */
  299. extern char optbuf[];
  300. #endif /* NOFRILLS */
  301.  
  302. char *homdir = "";            /* Pointer to home directory string */
  303.  
  304. char tmpbuf[50], *tp;            /* Temporary buffer */
  305. char numbuf[20];            /* Buffer for numeric strings. */
  306. char kermrc[100];            /* Name of initialization file */
  307. int noinit = 0;                /* Flag for skipping init file */
  308.  
  309. #ifndef NOSPL
  310. _PROTOTYP( static long expon, (long, long) );
  311. _PROTOTYP( static long gcd, (long, long) );
  312. _PROTOTYP( static long fact, (long) );
  313. int                    /* Initialize macro data structures. */
  314. macini() {            /* Allocate mactab and preset the first element. */
  315.     if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX)))
  316.     return(-1);
  317.     mactab[0].kwd = NULL;
  318.     mactab[0].mval = NULL;
  319.     mactab[0].flgs = 0;
  320.     return(0);
  321. }
  322. #endif /* NOSPL */
  323.  
  324. /*  C M D I N I  --  Initialize the interactive command parser  */
  325.  
  326. VOID
  327. cmdini() {
  328.     int i, x, y, z;
  329. #ifndef NOSPL
  330. /*
  331.   On stack in case of recursion!
  332. */
  333.     char vnambuf[VNAML];        /* Buffer for variable names */
  334. #endif /* NOSPL */
  335.  
  336. #ifndef MAC
  337. #ifndef NOSETKEY            /* Allocate & initialize the keymap */
  338.     if (!(keymap = (KEY *) malloc(sizeof(KEY)*KMSIZE)))
  339.       fatal("cmdini: no memory for keymap");
  340.     if (!(macrotab = (MACRO *) malloc(sizeof(MACRO)*KMSIZE)))
  341.       fatal("cmdini: no memory for macrotab");
  342.     for ( i = 0; i < KMSIZE; i++ ) {
  343.     keymap[i] = i;
  344.     macrotab[i] = NULL;
  345.     }
  346. #ifdef OS2
  347.     keymapinit();
  348. #endif /* OS2 */
  349. #endif /* NOSETKEY */
  350. #endif /* MAC */
  351.  
  352. #ifdef DCMDBUF
  353.     if (cmsetup() < 0) fatal("Can't allocate command buffers!");
  354. #ifndef NOSPL
  355.     if (!(cmdstk = (struct cmdptr *) malloc(sizeof(struct cmdptr)*CMDSTKL)))
  356.     fatal("cmdini: no memory for cmdstk");
  357.     if (!(ifcmd = (int *) malloc(sizeof(int)*CMDSTKL)))
  358.     fatal("cmdini: no memory for ifcmd");
  359.     if (!(count = (int *) malloc(sizeof(int)*CMDSTKL)))
  360.     fatal("cmdini: no memory for count");
  361.     if (!(iftest = (int *) malloc(sizeof(int)*CMDSTKL)))
  362.     fatal("cmdini: no memory for iftest");
  363.     if (!(intime = (int *) malloc(sizeof(int)*CMDSTKL)))
  364.     fatal("cmdini: no memory for intime");
  365.     if (!(incase = (int *) malloc(sizeof(int)*CMDSTKL)))
  366.     fatal("cmdini: no memory for incase");
  367.     if (!(terror = (int *) malloc(sizeof(int)*CMDSTKL)))
  368.     fatal("cmdini: no memory for terror");
  369.     if (!(merror = (int *) malloc(sizeof(int)*CMDSTKL)))
  370.     fatal("cmdini: no memory for merror");
  371. #endif /* NOSPL */
  372. #ifdef CK_CURSES
  373. /*
  374.   Termcap buffer for fullscreen display, UNIX only.  VMS does it another way.
  375.   The fullscreen display is not supported on AOS/VS or OS-9, etc, yet, and
  376.   the Mac has its own built-in fullscreen display.
  377. */
  378. #ifdef UNIX
  379.     if (!(trmbuf = malloc(TRMBUFL+1)))
  380.     fatal("cmdini: no memory for termcap buffer");
  381. #endif /* UNIX */
  382. #endif /* CK_CURSES */
  383.     if (!(line = malloc(LINBUFSIZ)))
  384.     fatal("cmdini: no memory for line");
  385. #endif /* DCMDBUF */
  386.  
  387. #ifndef NOSPL
  388.     if (macini() < 0) fatal("Can't allocate macro buffers!");
  389. #endif /* NOSPL */
  390.  
  391. #ifdef AMIGA
  392.     if (tlevel < 0)    
  393.       concb(escape);
  394. #endif /* AMIGA */
  395.  
  396. #ifndef NOSPL
  397.     cmdlvl = 0;                /* Start at command level 0 */
  398.     cmdstk[cmdlvl].src = CMD_KB;
  399.     cmdstk[cmdlvl].lvl = 0;
  400. #endif /* NOSPL */
  401.  
  402.     tlevel = -1;            /* Take file level = keyboard */
  403.     for (i = 0; i < MAXTAKE; i++)    /* Initialize command file names */
  404.       tfnam[i] = NULL;
  405.  
  406. #ifdef MAC 
  407.     cmsetp("Mac-Kermit>");        /* Set default prompt */
  408. #else
  409.     cmsetp("C-Kermit>");        /* Set default prompt */
  410. #endif /* MAC */
  411.  
  412. #ifndef NOSPL
  413.     initmac();                /* Initialize macro table */
  414. /* Add one-line macros */
  415.     addmac("ibm-linemode",m_ibm);    /* Add built-in macros. */
  416.     addmac("fatal",m_fat);        /* FATAL macro. */
  417. /* Add multiline macros */
  418.     addmmac("_forx",for_def);        /* FOR macro. */
  419.     addmmac("_xif",xif_def);        /* XIF macro. */
  420.     addmmac("_while",whil_def);        /* WHILE macro. */
  421. /* Fill in command line argument vector */
  422.     sprintf(vnambuf,"\\&@[%d]",xargs);     /* Command line argument vector */
  423.     y = arraynam(vnambuf,&x,&z);    /* goes in array \&@[] */
  424.     if (y > -1) {
  425.     dclarray((char)x,z);        /* Declare the array */
  426.     for (i = 0; i < xargs; i++) {    /* Fill it */
  427.         sprintf(vnambuf,"\\&@[%d]",i);
  428.         addmac(vnambuf,xargv[i]);
  429.     }
  430.     }
  431.     *vnambuf = NUL;
  432. #endif /* NOSPL */
  433.  
  434. /* Get our home directory now.  This needed in lots of places. */
  435.  
  436.     homdir = zhome();
  437.  
  438. /* If skipping init file ('-Y' on Kermit command line), return now. */
  439.  
  440.     if (noinit) return;
  441.  
  442. #ifdef OS2
  443. /*
  444.   The -y init file must be fully specified or in the current directory.
  445.   KERMRC is looked for via INIT, PATH and DPATH in that order.  Finally, our
  446.   own executable file path is taken and the .EXE suffix is replaced by .INI
  447.   and this is tried as initialization file.
  448. */
  449.     if (rcflag) {
  450.     strcpy(line, kermrc);
  451.     } else {
  452.     _searchenv(kermrc,"INIT",line);
  453.     if (line[0] == 0)
  454.       _searchenv(kermrc,"PATH",line);
  455.     if (line[0] == 0)
  456.       _searchenv(kermrc,"DPATH",line);
  457.     if (line[0] == 0) {
  458.         char *pgmptr = GetLoadPath();
  459.         if (pgmptr) {
  460.           lp = strrchr(pgmptr, '.');
  461.           strncpy(line, pgmptr, lp - pgmptr);
  462.           strcpy(line + (lp - pgmptr), ".ini");
  463.         }
  464.     }
  465.     }
  466.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  467.         tlevel = 0;
  468.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  469.       strcpy(tfnam[tlevel],line);
  470. #ifndef NOSPL
  471.     cmdlvl++;
  472.     cmdstk[cmdlvl].src = CMD_TF;
  473.     cmdstk[cmdlvl].lvl = tlevel;
  474.     ifcmd[cmdlvl] = 0;
  475.     iftest[cmdlvl] = 0;
  476.     count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  477.     intime[cmdlvl] = intime[cmdlvl-1];
  478.     incase[cmdlvl] = incase[cmdlvl-1];
  479.     terror[cmdlvl] = terror[cmdlvl-1];
  480.     merror[cmdlvl] = merror[cmdlvl-1];
  481. #endif /* NOSPL */
  482.         debug(F110,"init file",line,0);
  483.     } else {
  484.         debug(F100,"no init file","",0);
  485.     }
  486. #else /* not OS2 */
  487.     lp = line;
  488.     lp[0] = '\0';
  489. #ifdef GEMDOS
  490.     zkermini(line,rcflag, kermrc);
  491. #else
  492. #ifdef VMS
  493.     zkermini(line,LINBUFSIZ,kermrc);
  494. #else /* not VMS */
  495.     if (rcflag) {            /* If init file name from cmd line */
  496.     strcpy(lp,kermrc);        /* use it */
  497.     } else {                /* otherwise */
  498.     if (homdir) {            /* look in home directory for it */
  499.         strcpy(lp,homdir);
  500.         if (lp[0] == '/') strcat(lp,"/");
  501.     }
  502.     strcat(lp,kermrc);        /* and use the default name */
  503.     }
  504. #endif /* VMS */
  505. #endif /* GEMDOS */
  506.  
  507. #ifdef AMIGA
  508.     reqoff();                /* disable requestors */
  509. #endif /* AMIGA */
  510.  
  511.     debug(F110,"ini file is",line,0);
  512.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  513.     tlevel = 0;
  514.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  515.       strcpy(tfnam[tlevel],line);
  516. #ifndef NOSPL
  517.     cmdlvl++;
  518.     ifcmd[cmdlvl] = 0;
  519.     iftest[cmdlvl] = 0;
  520.     count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  521.     intime[cmdlvl] = intime[cmdlvl-1];
  522.     incase[cmdlvl] = incase[cmdlvl-1];
  523.     terror[cmdlvl] = terror[cmdlvl-1];
  524.     merror[cmdlvl] = merror[cmdlvl-1];
  525.     debug(F101,"open ok","",cmdlvl);
  526.     cmdstk[cmdlvl].src = CMD_TF;
  527.     cmdstk[cmdlvl].lvl = tlevel;
  528. #endif /* NOSPL */
  529.     debug(F110,"init file",line,0);
  530.     }
  531.     if (homdir && (tlevel < 0)) {
  532.         strcpy(lp,kermrc);
  533.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  534.         tlevel = 0;
  535.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  536.       strcpy(tfnam[tlevel],line);
  537. #ifndef NOSPL
  538.         cmdlvl++;
  539.         cmdstk[cmdlvl].src = CMD_TF;
  540.         cmdstk[cmdlvl].lvl = tlevel;
  541.         ifcmd[cmdlvl] = 0;
  542.         iftest[cmdlvl] = 0;
  543.         count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  544.         intime[cmdlvl] = intime[cmdlvl-1];
  545.         incase[cmdlvl] = incase[cmdlvl-1];
  546.         terror[cmdlvl] = terror[cmdlvl-1];
  547.         merror[cmdlvl] = merror[cmdlvl-1];
  548. #endif /* NOSPL */
  549.     }
  550.     }
  551. #endif /* OS2 */
  552. #ifdef AMIGA
  553.     reqpop();                /* Restore requestors */
  554. #endif /* AMIGA */
  555. }
  556.  
  557. #ifndef NOSPL
  558. /*
  559.   G E T N C M
  560.  
  561.   Get next command from current macro definition.
  562.  
  563.   Moved to a separate routine in edit 181 to allow multiline GET
  564.   to work when issued in a macro.
  565.  
  566.   Command is copied into string pointed to by argument s, max length n.
  567.   Returns:
  568.    0 if a string was copied, -1 if there was no string to copy.
  569. */
  570. int
  571. getncm(s,n) char *s; int n; {
  572.     int y, kp = 0, pp = 0;
  573.     char *s2;
  574.     
  575.     s2 = s;
  576.     *s = NUL;                /* Copy next cmd to command buffer. */
  577.     
  578.     debug(F111,"getncm",s,n);
  579.  
  580.     for (y = 0;
  581.       macp[maclvl] && *macp[maclvl] && y < n;
  582.      y++, s++, macp[maclvl]++) {
  583.     
  584.     *s = *macp[maclvl];        /* Get next character */
  585.     debug(F000,"char","",*s);
  586. /*
  587.   Allow braces around macro definition to prevent commas from being turned to
  588.   end-of-lines and also treat any commas within parens as text so that
  589.   multiple-argument functions won't cause the command to break prematurely.
  590. */
  591.     if (*s == '{') kp++;        /* Count braces */
  592.     if (*s == '}') kp--;
  593.     if (*s == '(') pp++;        /* Count parentheses. */
  594.     if (*s == ')') pp--;
  595.     if (*s == ',' && pp <= 0 && kp <= 0) {
  596.         macp[maclvl]++;
  597.         debug(F110,"next cmd",s,0);
  598.         kp = pp = 0;
  599.         break;
  600.     }
  601.     }                    /* Reached end. */
  602.     if (*s2 == NUL) {            /* If nothing was copied, */
  603.     debug(F100,"getncm eom","",0);
  604.     popclvl();            /* pop command level. */
  605.     return(-1);
  606.     } else {                /* otherwise, tack CR onto end */
  607.     *s++ = CR;
  608.     *s = '\0';
  609.     if (mecho && pflag)
  610.       printf("%s\n",s2);
  611.     debug(F101,"getncm returns ptr to",s2,0);
  612.     }
  613.     return(0);
  614. }
  615. #endif /* NOSPL */
  616.  
  617. /*
  618.   G E T N C T
  619.  
  620.   Get next command from current TAKE file.
  621.  
  622.   Moved to a separate routine in edit 181 to allow multiline GET
  623.   to work when issued in a macro.
  624.  
  625.   Command is copied into string pointed to by argument s, max length n.
  626.   Returns:
  627.    0 if a string was copied,
  628.   -1 on EOF,
  629.   -2 on malloc failure
  630.   -3 if line not properly terminated
  631. */
  632. int
  633. getnct(s,n) char *s; int n; {
  634.     int i, j;
  635.     char c, *s2, *lp, *lp2;
  636.  
  637.     s2 = s;                /* Remember original pointer */
  638.  
  639.     debug(F101,"getnct","",n);
  640.     if (!(lp2 = (char *) malloc(n+1))) { /* Get a temporary buffer */
  641.     debug(F101,"getnct malloc failure","",0);
  642.     return(-2);
  643.     }
  644.     lp = lp2;                /* Make a working pointer */
  645.                     /* (lp2 must not change!) */
  646.  
  647.     while (1) {                /* Loop to read lines from file */
  648.     
  649.     if (fgets(lp2,n,tfile[tlevel]) == NULL) { /* EOF */
  650.         free(lp2);            /* Free temporary storage */
  651.         *s = NUL;            /* Make destination be empty */
  652.         return(-1);            /* Return failure code */
  653.     }
  654.     debug(F110,"Line from TAKE file",lp2,0); /* Got a line */
  655.     if (techo && pflag)        /* If TAKE ECHO ON, */
  656.       printf("%s",lp2);        /* echo it. */
  657.  
  658.     lp = lp2;            /* Make a working pointer */
  659.  
  660. /* Trim trailing whitespace */
  661.  
  662.     j = strlen(lp2) - 1;        /* Position of line terminator */
  663.     if (j < 0) j = 0;
  664.     c = lp2[j];            /* Value of line terminator */
  665.     if (c < LF || c > CR) {        /* It's not a terminator */
  666.         debug(F111,"getnct bad line",lp2,c);
  667.         if (feof(tfile[tlevel]) && j > 0 && j < n) {
  668.         printf("Warning: Last line of TAKE file lacks terminator\n");
  669.         c = lp2[++j] = '\n';
  670.         } else return(-3);
  671.     }
  672.     for (i = j - 1; i > -1; i--)    /* Back up over spaces and tabs */
  673.       if (lp2[i] != SP && lp2[i] != HT && lp2[i] != NUL)
  674.         break;
  675.     lp2[i+1] = c;            /* Move after last nonblank char */
  676.     lp2[i+2] = NUL;            /* Terminate the string */
  677.     while (*s++ = *lp++) {        /* Copy result to target buffer */
  678.         if (--n < 2) {
  679.         printf("?Command too long, maximum length: %d.\n",CMDBL);
  680.         free(lp2);
  681.         return(dostop());
  682.         }
  683.  
  684. /* Check for trailing comment, " ;" or " #" */
  685.  
  686.         if ((s > s2 + 1) &&
  687.         (*(s-1) == ';' || *(s-1) == '#') &&
  688.         (*(s-2) == SP  || *(s-2) == HT)) {
  689.         debug(F100,"Trailing comment","",0);
  690.         s -= 2;            /* Got one, back up buffer pointer */
  691.         n += 2;            /* and adjust free space count. */
  692.         while ((s >= s2)    /* Trim whitespace again. */
  693.                && (*s == SP || *s == HT))
  694.           s--, n++;
  695.         s++;            /* Point after last character */
  696.         *s++ = c;        /* Put back line terminator */
  697.         *s++ = NUL;        /* and string terminator */
  698.         n -= 3;            /* Adjust free count */
  699.         debug(F110,"Comment trimmed & terminated",s2,0);
  700.         break;
  701.         }
  702.     }
  703.  
  704. /* Check whether this line is continued */
  705.  
  706.     debug(F000,"Last char in line","",*(s-3));
  707.     if (*(s - 3) != CMDQ && *(s - 3) != '-') /* Line continued? */
  708.       break;                 /* No, done. */
  709.     s -= 3;                     /* No, back up pointer */
  710.     debug(F100,"Got continue char","",0);     /* and continue */
  711.     }
  712.     untab(s2);                /* Done, convert tabs to spaces */
  713.     free(lp2);                /* Free temporary storage */
  714.     return(0);                /* Return success */
  715. }
  716.  
  717. /*  P A R S E R  --  Top-level interactive command parser.  */
  718.  
  719. /*
  720.   Call with:
  721.     m = 0 for normal behavior: keep parsing and executing commands
  722.           until an action command is parsed, then return with a
  723.           Kermit start-state as the value of this function.
  724.     m = 1 to parse only one command, can also be used to call parser()
  725.           recursively.
  726.     m = 2 to read but do not execute one command.
  727.   In all cases, parser() returns:
  728.     0     if no Kermit protocol action required
  729.     > 0   with a Kermit protocol start-state.
  730.     < 0   upon error.
  731. */
  732. int
  733. parser(m) int m; {
  734.     int tfcode, xx, yy, zz;        /* Workers */
  735.  
  736. #ifndef NOSPL
  737.     int inlevel;            /* Level we were called at */
  738. #endif /* NOSPL */
  739.     char *cbp;                /* Command buffer pointer */
  740. #ifdef MAC
  741.     extern char *lfiles;        /* Fake extern cast */
  742. #endif /* MAC */
  743.  
  744. #ifdef AMIGA
  745.     reqres();            /* restore AmigaDOS requestors */
  746. #endif /* AMIGA */
  747.  
  748.     what = W_COMMAND;        /* Now we're parsing commands. */
  749. #ifndef NOSPL
  750.     if (cmdlvl == 0)        /* If at top (interactive) level, */
  751. #else
  752.     if (tlevel < 0)
  753. #endif /* NOSPL */
  754.       concb((char)escape);    /* put console in cbreak mode. */
  755.  
  756. #ifndef NOSPL
  757.     ifcmd[0] = 0;        /* Command-level related variables */
  758.     iftest[0] = 0;        /* initialize variables at top level */
  759.     count[0] = 0;        /* of stack... */
  760.     intime[0] = 0;
  761.     incase[0] = 0;
  762.     terror[0] = 0;
  763.     merror[0] = 0;
  764.     inlevel = cmdlvl;        /* Current macro level */
  765.     debug(F101,"&parser entry maclvl","",maclvl);
  766.     debug(F101,"&parser entry inlevel","",inlevel);
  767.     debug(F101,"&parser entry tlevel","",tlevel);
  768.     debug(F101,"&parser entry cmdlvl","",cmdlvl);
  769.     debug(F101,"&parser entry m","",m);
  770. #endif /* NOSPL */
  771.  
  772. /*
  773.   sstate becomes nonzero when a command has been parsed that requires some
  774.   action from the protocol module.  Any non-protocol actions, such as local
  775.   directory listing or terminal emulation, are invoked directly from below.
  776. */
  777. #ifdef COMMENT
  778.     if (local && pflag)            /* Just returned from connect? */
  779.       printf("\n");
  780. #endif /* COMMENT */
  781.     sstate = 0;                /* Start with no start state. */
  782. #ifndef NOFRILLS
  783.     rmailf = rprintf = 0;        /* MAIL and PRINT modifiers for SEND */
  784.     *optbuf = NUL;            /* MAIL and PRINT options */
  785. #endif /* NOFRILLS */
  786.     while (sstate == 0) {        /* Parse cmds until action requested */
  787.     debug(F100,"top of parse loop","",0);
  788.  
  789.     /* Take requested action if there was an error in the previous command */
  790.  
  791. #ifndef MAC
  792.     conint(trap,stptrap);        /* In case we were just fg'd */
  793.     bgchk();            /* Check background status */
  794. #endif /* MAC */
  795.  
  796.     debug(F101,"tlevel","",tlevel);
  797. #ifndef NOSPL                /* In case we just reached top level */
  798.     debug(F101,"cmdlvl","",cmdlvl);
  799.     if (cmdlvl == 0) concb((char)escape);
  800. #else
  801.     if (tlevel < 0) concb((char)escape);
  802. #endif /* NOSPL */
  803.  
  804. #ifndef NOSPL
  805.     if (success == 0) {
  806.         if (cmdstk[cmdlvl].src == CMD_TF && terror[cmdlvl]) {
  807.         printf("Command error: take file terminated.\n");
  808.         popclvl();
  809.         if (cmdlvl == 0) return(0);
  810.         }
  811.         if (cmdstk[cmdlvl].src == CMD_MD && merror[cmdlvl]) {
  812.         printf("Command error: macro terminated.\n");
  813.         popclvl();
  814.         if (m && (cmdlvl < inlevel))
  815.           return((int) sstate);
  816.         }
  817.     }
  818.  
  819.     nulcmd = (m == 2);
  820. #else
  821.     if (success == 0 && tlevel > -1 && terror[tlevel]) {
  822.         printf("Command error: take file terminated.\n");
  823.         popclvl();
  824.         cmini(ckxech);        /* Clear the cmd buffer. */
  825.         if (tlevel < 0)         /* Just popped out of cmd files? */
  826.           return(0);        /* End of init file or whatever. */
  827.     }
  828. #endif /* NOSPL */
  829.  
  830. #ifdef MAC
  831.     /* Check for TAKE initiated by menu. */
  832.     if ((tlevel == -1) && lfiles)
  833.         startlfile();
  834. #endif /* MAC */
  835.  
  836.         /* If in TAKE file, check for EOF */
  837. #ifndef NOSPL
  838. #ifdef MAC
  839.     if
  840. #else
  841.     while
  842. #endif /* MAC */
  843.       ((cmdstk[cmdlvl].src == CMD_TF)  /* If end of take file */
  844.            && (tlevel > -1)
  845.            && feof(tfile[tlevel])) {
  846.         popclvl();            /* pop command level */
  847.         cmini(ckxech);        /* and clear the cmd buffer. */
  848.         if (cmdlvl == 0)        /* Just popped out of all cmd files? */
  849.           return(0);        /* End of init file or whatever. */
  850.      }
  851. #ifdef MAC
  852.     miniparser(1);
  853.     if (sstate == 'a') {        /* if cmd-. cancel */
  854.         debug(F100, "parser: cancel take due to sstate", "", sstate);
  855.         sstate = '\0';
  856.         dostop();
  857.         return(0);            /* End of init file or whatever. */
  858.     }
  859. #endif /*  MAC */
  860.  
  861. #else /* NOSPL */
  862.     if ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
  863.         popclvl();            /* Pop up one level. */
  864.         cmini(ckxech);        /* and clear the cmd buffer. */
  865.         if (tlevel < 0)         /* Just popped out of cmd files? */
  866.           return(0);        /* End of init file or whatever. */
  867.      }
  868. #endif /* NOSPL */
  869.  
  870. #ifndef NOSPL
  871.         if (cmdstk[cmdlvl].src == CMD_MD) { /* Executing a macro? */
  872.         debug(F100,"parser macro","",0);
  873.         maclvl = cmdstk[cmdlvl].lvl; /* Get current level */
  874.         debug(F101,"parser maclvl","",maclvl);
  875.         cbp = cmdbuf;        /* Copy next cmd to command buffer. */
  876.         *cbp = NUL;
  877.         if (*savbuf) {        /* In case then-part of 'if' command */
  878.         strcpy(cbp,savbuf);    /* was saved, restore it. */
  879.         *savbuf = '\0';
  880.         } else {            /* Else get next cmd from macro def */
  881.         if (getncm(cbp,CMDBL) < 0) {
  882.             if (m && (cmdlvl < inlevel))
  883.               return((int) sstate);
  884.             else /* if (!m) */ continue;
  885.         }
  886.         }
  887.         debug(F110,"cmdbuf from macro",cmdbuf,0);
  888.  
  889.     } else if (cmdstk[cmdlvl].src == CMD_TF)
  890. #else
  891.       if (tlevel > -1)  
  892. #endif /* NOSPL */
  893.       {
  894. #ifndef NOSPL
  895.         if (*savbuf) {        /* In case THEN-part of IF command */
  896.         strcpy(cmdbuf,savbuf);    /* was saved, restore it. */
  897.         *savbuf = '\0';
  898.         } else
  899. #endif /* NOSPL */
  900.  
  901.           /* Get next line from TAKE file */
  902.  
  903.           if ((tfcode = getnct(cmdbuf,CMDBL)) < 0) {
  904.           if (tfcode < -1) {    /* Error */
  905.               printf("?Error in TAKE command file: %s\n",
  906.                  (tfcode == -2) ? "Memory allocation failure" :
  907.                  "Line too long or contains NUL characters"
  908.                  );
  909.               popclvl();
  910.           }
  911.           continue;        /* -1 means EOF */
  912.           }        
  913.  
  914.         /* If interactive, get next command from user. */
  915.  
  916.     } else {            /* User types it in. */
  917.         if (pflag) prompt(xxstring);
  918.         cmini(ckxech);
  919.         }
  920.  
  921.         /* Now know where next command is coming from. Parse and execute it. */
  922.  
  923.     repars = 1;            /* 1 = command needs parsing */
  924.     displa = 0;            /* Assume no file transfer display */
  925.  
  926.     while (repars) {        /* Parse this cmd until entered. */
  927.         debug(F101,"parser top of while loop","",0);
  928.         cmres();            /* Reset buffer pointers. */
  929.         xx = cmkey2(cmdtab,ncmd,"Command","",toktab,xxstring);
  930.         debug(F101,"top-level cmkey2","",xx);
  931.         if (xx == -5) {
  932.         yy = chktok(toktab);
  933.         debug(F101,"top-level cmkey token","",yy);
  934.         ungword();
  935.         switch (yy) {
  936. #ifndef NOPUSH
  937.           case '!': xx = XXSHE; break; /* Shell escape */
  938. #endif /* NOPUSH */
  939.           case '#': xx = XXCOM; break; /* Comment */
  940.           case ';': xx = XXCOM; break; /* Comment */
  941. #ifndef NOSPL
  942.           case ':': xx = XXLBL; break; /* GOTO label */
  943. #endif /* NOSPL */
  944. #ifndef NOPUSH
  945.                   case '@': xx = XXSHE; break; /* Shell (DCL) escape */
  946. #endif /* NOPUSH */
  947.           default: 
  948.             printf("\n?Invalid - %s\n",cmdbuf);
  949.             xx = -2;
  950.         }
  951.         }
  952.  
  953. #ifndef NOSPL
  954.             /* Special handling for IF..ELSE */
  955.  
  956.         if (ifcmd[cmdlvl])        /* Count stmts after IF */
  957.           ifcmd[cmdlvl]++;
  958.         if (ifcmd[cmdlvl] > 2 && xx != XXELS && xx != XXCOM)
  959.           ifcmd[cmdlvl] = 0;
  960.  
  961.         /* Execute the command and take action based on return code. */
  962.  
  963.         if (nulcmd) {        /* Ignoring this command? */
  964.         xx = XXCOM;        /* Make this command a comment. */
  965.         }
  966. #endif /* NOSPL */
  967.  
  968.         zz = docmd(xx);    /* Parse rest of command & execute. */
  969.         debug(F101,"docmd returns","",zz);
  970. #ifdef MAC
  971.         if (tlevel > -1) {
  972.         if (sstate == 'a') {    /* if cmd-. cancel */
  973.             debug(F110, "parser: cancel take, sstate:", "a", 0);
  974.             sstate = '\0';
  975.             dostop();
  976.             return(0);        /* End of init file or whatever. */
  977.         }
  978.         }
  979. #endif /* MAC */
  980.         switch (zz) {
  981.         case -4:        /* EOF (e.g. on redirected stdin) */
  982.             doexit(GOOD_EXIT,xitsta); /* ...exit successfully */
  983.             case -1:        /* Reparse needed */
  984.             repars = 1;        /* Just set reparse flag and  */
  985.             continue;
  986.         case -6:        /* Invalid command given w/no args */
  987.             case -2:        /* Invalid command given w/args */
  988. #ifdef COMMENT
  989. #ifndef NOSPL
  990.             /* This is going to be really ugly... */
  991.             yy = mlook(mactab,atmbuf,nmac); /* Look in macro table */
  992.             if (yy > -1) {                /* If it's there */
  993.             if (zz == -2) {                /* insert "do" */
  994.                 char *mp;
  995.                 mp = malloc((int)strlen(cmdbuf) + 5);
  996.                 if (!mp) {
  997.                 printf("?malloc error 1\n");
  998.                 return(-2);
  999.                 }
  1000.                 sprintf(mp,"do %s ",cmdbuf);
  1001.                 strcpy(cmdbuf,mp);
  1002.                 free(mp);
  1003.             } else sprintf(cmdbuf,"do %s %c",atmbuf, CR);
  1004.             if (ifcmd[cmdlvl] == 2)    /* This one doesn't count! */
  1005.               ifcmd[cmdlvl]--;
  1006.             debug(F111,"stuff cmdbuf",cmdbuf,zz);
  1007.             repars = 1;    /* go for reparse */
  1008.             continue;
  1009.             } else {
  1010.             char *p;
  1011.             int n;
  1012.             p = cmdbuf;
  1013.             lp = line;     
  1014.             n = LINBUFSIZ;
  1015.             if (cmflgs == 0) printf("\n");
  1016.             if (xxstring(p,&lp,&n) > -1) 
  1017.               printf("?Invalid: %s\n",line);
  1018.             else
  1019.               printf("?Invalid: %s\n",cmdbuf);
  1020.             } /* (fall thru...) */
  1021. #else
  1022.             printf("?Invalid: %s\n",cmdbuf);
  1023. #endif /* NOSPL */
  1024. #else
  1025.             printf("?Invalid: %s\n",cmdbuf);
  1026. #endif /* COMMENT */
  1027.  
  1028.         case -9:        /* Bad, error message already done */
  1029.             success = 0;
  1030.             debug(F110,"top-level cmkey failed",cmdbuf,0);
  1031.             if (pflag == 0)    /* if background, terminate */
  1032.               fatal("Kermit command error in background execution");
  1033.             cmini(ckxech);    /* (fall thru) */
  1034.  
  1035.              case -3:        /* Empty command OK at top level */
  1036.             repars = 0;        /* Don't need to reparse. */
  1037.             continue;        /* Go back and get another command. */
  1038.  
  1039.         default:        /* Command was successful. */
  1040. #ifndef NOSPL
  1041.             debug(F101,"parser preparing to continue","",maclvl);
  1042. #endif /* NOSPL */
  1043.             repars = 0;        /* Don't need to reparse. */
  1044.             continue;        /* Go back and get another command. */
  1045.         }
  1046.     }
  1047. #ifndef NOSPL
  1048.     debug(F101,"parser breaks out of while loop","",maclvl);
  1049.     if (m && (cmdlvl < inlevel))  return((int) sstate);
  1050. #endif /* NOSPL */
  1051.     }
  1052.  
  1053. /* Got an action command, return start state. */
  1054.  
  1055. #ifdef COMMENT
  1056.     /* This is done in ckcpro.w instead, no need to do it twice. */
  1057.     /* Interrupts off only if remote */
  1058.     if (!local) connoi();
  1059. #endif /* COMMENT */
  1060.     return((int) sstate);
  1061. }
  1062.  
  1063. #ifndef NOSPL
  1064. /* OUTPUT command */
  1065.  
  1066. int                    /* This could easily become a macro */
  1067. #ifdef CK_ANSIC
  1068. xxout(char c)
  1069. #else
  1070. xxout(c) char c; 
  1071. #endif /* CK_ANSIC */
  1072. /* xxout */ {                /* Function to output a character. */
  1073.     debug(F101,"xxout","",c);
  1074.     if (local)                /* If in local mode */
  1075.       return(ttoc(c));            /* then to the external line */
  1076.     else return(conoc(c));        /* otherwise to the console. */
  1077. }
  1078.  
  1079. /* Returns 0 on failure, 1 on success */
  1080.  
  1081. int
  1082. dooutput(s) char *s; {
  1083.     int x, y, quote;
  1084.  
  1085.     if (local) {            /* Condition external line */
  1086.     y = ttvt(speed,flow);
  1087.     if (y < 0) return(0);
  1088.     }
  1089.     quote = 0;                /* Initialize backslash (\) quote */
  1090.  
  1091. #ifdef COMMENT
  1092. /* This is done automatically in ttopen() now... */
  1093. #ifdef TNCODE
  1094.     if (network && ttnproto == NP_TELNET) /* If telnet connection, */
  1095.       if (!tn_init++) tn_ini();           /* initialize it if necessary */
  1096. #endif /* TNCODE */
  1097. #endif /* COMMENT */
  1098.     while (x = *s++) {            /* Loop through the string */
  1099.     y = 0;                /* Error code, 0 = no error. */
  1100.     if (x == CMDQ) {        /* Look for \b or \B in string */
  1101.             quote++;            /* Got \ */
  1102.         continue;            /* Get next character */
  1103.     } else if (quote) {        /* This character is quoted */
  1104.         if (quote == 1 && (x == 'b' || x == 'B')) {    /* If \b or \B */
  1105.         debug(F100,"OUTPUT BREAK","",0);
  1106.         ttsndb();        /* send BREAK signal */
  1107.         quote = 0;        /* Turn off quote flag */
  1108.         continue;        /* and not the b or B */
  1109. #ifdef CK_LBRK
  1110.         } else if (quote == 1 && (x == 'l' || x == 'L')) { /* \l or \L */
  1111.         debug(F100,"OUTPUT Long BREAK","",0);
  1112.         ttsndlb();        /* send Long BREAK signal */
  1113.         quote = 0;        /* Turn off quote flag */
  1114.         continue;        /* and not the l or L */
  1115. #endif /* CK_LBRK */
  1116.         } else {            /* if \ not followed by b or B */
  1117.         y = xxout(dopar(CMDQ));    /* output the backslash. */
  1118.         quote = 0;        /* Turn off quote flag */
  1119.         }
  1120.     } else quote = 0;        /* Turn off quote flag */
  1121.     y = xxout(dopar((char)x));    /* Output this character */
  1122.     if (y < 0) {
  1123.         printf("output error.\n");
  1124.         return(0);
  1125.     }
  1126.     if (x == '\015') {        /* User typed carriage return */
  1127.         if (tnlm            /* If TERMINAL NEWLINE-MODE is ON */
  1128. #ifdef TNCODE
  1129.         || (network &&        /* Or we have a network connection */
  1130.             ttnproto == NP_TELNET && /* using TELNET protocol */
  1131.             tn_nlm        /* and TELNET NEWLINE-MODE is ON */
  1132.             )
  1133. #endif /* TNCODE */
  1134.         )
  1135.           xxout(dopar('\012'));    /* Send LF too (CR => CRLF) */
  1136.     }
  1137.     if (seslog && duplex)
  1138.       if (zchout(ZSFILE,(char)x) < 0) seslog = 0;
  1139.     }
  1140.     return(1);
  1141. }
  1142. #endif /* NOSPL */
  1143.  
  1144.  
  1145. /* Display version herald and initial prompt */
  1146.  
  1147. VOID
  1148. herald() {
  1149.     int x = 0;
  1150.     if (bgset > 0 || (bgset != 0 && backgrd != 0)) x = 1;
  1151.     debug(F101,"herald","",backgrd);
  1152.     if (x == 0)
  1153. #ifdef datageneral
  1154.       printf("%s,%s\nType ? or HELP for help\n",versio,ckxsys);
  1155. #else
  1156.       printf("%s,%s\n\rType ? or HELP for help\n",versio,ckxsys);
  1157. #endif /* datageneral */
  1158. }
  1159. #ifndef NOSPL
  1160. /*  M L O O K  --  Lookup the macro name in the macro table  */
  1161.  
  1162. /*
  1163.  Call this way:  v = mlook(table,word,n);
  1164.  
  1165.    table - a 'struct mtab' table.
  1166.    word  - the target string to look up in the table.
  1167.    n     - the number of elements in the table.
  1168.  
  1169.  The keyword table must be arranged in ascending alphabetical order, and
  1170.  all letters must be lowercase.
  1171.  
  1172.  Returns the table index, 0 or greater, if the name was found, or:
  1173.  
  1174.   -3 if nothing to look up (target was null),
  1175.   -2 if ambiguous,
  1176.   -1 if not found.
  1177.  
  1178.  A match is successful if the target matches a keyword exactly, or if
  1179.  the target is a prefix of exactly one keyword.  It is ambiguous if the
  1180.  target matches two or more keywords from the table.
  1181. */
  1182. int
  1183. mlook(table,cmd,n) struct mtab table[]; char *cmd; int n; {
  1184.  
  1185.     int i, v, cmdlen;
  1186.  
  1187. /* Lowercase & get length of target, if it's null return code -3. */
  1188.  
  1189.     if ((((cmdlen = lower(cmd))) == 0) || (n < 1)) return(-3);
  1190.  
  1191. /* Not null, look it up */
  1192.  
  1193.     for (i = 0; i < n-1; i++) {
  1194.         if (!strcmp(table[i].kwd,cmd) ||
  1195.            ((v = !strncmp(table[i].kwd,cmd,cmdlen)) &&
  1196.              strncmp(table[i+1].kwd,cmd,cmdlen))) {
  1197.                 return(i);
  1198.              }
  1199.         if (v) return(-2);
  1200.     }   
  1201.  
  1202. /* Last (or only) element */
  1203.  
  1204.     if (!strncmp(table[n-1].kwd,cmd,cmdlen)) {
  1205.         return(n-1);
  1206.     } else return(-1);
  1207. }
  1208.  
  1209. /* mxlook is like mlook, but an exact full-length match is required */
  1210.  
  1211. int
  1212. mxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  1213.     int i, cmdlen;
  1214.     if ((((cmdlen = lower(cmd))) == 0) || (n < 1)) return(-3);
  1215.     for (i = 0; i < n; i++)
  1216.       if (((int)strlen(table[i].kwd) == cmdlen) &&
  1217.       (!strncmp(table[i].kwd,cmd,cmdlen))) return(i);
  1218.     return(-1);
  1219. }
  1220.  
  1221. /*
  1222.   This routine is for the benefit of those compilers that can't handle
  1223.   long string constants or continued lines within them.  Long predefined
  1224.   macros like FOR, WHILE, and XIF have their contents broken up into
  1225.   arrays of string pointers.  This routine concatenates them back into a
  1226.   single string again, and then calls the real addmac() routine to enter
  1227.   the definition into the macro table.
  1228. */
  1229. int
  1230. addmmac(nam,s) char *nam, *s[]; {    /* Add a multiline macro definition */
  1231.     int i, x, y; char *p;
  1232.     x = 0;                /* Length counter */
  1233.     for (i = 0; (y = (int)strlen(s[i])) > 0; i++) { /* Add up total length */
  1234.         debug(F111,"addmmac line",s[i],y);    
  1235.     x += y;
  1236.     }
  1237.     debug(F101,"addmmac lines","",i);
  1238.     debug(F101,"addmmac loop exit","",y);
  1239.     debug(F111,"addmmac length",nam,x);
  1240.     if (x < 0) return(-1);
  1241.  
  1242.     p = malloc(x+1);            /* Allocate space for all of it. */
  1243.     if (!p) {
  1244.     printf("?addmmac malloc error: %s\n",nam);
  1245.     debug(F110,"addmmac malloc error",nam,0);
  1246.     return(-1);
  1247.     }
  1248.     *p = '\0';                /* Start off with null string. */
  1249.     for (i = 0; *s[i]; i++)        /* Concatenate them all together. */
  1250.       strcat(p,s[i]);
  1251.     y = (int)strlen(p);            /* Final precaution. */
  1252.     debug(F111,"addmmac constructed string",p,y);
  1253.     if (y == x) {
  1254.     y = addmac(nam,p);        /* Add result to the macro table. */
  1255.     } else {
  1256.     debug(F100,"addmmac length mismatch","",0);
  1257.     printf("\n!addmmac internal error!\n");
  1258.     y = -1;
  1259.     }
  1260.     free(p);                /* Free the temporary copy. */
  1261.     return(y);    
  1262. }
  1263.  
  1264. /* Here is the real addmac routine. */
  1265.  
  1266. int
  1267. addmac(nam,def) char *nam, *def; {    /* Add a macro to the macro table */
  1268.     int i, x, y, z, namlen, deflen;
  1269.     char *p, c;
  1270.  
  1271.     if (!nam) return(-1);
  1272.     namlen = (int)strlen(nam);        /* Get argument lengths */
  1273.     debug(F111,"addmac nam",nam,namlen);
  1274.     if (!def) {                /* Watch out for null pointer */
  1275.     deflen = 0;
  1276.     debug(F111,"addmac def","(null pointer)",deflen);
  1277.     } else {
  1278.     deflen = (int)strlen(def);
  1279.     debug(F111,"addmac def",def,deflen);
  1280.     }
  1281.     if (deflen < 0) return(-1);        /* strlen() failure, fail. */
  1282.     if (namlen < 1) return(-1);        /* No name given, fail. */
  1283.  
  1284.     if (*nam == CMDQ) nam++;        /* Backslash quote? */
  1285.     if (*nam == '%') {            /* Yes, if it's a variable name, */
  1286.     delmac(nam);            /* Delete any old value. */
  1287.     if (!(c = *(nam + 1))) return(-1); /* Variable name letter or digit */
  1288.     if (deflen < 1) {        /* Null definition */
  1289.         p = NULL;            /* Better not malloc or strcpy! */
  1290.     } else {            /* A substantial definition */
  1291.         p = malloc(deflen + 1);    /* Allocate space for it */
  1292.         if (!p) {
  1293.         printf("?addmac malloc error 2\n");
  1294.         return(-1);
  1295.         } else strcpy(p,def);    /* Copy definition into new space */
  1296.     }
  1297.  
  1298.     /* Now p points to the definition, or is a null pointer */
  1299.  
  1300.     if (p)
  1301.       debug(F110,"addmac p",p,0);
  1302.     else
  1303.       debug(F110,"addmac p","(null pointer)",0);
  1304.  
  1305.     if (c >= '0' && c <= '9') {    /* Digit variable */
  1306.         if (maclvl < 0) {        /* Are we calling or in a macro? */
  1307.         g_var[c] = p;        /* No, it's a global "top level" one */
  1308.         debug(F101,"addmac numeric global maclvl","",maclvl);
  1309.         } else {            /* Yes, it's a macro argument */
  1310.         m_arg[maclvl][c - '0'] = p;
  1311.         debug(F101,"addmac macro arg maclvl","",maclvl);
  1312.         }
  1313.     } else {            /* It's a global variable */
  1314.         if (c < 33 || c > GVARS) return(-1);
  1315.         if (isupper(c)) c = tolower(c);
  1316.         g_var[c] = p;        /* Put pointer in global-var table */
  1317.         debug(F100,"addmac global","",0);
  1318.     }
  1319.     return(0);
  1320.     } else if (*nam == '&') {        /* An array reference? */
  1321.     char **q;
  1322.     if ((y = arraynam(nam,&x,&z)) < 0) /* If syntax is bad */
  1323.       return(-1);            /* return -1. */
  1324.     if (chkarray(x,z) < 0)        /* If array not declared or */
  1325.       return(-2);            /* subscript out of range, ret -2 */
  1326.     delmac(nam);            /* Delete any current definition. */
  1327.     x -= 96;            /* Convert name letter to index. */
  1328.     if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  1329.       return(-3);            /* return -3. */
  1330.     if (deflen > 0) {
  1331.         if ((p = malloc(deflen+1)) == NULL) { /* Allocate space */
  1332.         printf("addmac macro error 7: %s\n",nam);
  1333.         return(-4);        /* for new def, return -4 on fail. */
  1334.         }
  1335.         strcpy(p,def);        /* Copy definition into new space. */
  1336.     } else p = NULL;
  1337.     q[z] = p;            /* Store pointer to it. */
  1338.     return(0);            /* Done. */
  1339.     } else debug(F110,"addmac macro def",nam,0);
  1340.  
  1341. /* Not a macro argument or a variable, so it's a macro definition */
  1342.  
  1343.     lower(nam);                /* Lowercase the name */
  1344.     if (mxlook(mactab,nam,nmac) > -1)    /* Look up, requiring exact match */
  1345.       delmac(nam);            /* if it's there, delete it. */
  1346.     debug(F111,"addmac table size",nam,nmac);
  1347.     for (y = 0;                /* Find the alphabetical slot */
  1348.      y < MAC_MAX && mactab[y].kwd != NULL && strcmp(nam,mactab[y].kwd) > 0;
  1349.      y++) ;
  1350.     if (y == MAC_MAX) {            /* No more room. */
  1351.     debug(F101,"addmac table overflow","",y);
  1352.     return(-1);
  1353.     } else debug(F111,"addmac position",nam,y);
  1354.     if (mactab[y].kwd != NULL) {    /* Must insert */
  1355.     for (i = nmac; i > y; i--) {    /* Move the rest down one slot */
  1356.         mactab[i].kwd = mactab[i-1].kwd;
  1357.         mactab[i].mval = mactab[i-1].mval;
  1358.         mactab[i].flgs = mactab[i-1].flgs;
  1359.     }
  1360.     }
  1361.     p = malloc(namlen + 1);        /* Allocate space for name */
  1362.     if (!p) {
  1363.     printf("?addmac malloc error 3: %s\n",nam);
  1364.     return(-1);
  1365.     }
  1366.     strcpy(p,nam);            /* Copy name into new space */
  1367.     mactab[y].kwd = p;            /* Add pointer to table */
  1368.  
  1369.     if (deflen > 0) {            /* Same deal for definition */
  1370.     p = malloc(deflen + 1);        /* but watch out for null pointer */
  1371.     if (p == NULL) {
  1372.         printf("?addmac malloc error 5: %s\n", nam);
  1373.         free(mactab[y].kwd);
  1374.         mactab[y].kwd = NULL;
  1375.         return(-1);
  1376.     } else strcpy(p,def);        /* Copy the definition */
  1377.     } else p = NULL;
  1378.     mactab[y].mval = p;
  1379.     mactab[y].flgs = 0;
  1380.     nmac++;                /* Count this macro */
  1381.     return(y);
  1382. }
  1383.  
  1384. int
  1385. delmac(nam) char *nam; {        /* Delete the named macro */
  1386.     int i, x, z;
  1387.     char *p, c;
  1388.  
  1389.     if (!nam) return(0);        /* Watch out for null pointer */
  1390.     debug(F110,"delmac nam",nam,0);
  1391.     if (*nam == CMDQ) nam++;
  1392.     if (*nam == '%') {            /* If it's a variable name */
  1393.     if (!(c = *(nam+1))) return(0);    /* Get variable name letter or digit */
  1394.     p = (char *)0;            /* Initialize value pointer */
  1395.     if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */
  1396.         p = m_arg[maclvl][c - '0'];    /* Get pointer from macro-arg table */
  1397.         m_arg[maclvl][c - '0'] = NULL; /* Zero the table pointer */
  1398.     } else {            /* It's a global variable */
  1399.         if (c < 33 || c > GVARS) return(0);
  1400.         p = g_var[c];        /* Get pointer from global-var table */
  1401.         g_var[c] = NULL;        /* Zero the table entry */
  1402.     }
  1403.     if (p) {
  1404.         debug(F110,"delmac def",p,0);
  1405.         free(p);            /* Free the storage */
  1406.     } else debug(F110,"delmac def","(null pointer)",0);
  1407.     return(0);
  1408.     }
  1409.         
  1410.     if (*nam == '&') {            /* An array reference? */
  1411.     char **q;
  1412.     if (arraynam(nam,&x,&z) < 0)    /* If syntax is bad */
  1413.       return(-1);            /* return -1. */
  1414.     x -= 96;            /* Convert name to number. */
  1415.     if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  1416.       return(-2);            /* return -2. */
  1417.     if (z > a_dim[x])        /* If subscript out of range, */
  1418.       return(-3);            /* return -3. */
  1419.     if (q[z]) {            /* If there is an old value, */
  1420.         debug(F110,"delman def",q[z],0);
  1421.         free(q[z]);            /* delete it. */
  1422.         q[z] = NULL;
  1423.     } else debug(F110,"delmac def","(null pointer)",0);
  1424.     }
  1425.  
  1426.    /* Not a variable or an array, so it must be a macro. */
  1427.  
  1428.     if ((x = mlook(mactab,nam,nmac)) < 0) { /* Look it up */
  1429.     debug(F111,"delmac mlook",nam,x);
  1430.     return(x);
  1431.     }
  1432.     if (mactab[x].kwd)            /* Free the storage for the name */
  1433.       free(mactab[x].kwd);
  1434.     if (mactab[x].mval)            /* and for the definition */
  1435.       free(mactab[x].mval);
  1436.  
  1437.     for (i = x; i < nmac; i++) {    /* Now move up the others. */
  1438.     mactab[i].kwd = mactab[i+1].kwd;
  1439.     mactab[i].mval = mactab[i+1].mval;
  1440.     mactab[i].flgs = mactab[i+1].flgs;
  1441.     }
  1442.     nmac--;                /* One less macro */
  1443.     mactab[nmac].kwd = NULL;        /* Delete last item from table */
  1444.     mactab[nmac].mval = NULL;
  1445.     mactab[nmac].flgs = 0;
  1446.     return(0);
  1447. }
  1448.  
  1449. VOID
  1450. initmac() {                /* Init macro & variable tables */
  1451.     int i, j;
  1452.  
  1453.     nmac = 0;                /* No macros */
  1454.     for (i = 0; i < MAC_MAX; i++) {    /* Initialize the macro table */
  1455.     mactab[i].kwd = NULL;
  1456.     mactab[i].mval = NULL;
  1457.     mactab[i].flgs = 0;
  1458.     }
  1459.     for (i = 0; i < MACLEVEL; i++) {    /* Init the macro argument tables */
  1460.     mrval[i] = NULL;
  1461.     for (j = 0; j < 10; j++) {
  1462.         m_arg[i][j] = NULL;
  1463.     }
  1464.     }
  1465.     for (i = 0; i < GVARS; i++) {    /* And the global variables table */
  1466.     g_var[i] = NULL;
  1467.     }
  1468.     for (i = 0; i < 26; i++) {        /* And the table of arrays */
  1469.     a_ptr[i] = (char **) NULL;    /* Null pointer for each */
  1470.     a_dim[i] = 0;            /* and a dimension of zero */
  1471.     }
  1472. }
  1473.  
  1474. int
  1475. popclvl() {                /* Pop command level, return cmdlvl */
  1476.     if (cmdlvl < 1) {            /* If we're already at top level */
  1477.     cmdlvl = 0;            /* just make sure all the */
  1478.     tlevel = -1;            /* stack pointers are set right */
  1479.     maclvl = -1;            /* and return */
  1480.     } else if (cmdstk[cmdlvl].src == CMD_TF) { /* Reading from TAKE file? */
  1481.     if (tlevel > -1) {        /* Yes, */
  1482.         if (tfnam[tlevel]) {
  1483.         free(tfnam[tlevel]);
  1484.         tfnam[tlevel] = NULL;
  1485.         }
  1486.         fclose(tfile[tlevel--]);    /* close it and pop take level */
  1487.         cmdlvl--;            /* pop command level */
  1488.     } else tlevel = -1;
  1489.     } else if (cmdstk[cmdlvl].src == CMD_MD) { /* In a macro? */
  1490.     if (maclvl > -1) {        /* Yes, */
  1491.         debug(F111,"popclvl before",macx[maclvl],maclvl);
  1492.         macp[maclvl] = "";        /* set macro pointer to null string */
  1493.         *cmdbuf = '\0';        /* clear the command buffer */
  1494.         if (mrval[maclvl+1]) {    /* Free any deeper return values. */
  1495.         free(mrval[maclvl+1]);
  1496.         mrval[maclvl+1] = NULL;
  1497.         }
  1498.         maclvl--;            /* pop macro level */
  1499.         cmdlvl--;            /* and command level */
  1500.         debug(F111,"popclvl after ",
  1501.           macx[maclvl] ? macx[maclvl] : "",maclvl);
  1502.     } else maclvl = -1;
  1503.     }
  1504. #ifndef MAC
  1505.     if (cmdlvl < 1) {            /* If back at top level */
  1506.     conint(trap,stptrap);        /* Fix interrupts */
  1507.     bgchk();            /* Check background status */
  1508.     concb((char)escape);        /* Go into cbreak mode */
  1509.     }
  1510. #endif /* MAC */
  1511.     return(cmdlvl < 1 ? 0 : cmdlvl);    /* Return command level */
  1512. }
  1513. #else /* No script programming language */
  1514. int popclvl() {                /* Just close current take file. */
  1515.     if (tlevel > -1) {            /* if any... */
  1516.     if (tfnam[tlevel]) {
  1517.         free(tfnam[tlevel]);
  1518.         tfnam[tlevel] = NULL;
  1519.     }
  1520.     fclose(tfile[tlevel--]);
  1521.     }
  1522.     if (tlevel == -1) {            /* And if back at top level */
  1523.     conint(trap,stptrap);        /* check and set interrupts */
  1524.         bgchk();            /* and background status */
  1525.         concb((char)escape);        /* and go back into cbreak mode. */
  1526.     }
  1527.     return(tlevel + 1);
  1528. }
  1529. #endif /* NOSPL */
  1530.  
  1531. /* STOP - get back to C-Kermit prompt, no matter where from. */
  1532.  
  1533. int
  1534. dostop() {
  1535.     while ( popclvl() )  ;    /* Pop all macros & take files */
  1536. #ifndef NOSPL
  1537.     while (cmpop() > -1) ;    /* And all recursive cmd pkg invocations */
  1538. #endif /* NOSPL */
  1539.     cmini(ckxech);        /* Clear the command buffer. */
  1540.     return(0);
  1541. }
  1542.  
  1543.  
  1544. /* Close the given log */
  1545.  
  1546. int
  1547. doclslog(x) int x; {
  1548.     int y;
  1549.     switch (x) {
  1550. #ifdef DEBUG
  1551.     case LOGD:
  1552.         if (deblog == 0) {
  1553.         printf("?Debugging log wasn't open\n");
  1554.         return(0);
  1555.         }
  1556.         *debfil = '\0';
  1557.         deblog = 0;
  1558.         return(zclose(ZDFILE));
  1559. #endif /* DEBUG */
  1560.  
  1561.     case LOGP:
  1562.         if (pktlog == 0) {
  1563.         printf("?Packet log wasn't open\n");
  1564.         return(0);
  1565.         }
  1566.         *pktfil = '\0';
  1567.         pktlog = 0;
  1568.         return(zclose(ZPFILE));
  1569.  
  1570.     case LOGS:
  1571.         if (seslog == 0) {
  1572.         printf("?Session log wasn't open\n");
  1573.         return(0);
  1574.         }
  1575.         *sesfil = '\0';
  1576.         seslog = 0;
  1577.         return(zclose(ZSFILE));
  1578.  
  1579. #ifdef TLOG
  1580.         case LOGT:
  1581.         if (tralog == 0) {
  1582.         printf("?Transaction log wasn't open\n");
  1583.         return(0);
  1584.         }
  1585.         *trafil = '\0';
  1586.         tralog = 0;
  1587.         return(zclose(ZTFILE));
  1588. #endif /* TLOG */
  1589.  
  1590. #ifndef NOSPL
  1591.           case LOGW:            /* WRITE file */
  1592.       case LOGR:            /* READ file */
  1593.         y = (x == LOGR) ? ZRFILE : ZWFILE;
  1594.         if (chkfn(y) < 1)        /* If no file to close */
  1595.           return(1);        /* succeed silently. */
  1596.         return(zclose(y));        /* Otherwise, close the file. */
  1597. #endif /* NOSPL */
  1598.  
  1599.     default:
  1600.         printf("\n?Unexpected log designator - %d\n", x);
  1601.         return(0);
  1602.     }
  1603. }
  1604.  
  1605. #ifndef NOSERVER
  1606. #ifndef NOFRILLS
  1607. static char *nm[] = { "disabled", "enabled" };
  1608. #endif /* NOFRILLS */
  1609. #endif /* NOSERVER */
  1610.  
  1611. static int slc = 0;            /* Screen line count */
  1612.  
  1613. #ifndef NOSHOW
  1614. #ifndef NOFRILLS
  1615. #define xxdiff(v,sys) strncmp(v,sys,strlen(sys))
  1616. VOID
  1617. shover() {
  1618.     printf("\nVersions:\n %s\n Numeric: %ld",versio,vernum);
  1619.     if (verwho) printf("-%d",verwho);
  1620.     printf(xxdiff(ckxv,ckxsys) ? "\n %s for%s\n" : "\n %s\n",ckxv,ckxsys);
  1621.     printf(xxdiff(ckzv,ckzsys) ? " %s for%s\n" : " %s\n",ckzv,ckzsys);
  1622.     printf(" %s\n",protv);
  1623.     printf(" %s\n",fnsv);
  1624.     printf(" %s\n %s\n",cmdv,userv);
  1625. #ifndef NOCSETS
  1626.     printf(" %s\n",xlav);
  1627. #endif /* NOCSETS */
  1628. #ifndef MAC
  1629.     printf(" %s\n",connv);
  1630. #endif /* MAC */
  1631. #ifndef NODIAL
  1632.     printf(" %s\n",dialv);
  1633. #endif /* NODIAL */
  1634. #ifndef NOSCRIPT
  1635.     printf(" %s\n",loginv);
  1636. #endif /* NOSCRIPT */
  1637. #ifdef NETCONN
  1638.     printf(" %s\n",cknetv);
  1639. #endif /* NETCONN */
  1640.     printf("\n");
  1641. }
  1642.  
  1643. VOID
  1644. shofea() {
  1645. #ifdef OS2
  1646. #ifdef M_I286
  1647.     printf("\nOS/2 16-bit.\n");
  1648. #else
  1649.     printf("\nOS/2 32-bit.\n");
  1650. #endif /* M_I286 */
  1651. #endif /* OS2 */
  1652.     printf("\nSpecial features:\n");
  1653. #ifdef NETCONN
  1654.     printf(" Network support (type SHOW NET for further info)\n");
  1655. #endif /* NETCONN */
  1656. #ifndef NOCSETS
  1657.     printf(" Latin-1 (West European) character-set translation\n");
  1658. #ifdef LATIN2
  1659.     printf(" Latin-2 (East European) character-set translation\n");
  1660. #endif /* LATIN2 */
  1661. #ifdef CYRILLIC
  1662.     printf(" Cyrillic (Russian, Ukrainian, etc) character-set translation\n");
  1663. #endif /* CYRILLIC */
  1664. #ifdef KANJI
  1665.     printf(" Kanji (Japanese) character-set translation\n");
  1666. #endif /* KANJI */
  1667. #endif /* NOCSETS */
  1668.  
  1669. #ifdef CK_CURSES
  1670.     printf(" Fullscreen file transfer display\n");
  1671. #endif /* CK_CURSES */
  1672.  
  1673.     printf("\nFeatures not included:\n");
  1674. #ifndef CK_CURSES
  1675. #ifndef MAC
  1676.     printf(" No fullscreen file transfer display\n");
  1677. #endif /* MAC */
  1678. #endif /* CK_CURSES */
  1679. #ifdef NOSERVER
  1680.     printf(" No server mode\n");
  1681. #endif /* NOSERVER */
  1682. #ifdef NODEBUG
  1683.     printf(" No debugging\n");
  1684. #endif /* NODEBUG */
  1685. #ifdef NOTLOG
  1686.     printf(" No transaction log\n");
  1687. #endif /* NOTLOG */
  1688. #ifdef NOHELP
  1689.     printf(" No built-in help\n");
  1690. #endif /* NOHELP */
  1691. #ifndef NETCONN
  1692.     printf(" No network support\n");
  1693. #endif /* NETCONN */
  1694. #ifdef NOMSEND
  1695.     printf(" No MSEND command\n");
  1696. #endif /* NOMSEND */
  1697. #ifdef NODIAL
  1698.     printf(" No DIAL command\n");
  1699. #else
  1700. #ifdef MINIDIAL
  1701.     printf(" DIAL command for modems other than Hayes, CCITT, and Unknown\n");
  1702. #endif /* MINIDIAL */
  1703. #endif /* NODIAL */
  1704. #ifdef NOXMIT
  1705.     printf(" No TRANSMIT command\n");
  1706. #endif /* NOXMIT */
  1707. #ifdef NOSCRIPT
  1708.     printf(" No SCRIPT command\n");
  1709. #endif /* NOSCRIPT */
  1710. #ifdef NOSPL
  1711.     printf(" No script programming features\n");
  1712. #endif /* NOSPL */
  1713. #ifdef NOCSETS
  1714.     printf(" No character-set translation\n");
  1715. #else
  1716. #ifndef LATIN2
  1717.     printf(" No Latin-2 character-set translation\n");
  1718. #endif /* LATIN2 */
  1719. #ifdef NOCYRIL
  1720.     printf(" No Cyrillic character-set translation\n");
  1721. #endif /* NOCYRIL */
  1722. #ifndef KANJI
  1723.     printf(" No Kanji character-set translation\n");
  1724. #endif /* KANJI */
  1725. #endif /* NOCSETS */
  1726. #ifdef NOCMDL
  1727.     printf(" No command-line arguments\n");
  1728. #endif /* NOCMDL */
  1729. #ifdef NOFRILLS
  1730.     printf(" No frills\n");
  1731. #endif /* NOFRILLS */
  1732. #ifdef NOPUSH
  1733.     printf(" No escape to system\n");
  1734. #endif /* NOPUSH */
  1735. #ifdef NOJC
  1736. #ifdef UNIX
  1737.     printf(" No UNIX job control\n");
  1738. #endif /* UNIX */
  1739. #endif /* NOJC */
  1740. #ifdef NOSETKEY
  1741.     printf(" No SET KEY command\n");
  1742. #endif /* NOSETKEY */
  1743. #ifdef NOESCSEQ
  1744.     printf(" No ANSI escape sequence recognition\n");
  1745. #endif /* NOESCSEQ */
  1746. #ifndef PARSENSE
  1747.     printf(" No automatic parity detection\n");
  1748. #endif /* PARSENSE */
  1749. /*
  1750.   Print all of Kermit's compile-time options, as well as C preprocessor
  1751.   predefined symbols that might affect us...
  1752. */
  1753.     printf("\nCompiler options:\n");
  1754. #ifdef DEBUG
  1755. #ifdef IFDEBUG
  1756.     prtopt(" IFDEBUG");
  1757. #else
  1758.     prtopt(" DEBUG");
  1759. #endif /* IFDEBUG */
  1760. #endif /* DEBUG */
  1761. #ifdef TLOG
  1762.     prtopt(" TLOG");
  1763. #endif /* TLOG */
  1764. #ifdef NODIAL
  1765.     prtopt(" NODIAL");
  1766. #endif /* NODIAL */
  1767. #ifdef MINIDIAL
  1768.     prtopt(" MINIDIAL");
  1769. #endif /* MINIDIAL */
  1770. #ifdef DYNAMIC
  1771.     prtopt(" DYNAMIC");
  1772. #endif /* IFDEBUG */
  1773. #ifndef NOSPL
  1774.     sprintf(line," CMDDEP=%d",CMDDEP);
  1775.     prtopt(line);
  1776. #endif /* NOSPL */
  1777. #ifdef UNIX
  1778.     prtopt(" UNIX");
  1779. #endif /* UNIX */
  1780. #ifdef VMS
  1781.     prtopt(" VMS");
  1782. #endif /* VMS */
  1783. #ifdef vms
  1784.     prtopt(" vms");
  1785. #endif /* vms */
  1786. #ifdef VMSSHARE
  1787.     prtopt(" VMSSHARE");
  1788. #endif /* VMSSHARE */
  1789. #ifdef datageneral
  1790.     prtopt(" datageneral");
  1791. #endif /* datageneral */
  1792. #ifdef apollo
  1793.     prtopt(" apollo");
  1794. #endif /* apollo */
  1795. #ifdef aegis
  1796.     prtopt(" aegis");
  1797. #endif /* aegis */
  1798. #ifdef A986
  1799.     prtopt(" A986");
  1800. #endif /* A986 */
  1801. #ifdef AMIGA
  1802.     prtopt(" AMIGA");
  1803. #endif /* AMIGA */
  1804. #ifdef CONVEX9
  1805.     prtopt(" CONVEX9");
  1806. #endif /* CONVEX9 */
  1807. #ifdef MAC
  1808.     prtopt(" MAC");
  1809. #endif /* MAC */
  1810. #ifdef AUX
  1811.     prtopt(" AUX");
  1812. #endif /* AUX */
  1813. #ifdef OS2
  1814.     prtopt(" OS2");
  1815. #endif /* OS2 */
  1816. #ifdef OS9
  1817.     prtopt(" OS9");
  1818. #endif /* OS9 */
  1819. #ifdef MSDOS
  1820.     prtopt(" MSDOS");
  1821. #endif /* MSDOS */
  1822. #ifdef DIRENT
  1823.     prtopt(" DIRENT");
  1824. #endif /* DIRENT */
  1825. #ifdef SDIRENT
  1826.     prtopt(" SDIRENT");
  1827. #endif /* SDIRENT */
  1828. #ifdef NDIR
  1829.     prtopt(" NDIR");
  1830. #endif /* NDIR */
  1831. #ifdef XNDIR
  1832.     prtopt(" XNDIR");
  1833. #endif /* XNDIR */
  1834. #ifdef MATCHDOT
  1835.     prtopt(" MATCHDOT");
  1836. #endif /* MATCHDOT */
  1837. #ifdef SAVEDUID
  1838.     prtopt(" SAVEDUID");
  1839. #endif /* SAVEDUID */
  1840. #ifdef NOCCTRAP
  1841.     prtopt(" NOCCTRAP");
  1842. #endif /* NOCCTRAP */
  1843. #ifdef SUNX25
  1844.     prtopt(" SUNX25");
  1845. #endif /* SUNX25 */
  1846. #ifdef DECNET
  1847.     prtopt(" DECNET");
  1848. #endif /* DECNET */
  1849. #ifdef ATT7300
  1850.     prtopt(" ATT7300");
  1851. #endif /* ATT7300 */
  1852. #ifdef ATT6300
  1853.     prtopt(" ATT6300");
  1854. #endif /* ATT6300 */
  1855. #ifdef HDBUUCP
  1856.     prtopt(" HDBUUCP");
  1857. #endif /* HDBUUCP */
  1858. #ifdef NOUUCP
  1859.     prtopt(" NOUUCP");
  1860. #endif /* NOUUCP */
  1861. #ifdef LONGFN
  1862.     prtopt(" LONGFN");
  1863. #endif /* LONGFN */
  1864. #ifdef RDCHK
  1865.     prtopt(" RDCHK");
  1866. #endif /* RDCHK */
  1867. #ifdef NAP
  1868.     prtopt(" NAP");
  1869. #endif /* NAP */
  1870. #ifdef NAPHACK
  1871.     prtopt(" NAPHACK");
  1872. #endif /* NAPHACK */
  1873. #ifdef NOIEXTEN
  1874.     prtopt(" NOIEXTEN");
  1875. #endif /* NOIEXTEN */
  1876. #ifdef EXCELAN
  1877.     prtopt(" EXCELAN");
  1878. #endif /* EXCELAN */
  1879. #ifdef PARAMH
  1880.     prtopt(" PARAMH");
  1881. #endif /* PARAMH */
  1882. #ifdef INTERLAN
  1883.     prtopt(" INTERLAN");
  1884. #endif /* INTERLAN */
  1885. #ifdef NOFILEH
  1886.     prtopt(" NOFILEH");
  1887. #endif /* NOFILEH */
  1888. #ifdef NOSYSIOCTLH
  1889.     prtopt(" NOSYSIOCTLH");
  1890. #endif /* NOSYSIOCTLH */
  1891. #ifdef DCLPOPEN
  1892.     prtopt(" DCLPOPEN");
  1893. #endif /* DCLPOPEN */
  1894. #ifdef NOSETBUF
  1895.     prtopt(" NOSETBUF");
  1896. #endif /* NOSETBUF */
  1897. #ifdef NOFDZERO
  1898.     prtopt(" NOFDZERO");
  1899. #endif /* NOFDZERO */
  1900. #ifdef NOPOPEN
  1901.     prtopt(" NOPOPEN");
  1902. #endif /* NOPOPEN */
  1903. #ifdef NOPARTIAL
  1904.     prtopt(" NOPARTIAL");
  1905. #endif /* NOPARTIAL */
  1906. #ifdef NOSETREU
  1907.     prtopt(" NOSETREU");
  1908. #endif /* NOSETREU */
  1909. #ifdef _POSIX_SOURCE
  1910.     prtopt(" _POSIX_SOURCE");
  1911. #endif /* _POSIX_SOURCE */
  1912. #ifdef LCKDIR
  1913.     prtopt(" LCKDIR");
  1914. #endif /* LCKDIR */
  1915. #ifdef ACUCNTRL
  1916.     prtopt(" ACUCNTRL");
  1917. #endif /* ACUCNTRL */
  1918. #ifdef BSD4
  1919.     prtopt(" BSD4");
  1920. #endif /* BSD4 */
  1921. #ifdef BSD44
  1922.     prtopt(" BSD44");
  1923. #endif /* BSD44 */
  1924. #ifdef BSD41
  1925.     prtopt(" BSD41");
  1926. #endif /* BSD41 */
  1927. #ifdef BSD43
  1928.     prtopt(" BSD43");
  1929. #endif /* BSD43 */
  1930. #ifdef BSD29
  1931.     prtopt(" BSD29");
  1932. #endif /* BSD29 */
  1933. #ifdef V7
  1934.     prtopt(" V7");
  1935. #endif /* V7 */
  1936. #ifdef AIX370
  1937.     prtopt(" AIX370");
  1938. #endif /* AIX370 */
  1939. #ifdef RTAIX
  1940.     prtopt(" RTAIX");
  1941. #endif /* RTAIX */
  1942. #ifdef HPUX
  1943.     prtopt(" HPUX");
  1944. #endif /* HPUX */
  1945. #ifdef HPUXPRE65
  1946.     prtopt(" HPUXPRE65");
  1947. #endif /* HPUXPRE65 */
  1948. #ifdef DGUX
  1949.     prtopt(" DGUX");
  1950. #endif /* DGUX */
  1951. #ifdef DGUX430
  1952.     prtopt(" DGUX430");
  1953. #endif /* DGUX430 */
  1954. #ifdef DGUX540
  1955.     prtopt(" DGUX540");
  1956. #endif /* DGUX540 */
  1957. #ifdef sony_news
  1958.     prtopt(" sony_news");
  1959. #endif /* sony_news */
  1960. #ifdef CIE
  1961.     prtopt(" CIE");
  1962. #endif /* CIE */
  1963. #ifdef XENIX
  1964.     prtopt(" XENIX");
  1965. #endif /* XENIX */
  1966. #ifdef SCO_XENIX
  1967.     prtopt(" SCO_XENIX");
  1968. #endif /* SCO_XENIX */
  1969. #ifdef ISIII
  1970.     prtopt(" ISIII");
  1971. #endif /* ISIII */
  1972. #ifdef I386IX
  1973.     prtopt(" I386IX");
  1974. #endif /* I386IX */
  1975. #ifdef RTU
  1976.     prtopt(" RTU");
  1977. #endif /* RTU */
  1978. #ifdef PROVX1
  1979.     prtopt(" PROVX1");
  1980. #endif /* PROVX1 */
  1981. #ifdef TOWER1
  1982.     prtopt(" TOWER1");
  1983. #endif /* TOWER1 */
  1984. #ifdef UTEK
  1985.     prtopt(" UTEK");
  1986. #endif /* UTEK */
  1987. #ifdef ZILOG
  1988.     prtopt(" ZILOG");
  1989. #endif /* ZILOG */
  1990. #ifdef TRS16
  1991.     prtopt(" TRS16");
  1992. #endif /* TRS16 */
  1993. #ifdef MINIX
  1994.     prtopt(" MINIX");
  1995. #endif /* MINIX */
  1996. #ifdef C70
  1997.     prtopt(" C70");
  1998. #endif /* C70 */
  1999. #ifdef AIXPS2
  2000.     prtopt(" AIXPS2");
  2001. #endif /* AIXPS2 */
  2002. #ifdef AIXRS
  2003.     prtopt(" AIXRS");
  2004. #endif /* AIXRS */
  2005. #ifdef UTSV
  2006.     prtopt(" UTSV");
  2007. #endif /* UTSV */
  2008. #ifdef ATTSV
  2009.     prtopt(" ATTSV");
  2010. #endif /* ATTSV */
  2011. #ifdef SVR3
  2012.     prtopt(" SVR3");
  2013. #endif /* SVR3 */
  2014. #ifdef SVR4
  2015.     prtopt(" SVR4");
  2016. #endif /* SVR4 */
  2017. #ifdef DELL_SVR4
  2018.     prtopt(" DELL_SVR4");
  2019. #endif /* DELL_SVR4 */
  2020. #ifdef ICL_SVR4
  2021.     prtopt(" ICL_SVR4");
  2022. #endif /* ICL_SVR4 */
  2023. #ifdef OSF
  2024.     prtopt(" OSF");
  2025. #endif /* OSF */
  2026. #ifdef PTX
  2027.     prtopt(" PTX");
  2028. #endif /* PTX */
  2029. #ifdef POSIX
  2030.     prtopt(" POSIX");
  2031. #endif /* POSIX */
  2032. #ifdef SOLARIS
  2033.     prtopt(" SOLARIS");
  2034. #endif /* SOLARIS */
  2035. #ifdef SUNOS4
  2036.     prtopt(" SUNOS4");
  2037. #endif /* SUNOS4 */
  2038. #ifdef SUN4S5
  2039.     prtopt(" SUN4S5");
  2040. #endif /* SUN4S5 */
  2041. #ifdef ENCORE
  2042.     prtopt(" ENCORE");
  2043. #endif /* ENCORE */
  2044. #ifdef ultrix
  2045.     prtopt(" ultrix");
  2046. #endif
  2047. #ifdef sxaE50
  2048.     prtopt(" sxaE50");
  2049. #endif
  2050. #ifdef mips
  2051.     prtopt(" mips");
  2052. #endif
  2053. #ifdef MIPS
  2054.     prtopt(" MIPS");
  2055. #endif
  2056. #ifdef vax
  2057.     prtopt(" vax");
  2058. #endif
  2059. #ifdef VAX
  2060.     prtopt(" VAX");
  2061. #endif
  2062. #ifdef sun
  2063.     prtopt(" sun");
  2064. #endif
  2065. #ifdef sun3
  2066.     prtopt(" sun3");
  2067. #endif
  2068. #ifdef sun386
  2069.     prtopt(" sun386");
  2070. #endif
  2071. #ifdef _SUN
  2072.     prtopt(" _SUN");
  2073. #endif
  2074. #ifdef sun4
  2075.     prtopt(" sun4");
  2076. #endif
  2077. #ifdef sparc
  2078.     prtopt(" sparc");
  2079. #endif
  2080. #ifdef _CRAY
  2081.     prtopt(" _CRAY");
  2082. #endif /* _CRAY */
  2083. #ifdef NEXT
  2084.     prtopt(" NEXT");
  2085. #endif
  2086. #ifdef NEXT3
  2087.     prtopt(" NEXT3");
  2088. #endif /* NEXT3 */
  2089. #ifdef NeXT
  2090.     prtopt(" NeXT");
  2091. #endif
  2092. #ifdef sgi
  2093.     prtopt(" sgi");
  2094. #endif
  2095. #ifdef M_SYS5
  2096.     prtopt(" M_SYS5");
  2097. #endif
  2098. #ifdef __SYSTEM_FIVE
  2099.     prtopt(" __SYSTEM_FIVE");
  2100. #endif
  2101. #ifdef sysV
  2102.     prtopt(" sysV");
  2103. #endif
  2104. #ifdef M_XENIX                /* SCO Xenix V and UNIX/386 */
  2105.     prtopt(" M_XENIX");
  2106. #endif 
  2107. #ifdef M_UNIX
  2108.     prtopt(" M_UNIX");
  2109. #endif
  2110. #ifdef M_I386
  2111.     prtopt(" M_I386");
  2112. #endif
  2113. #ifdef _M_I386
  2114.     prtopt(" _M_I386");
  2115. #endif
  2116. #ifdef i386
  2117.     prtopt(" i386");
  2118. #endif
  2119. #ifdef i286
  2120.     prtopt(" i286");
  2121. #endif
  2122. #ifdef M_I286
  2123.     prtopt(" M_I286");
  2124. #endif
  2125. #ifdef mc68000
  2126.     prtopt(" mc68000");
  2127. #endif
  2128. #ifdef mc68010
  2129.     prtopt(" mc68010");
  2130. #endif
  2131. #ifdef mc68020
  2132.     prtopt(" mc68020");
  2133. #endif
  2134. #ifdef mc68030
  2135.     prtopt(" mc68030");
  2136. #endif
  2137. #ifdef mc68040
  2138.     prtopt(" mc68040");
  2139. #endif
  2140. #ifdef M_68000
  2141.     prtopt(" M_68000");
  2142. #endif
  2143. #ifdef M_68010
  2144.     prtopt(" M_68010");
  2145. #endif
  2146. #ifdef M_68020
  2147.     prtopt(" M_68020");
  2148. #endif
  2149. #ifdef M_68030
  2150.     prtopt(" M_68030");
  2151. #endif
  2152. #ifdef M_68040
  2153.     prtopt(" M_68040");
  2154. #endif
  2155. #ifdef m68k
  2156.     prtopt(" m68k");
  2157. #endif
  2158. #ifdef m88k
  2159.     prtopt(" m88k");
  2160. #endif
  2161. #ifdef pdp11
  2162.     prtopt(" pdp11");
  2163. #endif
  2164. #ifdef iAPX
  2165.     prtopt(" iAPX");
  2166. #endif
  2167. #ifdef __hp9000s800
  2168.     prtopt(" __hp9000s800");
  2169. #endif
  2170. #ifdef __hp9000s500
  2171.     prtopt(" __hp9000s500");
  2172. #endif
  2173. #ifdef __hp9000s300
  2174.     prtopt(" __hp9000s300");
  2175. #endif
  2176. #ifdef __hp9000s200
  2177.     prtopt(" __hp9000s200");
  2178. #endif
  2179. #ifdef AIX
  2180.     prtopt(" AIX");
  2181. #endif
  2182. #ifdef _AIXFS
  2183.     prtopt(" _AIXFS");
  2184. #endif
  2185. #ifdef u370
  2186.     prtopt(" u370");
  2187. #endif
  2188. #ifdef u3b
  2189.     prtopt(" u3b");
  2190. #endif
  2191. #ifdef u3b2
  2192.     prtopt(" u3b2");
  2193. #endif
  2194. #ifdef multimax
  2195.     prtopt(" multimax");
  2196. #endif
  2197. #ifdef balance
  2198.     prtopt(" balance");
  2199. #endif
  2200. #ifdef ibmrt
  2201.     prtopt(" ibmrt");
  2202. #endif
  2203. #ifdef _IBMRT
  2204.     prtopt(" _IBMRT");
  2205. #endif
  2206. #ifdef ibmrs6000
  2207.     prtopt(" ibmrs6000");
  2208. #endif
  2209. #ifdef _AIX
  2210.     prtopt(" _AIX");
  2211. #endif /* _AIX */
  2212. #ifdef _IBMR2
  2213.     prtopt(" _IBMR2");
  2214. #endif
  2215. #ifdef QNX
  2216.     prtopt(" QNX");
  2217. #endif
  2218. #ifdef __STRICT_BSD__
  2219.     prtopt(" __STRICT_BSD__");
  2220. #endif
  2221. #ifdef __STRICT_ANSI__
  2222.     prtopt(" __STRICT_ANSI__");
  2223. #endif
  2224. #ifdef _ANSI_C_SOURCE
  2225.     prtopt(" _ANSI_C_SOURCE");
  2226. #endif
  2227. #ifdef __STDC__
  2228.     prtopt(" __STDC__");
  2229. #endif
  2230. #ifdef __GNUC__                /* gcc in ansi mode */
  2231.     prtopt(" __GNUC__");
  2232. #endif
  2233. #ifdef GNUC                /* gcc in traditional mode */
  2234.     prtopt(" GNUC");
  2235. #endif
  2236. #ifdef CK_ANSIC
  2237.     prtopt(" CK_ANSIC");
  2238. #endif
  2239. #ifdef CK_ANSILIBS
  2240.     prtopt(" CK_ANSILIBS");
  2241. #endif
  2242. #ifdef _XOPEN_SOURCE
  2243.     prtopt(" _XOPEN_SOURCE");
  2244. #endif
  2245. #ifdef _ALL_SOURCE
  2246.     prtopt(" _ALL_SOURCE");
  2247. #endif
  2248. #ifdef _SC_JOB_CONTROL
  2249.     prtopt(" _SC_JOB_CONTROL");
  2250. #endif
  2251. #ifdef _POSIX_JOB_CONTROL
  2252.     prtopt(" _POSIX_JOB_CONTROL");
  2253. #endif
  2254. #ifdef SVR3JC
  2255.     prtopt(" SVR3JC");
  2256. #endif
  2257. #ifdef _386BSD
  2258.     prtopt(" _386BSD");
  2259. #endif
  2260. #ifdef _BSD
  2261.     prtopt(" _BSD");
  2262. #endif
  2263. #ifdef TERMIOX
  2264.     prtopt(" TERMIOX");
  2265. #endif /* TERMIOX */
  2266. #ifdef STERMIOX
  2267.     prtopt(" STERMIOX");
  2268. #endif /* STERMIOX */
  2269. #ifdef CK_CURSES
  2270.     prtopt(" CK_CURSES");
  2271. #endif /* CK_CURSES */
  2272. #ifdef CK_DTRCD
  2273.     prtopt(" CK_DTRCD");
  2274. #endif /* CK_DTRCD */
  2275. #ifdef CK_DTRCTS
  2276.     prtopt(" CK_DTRCTS");
  2277. #endif /* CK_DTRCTS */
  2278. #ifdef CK_RTSCTS
  2279.     prtopt(" CK_RTSCTS");
  2280. #endif /* CK_RTSCTS */
  2281.     prtopt((char *)0);
  2282.     printf("\n\n");
  2283. }
  2284. #endif /* NOFRILLS */
  2285. #endif /* NOSHOW */
  2286.  
  2287. #ifdef VMS
  2288. int
  2289. sholbl() {
  2290.     printf("VMS Labeled File Features:\n");
  2291.     printf(" acl %s (ACL info %s)\n",
  2292.        lf_opts & LBL_ACL ? "on " : "off",
  2293.        lf_opts & LBL_ACL ? "preserved" : "discarded");
  2294.     printf(" backup-date %s (backup date/time %s)\n",
  2295.        lf_opts & LBL_BCK ? "on " : "off",
  2296.        lf_opts & LBL_BCK ? "preserved" : "discarded");
  2297.     printf(" name %s (original filename %s)\n",
  2298.        lf_opts & LBL_NAM ? "on " : "off",
  2299.        lf_opts & LBL_NAM ? "preserved" : "discarded");
  2300.     printf(" owner %s (original file owner id %s)\n",
  2301.        lf_opts & LBL_OWN ? "on " : "off",
  2302.        lf_opts & LBL_OWN ? "preserved" : "discarded");
  2303.     printf(" path %s (original file's disk:[directory] %s)\n",
  2304.        lf_opts & LBL_PTH ? "on " : "off",
  2305.        lf_opts & LBL_PTH ? "preserved" : "discarded");
  2306. }
  2307. #endif /* VMS */
  2308.  
  2309. #ifndef NOSHOW
  2310. VOID
  2311. shotcs(cs1,cs2) int cs1, cs2; {        /* Show terminal character set */
  2312. #ifndef NOCSETS
  2313. #ifndef MAC
  2314.     int y;
  2315.     char *s;
  2316. #ifdef CK_ANSIC
  2317.     int gettcs(int, int);
  2318. #else
  2319.     int gettcs();
  2320. #endif /* CK_ANSIC */
  2321.  
  2322.     printf(" Terminal character-set");
  2323.     if (cs1 == cs2) {
  2324.     printf(": transparent\n");
  2325.     } else {
  2326.     s = "unknown";
  2327. #ifdef COMMENT /* old dumb way */
  2328.     for (y = 0; y <= nfilc; y++)    /* Look up name in keyword table */
  2329.       if (ttcstab[y].kwval == cs2) {
  2330.           if (ttcstab[y].flgs & CM_INV) /* Skip synonyms */
  2331.         continue;
  2332.           s = ttcstab[y].kwd;
  2333.           break;
  2334.       }
  2335.     printf("s:\n   Remote: %s\n   Local:  ",s);
  2336.     s = "unknown";
  2337.     for (y = 0; y <= nfilc; y++)
  2338.       if (ttcstab[y].kwval == cs1) {
  2339.         if (ttcstab[y].flgs & CM_INV) /* Skip synonyms */
  2340.           continue;
  2341.         s = ttcstab[y].kwd;
  2342.           break;
  2343.       }
  2344.     printf("%s",s);
  2345. #else
  2346.     printf("s:\n   Remote: %s\n   Local:  %s",
  2347.            fcsinfo[cs2].keyword,fcsinfo[cs1].keyword);
  2348. #endif /* COMMENT */
  2349.     if (cs2 != cs1) {
  2350.         switch(gettcs(cs2,cs1)) {
  2351.           case TC_USASCII:  s = "ascii";        break;
  2352.           case TC_1LATIN:   s = "latin1-iso";   break;
  2353.           case TC_2LATIN:   s = "latin2-iso";   break;
  2354.           case TC_CYRILL:   s = "cyrillic-iso"; break;
  2355.           case TC_JEUC:     s = "japanese-euc"; break;
  2356.           default:          s = "transparent";  break;
  2357.         }
  2358.         printf("\n   Via:    %s\n",s);
  2359.     }
  2360.     }
  2361. #endif /* MAC */
  2362. #endif /* NOCSETS */
  2363. }
  2364. #endif /* NOSHOW */
  2365.  
  2366. #ifndef NOSHOW
  2367. int
  2368. doshow(x) int x; {
  2369.     int y, i; long zz;
  2370.     char *s;
  2371.  
  2372. #ifndef NOSETKEY
  2373.     if (x == SHKEY) {            /* SHOW KEY */
  2374.     int c;
  2375.     KEY ch;
  2376.     CHAR *s;
  2377.  
  2378.     if ((y = cmcfm()) < 0) return(y);        
  2379. #ifdef MAC
  2380.     printf("Not implemented\n");
  2381.     return(0);
  2382. #else /* Not MAC */
  2383.     printf(" Press key: ");
  2384. #ifdef UNIX
  2385. #ifdef NOSETBUF
  2386.     fflush(stdout);
  2387. #endif /* NOSETBUF */
  2388. #endif /* UNIX */
  2389.     conbin((char)escape);        /* Put terminal in binary mode */
  2390.     c = congks(0);            /* Get character or scan code */
  2391.     concb((char)escape);        /* Restore terminal to cbreak mode */
  2392.     if (c < 0) {            /* Check for error */
  2393.         printf("?Error reading key\n");
  2394.         return(0);
  2395.     }
  2396. #ifndef OS2
  2397. /*
  2398.   Do NOT mask when it can be a raw scan code, perhaps > 255
  2399. */
  2400.     c &= cmdmsk;            /* Apply command mask */
  2401. #endif /* OS2 */
  2402.     printf("\n Key code \\%d => ",c);
  2403.         if (macrotab[c]) {        /* See if there's a macro */
  2404.         printf("String: ");        /* If so, display its definition */
  2405.             s = macrotab[c];
  2406.         while (ch = *s++)
  2407.           if (ch < 32 || ch == 127
  2408. /*
  2409.   Systems whose native character sets have graphic characters in C1...
  2410. */
  2411. #ifndef NEXT                /* NeXT */
  2412. #ifndef AUX                /* Macintosh */
  2413. #ifndef XENIX                /* IBM PC */
  2414. #ifndef OS2                /* IBM PC */
  2415.           || (ch > 127 && ch < 160)
  2416. #endif /* OS2 */
  2417. #endif /* XENIX */
  2418. #endif /* AUX */
  2419. #endif /* NEXT */
  2420.           )
  2421.                 printf("\\{%d}",ch);    /* Display control characters */
  2422.           else putchar((char) ch);    /* in backslash notation */
  2423.         printf("\n");
  2424.         } else {            /* No macro, show single character */
  2425.         printf("Character: ");
  2426.         ch = keymap[c];
  2427.         if (ch < 32 || ch == 127 || ch > 255
  2428. #ifndef NEXT
  2429. #ifndef AUX
  2430. #ifndef XENIX
  2431. #ifndef OS2
  2432.           || (ch > 127 && ch < 160)
  2433. #endif /* OS2 */
  2434. #endif /* XENIX */
  2435. #endif /* AUX */
  2436. #endif /* NEXT */
  2437.         )
  2438. /*
  2439.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  2440.   %u is supposed to be totally portable.
  2441. */
  2442.           printf("\\%u",(unsigned int) ch);
  2443.         else printf("%c \\%u",(CHAR) ch,(unsigned int) ch);
  2444.     }
  2445.     if (ch == (KEY) c)
  2446.       printf(" (self, no translation)\n");
  2447.     else printf("\n");
  2448.     return(1);
  2449. #endif /* MAC */
  2450.     }
  2451. #endif /* NOSETKEY */
  2452.  
  2453. #ifndef NOSPL
  2454.     if (x == SHMAC) {            /* SHOW MACRO */
  2455.     x = cmfld("Macro name, or carriage return to see them all","",&s,
  2456.           NULL);
  2457.     if (x == -3)            /* This means they want see all */
  2458.       *line = '\0';
  2459.     else if (x < 0)            /* Otherwise negative = parse error */
  2460.       return(x);
  2461.     else                /* 0 or greater */
  2462.       strcpy(line,s);        /* means they typed something */
  2463.     if ((y = cmcfm()) < 0) return(y); /* Get confirmation */
  2464.     if (*line) {
  2465.         slc = 0;            /* Initial SHO MAC line number */
  2466.         x = mlook(mactab,s,nmac);    /* Look up what they typed */
  2467.         switch (x) {
  2468.           case -3:            /* Nothing to look up */
  2469.         return(0);
  2470.           case -1:            /* Not found */
  2471.         printf("%s - not found\n",s);
  2472.         return(0);
  2473.           case -2:            /* Ambiguous, matches more than one */
  2474.         y = (int)strlen(line);
  2475.         slc = 1;
  2476.         for (x = 0; x < nmac; x++)
  2477.           if (!strncmp(mactab[x].kwd,line,y))
  2478.             if (shomac(mactab[x].kwd,mactab[x].mval) < 0) break;
  2479.         return(1);
  2480.           default:            /* Matches one exactly */
  2481.         shomac(mactab[x].kwd,mactab[x].mval);
  2482.         return(1);
  2483.         }
  2484.     } else {            /* They want to see them all */
  2485.         printf("Macros:\n");
  2486.         slc = 1;
  2487.         for (y = 0; y < nmac; y++)
  2488.           if (shomac(mactab[y].kwd,mactab[y].mval) < 0) break;
  2489.         return(1);
  2490.     }
  2491.     }
  2492. #endif /* NOSPL */
  2493.  
  2494. /*
  2495.   Other SHOW commands only have two fields.  Get command confirmation here,
  2496.   then handle with big switch() statement.
  2497. */
  2498.     if ((y = cmcfm()) < 0) return(y);
  2499.     switch (x) {
  2500.  
  2501. #ifdef SUNX25
  2502.         case SHPAD:
  2503.             shopad();
  2504.             break;
  2505. #endif /* SUNX25 */
  2506.  
  2507. #ifdef NETCONN
  2508.     case SHNET:
  2509.         shonet();
  2510.         break;
  2511. #endif /* NETCONN */
  2512.  
  2513.     case SHPAR:
  2514.         shopar();
  2515.         break;
  2516.  
  2517.         case SHATT:
  2518.         shoatt();
  2519.         break;
  2520.  
  2521. #ifndef NOSPL
  2522.     case SHCOU:
  2523.         printf(" %d\n",count[cmdlvl]);
  2524.         break;
  2525. #endif /* NOSPL */
  2526.  
  2527. #ifndef NOSERVER
  2528.         case SHSER:            /* Show Server */
  2529. #ifndef NOFRILLS
  2530.         printf("Function           Status:\n");
  2531.         printf(" GET                %s\n",nm[en_get]);
  2532.         printf(" SEND               %s\n",nm[en_sen]);        
  2533.         printf(" REMOTE CD/CWD      %s\n",nm[en_cwd]);
  2534.         printf(" REMOTE DELETE      %s\n",nm[en_del]);
  2535.         printf(" REMOTE DIRECTORY   %s\n",nm[en_dir]);
  2536.         printf(" REMOTE HOST        %s\n",nm[en_hos]);        
  2537.         printf(" REMOTE SET         %s\n",nm[en_set]);        
  2538.         printf(" REMOTE SPACE       %s\n",nm[en_spa]);        
  2539.         printf(" REMOTE TYPE        %s\n",nm[en_typ]);        
  2540.         printf(" REMOTE WHO         %s\n",nm[en_who]);
  2541.         printf(" BYE                %s\n",nm[en_bye]);
  2542.             printf(" FINISH             %s\n",nm[en_fin]);
  2543. #endif /* NOFRILLS */
  2544.         printf("Server timeout: %d\n",srvtim);
  2545.         printf("Server display: %s\n\n", srvdis ? "on" : "off");
  2546.         break;
  2547. #endif /* NOSERVER */
  2548.  
  2549.         case SHSTA:            /* Status of last command */
  2550.         printf( " %s\n", success ? "SUCCESS" : "FAILURE" );
  2551.         return(0);            /* Don't change it */
  2552.  
  2553. #ifdef MAC
  2554.     case SHSTK: {            /* Stack for MAC debugging */
  2555.         long sp;
  2556.  
  2557.         sp = -1;
  2558.         loadA0 ((char *)&sp);    /* set destination address */
  2559.         SPtoaA0();            /* move SP to destination */
  2560.         printf("Stack at 0x%x\n", sp);
  2561.         show_queue();        /* more debugging */
  2562.         break; 
  2563.     }
  2564. #endif /* MAC */
  2565.  
  2566.     case SHTER:
  2567.         printf(" Command bytesize:  %d bits\n",
  2568.            (cmdmsk == 0377) ? 8 : 7);
  2569.         printf(" Terminal bytesize: %d bits\n",
  2570.            (cmask == 0377) ? 8 : 7);
  2571. #ifdef OS2
  2572.         printf(" Terminal type: %s\n",
  2573.            (tt_type == TT_VT102) ? "VT102" : "VT52");
  2574.  
  2575. #endif /* OS2 */
  2576.         printf(" Terminal echo: %s\n", duplex ? "local" : "remote");
  2577.         printf(" Terminal locking-shift: %s\n", sosi ? "on" : "off");
  2578.         printf(" Terminal newline-mode:  %s\n", tnlm ? "on" : "off");
  2579.         printf(" Terminal cr-display:    %s\n",
  2580.            tt_crd ? "crlf" : "normal");
  2581. #ifdef OS2
  2582. /* Should show cursor and colors here too... */
  2583.         printf(" Terminal arrow-keys:    %s\n",
  2584.            tt_arrow ? "cursor" : "application");
  2585.         printf(" Terminal keypad-mode:   %s\n",
  2586.            tt_keypad ? "numeric" : "application");
  2587.         printf(" Terminal answerback:    %s\n",
  2588.            tt_answer ? "on" : "off");
  2589.         printf(" Terminal wrap:          %s\n",
  2590.            tt_wrap ? "on" : "off");
  2591. #endif /* OS2 */
  2592.  
  2593. #ifndef NOCSETS
  2594.         shotcs(tcsl,tcsr);
  2595. #endif /* NOCSETS */
  2596.         printf(" CONNECT-mode escape character: %d (Ctrl-%c, %s)\n",
  2597.          escape,ctl(escape),(escape == 127 ? "DEL" : ccntab[escape]));
  2598. #ifdef UNIX
  2599.         printf(" Suspend: %s\n", suspend ? "on" : "off");
  2600. #endif /* UNIX */
  2601.         break;
  2602.  
  2603. #ifndef NOFRILLS
  2604.     case SHVER:
  2605.         shover();
  2606.         break;
  2607. #endif /* NOFRILLS */
  2608.  
  2609. #ifndef NOSPL
  2610.     case SHBUI:            /* Built-in variables */
  2611.         i = 0;
  2612.         for (y = 0; y < nvars; y++) {
  2613.         printf(" \\v(%s) = %s\n",vartab[y].kwd,nvlook(vartab[y].kwd));
  2614.         if (++i > SCRNLEN) {    /* More than a screenful... */
  2615.             if (!askmore())
  2616.               break;
  2617.             else
  2618.               i = 0;
  2619.         }
  2620.         }
  2621.             break;
  2622.  
  2623.     case SHFUN:            /* Functions */
  2624.         for (y = 0; y < nfuncs; y++)
  2625.           printf(" \\f%s()\n",fnctab[y].kwd);
  2626.         break;
  2627.  
  2628.         case SHVAR:            /* Global variables */
  2629.         x = 0;            /* Variable count */
  2630.         slc = 1;            /* Screen line count for "more?" */
  2631.         for (y = 33; y < GVARS; y++)
  2632.           if (g_var[y]) {
  2633.           if (x++ == 0) printf("Global variables:\n");
  2634.           sprintf(line," \\%%%c",y);
  2635.           if (shomac(line,g_var[y]) < 0) break;
  2636.           }
  2637.         if (!x) printf(" No variables defined\n");
  2638.         break;
  2639.  
  2640.         case SHARG:            /* Args */
  2641.         if (maclvl > -1) {
  2642.         printf("Macro arguments at level %d\n",maclvl);
  2643.         for (y = 0; y < 10; y++)
  2644.           if (m_arg[maclvl][y])
  2645.             printf(" \\%%%d = %s\n",y,m_arg[maclvl][y]);
  2646.         } else {
  2647.         printf(" No macro arguments at top level\n");
  2648.         }
  2649.         break;
  2650.  
  2651.         case SHARR:            /* Arrays */
  2652.         x = 0;
  2653.         for (y = 0; y < 27; y++)
  2654.           if (a_ptr[y]) {
  2655.           if (x == 0) printf("Declared arrays:\n");
  2656.           x = 1;
  2657.           printf(" \\&%c[%d]\n",(y == 0) ? 64 : y + 96, a_dim[y]);
  2658.           }
  2659.         if (!x) printf(" No arrays declared\n");
  2660.         break;
  2661. #endif /* NOSPL */
  2662.  
  2663.     case SHPRO:            /* Protocol parameters */
  2664.         shoparp();
  2665.         printf("\n");
  2666.         break;
  2667.  
  2668.     case SHCOM:            /* Communication parameters */
  2669.         printf("\n");
  2670.         shoparc();
  2671. #ifndef NODIAL
  2672.         printf("\n");
  2673. #ifdef NETCONN
  2674.         if (!network)
  2675. #endif /* NETCONN */
  2676.           shodial();
  2677. #endif /* NODIAL */
  2678.         printf("\n");
  2679.         shomdm();
  2680.         printf("\n");
  2681.         break;
  2682.  
  2683.     case SHFIL:            /* File parameters */
  2684.         shoparf();
  2685.         printf("\n");
  2686.         break;
  2687.  
  2688. #ifndef NOCSETS
  2689.     case SHLNG:            /* Languages */
  2690.         shoparl();
  2691.         break;
  2692. #endif /* NOCSETS */
  2693.  
  2694. #ifndef NOSPL
  2695.     case SHSCR:            /* Scripts */
  2696.         printf(" Take  Echo:     %s\n", techo  ? "On" : "Off");
  2697.         printf(" Take  Error:    %s\n", terror[cmdlvl] ? "On" : "Off");
  2698.         printf(" Macro Echo:     %s\n", mecho  ? "On" : "Off");
  2699.         printf(" Macro Error:    %s\n", merror[cmdlvl] ? "On" : "Off");
  2700.         printf(" Input Case:     %s\n", incase[cmdlvl] ?
  2701.            "Observe" : "Ignore");
  2702.         printf(" Input Echo:     %s\n", inecho ? "On" : "Off");
  2703.             printf(" Input Silence:  %d\n", insilence);
  2704.         printf(" Input Timeout:  %s\n", intime[cmdlvl] ?
  2705.            "Quit" : "Proceed");
  2706. #ifndef NOSCRIPT
  2707.         printf(" Script Echo:    %s\n", secho  ? "On" : "Off");
  2708. #endif /* NOSCRIPT */
  2709.         break;
  2710. #endif /* NOSPL */
  2711.  
  2712. #ifndef NOXMIT
  2713.       case SHXMI:
  2714.         printf(" File type: %s\n", binary ? "binary" : "text");
  2715. #ifndef NOCSETS
  2716.         shotcs(tcsl,tcsr);
  2717. #endif /* NOCSETS */
  2718.         printf(" Terminal echo: %s\n", duplex ? "local" : "remote");
  2719.             printf(" Transmit EOF: ");
  2720.         if (*xmitbuf == NUL) {
  2721.         printf("none\n");
  2722.         } else {
  2723.         char *p;
  2724.         p = xmitbuf;
  2725.         while (*p) {
  2726.             if (*p < SP)
  2727.               printf("^%c",ctl(*p));
  2728.             else
  2729.               printf("%c",*p);
  2730.             p++;
  2731.         }
  2732.         printf("\n");
  2733.         }
  2734.         if (xmitf)
  2735.           printf(" Transmit Fill: %d (fill character for blank lines)\n",
  2736.            xmitf);
  2737.         else printf(" Transmit Fill: none\n");
  2738.         printf(" Transmit Linefeed: %s\n",
  2739.            xmitl ? "on (send linefeeds too)" : "off");
  2740.         if (xmitp) 
  2741.           printf(" Transmit Prompt: %d (host line end character)\n",xmitp);
  2742.         else printf(" Transmit Prompt: none\n");
  2743.         printf(" Transmit Echo: %s\n",
  2744.            xmitx ? "on" : "off");
  2745.         printf(" Transmit Locking-Shift: %s\n",xmits ? "on" : "off");
  2746.         printf(" Transmit Pause: %d milliseconds\n", xmitw);
  2747.         break;
  2748. #endif /* NOXMIT */
  2749.  
  2750.       case SHMOD:            /* SHOW MODEM */
  2751.         shmdmlin();
  2752.         printf("\n");
  2753.         shomdm();
  2754.         break;
  2755.  
  2756. #ifndef MAC
  2757.           case SHDFLT:
  2758.         zsyscmd(PWDCMD);
  2759.             break;
  2760. #endif /* MAC */
  2761.  
  2762.           case SHESC:
  2763.         printf(" Escape character: Ctrl-%c (ASCII %d, %s)\r\n",
  2764.            ctl(escape), escape, (escape == 127 ? "DEL" : ccntab[escape]));
  2765.         break;
  2766.  
  2767. #ifndef NODIAL
  2768.       case SHDIA:
  2769.         shmdmlin();
  2770.         printf(", speed: ");
  2771.         if ((zz = ttgspd()) < 0) {
  2772.         printf("unknown\n");
  2773.         } else {
  2774.         if (zz == 8880) printf("75/1200\n"); else printf("%ld\n",zz);
  2775.         }
  2776.         doshodial();
  2777.         if (carrier == CAR_OFF) s = "off";
  2778.         else if (carrier == CAR_ON) s = "on";
  2779.         else if (carrier == CAR_AUT) s = "auto";
  2780.         else s = "unknown";
  2781.         printf(" Carrier: %s", s);
  2782.         if (carrier == CAR_ON) {
  2783.         if (cdtimo) printf(", timeout: %d sec", cdtimo);
  2784.         else printf(", timeout: none");
  2785.         }
  2786.         if (local
  2787. #ifdef NETCONN
  2788.         && !network
  2789. #endif /* NETCONN */
  2790.         ) {
  2791.         printf("\n%s modem signals:\n",ttname);
  2792.         shomdm();
  2793.         } else printf("\n");
  2794.         break;
  2795. #endif /* NODIAL */
  2796.  
  2797. #ifdef VMS
  2798.     case SHLBL:            /* Labeled file info */
  2799.         sholbl();
  2800.         break;
  2801. #endif /* VMS */        
  2802.  
  2803.     case SHCSE:            /* Character sets */
  2804. #ifdef NOCSETS
  2805.         printf(
  2806. " Character set translation is not supported in this version of C-Kermit\n");
  2807. #else
  2808.         shocharset();
  2809.             printf("\n Unknown-Char-Set: %s\n",
  2810.            unkcs ? "Keep" : "Discard");
  2811.         shotcs(tcsl,tcsr);
  2812.         printf("\n");
  2813. #endif /* NOCSETS */
  2814.         break;
  2815.  
  2816. #ifndef NOFRILLS
  2817.       case SHFEA:            /* Features */
  2818.         shofea();
  2819.         break;
  2820. #endif /* NOFRILLS */
  2821.  
  2822.     default:
  2823.         printf("\nNothing to show...\n");
  2824.         return(-2);
  2825.     }
  2826.     return(success = 1);
  2827. }
  2828.  
  2829. VOID
  2830. shmdmlin() {                /* Briefly show modem & line */
  2831.     int i;
  2832. #ifndef NODIAL
  2833. #ifndef MINIDIAL
  2834.     extern int tbmodel;
  2835.     _PROTOTYP( char * gtbmodel, (void) );
  2836. #endif /* MINIDIAL */
  2837. #endif /* NODIAL */
  2838.     if (local)
  2839.       printf(" Line: %s, Modem: ",ttname);
  2840.     else
  2841.       printf(" Communication device not yet selected with SET LINE\n Modem: ");
  2842. #ifndef NODIAL
  2843.     for (i = 0; i < nmdm; i++) {
  2844.     if (mdmtab[i].kwval == mdmtyp) {
  2845.         printf("%s",mdmtab[i].kwd);
  2846.         break;
  2847.     }
  2848.     }
  2849. #ifndef MINIDIAL
  2850.     if (tbmodel) printf(" (%s)",gtbmodel()); /* Telebit model info */
  2851. #endif /* MINIDIAL */
  2852. #else
  2853.     printf("(disabled)");
  2854. #endif /* NODIAL */
  2855. }
  2856. #endif /* NOSHOW */
  2857.  
  2858. #ifdef GEMDOS
  2859. isxdigit(c) int c; {
  2860.     return(isdigit(c) ||
  2861.        (c >= 'a' && c <= 'f') ||
  2862.        (c >= 'A' && c <= 'F'));
  2863. }
  2864. #endif /* GEMDOS */
  2865.  
  2866. #ifndef NOSHOW
  2867. #ifndef NOSPL
  2868. int                    /* SHO MACROS */
  2869. shomac(s1, s2) char *s1, *s2; {
  2870.     int x, n, pp;
  2871.     pp = 0;                /* Parenthesis counter */
  2872.  
  2873.     if (!s1)
  2874.       return(0);
  2875.     else
  2876.       printf("\n%s = ",s1);        /* Print blank line and macro name */
  2877.     slc++;                /* Count the line */
  2878.     n = (int)strlen(s1) + 4;        /* Width of current line */
  2879.     if (!s2) s2 = "(null definition)";
  2880.  
  2881.     while (x = *s2++) {            /* Loop thru definition */
  2882.     if (x == '(') pp++;        /* Treat commas within parens */
  2883.     if (x == ')') pp--;        /* as ordinary text */
  2884.     if (pp < 0) pp = 0;        /* Outside parens, */
  2885.     if (x == ',' && pp == 0) {    /* comma becomes comma-dash-NL. */
  2886.         putchar(',');
  2887.         putchar('-');
  2888.         x = '\n';
  2889.     }
  2890.     putchar(x);            /* Output the character */
  2891.     if (x == '\n') {        /* If it was a newline */
  2892. #ifdef UNIX
  2893. #ifdef NOSETBUF
  2894.         fflush(stdout);
  2895. #endif /* NOSETBUF */
  2896. #endif /* UNIX */
  2897.         putchar(' ');        /* Indent the next line 1 space */
  2898.         while(*s2 == ' ') s2++;    /* skip past leading blanks */
  2899.         n = 2;            /* restart the character counter */
  2900.         slc++;            /* and increment the line counter. */
  2901.     } else if (++n > SCRNWID) {    /* If line is too wide */
  2902.         putchar('-');        /* output a dash */
  2903.         putchar(NL);        /* and a newline */
  2904. #ifdef UNIX
  2905. #ifdef NOSETBUF
  2906.         fflush(stdout);
  2907. #endif /* NOSETBUF */
  2908. #endif /* UNIX */
  2909.         n = 1;            /* and restart the char counter */
  2910.         slc++;            /* and increment the line counter */
  2911.     }
  2912.     if (n < 3 && slc > SCRNLEN) {    /* If new line and screen is full */
  2913.         if (!askmore()) return(-1);    /* ask if they want more. */
  2914.         n = 1;            /* They do, start a new line */
  2915.         slc = 0;            /* and restart line counter */
  2916.     }
  2917.     }
  2918.     putchar(NL);            /* End of definition */
  2919.     if (++slc > SCRNLEN) {
  2920.     if (!askmore()) return(-1);
  2921.     slc = 0;
  2922.     }
  2923.     return(0);
  2924. }
  2925. #endif /* NOSPL */
  2926. #endif /* NOSHOW */
  2927.  
  2928. #ifndef NOSHOW
  2929. int
  2930. shoatt() {
  2931.     printf("Attributes: %s\n", atcapr ? "On" : "Off");
  2932.     if (!atcapr) return(0);
  2933.     printf(" Blocksize: %s\n", atblki ? "On" : "Off");
  2934.     printf(" Date: %s\n", atdati ? "On" : "Off");
  2935.     printf(" Disposition: %s\n", atdisi ? "On" : "Off");
  2936.     printf(" Encoding (Character Set): %s\n", atenci ? "On" : "Off");
  2937.     printf(" Length: %s\n", atleni ? "On" : "Off");
  2938.     printf(" Type (text/binary): %s\n", attypi ? "On" : "Off");
  2939.     printf(" System ID: %s\n", atsidi ? "On" : "Off");
  2940.     printf(" System Info: %s\n", atsysi ? "On" : "Off");
  2941.     return(0);
  2942. }
  2943. #endif /* NOSHOW */
  2944.  
  2945. #ifndef NOSPL
  2946. /* Evaluate an arithmetic expression. */
  2947. /* Code adapted from ev, by Howie Kaye of Columbia U & others. */
  2948.  
  2949. static int xerror;
  2950. static char *cp;
  2951. static long tokval;
  2952. static char curtok;
  2953. static long expval;
  2954.  
  2955. #define LONGBITS (8*sizeof (long))
  2956. #define NUMBER 'N'
  2957. #define EOT 'E'
  2958.  
  2959. /*
  2960.  Replacement for strchr() and index(), neither of which seem to be universal.
  2961. */
  2962.  
  2963. static char *
  2964. #ifdef CK_ANSIC
  2965. windex(char * s, char c)
  2966. #else
  2967. windex(s,c) char *s, c;
  2968. #endif /* CK_ANSIC */
  2969. /* windex */ {
  2970.     while (*s != NUL && *s != c) s++;
  2971.     if (*s == c) return(s); else return(NULL);
  2972. }
  2973.  
  2974. /*
  2975.  g e t t o k
  2976.  
  2977.  Returns the next token.  If token is a NUMBER, sets tokval appropriately.
  2978. */
  2979. static char
  2980. gettok() {
  2981.     while (isspace(*cp)) cp++ ;
  2982.     switch(*cp) {
  2983.       case '$':                /* ??? */
  2984.       case '+':                /* Add */
  2985.       case '-':                /* Subtract or Negate */
  2986.       case '@':                /* Greatest Common Divisor */
  2987.       case '*':                /* Multiply */
  2988.       case '/':                /* Divide */
  2989.       case '%':                /* Modulus */
  2990.       case '<':                /* Left shift */
  2991.       case '>':                /* Right shift */
  2992.       case '&':                /* And */
  2993.       case '|':                /* Or */
  2994.       case '#':                /* Exclusive Or */
  2995.       case '~':                /* Not */
  2996.       case '^':                /* Exponent */
  2997.       case '!':                /* Factorial */
  2998.       case '(':                /* Parens for grouping */
  2999.       case ')': return(*cp++);        /* operator, just return it */
  3000.       case '\n':
  3001.       case '\0': return(EOT);        /* end of line, return that */
  3002.     }
  3003.     if (isxdigit(*cp)) {        /* digit, must be a number */
  3004.     char tbuf[80],*tp;        /* buffer to accumulate number */
  3005.     int radix = 10;            /* default radix */
  3006.     for (tp=tbuf; isxdigit(*cp); cp++)
  3007.       *tp++ = isupper(*cp) ? tolower(*cp) : *cp;
  3008.     *tp = '\0';            /* end number */
  3009.     switch(isupper(*cp) ? tolower(*cp) : *cp) { /* examine break char */
  3010.       case 'h':
  3011.       case 'x': radix = 16; cp++; break; /* if radix signifier... */
  3012.       case 'o':
  3013.       case 'q': radix = 8; cp++; break;
  3014.       case 't': radix = 2; cp++; break;
  3015.     }
  3016.     for (tp=tbuf,tokval=0; *tp != '\0'; tp++)  {
  3017.         int dig;
  3018.         dig = *tp - '0';        /* convert number */
  3019.         if (dig > 10) dig -= 'a'-'0'-10;
  3020.         if (dig >= radix) {
  3021.         xerror = 1;
  3022.         if (cmdlvl == 0)
  3023.           printf("invalid digit '%c' in number\n",*tp);
  3024.         return(NUMBER);
  3025.         }
  3026.         tokval = radix*tokval + dig;
  3027.     }
  3028.     return(NUMBER);
  3029.     }
  3030.     if (cmdlvl == 0)
  3031.       printf("Invalid character '%c' in input\n",*cp);
  3032.     xerror = 1;
  3033.     cp++;
  3034.     return(gettok());
  3035. }
  3036.  
  3037. static long
  3038. #ifdef CK_ANSIC
  3039. expon(long x, long y)
  3040. #else
  3041. expon(x,y) long x,y;
  3042. #endif /* CK_ANSIC */
  3043. /* expon */ {
  3044.     long result = 1;
  3045.     int sign = 1;
  3046.     if (y < 0) return(0);
  3047.     if (x < 0) {
  3048.     x = -x;
  3049.     if (y & 1) sign = -1;
  3050.     }
  3051.     while (y != 0) {
  3052.     if (y & 1) result *= x;
  3053.     y >>= 1;
  3054.     if (y != 0) x *= x;
  3055.   }
  3056.   return(result * sign);
  3057. }
  3058.  
  3059. /*
  3060.  * factor ::= simple | simple ^ factor
  3061.  *
  3062.  */
  3063. _PROTOTYP( static VOID simple, (void) );
  3064.  
  3065. static VOID
  3066. factor() {
  3067.     long oldval;
  3068.     simple();
  3069.     if (curtok == '^') {
  3070.     oldval = expval;
  3071.     curtok = gettok();
  3072.     factor();
  3073.     expval = expon(oldval,expval);
  3074.     }
  3075. }
  3076.  
  3077. /*
  3078.  * termp ::= NULL | {*,/,%,&} factor termp
  3079.  *
  3080.  */
  3081. static VOID
  3082. termp() {
  3083.     while (curtok == '*' || curtok == '/' || curtok == '%' || curtok == '&') {
  3084.     long oldval;
  3085.     char op;
  3086.     op = curtok;
  3087.     curtok = gettok();        /* skip past operator */
  3088.     oldval = expval;
  3089.     factor();
  3090.     switch(op) {
  3091.       case '*': expval = oldval * expval; break;
  3092.       case '/':
  3093.         if (expval == 0) expval = -1; /* don't divide by 0 */
  3094.         else expval = oldval / expval; break;
  3095.       case '%': expval = oldval % expval; break;
  3096.       case '&': expval = oldval & expval; break;
  3097.     }
  3098.     }
  3099. }
  3100.  
  3101. static long
  3102. #ifdef CK_ANSIC
  3103. fact(long x)
  3104. #else
  3105. fact(x) long x;
  3106. #endif /* CK_ANSIC */
  3107. /* fact */ {                /* factorial */
  3108.     long result = 1;
  3109.     while (x > 1)
  3110.       result *= x--;
  3111.     return(result);
  3112. }
  3113.  
  3114. /*
  3115.  * term ::= factor termp
  3116.  *
  3117.  */
  3118. static VOID
  3119. term() {
  3120.     factor();
  3121.     termp();
  3122. }
  3123.  
  3124. static long
  3125. #ifdef CK_ANSIC
  3126. gcd(long x, long y)
  3127. #else
  3128. gcd(x,y) long x,y;
  3129. #endif /* CK_ANSIC */
  3130. /* gcd */ {                /* Greatest Common Divisor */
  3131.     int nshift = 0;
  3132.     if (x < 0) x = -x;
  3133.     if (y < 0) y = -y;            /* validate arguments */
  3134.     if (x == 0 || y == 0) return(x + y);    /* this is bogus */
  3135.     
  3136.     while (!((x & 1) | (y & 1))) {    /* get rid of powers of 2 */
  3137.     nshift++;
  3138.     x >>= 1;
  3139.     y >>= 1;
  3140.     }
  3141.     while (x != 1 && y != 1 && x != 0 && y != 0) {
  3142.     while (!(x & 1)) x >>= 1;    /* eliminate unnecessary */
  3143.     while (!(y & 1)) y >>= 1;    /* powers of 2 */
  3144.     if (x < y) {            /* force x to be larger */
  3145.         long t;
  3146.         t = x;
  3147.         x = y;
  3148.         y = t;
  3149.     }
  3150.     x -= y;
  3151.     }
  3152.     if (x == 0 || y == 0) return((x + y) << nshift); /* gcd is non-zero one */
  3153.     else return((long) 1 << nshift);    /* else gcd is 1 */
  3154. }
  3155.  
  3156. /*
  3157.  * exprp ::= NULL | {+,-,|,...} term exprp
  3158.  *
  3159.  */
  3160. static VOID
  3161. exprp() {
  3162.     while (windex("+-|<>#@",curtok) != NULL) {
  3163.     long oldval;
  3164.     char op;
  3165.     op = curtok;
  3166.     curtok = gettok();        /* skip past operator */
  3167.     oldval = expval;
  3168.     term();
  3169.     switch(op) {
  3170.       case '+' : expval = oldval + expval; break;
  3171.       case '-' : expval = oldval - expval; break;
  3172.       case '|' : expval = oldval | expval; break;
  3173.       case '#' : expval = oldval ^ expval; break;
  3174.       case '@' : expval = gcd(oldval,expval); break;
  3175.       case '<' : expval = oldval << expval; break;
  3176.       case '>' : expval = oldval >> expval; break;
  3177.     }
  3178.     }
  3179. }
  3180.  
  3181. /*
  3182.  * expr ::= term exprp
  3183.  *
  3184.  */
  3185. static VOID
  3186. expr() {
  3187.     term();
  3188.     exprp();
  3189. }
  3190.  
  3191. static long
  3192. xparse() {
  3193.     curtok = gettok();
  3194.     expr();
  3195. #ifdef COMMENT
  3196.     if (curtok == '$') {
  3197.     curtok = gettok();
  3198.     if (curtok != NUMBER) {
  3199.         if (cmdlvl == 0) printf("illegal radix\n");
  3200.         return(0);
  3201.     }
  3202.     curtok = gettok();
  3203.     }
  3204. #endif /* COMMENT */
  3205.     if (curtok != EOT) {
  3206.     if (cmdlvl == 0)
  3207.       printf("extra characters after expression\n");
  3208.     xerror = 1;
  3209.     }
  3210.     return(expval);
  3211. }
  3212.  
  3213. char *
  3214. evala(s) char *s; {
  3215.     char *p;                /* Return pointer */
  3216.     long v;                /* Numeric value */
  3217.  
  3218.     xerror = 0;                /* Start out with no error */
  3219.     cp = s;                /* Make the argument global */
  3220.     v = xparse();            /* Parse the string */
  3221.     p = numbuf;                /* Convert long number to string */
  3222.     sprintf(p,"%ld",v);
  3223.     return(xerror ? "" : p);        /* Return empty string on error */
  3224. }
  3225.  
  3226. /*
  3227.  * simplest ::= NUMBER | ( expr )
  3228.  *
  3229.  */
  3230. static VOID
  3231. simplest() {
  3232.     if (curtok == NUMBER) expval = tokval;
  3233.     else if (curtok == '(') {
  3234.     curtok = gettok();        /* skip over paren */
  3235.     expr();
  3236.     if (curtok != ')') {
  3237.         if (cmdlvl == 0) printf("missing right parenthesis\n");
  3238.         xerror = 1;
  3239.     }
  3240.     }
  3241.     else {
  3242.     if (cmdlvl == 0) printf("operator unexpected\n");
  3243.     xerror = 1;
  3244.     }
  3245.     curtok = gettok();
  3246. }
  3247.  
  3248. /*
  3249.  * simpler ::= simplest | simplest !
  3250.  *
  3251.  */
  3252. static VOID
  3253. simpler() {
  3254.     simplest();
  3255.     if (curtok == '!') {
  3256.     curtok = gettok();
  3257.     expval = fact(expval);
  3258.     }
  3259. }
  3260.  
  3261. /*
  3262.  * simple ::= {-,~} simpler | simpler
  3263.  *
  3264.  */
  3265.  
  3266. static VOID
  3267. simple() {
  3268.     if (curtok == '-' || curtok == '~') {
  3269.     int op = curtok;
  3270.     curtok = gettok();        /* skip over - sign */
  3271.     simpler();            /* parse the factor again */
  3272.     expval = op == '-' ? -expval : ~expval;
  3273.     } else simpler();
  3274. }
  3275. #endif /* NOSPL */
  3276.  
  3277. #ifndef NOSPL
  3278. /*  D C L A R R A Y  --  Declare an array  */
  3279.  
  3280. int                    /* Declare an array of size n */
  3281. #ifdef CK_ANSIC
  3282. dclarray(char a, int n)
  3283. #else
  3284. dclarray(a,n) char a; int n;
  3285. #endif /* CK_ANSIC */
  3286. /* dclarray */ {
  3287.     char **p; int i, n2;
  3288.  
  3289.     if (a > 63 && a < 96) a += 32;    /* Convert to lowercase */
  3290.     if (a < 96 || a > 122) return(-1);    /* Verify name */
  3291.     a -= 96;                /* Convert name to number */
  3292.     if ((p = a_ptr[a]) != NULL) {    /* Delete old array of same name */
  3293.     n2 = a_dim[a];
  3294.     for (i = 0; i <= n2; i++)    /* First delete its elements */
  3295.       if (p[i]) free(p[i]);
  3296.     free(a_ptr[a]);            /* Then the element list */
  3297.     a_ptr[a] = (char **) NULL;    /* Remove pointer to element list */
  3298.     a_dim[a] = 0;            /* Set dimension at zero. */
  3299.     }
  3300.     if (n == 0) return(0);        /* If dimension 0, just deallocate. */
  3301.  
  3302.     p = (char **) malloc((n+1) * sizeof(char **)); /* Allocate for new array */
  3303.     if (p == NULL) return(-1);        /* Check */
  3304.     a_ptr[a] = p;            /* Save pointer to member list */
  3305.     a_dim[a] = n;            /* Save dimension */
  3306.     for (i = 0; i <= n; i++)        /* Initialize members to null */
  3307.       p[i] = NULL;
  3308.     return(0);
  3309. }
  3310.  
  3311. /*  A R R A Y N A M  --  Parse an array name  */
  3312.  
  3313. /*
  3314.   Call with pointer to string that starts with the array reference.
  3315.   String may begin with either \& or just &.
  3316.   On success,
  3317.     Returns letter ID (always lowercase) in argument c,
  3318.       which can also be accent grave (` = 96; '@' is converted to grave);
  3319.     Dimension or subscript in argument n;
  3320.     IMPORTANT: These arguments must be provided by the caller as addresses
  3321.     of ints (not chars), for example:
  3322.       char *s; int x, y;
  3323.       arraynam(s,&x,&y);
  3324.   On failure, returns a negative number, with args n and c set to zero.
  3325. */
  3326. int
  3327. arraynam(ss,c,n) char *ss; int *c; int *n; {
  3328.     int i, y, pp;
  3329.     char x;
  3330.     char *s, *p, *sx, *vnp;
  3331.     char vnbuf[VNAML+1];        /* On stack to allow for */
  3332.     char ssbuf[VNAML+1];        /* recursive calls... */
  3333.     char sxbuf[VNAML+1];
  3334.  
  3335.     *c = *n = 0;            /* Initialize return values */
  3336.     for (i = 0; i < (int)strlen(ss); i++) /* Check length */
  3337.       if (ss[i] == ']')
  3338.     break;
  3339.     if (i > VNAML) {
  3340.     printf("?Array reference too long - %s\n",ss);
  3341.     return(-9);
  3342.     }
  3343.     strncpy(vnbuf,ss,VNAML);
  3344.     vnp = vnbuf;
  3345.     if (vnbuf[0] == CMDQ && vnbuf[1] == '&') vnp++;
  3346.     if (*vnp != '&') {
  3347.     printf("?Not an array - %s\n",vnbuf);
  3348.     return(-9);
  3349.     }
  3350.     x = *(vnp + 1);            /* Fold case of array name */
  3351.     /* We don't use isupper & tolower here on purpose because these */
  3352.     /* would produce undesired effects with accented letters. */
  3353.     if (x > 63 && x < 91) x  = *(vnp +1) = x + 32;
  3354.     if ((x < 96) || (x > 122) || (*(vnp+2) != '[')) {
  3355.     printf("?Invalid format for array name - %s\n",vnbuf);
  3356.     return(-9);
  3357.     }
  3358.     *c = x;                /* Return the array name */
  3359.     s = vnp+3;                /* Get dimension */
  3360.     p = ssbuf;    
  3361.     pp = 1;                /* Bracket counter */
  3362.     for (i = 0; i < VNAML && *s != NUL; i++) { /* Copy up to ] */
  3363.     if (*s == '[') pp++;
  3364.     if (*s == ']' && --pp == 0) break;
  3365.     *p++ = *s++;
  3366.     }
  3367.     if (*s != ']') {
  3368.     printf("?No closing bracket on array dimension - %s\n",vnbuf);
  3369.     return(-9);
  3370.     }
  3371.     *p = NUL;                /* Terminate subscript with null */
  3372.     p = ssbuf;                /* Point to beginning of subscript */
  3373.     sx = sxbuf;                /* Where to put expanded subscript */
  3374.     y = VNAML-1;
  3375.     xxstring(p,&sx,&y);            /* Convert variables, etc. */
  3376.     if (!chknum(sxbuf)) {        /* Make sure it's all digits */
  3377.     printf("?Array dimension or subscript must be numeric - %s\n",sxbuf);
  3378.     return(-9);
  3379.     }
  3380.     if ((y = atoi(sxbuf)) < 0) {
  3381.         if (cmflgs == 0) printf("\n");
  3382.         printf("?Array dimension or subscript must be positive or zero - %s\n",
  3383.            sxbuf);
  3384.     return(-9);
  3385.     }
  3386.     *n = y;                /* Return the subscript or dimension */
  3387.     return(0);
  3388. }
  3389.  
  3390. int
  3391. chkarray(a,i) int a, i; {        /* Check if array is declared */
  3392.     int x;                /* and if subscript is in range */
  3393.     if (a == 64) a = 96;        /* Convert atsign to grave accent */
  3394.     x = a - 96;                /* Values must be in range 96-122 */
  3395.     if (x < 0 || x > 26) return(-2);    /* Not in range */
  3396.     if (a_ptr[x] == NULL) return(-1);    /* Not declared */
  3397.     if (i > a_dim[x]) return(-2);    /* Declared but out of range. */
  3398.     return(a_dim[x]);            /* All ok, return dimension */
  3399. }
  3400.  
  3401. char *
  3402. arrayval(a,i) int a, i; {        /* Return value of \&a[i] */
  3403.     int x; char **p;            /* (possibly NULL) */
  3404.  
  3405.     if (a == 64) a = 96;        /* Convert atsign to grave accent */
  3406.     x = a - 96;                /* Values must be in range 96-122 */
  3407.     if (x < 0 || x > 26) return(NULL);    /* Not in range */
  3408.     if ((p = a_ptr[x]) == NULL)        /* Array not declared */
  3409.       return(NULL);
  3410.     if (i > a_dim[x])            /* Subscript out of range. */
  3411.       return(NULL);
  3412.     return(p[i]);            /* All ok, return pointer to value. */
  3413. }
  3414. #endif /* NOSPL */
  3415.  
  3416. #ifndef NOSPL
  3417. /*  P A R S E V A R  --  Parse a variable name or array reference.  */
  3418. /*
  3419.  Call with:
  3420.    s  = pointer to candidate variable name or array reference.
  3421.    *c = address of integer in which to return variable ID.
  3422.    *i = address of integer in which to return array subscript.
  3423.  Returns:
  3424.    -2:  syntax error in variable name or array reference.
  3425.     1:  successful parse of a simple variable, with ID in c.
  3426.     2:  successful parse of an array reference, w/ID in c and subscript in i.
  3427. */
  3428. int
  3429. parsevar(s,c,i) char *s; int *c, *i; {
  3430.     char *p;
  3431.     int x,y,z;
  3432.  
  3433.     p = s;
  3434.     if (*s == CMDQ) s++;        /* Point after backslash */
  3435.  
  3436.     if (*s != '%' && *s != '&') {    /* Make sure it's % or & */
  3437.     printf("?Not a variable name - %s\n",p);
  3438.     return(-9);
  3439.     }
  3440.     if ((int)strlen(s) < 2) {
  3441.     printf("?Incomplete variable name - %s\n",p);
  3442.     return(-9);
  3443.     }
  3444.     if (*s == '%' && *(s+2) != '\0') {
  3445.     printf("?Only one character after '%%' in variable name, please\n");
  3446.     return(-9);
  3447.     }
  3448.     if (*s == '&' && *(s+2) != '[') {
  3449.     printf("?Array subscript expected - %s\n",p);
  3450.     return(-9);
  3451.     }
  3452.     if (*s == '%') {            /* Simple variable. */
  3453.     y = *(s+1);            /* Get variable ID letter/char */
  3454.     if (isupper(y)) y -= ('a'-'A');    /* Convert upper to lower case */
  3455.     *c = y;                /* Set the return values. */
  3456.     *i = -1;            /* No array subscript. */
  3457.     return(1);            /* Return 1 = simple variable */
  3458.     }
  3459.     if (*s == '&') {            /* Array reference. */
  3460.     if (arraynam(s,&x,&z) < 0) { /* Go parse it. */
  3461.         printf("?Invalid array reference - %s\n",p);
  3462.         return(-9);
  3463.     }
  3464.     if (chkarray(x,z) < 0) {    /* Check if declared, etc. */
  3465.         printf("?Array not declared or subscript out of range\n");
  3466.         return(-9);
  3467.     }
  3468.     *c = x;                /* Return array letter */
  3469.     *i = z;                /* and subscript. */
  3470.     return(2);
  3471.     }    
  3472.     return(-2);                /* None of the above. */
  3473. }
  3474.  
  3475. #define VALN 20
  3476.  
  3477. /* Get the numeric value of a variable */
  3478. /*
  3479.   Call with pointer to variable name, pointer to int for return value.
  3480.   Returns:
  3481.     0 on success with second arg containing the value.
  3482.    -1 on failure (bad variable syntax, variable not defined or not numeric).
  3483. */
  3484. int
  3485. varval(s,v) char *s; int *v; {
  3486.     char valbuf[VALN+1];        /* s is pointer to variable name */
  3487.     char *p;
  3488.     int y;
  3489.  
  3490.     p = valbuf;                /* Expand variable into valbuf. */
  3491.     y = VALN;
  3492.     if (xxstring(s,&p,&y) < 0) return(-1);
  3493.     p = valbuf;                /* Make sure value is numeric */
  3494.     if (!chknum(p)) return(-1);
  3495.     *v = atoi(p);            /* Convert numeric string to int */
  3496.     return(0);    
  3497. }
  3498.  
  3499. /* Increment or decrement a variable */
  3500. /* Returns -1 on failure, 0 on success, with 4th argument set to result */
  3501.  
  3502. int
  3503. incvar(s,x,z,r) char *s; int x, z, *r; { /* Increment a numeric variable */
  3504.     char valbuf[VALN+1];        /* s is pointer to variable name */
  3505.                     /* x is amount to increment by */
  3506.     int n;                /* z != 0 means add */
  3507.                     /* z = 0 means subtract */
  3508.  
  3509.     if (varval(s,&n) < 0)        /* Convert numeric string to int */
  3510.       return(-1);
  3511.     if (z)                /* Increment it by the given amount */
  3512.       n += x;
  3513.     else                /* or decrement as requested. */
  3514.       n -= x;
  3515.     sprintf(valbuf,"%d",n);        /* Convert back to numeric string */
  3516.     addmac(s,valbuf);            /* Replace old variable */
  3517.     *r = n;                /* Return the integer value */
  3518.     return(0);
  3519. }
  3520. #endif /* NOSPL */
  3521.  
  3522. /* Functions moved here from ckuusr.c to even out the module sizes... */
  3523.  
  3524. #ifndef NOSPL                /* Need xwords() function to break */
  3525. #define XWORDS                /* string up into words. */
  3526. #endif /* NOSPL */
  3527. #ifndef NODIAL
  3528. #ifndef XWORDS
  3529. #define XWORDS
  3530. #endif /* XWORDS */
  3531. #endif /* NODIAL */
  3532.  
  3533. #ifdef XWORDS
  3534. /*
  3535.   Breaks string s up into a list of up to max words.
  3536.   Pointers to each word go into the array list[].
  3537.   If list is NULL, then they are added to the macro table.
  3538. */
  3539.  
  3540. VOID
  3541. xwords(s,max,list) char *s; int max; char *list[]; {
  3542.     char *p;
  3543.     int b, k, y, z;
  3544. #ifndef NOSPL
  3545.     int macro;
  3546.     macro = (list == NULL);
  3547.     debug(F101,"xwords macro","",macro);
  3548. #endif /* NOSPL */
  3549.  
  3550.     p = s;                /* Pointer to beginning of string */
  3551.     b = 0;                /* Flag for outer brace removal */
  3552.     k = 0;                /* Flag for in-word */
  3553.     y = 0;                /* Brace nesting level */
  3554.     z = 0;                /* Argument counter, 0 thru max */
  3555.  
  3556.     while (1) {                /* Go thru argument list */
  3557.     if (!s || (*s == '\0')) {    /* No more characters? */
  3558.         if (k != 0) {
  3559.         if (z == max) break;    /* Only go up to max. */
  3560.         z++;            /* Count it. */
  3561. #ifndef NOSPL
  3562.         if (macro) {
  3563.             varnam[1] = z + '0'; /* Assign last argument */
  3564.             addmac(varnam,p);
  3565.         } else
  3566. #endif /* NOSPL */
  3567.           list[z] = p;
  3568.         break;            /* And get out. */
  3569.         } else break;
  3570.     } 
  3571.     if (k == 0 && (*s == SP || *s == HT)) { /* Eat leading blanks */
  3572.         s++;
  3573.         continue;
  3574.     } else if (*s == '{') {        /* An opening brace */
  3575.         if (k == 0 && y == 0) {    /* If leading brace */
  3576.         p = s+1;        /* point past it */
  3577.         b = 1;            /* and flag that we did this */
  3578.         }
  3579.         k = 1;            /* Flag that we're in a word */
  3580.         y++;            /* Count the brace. */
  3581.     } else if (*s == '}') {        /* A closing brace. */
  3582.         y--;            /* Count it. */
  3583.         if (y == 0 && b != 0) {    /* If it matches the leading brace */
  3584.         *s = SP;        /* change it to a space */
  3585.         b = 0;            /* and we're not in braces any more */
  3586.         } else if (y < 0) k = 1;    /* otherwise just start a new word. */
  3587.     } else if (*s != SP && *s != HT) { /* Nonspace means we're in a word */
  3588.         if (k == 0) p = s;        /* Mark the beginning */
  3589.         k = 1;            /* Set in-word flag */
  3590.     }
  3591.     /* If we're not inside a braced quantity, and we are in a word, and */
  3592.     /* we have hit whitespace, then we have an argument to assign. */
  3593.     if ((y < 1) && (k != 0) && (*s == SP || *s == HT)) { 
  3594.         *s = '\0';            /* terminate the arg with null */
  3595.         k = 0;            /* say we're not in a word any more */
  3596.         y = 0;            /* start braces off clean again */
  3597.         if (z == max) break;    /* Only go up to max. */
  3598.         z++;            /* count this arg */
  3599. #ifndef NOSPL
  3600.         if (macro) {
  3601.         varnam[1] = z + '0';    /* compute its name */
  3602.         addmac(varnam,p);    /* add it to the macro table */
  3603.         } else
  3604. #endif /* NOSPL */
  3605.           list[z] = p;
  3606.         p = s+1;
  3607.     }
  3608.     s++;                /* Point past this character */
  3609.     }
  3610.     if ((z == 0) && (y > 1)) {        /* Extra closing brace(s) at end */
  3611.     z++;
  3612. #ifndef NOSPL
  3613.     if (macro) {
  3614.         varnam[1] = z + '0';    /* compute its name */
  3615.         addmac(varnam,p);        /* Add rest of line to last arg */
  3616.     } else
  3617. #endif /* NOSPL */
  3618.       list[z] = p;
  3619.     }
  3620. #ifndef NOSPL
  3621.     if (macro) macargc[maclvl] = z + 1;    /* Set \v(argc) variable */
  3622. #endif /* NOSPL */
  3623.     return;
  3624. }
  3625. #endif /* XWORDS */
  3626.  
  3627. #ifndef NOSPL
  3628. /* D O D O  --  Do a macro */
  3629.  
  3630. /*
  3631.   Call with x = macro table index, s = pointer to arguments.
  3632.   Returns 0 on failure, 1 on success.
  3633. */
  3634.  
  3635. int
  3636. dodo(x,s) int x; char *s; {
  3637.     int y;
  3638.  
  3639.     debug(F101,"dodo maclvl","",maclvl);
  3640.     if (++maclvl > MACLEVEL) {        /* Make sure we have storage */
  3641.         debug(F101,"dodo maclvl too deep","",maclvl);
  3642.     --maclvl;
  3643.     printf("Macros nested too deeply\n");
  3644.     return(0);
  3645.     }
  3646.     macp[maclvl] = mactab[x].mval;    /* Point to the macro body */ 
  3647.     macx[maclvl] = mactab[x].mval;    /* Remember where the beginning is */
  3648.     debug(F111,"do macro",macp[maclvl],maclvl);
  3649.  
  3650.     cmdlvl++;                /* Entering a new command level */
  3651.     if (cmdlvl > CMDSTKL) {        /* Too many macros + TAKE files? */
  3652.         debug(F101,"dodo cmdlvl too deep","",cmdlvl);
  3653.     cmdlvl--;
  3654.     printf("?TAKE files and DO commands nested too deeply\n");
  3655.     return(0);
  3656.     }
  3657. #ifdef VMS
  3658.     conres();                /* So Ctrl-C, etc, will work. */
  3659. #endif /* VMS */
  3660.     ifcmd[cmdlvl] = 0;
  3661.     iftest[cmdlvl] = 0;
  3662.     count[cmdlvl] = count[cmdlvl-1]; /* Inherit COUNT from previous level */
  3663.     intime[cmdlvl] = intime[cmdlvl-1];    /* Inherit previous INPUT TIMEOUT */
  3664.     incase[cmdlvl] = incase[cmdlvl-1];    /*   and INPUT CASE */
  3665.     terror[cmdlvl] = terror[cmdlvl-1];    /*   and TAKE ERROR */
  3666.     merror[cmdlvl] = merror[cmdlvl-1];    /*   and MACRO ERROR */
  3667.     cmdstk[cmdlvl].src = CMD_MD;    /* Say we're in a macro */
  3668.     cmdstk[cmdlvl].lvl = maclvl;    /* and remember the macro level */
  3669.     mrval[maclvl] = NULL;        /* Initialize return value */
  3670.  
  3671.     debug(F110,"do macro",mactab[x].kwd,0);
  3672.  
  3673. /* Clear old %0..%9 arguments */
  3674.  
  3675.     addmac("%0",mactab[x].kwd);        /* Define %0 = name of macro */
  3676.     varnam[0] = '%';
  3677.     varnam[2] = '\0';
  3678.     for (y = 1; y < 10; y++) {        /* Clear args %1..%9 */
  3679.     varnam[1] = y + '0';
  3680.     delmac(varnam);
  3681.     }    
  3682.  
  3683. /* Assign the new args one word per arg, allowing braces to group words */
  3684.  
  3685.     xwords(s,9,NULL);
  3686.     return(1);
  3687. }
  3688.  
  3689. /* Insert "literal" quote around each comma-separated command to prevent */
  3690. /* its premature expansion.  Only do this if object command is surrounded */
  3691. /* by braces. */
  3692.  
  3693. static char* flit = "\\flit(";
  3694.  
  3695. int
  3696. litcmd(src,dest) char **src, **dest; {
  3697.     int bc = 0, pp = 0;
  3698.     char *s, *lp, *ss;
  3699.  
  3700.     s = *src;
  3701.     lp = *dest;
  3702.  
  3703.     while (*s == SP) s++;        /* strip extra leading spaces */
  3704.     if (*s == '{') {
  3705.  
  3706.         pp = 0;                /* paren counter */
  3707.     bc = 1;                /* count leading brace */
  3708.     *lp++ = *s++;            /* copy it */
  3709.     while (*s == SP) s++;        /* strip interior leading spaces */
  3710.     ss = flit;            /* point to "\flit(" */
  3711.     while (*lp++ = *ss++) ;        /* copy it */
  3712.     lp--;                /* back up over null */
  3713.     while (*s) {            /* go thru rest of text */
  3714.         ss = flit;            /* point back to start of "\flit(" */
  3715.         if (*s == '{') bc++;    /* count brackets */
  3716.         if (*s == '(') pp++;    /* and parens */
  3717.         if (*s == ')') pp--;
  3718.         if (*s == '}') {        /* Closing brace. */
  3719.         if (--bc == 0) {    /* Final one? */
  3720.             *lp++ = ')';    /* Add closing paren for "\flit()" */
  3721.             *lp++ = *s++;
  3722.             break;
  3723.         }
  3724.         }
  3725.         if (*s == ',' && pp == 0) {    /* comma not inside of parens */
  3726.         *lp++ = ')';        /* closing ) of \flit( */
  3727.         *lp++ = ',';        /* insert the comma */
  3728.         while (*lp++ = *ss++) ;    /* start new "\flit(" */
  3729.         lp--;            /* back up over null */
  3730.         s++;            /* skip over comma in source string */
  3731.         while (*s++ == SP);    /* eat leading spaces again. */
  3732.         s--;            /* back up over nonspace */
  3733.         continue;
  3734.         }
  3735.             *lp++ = *s++;        /* Copy anything but comma here. */
  3736.         }
  3737.     *lp = NUL;
  3738.     } else {                /* No brackets around, */
  3739.     while (*lp++ = *s++) ;        /* just copy. */
  3740.     lp--;
  3741.     }
  3742.     *src = s;
  3743.     *dest = lp;
  3744.     if (bc) return(-1);
  3745.     else return(0);
  3746. }
  3747. #endif /* NOSPL */
  3748.  
  3749. int
  3750. docd() {                /* Do the CD command */
  3751.     int x;
  3752.     char *s;
  3753.  
  3754. #ifdef GEMDOS
  3755.     if ((x = cmdir("Name of local directory, or carriage return",homdir,&s,
  3756.            NULL)) < 0 )
  3757. #else
  3758.     if ((x = cmdir("Name of local directory, or carriage return",homdir,&s,
  3759.            xxstring)) < 0 )
  3760. #endif /* GEMDOS */
  3761.       return(x);
  3762.     if (x == 2) {
  3763.     printf("?Wildcards not allowed in directory name\n");
  3764.     return(-9);
  3765.     }
  3766.     strcpy(line,s);            /* Make a safe copy */
  3767.     s = line;
  3768.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  3769.       return(x);
  3770.     if (! zchdir(s)) {
  3771.     cwdf = 0;
  3772.     perror(s);
  3773.     } else cwdf = 1;
  3774. #ifdef OS2
  3775.     printf("%s\n", zgtdir());
  3776. #else /* Not OS2 */
  3777. #ifndef MAC
  3778.     zsyscmd(PWDCMD);            /* assume this works... */
  3779. #endif /* MAC */
  3780. #endif /* OS2 */
  3781.     return(cwdf);
  3782. }
  3783.  
  3784. VOID
  3785. fixcmd() {            /* Fix command parser after interruption */
  3786.     dostop();            /* Back to top level (also calls conint()). */
  3787.     bgchk();            /* Check background status */
  3788.     if (*psave) {        /* If old prompt saved, */
  3789.     cmsetp(psave);        /* restore it. */
  3790.     *psave = NUL;
  3791.     }
  3792.     success = 0;        /* Tell parser last command failed */
  3793. }
  3794.  
  3795. VOID
  3796. prtopt(s) char *s; {            /* Print an option */
  3797.     static int x = 0;            /* (used by SHOW VER) */
  3798.     int y;                /* Does word wrap. */
  3799.     if (!s) { x = 0; return; }        /* Call with null pointer to */
  3800.     y = (int)strlen(s);            /* reset horizontal position. */
  3801.     x += y;
  3802.     if (x > 79) {
  3803.     printf("\n%s",s);
  3804.     x = y;
  3805.     } else printf("%s",s);
  3806. }
  3807.  
  3808. #endif /* NOICP */
  3809.