home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv197.zip / ckuus5.c < prev    next >
C/C++ Source or Header  |  1999-12-30  |  282KB  |  9,858 lines

  1. #include "ckcsym.h"
  2.  
  3. #ifdef NOICP
  4. int cmdsrc() { return(0); }
  5. #endif /* NOICP */
  6.  
  7. #ifndef NOICP
  8.  
  9. /*  C K U U S 5 --  "User Interface" for C-Kermit, part 5  */
  10.  
  11. /*
  12.   Author: Frank da Cruz <fdc@columbia.edu>,
  13.   Columbia University Academic Information Systems, New York City.
  14.  
  15.   Copyright (C) 1985, 2000,
  16.     Trustees of Columbia University in the City of New York.
  17.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  18.     copyright text in the ckcmai.c module for disclaimer and permissions.
  19. */
  20.  
  21. /* Includes */
  22.  
  23. #include "ckcdeb.h"
  24. #include "ckcasc.h"
  25. #include "ckcker.h"
  26. #include "ckuusr.h"
  27. #include "ckcnet.h"
  28. #ifndef NOCSETS
  29. #include "ckcxla.h"
  30. #endif /* NOCSETS */
  31. #ifdef MAC
  32. #include "ckmasm.h"
  33. #endif /* MAC */
  34. #ifdef CK_SSL
  35. #include "ck_ssl.h"
  36. #endif /* CK_SSL */
  37.  
  38. #ifdef OS2
  39. #include "ckoetc.h"
  40. #ifndef NT
  41. #define INCL_NOPM
  42. #define INCL_VIO /* Needed for ckocon.h */
  43. #include <os2.h>
  44. #undef COMMENT
  45. #else /* NT */
  46. #include <windows.h>
  47. #define TAPI_CURRENT_VERSION 0x00010004
  48. #include <tapi.h>
  49. #include <mcx.h>
  50. #include "ckntap.h"
  51. #define APIRET ULONG
  52. extern int DialerHandle;
  53. extern int StartedFromDialer;
  54. #endif /* NT */
  55. #include "ckocon.h"
  56. #include "ckokey.h"
  57. #ifdef putchar
  58. #undef putchar
  59. #endif /* putchar */
  60. #define putchar(x) conoc(x)
  61. extern int cursor_save ;
  62. extern bool cursorena[] ;
  63. #endif /* OS2 */
  64.  
  65. /* For formatted screens, "more?" prompting, etc. */
  66.  
  67. #ifdef FT18
  68. #define isxdigit(c) isdigit(c)
  69. #endif /* FT18 */
  70.  
  71. #ifdef STRATUS                /* Stratus Computer, Inc.  VOS */
  72. #ifdef putchar
  73. #undef putchar
  74. #endif /* putchar */
  75. #define putchar(x) conoc(x)
  76. #ifdef getchar
  77. #undef getchar
  78. #endif /* getchar */
  79. #define getchar(x) coninc(0)
  80. #endif /* STRATUS */
  81.  
  82. /* External variables */
  83.  
  84. extern int carrier, cdtimo, local, quiet, backgrd, bgset, sosi, suspend,
  85.   binary, escape, xargs, flow, cmdmsk, duplex, ckxech, seslog, what,
  86.   inserver, diractive, tlevel, cwdf, nfuncs, msgflg, remappd, hints, mdmtyp,
  87.   zincnt, cmask, rcflag, success, xitsta, pflag, tnlm, tn_nlm, xitwarn,
  88.   debses, xaskmore, parity, saveask, wasclosed, whyclosed;
  89.  
  90. #ifdef CK_SPEED
  91. extern int prefixing;
  92. #endif /* CK_SPEED */
  93.  
  94. extern int g_matchdot;
  95.  
  96. #ifdef RECURSIVE
  97. extern int recursive;
  98. #endif /* RECURSIVE */
  99.  
  100. #ifdef IKSDCONF
  101. extern char * iksdconf;
  102. #endif /* IKSDCONF */
  103.  
  104. extern int ngetpath, exitonclose;
  105. extern char * getpath[];
  106. extern CHAR * epktmsg;
  107.  
  108. extern char * snd_move;
  109. extern char * snd_rename;
  110. extern char * rcv_move;
  111. extern char * rcv_rename;
  112. extern char * g_snd_move;
  113. extern char * g_snd_rename;
  114. extern char * g_rcv_move;
  115. extern char * g_rcv_rename;
  116.  
  117. extern char * nm[];
  118.  
  119. #ifdef CK_UTSNAME
  120. extern char unm_mch[];
  121. extern char unm_mod[];
  122. extern char unm_nam[];
  123. extern char unm_rel[];
  124. extern char unm_ver[];
  125. #endif /* CK_UTSNAME */
  126.  
  127. #ifndef NOPUSH
  128. #ifndef NOFRILLS
  129. extern char editor[];
  130. extern char editfile[];
  131. extern char editopts[];
  132. #ifdef BROWSER
  133. extern char browser[];
  134. extern char browsopts[];
  135. extern char browsurl[];
  136. #endif /* BROWSER */
  137. #endif /*  NOFRILLS */
  138. #endif /* NOPUSH */
  139.  
  140. #ifndef NOSERVER
  141. extern char * x_user, * x_passwd, * x_acct;
  142. #endif /* NOSERVER */
  143.  
  144. #ifdef CKLOGDIAL
  145. extern int dialog;
  146. extern char diafil[];
  147. #endif /* CKLOGDIAL */
  148.  
  149. #ifndef NOSPL
  150. extern int cfilef, xxdot;
  151. extern char cmdfil[];
  152.  
  153. struct localvar * localhead[CMDSTKL];
  154. struct localvar * localtail = NULL;
  155. struct localvar * localnext = NULL;
  156.  
  157. _PROTOTYP( static VOID shoinput, (void) );
  158. _PROTOTYP( static char gettok,   (void) );
  159. _PROTOTYP( static VOID factor,   (void) );
  160. _PROTOTYP( static VOID term,     (void) );
  161. _PROTOTYP( static VOID termp,    (void) );
  162. _PROTOTYP( static VOID exprp,    (void) );
  163. _PROTOTYP( static VOID expr,     (void) );
  164. _PROTOTYP( static VOID simple,   (void) );
  165. _PROTOTYP( static VOID simpler,  (void) );
  166. _PROTOTYP( static VOID simplest, (void) );
  167. _PROTOTYP( static long xparse,   (void) );
  168. #endif /* NOSPL */
  169.  
  170. #ifdef MAC
  171. char * ckprompt = "Mac-Kermit>";    /* Default prompt for Macintosh */
  172. char * ikprompt = "IKSD>";
  173. #else  /* Not MAC */
  174. #ifdef NOSPL
  175. #ifdef OS2
  176. char * ckprompt = "K-95> ";        /* Default prompt for Win32 */
  177. char * ikprompt = "IKSD> ";
  178. #else
  179. char * ckprompt = "C-Kermit>";
  180. char * ikprompt = "IKSD>";
  181. #endif /* NT */
  182. #else  /* NOSPL */
  183. #ifdef OS2
  184. /* Default prompt for OS/2 and Win32 */
  185. char * ckprompt = "[\\freplace(\\v(dir),/,\\\\)] K-95> ";
  186. char * ikprompt = "[\\freplace(\\v(dir),/,\\\\)] IKSD> ";
  187. #else
  188. #ifdef VMS
  189. char * ckprompt = "\\v(dir) C-Kermit>";    /* Default prompt VMS */
  190. char * ikprompt = "\\v(dir) IKSD>";
  191. #else
  192. char * ckprompt = "(\\v(dir)) C-Kermit>"; /* Default prompt for others */
  193. char * ikprompt = "(\\v(dir)) IKSD>";
  194. #endif /* VMS */
  195. #endif /* NT */
  196. #endif /* NOSPL */
  197. #endif /* MAC */
  198.  
  199. #ifndef CCHMAXPATH
  200. #define CCHMAXPATH 257
  201. #endif /* CCHMAXPATH */
  202. char inidir[CCHMAXPATH] = { NUL, NUL };    /* Directory INI file executed from */
  203.  
  204. #ifdef TNCODE
  205. extern int tn_b_nlm;            /* TELNET BINARY newline mode */
  206. #endif /* TNCODE */
  207.  
  208. #ifndef NOKVERBS
  209. extern struct keytab kverbs[];        /* Table of \Kverbs */
  210. extern int nkverbs;            /* Number of \Kverbs */
  211. #endif /* NOKVERBS */
  212.  
  213. #ifndef NOPUSH
  214. extern int nopush;
  215. #endif /* NOPUSH */
  216.  
  217. #ifdef CK_RECALL
  218. extern int cm_recall;
  219. #endif /* CK_RECALL */
  220.  
  221. extern char *ccntab[];
  222.  
  223. /* Printer stuff */
  224.  
  225. extern char *printername;
  226. extern int printpipe;
  227. #ifdef BPRINT
  228. extern int printbidi, pportparity, pportflow;
  229. extern long pportspeed;
  230. #endif /* BPRINT */
  231.  
  232. #ifdef OS2
  233. _PROTOTYP (int os2getcp, (void) );
  234. _PROTOTYP (int os2getcplist, (int *, int) );
  235. #ifdef OS2MOUSE
  236. extern int tt_mouse;
  237. #endif /* OS2MOUSE */
  238. extern int tt_update, tt_updmode, tt_font, updmode;
  239. extern struct keytab termfont[];
  240. extern int ntermfont;
  241. extern unsigned char colornormal, colorunderline, colorstatus,
  242.     colorhelp, colorselect, colorborder, colorgraphic, colordebug,
  243.     colorreverse, colorcmd;
  244. extern int priority;
  245. extern struct keytab prtytab[];
  246. extern int nprty;
  247. char * cmdmac = NULL;
  248. #endif /* OS2 */
  249.  
  250. #ifdef VMS
  251. _PROTOTYP (int zkermini, (char *, int, char *) );
  252. #endif /* VMS */
  253.  
  254. extern long vernum;
  255. extern int inecho, insilence, inbufsize, nvars, inintr;
  256. extern char *protv, *fnsv, *cmdv, *userv, *ckxv, *ckzv, *ckzsys, *xlav,
  257.  *cknetv, *clcmds;
  258. #ifdef CK_AUTHENTICATION
  259. extern char * ckathv;
  260. #endif /* CK_AUTHENTICATION */
  261. #ifdef CK_SSL
  262. extern char * cksslv;
  263. #endif /* CK_SSL */
  264. #ifdef CK_ENCRYPTION
  265. #ifndef CRYPT_DLL
  266. extern char * ckcrpv;
  267. #endif /* CRYPT_DLL */
  268. #endif /* CK_ENCRYPTION */
  269.  
  270. #ifdef TNCODE
  271. extern char *cktelv;
  272. #endif /* TNCODE */
  273.  
  274. extern int srvidl;
  275.  
  276. #ifdef OS2
  277. extern char *ckonetv;
  278. extern int interm;
  279. #ifdef CK_NETBIOS
  280. extern char *ckonbiv;
  281. #endif /* CK_NETBIOS */
  282. #ifdef OS2MOUSE
  283. extern char *ckomouv;
  284. #endif /* OS2MOUSE */
  285. #endif /* OS2 */
  286.  
  287. #ifndef NOLOCAL
  288. extern char *connv;
  289. #endif /* NOLOCAL */
  290. #ifndef NODIAL
  291. extern char *dialv;
  292. #endif /* NODIAL */
  293. #ifndef NOSCRIPT
  294. extern char *loginv;
  295. extern int secho;
  296. #endif /* NOSCRIPT */
  297.  
  298. #ifndef NODIAL
  299. extern int nmdm, dirline;
  300. extern struct keytab mdmtab[];
  301. #endif /* NODIAL */
  302.  
  303. extern int network, ttnproto;
  304.  
  305. #ifdef OS2
  306. /* SET TERMINAL items... */
  307. extern int tt_type, tt_arrow, tt_keypad, tt_wrap, tt_answer, tt_scrsize[];
  308. extern int tt_bell, tt_roll[], tt_ctstmo, tt_cursor, tt_pacing, tt_type_mode;
  309. extern char answerback[];
  310. extern struct tt_info_rec tt_info[];    /* Indexed by terminal type */
  311. extern int max_tt;
  312. #endif /* OS2 */
  313.  
  314. _PROTOTYP( VOID shotrm, (void) );
  315. _PROTOTYP( int shofea, (void) );
  316.  
  317. #ifdef OS2
  318. extern int tt_rows[], tt_cols[];
  319. #else /* OS2 */
  320. extern int tt_rows, tt_cols;
  321. #endif /* OS2 */
  322. extern int cmd_rows, cmd_cols;
  323.  
  324. #ifdef CK_TMPDIR
  325. extern int f_tmpdir;            /* Directory changed temporarily */
  326. extern char savdir[];            /* Temporary directory */
  327. #endif /* CK_TMPDIR */
  328.  
  329. #ifndef NOLOCAL
  330. extern int tt_crd, tt_escape;
  331. #endif /* NOLOCAL */
  332.  
  333. #ifndef NOCSETS
  334. extern int language, nfilc, tcsr, tcsl, tcs_transp, fcharset;
  335. extern struct keytab fcstab[];
  336. extern struct csinfo fcsinfo[];
  337. #ifndef MAC
  338. extern struct keytab ttcstab[];
  339. #endif /* MAC */
  340. #endif /* NOCSETS */
  341.  
  342. extern long speed;
  343.  
  344. #ifndef NOXMIT
  345. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  346. extern char xmitbuf[];
  347. #endif /* NOXMIT */
  348.  
  349. extern char **xargv, *versio, *ckxsys, *dftty, *lp;
  350.  
  351. #ifdef DCMDBUF
  352. extern char *cmdbuf, *atmbuf;        /* Command buffers */
  353. #ifndef NOSPL
  354. extern char *savbuf;            /* Command buffers */
  355. #endif /* NOSPL */
  356. #else
  357. extern char cmdbuf[], atmbuf[];        /* Command buffers */
  358. #ifndef NOSPL
  359. extern char savbuf[];            /* Command buffers */
  360. #endif /* NOSPL */
  361. #endif /* DCMDBUF */
  362.  
  363. extern char toktab[], ttname[], psave[];
  364. extern CHAR sstate, feol;
  365. extern int cmflgs, techo, repars, ncmd;
  366. extern struct keytab cmdtab[];
  367.  
  368. #ifndef NOSETKEY
  369. KEY *keymap;
  370. #ifndef OS2
  371. #define mapkey(x) keymap[x]
  372. #endif /* OS2 */
  373. MACRO *macrotab;
  374. _PROTOTYP( VOID shostrdef, (CHAR *) );
  375. #endif /* NOSETKEY */
  376.  
  377. extern int cmdlvl;
  378.  
  379. #ifndef NOSPL
  380. extern struct mtab *mactab;
  381. extern struct keytab mackey[];
  382. extern struct keytab vartab[], fnctab[];
  383. extern int maclvl, nmac, mecho, fndiags, fnerror, fnsuccess;
  384. #endif /* NOSPL */
  385.  
  386. FILE *tfile[MAXTAKE];            /* TAKE file stack */
  387. char *tfnam[MAXTAKE];
  388. int tfline[MAXTAKE];
  389.  
  390. int topcmd = -1;            /* cmdtab index of current command */
  391.  
  392. #ifdef DCMDBUF                /* Initialization filespec */
  393. char *kermrc = NULL;
  394. #else
  395. char kermrcb[KERMRCL];
  396. char *kermrc = kermrcb;
  397. #endif /* DCMDBUF */
  398.  
  399. int noherald = 0;
  400. int cm_retry = 1;            /* Command retry enabled */
  401. xx_strp xxstring = zzstring;
  402.  
  403. #ifndef NOXFER
  404. extern int displa, bye_active, protocol, pktlog, remfile, rempipe, unkcs,
  405.   keep, lf_opts, fncnv, pktpaus, autodl, xfrcan, xfrchr, xfrnum, srvtim,
  406.   srvdis, query, retrans, streamed, reliable, crunched, timeouts,
  407.   fnrpath, autopath, rpackets, spackets, epktrcvd, srvping;
  408.  
  409. #ifdef CK_AUTODL
  410. extern int inautodl, cmdadl;
  411. #endif /* CK_AUTODL */
  412.  
  413. #ifndef NOSERVER
  414. extern int en_asg, en_cwd, en_cpy, en_del, en_dir, en_fin, en_bye, en_ret,
  415.   en_get, en_hos, en_que, en_ren, en_sen, en_set, en_spa, en_typ, en_who,
  416.   en_mai, en_pri, en_mkd, en_rmd, en_xit, en_ena;
  417. #endif /* NOSERVER */
  418.  
  419. extern int atcapr,
  420.   atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,
  421.   attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  422.  
  423. #ifdef STRATUS
  424. extern int atfrmi, atfrmo, atcrei, atcreo, atacti, atacto;
  425. #endif /* STRATUS */
  426.  
  427. #ifdef CK_PERMS
  428. extern int atlpri, atlpro, atgpri, atgpro;
  429. #endif /* CK_PERMS */
  430.  
  431. #ifdef CK_LOGIN
  432. extern char * anonfile;            /* Anonymous login init file */
  433. extern char * anonroot;            /* Anonymous file-system root */
  434. extern char * userfile;                 /* Forbidden user file */
  435. extern int isguest;            /* Flag for anonymous user */
  436. #endif /* CK_LOGIN */
  437. #endif /* NOXFER */
  438.  
  439. #ifdef DCMDBUF
  440. int *xquiet = NULL;
  441. #else
  442. int xquiet[CMDSTKL];
  443. #endif /* DCMDBUF */
  444.  
  445. #ifndef NOSPL
  446.  
  447. extern long ck_alarm;
  448. extern char alrm_date[], alrm_time[];
  449.  
  450. /* Local declarations */
  451.  
  452. static int nulcmd = 0;            /* Flag for next cmd to be ignored */
  453.  
  454. /* Definitions for predefined macros */
  455.  
  456. /* First, the single-line macros, installed with addmac()... */
  457.  
  458. /* IBM-LINEMODE macro */
  459. char *m_ibm = "set parity mark, set dupl half, set handsh xon, set flow none";
  460.  
  461. /* FATAL macro */
  462. char *m_fat = "if def \\%1 echo \\%1, if not = \\v(local) 0 hangup, stop 1";
  463.  
  464. #ifdef CK_SPEED
  465. #ifdef IRIX65
  466. char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
  467. #else
  468. #ifdef IRIX
  469. /* Because of bug in telnet server */
  470. char *m_fast = "set window 30, set rec pack 4000, set send pack 4000,\
  471.  set pref cautious";
  472. #else
  473. #ifdef pdp11
  474. char *m_fast = "set win 3, set rec pack 1024, set prefix cautious";
  475. #else
  476. #ifdef BIGBUFOK
  477. char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
  478. #else
  479. char *m_fast = "set win 4, set rec pack 2200, set prefix cautious";
  480. #endif /* BIGBUFOK */
  481. #endif /* IRIX */
  482. #endif /* IRIX65 */
  483. #endif /* pdp11 */
  484. #ifdef pdp11
  485. char *m_cautious = "set win 2, set rec pack 512, set prefixing cautious";
  486. #else
  487. char *m_cautious = "set win 4, set rec pack 1000, set prefixing cautious";
  488. #endif /* pdp11 */
  489. char *m_robust = "set win 1, set rec pack 90, set prefixing all, \
  490. set reliable off, set clearchannel off";
  491. #else
  492. #ifdef BIGBUFOK
  493. #ifdef IRIX65
  494. char *m_fast = "set win 30, set rec pack 4000";
  495. #else
  496. #ifdef IRIX
  497. char *m_fast = "set win 30, set rec pack 4000, set send pack 4000";
  498. #else
  499. char *m_fast = "set win 30, set rec pack 4000";
  500. #endif /* IRIX */
  501. #endif /* IRIX65 */
  502. #else /* Not BIGBUFOK */
  503. char *m_fast = "set win 4, set rec pack 2200";
  504. #endif /* BIGBUFOK */
  505. char *m_cautious = "set win 4, set rec pack 1000";
  506. char *m_robust = "set win 1, set rec pack 90, set reliable off";
  507. #endif /* CK_SPEED */
  508.  
  509. #ifdef VMS
  510. char *m_purge = "run purge \\%*";
  511. #endif /* VMS */
  512.  
  513. #ifdef OS2
  514. char *m_manual = "browse \\v(exedir)docs/manual/kermit95.htm";
  515. #endif /* OS2 */
  516.  
  517. /* Now the multiline macros, defined with addmmac()... */
  518.  
  519. /* FOR macro */
  520. char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
  521. "define \\\\\\%1 \\feval(\\%2),:_..top,if \\%5 \\\\\\%1 \\%3 goto _..bot,",
  522. "\\%6,:_..inc,incr \\\\\\%1 \\%4,goto _..top,:_..bot,_putargs},",
  523. "def break goto _..bot, def continue goto _..inc,",
  524. "do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
  525. ""};
  526.  
  527. /* WHILE macro */
  528. char *whil_def[] = { "_assign _whi\\v(cmdlevel) {_getargs,",
  529. ":_..inc,\\%1,\\%2,goto _..inc,:_..bot,_putargs},",
  530. "_def break goto _..bot, _def continue goto _..inc,",
  531. "do _whi\\v(cmdlevel),_assign _whi\\v(cmdlevel)",
  532. ""};
  533.  
  534. /* SWITCH macro */
  535. char *sw_def[] = { "_assign _sw_\\v(cmdlevel) {_getargs,",
  536. "_forward \\%1,\\%2,:default,:_..bot,_putargs},_def break goto _..bot,",
  537. "do _sw_\\v(cmdlevel),_assign _sw_\\v(cmdlevel)",
  538. ""};
  539.  
  540. /* XIF macro */
  541. char *xif_def[] = {
  542. "_assign _if\\v(cmdlevel) {_getargs,\\%1,_putargs},",
  543. "do _if\\v(cmdlevel),_assign _if\\v(cmdlevel)",
  544. ""};
  545.  
  546. /*
  547.   Variables declared here for use by other ckuus*.c modules.
  548.   Space is allocated here to save room in ckuusr.c.
  549. */
  550. #ifdef DCMDBUF
  551. struct cmdptr *cmdstk;
  552. int
  553.   *ifcmd  = NULL,
  554.   *count  = NULL,
  555.   *iftest = NULL,
  556.   *intime = NULL,
  557.   *inpcas = NULL,
  558.   *takerr = NULL,
  559.   *merror = NULL;
  560. #else
  561. struct cmdptr cmdstk[CMDSTKL];
  562. int ifcmd[CMDSTKL], count[CMDSTKL], iftest[CMDSTKL], intime[CMDSTKL],
  563.   inpcas[CMDSTKL], takerr[CMDSTKL], merror[CMDSTKL];
  564. #endif /* DCMDBUF */
  565.  
  566. /* Macro stack */
  567.  
  568. char *m_line[MACLEVEL] = { NULL, NULL }; /* Stack of macro invocation lines */
  569. char **m_xarg[MACLEVEL];        /* Pointers to arg vector arrays */
  570. int n_xarg[MACLEVEL];            /* Sizes of arg vector arrays */
  571. char *m_arg[MACLEVEL][NARGS];        /* Args of each level */
  572. int macargc[MACLEVEL];            /* Argc of each level */
  573. char *macp[MACLEVEL];            /* Current position in each macro */
  574. char *macx[MACLEVEL];            /* Beginning of each macro def */
  575. char *mrval[MACLEVEL];            /* RETURN value at each level */
  576. int topargc = 0;            /* Argc at top level */
  577. char **topxarg = NULL;            /* Argv at top level */
  578. char *toparg[MAXARGLIST+2];
  579.  
  580. /* Global Variables */
  581.  
  582. char *g_var[GVARS];            /* Global \%a..z pointers */
  583. extern char varnam[];            /* \%x variable name buffer */
  584.  
  585. /* Arrays -- Dimension must be 'z' - ARRAYBASE + 1 */
  586.  
  587. char **a_ptr[28];            /* Array pointers, for arrays a-z */
  588. int a_dim[28];                /* Dimensions for each array */
  589.  
  590. char **aa_ptr[CMDSTKL][28];        /* Array stack for automatic arrays */
  591. int aa_dim[CMDSTKL][28];        /* Dimensions for each array */
  592.  
  593. /* INPUT command buffers and variables */
  594.  
  595. char * inpbuf = NULL;            /* Buffer for INPUT and REINPUT */
  596. extern char * inpbp;            /* Global/static pointer to it  */
  597. char inchar[2] = { NUL, NUL };        /* Last character that was INPUT */
  598. int  incount = 0;            /* INPUT character count */
  599. extern int instatus;            /* INPUT status */
  600. static char * i_text[] = {        /* INPUT status text */
  601.     "success", "timeout", "interrupted", "internal error", "i/o error"
  602. };
  603.  
  604. char lblbuf[LBLSIZ];            /* Buffer for labels */
  605.  
  606. #else  /* NOSPL */
  607.  
  608. int takerr[MAXTAKE];
  609. #endif /* NOSPL */
  610.  
  611. static char *prevdir = NULL;
  612.  
  613. int pacing = 0;                /* OUTPUT pacing */
  614.  
  615. #ifdef DCMDBUF
  616. char *line;                /* Character buffer for anything */
  617. char *tmpbuf;
  618. #else
  619. char line[LINBUFSIZ+1];
  620. char tmpbuf[TMPBUFSIZ+1];        /* Temporary buffer */
  621. #endif /* DCMDBUF */
  622. char *tp;                /* Temporary buffer pointer */
  623.  
  624. int timelimit = 0, asktimer = 0;    /* Timers for time-limited commands */
  625.  
  626. #ifdef CK_APC                /* Application Program Command (APC) */
  627. int apcactive = APC_INACTIVE;
  628. int apcstatus = APC_OFF;        /* OFF by default everywhere */
  629. #ifdef DCMDBUF
  630. char *apcbuf;
  631. #else
  632. char apcbuf[APCBUFLEN];
  633. #endif /* DCMDBUF */
  634. #endif /* CK_APC */
  635.  
  636. extern char pktfil[],
  637. #ifdef DEBUG
  638.   debfil[],
  639. #endif /* DEBUG */
  640. #ifdef TLOG
  641.   trafil[],
  642. #endif /* TLOG */
  643.   sesfil[];
  644.  
  645. #ifndef NOFRILLS
  646. extern int rmailf, rprintf;        /* REMOTE MAIL & PRINT items */
  647. extern char optbuf[];
  648. #endif /* NOFRILLS */
  649.  
  650. char *homdir = "";            /* Pointer to home directory string */
  651.  
  652. char numbuf[20];            /* Buffer for numeric strings. */
  653. extern int noinit;
  654.  
  655. #ifndef NOSPL
  656. _PROTOTYP( VOID freelocal, (int) );
  657. _PROTOTYP( static long expon, (long, long) );
  658. _PROTOTYP( static long gcd, (long, long) );
  659. _PROTOTYP( static long fact, (long) );
  660.  
  661. int            /* Initialize macro data structures. */
  662. macini() {        /* Allocate mactab and preset the first element. */
  663.     int i;
  664.     if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX)))
  665.       return(-1);
  666.     mactab[0].kwd = NULL;
  667.     mactab[0].mval = NULL;
  668.     mactab[0].flgs = 0;
  669.     for (i = 0; i < MACLEVEL; i++)
  670.       localhead[i] = NULL;
  671.     return(0);
  672. }
  673. #endif /* NOSPL */
  674.  
  675. /*  C M D S R C  --  Returns current command source  */
  676.  
  677. /*  0 = top level, 1 = file, 2 = macro, -1 = error (shouldn't happen) */
  678.  
  679. int
  680. cmdsrc() {
  681. #ifndef NOSPL
  682.     if (cmdlvl == 0)
  683.       return(0);
  684.     else if (cmdstk[cmdlvl].src == CMD_MD)
  685.       return(2);
  686.     else if (cmdstk[cmdlvl].src == CMD_TF)
  687.       return(1);
  688.     else
  689.       return(-1);
  690. #else
  691.     if (tlevel < 0)
  692.       return(0);
  693.     else
  694.       return(1);
  695. #endif /* NOSPL */
  696. }
  697.  
  698. /*  C M D I N I  --  Initialize the interactive command parser  */
  699.  
  700. static int cmdinited = 0;        /* Command parser initialized */
  701. extern int cmdint;            /* Interrupts are allowed */
  702. #ifdef CK_AUTODL
  703. int cmdadl = 1;                /* Autodownload */
  704. #else
  705. int cmdadl = 0;
  706. #endif /* CK_AUTODL */
  707.  
  708. char * k_info_dir = NULL;        /* Where to find text files */
  709. #ifdef UNIX
  710. static char * txtdir[] = {
  711.     "/usr/local/doc/",            /* Linux, SunOS, ... */
  712.     "/usr/share/lib/",            /* HP-UX 10.xx... */
  713.     "/usr/share/doc/",            /* Other possibilities... */
  714.     "/usr/local/lib/",            /* NOTE: Each of these is tried */
  715.     "/usr/local/share/",        /* as is, and also with a kermit */
  716.     "/usr/local/share/doc/",        /* subdirectory. */
  717.     "/usr/local/share/lib/",
  718.     "/usr/doc/",
  719.     "/opt/",
  720.     "/doc/",
  721.     ""
  722. };
  723. #endif /* UNIX */
  724.  
  725. VOID
  726. cmdini() {
  727.     int i = 0, x = 0, y = 0, z = 0, skip = 0;
  728.     char * p;
  729. #ifdef TTSPDLIST
  730.     long * ss = NULL;
  731.     extern int nspd;
  732.     extern struct keytab * spdtab;
  733. #endif /* TTSPDLIST */
  734.  
  735. #ifndef NOSPL
  736. /*
  737.   On stack to allow recursion!
  738. */
  739.     char vnambuf[VNAML];        /* Buffer for variable names */
  740. #endif /* NOSPL */
  741.  
  742.     if (cmdinited)            /* Already initialized */
  743.       return;                /* Don't do it again */
  744.  
  745.     p = getenv("K_INFO_DIRECTORY");
  746.     if (p && *p && strlen(p) <= CKMAXPATH)
  747.       makestr(&k_info_dir,p);
  748.     if (!k_info_dir) {
  749.         p = getenv("K_INFO_DIR");
  750.         if (p && *p && strlen(p) <= CKMAXPATH)
  751.       makestr(&k_info_dir,p);
  752.     }
  753. #ifdef UNIX
  754.     if (k_info_dir) {            /* Look for Kermit docs directory */
  755.     if (zchki(k_info_dir) == -2) {
  756.         char xbuf[CKMAXPATH+32], *s = "";
  757.         if (ckrchar(k_info_dir) != '/')
  758.           s = "/";
  759.         sprintf(xbuf,"%s%sckermit2.txt",k_info_dir,s);
  760.         if (zchki(xbuf) < 0)
  761.           makestr(&k_info_dir,NULL);
  762.     }
  763.     }
  764.     if (!k_info_dir) {
  765.     char xbuf[CKMAXPATH+32];
  766.     int i;
  767.     for (i = 0; *(txtdir[i]); i++) {
  768.         sprintf(xbuf,"%s%s",txtdir[i],"ckermit2.txt");
  769.         if (zchki(xbuf) > 0) {
  770.         makestr(&k_info_dir,txtdir[i]);
  771.         debug(F110,"k_info_dir 1",k_info_dir,0);
  772.         break;
  773.         }
  774.         sprintf(xbuf,"%skermit/%s",txtdir[i],"ckermit2.txt");
  775.         if (zchki(xbuf) > 0) {
  776.         sprintf(xbuf,"%skermit/",txtdir[i]);
  777.         makestr(&k_info_dir,xbuf);
  778.         debug(F110,"k_info_dir 2",k_info_dir,0);
  779.         break;
  780.         }
  781.     }
  782.     if (k_info_dir) {        /* Make sure it ends with "/" */
  783.         if (ckrchar(k_info_dir) != '/') {
  784.         char xbuf[CKMAXPATH+32];
  785.         sprintf(xbuf,"%s/",k_info_dir);
  786.         makestr(&k_info_dir,xbuf);
  787.         }
  788.     }
  789.     }
  790. #else
  791. #ifdef OS2
  792.     {
  793.     char xdir[CKMAXPATH+8], *s = "";
  794.         extern char startupdir[];
  795.     xdir[0] = NUL;
  796.     if (ckrchar(startupdir) != '/')
  797.       s = "/";
  798.         if (strlen(s) + strlen(startupdir) + 5 < CKMAXPATH + 8 )
  799.       sprintf(xdir,"%s%sDOC/",s,startupdir);
  800.         makestr(&k_info_dir,xdir);
  801.     }
  802. #endif /* OS2 */
  803. #endif /* UNIX */
  804.  
  805. #ifdef TTSPDLIST
  806.     if (!spdtab && (ss = ttspdlist())) { /* Get speed list if necessary */
  807.     int j, k, m = 0, n;        /* Create sorted keyword table */
  808.     char buf[16];
  809.     char * p;
  810.     if ((spdtab =
  811.          (struct keytab *) malloc(sizeof(struct keytab) * ss[0]))) {
  812.         for (i = 1; i <= ss[0]; i++) { /* ss[0] = number of elements */
  813.         if (ss[i] < 1L) break;       /* Shouldn't happen */
  814.         buf[0] = NUL;           /* Make string */
  815.         sprintf(buf,"%ld",ss[i]);
  816.         if (ss[i] == 8880L)
  817.           strcpy(buf,"75/1200");
  818.         if (ss[i] == 134L)
  819.           strcat(buf,".5");
  820.         n = strlen(buf);
  821.         if ((n > 0) && (p = (char *)malloc(n+1))) {
  822.             if (m > 0) {    /* Have at least one in list */
  823.             for (j = 0;    /* Find slot */
  824.                  j < m && strcmp(buf,spdtab[j].kwd) > 0;
  825.                  j++
  826.                  )
  827.               ;
  828.             if (j < m) {    /* Must insert */
  829.                 for (k = m-1; k >= j; k--) { /* Move others down */
  830.                 spdtab[k+1].kwd = spdtab[k].kwd;
  831.                 spdtab[k+1].flgs = spdtab[k].flgs;
  832.                 spdtab[k+1].kwval = spdtab[k].kwval;
  833.                 }
  834.             }
  835.             } else        /* First one */
  836.               j = 0;
  837.             strcpy(p,buf);    /* Add new speed */
  838.             spdtab[j].kwd = p;
  839.             spdtab[j].flgs = 0;
  840.             spdtab[j].kwval = (int) ss[i] / 10;
  841.             m++;        /* Count this one */
  842.         }
  843.         }
  844.     }
  845.     nspd = m;
  846.     }
  847. #endif /* TTSPDLIST */
  848.  
  849. #ifndef NOSPL
  850.     /* Allocate INPUT command buffer */
  851.     if (!inpbuf) {
  852.     if (!(inpbuf = (char *) malloc(INPBUFSIZ+1)))
  853.       fatal("cmdini: no memory for INPUT buffer");
  854.     }
  855.     for (x = 0; x < INPBUFSIZ; x++)    /* Initialize it */
  856.       inpbuf[x] = NUL;
  857.     inpbp = inpbuf;            /* Initialize pointer */
  858.     inbufsize = INPBUFSIZ;        /* and size. */
  859. #endif /* NOSPL */
  860.  
  861. #ifdef DCMDBUF
  862.     if (cmsetup() < 0) fatal("Can't allocate command buffers!");
  863.  
  864. #ifndef NOSPL
  865.     /* Allocate command stack allowing command parser to call itself */
  866.  
  867.     if (!(cmdstk = (struct cmdptr *) malloc(sizeof(struct cmdptr)*CMDSTKL)))
  868.       fatal("cmdini: no memory for cmdstk");
  869.     if (!(ifcmd = (int *) malloc(sizeof(int)*CMDSTKL)))
  870.       fatal("cmdini: no memory for ifcmd");
  871.     if (!(count = (int *) malloc(sizeof(int)*CMDSTKL)))
  872.       fatal("cmdini: no memory for count");
  873.     if (!(iftest = (int *) malloc(sizeof(int)*CMDSTKL)))
  874.       fatal("cmdini: no memory for iftest");
  875.     if (!(intime = (int *) malloc(sizeof(int)*CMDSTKL)))
  876.       fatal("cmdini: no memory for intime");
  877.     if (!(inpcas = (int *) malloc(sizeof(int)*CMDSTKL)))
  878.       fatal("cmdini: no memory for inpcas");
  879.     if (!(takerr = (int *) malloc(sizeof(int)*CMDSTKL)))
  880.       fatal("cmdini: no memory for takerr");
  881.     if (!(merror = (int *) malloc(sizeof(int)*CMDSTKL)))
  882.       fatal("cmdini: no memory for merror");
  883.     if (!(xquiet = (int *) malloc(sizeof(int)*CMDSTKL)))
  884.       fatal("cmdini: no memory for xquiet");
  885.     if (!kermrc)
  886.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  887.     fatal("cmdini: no memory for kermrc");
  888. #ifdef CK_APC
  889. /* Application Program Command buffer */
  890.     if (!(apcbuf = malloc(APCBUFLEN + 1)))
  891.     fatal("cmdini: no memory for apcbuf");
  892. #endif /* CK_APC */
  893. #endif /* NOSPL */
  894.  
  895. /* line[] and tmpbuf[] are the two string buffers used by the command parser */
  896.  
  897.     if (!(line = malloc(LINBUFSIZ + 1)))
  898.     fatal("cmdini: no memory for line");
  899.     if (!(tmpbuf = malloc(LINBUFSIZ + 1)))
  900.     fatal("cmdini: no memory for tmpbuf");
  901. #endif /* DCMDBUF */
  902.  
  903. #ifndef NOSPL
  904. #ifdef CK_MINPUT
  905.     {                    /* Initialize MINPUT pointers */
  906.     int i;
  907.     extern char *ms[];
  908.     for (i = 0; i < MINPMAX; i++)
  909.       ms[i] = NULL;
  910.     }
  911. #endif /* CK_MINPUT */
  912.  
  913.     if (macini() < 0)            /* Allocate macro buffers */
  914.       fatal("Can't allocate macro buffers!");
  915.  
  916.     ifcmd[0] = 0;            /* Command-level related variables. */
  917.     iftest[0] = 0;            /* Initialize variables at top level */
  918.     count[0] = 0;            /* of stack... */
  919.     intime[0] = 0;
  920.     inpcas[0] = 0;
  921.     takerr[0] = 0;
  922.     merror[0] = 0;
  923.     xquiet[0] = quiet;
  924. #endif /* NOSPL */
  925.  
  926. #ifndef NOSPL
  927.     cmdlvl = 0;                /* Initialize the command stack */
  928.     cmdstk[cmdlvl].src = CMD_KB;    /* Source is console */
  929.     cmdstk[cmdlvl].lvl = 0;        /* Level is 0 */
  930.     cmdstk[cmdlvl].ccflgs = 0;        /* No flags */
  931. #endif /* NOSPL */
  932.  
  933.     tlevel = -1;            /* Take file level = keyboard */
  934.     for (i = 0; i < MAXTAKE; i++)    /* Initialize command file names */
  935.       tfnam[i] = NULL;
  936.  
  937.     cmsetp(ckprompt);             /* Set up C-Kermit's prompt */
  938.                                         /* Can't set IKSD prompt here since */
  939.                                         /* we do not yet know if we are IKSD */
  940. #ifndef NOSPL
  941.  
  942.     initmac();                /* Initialize macro table */
  943.  
  944. /* Predefine built-in one-line macros */
  945.  
  946.     addmac("ibm-linemode",m_ibm);    /* IBM-LINEMODE */
  947.     addmac("fatal",m_fat);        /* FATAL macro */
  948.     y = addmac("fast",m_fast);        /* FAST macro */
  949.     addmac("cautious",m_cautious);    /* CAUTIOUS macro */
  950.     addmac("robust",m_robust);        /* ROBUST macro */
  951. #ifdef OS2
  952.     addmac("manual",m_manual);          /* MANUAL macro */
  953. #endif /* OS2 */
  954. #ifdef VMS
  955.     addmac("purge",m_purge);        /* PURGE macro */
  956. #endif /* VMS */
  957.  
  958. /*
  959.   Predefine built-in multiline macros; these are top-level commands
  960.   that are implemented internally as macros.  NOTE: When adding a new
  961.   one of these, remember to update the END and RETURN commands to
  962.   account for it, or else END and RETURN from within it won't work right.
  963. */
  964.     x = addmmac("_forx",for_def);    /* FOR macro */
  965.     if (x > -1) mactab[x].flgs = CM_INV;
  966.     x = addmmac("_xif",xif_def);    /* XIF macro */
  967.     if (x > -1) mactab[x].flgs = CM_INV;
  968.     x = addmmac("_while",whil_def);    /* WHILE macro */
  969.     if (x > -1) mactab[x].flgs = CM_INV;
  970.     x = addmmac("_switx",sw_def);    /* SWITCH macro */
  971.     if (x > -1) mactab[x].flgs = CM_INV;
  972.  
  973. /* Fill in command-line argument vector */
  974.  
  975.     sprintf(vnambuf,"\\&@[%d]",xargs);     /* Command line argument vector */
  976.     if (inserver) {            /* (except in IKSD) */
  977.     y = -1;
  978.     xargs = 0;
  979.     } else
  980.       y = arraynam(vnambuf,&x,&z);    /* goes in array \&@[] */
  981.  
  982.     if (y > -1) {
  983.     int j = -1;
  984.     int yy = 0;
  985.     dclarray((char)x,z);        /* Declare the array */
  986. #ifndef NOTAKEARGS
  987.     sprintf(vnambuf,"\\&_[%d]",z);     /* Macro argument vector */
  988.     yy = arraynam(vnambuf,&x,&z);    /* goes in array \&_[] */
  989.     if (yy > -1)            /* Name is OK */
  990.       dclarray((char)x,z);        /* Declare the array */
  991. #endif /* NOTAKEARGS */
  992.     skip = 0;
  993.     for (i = 0; i < xargs; i++) {    /* Fill the arrays */
  994.         sprintf(vnambuf,"\\&@[%d]",i);
  995.         addmac(vnambuf,xargv[i]);
  996.         if (cfilef && i == 0)
  997.           continue;
  998. #ifdef KERBANG
  999.         if (skip) {
  1000.         j = 0;
  1001.         skip = 0;
  1002.         continue;
  1003.         }
  1004. #endif /* KERBANG */
  1005.         if (j < 0 &&        /* Assign items after "=" or "--"*/
  1006.         (!strcmp(xargv[i],"=") || !strcmp(xargv[i],"--"))
  1007.         ) {
  1008.         j = 0;            /* to \%1..\%9 */
  1009. #ifdef KERBANG
  1010.         } else if (j < 0 && !strcmp(xargv[i],"+")) {
  1011.         skip = 1;
  1012.         continue;
  1013. #endif /* KERBANG */
  1014.         } else if (j > -1) {
  1015.         j++;
  1016.         if (j <= 9) {
  1017.             vnambuf[0] = '\\';
  1018.             vnambuf[1] = '%';
  1019.             vnambuf[2] = (char)(j+'0');
  1020.             vnambuf[3] = NUL;
  1021.             addmac(vnambuf,xargv[i]);
  1022.         }
  1023.         if (yy > -1)
  1024.           makestr(&(toparg[j]),xargv[i]);
  1025.         }
  1026.     }
  1027.     if (cfilef) {
  1028.         addmac("\\%0",cmdfil);
  1029.         if (yy > -1)
  1030.           makestr(&(toparg[0]),cmdfil);
  1031.     } else {
  1032.         addmac("\\%0",xargv[0]);
  1033.         if (yy > -1)
  1034.           makestr(&(toparg[0]),xargv[0]);
  1035.     }
  1036.     if (yy > -1) {
  1037.         topargc = (j < 0) ? 1 : j + 1;
  1038.         topxarg = toparg;
  1039.     } else {
  1040.         topargc = 0;
  1041.         topxarg = NULL;
  1042.     }
  1043.     a_dim[0] = topargc - 1;
  1044.     a_ptr[0] = topxarg;
  1045.     }
  1046.     *vnambuf = NUL;
  1047.  
  1048. #endif /* NOSPL */
  1049.  
  1050. /* Get our home directory now.  This needed in lots of places. */
  1051.  
  1052.     homdir = zhome();
  1053.     cmdinited = 1;
  1054. }
  1055.  
  1056. VOID
  1057. doinit() {
  1058.     int x = 0, ok = 0;
  1059. #ifdef OS2
  1060.     char * ptr = 0;
  1061. #endif /* OS2 */
  1062.  
  1063.     if (!cmdinited)
  1064.       cmdini();
  1065.  
  1066. #ifdef MAC
  1067.     return;                /* Mac Kermit has no init file */
  1068.  
  1069. #else /* !MAC */
  1070.  
  1071. /* If skipping init file ('-Y' on Kermit command line), return now. */
  1072.  
  1073.     if (noinit) {
  1074.     kermrc[0] = '\0';
  1075.     inidir[0] = '\0';
  1076. /*
  1077.   But returning from here results in inidir[] never being set to anything.
  1078.   Instead it should be set to wherever the init file *would* have been
  1079.   executed from.  So this bit of code should be removed, and then we should
  1080.   sprinkle "if (noinit)" tests throughout the following code until we have
  1081.   set inidir[], and then return without actually taking the init file.
  1082. */
  1083.     return;
  1084.     }
  1085.  
  1086. #ifdef OS2
  1087. /*
  1088.   The -y init file must be fully specified or in the current directory.
  1089.   KERMRC is looked for via INIT, DPATH and PATH in that order.  Finally, our
  1090.   own executable file path is taken and the .EXE suffix is replaced by .INI
  1091.   and this is tried as the initialization file.
  1092. */
  1093.     if (rcflag) {
  1094.     ckstrncpy(line,kermrc,LINBUFSIZ+1);
  1095.     } else {
  1096.         char * env = 0;
  1097. #ifdef NT
  1098.     env = getenv("K95.KSC");
  1099. #else
  1100.     env = getenv("K2.KSC");
  1101. #endif /* NT */
  1102.         if (!env) {
  1103. #ifdef NT
  1104.             env = getenv("K95.INI");
  1105. #else
  1106.             env = getenv("K2.INI");
  1107. #endif /* NT */
  1108.         }
  1109.     if (!env)
  1110.       env = getenv("CKERMIT.INI");
  1111.     if (!env)
  1112.       env = getenv("CKERMIT_INI");
  1113.         line[0] = '\0';
  1114.  
  1115.     if (env)
  1116.       ckstrncpy(line,env,LINBUFSIZ+1);
  1117.     if (line[0] == 0)
  1118.       _searchenv(kermrc,"INIT",line);
  1119.     if (line[0] == 0)
  1120.       _searchenv(kermrc,"DPATH",line);
  1121.     if (line[0] == 0)
  1122.       _searchenv(kermrc,"PATH",line);
  1123.     if (line[0] == 0) {
  1124.         char *pgmptr = GetLoadPath();
  1125.         if (pgmptr && strlen(pgmptr) < LINBUFSIZ-8) {
  1126.         lp = strrchr(pgmptr, '\\');
  1127.                 if (lp) {
  1128.                     strncpy(line, pgmptr, lp - pgmptr);
  1129. #ifdef NT
  1130.                     strcpy(line + (lp - pgmptr), "\\k95.ini");
  1131. #else /* NT */
  1132.                     strcpy(line + (lp - pgmptr), "\\k2.ini");
  1133. #endif /* NT */
  1134.                 } else {
  1135.                     lp = strrchr(pgmptr, '.');
  1136.                     if (lp) {
  1137.                         strncpy(line, pgmptr, lp - pgmptr);
  1138.                         strcpy(line + (lp - pgmptr), ".ini");
  1139.                     }
  1140.                 }
  1141.         }
  1142.     }
  1143.     }
  1144.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  1145.     ok = 1;
  1146.         tlevel = 0;
  1147.     tfline[tlevel] = 0;
  1148.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  1149.       strcpy(tfnam[tlevel],line);
  1150. #ifndef NOSPL
  1151.     cmdlvl++;
  1152.     cmdstk[cmdlvl].src = CMD_TF;
  1153.     cmdstk[cmdlvl].lvl = tlevel;
  1154.     cmdstk[cmdlvl].ccflgs = 0;
  1155.     ifcmd[cmdlvl] = 0;
  1156.     iftest[cmdlvl] = 0;
  1157.     count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1158.     intime[cmdlvl] = intime[cmdlvl-1];
  1159.     inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1160.     takerr[cmdlvl] = takerr[cmdlvl-1];
  1161.     merror[cmdlvl] = merror[cmdlvl-1];
  1162.     xquiet[cmdlvl] = quiet;
  1163. #endif /* NOSPL */
  1164.         debug(F110,"doinit init file",line,0);
  1165.     } else {
  1166.         debug(F100,"doinit no init file","",0);
  1167.     }
  1168.     ckstrncpy(kermrc,line,KERMRCL);
  1169.     for (ptr = kermrc; *ptr; ptr++)    /* Convert backslashes to slashes */
  1170.        if (*ptr == '\\')
  1171.          *ptr = '/';
  1172. #else /* not OS2 */
  1173.     lp = line;
  1174.     lp[0] = '\0';
  1175.     debug(F101,"doinit rcflag","",rcflag);
  1176. #ifdef GEMDOS
  1177.     zkermini(line, rcflag, kermrc);
  1178. #else
  1179. #ifdef VMS
  1180.     zkermini(line,LINBUFSIZ,kermrc);
  1181. #else /* not VMS */
  1182. #ifdef CK_LOGIN
  1183.     debug(F101,"doinit isguest","",isguest);
  1184.     if (isguest)
  1185.       strcpy(lp, anonfile ? anonfile : kermrc);
  1186.     else
  1187. #endif /* CK_LOGIN */
  1188.       if (rcflag) {            /* If init file name from cmd line */
  1189.       strcpy(lp,kermrc);        /* use it, */
  1190.       } else {                /* otherwise... */
  1191. #ifdef CK_INI_A                /* If we've a system-wide init file */
  1192.       /* And it takes precedence over the user's... */
  1193.       ckstrncpy(lp,CK_SYSINI,KERMRCL); /* Use it */
  1194.       if (zchki(lp) < 0) {        /* (if it exists...) */
  1195. #endif /* CK_INI_A */
  1196.           line[0] = NUL;
  1197.           if (homdir) {        /* Home directory for init file. */
  1198.           strcpy(lp,homdir);
  1199. #ifdef STRATUS
  1200.           strcat(lp,">");    /* VOS separates dirs with >'s */
  1201. #else
  1202.           if (lp[0] == '/') strcat(lp,"/");
  1203. #endif /* STRATUS */
  1204.           }
  1205.           strcat(lp,kermrc);    /* Append the default file name */
  1206. #ifdef CK_INI_A
  1207.       }
  1208. #endif /* CK_INI_A */
  1209.       }
  1210. #ifdef CK_INI_B                /* System-wide init defined? */
  1211.     /* But user's ini file takes precedence */
  1212.     if (zchki(lp) < 0)            /* If user doesn't have her own, */
  1213.       ckstrncpy(lp,CK_SYSINI,KERMRCL);    /* use system-wide one. */
  1214. #endif /* CK_INI_B */
  1215.  
  1216. #endif /* VMS */
  1217. #endif /* GEMDOS */
  1218.  
  1219. #ifdef AMIGA
  1220.     reqoff();                /* Disable requestors */
  1221. #endif /* AMIGA */
  1222.  
  1223.     debug(F110,"doinit ini file is",line,0);
  1224.     if ((tfile[0] = fopen(line,"r")) != NULL) {    /* Try to open init file. */
  1225.     ok = 1;
  1226.     tlevel = 0;
  1227.     tfline[tlevel] = 0;
  1228.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  1229.       strcpy(tfnam[tlevel],line);
  1230.  
  1231.     ckstrncpy(kermrc,line,KERMRCL);
  1232.  
  1233. #ifndef NOSPL
  1234.     cmdlvl++;
  1235.     ifcmd[cmdlvl] = 0;
  1236.     iftest[cmdlvl] = 0;
  1237.     count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1238.     intime[cmdlvl] = intime[cmdlvl-1];
  1239.     inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1240.     takerr[cmdlvl] = takerr[cmdlvl-1];
  1241.     merror[cmdlvl] = merror[cmdlvl-1];
  1242.     xquiet[cmdlvl] = quiet;
  1243.     debug(F101,"doinit open ok","",cmdlvl);
  1244.     cmdstk[cmdlvl].src = CMD_TF;
  1245.     cmdstk[cmdlvl].lvl = tlevel;
  1246.     cmdstk[cmdlvl].ccflgs = 0;
  1247. #endif /* NOSPL */
  1248.     } else if (rcflag) {
  1249.     /* Print an error message only if a specific file was asked for. */
  1250.     printf("?%s - %s\n", ck_errstr(), line);
  1251.     }
  1252.  
  1253. #ifdef datageneral
  1254. /* If CKERMIT.INI not found in home directory, look in searchlist */
  1255.     if (homdir && (tlevel < 0)) {
  1256.         strcpy(lp,kermrc);
  1257.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  1258.         ok = 1;
  1259.         tlevel = 0;
  1260.         tfline[tlevel] = 0;
  1261.         if (tfnam[tlevel] = malloc(strlen(line)+1))
  1262.           strcpy(tfnam[tlevel],line);
  1263. #ifndef NOSPL
  1264.         cmdlvl++;
  1265.         cmdstk[cmdlvl].src = CMD_TF;
  1266.         cmdstk[cmdlvl].lvl = tlevel;
  1267.         cmdstk[cmdlvl].ccflgs = 0;
  1268.         ifcmd[cmdlvl] = 0;
  1269.         iftest[cmdlvl] = 0;
  1270.         count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1271.         intime[cmdlvl] = intime[cmdlvl-1];
  1272.         inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1273.         takerr[cmdlvl] = takerr[cmdlvl-1];
  1274.         merror[cmdlvl] = merror[cmdlvl-1];
  1275.         xquiet[cmdlvl] = quiet;
  1276. #endif /* NOSPL */
  1277.     }
  1278.     }
  1279. #endif /* datageneral */
  1280.  
  1281. #ifdef AMIGA                /* Amiga... */
  1282.     reqpop();                /* Restore requestors */
  1283. #endif /* AMIGA */
  1284. #endif /* OS2 */
  1285. #endif /* MAC */
  1286.  
  1287.     /* Assign value to inidir */
  1288.  
  1289.     if (!ok) {
  1290.     inidir[0] = NUL;
  1291.     } else {
  1292.     strcpy(inidir, kermrc);
  1293.     x = strlen(inidir);
  1294.     if (x > 0) {
  1295.         int i;
  1296.         for (i = x - 1; i > 0; i-- ) {
  1297.         if (inidir[i] ==
  1298. #ifdef MAC
  1299.             ':'
  1300. #else
  1301. #ifdef UNIX
  1302.             '/'
  1303. #else
  1304. #ifdef OSK
  1305.             '/'
  1306. #else
  1307. #ifdef STRATUS
  1308.             '>'
  1309. #else
  1310. #ifdef VMS
  1311.             ']' || inidir[i] == ':'
  1312. #else
  1313. #ifdef datageneral
  1314.             ':'
  1315. #else
  1316. #ifdef OS2
  1317.             '/' || inidir[i+1] == '\\'
  1318. #else
  1319. #ifdef AMIGA
  1320.             '/' || inidir[i+1] == ':'
  1321. #endif /* AMIGA */
  1322. #endif /* OS2 */
  1323. #endif /* datageneral */
  1324. #endif /* VMS */
  1325. #endif /* STRATUS */
  1326. #endif /* OSK */
  1327. #endif /* UNIX */
  1328. #endif /* MAC */
  1329.             ) {
  1330.             inidir[i+1] = NUL;
  1331.             break;
  1332.         }
  1333.         }
  1334.     }
  1335.     }
  1336. }
  1337.  
  1338. VOID
  1339. doiksdinit() {
  1340. #ifdef CK_SSL
  1341.     /* IKSD doesn't request client certs */
  1342.     ssl_verify_flag = SSL_VERIFY_NONE;
  1343. #endif /* CK_SSL */
  1344.  
  1345.     if (!cmdinited)
  1346.       cmdini();
  1347.  
  1348. #ifdef IKSDCONF
  1349. #ifdef OS2
  1350.     line[0] = '\0';
  1351.     _searchenv(iksdconf,"INIT",line);
  1352.     if (line[0] == 0)
  1353.       _searchenv(iksdconf,"DPATH",line);
  1354.     if (line[0] == 0)
  1355.       _searchenv(iksdconf,"PATH",line);
  1356.     if (line[0] == 0) {
  1357.         char *pgmptr = GetLoadPath();
  1358.         if (pgmptr && strlen(pgmptr) < LINBUFSIZ-8) {
  1359.             lp = strrchr(pgmptr, '\\');
  1360.             if (lp) {
  1361.                 strncpy(line, pgmptr, lp - pgmptr);
  1362.                 strcpy(line + (lp - pgmptr + 1), "\\");
  1363.                 strcpy(line + (lp - pgmptr + 1), iksdconf);
  1364.             } else {
  1365.                 lp = strrchr(pgmptr, '.');
  1366.                 if (lp) {
  1367.                     strncpy(line, pgmptr, lp - pgmptr);
  1368.                     strcpy(line + (lp - pgmptr), ".ksc");
  1369.                 }
  1370.             }
  1371.         }
  1372.     }
  1373.     debug(F110,"doiksdinit() line",line,0);
  1374.     tfile[0] = fopen(line,"r");
  1375. #else /* OS2 */
  1376.     tfile[0] = fopen(iksdconf,"r");
  1377. #endif /* OS2 */
  1378.     if (tfile[0] != NULL) {
  1379.         tlevel = 0;
  1380.     tfline[tlevel] = 0;
  1381.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  1382.       strcpy(tfnam[tlevel],iksdconf);
  1383. #ifndef NOSPL
  1384.     cmdlvl++;
  1385.     cmdstk[cmdlvl].src = CMD_TF;
  1386.     cmdstk[cmdlvl].lvl = tlevel;
  1387.     cmdstk[cmdlvl].ccflgs = 0;
  1388.     ifcmd[cmdlvl]  = 0;
  1389.     iftest[cmdlvl] = 0;
  1390.     count[cmdlvl]  = count[cmdlvl-1]; /* Inherit from previous level */
  1391.     intime[cmdlvl] = intime[cmdlvl-1];
  1392.     inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1393.     takerr[cmdlvl] = takerr[cmdlvl-1];
  1394.     merror[cmdlvl] = merror[cmdlvl-1];
  1395.     xquiet[cmdlvl] = quiet;
  1396. #endif /* NOSPL */
  1397.         debug(F110,"doiksdinit file ok",iksdconf,0);
  1398.     } else {
  1399.         debug(F110,"doiksdinit open failed",iksdconf,0);
  1400.     }
  1401. #endif /* IKSDCONF */
  1402. }
  1403.  
  1404. #ifndef NOSPL
  1405. /*
  1406.   G E T N C M
  1407.  
  1408.   Get next command from current macro definition.  Command is copied
  1409.   into string pointed to by argument s, max length n.   Returns:
  1410.    0 if a string was copied;
  1411.   -1 if there was no string to copy.
  1412. */
  1413. int
  1414. getncm(s,n) char *s; int n; {
  1415.     int y,                /* Character counter */
  1416. #ifdef COMMENT
  1417.     quote = 0,
  1418. #endif /* COMMENT */
  1419.     kp = 0,                /* Brace up-down counter */
  1420.     pp = 0;                /* Parenthesis up-down counter */
  1421.     char *s2;                /* Copy of destination pointer */
  1422.  
  1423.     s2 = s;                /* Initialize string pointers */
  1424.     *s = NUL;                /* and destination buffer */
  1425.  
  1426.     debug(F101,"getncm dest length","",n);
  1427.  
  1428.     for (y = 0;                /* Loop for n bytes max */
  1429.       macp[maclvl] && *macp[maclvl] && y < n;
  1430.      y++, s++, macp[maclvl]++) {
  1431.  
  1432.     *s = *macp[maclvl];        /* Get next char from macro def */
  1433.     /* debug(F000,"char","",*s); */
  1434. #ifdef COMMENT
  1435. /*
  1436.   The intention here was to allow quoting of commas, braces, etc,
  1437.   in macro definitions, e.g. "define rows mode co80\,\%1".  And it
  1438.   works, but it breaks just about everything else.
  1439. */
  1440.     if (*s == CMDQ && quote == 0) {    /* Allow for quoting of */
  1441.         quote = 1;            /* braces, commas, etc. */
  1442.         continue;
  1443.     }
  1444. #endif /* COMMENT */
  1445. /*
  1446.   Allow braces around macro definition to prevent commas from being turned to
  1447.   end-of-lines and also treat any commas within parens as text so that
  1448.   multiple-argument functions won't cause the command to break prematurely.
  1449. */
  1450. #ifdef COMMENT
  1451.     if (!quote) {
  1452. #endif /* COMMENT */
  1453.         if (*s == '{') kp++;    /* Count braces */
  1454.         if (*s == '}') kp--;
  1455.         if (*s == '(') pp++;    /* Count parentheses. */
  1456.         if (*s == ')') pp--;
  1457.         if (*s == ',' && pp <= 0 && kp <= 0) {
  1458.         macp[maclvl]++;        /* Comma not in {} or () */
  1459.         debug(F110,"next cmd",s,0);
  1460.         kp = pp = 0;        /* so we have the next command */
  1461.         break;
  1462.         }
  1463. #ifdef COMMENT
  1464.     }
  1465. #endif /* COMMENT */
  1466.     }                    /* Reached end. */
  1467.     if (*s2 == NUL) {            /* If nothing was copied, */
  1468.     debug(F100,"getncm eom","",0);
  1469.     popclvl();            /* pop command level. */
  1470.     return(-1);
  1471.     } else {                /* otherwise, tack CR onto end */
  1472.     *s++ = CR;
  1473.     *s = '\0';
  1474.     if (mecho && pflag)        /* If MACRO ECHO ON, echo the cmd */
  1475.       printf("%s\n",s2);
  1476.     debug(F110,"getncm returns ptr to",s2,0);
  1477.     }
  1478.     return(0);
  1479. }
  1480.  
  1481. /*  D O M A C  --  Define and then execute a macro */
  1482.  
  1483. int
  1484. domac(name, def, flags) char *name, *def; int flags; {
  1485.     int x, m;
  1486. #ifdef OS2
  1487.     extern int term_io;
  1488.     int term_io_sav = term_io;
  1489.     term_io = 0;            /* Disable Terminal Emulator I/O */
  1490. #endif /* OS2 */
  1491.  
  1492.     m = maclvl;                /* Current macro stack level */
  1493.     debug(F101,"domac entry maclvl","",maclvl);
  1494.     x = addmac(name, def);        /* Define a new macro */
  1495.     if (x > -1) {            /* If successful, */
  1496.     dodo(x,NULL,flags);        /* start it (increments maclvl). */
  1497.     while (maclvl > m) {        /* Keep going till done with it, */
  1498.         debug(F101,"domac loop maclvl 1","",maclvl);
  1499.         sstate = (CHAR) parser(1);    /* parsing & executing each command, */
  1500.         debug(F101,"domac loop maclvl 2","",maclvl);
  1501.         if (sstate) proto();    /* including protocol commands. */
  1502.     }
  1503.     debug(F101,"domac loop exit maclvl","",maclvl);
  1504.     }
  1505. #ifdef OS2
  1506.     term_io = term_io_sav;
  1507. #endif /* OS2 */
  1508.     return(success);
  1509. }
  1510. #endif /* NOSPL */
  1511.  
  1512. /*
  1513.   G E T N C T
  1514.  
  1515.   Get next command from TAKE (command) file.
  1516.  
  1517.   Call with:
  1518.    s     Pointer to buffer to read into
  1519.    n     Length of buffer
  1520.    f     File descriptor of file to read from
  1521.    flag  0 == keep line terminator on and allow continuation
  1522.          1 == discard line terminator and don't allow continuation
  1523.  
  1524.   Call with flag == 0 to read a command from a TAKE file;
  1525.   Call with flag != 0 to read a line from a dialing or network directory.
  1526.  
  1527.   In both cases, trailing comments and/or trailing whitespace is/are stripped.
  1528.   If flag == 0, continued lines are combined into one line.  A continued line
  1529.   is one that ends in hypen, or any line in a "block", which starts with "{"
  1530.   at the end of a line and ends with a matching "}" at the beginning of a
  1531.   subsequent line; blocks may be nested.
  1532.  
  1533.   Returns:
  1534.    0 if a string was copied,
  1535.   -1 on EOF,
  1536.   -2 on malloc failure
  1537.   -3 if line is not properly terminated
  1538.   -4 if (possibly continued) line is too long.
  1539. */
  1540. static char * lpx = NULL;
  1541. static int lpxlen = 0;
  1542.  
  1543. int
  1544. getnct(s,n,f,flag) char *s; int n; FILE *f; int flag; {
  1545.     int i = 0, len = 0, buflen = 0;
  1546.     char c = NUL, cc = NUL, ccl = NUL, ccx = NUL, *s2 = NULL;
  1547.     char *lp = NULL, *lpx = NULL, *lp2 = NULL, *lp3 = NULL, *lastcomma = NULL;
  1548.     int bc = 0;                /* Block counter */
  1549.  
  1550.     s2 = s;                /* Remember original pointer */
  1551.     buflen = n;                /* Remember original buffer length */
  1552.  
  1553.     debug(F101,"getnct","",n);
  1554.     if (n < 0)
  1555.         return(-2);
  1556.  
  1557.     /* Allocate a line buffer only if we don't have one that's big enough */
  1558.  
  1559.     if (lpx && (n > lpxlen)) {        /* Have one already */
  1560.     free(lpx);            /* But it's not big enough */
  1561.     lpx = NULL;            /* Free current one */
  1562.     lpxlen = 0;
  1563.     }
  1564.     if (!lpx) {                /* Get new one */
  1565.     if (!(lpx = (char *) malloc(n))) {
  1566.         debug(F101,"getnct malloc failure","",0);
  1567.         printf("?Memory allocation failure [getnct]\n");
  1568.         return(-2);
  1569.     }
  1570.     lpxlen = n;
  1571.     }
  1572.     lp2 = lpx;
  1573. #define KLUDGE                /* See below */
  1574. #ifdef KLUDGE
  1575.     lp2++;
  1576. #endif /* KLUDGE */
  1577.  
  1578.     while (1) {                /* Loop to read lines from file */
  1579.     if (fgets(lp2,n,f) == NULL) {    /* Read a line into lp2 */
  1580.         debug(F100,"getnct fgets EOF","",0); /* EOF */
  1581.         free(lpx);            /* Free temporary storage */
  1582.         lpx = NULL;
  1583.         *s = NUL;            /* Make destination be empty */
  1584.         return(-1);            /* Return failure code */
  1585.     }
  1586. #ifndef NODIAL
  1587.     if (flag)            /* Count this line */
  1588.       dirline++;
  1589.     else
  1590. #endif /* NODIAL */
  1591.       tfline[tlevel]++;
  1592.     len = strlen(lp2) - 1;        /* Position of line terminator */
  1593.     debug(F111,"getnct fgets ok",lp2,len);
  1594.     if (len == 0 && lp2[0] != '\n') { /* Last line in file has one char */
  1595.         lp2[++len] = '\n';        /* that is not a newline */
  1596.         lp2[len] = NUL;
  1597.     }
  1598.     if (len < 0)
  1599.       len = 0;
  1600.     if (techo && pflag)        /* If TAKE ECHO ON, */
  1601.       printf("%3d. %s",        /* echo it this line. */
  1602. #ifndef NODIAL
  1603.          flag ? dirline :
  1604. #endif /* NODIAL */
  1605.          tfline[tlevel],
  1606.          lp2
  1607.          );
  1608.         lp3 = lp2;            /* Working pointer */
  1609.     i = len;            /* Get first nonwhitespace character */
  1610.     while (i > 0 && *lp3 == SP || *lp3 == HT) {
  1611.         i--;
  1612.         lp3++;
  1613.     }
  1614.     if (i == 0 && bc > 0)        /* Blank line in {...} block */
  1615.       continue;
  1616.  
  1617.     /* Isolate, remove, and check terminator */
  1618.  
  1619.     c = lp2[len];            /* Value of line terminator */
  1620.     debug(F101,"getnct terminator","",c);
  1621.     if (c < LF || c > CR) {        /* It's not a terminator */
  1622.         debug(F111,"getnct bad line",lp2,c);
  1623.         if (feof(f) && len > 0 && len < n) {
  1624.         /* Kludge Alert... */
  1625.         if (!quiet)
  1626.           printf("WARNING: Last line of %s lacks terminator\n",
  1627.              s2 == cmdbuf ? "command file" : "directory file");
  1628.         c = lp2[++len] = '\n';    /* No big deal - supply one. */
  1629.         } else {            /* Something's wrong, fail. */
  1630.         free(lpx);
  1631.         lpx = NULL;
  1632.         return(-3);
  1633.         }
  1634.     }
  1635.  
  1636.     /* Trim trailing whitespace */
  1637.  
  1638.     for (i = len - 1; i > -1 && lp2[i] <= SP; i--) /* Trim */
  1639.       ;
  1640.     debug(F101,"getnct i","",i);
  1641.     lp2[i+1] = NUL;            /* Terminate the string */
  1642.     debug(F110,"getnct lp2",lp2,0);
  1643.     lp = lp2;            /* Make a working pointer */
  1644.  
  1645.     /* Remove trailing or full-line comment */
  1646.  
  1647.     while (cc = *lp) {
  1648.         if (cc == ';' || cc == '#') { /* Comment introducer? */
  1649.         if (lp == lp2) {    /* First char on line */
  1650.             *lp = NUL;
  1651.             break;
  1652.         } else if (*(lp - 1) == SP || *(lp - 1) == HT) {
  1653.             lp--;
  1654.             *lp = NUL;    /* Or preceded by whitespace */
  1655.             break;
  1656.         }
  1657.         }
  1658.         lp++;
  1659.     }
  1660.     if (lp > lp2)
  1661.       lp--;                /* Back up over the NUL */
  1662.  
  1663.     /* Now trim any space that preceded the comment */
  1664.  
  1665.     while ((*lp == SP || *lp == HT) && lp >= lp2) {
  1666.         *lp = NUL;
  1667.         if (lp <= lp2)
  1668.           break;
  1669.         lp--;
  1670.     }
  1671.     debug(F110,"getnct comment trimmed",lp2,0);
  1672.  
  1673.     len = strlen(lp2);        /* Length after trimming */
  1674.  
  1675.     if (n - len < 2) {        /* Check remaining space */
  1676.         debug(F111,"getnct command too long",s2,buflen);
  1677.         printf("?Line too long, maximum length: %d.\n",buflen);
  1678.         free(lpx);
  1679.         return(-4);
  1680.     }
  1681.     ccl = (len > 0) ? lp2[len-1] : 0;     /* Last character in line */
  1682.     ccx = (len > 1) ? lp2[len-2] : 0;     /* Penultimate char in line */
  1683.  
  1684. #ifdef KLUDGE
  1685. /*
  1686.   If it is a command and it begins with a token (like ! or .) that is not
  1687.   followed by a space, insert a space now; otherwise cmkey() can get might
  1688.   confused.
  1689. */
  1690.     if (s == s2 && !flag) {
  1691.         char *p = toktab;
  1692.         while (*p) {
  1693.         if (*p == *lp3 && *(p+1) != SP) {
  1694.             *lp3-- = SP;
  1695.             *lp3 = *p;
  1696.             if (lp3 < lp2) {
  1697.             lp2--;
  1698.             len++;
  1699.             }
  1700.             break;
  1701.         } else
  1702.           p++;
  1703.         }
  1704.     }
  1705. #endif /* KLUDGE */
  1706.     lp = lp2;
  1707.  
  1708.     while (*s++ = *lp++)        /* Copy result to target buffer */
  1709.       n--;                /* accounting for length */
  1710.     s--;                /* Back up over the NUL */
  1711.  
  1712.     /* Check whether this line is continued */
  1713.  
  1714.         if (flag)            /* No line continuation when flag=1 */
  1715.       break;            /* So break out of read-lines loop */
  1716.  
  1717.     debug(F000,"getnct first char","",*lp3);
  1718.     debug(F000,"getnct last char","",ccl);
  1719.     debug(F000,"getnct next-to-last char","",ccx);
  1720.  
  1721.     if (bc > 0 && *lp3 == '}')    /* First char on line is '}' */
  1722.       bc--;                /* Decrement block counter */
  1723.  
  1724.     if (bc == 0 &&            /* Line is continued if bc > 0 */
  1725. #ifdef COMMENT
  1726.         /* Not supported as of C-Kermit 6.0 */
  1727.         ccl != CMDQ &&        /* or line ends with CMDQ */
  1728. #endif /* COMMENT */
  1729.         ccl != '-'  &&        /* or line ends with dash */
  1730.         ccl != '{')            /* or line ends with opening brace */
  1731.       break;            /* None of those, we're done. */
  1732.  
  1733.     if (ccl == '-' || ccl == '{')    /* Continuation character */
  1734.       if (ccx == CMDQ)        /* But it's quoted */
  1735.         break;            /* so ignore it */
  1736.  
  1737.     if (ccl == '{') {        /* Last char on line is '{'? */
  1738.         bc++;            /* Count the block opener. */
  1739.     } else if (ccl == '-'        /* Explicit continue? */
  1740. #ifdef COMMENT
  1741. /* Not supported as of C-Kermit 6.0. */
  1742.            || ccl == CMDQ
  1743. #endif /* COMMENT */
  1744.            ) {
  1745.         char c, * ss;
  1746.         int state = 0, nn;
  1747.         s--;            /* Yes, back up over terminators */
  1748.         n++;            /* and over continuation character */
  1749.         nn = n;            /* Save current count */
  1750.         ss = s;            /* and pointer */
  1751.         s--;            /* Back up over dash */
  1752.         n++;
  1753.         debug(F110,"XXX lp2 A",s2,0);
  1754.         while (state < 2 && s >= s2) { /* Check for "{,-" */
  1755.         n++;
  1756.         c = *s--;
  1757.         debug(F000,"XXX c","",c);
  1758.         if (c <= SP)
  1759.           continue;
  1760.         if (c != ',' && c != '{')
  1761.           break;
  1762.         switch (state) {
  1763.           case 0:        /* Looking for comma */
  1764.             if (c == ',')
  1765.               state = 1;
  1766.             break;
  1767.           case 1:        /* Looking for left brace */
  1768.             if (c == '{') {
  1769.             state = 2;
  1770.             s += 2;
  1771.             *s = NUL;
  1772.             bc++;
  1773.             }
  1774.             break;
  1775.         }
  1776.         }
  1777.         if (state != 2) { s = ss; n = nn; }
  1778.         debug(F110,"XXX lp2 B",s2,0);
  1779.     } else {            /* None of those but (bc > 0) */
  1780.         lastcomma = s;
  1781.         *s++ = ',';            /* and insert a comma */
  1782.         n--;
  1783.     }
  1784.     debug(F101,"getnct bc","",bc);
  1785.     debug(F100,"getnct continued","",0);
  1786.     } /* read-lines while loop */
  1787.  
  1788.     if (lastcomma)
  1789.       *lastcomma = SP;
  1790.     if (!flag)                /* Tack line terminator back on */
  1791.       *s++ = c;
  1792.     *s++ = NUL;                /* Terminate the string */
  1793.     untab(s2);                /* Done, convert tabs to spaces */
  1794.     debug(F110,"getnct return",s2,0);
  1795.     free(lpx);                /* Free temporary storage */
  1796.     return(0);                /* Return success */
  1797. }
  1798.  
  1799. VOID
  1800. shostack() {                /* Dump the command stack */
  1801.     int i;
  1802.     char *p;
  1803. #ifndef NOSPL
  1804.     for (i = cmdlvl; i > 0; i--) {
  1805.     if (cmdstk[i].src == CMD_TF) {
  1806.         p = tfnam[cmdstk[i].lvl];
  1807.         if (zfnqfp(p,TMPBUFSIZ,tmpbuf))
  1808.           p = tmpbuf;
  1809.         printf(" %2d. File  : %s (line %d)\n",
  1810.            i,
  1811.            p,
  1812.            tfline[cmdstk[i].lvl]
  1813.            );
  1814.     } else if (cmdstk[i].src == CMD_MD) {
  1815.         char * m;
  1816.         m = m_arg[cmdstk[i].lvl][0]; /* Name of this macro */
  1817.         if (i > 0) {         /* Special handling for 2-level */
  1818.         char *s;         /* built-in macros... */
  1819.         s = m_arg[cmdstk[i-1].lvl][0]; /* Name next level up */
  1820.         if (s && cmdstk[i-1].src == CMD_MD) {
  1821.             if (!strcmp(s,"_forx"))
  1822.               m = "FOR";
  1823.             else if (!strcmp(s,"_xif"))
  1824.               m = "XIF";
  1825.             else if (!strcmp(s,"_while"))
  1826.               m = "WHILE";
  1827.             else if (!strcmp(s,"_switx"))
  1828.               m = "SWITCH";
  1829.         }
  1830.         }
  1831.         printf(" %2d. Macro : %s\n",i,m);
  1832.     } else {
  1833.         printf(" 00. ERROR : Command source unknown\n");
  1834.     }
  1835.     }
  1836. #else
  1837.     for (i = tlevel; i > -1; i--) {
  1838.     p = tfnam[i];
  1839.     if (zfnqfp(p,TMPBUFSIZ,tmpbuf))
  1840.       p = tmpbuf;
  1841.     printf(" %2d. File  : %s (line %d)\n",
  1842.            i,
  1843.            p,
  1844.            tfline[i]
  1845.            );
  1846.     }
  1847. #endif /* NOSPL */
  1848.     if (i == 0)
  1849.       printf(" %2d. Prompt: (top level)\n",0);
  1850. }
  1851.  
  1852.  
  1853. /*  P A R S E R  --  Top-level interactive command parser.  */
  1854.  
  1855. /*
  1856.   Call with:
  1857.     m = 0 for normal behavior: keep parsing and executing commands
  1858.           until an action command is parsed, then return with a
  1859.           Kermit start-state as the value of this function.
  1860.     m = 1 to parse only one command, can also be used to call parser()
  1861.           recursively.
  1862.     m = 2 to read but do not execute one command.
  1863.   In all cases, parser() returns:
  1864.     0     if no Kermit protocol action required
  1865.     > 0   with a Kermit protocol start-state.
  1866.     < 0   upon error.
  1867. */
  1868. int
  1869. parser(m) int m; {
  1870.     int tfcode, xx, yy, zz;        /* Workers */
  1871.     int is_tn = 0;
  1872.  
  1873. #ifndef NOSPL
  1874.     int inlevel;            /* Level we were called at */
  1875.     extern int askflag;
  1876. #endif /* NOSPL */
  1877.     char *cbp;                /* Command buffer pointer */
  1878. #ifdef MAC
  1879.     extern char *lfiles;        /* Fake extern cast */
  1880. #endif /* MAC */
  1881. #ifndef NOXFER
  1882.     extern int sndcmd, getcmd, interrupted, fatalio, clearrq;
  1883. #endif /* NOXFER */
  1884.  
  1885. #ifdef AMIGA
  1886.     reqres();                /* Restore AmigaDOS requestors */
  1887. #endif /* AMIGA */
  1888.  
  1889. #ifdef OS2
  1890.     if (cursor_save > -1) {        /* Restore cursor if it was */
  1891.     cursorena[VCMD] = cursor_save;    /* turned off during file transfer */
  1892.     cursor_save = -1;
  1893.     }
  1894. #endif /* OS2 */
  1895.  
  1896.     what = W_COMMAND;            /* Now we're parsing commands. */
  1897.  
  1898. #ifdef IKSDB
  1899.     if (ikdbopen) slotstate(what,"COMMAND PROMPT","",""); /* IKSD database */
  1900. #endif /* IKSDB */
  1901.  
  1902.     is_tn = (local && network && ttnproto == NP_TELNET) ||
  1903.       (!local && sstelnet);
  1904.  
  1905.     if (!cmdsrc())            /* If at top (interactive) level ... */
  1906.       concb((char)escape);        /* put console in 'cbreak' mode. */
  1907.  
  1908. #ifdef CK_TMPDIR
  1909. /* If we were cd'd temporarily to another device or directory ... */
  1910.     if (f_tmpdir) {
  1911.     int x;
  1912.     x = zchdir((char *) savdir);    /* ... restore previous directory */
  1913.     f_tmpdir = 0;            /* and remember we did it. */
  1914.     debug(F111,"parser tmpdir restoring",savdir,x);
  1915.     }
  1916. #endif /* CK_TMPDIR */
  1917.  
  1918. #ifndef NOSPL
  1919.     inlevel = cmdlvl;        /* Current macro level */
  1920. #ifdef DEBUG
  1921.     if (deblog) {
  1922.     debug(F101,"&parser entry maclvl","",maclvl);
  1923.     debug(F101,"&parser entry inlevel","",inlevel);
  1924.     debug(F101,"&parser entry tlevel","",tlevel);
  1925.     debug(F101,"&parser entry cmdlvl","",cmdlvl);
  1926.     debug(F101,"&parser entry m","",m);
  1927.     }
  1928. #endif /* DEBUG */
  1929. #endif /* NOSPL */
  1930.  
  1931. #ifndef NOXFER
  1932.     ftreset();                /* Reset global file-xfer settings */
  1933. #endif /* NOXFER */
  1934. /*
  1935.   sstate becomes nonzero when a command has been parsed that requires some
  1936.   action from the protocol module.  Any non-protocol actions, such as local
  1937.   directory listing or terminal emulation, are invoked directly from below.
  1938. */
  1939.     sstate = 0;                /* Start with no start state. */
  1940.  
  1941. #ifndef NOXFER
  1942. #ifndef NOSPL
  1943.     query = 0;                /* QUERY not active */
  1944. #endif /* NOSPL */
  1945. #ifndef NOHINTS
  1946.     if (sndcmd && !success && hints && !interrupted && !fatalio && !cmdsrc()) {
  1947.     int x = 0;
  1948.         printf("\n*************************\n");
  1949.     printf("SEND-class command failed.\n");
  1950.     printf(" Packets sent: %d\n", spackets);
  1951.     printf(" Retransmissions: %d\n",retrans);
  1952.     printf(" Timeouts: %d\n", timeouts);
  1953.     if (epktrcvd) {
  1954.         printf(" Transfer canceled by receiver.\n");
  1955.         printf(" Receiver's message: \"%s\"\n",(char *)epktmsg);
  1956.     }
  1957.     printf(" Most recent local error: \"%s\"\n",ck_errstr());
  1958.     printf(
  1959.    "\nHINTS... If the preceding error message%s not explain the failure:\n",
  1960.            epktrcvd ? "s do" : " does"
  1961.            );
  1962. #ifndef NOLOCAL
  1963.     if (local) {
  1964.         if (rpackets == 0)
  1965.           printf(" . Did you start a Kermit receiver on the far end?\n");
  1966.         else
  1967.           printf(
  1968.           " . Try changing the remote Kermit's FLOW-CONTROL setting.\n");
  1969.     } else if (rpackets > 0) {
  1970.         if (flow == FLO_NONE)
  1971.          printf(" . Give me a SET FLOW XON/XOFF command and try again.\n");
  1972.         else
  1973.          printf(" . Give me a SET FLOW NONE command and try again.\n");
  1974.     }
  1975.     x++;
  1976. #endif /* NOLOCAL */
  1977. #ifdef CK_SPEED
  1978.     if (prefixing != PX_ALL && rpackets > 2) {
  1979.         printf(" . Try it again with SET PREFIXING ALL.\n");
  1980.         x++;
  1981.     }
  1982. #endif /* CK_SPEED */
  1983. #ifdef STREAMING
  1984.     if (streamed) {
  1985.         printf(" . Try it again with SET STREAMING OFF.\n");
  1986.         x++;
  1987.     } else if (reliable) {
  1988.         printf(" . Try it again with SET RELIABLE OFF.\n");
  1989.         x++;
  1990.     }
  1991. #endif /* STREAMING */
  1992.         if (clearrq > 0 && prefixing == PX_NON) {
  1993.         printf(" . Try it again with SET CLEAR-CHANNEL OFF.\n");
  1994.         x++;
  1995.         }
  1996.     if (!parity) {
  1997.         printf(" . Try it again with SET PARITY SPACE.\n");
  1998.         x++;
  1999.     }
  2000.     printf(" . %sive a ROBUST command and try again.\n",
  2001.            (x > 0) ? "As a last resort, g" : "G"
  2002.            );
  2003.     printf("Also:\n");
  2004.         printf(" . Be sure the source file has read permission.\n");
  2005.     printf(" . Be sure the target directory has write permission.\n");
  2006.     printf("(Use SET HINTS OFF to suppress hints.)\n");
  2007.     printf("*************************\n\n");
  2008.     }
  2009.     if (getcmd && !success && hints && !interrupted && !fatalio && !cmdsrc()) {
  2010.     int x = 0;
  2011.     extern int urpsiz, wslotr;
  2012.         printf("\n*************************\n");
  2013.     printf("RECEIVE- or GET-class command failed.\n");
  2014.     printf(" Packets received: %d\n", rpackets);
  2015.     printf(" Damaged packets: %d\n", crunched);
  2016.     printf(" Timeouts: %d\n", timeouts);
  2017.     if (rpackets > 0)
  2018.       printf(" Packet length: %d\n", urpsiz);
  2019.     if (epktrcvd) {
  2020.         printf(" Transfer canceled by sender.\n");
  2021.         printf(" Sender's message: \"%s\"\n",(char *)epktmsg);
  2022.     }
  2023.     printf(" Most recent local error: \"%s\"\n",ck_errstr());
  2024.     printf(
  2025.    "\nHINTS... If the preceding error message%s not explain the failure:\n",
  2026.            epktrcvd ? "s do" : " does"
  2027.            );
  2028. #ifndef NOLOCAL
  2029.     if (local) {
  2030.         if (rpackets == 0)
  2031.           printf(" . Did you start a Kermit sender on the far end?\n");
  2032.         else
  2033.           printf(
  2034.           " . Choose a different FLOW-CONTROL setting and try again.\n");
  2035.     }
  2036.     if (rpackets > 0 && urpsiz > 90)
  2037.       printf(" . Try smaller packets (SET RECEIVE PACKET-LENGH).\n");
  2038.     if (rpackets > 0 && wslotr > 1 && !streamed)
  2039.       printf(" . Try a smaller window size (SET WINDOW).\n");
  2040.     if (!local && rpackets > 0) {
  2041.         if (flow == FLO_NONE)
  2042.          printf(" . Give me a SET FLOW XON/XOFF command and try again.\n");
  2043.         else
  2044.          printf(" . Give me a SET FLOW NONE command and try again.\n");
  2045.     }
  2046.     x++;
  2047. #endif /* NOLOCAL */
  2048. #ifdef STREAMING
  2049.     if (streamed) {
  2050.         printf(" . Try it again with SET STREAMING OFF.\n");
  2051.         x++;
  2052.     } else if (reliable && local) {
  2053.         printf(" . Try it again with SET RELIABLE OFF.\n");
  2054.         x++;
  2055.         } else
  2056. #endif /* STREAMING */
  2057.     if (!parity) {
  2058.         printf(" . Try it again with SET PARITY SPACE.\n");
  2059.         x++;
  2060.     }
  2061.     printf((x > 0) ?
  2062.            " . As a last resort, give a ROBUST command and try again.\n" :
  2063.            " . Give a ROBUST command and try again.\n"
  2064.            );
  2065.     printf("Also:\n");
  2066.     printf(" . Be sure the target directory has write permission.\n");
  2067.         printf(" . Try telling sender to SET PREFIXING ALL.\n");
  2068.     printf(" . Try giving a ROBUST command to the sender.\n");
  2069.     printf("(Use SET HINTS OFF to suppress hints.)\n");
  2070.     printf("*************************\n\n");
  2071.     }
  2072. #endif /* NOHINTS */
  2073.     getcmd = 0;
  2074.     sndcmd = 0;
  2075.     interrupted = 0;
  2076. #endif /* NOXFER */
  2077.  
  2078.     while (sstate == 0) {        /* Parse cmds until action requested */
  2079.     debug(F100,"parse top","",0);
  2080. #ifdef IKS_OPTION
  2081.         if ((local &&
  2082.          !cmdsrc() &&
  2083.          is_tn &&
  2084.          TELOPT_ME(TELOPT_KERMIT) &&
  2085.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start) ||
  2086.         (!local &&
  2087.          !cmdadl &&
  2088.          TELOPT_ME(TELOPT_KERMIT) &&
  2089.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2090.         ) {
  2091.             tn_siks(KERMIT_STOP);
  2092.         }
  2093. #endif /* IKS_OPTION */
  2094.  
  2095. #ifndef NOXFER
  2096.     if (autopath) {
  2097.         fnrpath = PATH_AUTO;
  2098.         autopath = 0;
  2099.     }
  2100.     remfile = 0;            /* Clear these in case REMOTE */
  2101.     remappd = 0;            /* command was interrupted... */
  2102.     rempipe = 0;
  2103.     makestr(&snd_move,g_snd_move);    /* Restore these */
  2104.     makestr(&rcv_move,g_rcv_move);
  2105.     makestr(&snd_rename,g_snd_rename);
  2106.     makestr(&rcv_rename,g_rcv_rename);
  2107. #endif /* NOXFER */
  2108.     diractive = 0;
  2109.  
  2110. #ifndef NOSPL
  2111.     askflag = 0;
  2112. #endif /* NOSPL */
  2113.  
  2114.     /* Take requested action if there was an error in the previous command */
  2115.  
  2116.     setint();
  2117.     debug(F101,"parser tlevel","",tlevel);
  2118.     debug(F101,"parser cmd_rows","",cmd_rows);
  2119.  
  2120. #ifndef NOLOCAL
  2121.     if (wasclosed) {        /* If connection was just closed */
  2122. #ifndef NOSPL
  2123.         int k;
  2124.         k = mlook(mactab,"on_close",nmac); /* Look up "on_close" */
  2125.         if (k >= 0) {        /* If found, */
  2126.         /* printf("ON_CLOSE CMD LOOP\n"); */
  2127.         dodo(k,ckitoa(whyclosed),0); /* Set it up */
  2128.         }
  2129. #endif /* NOSPL */
  2130.         whyclosed = WC_REMO;
  2131.         wasclosed = 0;
  2132.         }
  2133. #endif /* NOLOCAL */
  2134.  
  2135. #ifndef NOSPL
  2136.     xxdot = 0;            /* Clear this... */
  2137.  
  2138.     if (success == 0) {
  2139.         if (cmdstk[cmdlvl].src == CMD_TF && takerr[cmdlvl]) {
  2140.         printf("Command file terminated by error.\n");
  2141.         popclvl();
  2142.         if (cmdlvl == 0) return(0);
  2143.         }
  2144.         if (cmdstk[cmdlvl].src == CMD_MD && merror[cmdlvl]) {
  2145.         printf("Command error: macro terminated.\n");
  2146.         popclvl();
  2147.         if (m && (cmdlvl < inlevel))
  2148.           return((int) sstate);
  2149.         }
  2150.     }
  2151.     nulcmd = (m == 2);
  2152. #else
  2153.     if (success == 0 && tlevel > -1 && takerr[tlevel]) {
  2154.         printf("Command file terminated by error.\n");
  2155.         popclvl();
  2156.         cmini(ckxech);        /* Clear the cmd buffer. */
  2157.         if (tlevel < 0)         /* Just popped out of cmd files? */
  2158.           return(0);        /* End of init file or whatever. */
  2159.     }
  2160. #endif /* NOSPL */
  2161.  
  2162. #ifdef MAC
  2163.     /* Check for TAKE initiated by menu. */
  2164.     if ((tlevel == -1) && lfiles)
  2165.         startlfile();
  2166. #endif /* MAC */
  2167.  
  2168.         /* If in TAKE file, check for EOF */
  2169. #ifndef NOSPL
  2170. #ifdef MAC
  2171.     if
  2172. #else
  2173.     while
  2174. #endif /* MAC */
  2175.       ((cmdstk[cmdlvl].src == CMD_TF)  /* If end of take file */
  2176.            && (tlevel > -1)
  2177.            && feof(tfile[tlevel])) {
  2178.         popclvl();            /* pop command level */
  2179.         cmini(ckxech);        /* and clear the cmd buffer. */
  2180.         if (cmdlvl == 0) {        /* Just popped out of all cmd files? */
  2181.         return(0);        /* End of init file or whatever. */
  2182.         }
  2183.     }
  2184. #ifdef MAC
  2185.     miniparser(1);
  2186.     if (sstate == 'a') {        /* if cmd-. cancel */
  2187.         debug(F100, "parser: cancel take due to sstate", "", sstate);
  2188.         sstate = '\0';
  2189.         dostop();
  2190.         return(0);            /* End of init file or whatever. */
  2191.     }
  2192. #endif /*  MAC */
  2193.  
  2194. #else /* NOSPL */
  2195.     if ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
  2196.         popclvl();            /* Pop up one level. */
  2197.         cmini(ckxech);        /* and clear the cmd buffer. */
  2198.         if (tlevel < 0)         /* Just popped out of cmd files? */
  2199.           return(0);        /* End of init file or whatever. */
  2200.      }
  2201. #endif /* NOSPL */
  2202.  
  2203. #ifndef NOSPL
  2204.         if (cmdstk[cmdlvl].src == CMD_MD) { /* Executing a macro? */
  2205.         debug(F100,"parser macro","",0);
  2206.         maclvl = cmdstk[cmdlvl].lvl; /* Get current level */
  2207.         debug(F101,"parser maclvl","",maclvl);
  2208.         cbp = cmdbuf;        /* Copy next cmd to command buffer. */
  2209.         *cbp = NUL;
  2210.         if (*savbuf) {        /* In case then-part of 'if' command */
  2211.         strcpy(cbp,savbuf);    /* was saved, restore it. */
  2212.         *savbuf = '\0';
  2213.         } else {            /* Else get next cmd from macro def */
  2214.         if (getncm(cbp,CMDBL) < 0) {
  2215.             if (m && (cmdlvl < inlevel))
  2216.               return((int) sstate);
  2217.             else /* if (!m) */ continue;
  2218.         }
  2219.         }
  2220.         debug(F110,"cmdbuf from macro",cmdbuf,0);
  2221.  
  2222.     } else if (cmdstk[cmdlvl].src == CMD_TF)
  2223. #else
  2224.       if (tlevel > -1)
  2225. #endif /* NOSPL */
  2226.       {
  2227. #ifndef NOSPL
  2228.         if (*savbuf) {        /* In case THEN-part of IF command */
  2229.         strcpy(cmdbuf,savbuf);    /* was saved, restore it. */
  2230.         *savbuf = '\0';
  2231.         } else
  2232. #endif /* NOSPL */
  2233.  
  2234.           /* Get next line from TAKE file */
  2235.  
  2236.           if ((tfcode = getnct(cmdbuf,CMDBL,tfile[tlevel],0)) < 0) {
  2237.           if (tfcode < -1) {    /* Error */
  2238.               printf("?Error in TAKE command file: %s\n",
  2239.                  (tfcode == -2) ? "Memory allocation failure" :
  2240.                  "Line too long or contains NUL characters"
  2241.                  );
  2242.               dostop();
  2243.           }
  2244.           continue;        /* -1 means EOF */
  2245.           }
  2246.  
  2247.         /* If interactive, get next command from user. */
  2248.  
  2249.     } else {            /* User types it in. */
  2250.         if (pflag) prompt(xxstring);
  2251.         cmini(ckxech);
  2252.         }
  2253.  
  2254.     /* Now we know where next command is coming from. Parse and execute it. */
  2255.  
  2256.     repars = 1;            /* 1 = command needs parsing */
  2257. #ifndef NOXFER
  2258.     displa = 0;            /* Assume no file transfer display */
  2259. #endif /* NOXFER */
  2260.  
  2261.     while (repars) {        /* Parse this cmd until entered. */
  2262.  
  2263.         debug(F101,"parser top of while loop","",0);
  2264.  
  2265.         /* In case of "send /recursive ./?<Ctrl-U>" etc */
  2266.  
  2267. #ifdef RECURSIVE
  2268.         recursive = 0;            /* This is never sticky */
  2269. #endif /* RECURSIVE */
  2270.         /* This might have been changed by a switch */
  2271.         if (g_matchdot > -1) {
  2272.         matchdot = g_matchdot;
  2273.         g_matchdot = -1;
  2274.         }
  2275.         if (saveask > -1) {
  2276.         xaskmore = saveask;
  2277.         saveask = -1;
  2278.         }
  2279.         cmres();            /* Reset buffer pointers. */
  2280.  
  2281. #ifdef OS2
  2282. #ifdef COMMENT
  2283.         /* we check to see if a macro is waiting to be executed */
  2284.         /* if so, we call domac on it */
  2285.         if (cmdmac) {
  2286.         ckstrncpy(cmdbuf, cmdmac, CMDBL);
  2287.         free(cmdmac);
  2288.         cmdmac = NULL;
  2289.         }
  2290. #endif /* COMMENT */
  2291. #endif /* OS2 */
  2292. #ifndef NOXFER
  2293.         bye_active = 0;
  2294. #endif /* NOXFER */
  2295.         xx = cmkey2(cmdtab,ncmd,"Command","",toktab,xxstring,1);
  2296.         debug(F101,"top-level cmkey2","",xx);
  2297.         if (xx == -5) {
  2298.         yy = chktok(toktab);
  2299.         debug(F101,"top-level cmkey token","",yy);
  2300.         ungword();
  2301.         switch (yy) {
  2302.           case '#': xx = XXCOM; break; /* Comment */
  2303.           case ';': xx = XXCOM; break; /* Comment */
  2304. #ifndef NOSPL
  2305.           case '.': xx = XXDEF; xxdot = 1; break; /* Assignment */
  2306.           case ':': xx = XXLBL; break; /* GOTO label */
  2307. #endif /* NOSPL */
  2308.  
  2309. #ifndef NOPUSH
  2310. #ifdef CK_REDIR
  2311.                   case '<':
  2312. #endif /* CK_REDIR */
  2313.                   case '@':
  2314.                   case '!':
  2315.             if (!nopush) {
  2316.             switch(yy) {
  2317. #ifdef CK_REDIR
  2318.               case '<': xx = XXFUN; break; /* REDIRECT */
  2319. #endif /* CK_REDIR */
  2320.               case '@':
  2321.               case '!': xx = XXSHE; break; /* Shell escape */
  2322.             }
  2323.             }
  2324.             break;
  2325. #endif /* NOPUSH */
  2326. #ifdef CK_RECALL
  2327.           case '^': xx = XXREDO; break;
  2328. #endif /* CK_RECALL */
  2329. #ifndef NOSPL
  2330.           case '{': xx = XXMACRO; break;
  2331. #endif /* NOSPL */
  2332.  
  2333.           default:
  2334.             if (!quiet) {
  2335.             printf("\n?Invalid - \"%s\"\n",cmdbuf);
  2336. #ifdef COMMENT
  2337. #ifndef NOSPL
  2338.             if (maclvl > -1 && cmdsrc() == 2)
  2339.               printf("Macro: %s; ",
  2340.                  m_arg[maclvl][0] ?
  2341.                  m_arg[maclvl][0] : "");
  2342. #endif /* NOSPL */
  2343.             if (tlevel > -1) {
  2344.                 printf("Command file: %s, line %d\n",
  2345.                    tfnam[tlevel] ? tfnam[tlevel] : "",
  2346.                    tfline[tlevel]
  2347.                    );
  2348.             }
  2349. #else
  2350.             if (cmdsrc() > 0) {
  2351.                 printf("Command stack:\n");
  2352.                 shostack();
  2353.             }
  2354. #endif /* COMMENT */
  2355.  
  2356.             }
  2357.             xx = -2;
  2358.         }
  2359.         }
  2360.         topcmd = xx;        /* Top-level command index */
  2361.  
  2362. #ifndef NOSPL
  2363.             /* Special handling for IF..ELSE */
  2364.  
  2365.         if (ifcmd[cmdlvl])        /* Count stmts after IF */
  2366.           ifcmd[cmdlvl]++;
  2367.         if (ifcmd[cmdlvl] > 2 && xx != XXELS && xx != XXCOM)
  2368.           ifcmd[cmdlvl] = 0;
  2369.  
  2370.         /* Execute the command and take action based on return code. */
  2371.  
  2372.         if (nulcmd) {        /* Ignoring this command? */
  2373.         xx = XXCOM;        /* Make this command a comment. */
  2374.         }
  2375.         fnsuccess = 1;        /* For catching \function() errors */
  2376. #endif /* NOSPL */
  2377.  
  2378.         zz = docmd(xx);        /* Parse rest of command & execute. */
  2379.  
  2380. #ifndef NOSPL
  2381.         if (fnerror && !fnsuccess)
  2382.           success = 0;
  2383. #endif /* NOSPL */
  2384.         debug(F101,"docmd returns","",zz);
  2385.         debug(F110,"cmdbuf",cmdbuf,"");
  2386.         debug(F110,"atmbuf",atmbuf,"");
  2387. #ifdef CK_RECALL
  2388.         if (zz < 0 && cmflgs == 1)
  2389.           addcmd(cmdbuf);
  2390. #endif /* CK_RECALL */
  2391.  
  2392. #ifdef MAC
  2393.         if (tlevel > -1) {
  2394.         if (sstate == 'a') {    /* if cmd-. cancel */
  2395.             debug(F110, "parser: cancel take, sstate:", "a", 0);
  2396.             sstate = '\0';
  2397.             dostop();
  2398.             return(0);        /* End of init file or whatever. */
  2399.         }
  2400.         }
  2401. #endif /* MAC */
  2402.         switch (zz) {
  2403.           case -4:            /* EOF (e.g. on redirected stdin) */
  2404.         doexit(GOOD_EXIT,xitsta); /* ...exit successfully */
  2405.           case -1:            /* Reparse needed */
  2406.         repars = 1;        /* Just set reparse flag and... */
  2407.         continue;
  2408. #ifdef OS2
  2409.           case -7:            /* They typed a disk letter */
  2410.         if (!zchdir((char *)cmdbuf)) {
  2411.             perror((char *)cmdbuf);
  2412.             success = 0;
  2413.         } else success = 1;
  2414.         repars = 0;
  2415.         continue;
  2416.  
  2417. #endif /* OS2 */
  2418.           case -6:            /* Invalid command given w/no args */
  2419.           case -2:            /* Invalid command given w/args */
  2420. #ifdef COMMENT
  2421. #ifndef NOSPL
  2422.             /* This is going to be really ugly... */
  2423.             yy = mlook(mactab,atmbuf,nmac); /* Look in macro table */
  2424.             if (yy > -1) {                /* If it's there */
  2425.             if (zz == -2) {                /* insert "do" */
  2426.                 char *mp;
  2427.                 mp = malloc((int)strlen(cmdbuf) + 5);
  2428.                 if (!mp) {
  2429.                 printf("?malloc error 1\n");
  2430.                 return(-2);
  2431.                 }
  2432.                 sprintf(mp,"do %s ",cmdbuf);
  2433.                 strcpy(cmdbuf,mp);
  2434.                 free(mp);
  2435.                 mp = NULL;
  2436.             } else sprintf(cmdbuf,"do %s %c",atmbuf, CR);
  2437.             if (ifcmd[cmdlvl] == 2)    /* This one doesn't count! */
  2438.               ifcmd[cmdlvl]--;
  2439.             debug(F111,"stuff cmdbuf",cmdbuf,zz);
  2440.             repars = 1;    /* Go for reparse */
  2441.             continue;
  2442.             } else {
  2443.             char *p;
  2444.             int n;
  2445.             p = cmdbuf;
  2446.             lp = line;
  2447.             n = LINBUFSIZ;
  2448.             if (cmflgs == 0) printf("\n");
  2449.             if (zzstring(p,&lp,&n) > -1)
  2450.               printf("?Invalid: %s\n",line);
  2451.             else
  2452.               printf("?Invalid: %s\n",cmdbuf);
  2453.             } /* (fall thru...) */
  2454. #else
  2455.             printf("?Invalid: %s\n",cmdbuf);
  2456. #endif /* NOSPL */
  2457. #else /* Not COMMENT */
  2458.             printf("?Invalid: %s\n",cmdbuf);
  2459. #endif /* COMMENT */
  2460.  
  2461.         case -9:        /* Bad, error message already done */
  2462.             success = 0;
  2463.             debug(F110,"top-level cmkey failed",cmdbuf,0);
  2464.             /* If in background w/ commands coming stdin, terminate */
  2465.             if (pflag == 0 && tlevel < 0)
  2466.               fatal("Kermit command error in background execution");
  2467. /*
  2468.   Command retry feature, edit 190.  If we're at interactive prompting level,
  2469.   reprompt the user with as much of the command as didn't fail.
  2470. */
  2471. #ifdef CK_RECALL
  2472.             if (cm_retry && !cmdsrc()) { /* If at top level */
  2473.             int len;
  2474.             char *p, *s;
  2475.             len = strlen(cmdbuf); /* Length of command buffer */
  2476.             p = malloc(len + 1);  /* Allocate space for copy */
  2477.             if (p) {          /* If we got the space */
  2478.                 strcpy(p,cmdbuf); /* copy the command buffer. */
  2479.                 /* Chop off final field, the one that failed. */
  2480.                 s = p + len - 1;          /* Point to end */
  2481.                 while (*s == SP && s > p) /* Trim blanks */
  2482.                   s--;
  2483.                 while (*s != SP && s > p) /* Trim last field */
  2484.                   s--;
  2485.                 if (s > p)        /* Keep the space */
  2486.                   s++;          /* after last good field */
  2487.                 if (s >= p)          /* Cut off remainder */
  2488.                   *s = NUL;
  2489.                 cmini(ckxech);    /* Reinitialize the parser */
  2490.                 strcpy(cmdbuf,p); /* Copy truncated cmd back */
  2491.                 free(p);          /* Free temporary storage */
  2492.                 p = NULL;
  2493.                 prompt(xxstring); /* Reprint the prompt */
  2494.                 printf("%s",cmdbuf); /* Reprint partial command */
  2495.                 repars = 1;          /* Force reparse */
  2496.                 continue;
  2497.             }
  2498.             } else
  2499. #endif /* CK_RECALL */
  2500.               if (!quiet) {
  2501. #ifdef COMMENT
  2502. #ifndef NOSPL
  2503.               if (maclvl > -1)
  2504.                 printf("Macro: %s; ",
  2505.                    m_arg[maclvl][0] ?
  2506.                    m_arg[maclvl][0] : "");
  2507. #endif /* NOSPL */
  2508.               if (tlevel > -1)
  2509.                 printf("Command file: %s, line %d\n",
  2510.                    tfnam[tlevel] ? tfnam[tlevel] : "",
  2511.                    tfline[tlevel]
  2512.                    );
  2513. #else
  2514.               if (cmdsrc() > 0) {
  2515.                   printf("Command stack:\n");
  2516.                   shostack();
  2517.               }
  2518. #endif /* COMMENT */
  2519.               }
  2520.               cmini(ckxech);    /* (fall thru) */
  2521.  
  2522.              case -3:        /* Empty command OK at top level */
  2523.             repars = 0;        /* Don't need to reparse. */
  2524.             continue;        /* Go back and get another command. */
  2525.  
  2526.         default:        /* Command was successful. */
  2527. #ifndef NOSPL
  2528.             debug(F101,"parser preparing to continue","",maclvl);
  2529. #endif /* NOSPL */
  2530.             repars = 0;        /* Don't need to reparse. */
  2531.             continue;        /* Go back and get another command. */
  2532.         }
  2533.     }
  2534. #ifndef NOSPL
  2535.     debug(F101,"parser breaks out of while loop","",maclvl);
  2536.     if (m && (cmdlvl < inlevel))  return((int) sstate);
  2537. #endif /* NOSPL */
  2538.     }
  2539.  
  2540. /* Got an action command, return start state. */
  2541.  
  2542.     return((int) sstate);
  2543. }
  2544.  
  2545. #ifndef NOSPL
  2546. /*
  2547.   OUTPUT command.
  2548.   Buffering and pacing added by L.I. Kirby, 5A(189), June 1993.
  2549. */
  2550. #define OBSIZE 80            /* Size of local character buffer */
  2551.  
  2552. static int obn;                /* Buffer offset (high water mark) */
  2553. static char obuf[OBSIZE+1];        /* OUTPUT buffer. */
  2554. static char *obp;            /* Pointer to output buffer. */
  2555. _PROTOTYP( static int oboc, (char) );
  2556. _PROTOTYP( static int xxout, (char *, int) );
  2557.  
  2558. static int
  2559. #ifdef CK_ANSIC
  2560. xxout(char *obuf, int obsize)
  2561. #else
  2562. xxout(obuf, obsize) char *obuf; int obsize;
  2563. #endif /* CK_ANSIC */
  2564. /* xxout */ {                /* OUTPUT command's output function */
  2565.     int i, rc;
  2566.  
  2567.     debug(F101,"xxout obsize","",obsize);
  2568.     debug(F101,"xxout pacing","",pacing);
  2569.     debug(F111,"xxout string",obuf,strlen(obuf));
  2570.  
  2571.     rc = 0;                /* Initial return code. */
  2572.     if (!obuf || (obsize <= 0))        /* Nothing to output. */
  2573.       goto xxout_x;            /* Return successfully */
  2574.  
  2575.     rc = -1;                  /* Now assume failure */
  2576.     if (pacing == 0) {              /* Is pacing enabled? */
  2577.     if ((local ?               /* No, write entire string at once */
  2578.          ttol((CHAR *)obuf, obsize) : /* to communications device */
  2579.          conxo(obsize, obuf))      /* or to console */
  2580.         != obsize)
  2581.       goto xxout_x;
  2582.     } else {
  2583.     for (i = 0; i < obsize; i++) {    /* Write individual chars */
  2584.         if ((local ? ttoc(obuf[i]) : conoc(obuf[i])) < 0)
  2585.           goto xxout_x;
  2586.         msleep(pacing);
  2587.     }
  2588.     }
  2589.     if (duplex) {
  2590. #ifdef OS2
  2591.         if (inecho && local) {
  2592.             for (i = 0; i < obsize; i++) { /* Write to emulator */
  2593.                 scriptwrtbuf((USHORT)obuf[i]); /* which also logs session */
  2594.             }
  2595.             conxo(obsize,obuf);
  2596.         } else if (seslog) {        /* or log session here */
  2597.             logstr((char *) obuf, obsize);
  2598.         }
  2599. #else /* OS2 */
  2600.         if (seslog) {
  2601.             logstr((char *) obuf, obsize);
  2602.     }
  2603.         if (inecho && local) {
  2604.             conxo(obsize,obuf);
  2605.         }
  2606. #endif /* OS2 */
  2607.     }
  2608.     rc = 0;                /* Success */
  2609.   xxout_x:
  2610.     obn = 0;                /* Reset count */
  2611.     obp = obuf;                /* and pointers */
  2612.     return(rc);                /* return our return code */
  2613. }
  2614.  
  2615. #ifdef COMMENT
  2616. /*
  2617.   Macros for OUTPUT command execution, to make it go faster.
  2618. */
  2619. #define obfls() ((xxout(obuf,obn)<0)?-1:0)
  2620. #define oboc(c) ((*obp++=(char)(c)),*obp=0,(((++obn)>=OBSIZE)?obfls():0))
  2621.  
  2622. #else /* The macros cause some compilers to generate bad code. */
  2623.  
  2624. static int
  2625. #ifdef CK_ANSIC
  2626. oboc(char c)
  2627. #else
  2628. oboc(c) char c;
  2629. #endif /* CK_ANSIC */
  2630. /* oboc */ {                /* OUTPUT command's output function */
  2631.  
  2632.     *obp++ = c;                /* Deposit character */
  2633.     *obp = NUL;                /* Flush buffer if it's now full */
  2634.  
  2635.     return(((++obn) >= OBSIZE) ? xxout(obuf,obn) : 0);
  2636. }
  2637. #endif /* COMMENT */
  2638.  
  2639. /*  Routines for handling local variables -- also see popclvl().  */
  2640.  
  2641. VOID
  2642. freelocal(m) int m; {            /* Free local variables */
  2643.     struct localvar * v, * tv;        /* at macro level m... */
  2644.     debug(F101,"freelocal level","",m);
  2645.     if (m < 0) return;
  2646.     v = localhead[m];            /* List head for level m */
  2647.     while (v) {
  2648.     if (v->lv_name)            /* Variable name */
  2649.       free(v->lv_name);
  2650.     if (v->lv_value)        /* Value */
  2651.       free(v->lv_value);
  2652.     tv = v;                /* Save pointer to this node */
  2653.     v = v->lv_next;            /* Get next one */
  2654.     if (tv)                /* Free this one */
  2655.       free(tv);
  2656.     }
  2657.     localhead[m] = (struct localvar *) NULL; /* Done, set list head to NULL */
  2658. }
  2659.  
  2660. #define MAXLOCALVAR 64
  2661.  
  2662. int
  2663. dolocal() {                /* Do the LOCAL command */
  2664.     int i, x, z;
  2665.     char * s, * p;
  2666.     char * list[MAXLOCALVAR+2];        /* Up to 64 variables per line */
  2667.     int fe;
  2668.     struct localvar * v, *prev = (struct localvar *)NULL;
  2669.     extern int tra_asg; int tra_tmp;
  2670.  
  2671.     tra_tmp = tra_asg;
  2672.  
  2673.     if ((x = cmtxt("Variable name(s)","",&s,NULL)) < 0)
  2674.       return(x);
  2675.  
  2676.     xwords(s,MAXLOCALVAR,list,0);    /* Break up line into "words" */
  2677. /*
  2678.   loop thru variable list.
  2679.   if variable is defined, allocate a node for it,
  2680.   copy its value to the node,
  2681.   and undefine it.
  2682. */
  2683.     if (v = localhead[cmdlvl]) {    /* Already have some at this level? */
  2684.     while (v) {            /* Find end of list */
  2685.         prev = v;
  2686.         v = v->lv_next;
  2687.     }
  2688.     }
  2689.     /* Note: Arrays do not use the localhead list, but have their own stack */
  2690.  
  2691.     for (i = 1; i < MAXLOCALVAR && list[i]; i++) { /* Go through the list */
  2692.     p = list[i];            /* This element */
  2693.     if (*p == CMDQ) {        /* Starts with backslash? */
  2694.         int xx;
  2695.         if (*(p+1) == '&') {    /* Array? */
  2696.         xx = arraynam(p,&x,&z);    /* Check name but not whether it */
  2697.         if (xx < 0 && z != -17)    /* is defined. */
  2698.           continue;
  2699.         if (z == -17) z = 0;    /* Secret code for empty brackets */
  2700.         pusharray(x,z);        /* It's an array name, push it */
  2701.         continue;
  2702.         } else if (parsevar(p,&x,&z) < 0) /* Variable other than array */
  2703.           continue;
  2704.         sprintf(tmpbuf,"\\fcontents(%s)",p); /* Get definition */
  2705.     } else {            /* Macro */
  2706.         sprintf(tmpbuf,"\\fdefinition(%s)",p); /* Get def */
  2707.     }
  2708.     debug(F110,"dolocal tmpbuf",tmpbuf,0);
  2709.     s = line;            /* Point to destination buffer */
  2710.     x = LINBUFSIZ;            /* Length of destination buffer */
  2711.     zzstring(tmpbuf,&s,&x);        /* Get definition */
  2712.     debug(F110,"dolocal line",line,0);
  2713.  
  2714. /* Name is in list[i], definition is in line[] */
  2715.  
  2716.     v = (struct localvar *) malloc(sizeof(struct localvar));
  2717.     if (!v) {
  2718.         printf("?Failure to allocate storage for local variables");
  2719.         return(-9);
  2720.     }
  2721.     if (!localhead[cmdlvl])        /* If first, set list head */
  2722.       localhead[cmdlvl] = v;
  2723.     else                /* Otherwise link previous to this */
  2724.       prev->lv_next = v;
  2725.     prev = v;            /* And make this previous */
  2726.     v->lv_next = (struct localvar *) NULL; /* No next yet */
  2727.  
  2728.     if (!(v->lv_name = (char *) malloc((int) strlen(list[i]) + 1)))
  2729.       goto localbad;
  2730.     strcpy(v->lv_name, list[i]);    /* Copy name into new node */
  2731.  
  2732.     if (*line) {
  2733.         if (!(v->lv_value = (char *) malloc((int) strlen(line) + 1)))
  2734.           goto localbad;
  2735.         strcpy(v->lv_value, line);    /* Copy value into new node */
  2736.     } else
  2737.       v->lv_value = NULL;
  2738.  
  2739.     tra_asg = 0;
  2740.     delmac(list[i]);        /* Delete the original macro */
  2741.     tra_asg = tra_tmp;
  2742.     }
  2743.     return(success = 1);
  2744.  
  2745.   localbad:
  2746.     printf("?Failure to allocate storage for local variables");
  2747.     freelocal(cmdlvl);
  2748.     return(-9);
  2749. }
  2750.  
  2751. /*  D O O U T P U T  --  Returns 0 on failure, 1 on success */
  2752.  
  2753. #ifndef NOKVERBS
  2754. #define K_BUFLEN 30
  2755. #define SEND_BUFLEN 255
  2756. #define sendbufd(x) { osendbuf[sendndx++] = x;\
  2757.  if (sendndx == SEND_BUFLEN) {dooutput(s,cx); sendndx = 0;}}
  2758. #endif /* NOKVERBS */
  2759.  
  2760. int outesc = 1;                /* Process special OUTPUT escapes */
  2761.  
  2762. int
  2763. dooutput(s, cx) char *s; int cx; {
  2764.  
  2765.     int x, xx, y, quote;        /* Workers */
  2766.     int is_tn = 0;
  2767.  
  2768.     is_tn = (local && network && ttnproto == NP_TELNET) ||
  2769.       (!local && sstelnet);
  2770.  
  2771.     debug(F111,"dooutput s",s,(int)strlen(s));
  2772.  
  2773.     if (local) {            /* Condition external line */
  2774. #ifdef NOLOCAL
  2775.     goto outerr;
  2776. #else
  2777.     if (ttchk() < 0) {
  2778.         printf("?Connection %s %s is not open.\n",
  2779.            network ? "to" : "on",
  2780.            ttname
  2781.            );
  2782.         return(0);
  2783.     }
  2784.     if (ttvt(speed,flow) < 0) {
  2785.         printf("?OUTPUT initialization error\n");
  2786.         return(0);
  2787.     }
  2788. #endif /* NOLOCAL */
  2789.     }
  2790.     if (!cmdgquo()) {            /* COMMAND QUOTING OFF */
  2791.     x = strlen(s);            /* Just send the string literally */
  2792.     xx = local ? ttol((CHAR *)s,x) : conxo(x,s);
  2793.     return(success = (xx == x) ? 1 : 0);
  2794.     }
  2795.     quote = 0;                /* Initialize backslash (\) quote */
  2796.     obn = 0;                /* Reset count */
  2797.     obp = obuf;                /* and pointers */
  2798.  
  2799.   outagain:
  2800.     while (x = *s++) {            /* Loop through the string */
  2801.     y = 0;                /* Error code, 0 = no error. */
  2802.     debug(F000,"dooutput","",x);
  2803.     if (quote) {            /* This character is quoted */
  2804. #ifndef NOKVERBS
  2805.            if (x == 'k' || x == 'K') {    /* \k or \K */
  2806.                extern struct keytab kverbs[];
  2807.                extern int nkverbs;
  2808.                extern char * keydefptr;
  2809.                extern int keymac;
  2810.                extern int keymacx;
  2811.                int x, y, brace = 0;
  2812.                int pause;
  2813.                char * p, * b;
  2814.                char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  2815.            char osendbuf[SEND_BUFLEN +1];
  2816.                int  sendndx = 0;
  2817.  
  2818.            if (xxout(obuf,obn) < 0) /* Flush buffer */
  2819.          goto outerr;
  2820.            debug(F100,"OUTPUT KVERB","",0); /* Send a KVERB */
  2821.                {            /* Have K verb? */
  2822.            if (!*s) {
  2823.                        break;
  2824.                    }
  2825. /*
  2826.   We assume that the verb name is {braced}, or it extends to the end of the
  2827.   string, s, or it ends with a space, control character, or backslash.
  2828. */
  2829.                    p = kbuf;        /* Copy verb name into local buffer */
  2830.                    x = 0;
  2831.                    while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  2832.                        if (brace && *s == '}') {
  2833.                            break;
  2834.                        }
  2835.                        *p++ = *s++;
  2836.                    }
  2837.                    if (*s && !brace)    /* If we broke because of \, etc, */
  2838.                      s--;        /*  back up so we get another look. */
  2839.                    brace = 0;
  2840.                    *p = NUL;        /* Terminate. */
  2841.                    p = kbuf;        /* Point back to beginning */
  2842.                    debug(F110,"dooutput kverb",p,0);
  2843.                    y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  2844.                    debug(F101,"dooutput lookup",0,y);
  2845.                    if (y > -1) {
  2846.                        if (sendndx) {
  2847.                            dooutput(osendbuf,cx);
  2848.                            sendndx = 0;
  2849.                        }
  2850.                        dokverb(VCMD,y);
  2851. #ifndef NOSPL
  2852.                    } else {        /* Is it a macro? */
  2853.                        y = mxlook(mactab,p,nmac);
  2854.                        if (y > -1) {
  2855.                            cmpush();
  2856.                            keymac = 1;    /* Flag for key macro active */
  2857.                            keymacx = y;    /* Key macro index */
  2858.                            keydefptr = s; /* Where to resume next time */
  2859.                            debug(F111,"dooutput mxlook",keydefptr,y);
  2860.                            parser(1);
  2861.                            cmpop();
  2862.                        }
  2863. #endif /* NOSPL */
  2864.                    }
  2865.                }
  2866.                quote = 0;
  2867.            continue;
  2868.        } else
  2869. #endif /* NOKVERBS */
  2870.          if (outesc && (x == 'n' || x == 'N')) { /* \n or \N */
  2871.          if (xxout(obuf,obn) < 0) /* Flush buffer */
  2872.            goto outerr;
  2873.          debug(F100,"OUTPUT NUL","",0); /* Send a NUL */
  2874.          if (local)
  2875.            ttoc(NUL);
  2876.          else
  2877.            conoc(NUL);
  2878.          quote = 0;
  2879.          continue;
  2880.  
  2881.          } else if (outesc && (x == 'b' || x == 'B')) { /* \b or \B */
  2882.  
  2883.         if (xxout(obuf,obn) < 0) /* Flush buffer first */
  2884.           goto outerr;
  2885.         debug(F100,"OUTPUT BREAK","",0);
  2886. #ifndef NOLOCAL
  2887.         ttsndb();        /* Send BREAK signal */
  2888. #else
  2889.          if (local)
  2890.            ttoc(NUL);
  2891.          else
  2892.            conoc(NUL);
  2893. #endif /* NOLOCAL */
  2894.         quote = 0;        /* Turn off quote flag */
  2895.         continue;        /* and not the b or B */
  2896. #ifdef CK_LBRK
  2897.          } else if (outesc && (x == 'l' || x == 'L')) { /* \l or \L */
  2898.          if (xxout(obuf,obn) < 0) /* Flush buffer first */
  2899.            goto outerr;
  2900.          debug(F100,"OUTPUT Long BREAK","",0);
  2901. #ifndef NOLOCAL
  2902.          ttsndlb();        /* Send Long BREAK signal */
  2903. #else
  2904.          if (local)
  2905.            ttoc(NUL);
  2906.          else
  2907.            conoc(NUL);
  2908. #endif /* NOLOCAL */
  2909.          quote = 0;        /* Turn off quote flag */
  2910.          continue;        /* and not the l or L */
  2911. #endif /* CK_LBRK */
  2912.  
  2913.          } else if (x == CMDQ) {    /* Backslash itself */
  2914.          debug(F100,"OUTPUT CMDQ","",0);
  2915.          xx = oboc(dopar(CMDQ)); /* Output the backslash. */
  2916.          if (xx < 0)
  2917.            goto outerr;
  2918.          quote = 0;
  2919.          continue;
  2920.  
  2921.          } else {            /* if \ not followed by special esc */
  2922.         /* Note: Atari ST compiler won't allow macro call in "if ()" */
  2923.          xx = oboc(dopar(CMDQ)); /* Output the backslash. */
  2924.          if (xx < 0)
  2925.            goto outerr;
  2926.          quote = 0;        /* Turn off quote flag */
  2927.          }
  2928.     } else if (x == CMDQ) {        /* This is the quote character */
  2929.             quote = 1;            /* Go back and get next character */
  2930.         continue;            /* which is quoted */
  2931.     }
  2932.     xx = oboc(dopar((char)x));    /* Output this character */
  2933.     debug(F111,"dooutput",obuf,obn);
  2934.     if (xx < 0)
  2935.       goto outerr;
  2936. #ifdef COMMENT
  2937.         if (seslog && duplex) {        /* Log the character if log is on */
  2938.             logchar((char)x);
  2939.         }
  2940. #endif /* COMMENT */
  2941.     if (x == '\015') {        /* String contains carriage return */
  2942.         int stuff = -1, stuff2 = -1;
  2943.         if (tnlm) {            /* TERMINAL NEWLINE ON */
  2944.         stuff = LF;        /* Stuff LF */
  2945.         }
  2946. #ifdef TNCODE
  2947.         /* TELNET NEWLINE ON/OFF/RAW */
  2948.         if (is_tn) {
  2949.         switch (TELOPT_ME(TELOPT_BINARY) ? /* NVT or BINARY */
  2950.             tn_b_nlm :
  2951.             tn_nlm
  2952.             ) {
  2953.           case TNL_CR:
  2954.                     break;
  2955.           case TNL_CRNUL:
  2956.                     stuff2 = stuff;
  2957.                     stuff  = NUL;
  2958.                     break;
  2959.           case TNL_CRLF:
  2960.                     stuff2 = stuff;
  2961.                     stuff = LF;
  2962.                     break;
  2963.                 }
  2964.             }
  2965. #endif /* TNCODE */
  2966.         if (stuff > -1) {        /* Stuffing another character... */
  2967.         xx = oboc(dopar((CHAR)stuff));
  2968.         if (xx < 0)
  2969.           goto outerr;
  2970. #ifdef COMMENT
  2971.         if (seslog && duplex) {    /* Log stuffed char if appropriate */
  2972.                     logchar((char)stuff);
  2973.                 }
  2974. #endif /* COMMENT */
  2975.         }
  2976.         if (stuff2 > -1) {        /* Stuffing another character... */
  2977.         xx = oboc(dopar((CHAR)stuff2));
  2978.         if (xx < 0)
  2979.           goto outerr;
  2980. #ifdef COMMENT
  2981.         if (seslog && duplex) {    /* Log stuffed char if appropriate */
  2982.                     logchar((char)stuff2);
  2983.                 }
  2984. #endif /* COMMENT */
  2985.         }
  2986.         if (xxout(obuf,obn) < 0)    /* Flushing is required here! */
  2987.           goto outerr;
  2988.     }
  2989.     }
  2990.     if (cx == XXLNOUT) {
  2991.     s = "\015";
  2992.     cx = 0;
  2993.     goto outagain;
  2994.     }
  2995.     if (quote == 1)            /* String ended with backslash */
  2996.       xx = oboc(dopar(CMDQ));
  2997.  
  2998.     if (obn > 0)            /* OUTPUT done */
  2999.       if (xxout(obuf,obn) < 0)        /* Flush the buffer if necessary. */
  3000.     goto outerr;
  3001.     return(1);
  3002.  
  3003. outerr:                    /* OUTPUT command error handler */
  3004.     if (msgflg) printf("?OUTPUT execution error\n");
  3005.     return(0);
  3006.  
  3007. /* Remove "local" OUTPUT macro defininitions */
  3008.  
  3009. #ifdef COMMENT
  3010. /* No more macros ... */
  3011. #undef oboc
  3012. #undef obfls
  3013. #endif /* COMMENT */
  3014. }
  3015. #endif /* NOSPL */
  3016.  
  3017. /* Display version herald and initial prompt */
  3018.  
  3019. VOID
  3020. herald() {
  3021.     int x = 0, i;
  3022.     extern int srvcdmsg;
  3023.     extern char * cdmsgfile[];
  3024. #ifndef NOCMDL
  3025.     extern char * bannerfile;
  3026.     if (bannerfile) {
  3027.     concb((char)escape);
  3028.     if (dotype(bannerfile,1,0,0,NULL,0,NULL) > 0) {
  3029.         if (srvcdmsg) {
  3030.         for (i = 0; i < 8; i++) {
  3031.             if (zchki(cdmsgfile[i]) > -1) {
  3032.             printf("\n");
  3033.             dotype(cdmsgfile[i],xaskmore,0,0,NULL,0,NULL);
  3034.             break;
  3035.             }
  3036.         }
  3037.         }
  3038.             return;
  3039.         }
  3040.     }
  3041. #endif /* NOCMDL */
  3042.  
  3043. #ifdef COMMENT
  3044.     /* The following generates bad code in SCO compilers. */
  3045.     /* Observed in both OSR5 and Unixware 2 -- after executing this */
  3046.     /* statement when all conditions are false, x has a value of -32. */
  3047.     if (noherald || bgset > 0 || (bgset != 0 && backgrd != 0)) x = 1;
  3048. #else
  3049.     x = 0;
  3050.     if (noherald)
  3051.       x = 1;
  3052.     else if (bgset > 0)
  3053.       x = 1;
  3054.     else if (bgset < 0 && backgrd > 0)
  3055.       x = 1;
  3056. #endif /* COMMENT */
  3057.  
  3058.     if (x == 0) {
  3059. #ifdef datageneral
  3060.     printf("%s, for%s\n",versio,ckxsys);
  3061. #else
  3062. #ifdef OSK
  3063.     printf("%s, for%s\n",versio,ckxsys);
  3064. #else
  3065.     printf("%s, for%s\n\r",versio,ckxsys);
  3066. #endif /* OSK */
  3067. #endif /* datageneral */
  3068.     printf(" Copyright (C) 1985, 2000,\n");
  3069.     printf("  Trustees of Columbia University in the City of New York.\n");
  3070.  
  3071. #ifdef OS2
  3072.        shoreg();
  3073. #endif /* OS2 */
  3074.  
  3075.     if (!quiet && !backgrd) {
  3076. #ifdef COMMENT
  3077. /* "Default file-transfer mode is AUTOMATIC" is useless information... */
  3078.         char * s;
  3079.         extern int xfermode;
  3080. #ifdef VMS
  3081.         s = "AUTOMATIC";
  3082. #else
  3083.         if (xfermode == XMODE_A) {
  3084.         s = "AUTOMATIC";
  3085.         } else {
  3086.         s = gfmode(binary,1);
  3087.         }
  3088.         if (!s) s = "";
  3089. #endif /* VMS */
  3090.         if (*s)
  3091.           printf("Default file-transfer mode is %s\n", s);
  3092. #endif /* COMMENT */
  3093.  
  3094.         if (srvcdmsg) {
  3095.         for (i = 0; i < 8; i++) {
  3096.             if (zchki(cdmsgfile[i]) > -1) {
  3097.             printf("\n");
  3098.             dotype(cdmsgfile[i],xaskmore,0,0,NULL,0,NULL);
  3099.             break;
  3100.             }
  3101.         }
  3102.         }
  3103.         printf("Type ? or HELP for help.\n");
  3104.     }
  3105.     }
  3106. }
  3107.  
  3108. /*  G F M O D E  --  Get File (transfer) Mode  */
  3109.  
  3110. char *
  3111. gfmode(binary,upcase) int binary, upcase; {
  3112.     char * s;
  3113.     switch (binary) {
  3114.       case XYFT_T: s = upcase ? "TEXT" : "text"; break;
  3115. #ifdef VMS
  3116.       case XYFT_B: s = upcase ? "BINARY FIXED" : "binary fixed"; break;
  3117.       case XYFT_I: s = upcase ? "IMAGE" : "image"; break;
  3118.       case XYFT_L: s = upcase ? "LABELED" : "labeled"; break;
  3119.       case XYFT_U: s = upcase ? "BINARY UNDEF" : "binary undef"; break;
  3120. #else
  3121. #ifdef MAC
  3122.       case XYFT_B: s = upcase ? "BINARY" : "binary"; break;
  3123.       case XYFT_M: s = upcase ? "MACBINARY" : "macbinary"; break;
  3124. #else
  3125.       case XYFT_B: s = upcase ? "BINARY" : "binary"; break;
  3126. #ifdef CK_LABELED
  3127.       case XYFT_L: s = upcase ? "LABELED" : "labeled"; break;
  3128. #endif /* CK_LABELED */
  3129. #endif /* MAC */
  3130. #endif /* VMS */
  3131.       default: s = "";
  3132.     }
  3133.     return(s);
  3134. }
  3135.  
  3136. #ifndef NOSPL
  3137. static int
  3138. isaa(s) char * s; {            /* Is associative array */
  3139.     char c;
  3140.     int x;
  3141.     if (!s) s = "";
  3142.     if (!*s) return(0);
  3143.     s++;
  3144.     while (c = *s++) {
  3145.     if (c == '<') {
  3146.         x = strlen(s);
  3147.         return ((*(s+x-1) == '>') ? 1 : 0);
  3148.     }
  3149.     }
  3150.     return(0);
  3151. }
  3152.  
  3153. /*  M L O O K  --  Lookup the macro name in the macro table  */
  3154.  
  3155. /*
  3156.  Call this way:  v = mlook(table,word,n);
  3157.  
  3158.    table - a 'struct mtab' table.
  3159.    word  - the target string to look up in the table.
  3160.    n     - the number of elements in the table.
  3161.  
  3162.  The keyword table must be arranged in ascending alphabetical order, and
  3163.  all letters must be lowercase.
  3164.  
  3165.  Returns the table index, 0 or greater, if the name was found, or:
  3166.  
  3167.   -3 if nothing to look up (target was null),
  3168.   -2 if ambiguous,
  3169.   -1 if not found.
  3170.  
  3171.  A match is successful if the target matches a keyword exactly, or if
  3172.  the target is a prefix of exactly one keyword.  It is ambiguous if the
  3173.  target matches two or more keywords from the table.
  3174. */
  3175. int
  3176. mlook(table,cmd,n) struct mtab table[]; char *cmd; int n; {
  3177.  
  3178.     int x, i, v, cmdlen;
  3179.  
  3180. /* Lowercase & get length of target, if it's null return code -3. */
  3181.  
  3182.     if ((((cmdlen = cklower(cmd))) == 0) || (n < 1)) return(-3);
  3183.  
  3184. /* Not null, look it up */
  3185.  
  3186.     for (i = 0; i < n-1; i++) {
  3187.         if (!strcmp(table[i].kwd,cmd) ||
  3188.            ((v = !strncmp(table[i].kwd,cmd,cmdlen)) &&
  3189.              strncmp(table[i+1].kwd,cmd,cmdlen))) {
  3190.                 return(i);
  3191.              }
  3192.         if (v) return(-2);
  3193.     }
  3194.  
  3195. /* Last (or only) element */
  3196.  
  3197.     if (!strncmp(table[n-1].kwd,cmd,cmdlen)) {
  3198.         return(n-1);
  3199.     } else return(-1);
  3200. }
  3201.  
  3202. /* mxlook is like mlook, but an exact full-length match is required */
  3203.  
  3204. int
  3205. mxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  3206.     int i, cmdlen;
  3207.     if ((((cmdlen = cklower(cmd))) == 0) || (n < 1)) return(-3);
  3208.     /* debug(F111,"mxlook target",cmd,n); */
  3209.     for (i = 0; i < n; i++) {
  3210.     /* debug(F111,"mxlook",table[i].kwd,i); */
  3211.     if (((int)strlen(table[i].kwd) == cmdlen) &&
  3212.         (!strncmp(table[i].kwd,cmd,cmdlen))) return(i);
  3213.     }
  3214.     return(-1);
  3215. }
  3216.  
  3217. /* mxxlook is like mxlook, but but case-sensitive */
  3218.  
  3219. int
  3220. mxxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  3221.     int i, cmdlen;
  3222.     if (!cmd) cmd = "";
  3223.     if (((cmdlen = strlen(cmd)) < 1) || (n < 1)) return(-3);
  3224.     /* debug(F111,"mxxlook target",cmd,n); */
  3225.     for (i = 0; i < n; i++) {
  3226.     if (((int)strlen(table[i].kwd) == cmdlen) &&
  3227.         (!strncmp(table[i].kwd,cmd,cmdlen))) return(i);
  3228.     }
  3229.     return(-1);
  3230. }
  3231.  
  3232. static int
  3233. traceval(nam, val) char * nam, * val; {    /* For TRACE command */
  3234.     if (val)
  3235.       printf(">>> %s: \"%s\"\n", nam, val);
  3236.     else
  3237.       printf(">>> %s: (undef)\n", nam);
  3238.     return(0);
  3239. }
  3240.  
  3241. /*
  3242.   This routine is for the benefit of those compilers that can't handle
  3243.   long string constants or continued lines within them.  Long predefined
  3244.   macros like FOR, WHILE, and XIF have their contents broken up into
  3245.   arrays of string pointers.  This routine concatenates them back into a
  3246.   single string again, and then calls the real addmac() routine to enter
  3247.   the definition into the macro table.
  3248. */
  3249. int
  3250. addmmac(nam,s) char *nam, *s[]; {    /* Add a multiline macro definition */
  3251.     int i, x, y; char *p;
  3252.     x = 0;                /* Length counter */
  3253.     for (i = 0; (y = (int)strlen(s[i])) > 0; i++) { /* Add up total length */
  3254.         debug(F111,"addmmac line",s[i],y);
  3255.     x += y;
  3256.     }
  3257.     debug(F101,"addmmac lines","",i);
  3258.     debug(F101,"addmmac loop exit","",y);
  3259.     debug(F111,"addmmac length",nam,x);
  3260.     if (x < 0) return(-1);
  3261.  
  3262.     p = malloc(x+1);            /* Allocate space for all of it. */
  3263.     if (!p) {
  3264.     printf("?addmmac malloc error: %s\n",nam);
  3265.     debug(F110,"addmmac malloc error",nam,0);
  3266.     return(-1);
  3267.     }
  3268.     *p = '\0';                /* Start off with null string. */
  3269.     for (i = 0; *s[i]; i++)        /* Concatenate them all together. */
  3270.       strcat(p,s[i]);
  3271.     y = (int)strlen(p);            /* Final precaution. */
  3272.     debug(F111,"addmmac constructed string",p,y);
  3273.     if (y == x) {
  3274.     y = addmac(nam,p);        /* Add result to the macro table. */
  3275.     } else {
  3276.     debug(F100,"addmmac length mismatch","",0);
  3277.     printf("\n!addmmac internal error!\n");
  3278.     y = -1;
  3279.     }
  3280.     free(p);                /* Free the temporary copy. */
  3281.     return(y);
  3282. }
  3283.  
  3284. /* Here is the real addmac routine. */
  3285.  
  3286. /* Returns -1 on failure, macro table index >= 0 on success. */
  3287.  
  3288. int
  3289. addmac(nam,def) char *nam, *def; {    /* Add a macro to the macro table */
  3290.     int i, x, y, z, namlen, deflen;
  3291.     char * p = NULL, c;
  3292.     extern int tra_asg; int tra_tmp;
  3293.  
  3294.     if (!nam) return(-1);
  3295.     namlen = (int)strlen(nam);        /* Get argument lengths */
  3296.     tra_tmp = tra_asg;
  3297.     debug(F111,"addmac nam",nam,namlen);
  3298.     if (!def) {                /* Watch out for null pointer */
  3299.     deflen = 0;
  3300.     debug(F111,"addmac def","(null pointer)",deflen);
  3301.     } else {
  3302.     deflen = (int)strlen(def);
  3303.     debug(F111,"addmac def",def,deflen);
  3304.     }
  3305.     if (deflen < 0) return(-1);        /* strlen() failure, fail. */
  3306.     if (namlen < 1) return(-1);        /* No name given, fail. */
  3307.  
  3308.     if (*nam == CMDQ) nam++;        /* Backslash quote? */
  3309.     if (*nam == '%') {            /* Yes, if it's a variable name, */
  3310.     tra_asg = 0;
  3311.     delmac(nam);            /* Delete any old value. */
  3312.     tra_asg = tra_tmp;
  3313.     if (!(c = *(nam + 1))) return(-1); /* Variable name letter or digit */
  3314.     if (deflen < 1) {        /* Null definition */
  3315.         p = NULL;            /* Better not malloc or strcpy! */
  3316.     } else {            /* A substantial definition */
  3317.         p = malloc(deflen + 1);    /* Allocate space for it */
  3318.         if (!p) {
  3319.         printf("?addmac malloc error 2\n");
  3320.         return(-1);
  3321.         } else strcpy(p,def);    /* Copy definition into new space */
  3322.     }
  3323.  
  3324.     /* Now p points to the definition, or is a null pointer */
  3325.  
  3326.     if (c >= '0' && c <= '9') {    /* Digit variable */
  3327.         if (maclvl < 0) {        /* Are we calling or in a macro? */
  3328.         g_var[c] = p;        /* No, it's a global "top level" one */
  3329.         debug(F101,"addmac numeric global maclvl","",maclvl);
  3330.         makestr(&(toparg[c - '0']),p);
  3331.         } else {            /* Yes, it's a macro argument */
  3332.         m_arg[maclvl][c - '0'] = p; /* Assign the value */
  3333.         debug(F101,"addmac macro arg maclvl","",maclvl);
  3334.         makestr(&(m_xarg[maclvl][c - '0']),p); /* And a copy here */
  3335.         }
  3336.     } else {            /* It's a global variable */
  3337.         if (c < 33 || c > GVARS) return(-1);
  3338.         if (isupper(c)) c = (char) tolower(c);
  3339.         g_var[c] = p;        /* Put pointer in global-var table */
  3340.         debug(F100,"addmac global","",0);
  3341.     }
  3342.     if (tra_asg) traceval(nam,p);
  3343.     return(0);
  3344.     } else if (*nam == '&') {        /* An array reference? */
  3345.     char **q;
  3346.     debug(F110,"addmac array",nam,0);
  3347.     if ((y = arraynam(nam,&x,&z)) < 0) /* If syntax is bad */
  3348.       return(-1);            /* return -1. */
  3349.     if (chkarray(x,z) < 0)        /* If array not declared or */
  3350.       return(-2);            /* subscript out of range, ret -2 */
  3351.     tra_asg = 0;
  3352.     delmac(nam);            /* Delete any old value. */
  3353.     tra_asg = tra_tmp;
  3354.     x -= ARRAYBASE;            /* Convert name letter to index. */
  3355.     if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  3356.       return(-3);            /* return -3. */
  3357.     if (deflen > 0) {
  3358.         if ((p = malloc(deflen+1)) == NULL) { /* Allocate space */
  3359.         printf("addmac macro error 7: %s\n",nam);
  3360.         return(-4);        /* for new def, return -4 on fail. */
  3361.         }
  3362.         strcpy(p,def);        /* Copy definition into new space. */
  3363.     } else p = NULL;
  3364.     q[z] = p;            /* Store pointer to it. */
  3365.     debug(F110,"addmac array val",p,0);
  3366.     if (tra_asg) traceval(nam,p);
  3367.     return(0);            /* Done. */
  3368.     }
  3369.     debug(F110,"addmac macro def",nam,0);
  3370.  
  3371. /* Not a macro argument or a variable, so it's a macro definition */
  3372.  
  3373.     y = isaa(nam);            /* If it's not an associative array */
  3374.     debug(F111,"addmac isaa",nam,y);
  3375.     x = y ? mxxlook(mactab,nam,nmac) : mxlook(mactab,nam,nmac);
  3376.     if (x > -1) {
  3377.     tra_asg = 0;
  3378.     delmac(nam);            /* If it's there, delete it. */
  3379.     tra_asg = tra_tmp;
  3380.     }
  3381.     if (deflen < 1) {
  3382.     if (tra_asg) traceval(nam,p);
  3383.     return(0);
  3384.     }
  3385.     debug(F111,"addmac table size",nam,nmac);
  3386.     for (y = 0;                /* Find the alphabetical slot */
  3387.      y < MAC_MAX && mactab[y].kwd != NULL && strcmp(nam,mactab[y].kwd) > 0;
  3388.      y++);
  3389.     if (y == MAC_MAX) {            /* No more room. */
  3390.     debug(F101,"addmac table overflow","",y);
  3391.     printf("?Macro table overflow\n");
  3392.     return(-1);
  3393.     } else debug(F111,"addmac position",nam,y);
  3394.     if (mactab[y].kwd != NULL) {    /* Must insert */
  3395.     for (i = nmac; i > y; i--) {    /* Move the rest down one slot */
  3396.         mactab[i].kwd = mactab[i-1].kwd;
  3397.         mactab[i].mval = mactab[i-1].mval;
  3398.         mactab[i].flgs = mactab[i-1].flgs;
  3399.     }
  3400.     }
  3401.     p = malloc(namlen + 1);        /* Allocate space for name */
  3402.     if (!p) {
  3403.     printf("?addmac malloc error 3: %s\n",nam);
  3404.     return(-1);
  3405.     }
  3406.     strcpy(p,nam);            /* Copy name into new space */
  3407.     mactab[y].kwd = p;            /* Add pointer to table */
  3408.  
  3409.     if (deflen > 0) {            /* Same deal for definition */
  3410.     p = malloc(deflen + 1);        /* but watch out for null pointer */
  3411.     if (p == NULL) {
  3412.         printf("?addmac malloc error 5: %s\n", nam);
  3413.         if (mactab[y].kwd) {
  3414.         free(mactab[y].kwd);
  3415.         mactab[y].kwd = NULL;
  3416.         }
  3417.         return(-1);
  3418.     } else strcpy(p,def);        /* Copy the definition */
  3419.     } else p = NULL;
  3420.     mactab[y].mval = p;
  3421.     mactab[y].flgs = 0;
  3422.     nmac++;                /* Count this macro */
  3423.     if (tra_asg) traceval(nam,p);
  3424.     return(y);
  3425. }
  3426.  
  3427. int
  3428. xdelmac(x) int x; {            /* Delete a macro given its index */
  3429.     int i;
  3430.     extern int tra_asg;
  3431.     if (x < 0) return(x);
  3432.     if (tra_asg)
  3433.       traceval(mactab[x].kwd,NULL);
  3434.  
  3435.     if (mactab[x].kwd) {        /* Free the storage for the name */
  3436.     free(mactab[x].kwd);
  3437.     mactab[x].kwd = NULL;
  3438.     }
  3439.     if (mactab[x].mval) {        /* and for the definition */
  3440.     free(mactab[x].mval);
  3441.     mactab[x].mval = NULL;
  3442.     }
  3443.     for (i = x; i < nmac; i++) {    /* Now move up the others. */
  3444.     mactab[i].kwd = mactab[i+1].kwd;
  3445.     mactab[i].mval = mactab[i+1].mval;
  3446.     mactab[i].flgs = mactab[i+1].flgs;
  3447.     }
  3448.     nmac--;                /* One less macro */
  3449.  
  3450.     mactab[nmac].kwd = NULL;        /* Delete last item from table */
  3451.     mactab[nmac].mval = NULL;
  3452.     mactab[nmac].flgs = 0;
  3453.     return(0);
  3454. }
  3455.  
  3456.  
  3457. int
  3458. delmac(nam) char *nam; {        /* Delete the named macro */
  3459.     int x, z;
  3460.     char *p, c;
  3461.     extern int tra_asg;
  3462.  
  3463.     if (!nam) return(0);        /* Watch out for null pointer */
  3464.     debug(F110,"delmac nam",nam,0);
  3465.     if (*nam == CMDQ) nam++;
  3466.     if (*nam == '%') {            /* If it's a variable name */
  3467.     if (!(c = *(nam+1))) return(0);    /* Get variable name letter or digit */
  3468.     p = (char *)0;            /* Initialize value pointer */
  3469.     if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */
  3470.         p = m_arg[maclvl][c - '0'];    /* Get pointer from macro-arg table */
  3471.         m_arg[maclvl][c - '0'] = NULL; /* Zero the table pointer */
  3472.     } else {            /* It's a global variable */
  3473.         if (c < 33 || c > GVARS) return(0);
  3474.         p = g_var[c];        /* Get pointer from global-var table */
  3475.         g_var[c] = NULL;        /* Zero the table entry */
  3476.     }
  3477.     if (p) {
  3478.         debug(F110,"delmac def",p,0);
  3479.         free(p);            /* Free the storage */
  3480.         p = NULL;
  3481.     } else debug(F110,"delmac def","(null pointer)",0);
  3482.     if (tra_asg) traceval(nam,NULL);
  3483.     return(0);
  3484.     }
  3485.     if (*nam == '&') {            /* An array reference? */
  3486.     char **q;
  3487.     if (arraynam(nam,&x,&z) < 0)    /* If syntax is bad */
  3488.       return(-1);            /* return -1. */
  3489.     x -= ARRAYBASE;            /* Convert name to number. */
  3490.     if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  3491.       return(-2);            /* return -2. */
  3492.     if (z > a_dim[x])        /* If subscript out of range, */
  3493.       return(-3);            /* return -3. */
  3494.     if (q[z]) {            /* If there is an old value, */
  3495.         debug(F110,"delmac def",q[z],0);
  3496.         if (x != 0)            /* Macro arg vector is just a copy */
  3497.           free(q[z]);        /* Others are real so free them */
  3498.         q[z] = NULL;
  3499.         if (tra_asg) traceval(nam,NULL);
  3500.     } else debug(F110,"delmac def","(null pointer)",0);
  3501.     }
  3502.  
  3503.    /* Not a variable or an array, so it must be a macro. */
  3504.  
  3505.     z = isaa(nam);
  3506.     debug(F111,"delmac isaa",nam,z);
  3507.     x = z ? mxxlook(mactab,nam,nmac) : mlook(mactab,nam,nmac);
  3508.     if (x < 0) {
  3509.     debug(F111,"delmac mlook",nam,x);
  3510.     return(x);
  3511.     }
  3512.     return(xdelmac(x));
  3513. }
  3514.  
  3515. VOID
  3516. initmac() {                /* Init macro & variable tables */
  3517.     int i, j, x;
  3518.  
  3519.     nmac = 0;                /* No macros */
  3520.     for (i = 0; i < MAC_MAX; i++) {    /* Initialize the macro table */
  3521.     mactab[i].kwd = NULL;
  3522.     mactab[i].mval = NULL;
  3523.     mactab[i].flgs = 0;
  3524.     }
  3525.     x = (MAXARGLIST + 1) * sizeof(char **);
  3526.     for (i = 0; i < MACLEVEL; i++) {    /* Init the macro argument tables */
  3527.     m_xarg[i] = (char **) malloc(x);
  3528.     mrval[i] = NULL;        /* Macro return value */
  3529.     /* Pointer to entire argument vector, level i, for \&_[] array */
  3530.     for (j = 0; j <= MAXARGLIST; j++) { /* Macro argument list */
  3531.         if (j < 10)            /* For the \%0..\%9 variables */
  3532.           m_arg[i][j] = NULL;    /* Pointer to arg j, level i. */
  3533.         if (m_xarg[i])        /* For \&_[] - all args. */
  3534.           m_xarg[i][j] = NULL;
  3535.     }
  3536.     }
  3537.     for (i = 0; i < GVARS; i++) {    /* And the global variables table */
  3538.     g_var[i] = NULL;
  3539.     }
  3540.     /* And the table of arrays */
  3541.     for (i = 0; i < (int) 'z' - ARRAYBASE + 1; i++) {
  3542.     a_ptr[i] = (char **) NULL;    /* Null pointer for each */
  3543.     a_dim[i] = 0;            /* and a dimension of zero */
  3544.     for (j = 0; j < CMDSTKL; j++) {
  3545.         aa_ptr[j][i] = (char **) NULL;
  3546.         aa_dim[j][i] = 0;
  3547.     }
  3548.     }
  3549. }
  3550.  
  3551. int
  3552. popclvl() {                /* Pop command level, return cmdlvl */
  3553.     extern int tra_cmd;
  3554.     struct localvar * v;
  3555.     int i;
  3556.     debug(F101,"popclvl cmdlvl","",cmdlvl);
  3557.     if (cmdlvl > 0) {
  3558.     if (v = localhead[cmdlvl]) {    /* Did we save any variables? */
  3559.         while (v) {            /* Yes */
  3560.         if (v->lv_value)    /* Copy old ones back */
  3561.           addmac(v->lv_name,v->lv_value);
  3562.         else
  3563.           delmac(v->lv_name);
  3564.         v = v->lv_next;
  3565.         }
  3566.         freelocal(cmdlvl);        /* Free local storage */
  3567.     }
  3568.     /* Automatic arrays do not use the localhead list */
  3569.  
  3570.     for (i = 0; i < 28; i++) {    /* Free any local arrays */
  3571.         if (aa_ptr[cmdlvl][i]) { /* Does this one exist? */
  3572.         dclarray((char)(i+ARRAYBASE),0); /* Destroy global one */
  3573.         a_ptr[i] = aa_ptr[cmdlvl][i];
  3574.         a_dim[i] = aa_dim[cmdlvl][i];
  3575.         aa_ptr[cmdlvl][i] = (char **)NULL;
  3576.         aa_dim[cmdlvl][i] = 0;
  3577.         } else if (aa_dim[cmdlvl][i] == -23) { /* Secret code */
  3578.         dclarray((char)(i+ARRAYBASE),0); /* (see pusharray()) */
  3579.         aa_ptr[cmdlvl][i] = (char **)NULL;
  3580.         aa_dim[cmdlvl][i] = 0;
  3581.         }
  3582.         /* Otherwise do nothing - it is a local array that was declared */
  3583.         /* at a level above this one so leave it alone. */
  3584.     }
  3585.     }
  3586.     if (cmdlvl < 1) {            /* If we're already at top level */
  3587.     cmdlvl = 0;            /* just make sure all the */
  3588.     tlevel = -1;            /* stack pointers are set right */
  3589.     maclvl = -1;            /* and return */
  3590.     } else if (cmdstk[cmdlvl].src == CMD_TF) { /* Reading from TAKE file? */
  3591.     debug(F101,"popclvl tlevel","",tlevel);
  3592.     if (tlevel > -1) {        /* Yes, */
  3593.         fclose(tfile[tlevel]);    /* close it */
  3594.         if (tfnam[tlevel]) {    /* free storage for name */
  3595.         free(tfnam[tlevel]);
  3596.         tfnam[tlevel] = NULL;
  3597.         }
  3598.         tlevel--;            /* and pop take level */
  3599.         cmdlvl--;            /* and command level */
  3600.         quiet = xquiet[cmdlvl];
  3601.     } else tlevel = -1;
  3602.     } else if (cmdstk[cmdlvl].src == CMD_MD) { /* In a macro? */
  3603.     debug(F101,"popclvl maclvl","",maclvl);
  3604.     if (maclvl > -1) {        /* Yes, */
  3605. #ifdef COMMENT
  3606.         int i;
  3607.         char **q;
  3608. #endif /* COMMENT */
  3609.         macp[maclvl] = "";        /* set macro pointer to null string */
  3610.         *cmdbuf = '\0';        /* clear the command buffer */
  3611.  
  3612.         if ((maclvl > 0) &&        /* 2 May 1999 */
  3613.         (m_arg[maclvl-1][0]) &&
  3614.         (!strncmp(m_arg[maclvl-1][0],"_xif",4) ||
  3615.          !strncmp(m_arg[maclvl-1][0],"_for",4) ||
  3616.          !strncmp(m_arg[maclvl-1][0],"_swi",4) ||
  3617.          !strncmp(m_arg[maclvl-1][0],"_whi",4)) &&
  3618.         mrval[maclvl+1]) {
  3619.         makestr(&(mrval[maclvl-1]),mrval[maclvl+1]);
  3620.         }
  3621.  
  3622.         if (maclvl+1 < MACLEVEL) {
  3623.         if (mrval[maclvl+1]) {    /* Free any deeper return values. */
  3624.             free(mrval[maclvl+1]);
  3625.             mrval[maclvl+1] = NULL;
  3626.         }
  3627.         }
  3628.         maclvl--;            /* Pop macro level */
  3629.         cmdlvl--;            /* and command level */
  3630.         debug(F101,"popclvl mac new maclvl","",maclvl);
  3631.         debug(F111,"popclvl mac mrval[maclvl+1]",mrval[maclvl+2],maclvl+1);
  3632.  
  3633.         quiet = xquiet[cmdlvl];
  3634. #ifdef COMMENT
  3635.         q = a_ptr[0];
  3636.         debug(F101,"popclvl mac 7","",maclvl);
  3637.         if (maclvl > -1)
  3638.           for (i = 0; i < 10; i++)    /* Restore previous arg vector */
  3639.         q[i] = m_arg[maclvl][i];
  3640. #else
  3641.         if (maclvl > -1) {
  3642.         a_ptr[0] = m_xarg[maclvl];
  3643.         a_dim[0] = n_xarg[maclvl];
  3644.         } else {
  3645.         a_ptr[0] = topxarg;;
  3646.         a_dim[0] = topargc;
  3647.         }
  3648. #endif /* COMMENT */
  3649.     } else maclvl = -1;
  3650.     }
  3651. #ifndef MAC
  3652.     if (cmdlvl < 1) {            /* If back at top level */
  3653.     setint();
  3654.     concb((char)escape);        /* Go into cbreak mode */
  3655.     }
  3656. #endif /* MAC */
  3657.     if (tra_cmd && cmdlvl > 0) {
  3658.     if (cmdstk[cmdlvl].src == CMD_TF) {
  3659.         printf("[%d] -F: \"%s\"\n",cmdlvl,tfnam[cmdstk[cmdlvl].lvl]);
  3660.     } else if (cmdstk[cmdlvl].src == CMD_MD) {
  3661.         char * m;
  3662.         m = m_arg[cmdstk[cmdlvl].lvl][0]; /* Name of this macro */
  3663.         printf("[%d] -M: \"%s\"\n",cmdlvl,m);
  3664.     }
  3665.     }
  3666.     return(cmdlvl < 1 ? 0 : cmdlvl);    /* Return command level */
  3667. }
  3668. #else /* No script programming language */
  3669. int popclvl() {                /* Just close current take file. */
  3670.     if (tlevel > -1) {            /* if any... */
  3671.     if (tfnam[tlevel]) {
  3672.         free(tfnam[tlevel]);
  3673.         tfnam[tlevel] = NULL;
  3674.     }
  3675.     fclose(tfile[tlevel--]);
  3676.     }
  3677.     if (tlevel == -1) {            /* And if back at top level */
  3678.     setint();
  3679.         concb((char)escape);        /* and go back into cbreak mode. */
  3680.     }
  3681.     return(tlevel + 1);
  3682. }
  3683. #endif /* NOSPL */
  3684.  
  3685. /* STOP - get back to C-Kermit prompt, no matter where from. */
  3686.  
  3687. int
  3688. dostop() {
  3689.     while (popclvl()) ;        /* Pop all macros & take files */
  3690. #ifndef NOSPL
  3691.     while (cmpop() > -1);    /* And all recursive cmd pkg invocations */
  3692. #endif /* NOSPL */
  3693.     cmini(ckxech);        /* Clear the command buffer. */
  3694.     return(0);
  3695. }
  3696.  
  3697. /* Close the given log */
  3698.  
  3699. int
  3700. doclslog(x) int x; {
  3701.     int y;
  3702.     switch (x) {
  3703. #ifdef DEBUG
  3704.       case LOGD:
  3705.     if (deblog <= 0) {
  3706.         printf("?Debugging log wasn't open\n");
  3707.         return(0);
  3708.     }
  3709.     debug(F100,"Debug Log Closed","",0L);
  3710.     *debfil = '\0';
  3711.     deblog = 0;
  3712.     return(zclose(ZDFILE));
  3713. #endif /* DEBUG */
  3714.  
  3715. #ifndef NOXFER
  3716.       case LOGP:
  3717.     if (pktlog <= 0) {
  3718.         printf("?Packet log wasn't open\n");
  3719.         return(0);
  3720.     }
  3721.     *pktfil = '\0';
  3722.     pktlog = 0;
  3723.     return(zclose(ZPFILE));
  3724. #endif /* NOXFER */
  3725.  
  3726. #ifndef NOLOCAL
  3727.       case LOGS:
  3728.     if (seslog <= 0) {
  3729.         printf("?Session log wasn't open\n");
  3730.         return(0);
  3731.     }
  3732.     *sesfil = '\0';
  3733.     seslog = 0;
  3734.     return(zclose(ZSFILE));
  3735. #endif /* NOLOCAL */
  3736.  
  3737. #ifdef TLOG
  3738.       case LOGT:
  3739.     if (tralog <= 0) {
  3740.         if (msgflg) printf("?Transaction log wasn't open\n");
  3741.         return(0);
  3742.     }
  3743.     tlog(F100,"Transaction Log Closed","",0L);
  3744.     *trafil = '\0';
  3745.     tralog = 0;
  3746.     return(zclose(ZTFILE));
  3747. #endif /* TLOG */
  3748.  
  3749. #ifdef CKLOGDIAL
  3750.       case LOGM:
  3751.     if (dialog <= 0) {
  3752.         if (msgflg) printf("?Connection log wasn't open\n");
  3753.         return(0);
  3754.     }
  3755.     *diafil = '\0';
  3756.     dialog = 0;
  3757.     return(zclose(ZDIFIL));
  3758. #endif /* CKLOGDIAL */
  3759.  
  3760. #ifndef NOSPL
  3761.       case LOGW:            /* WRITE file */
  3762.       case LOGR:            /* READ file */
  3763.     y = (x == LOGR) ? ZRFILE : ZWFILE;
  3764.     if (chkfn(y) < 1)        /* If no file to close */
  3765.       return(1);            /* succeed silently. */
  3766.     return(zclose(y));        /* Otherwise, close the file. */
  3767. #endif /* NOSPL */
  3768.  
  3769.       default:
  3770.     printf("\n?Unexpected log designator - %d\n", x);
  3771.     return(0);
  3772.     }
  3773. }
  3774.  
  3775. static int slc = 0;            /* Screen line count */
  3776.  
  3777. char *
  3778. showoff(x) int x; {
  3779.     return(x ? "on" : "off");
  3780. }
  3781.  
  3782. char *
  3783. showooa(x) int x; {
  3784.     switch (x) {
  3785.       case SET_OFF:  return("off");
  3786.       case SET_ON:   return("on");
  3787.       case SET_AUTO: return("automatic");
  3788.       default:       return("(unknown)");
  3789.     }
  3790. }
  3791.  
  3792. #ifdef GEMDOS
  3793. isxdigit(c) int c; {
  3794.     return(isdigit(c) ||
  3795.        (c >= 'a' && c <= 'f') ||
  3796.        (c >= 'A' && c <= 'F'));
  3797. }
  3798. #endif /* GEMDOS */
  3799.  
  3800. #ifndef NOSETKEY
  3801. #ifdef OS2
  3802. static struct keytab shokeytab[] = {    /* SHOW KEY modes */
  3803.     "all",    1, 0,
  3804.     "one",    0, 0
  3805. };
  3806. static int nshokey = (sizeof(shokeytab) / sizeof(struct keytab));
  3807.  
  3808. #define SHKEYDEF TT_MAX+5
  3809. struct keytab shokeymtab[] = {
  3810.     "aixterm",   TT_AIXTERM, 0,         /* IBM AIXterm */
  3811.     "ansi-bbs",  TT_ANSI,    0,        /* ANSI.SYS (BBS) */
  3812.     "at386",     TT_AT386,   0,        /* Unixware ANSI */
  3813.     "avatar/0+", TT_ANSI,    0,         /* AVATAR/0+ */
  3814.     "ba80",      TT_BA80,    0,         /* Nixdorf BA80 */
  3815.     "be",        TT_BEOS,    CM_INV|CM_ABR,
  3816.     "beos-ansi", TT_BEOS,    CM_INV,    /* BeOS ANSI */
  3817.     "beterm",    TT_BEOS,    0,         /* BeOS Console */
  3818.     "d200",     TT_DG200,   CM_INV|CM_ABR, /* Data General DASHER 200 */
  3819.     "d210",     TT_DG210,   CM_INV|CM_ABR, /* Data General DASHER 210 */
  3820.     "d217",     TT_DG217,   CM_INV|CM_ABR, /* Data General DASHER 217 */
  3821.     "default",   SHKEYDEF,   0,
  3822.     "dg200",     TT_DG200,   0,        /* Data General DASHER 200 */
  3823.     "dg210",     TT_DG210,   0,        /* Data General DASHER 210 */
  3824.     "dg217",     TT_DG217,   0,        /* Data General DASHER 217 */
  3825.     "emacs",     TT_KBM_EMACS,   0,     /* Emacs mode */
  3826.     "h19",       TT_H19,     CM_INV,    /* Heath-19 */
  3827.     "heath19",   TT_H19,     0,        /* Heath-19 */
  3828.     "hebrew",    TT_KBM_HEBREW, 0,      /* Hebrew mode */
  3829.     "hft",       TT_HFT,     0,         /* IBM HFT */
  3830.     "hp2621a",   TT_HP2621,  0,        /* HP 2621A */
  3831.     "hpterm",    TT_HPTERM,  0,        /* HP TERM */
  3832.     "hz1500",    TT_HZL1500, 0,        /* Hazeltine 1500 */
  3833.     "ibm3151",   TT_IBM31,   CM_INV,    /* IBM 3101-xx,3161 */
  3834.     "linux",     TT_LINUX,   0,         /* Linux */
  3835.     "qansi",     TT_QANSI,   0,         /* QNX ANSI */
  3836.     "qnx",       TT_QNX,     0,         /* QNX */
  3837.     "russian",   TT_KBM_RUSSIAN, 0,     /* Russian mode */
  3838.     "scoansi",   TT_SCOANSI, 0,        /* SCO ANSI */
  3839.     "sni-97801", TT_97801,   0,         /* Sinix 97801 */
  3840. #ifdef OS2PM
  3841. #ifdef COMMENT
  3842.     "tek4014", TT_TEK40, 0,
  3843. #endif /* COMMENT */
  3844. #endif /* OS2PM */
  3845.     "tty",     TT_NONE,  0,
  3846.     "tvi910+", TT_TVI910, 0,
  3847.     "tvi925",  TT_TVI925, 0,
  3848.     "tvi950",  TT_TVI950, 0,
  3849.     "vc404",   TT_VC4404, 0,
  3850.     "vc4404",  TT_VC4404, CM_INV,
  3851.     "vip7809", TT_VIP7809, 0,
  3852.     "vt100",   TT_VT100, 0,
  3853.     "vt102",   TT_VT102, 0,
  3854.     "vt220",   TT_VT220, 0,
  3855.     "vt220pc", TT_VT220PC, 0,
  3856.     "vt320",   TT_VT320, 0,
  3857.     "vt320pc", TT_VT320PC, 0,
  3858.     "vt52",    TT_VT52,  0,
  3859.     "wp",      TT_KBM_WP, 0,
  3860.     "wy160",   TT_WY160,  0,
  3861.     "wy30",    TT_WY30,  0,
  3862.     "wy370",   TT_WY370, 0,
  3863.     "wy50",    TT_WY50,  0,
  3864.     "wy60",    TT_WY60,  0,
  3865.     "wyse30",  TT_WY30,  CM_INV,
  3866.     "wyse370", TT_WY370, CM_INV,
  3867.     "wyse50",  TT_WY50,  CM_INV,
  3868.     "wyse60",  TT_WY60,  CM_INV
  3869. };
  3870. int nshokeym = (sizeof(shokeymtab) / sizeof(struct keytab));
  3871. #endif /* OS2 */
  3872.  
  3873. VOID
  3874. #ifdef OS2
  3875. shokeycode(c,m) int c, m;
  3876. #else
  3877. shokeycode(c) int c;
  3878. #endif
  3879. /* shokeycode */ {
  3880.     KEY ch;
  3881.     CHAR *s;
  3882. #ifdef OS2
  3883.     int i;
  3884.     con_event km;
  3885. #else /* OS2 */
  3886.     int km;
  3887. #endif /* OS2 */
  3888.  
  3889. #ifdef OS2
  3890.     extern int mskkeys;
  3891.     char * mstr = "";
  3892.  
  3893.     if (c >= KMSIZE) {
  3894.     bleep(BP_FAIL);
  3895.     return;
  3896.     }
  3897. #else /* OS2 */
  3898.     printf(" Key code \\%d => ", c);
  3899. #endif /* OS2 */
  3900.  
  3901. #ifndef OS2
  3902.     km = mapkey(c);
  3903.  
  3904. #ifndef NOKVERBS
  3905.     if (IS_KVERB(km)) {            /* \Kverb? */
  3906.     int i, kv;
  3907.     kv = km & ~(F_KVERB);
  3908.     printf("Verb: ");
  3909.     for (i = 0; i < nkverbs; i++)
  3910.       if (kverbs[i].kwval == kv) {
  3911.           printf("\\K%s",kverbs[i].kwd);
  3912.           break;
  3913.       }
  3914.     printf("\n");
  3915.     } else
  3916. #endif /* NOKVERBS */
  3917.       if (IS_CSI(km)) {
  3918.       int xkm = km & 0xFF;
  3919.       if (xkm <= 32 || xkm >= 127)
  3920.         printf("String: \\{27}[\\{%d}\n",xkm);
  3921.       else
  3922.         printf("String: \\{27}[%c\n",xkm);
  3923.       } else if (IS_ESC(km)) {
  3924.       int xkm = km & 0xFF;
  3925.       if (xkm <= 32 || xkm >= 127)
  3926.         printf("String: \\{27}\\{%d}\n",xkm);
  3927.       else
  3928.         printf("String: \\{27}%c\n",xkm);
  3929.       } else if (macrotab[c]) {        /* See if there's a macro */
  3930.       printf("String: ");        /* If so, display its definition */
  3931.       s = macrotab[c];
  3932.       shostrdef(s);
  3933.       printf("\n");
  3934. #ifndef NOKVERBS
  3935.     } else if (km >= 0x100) {        /* This means "undefined" */
  3936.     printf("Undefined\n");
  3937. #endif /* NOKVERBS */
  3938.     } else {                /* No macro, show single character */
  3939.     printf("Character: ");
  3940.     ch = km;
  3941.     if (ch < 32 || ch == 127
  3942. #ifdef OS2
  3943.         || ch > 255
  3944. #endif /* OS2 */
  3945. #ifndef NEXT
  3946. #ifndef AUX
  3947. #ifndef XENIX
  3948. #ifndef OS2
  3949.         || (ch > 127 && ch < 160)
  3950. #endif /* OS2 */
  3951. #endif /* XENIX */
  3952. #endif /* AUX */
  3953. #endif /* NEXT */
  3954.         )
  3955. /*
  3956.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  3957.   %u is supposed to be totally portable.
  3958. */
  3959.       printf("\\%u",(unsigned int) ch);
  3960.     else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  3961.     if (ch == (KEY) c)
  3962.       printf(" (self, no translation)\n");
  3963.     else
  3964.       printf("\n");
  3965.     }
  3966. #else /* OS2 */
  3967.     if (m < 0) {
  3968.         km = mapkey(c);
  3969.         mstr = "default";
  3970.     } else {
  3971.         km = maptermkey(c,m);
  3972.         for (i = 0; i < nshokeym; i++) {
  3973.             if (m == shokeymtab[i].kwval) {
  3974.                 mstr = shokeymtab[i].kwd;
  3975.                 break;
  3976.             }
  3977.         }
  3978.     }
  3979.     s = keyname(c);
  3980.     debug(F111,"shokeycode mstr",mstr,m);
  3981.     debug(F111,"shokeycode keyname",s,c);
  3982.     printf(" %sKey code \\%d %s (%s) => ",
  3983.             mskkeys ? "mskermit " : "",
  3984.             mskkeys ? cktomsk(c) : c,
  3985.         s == NULL ? "" : s, mstr);
  3986.  
  3987.     switch (km.type) {
  3988. #ifndef NOKVERBS
  3989.       case kverb: {
  3990.       int i, kv;
  3991.       kv = km.kverb.id & ~(F_KVERB);
  3992.       printf("Verb: ");
  3993.       for (i = 0; i < nkverbs; i++) {
  3994.           if (kverbs[i].kwval == kv) {
  3995.           printf("\\K%s",kverbs[i].kwd);
  3996.           break;
  3997.           }
  3998.       }
  3999.       printf("\n");
  4000.       break;
  4001.       }
  4002. #endif /* NOKVERBS */
  4003.       case csi: {
  4004.       int xkm = km.csi.key & 0xFF;
  4005.       if (xkm <= 32 || xkm >= 127)
  4006.         printf("String: \\{27}[\\{%d}\n",xkm);
  4007.       else
  4008.         printf("String: \\{27}[%c\n",xkm);
  4009.       break;
  4010.       }
  4011.       case esc: {
  4012.       int xkm = km.esc.key & 0xFF;
  4013.       if (xkm <= 32 || xkm >= 127)
  4014.         printf("String: \\{%d}\\{%d}\n",ISDG200(tt_type)?30:27,xkm);
  4015.       else
  4016.         printf("String: \\{%d}%c\n",ISDG200(tt_type)?30:27,xkm);
  4017.       break;
  4018.       }
  4019.       case macro: {
  4020.       printf("String: ");        /* Macro, display its definition */
  4021.       shostrdef(km.macro.string);
  4022.       printf("\n");
  4023.       break;
  4024.       }
  4025.       case literal: {
  4026.           printf("Literal string: ");    /* Literal, display its definition */
  4027.           shostrdef(km.literal.string);
  4028.           printf("\n");
  4029.           break;
  4030.       }
  4031.       case error: {
  4032.       if (c >= 0x100) {
  4033.           printf("Undefined\n");
  4034.       } else {
  4035.           printf("Character: ");
  4036.           ch = c;
  4037.           if (ch < 32 || ch == 127 || ch > 255
  4038. #ifndef NEXT
  4039. #ifndef AUX
  4040. #ifndef XENIX
  4041. #ifndef OS2
  4042.            || (ch > 127 && ch < 160)
  4043. #endif /* OS2 */
  4044. #endif /* XENIX */
  4045. #endif /* AUX */
  4046. #endif /* NEXT */
  4047.            )
  4048. /*
  4049.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  4050.   %u is supposed to be totally portable.
  4051. */
  4052.           printf("\\%u",(unsigned int) ch);
  4053.           else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  4054.           printf(" (self, no translation)\n");
  4055.       }
  4056.       break;
  4057.       }
  4058.       case key: {
  4059.       printf("Character: ");
  4060.       ch = km.key.scancode;
  4061.       if (ch < 32 || ch == 127 || ch > 255
  4062. #ifndef NEXT
  4063. #ifndef AUX
  4064. #ifndef XENIX
  4065. #ifndef OS2
  4066.           || (ch > 127 && ch < 160)
  4067. #else
  4068.                || (ch > 127)
  4069. #endif /* OS2 */
  4070. #endif /* XENIX */
  4071. #endif /* AUX */
  4072. #endif /* NEXT */
  4073.           )
  4074. /*
  4075.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  4076.   %u is supposed to be totally portable.
  4077. */
  4078.         printf("\\%u",(unsigned int) ch);
  4079.       else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  4080.       if (ch == (KEY) c)
  4081.         printf(" (self, no translation)\n");
  4082.       else
  4083.         printf("\n");
  4084.       break;
  4085.       }
  4086.     }
  4087. #endif /* OS2 */
  4088. }
  4089. #endif /* NOSETKEY */
  4090.  
  4091. VOID
  4092. shostrdef(s) CHAR * s; {
  4093.     CHAR ch;
  4094.     while (ch = *s++) {
  4095.     if (ch < 32 || ch == 127 || ch == 255
  4096. /*
  4097.   Systems whose native character sets have graphic characters in C1...
  4098. */
  4099. #ifndef NEXT                /* NeXT */
  4100. #ifndef AUX                /* Macintosh */
  4101. #ifndef XENIX                /* IBM PC */
  4102. #ifdef OS2
  4103. /*
  4104.   It doesn't matter whether the local host can display 8-bit characters
  4105.   or not, they are not portable among character-sets and fonts.  Who
  4106.   knows what is going to be displayed
  4107. */
  4108.         || (ch > 127)
  4109. #else /* OS2 */
  4110.         || (ch > 127 && ch < 160)
  4111. #endif /* OS2 */
  4112. #endif /* XENIX */
  4113. #endif /* AUX */
  4114. #endif /* NEXT */
  4115.         )
  4116.       printf("\\{%d}",ch);        /* Display control characters */
  4117.     else putchar((char) ch);    /* in backslash notation */
  4118.     }
  4119. }
  4120.  
  4121. #define xxdiff(v,sys) strncmp(v,sys,strlen(sys))
  4122.  
  4123. #ifndef NOSHOW
  4124. VOID
  4125. shover() {
  4126. #ifdef OS2
  4127.     extern char ckxsystem[];
  4128. #endif /* OS2 */
  4129.     extern long xvernum;
  4130.     extern char *ck_patch, * cklibv;
  4131.     printf("\nVersions:\n %s\n",versio);
  4132.     printf(" Numeric: %ld\n",vernum);
  4133. #ifdef OS2
  4134.     printf(" Operating System: %s\n", ckxsystem);
  4135. #else /* OS2 */
  4136.     printf(" Built for: %s\n", ckxsys);
  4137. #ifdef CK_UTSNAME
  4138.     if (unm_nam[0])
  4139.       printf(" Running on: %s %s %s %s\n", unm_nam,unm_ver,unm_rel,unm_mch);
  4140. #endif /* CK_UTSNAME */
  4141.     printf(" Patches: %s\n", *ck_patch ? ck_patch : "(none)");
  4142. #endif /* OS2 */
  4143.     if (xxdiff(ckxv,ckxsys))
  4144.       printf(" %s for%s\n",ckxv,ckxsys);
  4145.     else
  4146.       printf(" %s\n",ckxv);
  4147.     if (xxdiff(ckzv,ckzsys))
  4148.       printf(" %s for%s\n",ckzv,ckzsys);
  4149.     else
  4150.       printf(" %s\n",ckzv);
  4151.     printf(" %s\n",cklibv);
  4152.     printf(" %s\n",protv);
  4153.     printf(" %s\n",fnsv);
  4154.     printf(" %s\n %s\n",cmdv,userv);
  4155. #ifndef NOCSETS
  4156.     printf(" %s\n",xlav);
  4157. #endif /* NOCSETS */
  4158. #ifndef MAC
  4159. #ifndef NOLOCAL
  4160.     printf(" %s\n",connv);
  4161. #endif /* NOLOCAL */
  4162. #endif /* MAC */
  4163. #ifndef NODIAL
  4164.     printf(" %s\n",dialv);
  4165. #endif /* NODIAL */
  4166. #ifndef NOSCRIPT
  4167.     printf(" %s\n",loginv);
  4168. #endif /* NOSCRIPT */
  4169. #ifdef NETCONN
  4170.     printf(" %s\n",cknetv);
  4171. #ifdef OS2
  4172.     printf(" %s\n",ckonetv);
  4173. #ifdef CK_NETBIOS
  4174.     printf(" %s\n",ckonbiv);
  4175. #endif /* CK_NETBIOS */
  4176. #endif /* OS2 */
  4177. #endif /* NETCONN */
  4178. #ifdef TNCODE
  4179.     printf(" %s\n",cktelv);
  4180. #endif /* TNCODE */
  4181. #ifdef OS2
  4182. #ifdef OS2MOUSE
  4183.     printf(" %s\n",ckomouv);
  4184. #endif /* OS2MOUSE */
  4185. #endif /* OS2 */
  4186. #ifdef CK_AUTHENTICATION
  4187.     printf(" %s\n",ckathv);
  4188. #endif /* CK_AUTHENTICATION */
  4189. #ifdef CK_ENCRYPTION
  4190. #ifdef CRYPT_DLL
  4191.     printf(" %s\n",ck_crypt_dll_version());
  4192. #else /* CRYPT_DLL */
  4193.     printf(" %s\n",ckcrpv);
  4194. #endif /* CRYPT_DLL */
  4195. #endif /* CK_ENCRYPTION */
  4196. #ifdef CK_SSL
  4197.     printf(" %s\n",cksslv);
  4198. #endif /* CK_SSL */
  4199.     printf("\n");
  4200. }
  4201.  
  4202. #ifdef CK_LABELED
  4203. VOID
  4204. sholbl() {
  4205. #ifdef VMS
  4206.     printf("VMS Labeled File Features:\n");
  4207.     printf(" acl %s (ACL info %s)\n",
  4208.        showoff(lf_opts & LBL_ACL),
  4209.        lf_opts & LBL_ACL ? "preserved" : "discarded");
  4210.     printf(" backup-date %s (backup date/time %s)\n",
  4211.        showoff(lf_opts & LBL_BCK),
  4212.        lf_opts & LBL_BCK ? "preserved" : "discarded");
  4213.     printf(" name %s (original filename %s)\n",
  4214.        showoff(lf_opts & LBL_NAM),
  4215.        lf_opts & LBL_NAM ? "preserved" : "discarded");
  4216.     printf(" owner %s (original file owner id %s)\n",
  4217.        showoff(lf_opts & LBL_OWN),
  4218.        lf_opts & LBL_OWN ? "preserved" : "discarded");
  4219.     printf(" path %s (original file's disk:[directory] %s)\n",
  4220.        showoff(lf_opts & LBL_PTH),
  4221.        lf_opts & LBL_PTH ? "preserved" : "discarded");
  4222. #else
  4223. #ifdef OS2
  4224.     printf("OS/2 Labeled File features (attributes):\n");
  4225.     printf(" archive:   %s\n", showoff(lf_opts & LBL_ARC));
  4226.     printf(" extended:  %s\n", showoff(lf_opts & LBL_EXT));
  4227.     printf(" hidden:    %s\n", showoff(lf_opts & LBL_HID));
  4228.     printf(" read-only: %s\n", showoff(lf_opts & LBL_RO ));
  4229.     printf(" system:    %s\n", showoff(lf_opts & LBL_SYS));
  4230. #endif /* OS2 */
  4231. #endif /* VMS */
  4232. }
  4233. #endif /* CK_LABELED */
  4234.  
  4235. VOID
  4236. shotcs(csl,csr) int csl, csr; {        /* Show terminal character set */
  4237. #ifndef NOCSETS
  4238. #ifdef OS2
  4239.     extern struct _vtG G[4], *GL, *GR;
  4240.     extern int decnrcm, sni_chcode;
  4241.     extern int tt_utf8, dec_nrc, dec_kbd, dec_lang;
  4242.  
  4243.     printf(" Terminal character-sets:\n");
  4244.     if (IS97801(tt_type_mode)) {
  4245.     if (cmask == 0377)
  4246.       printf("     Mode: 8-bit Mode\n");
  4247.     else
  4248.       printf("     Mode: 7-bit Mode\n");
  4249.     printf("     CH.CODE is %s\n",sni_chcode?"On":"Off");
  4250.     } else if (ISVT100(tt_type_mode)) {
  4251.     if (decnrcm)
  4252.       printf("     Mode: 7-bit National Mode\n");
  4253.     else
  4254.       printf("     Mode: 8-bit Multinational Mode\n");
  4255.     }
  4256.     printf("    Local: %s%s\n",
  4257.        isunicode() ? "Unicode/" : "",
  4258.        csl == TX_TRANSP ? "transparent" :
  4259.        csl == TX_UNDEF ? "undefined" : txrinfo[csl]->keywd);
  4260.     printf(tt_utf8 ?
  4261.        "   Remote: UTF-8\n           %sG0: %s (%s)\n":
  4262.        "   Remote: %sG0: %s (%s)\n",
  4263.        GL == &G[0] ? "GL->" : GR == &G[0] ? "GR->" : "    ",
  4264.        txrinfo[G[0].designation]->keywd,
  4265.            G[0].designation == TX_TRANSP ? "" :
  4266.        G[0].size == cs94 ? "94 chars" :
  4267.        G[0].size == cs96 ? "96 chars" : "multi-byte");
  4268.     printf("           %sG1: %s (%s)\n",
  4269.        GL == &G[1] ? "GL->" : GR == &G[1] ? "GR->" : "    ",
  4270.        txrinfo[G[1].designation]->keywd,
  4271.             G[1].designation == TX_TRANSP ? "" :
  4272.             G[1].size == cs94 ? "94 chars" :
  4273.             G[1].size == cs96 ? "96 chars" : "multi-byte");
  4274.     printf("           %sG2: %s (%s)\n",
  4275.        GL == &G[2] ? "GL->" : GR == &G[2] ? "GR->" : "    ",
  4276.        txrinfo[G[2].designation]->keywd,
  4277.             G[2].designation == TX_TRANSP ? "" :
  4278.             G[2].size == cs94 ? "94 chars" :
  4279.        G[2].size == cs96 ? "96 chars" : "multi-byte");
  4280.     printf("           %sG3: %s (%s)\n",
  4281.        GL == &G[3] ? "GL->" : GR == &G[3] ? "GR->" : "    ",
  4282.        txrinfo[G[3].designation]->keywd,
  4283.             G[3].designation == TX_TRANSP ? "" :
  4284.             G[3].size == cs94 ? "94 chars" :
  4285.        G[3].size == cs96 ? "96 chars" : "multi-byte");
  4286.     printf("\n");
  4287.     printf(" Keyboard character-sets:\n");
  4288.     printf("   Multinational: %s\n",txrinfo[dec_kbd]->keywd);
  4289.     printf("        National: %s\n",txrinfo[dec_nrc]->keywd);
  4290. #else /* OS2 */
  4291. #ifndef MAC
  4292.     char *s;
  4293.  
  4294.     debug(F101,"TERM LOCAL CSET","",csl);
  4295.     debug(F101,"TERM REMOTE CSET","",csr);
  4296.     printf(" Terminal character-set: ");
  4297.     if (tcs_transp) {            /* No translation */
  4298.     printf("transparent\n");
  4299.     } else {                /* Translation */
  4300.     printf("%s (remote) %s (local)\n",
  4301.            fcsinfo[csr].keyword,fcsinfo[csl].keyword);
  4302.     if (csr != csl) {
  4303.         switch(gettcs(csr,csl)) {
  4304.           case TC_USASCII:  s = "ascii";        break;
  4305.           case TC_1LATIN:   s = "latin1-iso";   break;
  4306.           case TC_2LATIN:   s = "latin2-iso";   break;
  4307.           case TC_CYRILL:   s = "cyrillic-iso"; break;
  4308.           case TC_JEUC:     s = "japanese-euc"; break;
  4309.           case TC_HEBREW:   s = "hebrew-iso";   break;
  4310.           case TC_GREEK:    s = "greek-iso";    break;
  4311.           case TC_9LATIN:   s = "latin9-iso";   break;
  4312.           default:          s = "transparent";  break;
  4313.         }
  4314.         if (strcmp(s,fcsinfo[csl].keyword) &&
  4315.         strcmp(s,fcsinfo[csr].keyword))
  4316.           printf("                         (via %s)\n",s);
  4317.     }
  4318.     }
  4319. #endif /* MAC */
  4320. #endif /* OS2 */
  4321. #endif /* NOCSETS */
  4322. }
  4323.  
  4324. #ifdef OS2
  4325. extern char htab[];
  4326. VOID
  4327. shotabs() {
  4328.     int i;
  4329.  
  4330.     printf("Tab Stops:\n\n");
  4331.     for (i = 1; i <= 70; i++)
  4332.       printf("%c",htab[i]=='T'?'T':'-');
  4333.     printf("\n1.......10........20........30........40........50........60\
  4334. ........70\n\n");
  4335.     for (; i <= 140; i++)
  4336.       printf("%c",htab[i]=='T'?'T':'-');
  4337.     printf("\n........80........90.......100.......110.......120.......130\
  4338. .......140\n\n");
  4339.     for (; i <= 210; i++)
  4340.       printf("%c",htab[i]=='T'?'T':'-');
  4341.     printf("\n.......150.......160.......170.......180.......190.......200\
  4342. .......210\n\n");
  4343.     for (; i <= 255; i++)
  4344.       printf("%c",htab[i]=='T'?'T':'-');
  4345.     printf("\n.......220.......230.......240.......250..255\n");
  4346. }
  4347. #endif /* OS2 */
  4348.  
  4349. #ifdef OS2MOUSE
  4350. VOID
  4351. shomou() {
  4352.     int button, event, id, i;
  4353.     char * name = "";
  4354.  
  4355.     printf("Mouse settings:\n");
  4356.     printf("   Active:         %s\n\n",showoff(tt_mouse));
  4357.  
  4358.     for (button = 0; button < MMBUTTONMAX; button++)
  4359.       for (event = 0; event < MMEVENTSIZE; event++)
  4360.     if (mousemap[button][event].type != error)
  4361.       switch (mousemap[button][event].type) {
  4362.         case key:
  4363.           printf("   %s = Character: %c \\%d\n",
  4364.              mousename(button,event),
  4365.              mousemap[button][event].key.scancode,
  4366.              mousemap[button][event].key.scancode );
  4367.           break;
  4368.         case kverb:
  4369.           id = mousemap[button][event].kverb.id & ~(F_KVERB);
  4370.           if (id != K_IGNORE) {
  4371.           for (i = 0; i< nkverbs; i++)
  4372.             if (id == kverbs[i].kwval) {
  4373.             name = kverbs[i].kwd;
  4374.             break;
  4375.             }
  4376.           printf("   %s = Kverb: \\K%s\n",
  4377.              mousename(button,event),
  4378.              name
  4379.              );
  4380.           }
  4381.           break;
  4382.         case macro:
  4383.           printf("   %s = Macro: ",
  4384.              mousename(button,event) );
  4385.           shostrdef(mousemap[button][event].macro.string);
  4386.           printf("\n");
  4387.           break;
  4388.       }
  4389. }
  4390. #endif /* OS2MOUSE */
  4391.  
  4392. #ifndef NOLOCAL
  4393. VOID
  4394. shotrm() {
  4395.     char *s;
  4396.     extern int tt_print;
  4397.  
  4398. #ifdef OS2
  4399.     int lines=0;
  4400.     extern int wy_autopage, autoscroll, sgrcolors, colorreset, user_erasemode,
  4401.     decscnm, decscnm_usr, tt_status, tt_diff_upd, tt_idlesnd_tmo, tt_senddata,
  4402.     wy_blockend, marginbell, marginbellcol, tt_modechg, dgunix;
  4403.     extern char * tt_idlesnd_str, * tt_trigger[];
  4404.  
  4405. #ifdef PCFONTS
  4406.     int i;
  4407.     char *font;
  4408.  
  4409.     if (IsOS2FullScreen()) {        /* Determine the font name */
  4410.         if (!os2LoadPCFonts()) {
  4411.             for (i = 0; i < ntermfont; i++) {
  4412.                 if (tt_font == termfont[i].kwval) {
  4413.             font = termfont[i].kwd;
  4414.             break;
  4415.         }
  4416.         }
  4417.     } else {
  4418.             font = "(DLL not available)";
  4419.     }
  4420.     } else {
  4421.         font =     "(full screen only)";
  4422.     }
  4423. #endif /* PCFONTS */
  4424.  
  4425.     printf("Terminal parameters:\n");
  4426.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4427.     printf(" %19s: %1d%-12s  %13s: %1d%-14s\n",
  4428.        "Bytesize: Command",
  4429.            (cmdmsk == 0377) ? 8 : 7,
  4430.            " bits","Terminal",
  4431.            (cmask == 0377) ? 8 : 7," bits");
  4432.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4433.     printf(" %19s: %-13s","Type",
  4434.        (tt_type >= 0 && tt_type <= max_tt) ?
  4435.        tt_info[tt_type].x_name :
  4436.        "unknown" );
  4437.     if (tt_type >= 0 && tt_type <= max_tt)
  4438.       if (strlen(tt_info[tt_type].x_id))
  4439.     printf("  %13s: <ESC>%s","ID",tt_info[tt_type].x_id);
  4440.     printf("\n");
  4441.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4442.     printf(" %19s: %-13s  %13s: %-15s\n","Echo",
  4443.        duplex ? "local" : "remote","Locking-shift",showoff(sosi));
  4444.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4445.     printf(" %19s: %-13s  %13s: %-15s\n","Newline-mode",
  4446.        showoff(tnlm),"Cr-display",tt_crd ? "crlf" : "normal");
  4447.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4448.     printf(" %19s: %-13s  %13s: %-15s\n","Cursor",
  4449.        (tt_cursor == 2) ? "full" :
  4450.        (tt_cursor == 1) ? "half" : "underline",
  4451. #ifdef CK_AUTODL
  4452.        "autodownload",autodl ? "on" : "off"
  4453. #else /* CK_AUTODL */
  4454.        "", ""
  4455. #endif /* CK_AUTODL */
  4456.        );
  4457.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4458.     printf(" %19s: %-13s  %13s: %-15s\n","Arrow-keys",
  4459.        tt_arrow ? "application" : "cursor",
  4460.            "Keypad-mode", tt_keypad ? "application" : "numeric"
  4461.        );
  4462.  
  4463.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4464.  
  4465.     /* Just to make sure we are using current info */
  4466.     updanswerbk();
  4467.  
  4468.     /*
  4469.        This line doesn't end with '\n' because the answerback string
  4470.        is terminated with a newline
  4471.     */
  4472.     printf(" %19s: %-13s  %13s: %-15s","Answerback",
  4473.        showoff(tt_answer),"response",answerback);
  4474.     switch (tt_bell) {
  4475.       case XYB_NONE:
  4476.     s = "none";
  4477.     break;
  4478.       case XYB_VIS:
  4479.     s= "visible";
  4480.     break;
  4481.       case XYB_AUD | XYB_BEEP:
  4482.     s="beep";
  4483.     break;
  4484.       case XYB_AUD | XYB_SYS:
  4485.     s="system sounds";
  4486.     break;
  4487.       default:
  4488.     s="(unknown)";
  4489.     }
  4490.     printf(" %19s: %-13s  %13s: %-15s\n","Bell",s,
  4491.        "Wrap",showoff(tt_wrap));
  4492.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4493.     printf(" %19s: %-13s  %13s: %-15s\n","Autopage",showoff(wy_autopage),
  4494.        "Autoscroll",showoff(autoscroll));
  4495.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4496.     printf(" %19s: %-13s  %13s: %-15s\n","SGR Colors",showoff(sgrcolors),
  4497.        "ESC[0m color",colorreset?"default-color":"current-color");
  4498.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4499.     printf(" %19s: %-13s  %13s: %-15s\n",
  4500.             "Erase color",user_erasemode?"default-color":"current-color",
  4501.        "Screen mode",decscnm?"reverse":"normal");
  4502.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4503.  
  4504.     printf(" %19s: %-13d  %13s: %-15d\n","Transmit-timeout",tt_ctstmo,
  4505.        "Output-pacing",tt_pacing);
  4506.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4507.     printf(" %19s: %-13s  %13s: %d seconds\n","Idle-Send: string",
  4508.        tt_idlesnd_str,"interval", tt_idlesnd_tmo);
  4509.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4510.     printf(" %19s: %-13s  %13s: %-15s\n","Send data",
  4511.       showoff(tt_senddata),"End of Block", wy_blockend?"crlf/etx":"us/cr");
  4512.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4513.     printf(" %19s: %-13s  %13s: %d seconds\n","Auto-exit trigger",
  4514.        tt_trigger[0],"Output pacing",tt_pacing );
  4515.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4516.     printf(" %19s: %-13s  %13s: %-15d\n","Margin bell",
  4517.        showoff(marginbell),"at column", marginbellcol);
  4518.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4519.     switch (tt_modechg) {
  4520.       case TVC_DIS: s = "disabled"; break;
  4521.       case TVC_ENA: s = "enabled";  break;
  4522.       case TVC_W95: s = "win95-restricted"; break;
  4523.       default: s = "(unknown)";
  4524.     }
  4525.     printf(" %19s: %-13s  %13s: %-15s\n","DG Unix mode",
  4526.        showoff(dgunix),"Video change", s);
  4527.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4528.  
  4529. #ifdef CK_APC
  4530.     if (apcstatus == APC_ON) s = "on";
  4531.     else if (apcstatus == APC_OFF) s = "off";
  4532.     else if (apcstatus == APC_UNCH) s = "unchecked";
  4533.     printf(" %19s: %-13s  %13s: %-15s\n",
  4534.        "APC", s,
  4535. #ifdef PCFONTS
  4536.        "Font (VGA)",font
  4537. #else /* PCFONTS */
  4538.        "Font (VGA)","(not supported)"
  4539. #endif /* PCFONTS */
  4540.  
  4541.        );
  4542. #endif /* CK_APC */
  4543.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4544.  
  4545. #ifdef CK_TTGWSIZ            /* Console terminal screen size */
  4546.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  4547.       ttgwsiz();            /* Try to get latest size */
  4548. #endif /* CK_TTGWSIZ */
  4549.     printf(" %19s: %-13d  %13s: %-15d\n","Height",tt_rows[VTERM],
  4550.            "Width",tt_cols[VTERM]);
  4551.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4552.     printf(" %19s: %-13s  %13s: %d lines\n","Roll-mode",
  4553.       tt_roll[VTERM]?"insert":"overwrite","Scrollback", tt_scrsize[VTERM]);
  4554.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4555.  
  4556.     if (updmode == tt_updmode)
  4557.       if (updmode == TTU_FAST)
  4558.     s = "fast (fast)";
  4559.       else
  4560.     s = "smooth (smooth)";
  4561.     else
  4562.       if (updmode == TTU_FAST)
  4563.     s = "fast (smooth)";
  4564.       else
  4565.     s = "smooth (fast)";
  4566.  
  4567.     printf(" %19s: %-13s  %13s: %d ms\n","Screen-update: mode",s,
  4568.        "interval",tt_update);
  4569.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4570.     printf(" %19s: %-13s  %13s: %-15s\n",
  4571.        "Screen-optimization",showoff(tt_diff_upd),
  4572.        "Status line",showoff(tt_status));
  4573.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4574.     printf(" %19s: %-13s  %13s: %-15s\n","Debug",
  4575.        showoff(debses),"Session log", seslog? sesfil : "(none)" );
  4576.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4577.  
  4578.     /* Display colors (should become SHOW COLORS) */
  4579.     {
  4580.         USHORT row, col;
  4581.         char * colors[16] = {
  4582.             "black","blue","green","cyan","red","magenta","brown","lgray",
  4583.             "dgray","lblue","lgreen","lcyan","lred","lmagent","yellow","white"
  4584.     };
  4585.         printf("\n");
  4586.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4587.  
  4588.         printf(" Color:");
  4589. #ifndef ONETERMUPD
  4590.         GetCurPos(&row, &col);
  4591.         WrtCharStrAtt("border",    6, row, 9, &colorborder );
  4592.     WrtCharStrAtt("debug",     5, row, 17, &colordebug );
  4593.         WrtCharStrAtt("helptext",  8, row, 25, &colorhelp );
  4594.     WrtCharStrAtt("reverse",   7, row, 34, &colorreverse );
  4595.         WrtCharStrAtt("select",    6, row, 42, &colorselect );
  4596.         WrtCharStrAtt("status",    6, row, 50, &colorstatus );
  4597.         WrtCharStrAtt("terminal",  8, row, 58, &colornormal );
  4598.     WrtCharStrAtt("underline",  9, row, 67, &colorunderline );
  4599. #endif /* ONETERMUPD */
  4600.         row = VscrnGetCurPos(VCMD)->y+1;
  4601.         VscrnWrtCharStrAtt(VCMD, "border",    6, row, 9, &colorborder );
  4602.     VscrnWrtCharStrAtt(VCMD, "debug",     5, row, 17, &colordebug );
  4603.         VscrnWrtCharStrAtt(VCMD, "helptext",  8, row, 25, &colorhelp );
  4604.     VscrnWrtCharStrAtt(VCMD, "reverse",   7, row, 34, &colorreverse );
  4605.         VscrnWrtCharStrAtt(VCMD, "select",    6, row, 42, &colorselect );
  4606.         VscrnWrtCharStrAtt(VCMD, "status",    6, row, 50, &colorstatus );
  4607.         VscrnWrtCharStrAtt(VCMD, "terminal",  8, row, 58, &colornormal );
  4608.     VscrnWrtCharStrAtt(VCMD, "underline",  9, row, 67, &colorunderline );
  4609.         printf("\n");
  4610.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4611.  
  4612.         /* Foreground color names */
  4613.         printf("%6s: %-8s%-8s%-9s%-8s%-8s%-8s%-9s%-9s\n","fore",
  4614.         "",
  4615.         colors[colordebug&0x0F],
  4616.         colors[colorhelp&0x0F],
  4617.         colors[colorreverse&0x0F],
  4618.         colors[colorselect&0x0F],
  4619.         colors[colorstatus&0x0F],
  4620.         colors[colornormal&0x0F],
  4621.         colors[colorunderline&0x0F] );
  4622.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4623.  
  4624.         /* Background color names */
  4625.         printf("%6s: %-8s%-8s%-9s%-8s%-8s%-8s%-9s%-9s\n","back",
  4626.         colors[colorborder],
  4627.         colors[colordebug>>4],
  4628.         colors[colorhelp>>4],
  4629.         colors[colorreverse>>4],
  4630.         colors[colorselect>>4],
  4631.         colors[colorstatus>>4],
  4632.         colors[colornormal>>4],
  4633.         colors[colorunderline>>4] );
  4634.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4635.         printf("\n");
  4636.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4637.         printf(" Color:");
  4638. #ifndef ONETERMUPD
  4639.         GetCurPos(&row, &col);
  4640.         WrtCharStrAtt("graphic",   7, row, 9, &colorgraphic );
  4641.     WrtCharStrAtt("command",   7, row, 17, &colorcmd );
  4642. #endif /* ONETERMUPD */
  4643.         row = VscrnGetCurPos(VCMD)->y+1;
  4644.         VscrnWrtCharStrAtt(VCMD, "graphic",   7, row, 9,  &colorgraphic );
  4645.     VscrnWrtCharStrAtt(VCMD, "command",   7, row, 17, &colorcmd );
  4646.         printf("\n");
  4647.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4648.  
  4649.         /* Foreground color names */
  4650.         printf("%6s: %-8s%-8s\n","fore",
  4651.         colors[colorgraphic&0x0F],
  4652.         colors[colorcmd&0x0F] );
  4653.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4654.  
  4655.         /* Background color names */
  4656.         printf("%6s: %-8s%-8s\n","back",
  4657.         colors[colorgraphic>>4],
  4658.         colors[colorcmd>>4] );
  4659.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4660.     }
  4661.     printf("\n");
  4662.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4663.     {
  4664.         extern int trueblink, truereverse, trueunderline;
  4665.         printf(" Attribute:  blink: %-3s  reverse: %-3s  underline: %-3s\n",
  4666.                 trueblink?"on":"off", truereverse?"on":"off",
  4667.                 trueunderline?"on":"off");
  4668.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4669.     }
  4670.     {
  4671.         extern vtattrib WPattrib;
  4672.         printf(" ASCII Protected chars: %s%s%s%s%s%s\n",
  4673.                 WPattrib.blinking?"blink ":"",
  4674.                 WPattrib.reversed?"reverse ":"",
  4675.                 WPattrib.underlined?"underline ":"",
  4676.                 WPattrib.bold?"bold ":"",
  4677.                 WPattrib.dim?"dim ":"",
  4678.                 WPattrib.invisible?"invisible ":"");
  4679.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4680.     }
  4681.  
  4682.     printf("\n");
  4683.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4684.  
  4685.     printf(" CONNECT-mode escape character: %d (Ctrl-%c, %s): %s\n",
  4686.        escape,ctl(escape),(escape == 127 ? "DEL" : ccntab[escape]),
  4687.        nm[tt_escape]);
  4688.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4689.     printf(" See SHOW CHARACTER-SETS for character-set info\n");
  4690.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  4691.  
  4692. #else /* OS2 */   /* Beginning of new non-OS2 version */
  4693.  
  4694.     printf("\n");
  4695.     printf("Terminal parameters:\n");
  4696.     printf(" %19s: %1d%-12s  %13s: %1d%-14s\n",
  4697.        "Bytesize: Command",
  4698.            (cmdmsk == 0377) ? 8 : 7,
  4699.            " bits","Terminal",
  4700.            (cmask == 0377) ? 8 : 7," bits");
  4701.     s = getenv("TERM");
  4702. #ifdef XPRINT
  4703.     printf(" %19s: %-13s  %13s: %-15s\n",
  4704.        "Type",
  4705.        s ? s : "(unknown)",
  4706.        "Print",
  4707.        showoff(tt_print)
  4708.        );
  4709. #else
  4710.     printf(" %19s: %-13s\n","Type", s ? s : "(unknown)");
  4711. #endif /* XPRINT */
  4712.     printf(" %19s: %-13s  %13s: %-15s\n","Echo",
  4713.        duplex ? "local" : "remote","Locking-shift",showoff(sosi));
  4714.     printf(" %19s: %-13s  %13s: %-15s\n","Newline-mode",
  4715.        showoff(tnlm),"Cr-display",tt_crd ? "crlf" : "normal");
  4716.  
  4717. #ifdef CK_APC
  4718.     if (apcstatus == APC_ON) s = "on";
  4719.     else if (apcstatus == APC_OFF) s = "off";
  4720.     else if (apcstatus == APC_UNCH) s = "unchecked";
  4721.     printf(" %19s: %-13s  %13s: %-15s\n",
  4722.        "APC", s,
  4723. #ifdef CK_AUTODL
  4724.        "Autodownload", autodl ? "on" : "off"
  4725. #else
  4726.        "",""
  4727. #endif /* CK_AUTODL */
  4728.        );
  4729. #endif /* CK_APC */
  4730.  
  4731. #ifdef CK_TTGWSIZ            /* Console terminal screen size */
  4732.     ttgwsiz();                /* Try to get latest size */
  4733.     printf(" %19s: %-13d  %13s: %-15d\n","Height",tt_rows, "Width", tt_cols);
  4734. #endif /* CK_TTGWSIZ */
  4735.  
  4736.     printf(" %19s: %-13s  %13s: %-15s\n","Debug",
  4737.        showoff(debses),"Session log", seslog? sesfil : "(none)" );
  4738.     printf("\n");
  4739.     printf(" CONNECT-mode escape character: %d (Ctrl-%c, %s): %s\n",
  4740.        escape,ctl(escape),(escape == 127 ? "DEL" : ccntab[escape]),
  4741.        nm[tt_escape]
  4742.        );
  4743. #ifndef NOCSETS
  4744.     shotcs(tcsl,tcsr);        /* Show terminal character sets */
  4745. #endif /* NOCSETS */
  4746.  
  4747. #ifdef UNIX
  4748. #ifndef NOJC
  4749.     printf(" %19s: %-13s\n\n","Suspend", showoff(suspend));
  4750. #endif /* NOJC */
  4751. #endif /* UNIX */
  4752. #endif /* OS2 */
  4753. }
  4754.  
  4755. VOID
  4756. shmdmlin() {                /* Briefly show modem & line */
  4757. #ifndef NODIAL
  4758. #ifndef MINIDIAL
  4759. #ifdef OLDTBCODE
  4760.     extern int tbmodel;
  4761.     _PROTOTYP( char * gtbmodel, (void) );
  4762. #endif /* OLDTBCODE */
  4763. #endif /* MINIDIAL */
  4764. #endif /* NODIAL */
  4765.     if (local)
  4766. #ifdef OS2
  4767.       printf(" Port: %s, Modem type: ",ttname);
  4768. #else
  4769.       printf(" Line: %s, Modem type: ",ttname);
  4770. #endif /* OS2 */
  4771.     else
  4772.       printf(
  4773. #ifdef OS2
  4774. " Communication device not yet selected with SET PORT\n Modem type: "
  4775. #else
  4776. " Communication device not yet selected with SET LINE\n Modem type: "
  4777. #endif /* OS2 */
  4778.          );
  4779. #ifndef NODIAL
  4780.     printf("%s",gmdmtyp());
  4781. #ifndef MINIDIAL
  4782. #ifdef OLDTBCODE
  4783.     if (tbmodel) printf(" (%s)",gtbmodel()); /* Telebit model info */
  4784. #endif /* OLDTBCODE */
  4785. #endif /* MINIDIAL */
  4786. #else
  4787.     printf("(disabled)");
  4788. #endif /* NODIAL */
  4789. }
  4790.  
  4791. #ifdef CK_TAPI
  4792. void
  4793. shotapi(int option) {
  4794.     int rc=0,k ;
  4795.     char *s=NULL;
  4796.     LPDEVCFG        lpDevCfg = NULL;
  4797.     LPCOMMCONFIG    lpCommConfig = NULL;
  4798.     LPMODEMSETTINGS lpModemSettings = NULL;
  4799.     DCB *           lpDCB = NULL;
  4800.     extern struct keytab * tapiloctab;    /* Microsoft TAPI Locations */
  4801.     extern int ntapiloc;
  4802.     extern struct keytab * tapilinetab;    /* Microsoft TAPI Line Devices */
  4803.     extern int ntapiline;
  4804.     extern int tttapi;            /* TAPI in use */
  4805.     extern int tapipass;        /* TAPI Passthrough mode */
  4806.     extern int tapiconv;        /* TAPI Conversion mode */
  4807.     extern int tapilights;
  4808.     extern int tapipreterm;
  4809.     extern int tapipostterm;
  4810.     extern int tapimanual;
  4811.     extern int tapiinactivity;
  4812.     extern int tapibong;
  4813.     extern int tapiusecfg;
  4814.     extern char tapiloc[];
  4815.     extern int tapilocid;
  4816.     extern int TAPIAvail;
  4817.  
  4818.     if (!TAPIAvail) {
  4819.         printf("TAPI Support not enabled\r\n");
  4820.         return;
  4821.     }
  4822.     switch (option) {
  4823.       case 0:
  4824.     printf("TAPI Settings:\n");
  4825.     printf("  Line:                      %s\n",
  4826.            tttapi ? ttname : "(none in use)");
  4827.  
  4828.     cktapiBuildLocationTable(&tapiloctab, &ntapiloc);
  4829.     if (tapilocid == -1)
  4830.       tapilocid = cktapiGetCurrentLocationID();
  4831.  
  4832.     /* Find the current tapiloc entry */
  4833.     /* and use it as the default. */
  4834.     for (k = 0; k < ntapiloc; k++) {
  4835.         if (tapiloctab[k].kwval == tapilocid)
  4836.           break;
  4837.     }
  4838.     if (k >= 0 && k < ntapiloc)
  4839.       s = tapiloctab[k].kwd;
  4840.     else
  4841.       s = "(unknown)";
  4842.     printf("  Location:                  %s\n",s);
  4843.     printf("  Modem-dialing:             %s\n",tapipass?"off":"on");
  4844.     printf("  Phone-number-conversions:  %s\n",
  4845.         tapiconv==CK_ON?"on":tapiconv==CK_AUTO?"auto":"off");
  4846.     printf("  Modem-lights:              %s %s\n",tapilights?"on ":"off",
  4847.         tapipass?"(n/a)":"");
  4848.     printf("  Predial-terminal:          %s %s\n",tapipreterm?"on ":"off",
  4849.         tapipass?"(n/a)":"");
  4850.     printf("  Postdial-terminal:         %s %s\n",tapipostterm?"on ":"off",
  4851.         tapipass?"(n/a)":"");
  4852.     printf("  Manual-dial:               %s %s\n",tapimanual?"on ":"off",
  4853.         tapipass?"(n/a)":"");
  4854.     printf("  Inactivity-timeout:        %d seconds %s\n",tapiinactivity,
  4855.         tapipass?"(n/a)":"");
  4856.     printf("  Wait-for-bong:             %d seconds %s\n",tapibong,
  4857.         tapipass?"(n/a)":"");
  4858.     printf("  Use-windows-configuration: %s %s\n",
  4859.         tapiusecfg?"on ":"off", tapipass?"(n/a)":"");
  4860.     printf("\n");
  4861.  
  4862. #ifdef BETATEST
  4863.     if (tapipass) {
  4864. printf("K-95 uses the TAPI Line in an exclusive mode.  Other applications\n");
  4865. printf("may open the device but may not place calls nor answer calls.\n");
  4866. printf("Dialing is performed using the K-95 dialing procedures.  SET MODEM\n");
  4867. printf("TYPE TAPI after the SET TAPI LINE command to activate the modem\n");
  4868. printf("definition associated with the active TAPI LINE device.\n\n");
  4869.  
  4870.     } else {
  4871.  
  4872. printf("K-95 uses the TAPI Line in a cooperative mode.  Other applications\n");
  4873. printf("may open the device, place and answer calls.  Dialing is performed\n");
  4874. printf("by TAPI.  K-95 SET MODEM commands are not used.\n\n");
  4875.     }
  4876.  
  4877.     if (tapiconv == CK_ON ||
  4878.         tapiconv == CK_AUTO && !tapipass) {
  4879. printf(
  4880. "Phone numbers are converted from canonical to dialable form by TAPI\n");
  4881. printf("using the dialing rules specified in the TAPI Dialing Properties\n");
  4882. printf("dialog.\n\n");
  4883.  
  4884.     } else {
  4885.  
  4886. printf(
  4887. "Phone numbers are converted from canonical to dialable form by K-95\n");
  4888. printf(
  4889. "using the dialing rules specified with the SET DIAL commands.  TAPI\n");
  4890. printf(
  4891. "Dialing Properties are imported automaticly upon startup and whenever\n");
  4892. printf("the TAPI Dialing Properties are altered or when the TAPI Location\n");
  4893. printf("is changed.\n\n");
  4894.         }
  4895. #endif /* BETATEST */
  4896.  
  4897.     if (tapipass) {
  4898.         printf("Type SHOW MODEM to see MODEM configuration.\n");
  4899.         if (tapiconv == CK_ON)
  4900.           printf("Type SHOW DIAL to see DIAL-related items.\n");
  4901.     } else {
  4902.         if (tapiconv == CK_ON || tapiconv == CK_AUTO)
  4903.           printf("Type SHOW DIAL to see DIAL-related items.\n");
  4904.     }
  4905.     break;
  4906.       case 1:
  4907.     cktapiDisplayTapiLocationInfo();
  4908.     break;
  4909.       case 2:
  4910.         rc = cktapiGetModemSettings(&lpDevCfg,&lpModemSettings,
  4911.                      &lpCommConfig,&lpDCB);
  4912.         if (rc) {
  4913.         cktapiDisplayModemSettings(lpDevCfg,lpModemSettings,
  4914.                      lpCommConfig,lpDCB);
  4915.     } else {
  4916.         printf("?Unable to retrieve Modem Settings\n");
  4917.     }
  4918.         break;
  4919.       case 3: {
  4920.       HANDLE hModem = GetModemHandleFromLine((HLINE)0);
  4921.       if (hModem)
  4922.         DisplayCommProperties(hModem);
  4923.       else
  4924.         printf("?Unable to retrieve a valid Modem Handle\n");
  4925.       CloseHandle(hModem);
  4926.       break;
  4927.       }
  4928.     }
  4929.     printf("\n");
  4930. }
  4931. #endif /* CK_TAPI */
  4932. #endif /* NOLOCAL */
  4933.  
  4934. #ifdef PATTERNS
  4935. static VOID
  4936. shopat() {
  4937.     extern char * binpatterns[], * txtpatterns[];
  4938.     extern int patterns;
  4939.     char **p, *s;
  4940.     int i, j, k, n, flag, width;
  4941. #ifdef CK_TTGWSIZ
  4942.     ttgwsiz();                /* Try to get latest size */
  4943. #ifdef OS2
  4944.     width = tt_cols[VCMD];
  4945. #else /* OS2 */
  4946.     width = tt_cols;
  4947. #endif /* OS2 */
  4948.     if (width < 1)
  4949. #endif /* CK_TTGWSIZ */
  4950.       width = 80;
  4951.     printf("\n");
  4952.     printf(" Set file type:            %s\n",gfmode(binary,1));
  4953.     printf(" Set file patterns:        %s", showooa(patterns));
  4954. #ifdef CK_LABELED
  4955.     if (binary == XYFT_L)
  4956.       printf(" (but SET FILE TYPE LABELED overrides)\n");
  4957.     else
  4958. #endif /* CK_LABELED */
  4959. #ifdef VMS
  4960.     if (binary == XYFT_I)
  4961.       printf(" (but SET FILE TYPE IMAGE overrides)\n");
  4962.     else
  4963. #endif /* VMS */
  4964.       printf("\n");
  4965.     printf(" Maximum patterns allowed: %d\n", FTPATTERNS);
  4966.     for (k = 0; k < 2; k++) {        /* For each kind of patter */
  4967.     printf("\n");
  4968.     if (k == 0) {            /* binary... */
  4969.         printf(" File binary-patterns: ");
  4970.         p = binpatterns;
  4971.     } else {            /* text... */
  4972.         printf(" File text-patterns:   ");
  4973.         p = txtpatterns;
  4974.     }
  4975.     if (!p[0]) {
  4976.         printf("(none)\n");
  4977.     } else {
  4978.         printf("\n ");
  4979.         n = 2;
  4980.         for (i = 0; i < FTPATTERNS; i++) { /* For each pattern */
  4981.         if (!p[i])        /* Done */
  4982.           break;
  4983.         s = p[i];        /* Look for embedded space */
  4984.         for (j = 0, flag = 1; *s; s++, j++) /* and also get length */
  4985.           if (*s == SP)
  4986.             flag = 3;
  4987.         n += j + flag;        /* Length of this line */
  4988.         if (n >= width - 1) {
  4989.             printf("\n ");
  4990.             n = j+2;
  4991.         }
  4992.         printf(flag == 3 ? " {%s}" : " %s", p[i]);
  4993.         }
  4994.         if (n > 2)
  4995.           printf("\n");
  4996.     }
  4997.     }
  4998.     printf("\n");
  4999. }
  5000. #endif /* PATTERNS */
  5001.  
  5002. #ifndef NOSPL
  5003. static VOID
  5004. shooutput() {
  5005.     printf(" Output pacing:          %d (milliseconds)\n",pacing);
  5006.     printf(" Output special-escapes: %s\n", showoff(outesc));
  5007. }
  5008.  
  5009. static VOID
  5010. shoinput() {
  5011. #ifdef CK_AUTODL
  5012.     printf(" Input autodownload:     %s\n", showoff(inautodl));
  5013. #endif /* CK_AUTODL */
  5014.     printf(" Input cancellation:     %s\n", showoff(inintr));
  5015.     printf(" Input case:             %s\n", inpcas[cmdlvl] ?
  5016.        "observe" : "ignore");
  5017.     printf(" Input buffer-length:    %d\n", inbufsize);
  5018.     printf(" Input echo:             %s\n", showoff(inecho));
  5019.     printf(" Input silence:          %d (seconds)\n", insilence);
  5020. #ifdef OS2
  5021.     printf(" Input terminal:         %s\n", showoff(interm));
  5022. #endif /* OS2 */
  5023.     printf(" Input timeout:          %s\n", intime[cmdlvl] ?
  5024.        "quit" : "proceed");
  5025.     if (instatus < 0)
  5026.       printf(" Last INPUT:             -1 (INPUT command not yet given)\n");
  5027.     else
  5028.       printf(" Last INPUT:             %d (%s)\n", instatus,i_text[instatus]);
  5029. }
  5030. #endif /* NOSPL */
  5031.  
  5032. #ifndef NOSPL
  5033. int
  5034. showarray() {
  5035. #ifdef COMMENT
  5036.     char * p, * q, ** ap;
  5037.     int i;
  5038. #endif /* COMMENT */
  5039.     char buf[16];
  5040.     char *s; int x = 0, y;
  5041.     int range[2];
  5042.     if ((y = cmfld("Array name","",&s,NULL)) < 0)
  5043.       if (y != -3)
  5044.     return(y);
  5045.     strcpy(line,s);
  5046.     s = line;
  5047.     if ((y = cmcfm()) < 0)
  5048.       return(y);
  5049.     if (*s) {
  5050.     char ** ap;
  5051.     if ((x = arraybounds(s,&(range[0]),&(range[1]))) < 0) {
  5052.         printf("?Bad array: %s\n",s);
  5053.         return(-9);
  5054.     }
  5055. #ifdef COMMENT
  5056.     range[0] = -1;
  5057.     range[1] = -1;
  5058.  
  5059.     p = s;
  5060.     for (p = s, q = NULL; *p; p++) {
  5061.         if (*p == '[') {
  5062.         q = p+1;
  5063.         } else if (*p == ']')
  5064.           break;
  5065.     }
  5066.     if (q && *p == ']') {
  5067.         int quitnow = 0;
  5068.         for (i = 0; i < 2 && !quitnow; i++) {
  5069.         for (p = q; *p; p++) {
  5070.             if (i == 0 && *p == ':' ||
  5071.             *p == ']') {
  5072.             if (*p == ']')
  5073.               quitnow = 1;
  5074.             *p = NUL;
  5075.             if (*q) {
  5076.                 y = 15;
  5077.                 s = buf;
  5078.                 zzstring(q,&s,&y);
  5079.                 s = evalx(buf);
  5080.                 if (s) if (*s) ckstrncpy(buf,s,16);
  5081.                 if (!rdigits(buf)) {
  5082.                 printf("?Not numeric: %s\n",buf);
  5083.                 return(-9);
  5084.                 }
  5085.                 q = (i == 0) ? p+1 : NULL;
  5086.                 range[i] = atoi(buf);
  5087.             }
  5088.             break;
  5089.             }
  5090.         }
  5091.         }
  5092.     }
  5093. #endif /* COMMENT */
  5094.     ap = a_ptr[x];
  5095.     if (!ap) {
  5096.         printf("Array not declared: %s\n", s);
  5097.         return(success = 1);
  5098.     } else {
  5099.         int i, n, max;
  5100.         max = (range[1] > 0) ?
  5101.           range[1] :
  5102.         ((range[0] > 0) ? range[0] : a_dim[x]);
  5103.         if (range[0] < 0)
  5104.           range[0] = 0;
  5105.         if (max > a_dim[x])
  5106.           max = a_dim[x];
  5107.         n = 1;
  5108.         printf("Dimension = %d\n",a_dim[x]);
  5109.         for (i = range[0]; i <= max; i++) {
  5110.         if (ap[i]) {
  5111.             printf("%3d. %s\n",i,ap[i]);
  5112.             if (xaskmore) {
  5113.             if (cmd_cols > 0) {
  5114.                 x = strlen(ap[i]) + 5;
  5115.                 y = (x % cmd_cols) ? 1 : 0;
  5116.                 n += (x / cmd_cols) + y;
  5117.             } else {
  5118.                 n++;
  5119.             }
  5120.             if (n > (cmd_rows - 3)) {
  5121.                 if (!askmore())
  5122.                   break;
  5123.                 else
  5124.                   n = 0;
  5125.             }
  5126.             }
  5127.         }
  5128.         }
  5129.     }
  5130.     return(1);
  5131.     }
  5132.  
  5133.     /* All arrays - just show name and dimension */
  5134.  
  5135.     for (y = 0; y < (int) 'z' - ARRAYBASE + 1; y++) {
  5136.     if (a_ptr[y]) {
  5137.         if (x == 0) printf("Declared arrays:\n");
  5138.         x = 1;
  5139.         printf(" \\&%c[%d]\n",
  5140.            (y == 1) ? 64 : y + ARRAYBASE, a_dim[y]);
  5141.     }
  5142.     if (!x) printf(" No arrays declared\n");
  5143.     }
  5144.     return(1);
  5145. }
  5146. #endif /* NOSPL */
  5147.  
  5148. int
  5149. doshow(x) int x; {
  5150.     int y, z, i; long zz;
  5151.     extern int optlines;
  5152.     char *s;
  5153. #ifdef OS2
  5154.     extern int os2gks;
  5155.     extern int tt_kb_mode;
  5156. #endif /* OS2 */
  5157.     extern int srvcdmsg;
  5158.     extern char * cdmsgstr, * ckcdpath;
  5159.  
  5160. #ifndef NOSETKEY
  5161.     if (x == SHKEY) {            /* SHOW KEY */
  5162.         int c;
  5163. #ifdef OS2
  5164.         if ((x = cmkey(shokeytab,nshokey,"How many keys should be shown?",
  5165.                         "one",xxstring)) < 0) return(x);
  5166.     switch (tt_kb_mode) {
  5167.       case KBM_EM:
  5168.         s = "emacs";
  5169.         break;
  5170.       case KBM_HE:
  5171.         s = "hebrew";
  5172.         break;
  5173.       case KBM_RU:
  5174.         s = "russian";
  5175.         break;
  5176.       case KBM_EN:
  5177.       default:
  5178.         s = "default";
  5179.         break;
  5180.     }
  5181.         if ((z = cmkey(shokeymtab,nshokeym,"Which definition should be shown?",
  5182.                         s,xxstring)) < 0) return(z);
  5183.     if (z == SHKEYDEF)
  5184.       z = -1;
  5185. #endif /* OS2 */
  5186.         if ((y = cmcfm()) < 0) return(y);
  5187. #ifdef IKSD
  5188.         if (inserver) {
  5189.             printf("Sorry, command disabled.\r\n");
  5190.             return(success = 0);
  5191.         }
  5192. #endif /* IKSD */
  5193.  
  5194. #ifdef MAC
  5195.     printf("Not implemented\n");
  5196.     return(0);
  5197. #else /* Not MAC */
  5198. #ifdef OS2
  5199.         if (x) {
  5200.         con_event evt;
  5201.         for (c = 0; c < KMSIZE; c++) {
  5202.         evt = (z < 0) ? mapkey(c) : maptermkey(c,z);
  5203.         if (evt.type != error) {
  5204.             shokeycode(c,z);
  5205.         }
  5206.         }
  5207.         } else {
  5208. #endif /* OS2 */
  5209.         printf(" Press key: ");
  5210. #ifdef UNIX
  5211. #ifdef NOSETBUF
  5212.         fflush(stdout);
  5213. #endif /* NOSETBUF */
  5214. #endif /* UNIX */
  5215.         conbin((char)escape);    /* Put terminal in binary mode */
  5216. #ifdef OS2
  5217.         os2gks = 0;            /* Raw scancode processing */
  5218. #endif /* OS2 */
  5219.         c = congks(0);        /* Get character or scan code */
  5220. #ifdef OS2
  5221.         os2gks = 1;            /* Cooked scancode processing */
  5222. #endif /* OS2 */
  5223.         concb((char)escape);    /* Restore terminal to cbreak mode */
  5224.         if (c < 0) {        /* Check for error */
  5225.         printf("?Error reading key\n");
  5226.         return(0);
  5227.         }
  5228. #ifndef OS2
  5229. /*
  5230.   Do NOT mask when it can be a raw scan code, perhaps > 255
  5231. */
  5232.         c &= cmdmsk;        /* Apply command mask */
  5233. #endif /* OS2 */
  5234.         printf("\n");
  5235. #ifdef OS2
  5236.         shokeycode(c,z);
  5237. #else /* OS2 */
  5238.         shokeycode(c);
  5239. #endif /* OS2 */
  5240. #ifdef OS2
  5241.         }
  5242. #endif /* OS2 */
  5243.     return(1);
  5244. #endif /* MAC */
  5245.     }
  5246. #ifndef NOKVERBS
  5247.     if (x == SHKVB) {            /* SHOW KVERBS */
  5248.     if ((y = cmcfm()) < 0) return(y);
  5249. #ifdef IKSD
  5250.         if (inserver) {
  5251.             printf("Sorry, command disabled.\r\n");
  5252.             return(success = 0);
  5253.         }
  5254. #endif /* IKSD */
  5255.     printf("\nThe following %d keyboard verbs are available:\n\n",nkverbs);
  5256.     kwdhelp(kverbs,nkverbs,"","\\K","",3,0);
  5257.     printf("\n");
  5258.     return(1);
  5259.     }
  5260. #ifdef OS2
  5261.     if (x == SHUDK) {            /* SHOW UDKs */
  5262.     extern void showudk(void);
  5263.     if ((y = cmcfm()) < 0) return(y);
  5264. #ifdef IKSD
  5265.         if (inserver) {
  5266.             printf("Sorry, command disabled.\r\n");
  5267.             return(success = 0);
  5268.         }
  5269. #endif /* IKSD */
  5270.     showudk();
  5271.     return(1);
  5272.     }
  5273. #endif /* OS2 */
  5274. #endif /* NOKVERBS */
  5275. #endif /* NOSETKEY */
  5276.  
  5277. #ifndef NOSPL
  5278.     if (x == SHMAC) {            /* SHOW MACRO */
  5279.     struct FDB kw, fl, cm;
  5280.     for (y = 0; y < nmac; y++) {    /* copy the macro table */
  5281.         mackey[y].kwd = mactab[y].kwd; /* into a regular keyword table */
  5282.         mackey[y].kwval = y;    /* with value = pointer to macro tbl */
  5283.         mackey[y].flgs = mactab[y].flgs;
  5284.     }
  5285.     /* parse name as keyword */
  5286.     cmfdbi(&kw,                /* First FDB - command switches */
  5287.        _CMKEY,            /* fcode */
  5288.        "Macro name",        /* hlpmsg */
  5289.        "",                /* default */
  5290.        "",                /* addtl string data */
  5291.        nmac,            /* addtl numeric data 1: tbl size */
  5292.        0,                /* addtl numeric data 2: 4 = cmswi */
  5293.        xxstring,            /* Processing function */
  5294.        mackey,            /* Keyword table */
  5295.        &fl                /* Pointer to next FDB */
  5296.        );
  5297.     cmfdbi(&fl,                /* 2nd FDB - command to send from */
  5298.        _CMFLD,            /* fcode */
  5299.        "Pattern",            /* hlpmsg */
  5300.        "",                /* default */
  5301.        "",                /* addtl string data */
  5302.        0,                /* addtl numeric data 1 */
  5303.        0,                /* addtl numeric data 2 */
  5304.        xxstring,
  5305.        NULL,
  5306.        &cm
  5307.        );
  5308.     cmfdbi(&cm,                /* 4th FDB - Confirmation */
  5309.        _CMCFM,            /* fcode */
  5310.        "",                /* hlpmsg */
  5311.        "",                /* default */
  5312.        "",                /* addtl string data */
  5313.        0,                /* addtl numeric data 1 */
  5314.        0,                /* addtl numeric data 2 */
  5315.        NULL,
  5316.        NULL,
  5317.        NULL
  5318.        );
  5319.  
  5320.     x = cmfdb(&kw);
  5321.     if (x < 0) return(x);
  5322.     switch (cmresult.fcode) {
  5323.       case _CMKEY:
  5324.       case _CMFLD:
  5325.         strcpy(line,atmbuf);
  5326.         if ((x = cmcfm()) < 0)
  5327.           return(x);
  5328.         break;
  5329.       case _CMCFM:
  5330.         line[0] = NUL;
  5331.       default:
  5332.         break;
  5333.     }
  5334.     s = line;
  5335.     if (*line) {
  5336.         slc = 0;            /* Initial SHO MAC line number */
  5337.         x = mlook(mactab,s,nmac);    /* Look up what they typed */
  5338.         switch (x) {
  5339.           case -3:            /* Nothing to look up */
  5340.         return(0);
  5341.           case -1:            /* Not found */
  5342.         printf("%s - not found\n",s);
  5343.         return(0);
  5344.           case -2:            /* Ambiguous, matches more than one */
  5345.         y = (int)strlen(line);
  5346.         slc = 1;
  5347.         for (x = 0; x < nmac; x++)
  5348.           if (!strncmp(mactab[x].kwd,line,y))
  5349.             if (shomac(mactab[x].kwd,mactab[x].mval) < 0) break;
  5350.         return(1);
  5351.           default:            /* Matches one exactly */
  5352.         shomac(mactab[x].kwd,mactab[x].mval);
  5353.         return(1);
  5354.         }
  5355.     } else {            /* They want to see them all */
  5356.         printf("Macros:\n");
  5357.         slc = 1;
  5358.         for (y = 0; y < nmac; y++)
  5359.           if (shomac(mactab[y].kwd,mactab[y].mval) < 0) break;
  5360.         return(1);
  5361.     }
  5362.     }
  5363. #endif /* NOSPL */
  5364.  
  5365. /*
  5366.   Other SHOW commands only have two fields.  Get command confirmation here,
  5367.   then handle with big switch() statement.
  5368. */
  5369. #ifndef NOSPL
  5370.     if (x != SHBUI && x != SHARR)
  5371. #endif /* NOSPL */
  5372.       if ((y = cmcfm()) < 0)
  5373.     return(y);
  5374.  
  5375. #ifdef COMMENT
  5376.     /* This restriction is too general. */
  5377. #ifdef IKSD
  5378.     if (inserver &&
  5379. #ifdef CK_LOGIN
  5380.     isguest
  5381. #else
  5382.     0
  5383. #endif /* CK_LOGIN */
  5384.     ) {
  5385.     printf("Sorry, command disabled.\r\n");
  5386.     return(success = 0);
  5387.     }
  5388. #endif /* IKSD */
  5389. #endif /* COMMENT */
  5390.  
  5391.     switch (x) {
  5392.  
  5393. #ifdef ANYX25
  5394. #ifndef IBMX25
  5395.       case SHPAD:
  5396.     shopad(0);
  5397.     break;
  5398. #endif /* IBMX25 */
  5399. #endif /* ANYX25 */
  5400.  
  5401.       case SHNET:
  5402. #ifdef NOLOCAL
  5403.     printf(" No network support in this version of C-Kermit.\n");
  5404. #else
  5405. #ifndef NETCONN
  5406.     printf(" No network support in this version of C-Kermit.\n");
  5407. #else
  5408.     shonet();
  5409. #endif /* NETCONN */
  5410. #endif /* NOLOCAL */
  5411.     break;
  5412.  
  5413.       case SHPAR:
  5414.     shopar();
  5415.     break;
  5416.  
  5417. #ifndef NOXFER
  5418.       case SHATT:
  5419.     shoatt();
  5420.     break;
  5421. #endif /* NOXFER */
  5422.  
  5423. #ifndef NOSPL
  5424.       case SHCOU:
  5425.     printf(" %d\n",count[cmdlvl]);
  5426.     break;
  5427. #endif /* NOSPL */
  5428.  
  5429. #ifndef NOSERVER
  5430.       case SHSER:            /* Show Server */
  5431.     i = 0;
  5432. #ifndef NOFRILLS
  5433.     printf("Function:          Status:\n");
  5434.     i++;
  5435.     printf(" GET                %s\n",nm[en_get]);
  5436.     i++;
  5437.     printf(" SEND               %s\n",nm[en_sen]);
  5438.     i++;
  5439.     printf(" MAIL               %s\n",nm[inserver ? 0 : en_mai]);
  5440.     i++;
  5441.     printf(" PRINT              %s\n",nm[inserver ? 0 : en_pri]);
  5442.     i++;
  5443. #ifndef NOSPL
  5444.     printf(" REMOTE ASSIGN      %s\n",nm[en_asg]);
  5445.     i++;
  5446. #endif /* NOSPL */
  5447.     printf(" REMOTE CD/CWD      %s\n",nm[en_cwd]);
  5448.     i++;
  5449. #ifdef ZCOPY
  5450.     printf(" REMOTE COPY        %s\n",nm[en_cpy]);
  5451.     i++;
  5452. #endif /* ZCOPY */
  5453.     printf(" REMOTE DELETE      %s\n",nm[en_del]);
  5454.     printf(" REMOTE DIRECTORY   %s\n",nm[en_dir]);
  5455.     printf(" REMOTE HOST        %s\n",nm[inserver ? 0 : en_hos]);
  5456.     i += 3;
  5457. #ifndef NOSPL
  5458.     printf(" REMOTE QUERY       %s\n",nm[en_que]);
  5459.     i++;
  5460. #endif /* NOSPL */
  5461.     printf(" REMOTE MKDIR       %s\n",nm[en_mkd]);
  5462.     printf(" REMOTE RMDIR       %s\n",nm[en_rmd]);
  5463.     printf(" REMOTE RENAME      %s\n",nm[en_ren]);
  5464.     printf(" REMOTE SET         %s\n",nm[en_set]);
  5465.     printf(" REMOTE SPACE       %s\n",nm[en_spa]);
  5466.     printf(" REMOTE TYPE        %s\n",nm[en_typ]);
  5467.     printf(" REMOTE WHO         %s\n",nm[inserver ? 0 : en_who]);
  5468.     printf(" BYE                %s\n",nm[en_bye]);
  5469.     printf(" FINISH             %s\n",nm[en_fin]);
  5470.     printf(" EXIT               %s\n",nm[en_xit]);
  5471.     printf(" ENABLE             %s\n",nm[en_ena]);
  5472.     i += 11;
  5473. #endif /* NOFRILLS */
  5474.     if (i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5475.     printf("Server timeout:      %d\n",srvtim);
  5476.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5477.         printf("Server idle-timeout: %d\n",srvidl);
  5478.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5479.     printf("Server keepalive     %s\n", showoff(srvping));
  5480.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5481.     printf("Server cd-message    %s\n", showoff(srvcdmsg));
  5482.     if (srvcdmsg && cdmsgstr)
  5483.       printf("Server cd-message    %s\n", cdmsgstr);
  5484.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5485.     printf("Server display:      %s\n", showoff(srvdis));
  5486.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5487.         printf("Server login:        ");
  5488.     if (!x_user) {
  5489.         printf("(none)\n");
  5490.     } else {
  5491.         printf("\"%s\", \"%s\", \"%s\"\n",
  5492.            x_user,
  5493.            x_passwd ? x_passwd : "",
  5494.            x_acct ? x_acct : ""
  5495.            );
  5496.     }
  5497.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  5498.     printf("Server get-path: ");
  5499.     if (ngetpath == 0) {
  5500.         printf("    (none)\n");
  5501.     } else {
  5502.         printf("\n");
  5503.         i += 3;
  5504.         for (x = 0; x < ngetpath; x++) {
  5505.         if (getpath[x]) printf(" %d. %s\n", x, getpath[x]);
  5506.         if (++i > (cmd_rows - 3)) { /* More than a screenful... */
  5507.             if (!askmore())
  5508.               break;
  5509.             else
  5510.               i = 0;
  5511.         }
  5512.         }
  5513.     }
  5514.     break;
  5515. #endif /* NOSERVER */
  5516.  
  5517.       case SHSTA:            /* Status of last command */
  5518.     printf(" %s\n", success ? "SUCCESS" : "FAILURE");
  5519.     return(0);            /* Don't change it */
  5520.  
  5521.       case SHSTK: {            /* Stack for MAC debugging */
  5522. #ifdef MAC
  5523.       long sp;
  5524.       sp = -1;
  5525.       loadA0 ((char *)&sp);        /* set destination address */
  5526.       SPtoaA0();            /* move SP to destination */
  5527.       printf("Stack at 0x%x\n", sp);
  5528.       show_queue();            /* more debugging */
  5529.       break;
  5530. #else
  5531.       shostack();
  5532. #endif /* MAC */
  5533.       break;
  5534.       }
  5535.  
  5536.  
  5537. #ifdef OS2
  5538.       case SHTAB:            /* SHOW TABS */
  5539. #ifdef IKSD
  5540.         if (inserver) {
  5541.             printf("Sorry, command disabled.\r\n");
  5542.             return(success = 0);
  5543.         }
  5544. #endif /* IKSD */
  5545.         shotabs();
  5546.         break;
  5547. #endif /* OS2 */
  5548.  
  5549. #ifndef NOLOCAL
  5550.       case SHTER:            /* SHOW TERMINAL */
  5551. #ifdef IKSD
  5552.         if (inserver) {
  5553.             printf("Sorry, command disabled.\r\n");
  5554.             return(success = 0);
  5555.         }
  5556. #endif /* IKSD */
  5557.     shotrm();
  5558.     break;
  5559. #endif /* NOLOCAL */
  5560.  
  5561. #ifdef OS2
  5562.       case SHVSCRN:            /* SHOW Virtual Screen - for debug */
  5563.     shovscrn();
  5564.         break;
  5565. #endif /* OS2 */
  5566.  
  5567. #ifdef OS2MOUSE
  5568.       case SHMOU:            /* SHOW MOUSE */
  5569. #ifdef IKSD
  5570.         if (inserver) {
  5571.             printf("Sorry, command disabled.\r\n");
  5572.             return(success = 0);
  5573.         }
  5574. #endif /* IKSD */
  5575.         shomou();
  5576.         break;
  5577. #endif /* OS2MOUSE */
  5578.  
  5579. #ifndef NOFRILLS
  5580.       case SHVER:
  5581.     shover();
  5582.     break;
  5583. #endif /* NOFRILLS */
  5584.  
  5585. #ifndef NOSPL
  5586.       case SHBUI:            /* Built-in variables */
  5587.     if ((y = cmtxt("Variable name or pattern","",&s,xxstring)) < 0)
  5588.       return(y);
  5589.     strcpy(line,s);
  5590.     if (line[0]) strcat(line,"*");
  5591.  
  5592.       case SHFUN:            /* or built-in functions */
  5593. #ifdef CK_TTGWSIZ
  5594. #ifdef OS2
  5595.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  5596.       ttgwsiz();
  5597. #else /* OS2 */
  5598.     if (ttgwsiz() > 0) {        /* Get current screen size */
  5599.         if (tt_rows > 0 && tt_cols > 0) {
  5600.         cmd_rows = tt_rows;
  5601.         cmd_cols = tt_cols;
  5602.         }
  5603.     }
  5604. #endif /* OS2 */
  5605. #endif /* CK_TTGWSIZ */
  5606.  
  5607.     if (x == SHFUN) {        /* Functions */
  5608.         printf("\nThe following functions are available:\n\n");
  5609.         kwdhelp(fnctab,nfuncs,"","\\F","()",3,0);
  5610.         printf("\n");
  5611. #ifndef NOHELP
  5612.         printf(
  5613. "HELP FUNCTION <name> gives the calling conventions of the given function.\n\n"
  5614.            );
  5615. #endif /* NOHELP */
  5616.         break;
  5617.     } else {            /* Variables */
  5618.         i = 0;
  5619.         for (y = 0; y < nvars; y++) {
  5620.         if ((vartab[y].flgs & CM_INV))
  5621.           continue;
  5622.         if (line[0])
  5623.           if (!ckmatch(line,vartab[y].kwd,0,1))
  5624.             continue;
  5625.         s = nvlook(vartab[y].kwd);
  5626.         printf(" \\v(%s) = ",vartab[y].kwd);
  5627.         if (vartab[y].kwval == VN_NEWL) { /* \v(newline) */
  5628.             while (*s)        /* Show control chars symbolically */
  5629.               printf("\\{%d}",*s++);
  5630.             printf("\n");
  5631.         } else if (vartab[y].kwval == VN_IBUF  || /* \v(input) */
  5632.                vartab[y].kwval == VN_QUE   || /* \v(query) */
  5633. #ifdef OS2
  5634.                vartab[y].kwval == VN_SELCT || /* \v(select) */
  5635. #endif /* OS2 */
  5636.                (vartab[y].kwval >= VN_M_AAA && /* modem ones */
  5637.                 vartab[y].kwval <= VN_M_ZZZ)
  5638.                ) {
  5639.             int r = 12;    /* This one can wrap around */
  5640.             char buf[10];
  5641.             while (*s) {
  5642.             if (isprint(*s)) {
  5643.                 buf[0] = *s;
  5644.                 buf[1] = NUL;
  5645.                 r++;
  5646.             } else {
  5647.                 sprintf(buf,"\\{%d}",*s);
  5648.                 r += (int) strlen(buf);
  5649.             }
  5650.             if (r >= cmd_cols - 1) {
  5651.                 printf("\n");
  5652.                 r = 0;
  5653.                 i++;
  5654.             }
  5655.             printf("%s",buf);
  5656.             s++;
  5657.             }
  5658.             printf("\n");
  5659.         } else
  5660.           printf("%s\n",s);
  5661.         if (++i > (cmd_rows - 3)) { /* More than a screenful... */
  5662.             if ((y >= nvars - 1) || !askmore())
  5663.               break;
  5664.             else
  5665.               i = 0;
  5666.         }
  5667.         }
  5668.     }
  5669.     break;
  5670.  
  5671.       case SHVAR:            /* Global variables */
  5672.     x = 0;                /* Variable count */
  5673.     slc = 1;            /* Screen line count for "more?" */
  5674.     for (y = 33; y < GVARS; y++)
  5675.       if (g_var[y]) {
  5676.           if (x++ == 0) printf("Global variables:\n");
  5677.           sprintf(line," \\%%%c",y);
  5678.           if (shomac(line,g_var[y]) < 0) break;
  5679.       }
  5680.     if (!x) printf(" No variables defined\n");
  5681.     break;
  5682.  
  5683.       case SHARG: {            /* Args */
  5684.       char * s1, * s2;
  5685.       if (maclvl > -1) {
  5686.           printf("Macro arguments at level %d (\\v(argc) = %d):\n",
  5687.              maclvl,
  5688.              macargc[maclvl]
  5689.              );
  5690.           for (y = 0; y < macargc[maclvl]; y++) {
  5691.           s1 = m_arg[maclvl][y];
  5692.           if (!s1) s1 = "(NULL)";
  5693.           s2 = m_xarg[maclvl][y];
  5694.           if (!s2) s2 = "(NULL)";
  5695.           if (y < 10)
  5696.             printf(" \\%%%d = %s\n",y,s1);
  5697.           else
  5698.             printf(" \\&_[%d] = %s\n",y,s2);
  5699.           }
  5700.       } else {
  5701.           printf("Top-level arguments (\\v(argc) = %d):\n", topargc);
  5702.           for (y = 0; y < topargc; y++) {
  5703.           s1 = g_var[y + '0'];
  5704.           if (!s1) s1 = "(NULL)";
  5705.           s2 = toparg[y];
  5706.           if (!s2) s2 = "(NULL)";
  5707.           if (y < 10 && g_var[y])
  5708.             printf(" \\%%%d = %s\n",y,s1);
  5709.           if (toparg[y])
  5710.             printf(" \\&_[%d] = %s\n",y,s2);
  5711.           }
  5712.       }
  5713.         }
  5714.     break;
  5715.  
  5716.       case SHARR:            /* Arrays */
  5717.     return(showarray());
  5718. #endif /* NOSPL */
  5719.  
  5720. #ifndef NOXFER
  5721.       case SHPRO:            /* Protocol parameters */
  5722.     shoparp();
  5723.     printf("\n");
  5724.     break;
  5725. #endif /* NOXFER */
  5726.  
  5727. #ifndef NOLOCAL
  5728.       case SHCOM:            /* Communication parameters */
  5729.     printf("\n");
  5730.     shoparc();
  5731. #ifdef OS2
  5732.     {
  5733.         int i;
  5734.         char *s = "(unknown)";
  5735.         for (i = 0; i < nprty; i++)
  5736.           if (prtytab[i].kwval == priority) {
  5737.           s = prtytab[i].kwd;
  5738.           break;
  5739.           }
  5740.         printf(" Priority: %s\n", s );
  5741.     }
  5742. #endif /* OS2 */
  5743.  
  5744.     printf("\n");
  5745. #ifdef NETCONN
  5746.     if (!network
  5747. #ifdef IKSD
  5748.              && !inserver
  5749. #endif /* IKSD */
  5750.              ) {
  5751. #endif /* NETCONN */
  5752.         shomdm();
  5753.         printf("\n");
  5754. #ifdef NETCONN
  5755.     }
  5756. #endif /* NETCONN */
  5757.  
  5758. #ifndef NODIAL
  5759. #ifdef IKSD
  5760.         if ( !inserver )
  5761. #endif /* IKSD */
  5762.         {
  5763.         printf("Type SHOW DIAL to see DIAL-related items.\n");
  5764.         printf("Type SHOW MODEM to see modem-related items.\n");
  5765. #ifdef CK_TAPI
  5766.         printf("Type SHOW TAPI to see TAPI-related items.\n");
  5767. #endif /* CK_TAPI */
  5768.         printf("\n");
  5769.     }
  5770. #endif /* NODIAL */
  5771.     break;
  5772. #endif /* NOLOCAL */
  5773.  
  5774.       case SHFIL:            /* File parameters */
  5775.     shofil();
  5776.     /* printf("\n"); */        /* (out o' space) */
  5777.     break;
  5778.  
  5779. #ifndef NOCSETS
  5780.       case SHLNG:            /* Languages */
  5781.     shoparl();
  5782.     break;
  5783. #endif /* NOCSETS */
  5784.  
  5785. #ifndef NOSPL
  5786.       case SHSCR:            /* Scripts */
  5787.     printf("\n");
  5788.     printf(" Command quoting:        %s\n", showoff(cmdgquo()));
  5789.     printf(" Take  echo:             %s\n", showoff(techo));
  5790.     printf(" Take  error:            %s\n", showoff(takerr[cmdlvl]));
  5791.     printf(" Macro echo:             %s\n", showoff(mecho));
  5792.     printf(" Macro error:            %s\n", showoff(merror[cmdlvl]));
  5793.         printf(" Quiet:                  %s\n", showoff(quiet));
  5794.         printf(" Function diagnostics:   %s\n", showoff(fndiags));
  5795.         printf(" Function error:         %s\n", showoff(fnerror));
  5796.     shoinput();
  5797.     shooutput();
  5798. #ifndef NOSCRIPT
  5799.     printf(" Script echo:            %s\n", showoff(secho));
  5800. #endif /* NOSCRIPT */
  5801.     printf(" Command buffer length:  %d\n", CMDBL);
  5802.     printf(" Atom buffer length:     %d\n", ATMBL);
  5803.     printf("\n");
  5804.     break;
  5805. #endif /* NOSPL */
  5806.  
  5807. #ifndef NOXMIT
  5808.       case SHXMI:
  5809.     printf("\n");
  5810.     printf(" File type:                       %s\n",
  5811.            binary ? "binary" : "text");
  5812. #ifndef NOCSETS
  5813.     printf(" File character-set:              %s\n",
  5814.            fcsinfo[fcharset].keyword);
  5815.     printf(" Terminal character-set (remote): %s\n",
  5816.            fcsinfo[tcsr].keyword);
  5817.     printf(" Terminal character-set (local):  %s\n",
  5818.            fcsinfo[tcsl].keyword);
  5819. #endif /* NOCSETS */
  5820.     printf(" Terminal bytesize:               %d\n",
  5821.            (cmask == 0xff) ? 8 : 7);
  5822.     printf(" Terminal echo:                   %s\n",
  5823.            duplex ? "local" : "remote");
  5824.     printf(" Transmit EOF:                    ");
  5825.     if (*xmitbuf == NUL) {
  5826.         printf("(none)\n");
  5827.     } else {
  5828.         char *p;
  5829.         p = xmitbuf;
  5830.         while (*p) {
  5831.         if (*p < SP)
  5832.           printf("^%c",ctl(*p));
  5833.         else
  5834.           printf("%c",*p);
  5835.         p++;
  5836.         }
  5837.         printf("\n");
  5838.     }
  5839.     if (xmitf)
  5840.       printf(" Transmit Fill:                   %d\n", xmitf);
  5841.     else
  5842.       printf(" Transmit Fill:                   (none)\n");
  5843.     printf(" Transmit Linefeed:               %s\n",showoff(xmitl));
  5844.     if (xmitp)
  5845.       printf(" Transmit Prompt:                 %d (%s)\n",
  5846.          xmitp,
  5847.          chartostr(xmitp)
  5848.          );
  5849.     else
  5850.       printf(" Transmit Prompt:                 (none)\n");
  5851.     printf(" Transmit Echo:                   %s\n", showoff(xmitx));
  5852.     printf(" Transmit Locking-Shift:          %s\n", showoff(xmits));
  5853.     printf(" Transmit Pause:                  %d (millisecond%s)\n",
  5854.            xmitw,
  5855.            (xmitw == 1) ? "" : "s"
  5856.            );
  5857.     printf(" Transmit Timeout:                %d (second%s)\n",
  5858.            xmitt,
  5859.            (xmitt == 1) ? "" : "s"
  5860.            );
  5861.     printf("\n");
  5862.     break;
  5863. #endif /* NOXMIT */
  5864.  
  5865. #ifndef NODIAL
  5866.       case SHMOD:            /* SHOW MODEM */
  5867. #ifdef IKSD
  5868.         if (inserver) {
  5869.             printf("Sorry, command disabled.\r\n");
  5870.             return(success = 0);
  5871.         }
  5872. #endif /* IKSD */
  5873.     shomodem();            /* Show SET MODEM items */
  5874.     break;
  5875. #endif /* NODIAL */
  5876.  
  5877. #ifndef MAC
  5878.       case SHDFLT:
  5879.         printf("%s\n",zgtdir());
  5880.     break;
  5881. #endif /* MAC */
  5882.  
  5883. #ifndef NOLOCAL
  5884.       case SHESC:
  5885. #ifdef IKSD
  5886.         if (inserver) {
  5887.             printf("Sorry, command disabled.\r\n");
  5888.             return(success = 0);
  5889.         }
  5890. #endif /* IKSD */
  5891.     printf(" Escape character: Ctrl-%c (ASCII %d, %s): %s\r\n",
  5892.            ctl(escape), escape, (escape == 127 ? "DEL" : ccntab[escape]),
  5893.        nm[tt_escape]
  5894.        );
  5895.     break;
  5896.  
  5897. #ifndef NODIAL
  5898.       case SHDIA:            /* SHOW DIAL */
  5899. #ifdef IKSD
  5900.         if (inserver) {
  5901.             printf("Sorry, command disabled.\r\n");
  5902.             return(success = 0);
  5903.         }
  5904. #endif /* IKSD */
  5905.     shmdmlin();
  5906.     printf(", speed: ");
  5907.     if ((zz = ttgspd()) < 0) {
  5908.         printf("unknown");
  5909.     } else {
  5910.         if (zz == 8880) printf("75/1200"); else printf("%ld",zz);
  5911.     }
  5912.     if (carrier == CAR_OFF) s = "off";
  5913.     else if (carrier == CAR_ON) s = "on";
  5914.     else if (carrier == CAR_AUT) s = "auto";
  5915.     else s = "unknown";
  5916.     printf(", carrier: %s", s);
  5917.     if (carrier == CAR_ON) {
  5918.         if (cdtimo) printf(", timeout: %d sec", cdtimo);
  5919.         else printf(", timeout: none");
  5920.     }
  5921.     printf("\n");
  5922.     doshodial();
  5923.     if (local
  5924. #ifdef NETCONN
  5925.         && !network
  5926. #endif /* NETCONN */
  5927.         ) {
  5928.         printf("Type SHOW MODEM to see modem settings.\n");
  5929. #ifdef CK_TAPI
  5930.             printf("Type SHOW TAPI to see TAPI-related items\n");
  5931. #endif /* CK_TAPI */
  5932.         printf("Type SHOW COMMUNICATIONS to see modem signals.\n");
  5933.     }
  5934.     break;
  5935. #endif /* NODIAL */
  5936. #endif /* NOLOCAL */
  5937.  
  5938. #ifndef NOXFER
  5939. #ifdef CK_LABELED
  5940.       case SHLBL:            /* Labeled file info */
  5941.     sholbl();
  5942.     break;
  5943. #endif /* CK_LABELED */
  5944. #endif /* NOXFER */
  5945.  
  5946.       case SHCSE:            /* Character sets */
  5947. #ifdef NOCSETS
  5948.     printf(
  5949. " Character set translation is not supported in this version of C-Kermit\n");
  5950. #else
  5951.     shocharset();
  5952. #ifndef NOXFER
  5953.     printf("\n Unknown-Char-Set: %s\n",
  5954.            unkcs ? "Keep" : "Discard");
  5955. #endif /* NOXFER */
  5956. #ifdef OS2
  5957.         printf("\n");
  5958. #endif /* OS2 */
  5959.         shotcs(tcsl,tcsr);
  5960.     printf("\n");
  5961. #ifdef OS2
  5962.         /* PC Code Page information */
  5963.         {
  5964.             char cpbuf[50];
  5965.             int cplist[16], cps;
  5966.             cps = os2getcplist(cplist, sizeof(cplist));
  5967.  
  5968.             sprintf(cpbuf,"%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d",
  5969.                      cps > 1 ? cplist[1] : 0,
  5970.                      cps > 2 ? cplist[2] : 0, cps > 3 ? cplist[3] : 0,
  5971.                      cps > 4 ? cplist[4] : 0, cps > 5 ? cplist[5] : 0,
  5972.                      cps > 6 ? cplist[6] : 0, cps > 7 ? cplist[7] : 0,
  5973.                      cps > 8 ? cplist[8] : 0, cps > 9 ? cplist[9] : 0,
  5974.                      cps > 10 ? cplist[10] : 0, cps > 11 ? cplist[11] : 0,
  5975.                      cps > 12 ? cplist[12] : 0
  5976.                      );
  5977.             printf(" Code Pages:\n");
  5978.             printf("     Active: %d\n",os2getcp());
  5979.             if (!isWin95())
  5980.               printf("  Available: %s\n",cpbuf);
  5981.             printf("\n");
  5982.         }
  5983. #endif /* OS2 */
  5984. #endif /* NOCSETS */
  5985.     break;
  5986.  
  5987.       case SHFEA:            /* Features */
  5988.     shofea();
  5989.     break;
  5990.  
  5991. #ifdef CK_SPEED
  5992.       case SHCTL:            /* Control-Prefix table */
  5993.     shoctl();
  5994.     break;
  5995. #endif /* CK_SPEED */
  5996.  
  5997.       case SHEXI:
  5998.     printf("\n Exit warning %s\n", xitwarn ?
  5999.            (xitwarn == 1 ? "on" : "always") : "off");
  6000.     printf(" Exit on-disconnect: %s\n", showoff(exitonclose));
  6001.     printf(" Current exit status: %d\n\n", xitsta);
  6002.     break;
  6003.  
  6004.       case SHPRT: {
  6005. #ifdef PRINTSWI
  6006.       extern int printtimo, printertype, noprinter;
  6007.       extern char * printterm, * printsep;
  6008. #ifdef BPRINT
  6009.       extern int printbidi;
  6010. #endif /* BPRINT */
  6011. #endif /* PRINTSWI */
  6012.  
  6013. #ifdef IKSD
  6014.         if (inserver &&
  6015. #ifdef CK_LOGIN
  6016.             isguest
  6017. #else /* CK_LOGIN */
  6018.             0
  6019. #endif /* CK_LOGIN */
  6020.              ) {
  6021.             printf("Sorry, command disabled.\r\n");
  6022.             return(success = 0);
  6023.         }
  6024. #endif /* IKSD */
  6025. #ifdef PRINTSWI
  6026.       if (noprinter) {
  6027.           printf("Printer: (none)\n\n");
  6028.           break;
  6029.       }
  6030. #endif /* PRINTSWI */
  6031.  
  6032.       printf("Printer: %s%s\n",
  6033.  
  6034.          printpipe ? "| " : "",
  6035.          printername ? printername :
  6036. #ifdef OS2
  6037.          "PRN"
  6038. #else
  6039.          "(default)"
  6040. #endif /* OS2 */
  6041.          );
  6042. #ifdef PRINTSWI
  6043. #ifdef BPRINT
  6044.       if (printbidi) {
  6045.           printf(" /BIDIRECTIONAL\n");
  6046.           if (pportspeed > 0)
  6047.         printf(" /SPEED:%ld\n",pportspeed);
  6048.           printf(" /PARITY:%s\n",parnam((char)pportparity));
  6049.           printf(" /FLOW:%s\n",
  6050.              pportflow == FLO_NONE ? "NONE" :
  6051.              (pportflow == FLO_RTSC ? "RTS/CTS" : "XON/XOFF")
  6052.              );
  6053.       } else
  6054.         printf(" /OUTPUT-ONLY\n");
  6055. #endif /* BPRINT */
  6056.       switch (printertype) {
  6057.         case PRT_NON: printf(" /NONE\n"); break;
  6058.         case PRT_FIL: printf(" /FILE\n"); break;
  6059.         case PRT_PIP: printf(" /PIPE\n"); break;
  6060.         case PRT_DOS: printf(" /DOS-DEVICE\n"); break;
  6061.         case PRT_WIN: printf(" /WINDOWS-QUEUE\n"); break;
  6062.       }
  6063.       printf(" /TIMEOUT:%d\n",printtimo);
  6064.           if (printterm) {
  6065.               printf(" /END-OF-JOB-STRING:");
  6066.               shostrdef(printterm);
  6067.               printf("\n");
  6068.           } else
  6069.         printf(" /END-OF-JOB-STRING:(none)\n");
  6070.       printf(" /JOB-HEADER-FILE:%s\n",printsep ? printsep : "(none)");
  6071. #endif /* PRINTSWI */
  6072.       printf("\n");
  6073.       break;
  6074.       }
  6075.  
  6076.       case SHCMD:
  6077. #ifdef CK_AUTODL
  6078.     printf(" Command autodownload: %s\n",showoff(cmdadl));
  6079. #else
  6080.     printf(" Command autodownload: (not available)\n");
  6081. #endif /* CK_AUTODL */
  6082.     printf(" Command bytesize: %d bits\n",
  6083.            (cmdmsk == 0377) ? 8 : 7);
  6084. #ifdef CK_RECALL
  6085.     printf(" Command recall-buffer-size: %d\n",cm_recall);
  6086. #else
  6087.     printf(" Command recall-buffer not available in this version\n");
  6088. #endif /* CK_RECALL */
  6089. #ifdef CK_RECALL
  6090.     printf(" Command retry: %s\n",showoff(cm_retry));
  6091. #else
  6092.     printf(" Command retry not available in this version\n");
  6093. #endif /* CK_RECALL */
  6094.     printf(" Command interruption: %s\n", showoff(cmdint));
  6095.     printf(" Command quoting: %s\n", showoff(cmdgquo()));
  6096.     printf(" Command more-prompting: %s\n", showoff(xaskmore));
  6097.     printf(" Command height: %d\n", cmd_rows);
  6098.     printf(" Command width:  %d\n", cmd_cols);
  6099.     printf(" Hints:          %s\n", showoff(hints));
  6100.     printf(" Quiet:          %s\n", showoff(quiet));
  6101.     printf(" Maximum command length: %d\n", CMDBL);
  6102. #ifndef NOSPL
  6103.     printf(" Maximum number of macros: %d\n", MAC_MAX);
  6104.     printf(" Macros defined: %d\n", nmac);
  6105.     printf(" Maximum macro depth: %d\n", MACLEVEL);
  6106.     printf(" Maximum TAKE depth: %d\n", MAXTAKE);
  6107. #endif /* NOSPL */
  6108. #ifdef UNIX
  6109. #ifndef NOJC
  6110.     printf(" Suspend: %s\n", showoff(suspend));
  6111. #endif /* NOJC */
  6112. #endif /* UNIX */
  6113.     break;
  6114.  
  6115. #ifndef NOSPL
  6116.       case SHALRM:
  6117.     if (ck_alarm)
  6118.       printf("Alarm at %s %s\n",alrm_date,alrm_time);
  6119.     else
  6120.       printf("(no alarm set)\n");
  6121.     break;
  6122. #endif /* NOSPL */
  6123.  
  6124. #ifndef NOMSEND
  6125.       case SHSFL: {
  6126.       extern struct filelist * filehead;
  6127.       if (!filehead) {
  6128.           printf("send-list is empty\n");
  6129.       } else {
  6130.           struct filelist * flp;
  6131.           char * s;
  6132.           flp = filehead;
  6133.           while (flp) {
  6134.           s = flp->fl_alias;
  6135.           if (!s) s = "(none)";
  6136.           printf("%s, mode: %s, alias: %s\n",
  6137.              flp->fl_name,
  6138.              gfmode(flp->fl_mode,0),
  6139.              s
  6140.              );
  6141.           flp = flp->fl_next;
  6142.           }
  6143.       }
  6144.       }
  6145.       break;
  6146. #endif /* NOMSEND */
  6147.  
  6148. #ifdef CKXXCHAR
  6149.       case SHDBL:
  6150.     shodbl();
  6151.     break;
  6152. #endif /* CKXXCHAR */
  6153.  
  6154. #ifndef NOPUSH
  6155. #ifndef NOFRILLS
  6156.       case SHEDIT:
  6157.     if (!editor[0]) {
  6158.         s = getenv("EDITOR");
  6159.         if (s) ckstrncpy(editor,s,CKMAXPATH);
  6160.     }
  6161.     printf("\n editor:  %s\n", editor[0] ? editor : "(none)");
  6162.     if (editor[0]) {
  6163.         printf(" options: %s\n", editopts[0] ? editopts : "(none)");
  6164.         printf(" file:    %s\n", editfile[0] ? editfile : "(none)");
  6165.         }
  6166.     printf("\n");
  6167.     break;
  6168.  
  6169. #ifdef BROWSER
  6170.       case SHBROWSE:
  6171.     if (!browser[0]) {
  6172.         s = getenv("BROWSER");
  6173.         if (s) ckstrncpy(browser,s,CKMAXPATH);
  6174.     }
  6175.     printf("\n browser: %s\n", browser[0] ? browser : "(none)");
  6176.     if (browser[0]) {
  6177.         printf(" options: %s\n", browsopts[0] ? browsopts : "(none)");
  6178.         printf(" url:     %s\n", browsurl[0] ? browsurl : "(none)");
  6179.     }
  6180.     printf("\n");
  6181.     break;
  6182. #endif /* BROWSER */
  6183. #endif /*  NOFRILLS */
  6184. #endif /* NOPUSH */
  6185.  
  6186. #ifndef NOLOCAL
  6187. #ifdef CK_TAPI
  6188.       case SHTAPI:            /* TAPI options */
  6189. #ifdef IKSD
  6190.         if (inserver) {
  6191.             printf("Sorry, command disabled.\r\n");
  6192.             return(success = 0);
  6193.         }
  6194. #endif /* IKSD */
  6195.     shotapi(0);
  6196.     break;
  6197.       case SHTAPI_L:            /* TAPI Locations */
  6198. #ifdef IKSD
  6199.         if (inserver) {
  6200.             printf("Sorry, command disabled.\r\n");
  6201.             return(success = 0);
  6202.         }
  6203. #endif /* IKSD */
  6204.     shotapi(1);
  6205.     break;
  6206.       case SHTAPI_M:            /* TAPI Modem */
  6207. #ifdef IKSD
  6208.         if (inserver) {
  6209.             printf("Sorry, command disabled.\r\n");
  6210.             return(success = 0);
  6211.         }
  6212. #endif /* IKSD */
  6213.     shotapi(2);
  6214.     break;
  6215.       case SHTAPI_C:            /* TAPI Comm */
  6216. #ifdef IKSD
  6217.         if (inserver) {
  6218.             printf("Sorry, command disabled.\r\n");
  6219.             return(success = 0);
  6220.         }
  6221. #endif /* IKSD */
  6222.     shotapi(3);
  6223.     break;
  6224. #endif /* CK_TAPI */
  6225.  
  6226. #ifdef TNCODE
  6227.       case SHTEL:            /* TELNET */
  6228.     printf("\n");
  6229.     shotel(0);
  6230.     printf("\n");
  6231.     break;
  6232.  
  6233.       case SHTOPT:            /* TELNET OPTIONS */
  6234.         printf("\n");
  6235.         shotopt(0);
  6236.         printf("\n");
  6237.         break;
  6238. #endif /* TNCODE */
  6239.  
  6240. #ifdef CK_TRIGGER
  6241.       case SHTRIG: {
  6242.       extern char * tt_trigger[], * triggerval;
  6243.       int i;
  6244.       if (!tt_trigger[0]) {
  6245.           printf(" Triggers: (none)\n");
  6246.       } else {
  6247.           printf(" Triggers:\n");
  6248.           for (i = 0; i < TRIGGERS; i++) {
  6249.           if (!tt_trigger[i])
  6250.             break;
  6251.           printf("  \"%s\"\n",tt_trigger[i]);
  6252.           }
  6253.           printf(" Most recent trigger encountered: ");
  6254.           if (triggerval)
  6255.         printf("\"%s\"\n",triggerval);
  6256.           else
  6257.         printf("(none)\n");
  6258.       }
  6259.       break;
  6260.       }
  6261. #endif /* CK_TRIGGER */
  6262. #endif /* NOLOCAL */
  6263.  
  6264. #ifndef NOSPL
  6265.       case SHINP:
  6266.     shoinput();
  6267.     break;
  6268. #endif /* NOSPL */
  6269.  
  6270.       case SHLOG: {
  6271. #ifndef MAC
  6272.       extern int xferlog;
  6273. #ifdef IKSD
  6274.           if (inserver &&
  6275. #ifdef CK_LOGIN
  6276.               isguest
  6277. #else /* CK_LOGIN */
  6278.               0
  6279. #endif /* CK_LOGIN */
  6280.              ) {
  6281.             printf("Sorry, command disabled.\r\n");
  6282.             return(success = 0);
  6283.         }
  6284. #endif /* IKSD */
  6285. #ifdef DEBUG
  6286.       printf("\n Debug log:       %s\n", deblog ? debfil : "(none)");
  6287. #endif /* DEBUG */
  6288. #ifndef NOXFER
  6289.       printf(" Packet log:      %s\n",   pktlog ? pktfil : "(none)");
  6290. #endif /* NOXFER */
  6291. #ifndef NOLOCAL
  6292.       printf(" Session log:     %s\n",   seslog ? sesfil : "(none)");
  6293. #endif /* NOLOCAL */
  6294. #ifdef TLOG
  6295.       if (tralog || (xferlog && tlogfmt == 2)) {
  6296.           extern int tlogsep;
  6297.           printf(" Transaction log: %s (%s)",
  6298.              trafil,
  6299.              tlogfmt ?
  6300.              ((tlogfmt == 2) ? "ftp" : "verbose") :
  6301.              "brief"
  6302.              );
  6303.           if (tlogfmt == 0)
  6304.         printf(" (separator='%c')", (char)tlogsep);
  6305.           printf("\n\n");
  6306.       } else
  6307.         printf(" Transaction log: (none)\n");
  6308. #endif /* TLOG */
  6309. #ifdef CKLOGDIAL
  6310.           printf(" Connection log:  %s\n", dialog ? diafil : "(none)");
  6311. #endif /* CKLOGDIAL */
  6312.       printf("\n");
  6313. #endif /* MAC */
  6314.       break;
  6315.       }
  6316.  
  6317. #ifndef NOSPL
  6318.       case SHOUTP:            /* OUTPUT */
  6319.     shooutput();
  6320.     break;
  6321. #endif /* NOSPL */
  6322.  
  6323. #ifdef PATTERNS
  6324.       case SHOPAT:            /* PATTERNS */
  6325.     shopat();
  6326.     break;
  6327. #endif /* PATTERNS */
  6328.  
  6329. #ifdef STREAMING
  6330.       case SHOSTR: {            /* STREAMING */
  6331.       extern int streamrq, tsecs, clearrq, cleared;
  6332.       extern long tfc;
  6333.       extern long tfcps;
  6334.       printf("\n Reliable:     %s\n",showooa(reliable));
  6335.       printf(" Clearchannel: %s\n",showooa(clearrq));
  6336.       printf(" Streaming:    %s\n\n",showooa(streamrq));
  6337.       if (!local && streamrq == SET_ON ||
  6338.           streamrq == SET_AUTO && reliable)
  6339.         printf(" Streaming will be done if requested.\n");
  6340.       else if (streamrq == SET_OFF || streamrq == SET_AUTO && !reliable)
  6341.         printf(" Streaming will not be requested and will not be done.\n");
  6342.       else if (streamrq == SET_ON || streamrq == SET_AUTO && reliable)
  6343.         printf(
  6344. " Streaming will be requested and will be done if the other Kermit agrees.\n");
  6345.       printf(" Last transfer: %sstreaming%s, %ld cps.\n",
  6346.          streamed > 0 ? "" : "no ",
  6347.          cleared ? ", clearchannel" : "",
  6348.          tfcps
  6349.          );
  6350.       printf("\n");
  6351.       break;
  6352.       }
  6353. #endif /* STREAMING */
  6354. #ifdef CK_AUTHENTICATION
  6355.       case SHOAUTH:
  6356.     return(sho_auth(0));
  6357. #endif /* CK_AUTHENTICATION */
  6358.  
  6359. #ifdef BROWSER
  6360.       case SHOFTP: {
  6361.       extern char ftpapp[], ftpopts[];
  6362. #ifdef IKSD
  6363.         if (inserver) {
  6364.             printf("Sorry, command disabled.\r\n");
  6365.             return(success = 0);
  6366.         }
  6367. #endif /* IKSD */
  6368.       printf("\n ftp-client:  %s\n", ftpapp[0] ? ftpapp : "(none)");
  6369.       if (ftpapp[0]) {
  6370.           printf(" ftp options: %s\n", ftpopts[0] ? ftpopts : "(none)");
  6371.       }
  6372.       printf("\n");
  6373.       break;
  6374.       }
  6375. #endif /* BROWSER */
  6376.  
  6377. #ifndef NOCMDL
  6378.       case SHXOPT: {
  6379. #ifdef IKSDB
  6380.       extern unsigned long mystate;
  6381.       extern int dbenabled;
  6382.       extern char * dbfile, * dbdir, myhexip[];
  6383.       extern unsigned long mypid;
  6384. #endif /* IKSDB */
  6385. #ifdef CKWTMP
  6386.       extern int ckxwtmp;
  6387.       extern char * wtmpfile;
  6388. #endif /* CKWTMP */
  6389. #ifdef CK_LOGIN
  6390.       extern int ckxanon, ckxpriv, ckxperms, xferlog, logintimo;
  6391.       extern char * xferfile;
  6392. #endif /* CK_LOGIN */
  6393.       extern char * bannerfile, * helpfile;
  6394.  
  6395. #ifdef IKSD
  6396.           if (inserver &&
  6397. #ifdef CK_LOGIN
  6398.               isguest
  6399. #else /* CK_LOGIN */
  6400.               0
  6401. #endif /* CK_LOGIN */
  6402.           ) {
  6403.           printf("Sorry, command disabled.\r\n");
  6404.           return(success = 0);
  6405.       }
  6406. #endif /* IKSD */
  6407.       printf("\n");
  6408.       if (!cmdint)
  6409.         printf(" --nointerrupts\n");
  6410.       printf(" --bannerfile=%s\n",bannerfile ? bannerfile : "(null)");
  6411.       printf(" --cdfile:%s\n",cdmsgstr ? cdmsgstr : "(null)");
  6412.       printf(" --cdmessage:%d\n",srvcdmsg);
  6413.       printf(" --helpfile:%d\n",helpfile);
  6414.       if (inserver) {
  6415.           printf("\n");
  6416.           break;
  6417.       }
  6418. #ifdef CKSYSLOG
  6419. #ifdef SYSLOGLEVEL
  6420.       printf(" --syslog:%d (forced)\n",ckxsyslog);
  6421. #else
  6422.       printf(" --syslog:%d\n",ckxsyslog);
  6423. #endif /* SYSLOGLEVEL */
  6424. #endif /* CKSYSLOG */
  6425. #ifdef CKWTMP
  6426.       printf(" --wtmplog:%d\n",ckxwtmp);
  6427.       printf(" --wtmpfile=%s\n",wtmpfile ? wtmpfile : "(null)");
  6428. #endif /* CKWTMP */
  6429. #ifdef IKSD
  6430. #ifdef CK_LOGIN
  6431.       printf(" --anonymous:%d\n",ckxanon);
  6432.       printf(" --privid:%d\n",ckxpriv);
  6433.       printf(" --permission:%04o\n",ckxperms);
  6434.       printf(" --initfile:%s\n",anonfile ? anonfile : "(null)");
  6435.       printf(" --userfile:%s\n",userfile ? userfile : "(null)");
  6436.       printf(" --root:%s\n",anonroot ? anonroot : "(null)");
  6437.       printf(" --xferlog=%d\n",xferlog);
  6438.       printf(" --xferfile=%s\n",xferfile ? xferfile : "(null)");
  6439.       printf(" --timeout=%d\n",logintimo);
  6440. #endif /* CK_LOGIN */
  6441. #ifdef IKSDB
  6442.       printf(" --database=%d\n",dbenabled);
  6443.       printf(" --dbfile=%s\n",dbfile ? dbfile : "(null)");
  6444.       if (dbdir)
  6445.         printf("   (db directory=[%s])\n",dbdir);
  6446. #endif /* IKSDB */
  6447. #ifdef IKSDCONF
  6448.       printf(" IKSD conf=%s\n",iksdconf);
  6449. #endif /* IKSDCONF */
  6450. #endif /* IKSD */
  6451.       printf("\n");
  6452.       break;
  6453.       }
  6454. #endif /* NOCMDL */
  6455.  
  6456.       case SHCD:
  6457.     s = getenv("CDPATH");
  6458.     if (!s) s = "(none)";
  6459.         printf("\n current directory:  %s\n", zgtdir());
  6460.         printf(" previous directory: %s\n", prevdir ? prevdir : "(none)");
  6461.         printf(" cd path:            %s\n", ckcdpath ? ckcdpath : s);
  6462.     printf(" cd message:         %s\n", showoff(srvcdmsg & 2));
  6463.     printf(" server cd-message:  %s\n", showoff(srvcdmsg & 1));
  6464.     printf(" cd message file:    %s\n\n", cdmsgstr ? cdmsgstr : "(none)");
  6465.     break;
  6466.  
  6467. #ifndef NOCSETS
  6468.       case SHASSOC:
  6469.     (VOID) showassoc();
  6470.     break;
  6471. #endif /* NOCSETS */
  6472.  
  6473. #ifdef CKLOGDIAL
  6474.       case SHCONNX:
  6475.     (VOID) dologshow(1);
  6476.     break;
  6477. #endif /* CKLOGDIAL */
  6478.  
  6479.       case SHOPTS:
  6480.     optlines = 0;
  6481. #ifndef NOFRILLS
  6482.     (VOID) showdelopts();
  6483. #endif /* NOFRILLS */
  6484. #ifdef DOMYDIR
  6485.     (VOID) showdiropts();
  6486. #endif /* DOMYDIR */
  6487. #ifdef CKPURGE
  6488.     (VOID) showpurgopts();
  6489. #endif /* CKPURGE */
  6490.     (VOID) showtypopts();
  6491.     break;
  6492.  
  6493. #ifndef NOLOCAL
  6494.       case SHOFLO:
  6495.     (VOID) shoflow();
  6496.     break;
  6497. #endif /* NOLOCAL */
  6498.  
  6499. #ifndef NOXFER
  6500.       case SHOXFER:
  6501.     (VOID) shoxfer();
  6502.     break;
  6503. #endif /* NOXFER */
  6504.  
  6505.       default:
  6506.     printf("\nNothing to show...\n");
  6507.     return(-2);
  6508.     }
  6509.     return(success = 1);
  6510. }
  6511.  
  6512. #ifndef NOXFER
  6513. int
  6514. shoatt() {
  6515.     printf("Attributes: %s\n", showoff(atcapr));
  6516.     if (!atcapr) return(0);
  6517.     printf(" Blocksize: %s\n", showoff(atblki));
  6518.     printf(" Date: %s\n", showoff(atdati));
  6519.     printf(" Disposition: %s\n", showoff(atdisi));
  6520.     printf(" Encoding (Character Set): %s\n", showoff(atenci));
  6521.     printf(" Length: %s\n", showoff(atleni));
  6522.     printf(" Type (text/binary): %s\n", showoff(attypi));
  6523.     printf(" System ID: %s\n", showoff(atsidi));
  6524.     printf(" System Info: %s\n", showoff(atsysi));
  6525. #ifdef CK_PERMS
  6526.     printf(" Protection: %s\n", showoff(atlpri));
  6527. #endif /* CK_PERMS */
  6528. #ifdef STRATUS
  6529.     printf(" Format: %s\n", showoff(atfrmi));
  6530.     printf(" Creator: %s\n", showoff(atcrei));
  6531.     printf(" Account: %s\n", showoff(atacti));
  6532. #endif /* STRATUS */
  6533.     return(0);
  6534. }
  6535. #endif /* NOXFER */
  6536.  
  6537. #ifndef NOSPL
  6538. int                    /* SHOW MACROS */
  6539. shomac(s1, s2) char *s1, *s2; {
  6540.     int x, n, pp;
  6541.     pp = 0;                /* Parenthesis counter */
  6542.  
  6543.     debug(F110,"shomac s1",s1,0);
  6544.     debug(F110,"shomac s2",s2,0);
  6545.  
  6546.     if (!s1)
  6547.       return(0);
  6548.     else
  6549.       printf("\n%s = ",s1);        /* Print blank line and macro name */
  6550.     slc++;                /* Count the line */
  6551.     n = (int)strlen(s1) + 4;        /* Width of current line */
  6552.     if (!s2) s2 = "(null definition)";
  6553.  
  6554.     while (x = *s2++) {            /* Loop thru definition */
  6555.     if (x == '(') pp++;        /* Treat commas within parens */
  6556.     if (x == ')') pp--;        /* as ordinary text */
  6557.     if (pp < 0) pp = 0;        /* Outside parens, */
  6558.     if (x == ',' && pp == 0) {    /* comma becomes comma-dash-NL. */
  6559.         putchar(',');
  6560.         putchar('-');
  6561.         x = '\n';
  6562.     }
  6563.     putchar((CHAR)x);        /* Output the character */
  6564.     if (x == '\n') {        /* If it was a newline */
  6565. #ifdef UNIX
  6566. #ifdef NOSETBUF
  6567.         fflush(stdout);
  6568. #endif /* NOSETBUF */
  6569. #endif /* UNIX */
  6570.         putchar(' ');        /* Indent the next line 1 space */
  6571.         while(*s2 == ' ') s2++;    /* skip past leading blanks */
  6572.         n = 2;            /* restart the character counter */
  6573.         slc++;            /* and increment the line counter. */
  6574.     } else if (++n > (cmd_cols - 1)) { /* If line is too wide */
  6575.         putchar('-');        /* output a dash */
  6576.         putchar(NL);        /* and a newline */
  6577. #ifdef UNIX
  6578. #ifdef NOSETBUF
  6579.         fflush(stdout);
  6580. #endif /* NOSETBUF */
  6581. #endif /* UNIX */
  6582.         n = 1;            /* and restart the char counter */
  6583.         slc++;            /* and increment the line counter */
  6584.     }
  6585.     if (n < 3 && slc > (cmd_rows - 3)) { /* If new line and screen full */
  6586.         if (!askmore()) return(-1);    /* ask if they want more. */
  6587.         n = 1;            /* They do, start a new line */
  6588.         slc = 0;            /* and restart line counter */
  6589.     }
  6590.     }
  6591.     putchar(NL);            /* End of definition */
  6592.     if (++slc > (cmd_rows - 3)) {
  6593.     if (!askmore()) return(-1);
  6594.     slc = 0;
  6595.     }
  6596.     return(0);
  6597. }
  6598. #endif /* NOSPL */
  6599. #endif /* NOSHOW */
  6600.  
  6601. int x_ifnum = 0;            /* Flag for IF NUMERIC active */
  6602.  
  6603. #ifndef NOSPL
  6604. /* Evaluate an arithmetic expression. */
  6605. /* Code adapted from ev, by Howie Kaye of Columbia U & others. */
  6606.  
  6607. static int xerror;
  6608. static char *cp;
  6609. static long tokval;
  6610. static char curtok;
  6611. static long expval;
  6612.  
  6613. #define LONGBITS (8*sizeof (long))
  6614. #define NUMBER 'N'
  6615. #define N_EOT 'E'
  6616.  
  6617. /*
  6618.  Replacement for strchr() and index(), neither of which seem to be universal.
  6619. */
  6620.  
  6621. static char *
  6622. #ifdef CK_ANSIC
  6623. windex(char * s, char c)
  6624. #else
  6625. windex(s,c) char *s, c;
  6626. #endif /* CK_ANSIC */
  6627. /* windex */ {
  6628.     while (*s != NUL && *s != c) s++;
  6629.     if (*s == c) return(s); else return(NULL);
  6630. }
  6631.  
  6632. /*
  6633.  g e t t o k
  6634.  
  6635.  Returns the next token.  If token is a NUMBER, sets tokval appropriately.
  6636. */
  6637. static char
  6638. gettok() {
  6639.  
  6640.     while (isspace(*cp))        /* Skip past leading spaces */
  6641.       cp++;
  6642.  
  6643.     switch (*cp) {
  6644.       case '$':                /* ??? */
  6645.       case '+':                /* Add */
  6646.       case '-':                /* Subtract or Negate */
  6647.       case '@':                /* Greatest Common Divisor */
  6648.       case '*':                /* Multiply */
  6649.       case '/':                /* Divide */
  6650.       case '%':                /* Modulus */
  6651.       case '<':                /* Left shift */
  6652.       case '>':                /* Right shift */
  6653.       case '&':                /* And */
  6654.       case '|':                /* Or */
  6655.       case '#':                /* Exclusive Or */
  6656.       case '~':                /* Not */
  6657.       case '^':                /* Exponent */
  6658.       case '!':                /* Factorial */
  6659.       case '(':                /* Parens for grouping */
  6660.       case ')': return(*cp++);        /* operator, just return it */
  6661.       case '\n':
  6662.       case '\0': return(N_EOT);        /* End of line, return that */
  6663.     }
  6664.     if (isxdigit(*cp)) {        /* Digit, must be a number */
  6665.     char tbuf[80],*tp;        /* Buffer to accumulate number */
  6666.     int radix = 10;            /* Default radix */
  6667.     for (tp = tbuf; isxdigit(*cp); cp++)
  6668.       *tp++ = (char) (isupper(*cp) ? tolower(*cp) : *cp);
  6669.     *tp = '\0';            /* End number */
  6670.     switch(isupper(*cp) ? tolower(*cp) : *cp) { /* Examine break char */
  6671.       case 'h':
  6672.       case 'x': radix = 16; cp++; break; /* if radix signifier... */
  6673.       case 'o':
  6674.       case 'q': radix = 8; cp++; break;
  6675.       case 't': radix = 2; cp++; break;
  6676.     }
  6677.     for (tp = tbuf, tokval = 0; *tp != '\0'; tp++)  {
  6678.         int dig;
  6679.         dig = *tp - '0';        /* Convert number */
  6680.         if (dig > 10) dig -= 'a'-'0'-10;
  6681.         if (dig >= radix) {
  6682.         xerror = 1;
  6683.         if (cmdlvl == 0 && !x_ifnum)
  6684.           printf("invalid digit '%c' in number\n",*tp);
  6685.         return(NUMBER);
  6686.         }
  6687.         tokval = radix*tokval + dig;
  6688.     }
  6689.     return(NUMBER);
  6690.     }
  6691.     if (cmdlvl == 0 && !x_ifnum)
  6692.       printf("Invalid character '%c' in input\n",*cp);
  6693.     xerror = 1;
  6694.     cp++;
  6695.     return(gettok());
  6696. }
  6697.  
  6698. static long
  6699. #ifdef CK_ANSIC
  6700. expon(long x, long y)
  6701. #else
  6702. expon(x,y) long x,y;
  6703. #endif /* CK_ANSIC */
  6704. /* expon */ {
  6705.     long result = 1;
  6706.     int sign = 1;
  6707.     if (y < 0) return(0);
  6708.     if (x < 0) {
  6709.     x = -x;
  6710.     if (y & 1) sign = -1;
  6711.     }
  6712.     while (y != 0) {
  6713.     if (y & 1) result *= x;
  6714.     y >>= 1;
  6715.     if (y != 0) x *= x;
  6716.   }
  6717.   return(result * sign);
  6718. }
  6719.  
  6720. /*
  6721.  * factor ::= simple | simple ^ factor
  6722.  *
  6723.  */
  6724. static VOID
  6725. factor() {
  6726.     long oldval;
  6727.     simple();
  6728.     if (curtok == '^') {
  6729.     oldval = expval;
  6730.     curtok = gettok();
  6731.     factor();
  6732.     expval = expon(oldval,expval);
  6733.     }
  6734. }
  6735.  
  6736. /*
  6737.  * termp ::= NULL | {*,/,%,&} factor termp
  6738.  *
  6739.  */
  6740. static VOID
  6741. termp() {
  6742.     while (curtok == '*' || curtok == '/' || curtok == '%' || curtok == '&') {
  6743.     long oldval;
  6744.     char op;
  6745.     op = curtok;
  6746.     curtok = gettok();        /* skip past operator */
  6747.     oldval = expval;
  6748.     factor();
  6749.     switch(op) {
  6750.       case '*': expval = oldval * expval; break;
  6751.       case '/':
  6752.       case '%':
  6753.         if (expval == 0) {
  6754.         if (!x_ifnum)
  6755.           printf("?Divide by zero\n");
  6756.         expval = -1; /* No way to return a null integer */
  6757.         } else
  6758.           expval = (op == '/') ? (oldval / expval) : (oldval % expval);
  6759.         break;
  6760.       case '&':
  6761.         expval = oldval & expval; break;
  6762.     }
  6763.     }
  6764. }
  6765.  
  6766. static long
  6767. #ifdef CK_ANSIC
  6768. fact(long x)
  6769. #else
  6770. fact(x) long x;
  6771. #endif /* CK_ANSIC */
  6772. /* fact */ {                /* factorial */
  6773.     long result = 1;
  6774.     while (x > 1)
  6775.       result *= x--;
  6776.     return(result);
  6777. }
  6778.  
  6779. /*
  6780.  * term ::= factor termp
  6781.  *
  6782.  */
  6783. static VOID
  6784. term() {
  6785.     factor();
  6786.     termp();
  6787. }
  6788.  
  6789. static long
  6790. #ifdef CK_ANSIC
  6791. gcd(long x, long y)
  6792. #else
  6793. gcd(x,y) long x,y;
  6794. #endif /* CK_ANSIC */
  6795. /* gcd */ {                /* Greatest Common Divisor */
  6796.     int nshift = 0;
  6797.     if (x < 0) x = -x;
  6798.     if (y < 0) y = -y;            /* validate arguments */
  6799.     if (x == 0 || y == 0) return(x + y);    /* this is bogus */
  6800.  
  6801.     while (!((x & 1) | (y & 1))) {    /* get rid of powers of 2 */
  6802.     nshift++;
  6803.     x >>= 1;
  6804.     y >>= 1;
  6805.     }
  6806.     while (x != 1 && y != 1 && x != 0 && y != 0) {
  6807.     while (!(x & 1)) x >>= 1;    /* eliminate unnecessary */
  6808.     while (!(y & 1)) y >>= 1;    /* powers of 2 */
  6809.     if (x < y) {            /* force x to be larger */
  6810.         long t;
  6811.         t = x;
  6812.         x = y;
  6813.         y = t;
  6814.     }
  6815.     x -= y;
  6816.     }
  6817.     if (x == 0 || y == 0) return((x + y) << nshift); /* gcd is non-zero one */
  6818.     else return((long) 1 << nshift);    /* else gcd is 1 */
  6819. }
  6820.  
  6821. /*
  6822.  * exprp ::= NULL | {+,-,|,...} term exprp
  6823.  *
  6824.  */
  6825. static VOID
  6826. exprp() {
  6827.     while (windex("+-|<>#@",curtok) != NULL) {
  6828.     long oldval;
  6829.     char op;
  6830.     op = curtok;
  6831.     curtok = gettok();        /* skip past operator */
  6832.     oldval = expval;
  6833.     term();
  6834.     switch(op) {
  6835.       case '+' : expval = oldval + expval; break;
  6836.       case '-' : expval = oldval - expval; break;
  6837.       case '|' : expval = oldval | expval; break;
  6838.       case '#' : expval = oldval ^ expval; break;
  6839.       case '@' : expval = gcd(oldval,expval); break;
  6840.       case '<' : expval = oldval << expval; break;
  6841.       case '>' : expval = oldval >> expval; break;
  6842.     }
  6843.     }
  6844. }
  6845.  
  6846. /*
  6847.  * expr ::= term exprp
  6848.  *
  6849.  */
  6850. static VOID
  6851. expr() {
  6852.     term();
  6853.     exprp();
  6854. }
  6855.  
  6856. static long
  6857. xparse() {
  6858.     curtok = gettok();
  6859.     expr();
  6860. #ifdef COMMENT
  6861.     if (curtok == '$') {
  6862.     curtok = gettok();
  6863.     if (curtok != NUMBER) {
  6864.         if (cmdlvl == 0 && !x_ifnum)
  6865.           printf("illegal radix\n");
  6866.         return(0);
  6867.     }
  6868.     curtok = gettok();
  6869.     }
  6870. #endif /* COMMENT */
  6871.     if (curtok != N_EOT) {
  6872.     if (cmdlvl == 0 && !x_ifnum)
  6873.       printf("extra characters after expression\n");
  6874.     xerror = 1;
  6875.     }
  6876.     return(expval);
  6877. }
  6878.  
  6879. char *                    /* Silent front end for evala() */
  6880. evalx(s) char *s; {
  6881.     char * p;
  6882.     int t;
  6883.     t = x_ifnum;
  6884.     x_ifnum = 1;
  6885.     p = evala(s);
  6886.     x_ifnum = t;
  6887.     return(p);
  6888. }
  6889.  
  6890. char *
  6891. evala(s) char *s; {
  6892.     char *p;                /* Return pointer */
  6893.     long v;                /* Numeric value */
  6894.  
  6895.     if (!s) return("");
  6896.     xerror = 0;                /* Start out with no error */
  6897.     cp = s;                /* Make the argument global */
  6898.     v = xparse();            /* Parse the string */
  6899.     p = numbuf;                /* Convert long number to string */
  6900.     sprintf(p,"%ld",v);
  6901.     return(xerror ? "" : p);        /* Return empty string on error */
  6902. }
  6903.  
  6904. /*
  6905.  * simplest ::= NUMBER | ( expr )
  6906.  *
  6907.  */
  6908. static VOID
  6909. simplest() {
  6910.     if (curtok == NUMBER)
  6911.       expval = tokval;
  6912.     else if (curtok == '(') {
  6913.     curtok = gettok();        /* skip over paren */
  6914.     expr();
  6915.     if (curtok != ')') {
  6916.         if (cmdlvl == 0 && !x_ifnum)
  6917.           printf("missing right parenthesis\n");
  6918.         xerror = 1;
  6919.     }
  6920.     } else {
  6921.     if (cmdlvl == 0 && !x_ifnum)
  6922.       printf("operator unexpected\n");
  6923.     xerror = 1;
  6924.     }
  6925.     curtok = gettok();
  6926. }
  6927.  
  6928. /*
  6929.  * simpler ::= simplest | simplest !
  6930.  *
  6931.  */
  6932. static VOID
  6933. simpler() {
  6934.     simplest();
  6935.     if (curtok == '!') {
  6936.     curtok = gettok();
  6937.     expval = fact(expval);
  6938.     }
  6939. }
  6940.  
  6941. /*
  6942.  * simple ::= {-,~,!} simpler | simpler
  6943.  *
  6944.  */
  6945.  
  6946. static VOID
  6947. simple() {
  6948.     if (curtok == '-' || curtok == '~' || curtok == '!' || curtok == '+') {
  6949.     int op = curtok;
  6950.     curtok = gettok();        /* skip over - sign */
  6951.     simpler();            /* parse the factor again */
  6952.     if (op != '+')
  6953.       expval = (op == '-') ? -expval : ((op == '!') ? !expval : ~expval);
  6954.     } else simpler();
  6955. }
  6956.  
  6957. /*  D C L A R R A Y  --  Declare an array  */
  6958. /*
  6959.   Call with:
  6960.    char a = single character designator for the array, e.g. "a".
  6961.    int  n = size of array.
  6962.   Returns:
  6963.    0 or greater on success, having created the requested array with
  6964.      with n+1 elements, 0..n.  If an array of the same name existed
  6965.      previously, it is destroyed.  The new array has all its elements
  6966.      initialized to NULL pointers.
  6967.   -1 on failure (because 'a' out of range or malloc failure).
  6968. */
  6969. int
  6970. #ifdef CK_ANSIC
  6971. dclarray(char a, int n)
  6972. #else
  6973. dclarray(a,n) char a; int n;
  6974. #endif /* CK_ANSIC */
  6975. /* dclarray */ {
  6976.     char **p; int i, n2, rc;
  6977.  
  6978.     if (a > 63 && a < 91) a += 32;    /* Convert letters to lowercase */
  6979.     if (a < ARRAYBASE || a > 122)    /* Verify name */
  6980.       return(-1);
  6981.     a -= ARRAYBASE;            /* Convert name to number */
  6982.     rc = a;
  6983.     if ((p = a_ptr[a]) != NULL) {    /* Delete old array of same name */
  6984.     n2 = a_dim[a];
  6985.     for (i = 0; i <= n2; i++) {    /* First delete its elements */
  6986.         if (p[i]) {
  6987.         free(p[i]);
  6988.         p[i] = NULL;
  6989.         }
  6990.     }
  6991.     free(a_ptr[a]);            /* Then the element list */
  6992.     a_ptr[a] = (char **) NULL;    /* Remove pointer to element list */
  6993.     a_dim[a] = 0;            /* Set dimension at zero. */
  6994.     }
  6995.     if (n == 0) return(0);        /* If dimension 0, just deallocate. */
  6996.  
  6997.     p = (char **) malloc((n+1) * sizeof(char **)); /* Allocate for new array */
  6998.     if (p == NULL) return(-1);        /* Check */
  6999.     a_ptr[a] = p;            /* Save pointer to member list */
  7000.     a_dim[a] = n;            /* Save dimension */
  7001.     for (i = 0; i <= n; i++)        /* Initialize members to null */
  7002.       p[i] = NULL;
  7003.     return(rc);
  7004. }
  7005.  
  7006. /*  X A R R A Y  -- Convert array name to array index  */
  7007.  
  7008. int
  7009. xarray(s) char * s; {
  7010.     char buf[8];
  7011.     int x;
  7012.     char c;
  7013.  
  7014.     if (!s) s = "";
  7015.     if (!*s)
  7016.       return(-1);
  7017.  
  7018.     buf[0] = NUL;
  7019.     buf[1] = NUL;
  7020.     buf[2] = s[0];
  7021.     buf[3] = s[1];
  7022.     buf[4] = s[2];
  7023.     buf[5] = s[3];
  7024.     buf[6] = NUL;
  7025.     s = buf+2;
  7026.     if (*s == '&') {
  7027.     buf[1] = CMDQ;
  7028.     s--;
  7029.     } else if (*s != CMDQ) {
  7030.     if (isupper(*s))
  7031.       *s = tolower(*s);
  7032.     buf[0] = CMDQ;
  7033.     buf[1] = '&';
  7034.     s = buf;
  7035.     }
  7036.     c = *(s+2);
  7037.     if (c == '@')
  7038.       c = 96;
  7039.     x = (int)c - ARRAYBASE;
  7040.     if (*(s+3) == '[')
  7041.       *(s+3) = NUL;
  7042.     return((x < 0 || x > 'z' - ARRAYBASE || *(s+3)) ? -1 : x);
  7043. }
  7044.  
  7045. /*  A R R A Y B O U N D S  --  Parse array segment notation \&a[n:m]  */
  7046.  
  7047. /*
  7048.   Call with s = array reference, plus two pointers to ints.
  7049.   Returns -1 on error, or array index, with the two ints set as follows:
  7050.    \&a[]     -1, -1
  7051.    \&a[3]     3, -1
  7052.    \&a[3:17]  3, 17
  7053.   The array need not be declared -- this routine is just for parsing.
  7054. */
  7055. int
  7056. arraybounds(s,lo,hi) char * s; int * lo, * hi; {
  7057.     int i, x, y, range[2];
  7058.     char buf[256], * p, * q;
  7059.     char * tmp = NULL;
  7060.  
  7061.     if (!s) s = "";            /* Defense de null args */
  7062.     if (!*s)
  7063.       return(-1);
  7064.  
  7065.     x = xarray(s);            /* Check basic structure */
  7066.     if (x < 0)                /* Not OK, fail. */
  7067.       return(-1);
  7068.     range[0] = -1;            /* It's OK -- get contents */
  7069.     range[1] = -1;            /* of subscript brackets */
  7070.     p = s;
  7071.     for (p = s, q = NULL; *p; p++) {    /* First find the brackets */
  7072.     if (*p == '[') {
  7073.         q = p+1;
  7074.     } else if (*p == ']')
  7075.       break;
  7076.     }
  7077.     makestr(&tmp,s);            /* Make a pokeable copy */
  7078.     s = tmp;
  7079.     if (q && *p == ']') {        /* If we have brackets... */
  7080.     int quitnow = 0;
  7081.     for (i = 0; i < 2 && !quitnow; i++) { /* Loop thru their contents */
  7082.         for (p = q; *p; p++) {
  7083.         if (i == 0 && *p == ':' ||
  7084.             *p == ']') {
  7085.             if (*p == ']')
  7086.               quitnow = 1;
  7087.             *p = NUL;
  7088.             if (*q) {        /* We have something */
  7089.             y = 255;    /* Expand variables, etc. */
  7090.             s = buf;
  7091.             zzstring(q,&s,&y);
  7092.             s = evalx(buf);    /* Evaluate it arithmetically */
  7093.             if (s) if (*s)
  7094.               ckstrncpy(buf,s,256);
  7095.             if (!chknum(buf)) { /* Did we get a number? */
  7096.                 makestr(&tmp,NULL);    /* No, fail. */
  7097.                 return(-1);
  7098.             }
  7099.             q = (i == 0) ? p+1 : NULL; /* Point to next if any */
  7100.             range[i] = atoi(buf); /* Set this one */
  7101.             }
  7102.             break;
  7103.         }
  7104.         }
  7105.     }
  7106.     }
  7107.     makestr(&tmp,NULL);            /* Free temporary poked string */
  7108.     *lo = range[0];            /* Return what we got */
  7109.     *hi = range[1];
  7110.     return(x);
  7111. }
  7112.  
  7113. /*  A R R A Y N A M  --  Parse an array name  */
  7114.  
  7115. /*
  7116.   Call with pointer to string that starts with the array reference.
  7117.   String may begin with either \& or just &.
  7118.   On success,
  7119.     Returns letter ID (always lowercase) in argument c,
  7120.       which can also be accent grave (` = 96; '@' is converted to grave);
  7121.     Dimension or subscript in argument n;
  7122.     IMPORTANT: These arguments must be provided by the caller as addresses
  7123.     of ints (not chars), for example:
  7124.       char *s; int x, y;
  7125.       arraynam(s,&x,&y);
  7126.   On failure, returns a negative number, with args n and c set to zero.
  7127. */
  7128. int
  7129. arraynam(ss,c,n) char *ss; int *c; int *n; {
  7130.     int i, y, pp;
  7131.     char x;
  7132.     char *s, *p, *sx, *vnp;
  7133.     /* On stack to allow for recursive calls... */
  7134.     char vnbuf[ARRAYREFLEN+1];        /* Entire array reference */
  7135.     char ssbuf[ARRAYREFLEN+1];        /* Subscript in "plain text" */
  7136.     char sxbuf[16];            /* Evaluated subscript */
  7137.  
  7138.     *c = *n = 0;            /* Initialize return values */
  7139.     for (i = 0; i < (int)strlen(ss); i++) /* Check length */
  7140.       if (ss[i] == ']')
  7141.     break;
  7142.     if (i > ARRAYREFLEN) {
  7143.     printf("?Array reference too long - %s\n",ss);
  7144.     return(-9);
  7145.     }
  7146.     ckstrncpy(vnbuf,ss,ARRAYREFLEN);
  7147.     vnp = vnbuf;
  7148.     if (vnbuf[0] == CMDQ && vnbuf[1] == '&') vnp++;
  7149.     if (*vnp != '&') {
  7150.     printf("?Not an array - %s\n",vnbuf);
  7151.     return(-9);
  7152.     }
  7153.     x = *(vnp + 1);            /* Fold case of array name */
  7154.  
  7155.     /* We don't use isupper & tolower here on purpose because these */
  7156.     /* would produce undesired effects with accented letters. */
  7157.     if (x > 63 && x < 91) x  = *(vnp + 1) = (char) (x + 32);
  7158.     if ((x < ARRAYBASE) || (x > 122) || (*(vnp+2) != '[')) {
  7159.     if (msgflg) {
  7160.         printf("?Invalid format for array name - %s\n",vnbuf);
  7161.         return(-9);
  7162.     } else
  7163.       return(-2);
  7164.     }
  7165.     *c = x;                /* Return the array name */
  7166.     s = vnp+3;                /* Get dimension */
  7167.  
  7168.     p = ssbuf;
  7169.     pp = 1;                /* Bracket counter */
  7170.     for (i = 0; i < ARRAYREFLEN && *s != NUL; i++) { /* Copy up to ] */
  7171.     if (*s == '[') pp++;
  7172.     if (*s == ']' && --pp == 0) break;
  7173.     *p++ = *s++;
  7174.     }
  7175.     if (*s != ']') {
  7176.     printf("?No closing bracket on array dimension - %s\n",vnbuf);
  7177.     return(-9);
  7178.     }
  7179.     p--;                /* Trim whitespace from end */
  7180.     while (*p == SP || *p == HT)
  7181.       p--;
  7182.     p++;
  7183.     *p = NUL;                /* Terminate subscript with null */
  7184.     p = ssbuf;                /* Point to beginning of subscript */
  7185.     while (*p == SP || *p == HT)    /* Trim whitespace from beginning */
  7186.       p++;
  7187.     sx = sxbuf;                /* Where to put expanded subscript */
  7188.     y = 16;
  7189.     zzstring(p,&sx,&y);            /* Convert variables, etc. */
  7190.     sx = sxbuf;
  7191.     while (*sx == SP) sx++;
  7192.     debug(F110,"arraynam sx","",sx);
  7193.     if (!*sx) {                /* Empty brackets... */
  7194.     *n = -17;            /* Secret code :-) */
  7195.     return(-2);
  7196.     }
  7197.     p = evala(sx);            /* Run it thru \fneval()... */
  7198.     if (p) if (*p) strcpy(sxbuf,p);    /* We know it has to be a number. */
  7199.  
  7200.     if (!chknum(sxbuf)) {        /* Make sure it's all digits */
  7201.     if (msgflg) {
  7202.         printf("?Array dimension or subscript missing or not numeric\n");
  7203.         return(-9);
  7204.     } else
  7205.       return(-2);
  7206.     }
  7207.     if ((y = atoi(sxbuf)) < 0) {
  7208.         if (cmflgs == 0) printf("\n");
  7209.     if (msgflg) {
  7210.         printf("?Array dimension or subscript not positive or zero\n");
  7211.         return(-9);
  7212.     } else
  7213.       return(-2);
  7214.     }
  7215.     *n = y;                /* Return the subscript or dimension */
  7216.     return(0);
  7217. }
  7218.  
  7219. int
  7220. chkarray(a,i) int a, i; {        /* Check if array is declared */
  7221.     int x;                /* and if subscript is in range */
  7222.     if (a == 64) a = 96;        /* Convert atsign to grave accent */
  7223.     x = a - ARRAYBASE;            /* Values must be in range 95-122 */
  7224. #ifdef COMMENT
  7225.     if (x == 0 && maclvl < 0)        /* Macro arg vector but no macro */
  7226.       return(0);
  7227. #endif /* COMMENT */
  7228.     if (x < 0 || x > 'z' - ARRAYBASE)    /* Not in range */
  7229.       return(-2);
  7230.     if (a_ptr[x] == NULL) return(-1);    /* Not declared */
  7231.     if (i > a_dim[x]) return(-2);    /* Declared but out of range. */
  7232.     return(a_dim[x]);            /* All ok, return dimension */
  7233. }
  7234.  
  7235. #ifdef COMMENT                /* This isn't used. */
  7236. char *
  7237. arrayval(a,i) int a, i; {        /* Return value of \&a[i] */
  7238.     int x; char **p;            /* (possibly NULL) */
  7239.     if (a == 64) a = 96;        /* Convert atsign to grave accent */
  7240.     x = a - ARRAYBASE;            /* Values must be in range 95-122 */
  7241.     if (x < 0 || x > 27) return(NULL);    /* Not in range */
  7242.     if ((x > 0) && (p = a_ptr[x]) == NULL) /* Array not declared */
  7243.       return(NULL);
  7244.     if (i > a_dim[x])            /* Subscript out of range. */
  7245.       return(NULL);
  7246.     return(p[i]);            /* All ok, return pointer to value. */
  7247. }
  7248. #endif /* COMMENT */
  7249.  
  7250. /*
  7251.   pusharray() is called when an array name is included in a LOCAL statement.
  7252.   It moves the pointers from the global definition to the stack, and removes
  7253.   the global definition.  Later, if the same array is declared in the local
  7254.   context, it occupies the global definition in the normal way.  But when
  7255.   popclvl() is called, it replaces the global definition with the one saved
  7256.   here.  The "secret code" is used to indicate to popclv() that it should
  7257.   remove the global array when popping through this level -- otherwise if a
  7258.   local array were declared that had no counterpart at any higher level, it
  7259.   would never be deleted.  This allows Algol-like inheritance to work both
  7260.   on the way down and on the way back up.
  7261. */
  7262. int
  7263. pusharray(x,z) int x, z; {
  7264.     int y;
  7265.     debug(F000,"pusharray x","",x);
  7266.     debug(F101,"pusharray z","",z);
  7267.     y = chkarray(x,z);
  7268.     debug(F101,"pusharray y","",y);
  7269.     x -= ARRAYBASE;            /* Convert name letter to index. */
  7270.     if (x < 0 || x > 27)
  7271.       return(-1);
  7272.     if (y < 0) {
  7273.     aa_ptr[cmdlvl][x] = (char **) NULL;
  7274.     aa_dim[cmdlvl][x] = -23;    /* Secret code (see popclvl()) */
  7275.     } else {
  7276.     aa_ptr[cmdlvl][x] = a_ptr[x];
  7277.     aa_dim[cmdlvl][x] = y;
  7278.     }
  7279.     a_ptr[x] = (char **) NULL;
  7280.     a_dim[x] = 0;
  7281.     return(0);
  7282. }
  7283.  
  7284. /*  P A R S E V A R  --  Parse a variable name or array reference.  */
  7285. /*
  7286.  Call with:
  7287.    s  = pointer to candidate variable name or array reference.
  7288.    *c = address of integer in which to return variable ID.
  7289.    *i = address of integer in which to return array subscript.
  7290.  Returns:
  7291.    -2:  syntax error in variable name or array reference.
  7292.     1:  successful parse of a simple variable, with ID in c.
  7293.     2:  successful parse of an array reference, w/ID in c and subscript in i.
  7294. */
  7295. int
  7296. parsevar(s,c,i) char *s; int *c, *i; {
  7297.     char *p;
  7298.     int x,y,z;
  7299.  
  7300.     p = s;
  7301.     if (*s == CMDQ) s++;        /* Point after backslash */
  7302.  
  7303.     if (*s != '%' && *s != '&') {    /* Make sure it's % or & */
  7304.     printf("?Not a variable name - %s\n",p);
  7305.     return(-9);
  7306.     }
  7307.     if ((int)strlen(s) < 2) {
  7308.     printf("?Incomplete variable name - %s\n",p);
  7309.     return(-9);
  7310.     }
  7311.     if (*s == '%' && *(s+2) != '\0') {
  7312.     printf("?Only one character after '%%' in variable name, please\n");
  7313.     return(-9);
  7314.     }
  7315.     if (*s == '&' && *(s+2) != '[') {
  7316.     printf("?Array subscript expected - %s\n",p);
  7317.     return(-9);
  7318.     }
  7319.     if (*s == '%') {            /* Simple variable. */
  7320.     y = *(s+1);            /* Get variable ID letter/char */
  7321.     if (isupper(y)) y -= ('a'-'A');    /* Convert upper to lower case */
  7322.     *c = y;                /* Set the return values. */
  7323.     *i = -1;            /* No array subscript. */
  7324.     return(1);            /* Return 1 = simple variable */
  7325.     }
  7326.     if (*s == '&') {            /* Array reference. */
  7327.     y = arraynam(s,&x,&z);        /* Go parse it. */
  7328.     debug(F101,"parsevar arraynam","",y);
  7329.     if ((y) < 0) {
  7330.         if (y == -2)
  7331.           return(pusharray(x,z));
  7332.         if (y != -9)
  7333.           printf("?Invalid array reference - %s\n",p);
  7334.         return(-9);
  7335.     }
  7336.     if (chkarray(x,z) < 0) {    /* Check if declared, etc. */
  7337.         printf("?Array not declared or subscript out of range\n");
  7338.         return(-9);
  7339.     }
  7340.     *c = x;                /* Return array letter */
  7341.     *i = z;                /* and subscript. */
  7342.     return(2);
  7343.     }
  7344.     return(-2);                /* None of the above. */
  7345. }
  7346.  
  7347. #define VALN 20
  7348.  
  7349. /* Get the numeric value of a variable */
  7350. /*
  7351.   Call with pointer to variable name, pointer to int for return value.
  7352.   Returns:
  7353.     0 on success with second arg containing the value.
  7354.    -1 on failure (bad variable syntax, variable not defined or not numeric).
  7355. */
  7356. int
  7357. varval(s,v) char *s; int *v; {
  7358.     char valbuf[VALN+1];        /* s is pointer to variable name */
  7359.     char name[256];
  7360.     char *p;
  7361.     int y;
  7362.  
  7363.     if (*s != CMDQ) {            /* Handle macro names too */
  7364.     sprintf(name,"\\m(%s)", s);
  7365.     s = name;
  7366.     }
  7367.     p = valbuf;                /* Expand variable into valbuf. */
  7368.     y = VALN;
  7369.     if (zzstring(s,&p,&y) < 0) return(-1);
  7370.     p = valbuf;                /* Make sure value is numeric  */
  7371.     if (!*p) {                /* Be nice -- let an undefined */
  7372.     valbuf[0] = '0';        /* variable be treated as 0.   */
  7373.     valbuf[1] = NUL;
  7374.     }
  7375.     if (chknum(p)) {            /* Convert numeric string to int */
  7376.     *v = atoi(p);            /* OK */
  7377.     } else {                /* Not OK */
  7378.     p = evala(p);            /* Maybe it's an expression */
  7379.     if (!chknum(p))            /* Did it evaluate? */
  7380.       return(-1);            /* No, failure. */
  7381.     else                /* Yes, */
  7382.       *v = atoi(p);            /* success */
  7383.     }
  7384.     return(0);
  7385. }
  7386.  
  7387. /* Increment or decrement a variable */
  7388. /* Returns -1 on failure, 0 on success */
  7389.  
  7390. int
  7391. incvar(s,x,z) char *s; int x; int z; {    /* Increment a numeric variable */
  7392.     int n;                /* s is pointer to variable name */
  7393.                     /* x is amount to increment by */
  7394.                     /* z != 0 means add */
  7395.                     /* z = 0 means subtract */
  7396.     if (varval(s,&n) < 0)        /* Convert numeric string to int */
  7397.       return(-1);
  7398.     if (z)                /* Increment it by the given amount */
  7399.       n += x;
  7400.     else                /* or decrement as requested. */
  7401.       n -= x;
  7402.     addmac(s,ckitoa(n));        /* Replace old variable */
  7403.     return(0);
  7404. }
  7405.  
  7406. /* D O D O  --  Do a macro */
  7407.  
  7408. /*
  7409.   Call with x = macro table index, s = pointer to arguments.
  7410.   Returns 0 on failure, 1 on success.
  7411. */
  7412.  
  7413. int
  7414. dodo(x,s,flags) int x; char *s; int flags; {
  7415.     int y;
  7416.     extern int tra_asg, tra_cmd; int tra_tmp;
  7417. #ifdef OS2
  7418.     extern int term_io;
  7419.     int term_io_sav = term_io;
  7420. #endif /* OS2 */
  7421.  
  7422.     tra_tmp = tra_asg;
  7423.     debug(F101,"dodo maclvl","",maclvl);
  7424.     debug(F101,"dodo flags","",flags);
  7425.     if (++maclvl >= MACLEVEL) {        /* Make sure we have storage */
  7426.         debug(F101,"dodo maclvl too deep","",maclvl);
  7427.     --maclvl;
  7428.     printf("Macros nested too deeply\n");
  7429.     return(0);
  7430.     }
  7431.     macp[maclvl] = mactab[x].mval;    /* Point to the macro body */
  7432.     macx[maclvl] = mactab[x].mval;    /* Remember where the beginning is */
  7433.     makestr(&(m_line[maclvl]),s);    /* Entire arg string for "\%*" */
  7434.     debug(F111,"do macro",macp[maclvl],maclvl);
  7435.  
  7436.     cmdlvl++;                /* Entering a new command level */
  7437.     if (cmdlvl >= CMDSTKL) {        /* Too many macros + TAKE files? */
  7438.         debug(F101,"dodo cmdlvl too deep","",cmdlvl);
  7439.     cmdlvl--;
  7440.     printf("?TAKE files and DO commands nested too deeply\n");
  7441.     return(0);
  7442.     }
  7443. #ifdef VMS
  7444.     conres();                /* So Ctrl-C, etc, will work. */
  7445. #endif /* VMS */
  7446. #ifdef OS2
  7447.     term_io = 0;            /* Disable terminal emulator I/O */
  7448. #endif /* OS2 */
  7449.     ifcmd[cmdlvl] = 0;
  7450.     iftest[cmdlvl] = 0;
  7451.     count[cmdlvl] = count[cmdlvl-1];    /* Inherit COUNT from previous level */
  7452.     intime[cmdlvl] = intime[cmdlvl-1];    /* Inherit previous INPUT TIMEOUT */
  7453.     inpcas[cmdlvl] = inpcas[cmdlvl-1];    /*   and INPUT CASE */
  7454.     takerr[cmdlvl] = takerr[cmdlvl-1];    /*   and TAKE ERROR */
  7455.     merror[cmdlvl] = merror[cmdlvl-1];    /*   and MACRO ERROR */
  7456.     xquiet[cmdlvl] = quiet;
  7457.     cmdstk[cmdlvl].src = CMD_MD;    /* Say we're in a macro */
  7458.     cmdstk[cmdlvl].lvl = maclvl;    /* and remember the macro level */
  7459.     cmdstk[cmdlvl].ccflgs = flags & ~CF_IMAC; /* Set flags */
  7460.  
  7461.     /* Initialize return value except in FOR, WHILE, IF, and SWITCH macros */
  7462.  
  7463.     debug(F111,"dodo mrval",mrval[maclvl],maclvl);
  7464.     if (!(flags & CF_IMAC) && mrval[maclvl]) {
  7465.     debug(F111,"dodo clearing mrval",mrval[maclvl],maclvl);
  7466.     makestr(&(mrval[maclvl]),NULL);
  7467.     }
  7468.     debug(F110,"do macro",mactab[x].kwd,0);
  7469.  
  7470. /* Clear old %0..%9 arguments */
  7471.  
  7472.     addmac("%0",mactab[x].kwd);        /* Define %0 = name of macro */
  7473.     makestr(&(m_xarg[maclvl][0]),mactab[x].kwd);
  7474.     varnam[0] = '%';
  7475.     varnam[2] = '\0';
  7476.     tra_asg = 0;
  7477.     for (y = 1; y < 10; y++) {        /* Clear args %1..%9 */
  7478.     varnam[1] = (char) (y + '0');
  7479.     delmac(varnam);
  7480.     }
  7481.     tra_asg = tra_tmp;
  7482.  
  7483. /* Assign the new args one word per arg, allowing braces to group words */
  7484.  
  7485.     xwords(s,MAXARGLIST,NULL,0);
  7486. #ifdef OS2
  7487.     term_io = term_io_sav;
  7488. #endif /* OS2 */
  7489.     if (tra_cmd)
  7490.       printf("[%d] +M: \"%s\"\n",cmdlvl,mactab[x].kwd);
  7491.     return(1);
  7492. }
  7493.  
  7494. /* Insert "literal" quote around each comma-separated command to prevent */
  7495. /* its premature expansion.  Only do this if object command is surrounded */
  7496. /* by braces. */
  7497.  
  7498. static char* flit = "\\flit(";
  7499.  
  7500. int
  7501. litcmd(src,dest,n) char **src, **dest; int n; {
  7502.     int bc = 0, pp = 0;
  7503.     char c, *s, *lp, *ss;
  7504.  
  7505.     s = *src;
  7506.     lp = *dest;
  7507.  
  7508.     debug(F110,"litcmd",s,0);
  7509.  
  7510.     while (*s == SP) s++;        /* Strip extra leading spaces */
  7511.  
  7512.     if (*s == '{') {            /* Starts with brace */
  7513.         pp = 0;                /* Paren counter */
  7514.     bc = 1;                /* Count leading brace */
  7515.     *lp++ = *s++;            /* Copy it */
  7516.     if (--n < 1) return(-1);    /* Check space */
  7517.     while (*s == SP) s++;        /* Strip interior leading spaces */
  7518.     ss = flit;            /* Point to "\flit(" */
  7519.     while (*lp++ = *ss++)        /* Copy it */
  7520.       if (--n < 1)            /* and check space */
  7521.         return(-1);
  7522.     lp--;                /* Back up over null */
  7523.  
  7524.     while (*s) {            /* Go thru rest of text */
  7525.         c = *s;
  7526.         if (c == '{') bc++;        /* Count brackets */
  7527.         if (c == '(') pp++;        /* and parens */
  7528.         if (c == ')') {        /* Right parenthesis. */
  7529.         pp--;            /* Count it. */
  7530.         if (pp < 0) {        /* An unbalanced right paren... */
  7531.             if (n < 5)        /* Out of space in dest buffer? */
  7532.               return(-1);    /* If so, give up. */
  7533.             *lp++ = CMDQ;    /* Must be quoted to prevent */
  7534.             *lp++ = '{';    /* premature termination of */
  7535.             *lp++ = '4';    /* \flit(...) */
  7536.             *lp++ = '1';
  7537.             *lp++ = '}';
  7538.             n -= 5;
  7539.             pp++;        /* Uncount it. */
  7540.             s++;
  7541.             continue;
  7542.         }
  7543.         }
  7544.         if (c == '}') {        /* Closing brace. */
  7545.         if (--bc == 0) {    /* Final one? */
  7546.             *lp++ = ')';    /* Add closing paren for "\flit()" */
  7547.             *lp++ = c;
  7548.             s++;
  7549.             break;
  7550.         }
  7551.         }
  7552.             *lp++ = c;            /* General case */
  7553.         if (--n < 1) return(-1);
  7554.         s++;
  7555.         }
  7556.     *lp = NUL;
  7557.     } else {                /* No brackets around, */
  7558.     while (*lp++ = *s++)        /* just copy. */
  7559.       if (--n < 1)
  7560.         return(-1);
  7561.     lp--;
  7562.     }
  7563.     *src = s;                /* Return updated source */
  7564.     *dest = lp;                /* and destination pointers */
  7565.     if (bc)                /* Fail if braces unbalanced */
  7566.       return(-1);
  7567.     else                /* Otherwise succeed. */
  7568.       return(0);
  7569. }
  7570. #endif /* NOSPL */
  7571.  
  7572. /* Functions moved here from ckuusr.c to even out the module sizes... */
  7573.  
  7574. /*
  7575.   Breaks up string s -- IN PLACE! -- into a list of up to max words.
  7576.   Pointers to each word go into the array list[].
  7577.   max is the maximum number of words (pointers).
  7578.   If list is NULL, then they are added to the macro table.
  7579.   flag = 0 means the last field is to be one word, like all the other fields,
  7580.          so anything after it is discarded.
  7581.   flag = 1 means the last field extends to the end of the string, even if
  7582.          there are lots of words left, so the last field contains the
  7583.          remainder of the string.
  7584. */
  7585. VOID
  7586. xwords(s,max,list,flag) char *s; int max; char *list[]; int flag; {
  7587.     char *p;
  7588.     int b, i, k, y, z;
  7589. #ifndef NOSPL
  7590.     int macro;
  7591.     macro = (list == NULL);
  7592.     debug(F111,"xwords",s,macro);
  7593. #endif /* NOSPL */
  7594.  
  7595. #ifdef XWORDSDEBUG
  7596.     printf("XWORDS string=%s\n",s);
  7597.     printf("XWORDS max=%d\n",max);
  7598. #endif /* XWORDSDEBUG */
  7599.     p = s;                /* Pointer to beginning of string */
  7600.     b = 0;                /* Flag for outer brace removal */
  7601.     k = 0;                /* Flag for in-word */
  7602.     y = 0;                /* Brace nesting level */
  7603.     z = 0;                /* "Word" counter, 0 thru max */
  7604.  
  7605.     if (list)
  7606.       for (i = 0; i <= max; i++)    /* Initialize pointers */
  7607.     list[i] = NULL;
  7608.  
  7609.     if (flag) max--;
  7610.  
  7611.     while (1) {                /* Go thru word list */
  7612.     if (!s || (*s == '\0')) {    /* No more characters? */
  7613.         if (k != 0) {        /* Was I in a word? */
  7614.         if (z == max) break;    /* Yes, only go up to max. */
  7615.         z++;            /* Count this word. */
  7616. #ifdef XWORDSDEBUG
  7617.         printf("1 z++ = %d\n", z);
  7618. #endif /* XWORDSDEBUG */
  7619. #ifndef NOSPL
  7620.         if (macro) {        /* Doing macro args */
  7621.             if (z < 10) {
  7622.             varnam[1] = (char) (z + '0'); /* Assign last arg */
  7623.             addmac(varnam,p);
  7624.             }
  7625.             if (z <= max) {
  7626.             if (maclvl < 0)
  7627.               addmac(varnam,p);
  7628.             else
  7629.               makestr(&(m_xarg[maclvl][z]),p);
  7630.             }
  7631.         } else {        /* Not doing macro args */
  7632. #endif /* NOSPL */
  7633.             list[z] = p;    /* Assign pointer. */
  7634. #ifdef XWORDSDEBUG
  7635.             printf("[1]LIST[%d]=\"%s\"\n",z,list[z]);
  7636. #endif /* XWORDSDEBUG */
  7637. #ifndef NOSPL
  7638.         }
  7639. #endif /* NOSPL */
  7640.         break;            /* And get out. */
  7641.         } else break;        /* Was not in a word */
  7642.     }
  7643.     if (k == 0 && (*s == SP || *s == HT)) { /* Eat leading blanks */
  7644.         s++;
  7645.         continue;
  7646.     } else if (*s == '{') {        /* An opening brace */
  7647.         if (k == 0 && y == 0) {    /* If leading brace */
  7648.         p = s+1;        /* point past it */
  7649.         b = 1;            /* and flag that we did this */
  7650.         }
  7651.         k = 1;            /* Flag that we're in a word */
  7652.         y++;            /* Count the brace. */
  7653.     } else if (*s == '}') {        /* A closing brace. */
  7654.         y--;            /* Count it. */
  7655.         if (y == 0 && b != 0) {    /* If it matches the leading brace */
  7656.         *s = SP;        /* change it to a space */
  7657.         b = 0;            /* and we're not in braces any more */
  7658.         } else if (y < 0) k = 1;    /* otherwise just start a new word. */
  7659.     } else if (*s != SP && *s != HT) { /* Nonspace means we're in a word */
  7660.         if (k == 0) {        /* If we weren't in a word before, */
  7661.         p = s;            /* Mark the beginning */
  7662.         if (flag && z == max) {    /* Want last word to be remainder? */
  7663.             z++;
  7664. #ifdef XWORDSDEBUG
  7665.             printf("1 z++ = %d\n", z);
  7666. #endif /* XWORDSDEBUG */
  7667.             list[z] = p;    /* Yes, point to it */
  7668. #ifdef XWORDSDEBUG
  7669.             printf("[4]LIST[%d]=\"%s\"\n",z,list[z]);
  7670. #endif /* XWORDSDEBUG */
  7671.             break;        /* and quit */
  7672.         }
  7673.         k = 1;            /* Set in-word flag */
  7674.         }
  7675.     }
  7676.     /* If we're not inside a braced quantity, and we are in a word, and */
  7677.     /* we have hit whitespace, then we have a word. */
  7678.     if ((y < 1) && (k != 0) && (*s == SP || *s == HT)) {
  7679.         if (!flag || z < max)    /* if we don't want to keep rest */
  7680.           *s = '\0';        /* terminate the arg with null */
  7681.         k = 0;            /* say we're not in a word any more */
  7682.         y = 0;            /* start braces off clean again */
  7683.         if (z == max) break;    /* Only go up to max. */
  7684.         z++;            /* count this arg */
  7685. #ifdef XWORDSDEBUG
  7686.         printf("1 z++ = %d\n", z);
  7687. #endif /* XWORDSDEBUG */
  7688.  
  7689. #ifndef NOSPL
  7690.         if (macro) {
  7691.         if (z < 10) {
  7692.             varnam[1] = (char) (z + '0'); /* compute its name */
  7693.             addmac(varnam,p);    /* add it to the macro table */
  7694.         }
  7695.         if (z <= max) {
  7696.             if (maclvl < 0)
  7697.               addmac(varnam,p);
  7698.             else
  7699.               makestr(&(m_xarg[maclvl][z]),p);
  7700.         }
  7701.         } else {
  7702. #endif /* NOSPL */
  7703.         list[z] = p;
  7704. #ifdef XWORDSDEBUG
  7705.         printf("[2]LIST[%d]=\"%s\"\n",z,list[z]);
  7706. #endif /* XWORDSDEBUG */
  7707. #ifndef NOSPL
  7708.         }
  7709. #endif /* NOSPL */
  7710.         p = s+1;
  7711.     }
  7712.     s++;                /* Point past this character */
  7713.     }
  7714.     if ((z == 0) && (y > 1)) {        /* Extra closing brace(s) at end */
  7715.     z++;
  7716. #ifndef NOSPL
  7717.     if (macro) {
  7718.         if (z < 10) {
  7719.         varnam[1] = z + '0';    /* compute its name */
  7720.         addmac(varnam,p);    /* Add rest of line to last arg */
  7721.         }
  7722.         if (z <= max) {
  7723.         if (maclvl < 0)
  7724.           addmac(varnam,p);
  7725.         else
  7726.           makestr(&(m_xarg[maclvl][z]),p);
  7727.         }
  7728.     } else {
  7729. #endif /* NOSPL */
  7730.         list[z] = p;
  7731. #ifdef XWORDSDEBUG
  7732.         printf("[3]LIST[%d]=\"%s\"\n",z,list[z]);
  7733. #endif /* XWORDSDEBUG */
  7734. #ifndef NOSPL
  7735.     }
  7736. #endif /* NOSPL */
  7737.     }
  7738. #ifndef NOSPL
  7739.     if (macro) {            /* Macro */
  7740.     if (maclvl < 0) {
  7741.         topargc = z + 1;
  7742.     } else {
  7743.         macargc[maclvl] = z + 1;    /* Set \v(argc) variable */
  7744.         n_xarg[maclvl] = z + 1;    /* This is the actual number */
  7745.         a_ptr[0] = m_xarg[maclvl];    /* Point \&_[] at the args */
  7746.         a_dim[0] = z;        /* And give it this dimension */
  7747.     }
  7748.     }
  7749. #endif /* NOSPL */
  7750.     return;
  7751. }
  7752.  
  7753. #ifndef NOSPL
  7754.  
  7755. /*  D O S H I F T  --  Do the SHIFT Command; shift macro args left by n */
  7756.  
  7757. /*  Note: at some point let's consolidate m_arg[][] and m_xarg[][]. */
  7758.  
  7759. int
  7760. doshift(n) int n; {            /* n = shift count */
  7761.     int i, k, top, level;
  7762.     char /* *s, *m, */ buf[6];        /* Buffer to build scalar names */
  7763.  
  7764.     debug(F101,"SHIFT count","",n);
  7765.     debug(F101,"SHIFT topargc","",topargc);
  7766.  
  7767.     if (n < 1)                /* Stay in range */
  7768.       return(n == 0 ? 1 : 0);
  7769.  
  7770.     level = maclvl;
  7771.     top = (level < 0) ? topargc : macargc[level];
  7772.  
  7773.     if (n >= top)
  7774.       n = top - 1;
  7775.  
  7776. #ifdef DEBUG
  7777.     if (deblog) {
  7778.     debug(F101,"SHIFT count 2","",n);
  7779.     debug(F101,"SHIFT level","",level);
  7780.     if (level > -1)
  7781.       debug(F101,"SHIFT macargc[level]","",macargc[level]);
  7782.     }
  7783. #endif /* DEBUG */
  7784.  
  7785.     buf[0] = '\\';            /* Initialize name template */
  7786.     buf[1] = '%';
  7787.     buf[2] = NUL;
  7788.     buf[3] = NUL;
  7789.  
  7790.     for (i = 1; i <= n; i++) {        /* Free shifted-over args */
  7791.     buf[2] = (char)(i+'0');
  7792.     if (level < 0) {
  7793.         makestr(&(toparg[i]),NULL);
  7794.     } else {
  7795.         makestr(&(m_xarg[level][i]),NULL);
  7796.     }
  7797.     if (i < 10)
  7798.       delmac(buf);
  7799.     }
  7800.     for (i = 1; i <= top-n; i++) {    /* Shift remaining args */
  7801.     buf[2] = (char)(i+'0');
  7802.     debug(F111,"SHIFT buf",buf,i);
  7803.     if (level < 0) {
  7804.         toparg[i] = toparg[i+n];    /* Full vector */
  7805.         if (i < 10)            /* Scalars... */
  7806.           makestr(&(g_var[i+'0']),toparg[i+n]);
  7807.     } else {
  7808.         m_xarg[level][i] = m_xarg[level][i+n];
  7809.         if (i < 10)
  7810.           addmac(buf,m_xarg[level][i+n]);
  7811.     }
  7812.     }
  7813.     for (i = top-n; i <= top; i++) {    /* Clear n args from the end */
  7814.     buf[2] = (char)(i+'0');
  7815.     if (level < 0) {
  7816.         toparg[i] = NULL;
  7817.         if (i < 10)
  7818.           makestr(&(g_var[i+'0']),NULL);
  7819.     } else {
  7820.         m_xarg[level][i] = NULL;
  7821.         delmac(buf);
  7822.     }
  7823.     }
  7824.     if (level > -1)            /* Adjust count */
  7825.       macargc[level] -= n;
  7826.     else
  7827.       topargc -= n;
  7828.  
  7829.     return(1);
  7830. }
  7831. #endif /* NOSPL */
  7832.  
  7833. int
  7834. docd(cx) int cx; {            /* Do the CD command */
  7835.     int x;
  7836.     extern int srvcdmsg;
  7837.     extern char * cdmsgfile[], * ckcdpath;
  7838.     char *s, *p;
  7839. #ifdef MAC
  7840.     char temp[34];
  7841. #endif /* MAC */
  7842.  
  7843. #ifndef NOFRILLS
  7844.     if (cx == XXBACK) {
  7845.     if ((x = cmcfm()) < 0)
  7846.     cwdf = 1;
  7847.     if (prevdir) {
  7848.         s = zgtdir();
  7849.         if (!zchdir(prevdir)) {
  7850.         cwdf = 0;
  7851.         perror(s);
  7852.         } else {
  7853.         makestr(&prevdir,s);
  7854.         }
  7855.     }
  7856.     return(cwdf);
  7857.     }
  7858. #endif /* NOFRILLS */
  7859.  
  7860. #ifdef GEMDOS
  7861.     if ((x = cmdir("Name of local directory, or carriage return",
  7862.            homdir,
  7863.            &s,
  7864.            NULL
  7865.            )
  7866.      ) < 0 )
  7867.       return(x);
  7868. #else
  7869. #ifdef OS2
  7870.     if ((x = cmdirp("Name of PC disk and/or directory,\n\
  7871.        or press the Enter key for the default",
  7872.             homdir,
  7873.             &s,
  7874.             ckcdpath ? ckcdpath : getenv("CDPATH"),
  7875.             xxstring
  7876.             )
  7877.      ) < 0 )
  7878.       return(x);
  7879. #else
  7880. #ifdef MAC
  7881.     x = ckstrncpy(temp,homdir,32);
  7882.     if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  7883.     if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  7884.  or press the Return key for the desktop on the boot disk",
  7885.            temp,&s, xxstring)) < 0 )
  7886.       return(x);
  7887. #else
  7888.     if ((x = cmdirp("Carriage return for home directory,\n\
  7889. or name of directory on this computer",
  7890. #ifdef VMS
  7891.             "SYS$LOGIN",    /* With no colon */
  7892. #else
  7893.             homdir,        /* In VMS this is "SYS$LOGIN:" */
  7894. #endif /* VMS */
  7895.             &s,
  7896.             ckcdpath ? ckcdpath : getenv("CDPATH"),
  7897.             xxstring
  7898.             )) < 0)
  7899.       return(x);
  7900. #endif /* MAC */
  7901. #endif /* OS2 */
  7902. #endif /* GEMDOS */
  7903.     strcpy(line,s);            /* Make a safe copy */
  7904.     s = line;
  7905. #ifdef VMS
  7906.     if (ckmatch("*.DIR;1",s,0,0))
  7907.       if (cvtdir(s,tmpbuf) > 0)
  7908.     s = tmpbuf;
  7909. #endif /* VMS */
  7910.     debug(F110,"docd",s,0);
  7911. #ifndef MAC
  7912.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  7913.       return(x);
  7914. #endif /* MAC */
  7915.  
  7916. #ifdef datageneral
  7917.     x = strlen(line);            /* homdir ends in colon, */
  7918.     if (x > 1 && line[x-1] == ':')    /* and "dir" doesn't like that... */
  7919.       line[x-1] = NUL;
  7920. #endif /* datageneral */
  7921.  
  7922. #ifdef MAC
  7923.     cwdf = 1;
  7924.     if (!zchdir(s)) {
  7925.     cwdf = 0;
  7926.     if (*s != ':') {        /* If it failed, */
  7927.         char *p;            /* supply leading colon */
  7928.         p = malloc((int)strlen(s) + 2); /* and try again... */
  7929.         if (p) {
  7930.         strcpy(p,":");
  7931.         strcat(p,s);
  7932.         if (zchdir(p))
  7933.           cwdf = 1;
  7934.         free(p);
  7935.         p = NULL;
  7936.         }
  7937.     }
  7938.     }
  7939.     if (!cwdf)
  7940.       perror(s);
  7941. #else
  7942.     p = zgtdir();
  7943.     if (!zchdir(s)) {
  7944.     cwdf = 0;
  7945.     perror(s);
  7946.     } else cwdf = 1;
  7947. #endif /* MAC */
  7948.  
  7949.     x = 0;
  7950.     if (cwdf) {
  7951.     makestr(&prevdir,p);
  7952.     if (srvcdmsg) {
  7953.         int i;
  7954.         for (i = 0; i < 8; i++) {
  7955.         if (zchki(cdmsgfile[i]) > -1) {
  7956.             x = 1;
  7957.             dotype(cdmsgfile[i],xaskmore,0,0,NULL,0,NULL);
  7958.             break;
  7959.         }
  7960.         }
  7961.     }
  7962.     }
  7963.     if (!x && srvcdmsg && !quiet && !cmdsrc())
  7964.       printf("%s\n", zgtdir());
  7965.  
  7966.     return(cwdf);
  7967. }
  7968.  
  7969. VOID
  7970. fixcmd() {            /* Fix command parser after interruption */
  7971.     dostop();            /* Back to top level (also calls conint()). */
  7972.     bgchk();            /* Check background status */
  7973.     if (*psave) {        /* If old prompt saved, */
  7974.     cmsetp(psave);        /* restore it. */
  7975.     *psave = NUL;
  7976.     }
  7977.     success = 0;        /* Tell parser last command failed */
  7978. }
  7979.  
  7980. #ifndef NOSHOW                /* SHOW FEATURES */
  7981. /*
  7982.   Note, presently optlist[] index overflow is not checked.
  7983.   There is plenty of room (less than 360 entries for 1000 slots).
  7984.   When space starts to get tight, check for noptlist >= NOPTLIST
  7985.   every time noptlist is incremented.
  7986. */
  7987. #define NOPTLIST 1024
  7988. static int noptlist = 0;
  7989. static char * optlist[NOPTLIST+1];
  7990. static int hpos = 0;
  7991.  
  7992. int
  7993. prtopt(lines,s) int * lines; char *s; {    /* Print an option */
  7994.     int y, i;                /* Does word wrap. */
  7995.     if (!s) s = "";
  7996.     i = *lines;
  7997.     if (!*s) {                /* Empty argument */
  7998.     if (hpos > 0) {            /* means to end this line. */
  7999.         printf("\n");        /* Not needed if already at */
  8000.         if (++i > (cmd_rows - 3)) {    /* beginning of new line. */
  8001.         if (!askmore())
  8002.           return(0);
  8003.         else
  8004.           i = 0;
  8005.         }
  8006.     }
  8007.     printf("\n");            /* And then make a blank line */
  8008.     if (++i > (cmd_rows - 3)) {
  8009.         if (!askmore())
  8010.           return(0);
  8011.         else
  8012.           i = 0;
  8013.     }
  8014.     hpos = 0;
  8015.     *lines = i;
  8016.     return(1);
  8017.     }
  8018.     y = (int)strlen(s) + 1;
  8019.     hpos += y;
  8020.     debug(F101,"prtopt hpos","",hpos);
  8021.     debug(F101,"prtopt cmd_cols","",cmd_cols);
  8022.  
  8023.     if (
  8024. #ifdef OS2
  8025.     hpos > ((cmd_cols > 40) ? (cmd_cols - 1) : 79)
  8026. #else /* OS2 */
  8027.     hpos > ((tt_cols > 40) ? (tt_cols - 1) : 79)
  8028. #endif /* OS2 */
  8029.     ) {
  8030.     printf("\n");
  8031.     if (++i > (cmd_rows - 3)) {
  8032.         if (!askmore())
  8033.           return(0);
  8034.         else
  8035.           i = 0;
  8036.     }
  8037.     printf(" %s",s);
  8038.     hpos = y;
  8039.     } else
  8040.       printf(" %s",s);
  8041.     *lines = i;
  8042.     return(1);
  8043. }
  8044.  
  8045. static VOID
  8046. initoptlist() {
  8047.     int i;
  8048.     if (noptlist > 0)
  8049.       return;
  8050.     for (i = 0; i < NOPTLIST; i++)
  8051.       optlist[i] = NULL;
  8052.  
  8053. #ifdef MAC
  8054. #ifdef MPW
  8055.     makestr(&(optlist[noptlist++]),"MPW");
  8056. #endif /* MPW */
  8057. #endif /* MAC */
  8058.  
  8059. #ifdef MAC
  8060. #ifdef THINK_C
  8061.     makestr(&(optlist[noptlist++]),"THINK_C");
  8062. #endif /* THINK_C */
  8063. #endif /* MAC */
  8064.  
  8065. #ifdef __386__
  8066.     makestr(&(optlist[noptlist++]),"__386__");
  8067. #endif /* __386__ */
  8068.  
  8069. #ifdef DEBUG
  8070. #ifdef IFDEBUG
  8071.     makestr(&(optlist[noptlist++]),"IFDEBUG");
  8072. #else
  8073.     makestr(&(optlist[noptlist++]),"DEBUG");
  8074. #endif /* IFDEBUG */
  8075. #endif /* DEBUG */
  8076. #ifdef TLOG
  8077.     makestr(&(optlist[noptlist++]),"TLOG");
  8078. #endif /* TLOG */
  8079. #ifdef BIGBUFOK
  8080.     makestr(&(optlist[noptlist++]),"BIGBUFOK");
  8081. #endif /* BIGBUFOK */
  8082. #ifdef INPBUFSIZ
  8083.     sprintf(line,"INPBUFSIZ=%d",INPBUFSIZ);
  8084.     makestr(&(optlist[noptlist++]),line);
  8085. #endif /* INPBUFSIZE */
  8086. #ifdef INBUFSIZE
  8087.     sprintf(line,"INBUFSIZE=%d",INBUFSIZE);
  8088.     makestr(&(optlist[noptlist++]),line);
  8089. #endif /* INBUFSIZE */
  8090. #ifdef OBUFSIZE
  8091.     sprintf(line,"OBUFSIZE=%d",OBUFSIZE);
  8092.     makestr(&(optlist[noptlist++]),line);
  8093. #endif /* OBUFSIZE */
  8094. #ifdef XFRCAN
  8095.     makestr(&(optlist[noptlist++]),"XFRCAN");
  8096. #endif /* XFRCAN */
  8097. #ifdef PIPESEND
  8098.     makestr(&(optlist[noptlist++]),"PIPESEND");
  8099. #endif /* PIPESEND */
  8100. #ifdef CK_SPEED
  8101.     makestr(&(optlist[noptlist++]),"CK_SPEED");
  8102. #endif /* CK_SPEED */
  8103. #ifdef CK_FAST
  8104.     makestr(&(optlist[noptlist++]),"CK_FAST");
  8105. #endif /* CK_FAST */
  8106. #ifdef CK_APC
  8107.     makestr(&(optlist[noptlist++]),"CK_APC");
  8108. #endif /* CK_APC */
  8109. #ifdef CK_AUTODL
  8110.     makestr(&(optlist[noptlist++]),"CK_AUTODL");
  8111. #endif /* CK_AUTODL */
  8112. #ifdef CK_MKDIR
  8113.     makestr(&(optlist[noptlist++]),"CK_MKDIR");
  8114. #endif /* CK_MKDIR */
  8115. #ifdef NOMKDIR
  8116.     makestr(&(optlist[noptlist++]),"NOMKDIR");
  8117. #endif /* NOMKDIR */
  8118. #ifdef CK_LABELED
  8119.     makestr(&(optlist[noptlist++]),"CK_LABELED");
  8120. #endif /* CK_LABELED */
  8121. #ifdef NODIAL
  8122.     makestr(&(optlist[noptlist++]),"NODIAL");
  8123. #endif /* NODIAL */
  8124. #ifdef MINIDIAL
  8125.     makestr(&(optlist[noptlist++]),"MINIDIAL");
  8126. #endif /* MINIDIAL */
  8127. #ifdef WHATAMI
  8128.     makestr(&(optlist[noptlist++]),"WHATAMI");
  8129. #endif /* WHATAMI */
  8130. #ifdef DYNAMIC
  8131.     makestr(&(optlist[noptlist++]),"DYNAMIC");
  8132. #endif /* IFDEBUG */
  8133. #ifndef NOSPL
  8134.     sprintf(line,"CMDDEP=%d",CMDDEP);
  8135.     makestr(&(optlist[noptlist++]),line);
  8136. #endif /* NOSPL */
  8137.  
  8138.     sprintf(line,"CKMAXPATH=%d",CKMAXPATH);
  8139.     makestr(&(optlist[noptlist++]),line);
  8140.  
  8141.     sprintf(line,"CKMAXOPEN=%d",CKMAXOPEN);
  8142.     makestr(&(optlist[noptlist++]),line);
  8143.  
  8144.     sprintf(line,"Z_MAXCHAN=%d",Z_MAXCHAN);
  8145.     makestr(&(optlist[noptlist++]),line);
  8146.  
  8147. #ifdef OPEN_MAX
  8148.     sprintf(line,"OPEN_MAX=%d",OPEN_MAX);
  8149.     makestr(&(optlist[noptlist++]),line);
  8150. #endif /* OPEN_MAX */
  8151.  
  8152. #ifdef _POSIX_OPEN_MAX
  8153.     sprintf(line,"_POSIX_OPEN_MAX=%d",_POSIX_OPEN_MAX);
  8154.     makestr(&(optlist[noptlist++]),line);
  8155. #endif /* _POSIX_OPEN_MAX */
  8156.  
  8157. #ifdef CKCHANNELIO
  8158.     {
  8159.     extern int z_maxchan;
  8160. #ifdef UNIX
  8161.     extern int ckmaxfiles;
  8162.     sprintf(line,"ckmaxfiles=%d",ckmaxfiles);
  8163.     makestr(&(optlist[noptlist++]),line);
  8164. #endif /* UNIX */
  8165.     sprintf(line,"z_maxchan=%d",z_maxchan);
  8166.     makestr(&(optlist[noptlist++]),line);
  8167.     }
  8168. #endif /* CKCHANNELIO */
  8169.  
  8170. #ifdef FOPEN_MAX
  8171.     sprintf(line,"FOPEN_MAX=%d",FOPEN_MAX);
  8172.     makestr(&(optlist[noptlist++]),line);
  8173. #endif /* FOPEN_MAX */
  8174.  
  8175. #ifdef MAXGETPATH
  8176.     sprintf(line,"MAXGETPATH=%d",MAXGETPATH);
  8177.     makestr(&(optlist[noptlist++]),line);
  8178. #endif /* MAXGETPATH */
  8179.  
  8180. #ifdef CMDBL
  8181.     sprintf(line,"CMDBL=%d",CMDBL);
  8182.     makestr(&(optlist[noptlist++]),line);
  8183. #endif /* CMDBL */
  8184.  
  8185. #ifdef VNAML
  8186.     sprintf(line,"VNAML=%d",VNAML);
  8187.     makestr(&(optlist[noptlist++]),line);
  8188. #endif /* VNAML */
  8189.  
  8190. #ifdef ARRAYREFLEN
  8191.     sprintf(line,"ARRAYREFLEN=%d",ARRAYREFLEN);
  8192.     makestr(&(optlist[noptlist++]),line);
  8193. #endif /* ARRAYREFLEN */
  8194.  
  8195. #ifdef UIDBUFLEN
  8196.     sprintf(line,"UIDBUFLEN=%d",UIDBUFLEN);
  8197.     makestr(&(optlist[noptlist++]),line);
  8198. #endif /* UIDBUFLEN */
  8199.  
  8200. #ifdef FORDEPTH
  8201.     sprintf(line,"FORDEPTH=%d",FORDEPTH);
  8202.     makestr(&(optlist[noptlist++]),line);
  8203. #endif /* FORDEPTH */
  8204.  
  8205. #ifdef MAXTAKE
  8206.     sprintf(line,"MAXTAKE=%d",MAXTAKE);
  8207.     makestr(&(optlist[noptlist++]),line);
  8208. #endif /* MAXTAKE */
  8209.  
  8210. #ifdef MACLEVEL
  8211.     sprintf(line,"MACLEVEL=%d",MACLEVEL);
  8212.     makestr(&(optlist[noptlist++]),line);
  8213. #endif /* MACLEVEL */
  8214.  
  8215. #ifdef MAC_MAX
  8216.     sprintf(line,"MAC_MAX=%d",MAC_MAX);
  8217.     makestr(&(optlist[noptlist++]),line);
  8218. #endif /* MAC_MAX */
  8219.  
  8220. #ifdef MINPUTMAX
  8221.     sprintf(line,"MINPUTMAX=%d",MINPUTMAX);
  8222.     makestr(&(optlist[noptlist++]),line);
  8223. #endif /* MINPUTMAX */
  8224.  
  8225. #ifdef MAXWLD
  8226.     sprintf(line,"MAXWLD=%d",MAXWLD);
  8227.     makestr(&(optlist[noptlist++]),line);
  8228. #else
  8229. #ifdef OS2
  8230.     makestr(&(optlist[noptlist++]),"MAXWLD=unlimited");
  8231. #endif /* OS2 */
  8232. #endif /* MAXWLD */
  8233.  
  8234. #ifdef MSENDMAX
  8235.     sprintf(line,"MSENDMAX=%d",MSENDMAX);
  8236.     makestr(&(optlist[noptlist++]),line);
  8237. #endif /* MSENDMAX */
  8238.  
  8239. #ifdef MAXDDIR
  8240.     sprintf(line,"MAXDDIR=%d",MAXDDIR);
  8241.     makestr(&(optlist[noptlist++]),line);
  8242. #endif /* MAXDDIR */
  8243.  
  8244. #ifdef MAXDNUMS
  8245.     sprintf(line,"MAXDNUMS=%d",MAXDNUMS);
  8246.     makestr(&(optlist[noptlist++]),line);
  8247. #endif /* MAXDNUMS */
  8248.  
  8249. #ifdef UNIX
  8250.     makestr(&(optlist[noptlist++]),"UNIX");
  8251. #endif /* UNIX */
  8252. #ifdef VMS
  8253.     makestr(&(optlist[noptlist++]),"VMS");
  8254. #ifdef __VMS_VER
  8255.     sprintf(line,"__VMS_VER=%d",__VMS_VER);
  8256.     makestr(&(optlist[noptlist++]),line);
  8257. #endif /* __VMS_VER */
  8258. #ifdef VMSV70
  8259.     makestr(&(optlist[noptlist++]),"VMSV70");
  8260. #endif /* VMSV70 */
  8261. #endif /* VMS */
  8262. #ifdef OLD_VMS
  8263.     makestr(&(optlist[noptlist++]),"OLD_VMS");
  8264. #endif /* OLD_VMS */
  8265. #ifdef vms
  8266.     makestr(&(optlist[noptlist++]),"vms");
  8267. #endif /* vms */
  8268. #ifdef VMSSHARE
  8269.     makestr(&(optlist[noptlist++]),"VMSSHARE");
  8270. #endif /* VMSSHARE */
  8271. #ifdef NOVMSSHARE
  8272.     makestr(&(optlist[noptlist++]),"NOVMSSHARE");
  8273. #endif /* NOVMSSHARE */
  8274. #ifdef datageneral
  8275.     makestr(&(optlist[noptlist++]),"datageneral");
  8276. #endif /* datageneral */
  8277. #ifdef apollo
  8278.     makestr(&(optlist[noptlist++]),"apollo");
  8279. #endif /* apollo */
  8280. #ifdef aegis
  8281.     makestr(&(optlist[noptlist++]),"aegis");
  8282. #endif /* aegis */
  8283. #ifdef A986
  8284.     makestr(&(optlist[noptlist++]),"A986");
  8285. #endif /* A986 */
  8286. #ifdef AMIGA
  8287.     makestr(&(optlist[noptlist++]),"AMIGA");
  8288. #endif /* AMIGA */
  8289. #ifdef CONVEX9
  8290.     makestr(&(optlist[noptlist++]),"CONVEX9");
  8291. #endif /* CONVEX9 */
  8292. #ifdef CONVEX10
  8293.     makestr(&(optlist[noptlist++]),"CONVEX10");
  8294. #endif /* CONVEX9 */
  8295. #ifdef MAC
  8296.     makestr(&(optlist[noptlist++]),"MAC");
  8297. #endif /* MAC */
  8298. #ifdef AUX
  8299.     makestr(&(optlist[noptlist++]),"AUX");
  8300. #endif /* AUX */
  8301. #ifdef OS2
  8302.     makestr(&(optlist[noptlist++]),"OS2");
  8303. #ifdef NT
  8304.     makestr(&(optlist[noptlist++]),"NT");
  8305. #endif /* NT */
  8306. #endif /* OS2 */
  8307. #ifdef OSK
  8308.     makestr(&(optlist[noptlist++]),"OS9");
  8309. #endif /* OSK */
  8310. #ifdef MSDOS
  8311.     makestr(&(optlist[noptlist++]),"MSDOS");
  8312. #endif /* MSDOS */
  8313. #ifdef DIRENT
  8314.     makestr(&(optlist[noptlist++]),"DIRENT");
  8315. #endif /* DIRENT */
  8316. #ifdef SDIRENT
  8317.     makestr(&(optlist[noptlist++]),"SDIRENT");
  8318. #endif /* SDIRENT */
  8319. #ifdef NDIR
  8320.     makestr(&(optlist[noptlist++]),"NDIR");
  8321. #endif /* NDIR */
  8322. #ifdef XNDIR
  8323.     makestr(&(optlist[noptlist++]),"XNDIR");
  8324. #endif /* XNDIR */
  8325. #ifdef SAVEDUID
  8326.     makestr(&(optlist[noptlist++]),"SAVEDUID");
  8327. #endif /* SAVEDUID */
  8328. #ifdef RENAME
  8329.     makestr(&(optlist[noptlist++]),"RENAME");
  8330. #endif /* RENAME */
  8331. #ifdef CK_TMPDIR
  8332.     makestr(&(optlist[noptlist++]),"CK_TMPDIR");
  8333. #endif /* CK_TMPDIR */
  8334. #ifdef NOCCTRAP
  8335.     makestr(&(optlist[noptlist++]),"NOCCTRAP");
  8336. #endif /* NOCCTRAP */
  8337. #ifdef NOCOTFMC
  8338.     makestr(&(optlist[noptlist++]),"NOCOTFMC");
  8339. #endif /* NOCOTFMC */
  8340. #ifdef NOMSEND
  8341.     makestr(&(optlist[noptlist++]),"NOMSEND");
  8342. #endif /* NOMSEND */
  8343.  
  8344. #ifdef NOFRILLS
  8345.     makestr(&(optlist[noptlist++]),"NOFRILLS");
  8346. #endif /* NOFRILLS */
  8347.  
  8348. #ifdef PARSENSE
  8349.     makestr(&(optlist[noptlist++]),"PARSENSE");
  8350. #endif /* PARSENSE */
  8351.  
  8352. #ifdef TIMEH
  8353.     makestr(&(optlist[noptlist++]),"TIMEH");
  8354. #endif /* TIMEH */
  8355. #ifdef NOTIMEH
  8356.     makestr(&(optlist[noptlist++]),"TIMEH");
  8357. #endif /* NOTIMEH */
  8358.  
  8359. #ifdef SYSTIMEH
  8360.     makestr(&(optlist[noptlist++]),"SYSTIMEH");
  8361. #endif /* SYSTIMEH */
  8362. #ifdef NOSYSTIMEH
  8363.     makestr(&(optlist[noptlist++]),"SYSTIMEH");
  8364. #endif /* NOSYSTIMEH */
  8365.  
  8366. #ifdef SYSTIMEBH
  8367.     makestr(&(optlist[noptlist++]),"SYSTIMEBH");
  8368. #endif /* SYSTIMEBH */
  8369. #ifdef NOSYSTIMEBH
  8370.     makestr(&(optlist[noptlist++]),"SYSTIMEBH");
  8371. #endif /* NOSYSTIMEBH */
  8372.  
  8373. #ifdef CK_NEED_SIG
  8374.     makestr(&(optlist[noptlist++]),"CK_NEED_SIG");
  8375. #endif /* CK_NEED_SIG */
  8376. #ifdef CK_TTYFD
  8377.     makestr(&(optlist[noptlist++]),"CK_TTYFD");
  8378. #endif /* CK_TTYFD */
  8379. #ifdef NETCONN
  8380.     makestr(&(optlist[noptlist++]),"NETCONN");
  8381. #endif /* NETCONN */
  8382. #ifdef TCPSOCKET
  8383.     makestr(&(optlist[noptlist++]),"TCPSOCKET");
  8384. #ifdef NOTCPOPTS
  8385.     makestr(&(optlist[noptlist++]),"NOTCPOPTS");
  8386. #endif /* NOTCPOPTS */
  8387. #ifdef CK_DNS_SRV
  8388.     makestr(&(optlist[noptlist++]),"CK_DNS_SRV");
  8389. #endif /* CK_DNS_SRV */
  8390. #ifdef NO_DNS_SRV
  8391.     makestr(&(optlist[noptlist++]),"NO_DNS_SRV");
  8392. #endif /* NO_DNS_SRV */
  8393. #ifdef CKGHNLHOST
  8394.     makestr(&(optlist[noptlist++]),"CKGHNLHOST");
  8395. #endif /* CKGHNLHOST */
  8396. #ifdef NOLISTEN
  8397.     makestr(&(optlist[noptlist++]),"NOLISTEN");
  8398. #endif /* NOLISTEN */
  8399. #ifdef SOL_SOCKET
  8400.     makestr(&(optlist[noptlist++]),"SOL_SOCKET");
  8401. #endif /* SOL_SOCKET */
  8402. #ifdef TCP_NODELAY
  8403.     makestr(&(optlist[noptlist++]),"TDP_NODELAY");
  8404. #endif /* TCP_NODELAY */
  8405. #ifdef HADDRLIST
  8406.     makestr(&(optlist[noptlist++]),"HADDRLIST");
  8407. #endif /* HADDRLIST */
  8408. #ifdef CK_SOCKS
  8409.     makestr(&(optlist[noptlist++]),"CK_SOCKS");
  8410. #ifdef CK_SOCKS5
  8411.     makestr(&(optlist[noptlist++]),"CK_SOCKS5");
  8412. #endif /* CK_SOCKS5 */
  8413. #endif /* CK_SOCKS */
  8414. #ifdef RLOGCODE
  8415.     makestr(&(optlist[noptlist++]),"RLOGCODE");
  8416. #endif /* RLOGCODE */
  8417. #ifdef NETCMD
  8418.     makestr(&(optlist[noptlist++]),"NETCMD");
  8419. #endif /* NETCMD */
  8420. #ifdef NETPTY
  8421.     makestr(&(optlist[noptlist++]),"NETPTY");
  8422. #endif /* NETPTY */
  8423. #ifdef CK_ENVIRONMENT
  8424.     makestr(&(optlist[noptlist++]),"CK_ENVIRONMENT");
  8425. #endif /* CK_ENVIRONMENT */
  8426. #endif /* TCPSOCKET */
  8427. #ifdef TNCODE
  8428.     makestr(&(optlist[noptlist++]),"TNCODE");
  8429. #endif /* TNCODE */
  8430. #ifdef CK_FORWARD_X
  8431.     makestr(&(optlist[noptlist++]),"CK_FORWARD_X");
  8432. #endif /* CK_FORWARD_X */
  8433. #ifdef MULTINET
  8434.     makestr(&(optlist[noptlist++]),"MULTINET");
  8435. #endif /* MULTINET */
  8436. #ifdef DEC_TCPIP
  8437.     makestr(&(optlist[noptlist++]),"DEC_TCPIP");
  8438. #endif /* DEC_TCPIP */
  8439. #ifdef TCPWARE
  8440.     makestr(&(optlist[noptlist++]),"TCPWARE");
  8441. #endif /* TCPWARE */
  8442. #ifdef UCX50
  8443.     makestr(&(optlist[noptlist++]),"UCX50");
  8444. #endif /* UCX50 */
  8445. #ifdef TTLEBUF
  8446.     makestr(&(optlist[noptlist++]),"TTLEBUF");
  8447. #endif /* TTLEBUF */
  8448. #ifdef NETLEBUF
  8449.     makestr(&(optlist[noptlist++]),"NETLEBUF");
  8450. #endif /* NETLEBUF */
  8451. #ifdef IKS_OPTION
  8452.     makestr(&(optlist[noptlist++]),"IKS_OPTION");
  8453. #endif /* IKS_OPTION */
  8454. #ifdef IKSDB
  8455.     makestr(&(optlist[noptlist++]),"IKSDB");
  8456. #endif /* IKSDB */
  8457. #ifdef IKSDCONF
  8458.     makestr(&(optlist[noptlist++]),"IKSDCONF");
  8459. #endif /* IKSDCONF */
  8460. #ifdef CK_LOGIN
  8461.     makestr(&(optlist[noptlist++]),"CK_LOGIN");
  8462. #endif /* CK_LOGIN */
  8463. #ifdef CONGSPD
  8464.     makestr(&(optlist[noptlist++]),"CONGSPD");
  8465. #endif /* CONGSPDCK_SOCKS */
  8466. #ifdef SUNX25
  8467.     makestr(&(optlist[noptlist++]),"SUNX25");
  8468. #endif /* SUNX25 */
  8469. #ifdef IBMX25
  8470.     makestr(&(optlist[noptlist++]),"IBMX25");
  8471. #endif /* IBMX25 */
  8472. #ifdef HPX25
  8473.     makestr(&(optlist[noptlist++]),"HPX25");
  8474. #endif /* HPX25 */
  8475. #ifdef DECNET
  8476.     makestr(&(optlist[noptlist++]),"DECNET");
  8477. #endif /* DECNET */
  8478. #ifdef SUPERLAT
  8479.     makestr(&(optlist[noptlist++]),"SUPERLAT");
  8480. #endif /* SUPERLAT */
  8481. #ifdef NPIPE
  8482.     makestr(&(optlist[noptlist++]),"NPIPE");
  8483. #endif /* NPIPE */
  8484. #ifdef CK_NETBIOS
  8485.     makestr(&(optlist[noptlist++]),"CK_NETBIOS");
  8486. #endif /* CK_NETBIOS */
  8487. #ifdef ATT7300
  8488.     makestr(&(optlist[noptlist++]),"ATT7300");
  8489. #endif /* ATT7300 */
  8490. #ifdef ATT6300
  8491.     makestr(&(optlist[noptlist++]),"ATT6300");
  8492. #endif /* ATT6300 */
  8493. #ifdef HDBUUCP
  8494.     makestr(&(optlist[noptlist++]),"HDBUUCP");
  8495. #endif /* HDBUUCP */
  8496. #ifdef USETTYLOCK
  8497.     makestr(&(optlist[noptlist++]),"USETTYLOCK");
  8498. #endif /* USETTYLOCK */
  8499. #ifdef NOUUCP
  8500.     makestr(&(optlist[noptlist++]),"NOUUCP");
  8501. #endif /* NOUUCP */
  8502. #ifdef LONGFN
  8503.     makestr(&(optlist[noptlist++]),"LONGFN");
  8504. #endif /* LONGFN */
  8505. #ifdef RDCHK
  8506.     makestr(&(optlist[noptlist++]),"RDCHK");
  8507. #endif /* RDCHK */
  8508. #ifdef SELECT
  8509.     makestr(&(optlist[noptlist++]),"SELECT");
  8510. #endif /* SELECT */
  8511. #ifdef USLEEP
  8512.     makestr(&(optlist[noptlist++]),"USLEEP");
  8513. #endif /* USLEEP */
  8514. #ifdef NAP
  8515.     makestr(&(optlist[noptlist++]),"NAP");
  8516. #endif /* NAP */
  8517. #ifdef NAPHACK
  8518.     makestr(&(optlist[noptlist++]),"NAPHACK");
  8519. #endif /* NAPHACK */
  8520. #ifdef CK_POLL
  8521.     makestr(&(optlist[noptlist++]),"CK_POLL");
  8522. #endif /* CK_POLL */
  8523. #ifdef NOIEXTEN
  8524.     makestr(&(optlist[noptlist++]),"NOIEXTEN");
  8525. #endif /* NOIEXTEN */
  8526. #ifdef EXCELAN
  8527.     makestr(&(optlist[noptlist++]),"EXCELAN");
  8528. #endif /* EXCELAN */
  8529. #ifdef INTERLAN
  8530.     makestr(&(optlist[noptlist++]),"INTERLAN");
  8531. #endif /* INTERLAN */
  8532. #ifdef NOFILEH
  8533.     makestr(&(optlist[noptlist++]),"NOFILEH");
  8534. #endif /* NOFILEH */
  8535. #ifdef NOSYSIOCTLH
  8536.     makestr(&(optlist[noptlist++]),"NOSYSIOCTLH");
  8537. #endif /* NOSYSIOCTLH */
  8538. #ifdef DCLPOPEN
  8539.     makestr(&(optlist[noptlist++]),"DCLPOPEN");
  8540. #endif /* DCLPOPEN */
  8541. #ifdef NOSETBUF
  8542.     makestr(&(optlist[noptlist++]),"NOSETBUF");
  8543. #endif /* NOSETBUF */
  8544. #ifdef NOXFER
  8545.     makestr(&(optlist[noptlist++]),"NOXFER");
  8546. #endif /* NOXFER */
  8547. #ifdef NOCURSES
  8548.     makestr(&(optlist[noptlist++]),"NOCURSES");
  8549. #endif /* NOCURSES */
  8550. #ifdef NOSERVER
  8551.     makestr(&(optlist[noptlist++]),"NOSERVER");
  8552. #endif /* NOSERVER */
  8553. #ifdef NOPATTERNS
  8554.     makestr(&(optlist[noptlist++]),"NOPATTERNS");
  8555. #else
  8556. #ifdef PATTERNS
  8557.     makestr(&(optlist[noptlist++]),"PATTERNS");
  8558. #endif /* PATTERNS */
  8559. #endif /* NOPATTERNS */
  8560. #ifdef NOCKEXEC
  8561.     makestr(&(optlist[noptlist++]),"NOCKEXEC");
  8562. #else
  8563. #ifdef CKEXEC
  8564.     makestr(&(optlist[noptlist++]),"CKEXEC");
  8565. #endif /* CKEXEC */
  8566. #endif /* NOCKEXEC */
  8567. #ifdef NOAUTODL
  8568.     makestr(&(optlist[noptlist++]),"NOAUTODL");
  8569. #endif /* NOAUTODL */
  8570. #ifdef NOMSEND
  8571.     makestr(&(optlist[noptlist++]),"NOMSEND");
  8572. #endif /* NOMSEND */
  8573. #ifdef NOFDZERO
  8574.     makestr(&(optlist[noptlist++]),"NOFDZERO");
  8575. #endif /* NOFDZERO */
  8576. #ifdef NOPOPEN
  8577.     makestr(&(optlist[noptlist++]),"NOPOPEN");
  8578. #endif /* NOPOPEN */
  8579. #ifdef NOPARTIAL
  8580.     makestr(&(optlist[noptlist++]),"NOPARTIAL");
  8581. #endif /* NOPARTIAL */
  8582. #ifdef NOKVERBS
  8583.     makestr(&(optlist[noptlist++]),"NOKVERBS");
  8584. #endif /* NOKVERBS */
  8585. #ifdef NOSETREU
  8586.     makestr(&(optlist[noptlist++]),"NOSETREU");
  8587. #endif /* NOSETREU */
  8588. #ifdef LCKDIR
  8589.     makestr(&(optlist[noptlist++]),"LCKDIR");
  8590. #endif /* LCKDIR */
  8591. #ifdef ACUCNTRL
  8592.     makestr(&(optlist[noptlist++]),"ACUCNTRL");
  8593. #endif /* ACUCNTRL */
  8594. #ifdef BSD4
  8595.     makestr(&(optlist[noptlist++]),"BSD4");
  8596. #endif /* BSD4 */
  8597. #ifdef BSD44
  8598.     makestr(&(optlist[noptlist++]),"BSD44");
  8599. #endif /* BSD44 */
  8600. #ifdef BSD41
  8601.     makestr(&(optlist[noptlist++]),"BSD41");
  8602. #endif /* BSD41 */
  8603. #ifdef BSD43
  8604.     makestr(&(optlist[noptlist++]),"BSD43");
  8605. #endif /* BSD43 */
  8606. #ifdef BSD29
  8607.     makestr(&(optlist[noptlist++]),"BSD29");
  8608. #endif /* BSD29 */
  8609. #ifdef BSDI
  8610.     makestr(&(optlist[noptlist++]),"BSDI");
  8611. #endif /* BSDI */
  8612. #ifdef __bsdi__
  8613.     makestr(&(optlist[noptlist++]),"__bsdi__");
  8614. #endif /* __bsdi__ */
  8615. #ifdef __NetBSD__
  8616.     makestr(&(optlist[noptlist++]),"__NetBSD__");
  8617. #endif /* __NetBSD__ */
  8618. #ifdef __FreeBSD__
  8619.     makestr(&(optlist[noptlist++]),"__FreeBSD__");
  8620. #endif /* __FreeBSD__ */
  8621. #ifdef __linux__
  8622.     makestr(&(optlist[noptlist++]),"__linux__");
  8623. #endif /* __linux__ */
  8624. #ifdef LINUX_HI_SPD
  8625.     makestr(&(optlist[noptlist++]),"LINUX_HI_SPD");
  8626. #endif /* LINUX_HI_SPD */
  8627. #ifdef LYNXOS
  8628.     makestr(&(optlist[noptlist++]),"LYNXOS");
  8629. #endif /* LYNXOS */
  8630. #ifdef V7
  8631.     makestr(&(optlist[noptlist++]),"V7");
  8632. #endif /* V7 */
  8633. #ifdef AIX370
  8634.     makestr(&(optlist[noptlist++]),"AIX370");
  8635. #endif /* AIX370 */
  8636. #ifdef RTAIX
  8637.     makestr(&(optlist[noptlist++]),"RTAIX");
  8638. #endif /* RTAIX */
  8639. #ifdef HPUX
  8640.     makestr(&(optlist[noptlist++]),"HPUX");
  8641. #endif /* HPUX */
  8642. #ifdef HPUXPRE65
  8643.     makestr(&(optlist[noptlist++]),"HPUXPRE65");
  8644. #endif /* HPUXPRE65 */
  8645. #ifdef DGUX
  8646.     makestr(&(optlist[noptlist++]),"DGUX");
  8647. #endif /* DGUX */
  8648. #ifdef DGUX430
  8649.     makestr(&(optlist[noptlist++]),"DGUX430");
  8650. #endif /* DGUX430 */
  8651. #ifdef DGUX540
  8652.     makestr(&(optlist[noptlist++]),"DGUX540");
  8653. #endif /* DGUX540 */
  8654. #ifdef DGUX543
  8655.     makestr(&(optlist[noptlist++]),"DGUX543");
  8656. #endif /* DGUX543 */
  8657. #ifdef DGUX54410
  8658.     makestr(&(optlist[noptlist++]),"DGUX54410");
  8659. #endif /* DGUX54410 */
  8660. #ifdef DGUX54411
  8661.     makestr(&(optlist[noptlist++]),"DGUX54411");
  8662. #endif /* DGUX54411 */
  8663. #ifdef sony_news
  8664.     makestr(&(optlist[noptlist++]),"sony_news");
  8665. #endif /* sony_news */
  8666. #ifdef CIE
  8667.     makestr(&(optlist[noptlist++]),"CIE");
  8668. #endif /* CIE */
  8669. #ifdef XENIX
  8670.     makestr(&(optlist[noptlist++]),"XENIX");
  8671. #endif /* XENIX */
  8672. #ifdef SCO_XENIX
  8673.     makestr(&(optlist[noptlist++]),"SCO_XENIX");
  8674. #endif /* SCO_XENIX */
  8675. #ifdef ISIII
  8676.     makestr(&(optlist[noptlist++]),"ISIII");
  8677. #endif /* ISIII */
  8678. #ifdef I386IX
  8679.     makestr(&(optlist[noptlist++]),"I386IX");
  8680. #endif /* I386IX */
  8681. #ifdef RTU
  8682.     makestr(&(optlist[noptlist++]),"RTU");
  8683. #endif /* RTU */
  8684. #ifdef PROVX1
  8685.     makestr(&(optlist[noptlist++]),"PROVX1");
  8686. #endif /* PROVX1 */
  8687. #ifdef PYRAMID
  8688.     makestr(&(optlist[noptlist++]),"PYRAMID");
  8689. #endif /* PYRAMID */
  8690. #ifdef TOWER1
  8691.     makestr(&(optlist[noptlist++]),"TOWER1");
  8692. #endif /* TOWER1 */
  8693. #ifdef UTEK
  8694.     makestr(&(optlist[noptlist++]),"UTEK");
  8695. #endif /* UTEK */
  8696. #ifdef ZILOG
  8697.     makestr(&(optlist[noptlist++]),"ZILOG");
  8698. #endif /* ZILOG */
  8699. #ifdef TRS16
  8700.     makestr(&(optlist[noptlist++]),"TRS16");
  8701. #endif /* TRS16 */
  8702. #ifdef MINIX
  8703.     makestr(&(optlist[noptlist++]),"MINIX");
  8704. #endif /* MINIX */
  8705. #ifdef C70
  8706.     makestr(&(optlist[noptlist++]),"C70");
  8707. #endif /* C70 */
  8708. #ifdef AIXPS2
  8709.     makestr(&(optlist[noptlist++]),"AIXPS2");
  8710. #endif /* AIXPS2 */
  8711. #ifdef AIXRS
  8712.     makestr(&(optlist[noptlist++]),"AIXRS");
  8713. #endif /* AIXRS */
  8714. #ifdef UTSV
  8715.     makestr(&(optlist[noptlist++]),"UTSV");
  8716. #endif /* UTSV */
  8717. #ifdef ATTSV
  8718.     makestr(&(optlist[noptlist++]),"ATTSV");
  8719. #endif /* ATTSV */
  8720. #ifdef SVR3
  8721.     makestr(&(optlist[noptlist++]),"SVR3");
  8722. #endif /* SVR3 */
  8723. #ifdef SVR4
  8724.     makestr(&(optlist[noptlist++]),"SVR4");
  8725. #endif /* SVR4 */
  8726. #ifdef DELL_SVR4
  8727.     makestr(&(optlist[noptlist++]),"DELL_SVR4");
  8728. #endif /* DELL_SVR4 */
  8729. #ifdef ICL_SVR4
  8730.     makestr(&(optlist[noptlist++]),"ICL_SVR4");
  8731. #endif /* ICL_SVR4 */
  8732. #ifdef OSF
  8733.     makestr(&(optlist[noptlist++]),"OSF");
  8734. #endif /* OSF */
  8735. #ifdef OSF1
  8736.     makestr(&(optlist[noptlist++]),"OSF1");
  8737. #endif /* OSF1 */
  8738. #ifdef __OSF
  8739.     makestr(&(optlist[noptlist++]),"__OSF");
  8740. #endif /* __OSF */
  8741. #ifdef __OSF__
  8742.     makestr(&(optlist[noptlist++]),"__OSF__");
  8743. #endif /* __OSF__ */
  8744. #ifdef __osf__
  8745.     makestr(&(optlist[noptlist++]),"__osf__");
  8746. #endif /* __osf__ */
  8747. #ifdef __OSF1
  8748.     makestr(&(optlist[noptlist++]),"__OSF1");
  8749. #endif /* __OSF1 */
  8750. #ifdef __OSF1__
  8751.     makestr(&(optlist[noptlist++]),"__OSF1__");
  8752. #endif /* __OSF1__ */
  8753. #ifdef PTX
  8754.     makestr(&(optlist[noptlist++]),"PTX");
  8755. #endif /* PTX */
  8756. #ifdef POSIX
  8757.     makestr(&(optlist[noptlist++]),"POSIX");
  8758. #endif /* POSIX */
  8759. #ifdef BSD44ORPOSIX
  8760.     makestr(&(optlist[noptlist++]),"BSD44ORPOSIX");
  8761. #endif /* BSD44ORPOSIX */
  8762. #ifdef _POSIX_SOURCE
  8763.     makestr(&(optlist[noptlist++]),"_POSIX_SOURCE");
  8764. #endif /* _POSIX_SOURCE */
  8765. #ifdef _XOPEN_SOURCE
  8766.     makestr(&(optlist[noptlist++]),"_XOPEN_SOURCE");
  8767. #endif
  8768. #ifdef _ALL_SOURCE
  8769.     makestr(&(optlist[noptlist++]),"_ALL_SOURCE");
  8770. #endif
  8771. #ifdef _SVID3
  8772.     makestr(&(optlist[noptlist++]),"_SVID3");
  8773. #endif /* _SVID3 */
  8774. #ifdef Plan9
  8775.     makestr(&(optlist[noptlist++]),"Plan9");
  8776. #endif /* Plan9 */
  8777. #ifdef SOLARIS
  8778.     makestr(&(optlist[noptlist++]),"SOLARIS");
  8779. #endif /* SOLARIS */
  8780. #ifdef SUNOS4
  8781.     makestr(&(optlist[noptlist++]),"SUNOS4");
  8782. #endif /* SUNOS4 */
  8783. #ifdef SUN4S5
  8784.     makestr(&(optlist[noptlist++]),"SUN4S5");
  8785. #endif /* SUN4S5 */
  8786. #ifdef IRIX
  8787.     makestr(&(optlist[noptlist++]),"IRIX");
  8788. #endif /* IRIX */
  8789. #ifdef ENCORE
  8790.     makestr(&(optlist[noptlist++]),"ENCORE");
  8791. #endif /* ENCORE */
  8792. #ifdef ultrix
  8793.     makestr(&(optlist[noptlist++]),"ultrix");
  8794. #endif
  8795. #ifdef sxaE50
  8796.     makestr(&(optlist[noptlist++]),"sxaE50");
  8797. #endif
  8798. #ifdef mips
  8799.     makestr(&(optlist[noptlist++]),"mips");
  8800. #endif
  8801. #ifdef MIPS
  8802.     makestr(&(optlist[noptlist++]),"MIPS");
  8803. #endif
  8804. #ifdef vax
  8805.     makestr(&(optlist[noptlist++]),"vax");
  8806. #endif
  8807. #ifdef VAX
  8808.     makestr(&(optlist[noptlist++]),"VAX");
  8809. #endif
  8810. #ifdef alpha
  8811.     makestr(&(optlist[noptlist++]),"alpha");
  8812. #endif
  8813. #ifdef ALPHA
  8814.     makestr(&(optlist[noptlist++]),"ALPHA");
  8815. #endif
  8816. #ifdef __ALPHA
  8817.     makestr(&(optlist[noptlist++]),"__ALPHA");
  8818. #endif
  8819. #ifdef __alpha
  8820.     makestr(&(optlist[noptlist++]),"__alpha");
  8821. #endif
  8822. #ifdef __AXP
  8823.     makestr(&(optlist[noptlist++]),"__AXP");
  8824. #endif
  8825. #ifdef AXP
  8826.     makestr(&(optlist[noptlist++]),"AXP");
  8827. #endif
  8828. #ifdef axp
  8829.     makestr(&(optlist[noptlist++]),"axp");
  8830. #endif
  8831. #ifdef __ALPHA__
  8832.     makestr(&(optlist[noptlist++]),"__ALPHA__");
  8833. #endif
  8834. #ifdef __alpha__
  8835.     makestr(&(optlist[noptlist++]),"__alpha__");
  8836. #endif
  8837. #ifdef sun
  8838.     makestr(&(optlist[noptlist++]),"sun");
  8839. #endif
  8840. #ifdef sun3
  8841.     makestr(&(optlist[noptlist++]),"sun3");
  8842. #endif
  8843. #ifdef sun386
  8844.     makestr(&(optlist[noptlist++]),"sun386");
  8845. #endif
  8846. #ifdef _SUN
  8847.     makestr(&(optlist[noptlist++]),"_SUN");
  8848. #endif
  8849. #ifdef sun4
  8850.     makestr(&(optlist[noptlist++]),"sun4");
  8851. #endif
  8852. #ifdef sparc
  8853.     makestr(&(optlist[noptlist++]),"sparc");
  8854. #endif
  8855. #ifdef _CRAY
  8856.     makestr(&(optlist[noptlist++]),"_CRAY");
  8857. #endif /* _CRAY */
  8858. #ifdef NEXT33
  8859.     makestr(&(optlist[noptlist++]),"NEXT33");
  8860. #endif
  8861. #ifdef NEXT
  8862.     makestr(&(optlist[noptlist++]),"NEXT");
  8863. #endif
  8864. #ifdef NeXT
  8865.     makestr(&(optlist[noptlist++]),"NeXT");
  8866. #endif
  8867. #ifdef MACH
  8868.     makestr(&(optlist[noptlist++]),"MACH");
  8869. #endif
  8870. #ifdef sgi
  8871.     makestr(&(optlist[noptlist++]),"sgi");
  8872. #endif
  8873. #ifdef M_SYS5
  8874.     makestr(&(optlist[noptlist++]),"M_SYS5");
  8875. #endif
  8876. #ifdef __SYSTEM_FIVE
  8877.     makestr(&(optlist[noptlist++]),"__SYSTEM_FIVE");
  8878. #endif
  8879. #ifdef sysV
  8880.     makestr(&(optlist[noptlist++]),"sysV");
  8881. #endif
  8882. #ifdef M_XENIX                /* SCO Xenix V and UNIX/386 */
  8883.     makestr(&(optlist[noptlist++]),"M_XENIX");
  8884. #endif
  8885. #ifdef M_UNIX                /* SCO UNIX */
  8886.     makestr(&(optlist[noptlist++]),"M_UNIX");
  8887. #endif
  8888. #ifdef _M_UNIX                /* SCO UNIX 3.2v4 = ODT 2.0 */
  8889.     makestr(&(optlist[noptlist++]),"_M_UNIX");
  8890. #endif
  8891. #ifdef CK_SCOV5
  8892.     makestr(&(optlist[noptlist++]),"CK_SCOV5");
  8893. #endif
  8894. #ifdef SCO_OSR504
  8895.     makestr(&(optlist[noptlist++]),"SCO_OSR504");
  8896. #endif
  8897. #ifdef M_I586
  8898.     makestr(&(optlist[noptlist++]),"M_I586");
  8899. #endif
  8900. #ifdef _M_I586
  8901.     makestr(&(optlist[noptlist++]),"_M_I586");
  8902. #endif
  8903. #ifdef i586
  8904.     makestr(&(optlist[noptlist++]),"i586");
  8905. #endif
  8906. #ifdef M_I486
  8907.     makestr(&(optlist[noptlist++]),"M_I486");
  8908. #endif
  8909. #ifdef _M_I486
  8910.     makestr(&(optlist[noptlist++]),"_M_I486");
  8911. #endif
  8912. #ifdef i486
  8913.     makestr(&(optlist[noptlist++]),"i486");
  8914. #endif
  8915. #ifdef M_I386
  8916.     makestr(&(optlist[noptlist++]),"M_I386");
  8917. #endif
  8918. #ifdef _M_I386
  8919.     makestr(&(optlist[noptlist++]),"_M_I386");
  8920. #endif
  8921. #ifdef i386
  8922.     makestr(&(optlist[noptlist++]),"i386");
  8923. #endif
  8924. #ifdef i286
  8925.     makestr(&(optlist[noptlist++]),"i286");
  8926. #endif
  8927. #ifdef M_I286
  8928.     makestr(&(optlist[noptlist++]),"M_I286");
  8929. #endif
  8930. #ifdef mc68000
  8931.     makestr(&(optlist[noptlist++]),"mc68000");
  8932. #endif
  8933. #ifdef mc68010
  8934.     makestr(&(optlist[noptlist++]),"mc68010");
  8935. #endif
  8936. #ifdef mc68020
  8937.     makestr(&(optlist[noptlist++]),"mc68020");
  8938. #endif
  8939. #ifdef mc68030
  8940.     makestr(&(optlist[noptlist++]),"mc68030");
  8941. #endif
  8942. #ifdef mc68040
  8943.     makestr(&(optlist[noptlist++]),"mc68040");
  8944. #endif
  8945. #ifdef M_68000
  8946.     makestr(&(optlist[noptlist++]),"M_68000");
  8947. #endif
  8948. #ifdef M_68010
  8949.     makestr(&(optlist[noptlist++]),"M_68010");
  8950. #endif
  8951. #ifdef M_68020
  8952.     makestr(&(optlist[noptlist++]),"M_68020");
  8953. #endif
  8954. #ifdef M_68030
  8955.     makestr(&(optlist[noptlist++]),"M_68030");
  8956. #endif
  8957. #ifdef M_68040
  8958.     makestr(&(optlist[noptlist++]),"M_68040");
  8959. #endif
  8960. #ifdef m68k
  8961.     makestr(&(optlist[noptlist++]),"m68k");
  8962. #endif
  8963. #ifdef m88k
  8964.     makestr(&(optlist[noptlist++]),"m88k");
  8965. #endif
  8966. #ifdef pdp11
  8967.     makestr(&(optlist[noptlist++]),"pdp11");
  8968. #endif
  8969. #ifdef iAPX
  8970.     makestr(&(optlist[noptlist++]),"iAPX");
  8971. #endif
  8972. #ifdef hpux
  8973.     makestr(&(optlist[noptlist++]),"hpux");
  8974. #endif
  8975. #ifdef __hpux
  8976.     makestr(&(optlist[noptlist++]),"__hpux");
  8977. #endif
  8978. #ifdef __hp9000s800
  8979.     makestr(&(optlist[noptlist++]),"__hp9000s800");
  8980. #endif
  8981. #ifdef __hp9000s700
  8982.     makestr(&(optlist[noptlist++]),"__hp9000s700");
  8983. #endif
  8984. #ifdef __hp9000s500
  8985.     makestr(&(optlist[noptlist++]),"__hp9000s500");
  8986. #endif
  8987. #ifdef __hp9000s300
  8988.     makestr(&(optlist[noptlist++]),"__hp9000s300");
  8989. #endif
  8990. #ifdef __hp9000s200
  8991.     makestr(&(optlist[noptlist++]),"__hp9000s200");
  8992. #endif
  8993. #ifdef AIX
  8994.     makestr(&(optlist[noptlist++]),"AIX");
  8995. #endif
  8996. #ifdef _AIXFS
  8997.     makestr(&(optlist[noptlist++]),"_AIXFS");
  8998. #endif
  8999. #ifdef u370
  9000.     makestr(&(optlist[noptlist++]),"u370");
  9001. #endif
  9002. #ifdef u3b
  9003.     makestr(&(optlist[noptlist++]),"u3b");
  9004. #endif
  9005. #ifdef u3b2
  9006.     makestr(&(optlist[noptlist++]),"u3b2");
  9007. #endif
  9008. #ifdef multimax
  9009.     makestr(&(optlist[noptlist++]),"multimax");
  9010. #endif
  9011. #ifdef balance
  9012.     makestr(&(optlist[noptlist++]),"balance");
  9013. #endif
  9014. #ifdef ibmrt
  9015.     makestr(&(optlist[noptlist++]),"ibmrt");
  9016. #endif
  9017. #ifdef _IBMRT
  9018.     makestr(&(optlist[noptlist++]),"_IBMRT");
  9019. #endif
  9020. #ifdef ibmrs6000
  9021.     makestr(&(optlist[noptlist++]),"ibmrs6000");
  9022. #endif
  9023. #ifdef _AIX
  9024.     makestr(&(optlist[noptlist++]),"_AIX");
  9025. #endif /* _AIX */
  9026. #ifdef _IBMR2
  9027.     makestr(&(optlist[noptlist++]),"_IBMR2");
  9028. #endif
  9029. #ifdef UNIXWARE
  9030.     makestr(&(optlist[noptlist++]),"UNIXWARE");
  9031. #endif
  9032. #ifdef QNX
  9033.     makestr(&(optlist[noptlist++]),"QNX");
  9034. #ifdef __QNX__
  9035.     makestr(&(optlist[noptlist++]),"__QNX__");
  9036. #ifdef __16BIT__
  9037.     makestr(&(optlist[noptlist++]),"__16BIT__");
  9038. #endif
  9039. #ifdef CK_QNX16
  9040.     makestr(&(optlist[noptlist++]),"CK_QNX16");
  9041. #endif
  9042. #ifdef __32BIT__
  9043.     makestr(&(optlist[noptlist++]),"__32BIT__");
  9044. #endif
  9045. #ifdef CK_QNX32
  9046.     makestr(&(optlist[noptlist++]),"CK_QNX32");
  9047. #endif
  9048. #endif /* __QNX__ */
  9049. #endif /* QNX */
  9050.  
  9051. #ifdef __STRICT_BSD__
  9052.     makestr(&(optlist[noptlist++]),"__STRICT_BSD__");
  9053. #endif
  9054. #ifdef __STRICT_ANSI__
  9055.     makestr(&(optlist[noptlist++]),"__STRICT_ANSI__");
  9056. #endif
  9057. #ifdef _ANSI_C_SOURCE
  9058.     makestr(&(optlist[noptlist++]),"_ANSI_C_SOURCE");
  9059. #endif
  9060. #ifdef __STDC__
  9061.     makestr(&(optlist[noptlist++]),"__STDC__");
  9062. #endif
  9063. #ifdef __DECC
  9064.     makestr(&(optlist[noptlist++]),"__DECC");
  9065. #ifdef __DECC_VER
  9066.     sprintf(line,"__DECC_VER=%d",__DECC_VER);
  9067.     makestr(&(optlist[noptlist++]),line);
  9068. #endif /* __DECC_VER */
  9069. #endif /* __DECC */
  9070. #ifdef __CRTL_VER
  9071.     sprintf(line,"__CRTL_VER=%d",__CRTL_VER);
  9072.     makestr(&(optlist[noptlist++]),line);
  9073. #endif /* __CRTL_VER */
  9074. #ifdef __GNUC__                /* gcc in ansi mode */
  9075.     makestr(&(optlist[noptlist++]),"__GNUC__");
  9076. #endif
  9077. #ifdef GNUC                /* gcc in traditional mode */
  9078.     makestr(&(optlist[noptlist++]),"GNUC");
  9079. #endif
  9080. #ifdef __EGCS__                /* egcs in ansi mode */
  9081.     makestr(&(optlist[noptlist++]),"__EGCS__");
  9082. #endif
  9083. #ifdef __egcs__                /* egcs in ansi mode */
  9084.     makestr(&(optlist[noptlist++]),"__egcs__");
  9085. #endif
  9086. #ifdef __WATCOMC__
  9087.     makestr(&(optlist[noptlist++]),"__WATCOMC__");
  9088. #endif
  9089. #ifdef CK_ANSIC
  9090.     makestr(&(optlist[noptlist++]),"CK_ANSIC");
  9091. #endif
  9092. #ifdef CK_ANSILIBS
  9093.     makestr(&(optlist[noptlist++]),"CK_ANSILIBS");
  9094. #endif
  9095. #ifdef CKCONINTB4CB
  9096.     makestr(&(optlist[noptlist++]),"CKCONINTB4CB");
  9097. #endif /* CKCONINTB4CB */
  9098. #ifdef NOTERMCAP
  9099.     makestr(&(optlist[noptlist++]),"NOTERMCAP");
  9100. #endif /* NOTERMCAP */
  9101. #ifdef __GLIBC__
  9102.     makestr(&(optlist[noptlist++]),"__GLIBC__");
  9103. #endif
  9104. #ifdef _SC_JOB_CONTROL
  9105.     makestr(&(optlist[noptlist++]),"_SC_JOB_CONTROL");
  9106. #endif
  9107. #ifdef _POSIX_JOB_CONTROL
  9108.     makestr(&(optlist[noptlist++]),"_POSIX_JOB_CONTROL");
  9109. #endif
  9110. #ifdef SIG_I
  9111.     makestr(&(optlist[noptlist++]),"SIG_I");
  9112. #endif /* SIG_I */
  9113. #ifdef SIG_V
  9114.     makestr(&(optlist[noptlist++]),"SIG_V");
  9115. #endif /* SIG_V */
  9116. #ifdef CK_POSIX_SIG
  9117.     makestr(&(optlist[noptlist++]),"CK_POSIX_SIG");
  9118. #endif
  9119. #ifdef SVR3JC
  9120.     makestr(&(optlist[noptlist++]),"SVR3JC");
  9121. #endif
  9122. #ifdef _386BSD
  9123.     makestr(&(optlist[noptlist++]),"_386BSD");
  9124. #endif
  9125. #ifdef _BSD
  9126.     makestr(&(optlist[noptlist++]),"_BSD");
  9127. #endif
  9128. #ifdef USE_MEMCPY
  9129.     makestr(&(optlist[noptlist++]),"USE_MEMCPY");
  9130. #endif /* USE_MEMCPY */
  9131. #ifdef USE_LSTAT
  9132.     makestr(&(optlist[noptlist++]),"USE_LSTAT");
  9133. #endif /* USE_LSTAT */
  9134. #ifdef TERMIOX
  9135.     makestr(&(optlist[noptlist++]),"TERMIOX");
  9136. #endif /* TERMIOX */
  9137. #ifdef STERMIOX
  9138.     makestr(&(optlist[noptlist++]),"STERMIOX");
  9139. #endif /* STERMIOX */
  9140. #ifdef CK_CURSES
  9141.     makestr(&(optlist[noptlist++]),"CK_CURSES");
  9142. #endif /* CK_CURSES */
  9143. #ifdef CK_NEWTERM
  9144.     makestr(&(optlist[noptlist++]),"CK_NEWTERM");
  9145. #endif /* CK_NEWTERM */
  9146. #ifdef CK_WREFRESH
  9147.     makestr(&(optlist[noptlist++]),"CK_WREFRESH");
  9148. #endif /* CK_WREFRESH */
  9149. #ifdef CK_PCT_BAR
  9150.     makestr(&(optlist[noptlist++]),"CK_PCT_BAR");
  9151. #endif /* CK_PCT_BAR */
  9152. #ifdef CK_DTRCD
  9153.     makestr(&(optlist[noptlist++]),"CK_DTRCD");
  9154. #endif /* CK_DTRCD */
  9155. #ifdef CK_DTRCTS
  9156.     makestr(&(optlist[noptlist++]),"CK_DTRCTS");
  9157. #endif /* CK_DTRCTS */
  9158. #ifdef CK_RTSCTS
  9159.     makestr(&(optlist[noptlist++]),"CK_RTSCTS");
  9160. #endif /* CK_RTSCTS */
  9161. #ifdef POSIX_CRTSCTS
  9162.     makestr(&(optlist[noptlist++]),"POSIX_CRTSCTS");
  9163. #endif /* POSIX_CRTSCTS */
  9164. #ifdef HWPARITY
  9165.     makestr(&(optlist[noptlist++]),"HWPARITY");
  9166. #endif /* HWPARITY */
  9167. #ifdef CK_SYSINI
  9168. #ifdef CK_INI_A
  9169.     makestr(&(optlist[noptlist++]),"CK_INI_A");
  9170.     sprintf(line,"CK_SYSINI=\"%s\"",CK_SYSINI);
  9171.     makestr(&(optlist[noptlist++]),line);
  9172. #else
  9173. #ifdef CK_INI_B
  9174.     makestr(&(optlist[noptlist++]),"CK_INI_B");
  9175.     sprintf(line,"CK_SYSINI=\"%s\"",CK_SYSINI);
  9176.     makestr(&(optlist[noptlist++]),line);
  9177. #else
  9178.     makestr(&(optlist[noptlist++]),"CK_SYSINI");
  9179. #endif /* CK_INI_B */
  9180. #endif /* CK_INI_A */
  9181. #endif /* CK_DSYSINI */
  9182. #ifdef CK_DSYSINI
  9183.     makestr(&(optlist[noptlist++]),"CK_DSYSINI");
  9184. #endif /* CK_DSYSINI */
  9185. #ifdef CK_TTGWSIZ
  9186.     makestr(&(optlist[noptlist++]),"CK_TTGWSIZ");
  9187. #endif /* CK_TTGWSIZ */
  9188. #ifdef CK_NAWS
  9189.     makestr(&(optlist[noptlist++]),"CK_NAWS");
  9190. #endif /* CK_NAWS */
  9191. #ifdef DCMDBUF
  9192.     makestr(&(optlist[noptlist++]),"DCMDBUF");
  9193. #endif /* DCMDBUF */
  9194. #ifdef CK_RECALL
  9195.     makestr(&(optlist[noptlist++]),"CK_RECALL");
  9196. #endif /* CK_RECALL */
  9197. #ifdef BROWSER
  9198.     makestr(&(optlist[noptlist++]),"BROWSER");
  9199. #endif /* BROWSER */
  9200. #ifdef CLSOPN
  9201.     makestr(&(optlist[noptlist++]),"CLSOPN");
  9202. #endif /* CLSOPN */
  9203. #ifdef STRATUS
  9204.     makestr(&(optlist[noptlist++]),"STRATUS");
  9205. #endif /* STRATUS */
  9206. #ifdef __VOS__
  9207.     makestr(&(optlist[noptlist++]),"__VOS__");
  9208. #endif /* __VOS__ */
  9209. #ifdef STRATUSX25
  9210.     makestr(&(optlist[noptlist++]),"STRATUSX25");
  9211. #endif /* STRATUSX25 */
  9212. #ifdef OS2MOUSE
  9213.     makestr(&(optlist[noptlist++]),"OS2MOUSE");
  9214. #endif /* OS2MOUSE */
  9215. #ifdef CK_REXX
  9216.     makestr(&(optlist[noptlist++]),"CK_REXX");
  9217. #endif /* CK_REXX */
  9218. #ifdef CK_TIMERS
  9219.     makestr(&(optlist[noptlist++]),"CK_TIMERS");
  9220. #endif /* CK_TIMERS */
  9221. #ifdef TTSPDLIST
  9222.     makestr(&(optlist[noptlist++]),"TTSPDLIST");
  9223. #endif /* TTSPDLIST */
  9224. #ifdef CK_PERMS
  9225.     makestr(&(optlist[noptlist++]),"CK_PERMS");
  9226. #endif /* CK_PERMS */
  9227. #ifdef CKTUNING
  9228.     makestr(&(optlist[noptlist++]),"CKTUNING");
  9229. #endif /* CKTUNING */
  9230. #ifdef CKREALPATH
  9231.     makestr(&(optlist[noptlist++]),"CKREALPATH");
  9232. #endif /* CKREALPATH */
  9233. #ifdef STREAMING
  9234.     makestr(&(optlist[noptlist++]),"STREAMING");
  9235. #endif /* STREAMING */
  9236. #ifdef UNPREFIXZERO
  9237.     makestr(&(optlist[noptlist++]),"UNPREFIXZERO");
  9238. #endif /* UNPREFIXZERO */
  9239. #ifdef CKREGEX
  9240.     makestr(&(optlist[noptlist++]),"CKREGEX");
  9241. #endif /* CKREGEX */
  9242. #ifdef ZXREWIND
  9243.     makestr(&(optlist[noptlist++]),"ZXREWIND");
  9244. #endif /* ZXREWIND */
  9245. #ifdef CKSYSLOG
  9246.     makestr(&(optlist[noptlist++]),"CKSYSLOG");
  9247. #endif /* CKSYSLOG */
  9248. #ifdef SYSLOGLEVEL
  9249.     sprintf(line,"SYSLOGLEVEL=%d",SYSLOGLEVEL);
  9250.     makestr(&(optlist[noptlist++]),line);
  9251. #endif /* SYSLOGLEVEL */
  9252. #ifdef NOFLOAT
  9253.     makestr(&(optlist[noptlist++]),"NOFLOAT");
  9254. #else
  9255. #ifdef FNFLOAT
  9256.     makestr(&(optlist[noptlist++]),"FNFLOAT");
  9257. #endif /* FNFLOAT */
  9258. #ifdef CKFLOAT
  9259. #ifdef GFTIMER
  9260.     makestr(&(optlist[noptlist++]),"GFTIMER");
  9261. #endif /* GFTIMER */
  9262. #ifdef CKFLOAT_S
  9263.     sprintf(line,"CKFLOAT=%s",CKFLOAT_S);
  9264.     makestr(&(optlist[noptlist++]),line);
  9265. #else
  9266.     makestr(&(optlist[noptlist++]),"CKFLOAT");
  9267. #endif /* CKFLOAT_S */
  9268. #endif /* CKFLOAT */
  9269. #endif /* NOFLOAT */
  9270.     debug(F101,"initoptlist noptlist","",noptlist);
  9271.     sh_sort(optlist,NULL,noptlist,0,0,0);
  9272. }
  9273.  
  9274. int
  9275. shofea() {
  9276.     int i;
  9277.     int flag = 0;
  9278.     int lines = 1;
  9279. #ifdef FNFLOAT
  9280.     extern int fp_digits, fp_rounding;
  9281. #endif /* FNFLOAT */
  9282.     extern int byteorder;
  9283.     debug(F101,"shofea NOPTLIST","",NOPTLIST);
  9284.     initoptlist();
  9285.     debug(F101,"shofea noptlist","",noptlist);
  9286.     printf("%s\n",versio);
  9287. #ifdef OS2
  9288. #ifdef NT
  9289.     if (isWin95())
  9290.       printf("Windows 95.\n");
  9291.     else
  9292.       printf("Windows NT.\n");
  9293. #else /* NT */
  9294. #ifdef M_I286
  9295.     printf("OS/2 16-bit.\n");
  9296. #else
  9297.     printf("OS/2 32-bit.\n");
  9298. #endif /* M_I286 */
  9299. #endif /* NT */
  9300.     lines++;
  9301. #endif /* OS2 */
  9302.     printf("\n");
  9303.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9304.     printf("Major optional features included:\n");
  9305.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9306.  
  9307. #ifdef NETCONN
  9308.     printf(" Network support (type SHOW NET for further info)\n");
  9309.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9310. #ifdef IKS_OPTION
  9311.     printf(" Telnet Kermit Option\n");
  9312.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9313. #endif /* IKS_OPTION */
  9314. #endif /* NETCONN */
  9315. #ifdef CK_AUTHENTICATION
  9316.     printf(" Telnet Authentication Option\n");
  9317.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9318. #ifdef CK_KERBEROS
  9319. #ifdef KRB4
  9320. #ifdef KRB5
  9321.     printf(" Kerberos(TM) IV and Kerberos V authentication\n");
  9322.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9323. #else /* KRB5 */
  9324.     printf(" Kerberos(TM) IV authentication\n");
  9325.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9326. #endif /* KRB5 */
  9327. #else /* KRB4 */
  9328. #ifdef KRB5
  9329.     printf(" Kerberos(TM) V authentication\n");
  9330.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9331. #endif /* KRB5 */
  9332. #endif /* KRB4 */
  9333. #endif /* CK_KERBEROS */
  9334. #ifdef CK_SRP
  9335.     printf(" SRP(TM) (Secure Remote Password) authentication\n");
  9336.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9337. #endif /* CK_SRP */
  9338. #ifdef CK_SSL
  9339.     printf(" Secure Sockets Layer (SSL)\n");
  9340.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9341.     printf(" Transport Layer Security (TLS)\n");
  9342.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9343. #endif /* CK_SSL */
  9344. #ifdef CK_ENCRYPTION
  9345.     printf(" Telnet Encryption Option\n");
  9346.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9347. #ifdef CK_DES
  9348.     printf(" DES Encryption\n");
  9349.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9350. #endif /* CK_DES */
  9351. #ifdef CK_CAST
  9352.     printf(" CAST Encryption\n");
  9353.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9354. #endif /* CK_CAST */
  9355. #endif /* CK_ENCRYPTION */
  9356. #endif /* CK_AUTHENTICATION */
  9357. #ifdef CK_FORWARD_X
  9358.     printf(" X Windows forwarding\n");
  9359.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9360. #endif /* CK_FORWARD_X */
  9361.  
  9362. #ifdef CK_RTSCTS
  9363.     printf(" Hardware flow control\n");
  9364.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9365. #endif /* CK_RTSCTS */
  9366.  
  9367. #ifdef CK_XYZ
  9368. #ifdef XYZ_INTERNAL
  9369.     printf(" Built-in XYZMODEM protocols\n");
  9370. #else
  9371.     printf(" External XYZMODEM protocol support\n");
  9372. #endif /* XYZ_INTERNAL */
  9373.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9374. #endif /* CK_XYZ */
  9375.  
  9376. #ifndef NOCSETS
  9377.     printf(" Latin-1 (West European) character-set translation\n");
  9378.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9379. #ifdef LATIN2
  9380.     printf(" Latin-2 (East European) character-set translation\n");
  9381.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9382. #endif /* LATIN2 */
  9383. #ifdef CYRILLIC
  9384.     printf(" Cyrillic (Russian, Ukrainian, etc) character-set translation\n");
  9385.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9386. #endif /* CYRILLIC */
  9387. #ifdef GREEK
  9388.     printf(" Greek character-set translation\n");
  9389.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9390. #endif /* GREEK */
  9391. #ifdef HEBREW
  9392.     printf(" Hebrew character-set translation\n");
  9393.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9394. #endif /* HEBREW */
  9395. #ifdef KANJI
  9396.     printf(" Japanese character-set translation\n");
  9397.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9398. #endif /* KANJI */
  9399. #ifdef UNICODE
  9400.     printf(" Unicode character-set translation\n");
  9401.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9402. #endif /* UNICODE */
  9403. #ifdef CKOUNI
  9404.     if (isunicode())
  9405.       printf(" Unicode support for ISO-2022 Terminal Emulation\n");
  9406.     else
  9407.       printf(" Unicode translation for Terminal Character-Sets\n");
  9408.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9409. #endif /* CKOUNI */
  9410. #endif /* NOCSETS */
  9411.  
  9412. #ifdef NETPTY
  9413.     printf(" Pseudoterminal control\n");
  9414.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9415. #endif /* NETPTY */
  9416.  
  9417. #ifdef CK_REDIR
  9418.     printf(" REDIRECT command\n");
  9419.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9420. #endif /* CK_REDIR */
  9421.  
  9422. #ifdef CK_RESEND
  9423.     printf(" RESEND command\n");
  9424.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9425. #endif /* CK_RESEND */
  9426.  
  9427. #ifdef CK_CURSES
  9428.     printf(" Fullscreen file transfer display\n");
  9429.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9430. #endif /* CK_CURSES */
  9431.  
  9432. #ifdef CK_SPEED
  9433.     printf(" Control-character unprefixing\n");
  9434.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9435. #endif /* CK_SPEED */
  9436.  
  9437. #ifdef STREAMING
  9438.     printf(" Streaming\n");
  9439.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9440. #endif /* STREAMING */
  9441.  
  9442. #ifdef CK_AUTODL
  9443.     printf(" Autodownload\n");
  9444.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9445. #endif /* CK_AUTODL */
  9446.  
  9447. #ifdef OS2MOUSE
  9448.     printf(" Mouse support\n");
  9449.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9450. #endif /* OS2MOUSE */
  9451.  
  9452. #ifdef CK_REXX
  9453.     printf(" REXX script language interface\n");
  9454.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9455. #endif /* CK_REXX */
  9456.  
  9457.     printf("\n");
  9458.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9459.     printf("Major optional features not included:\n");
  9460.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9461.  
  9462. #ifdef NOXFER
  9463.     printf(" No file-transfer protocols\n");
  9464.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9465.     flag = 1;
  9466. #else
  9467. #ifndef CK_CURSES
  9468. #ifndef MAC
  9469.     printf(" No fullscreen file transfer display\n");
  9470.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9471.     flag = 1;
  9472. #endif /* MAC */
  9473. #endif /* CK_CURSES */
  9474.  
  9475. #ifdef NOSERVER
  9476.     printf(" No server mode\n");
  9477.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9478.     flag = 1;
  9479. #endif /* NOSERVER */
  9480.  
  9481. #ifndef CK_SPEED
  9482.     printf(" No control-character unprefixing\n");
  9483.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9484.     flag = 1;
  9485. #endif /* CK_SPEED */
  9486.  
  9487. #ifndef STREAMING
  9488.     printf(" No streaming\n");
  9489.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9490.     flag = 1;
  9491. #endif /* STREAMING */
  9492.  
  9493. #ifndef CK_AUTODL
  9494.     printf(" No autodownload\n");
  9495.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9496.     flag = 1;
  9497. #endif /* CK_AUTODL */
  9498.  
  9499. #ifndef CK_XYZ
  9500.     printf(" No built-in XYZMODEM protocols\n");
  9501.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9502.     flag = 1;
  9503. #endif /* CK_XYZ */
  9504.  
  9505. #ifdef NOTLOG
  9506.     printf(" No transaction log\n");
  9507.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9508.     flag = 1;
  9509. #endif /* NOTLOG */
  9510. #endif /* NOXFER */
  9511.  
  9512. #ifdef NODEBUG
  9513.     printf(" No debugging\n");
  9514.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9515.     flag = 1;
  9516. #endif /* NODEBUG */
  9517.  
  9518. #ifdef NOHELP
  9519.     printf(" No built-in help\n");
  9520.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9521.     flag = 1;
  9522. #endif /* NOHELP */
  9523.  
  9524. #ifdef NOLOCAL
  9525.     printf(" No making connections\n");
  9526.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9527.     flag = 1;
  9528. #else
  9529. #ifndef NETCONN
  9530.     printf(" No network support\n");
  9531.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9532.     flag = 1;
  9533. #else /* NETCONN */
  9534. #ifndef IKS_OPTION
  9535.     printf(" No Telnet Kermit Option\n");
  9536.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9537.     flag = 1;
  9538. #endif /* IKS_OPTION */
  9539. #endif /* NETCONN */
  9540.  
  9541. #ifndef CK_AUTHENTICATION
  9542.     printf(" No Kerberos(TM) authentication\n");
  9543.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9544.     printf(" No SRP(TM) (Secure Remote Password) protocol\n");
  9545.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9546.     printf(" No Secure Sockets Layer (SSL) protocol\n");
  9547.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9548.     printf(" No Transport Layer Security (TLS) protocol\n");
  9549.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9550.     printf(" No encryption\n");
  9551.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9552.     flag = 1;
  9553. #else /* CK_AUTHENTICATION */
  9554. #ifndef CK_KERBEROS
  9555.     printf(" No Kerberos(TM) authentication\n");
  9556.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9557.     flag = 1;
  9558. #else /* CK_KERBEROS */
  9559. #ifndef KRB4
  9560.     printf(" No Kerberos(TM) IV authentication\n");
  9561.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9562.     flag = 1;
  9563. #endif /* KRB4 */
  9564. #ifndef KRB5
  9565.     printf(" No Kerberos(TM) V authentication\n");
  9566.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9567.     flag = 1;
  9568. #endif /* KRB5 */
  9569. #endif /* CK_KERBEROS */
  9570. #ifndef CK_SRP
  9571.     printf(" No SRP(TM) (Secure Remote Password) authentication\n");
  9572.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9573.     flag = 1;
  9574. #endif /* CK_SRP */
  9575. #ifndef CK_SSL
  9576.     printf(" No Secure Sockets Layer (SSL) protocol\n");
  9577.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9578.     printf(" No Transport Layer Security (TLS) protocol\n");
  9579.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9580.     flag = 1;
  9581. #endif /* CK_SSL */
  9582. #ifndef CK_ENCRYPTION
  9583.     printf(" No encryption\n");
  9584.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9585.     flag = 1;
  9586. #else /* CK_ENCRYPTION */
  9587. #ifndef OS2
  9588. #ifndef CK_DES
  9589.     printf(" No DES encryption\n");
  9590.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9591.     flag = 1;
  9592. #endif /* CK_DES */
  9593. #ifndef CK_CAST
  9594.     printf(" No CAST encryption\n");
  9595.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9596.     flag = 1;
  9597. #endif /* CK_CAST */
  9598. #endif /* OS2 */
  9599. #endif /* CK_ENCRYPTION */
  9600. #endif /* CK_AUTHENTICATION */
  9601. #ifndef CK_FORWARD_X
  9602.     printf(" No X Windows forwarding\n");
  9603.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9604. #endif /* CK_FORWARD_X */
  9605.  
  9606. #ifdef NODIAL
  9607.     printf(" No DIAL command\n");
  9608.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9609.     flag = 1;
  9610. #else
  9611. #ifdef MINIDIAL
  9612.     printf(" Support for most modem types excluded\n");
  9613.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9614.     flag = 1;
  9615. #endif /* MINIDIAL */
  9616. #endif /* NODIAL */
  9617. #endif /* NOLOCAL */
  9618.  
  9619. #ifndef CK_RTSCTS
  9620. #ifndef MAC
  9621.     printf(" No hardware flow control\n");
  9622.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9623.     flag = 1;
  9624. #endif /* MAC */
  9625. #endif /* CK_RTSCTS */
  9626.  
  9627. #ifdef NOXMIT
  9628.     printf(" No TRANSMIT command\n");
  9629.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9630.     flag = 1;
  9631. #endif /* NOXMIT */
  9632.  
  9633. #ifdef NOSCRIPT
  9634.     printf(" No SCRIPT command\n");
  9635.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9636.     flag = 1;
  9637. #endif /* NOSCRIPT */
  9638.  
  9639. #ifdef NOSPL
  9640.     printf(" No script programming features\n");
  9641.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9642.     flag = 1;
  9643. #endif /* NOSPL */
  9644.  
  9645. #ifdef NOCSETS
  9646.     printf(" No character-set translation\n");
  9647.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9648.     flag = 1;
  9649. #else
  9650.  
  9651. #ifndef LATIN2
  9652.     printf(" No Latin-2 character-set translation\n");
  9653.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9654.     flag = 1;
  9655. #endif /* LATIN2 */
  9656.  
  9657. #ifdef NOGREEK
  9658.     printf(" No Greek character-set translation\n");
  9659.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9660.     flag = 1;
  9661. #endif /* NOGREEK */
  9662.  
  9663. #ifdef NOHEBREW
  9664.     printf(" No Hebrew character-set translation\n");
  9665.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9666.     flag = 1;
  9667. #endif /* NOHEBREW */
  9668.  
  9669. #ifdef NOUNICODE
  9670.     printf(" No Unicode character-set translation\n");
  9671.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9672.     flag = 1;
  9673. #endif /* NOUNICODE */
  9674.  
  9675. #ifdef NOCYRIL
  9676.     printf(" No Cyrillic character-set translation\n");
  9677.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9678.     flag = 1;
  9679. #endif /* NOCYRIL */
  9680.  
  9681. #ifndef KANJI
  9682.     printf(" No Kanji character-set translation\n");
  9683.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9684.     flag = 1;
  9685. #endif /* KANJI */
  9686. #endif /* NOCSETS */
  9687.  
  9688. #ifdef NOCMDL
  9689.     printf(" No command-line arguments\n");
  9690.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9691.     flag = 1;
  9692. #endif /* NOCMDL */
  9693.  
  9694. #ifdef NOPUSH
  9695.     printf(" No escape to system\n");
  9696.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9697.     flag = 1;
  9698. #endif /* NOPUSH */
  9699.  
  9700. #ifdef NOJC
  9701. #ifdef UNIX
  9702.     printf(" No UNIX job control\n");
  9703.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9704.     flag = 1;
  9705. #endif /* UNIX */
  9706. #endif /* NOJC */
  9707.  
  9708. #ifdef NOSETKEY
  9709.     printf(" No SET KEY command\n");
  9710.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9711.     flag = 1;
  9712. #endif /* NOSETKEY */
  9713.  
  9714. #ifndef CK_REDIR
  9715.     printf(" No REDIRECT or PIPE command\n");
  9716.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9717.     flag = 1;
  9718. #endif /* CK_REDIR */
  9719.  
  9720. #ifndef NETPTY
  9721.     printf(" No pseudoterminal control\n");
  9722.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9723. #endif /* NETPTY */
  9724.  
  9725. #ifndef CK_RESEND
  9726.     printf(" No RESEND command\n");
  9727.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9728.     flag = 1;
  9729. #endif /* CK_RESEND */
  9730.  
  9731. #ifdef OS2
  9732. #ifdef __32BIT__
  9733. #ifndef OS2MOUSE
  9734.     printf(" No Mouse support\n");
  9735.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9736.     flag = 1;
  9737. #endif /* __32BIT__ */
  9738. #endif /* OS2 */
  9739. #endif /* OS2MOUSE */
  9740.  
  9741. #ifdef OS2
  9742. #ifndef NT
  9743. #ifndef CK_REXX
  9744.     printf(" No REXX script language interface\n");
  9745.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9746.     flag = 1;
  9747. #endif /* CK_REXX */
  9748. #endif /* NT */
  9749. #endif /* OS2 */
  9750.  
  9751.     if (flag == 0) {
  9752.     printf(" None\n");
  9753.     if (++lines > cmd_rows - 3)
  9754.       { if (!askmore()) return(1); else lines = 0; }
  9755.     }
  9756.  
  9757. #ifdef CK_UTSNAME
  9758.     printf("\n");
  9759.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9760.     printf("Host info:\n");
  9761.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9762.     printf(" Machine:    %s\n",unm_mch[0] ? unm_mch : "(unknown)");
  9763.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9764.     printf(" Model:      %s\n",unm_mod[0] ? unm_mod : "(unknown)");
  9765.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9766.     printf(" OS:         %s\n",unm_nam[0] ? unm_nam : "(unknown)");
  9767.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9768.     printf(" OS Release: %s\n",unm_rel[0] ? unm_rel : "(unknown)");
  9769.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9770.     printf(" OS Version: %s\n",unm_ver[0] ? unm_ver : "(unknown)");
  9771.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9772. #endif /* CK_UTSNAME */
  9773. /*
  9774.   Print compile-time (-D) options, as well as C preprocessor
  9775.   predefined symbols that might affect us...
  9776. */
  9777. #ifdef KTARGET
  9778.     {
  9779.     char * s;            /* Makefile target */
  9780.     s = KTARGET;
  9781.     if (!s) s = "";
  9782.     if (!*s) s = "(unknown)";
  9783.     printf("\n");
  9784.     if (++lines > cmd_rows - 3) {
  9785.         if (!askmore()) return(1); else lines = 0;
  9786.     }
  9787.     printf("Target: %s\n", s);
  9788.     if (++lines > cmd_rows - 3) {
  9789.         if (!askmore()) return(1); else lines = 0;
  9790.     }
  9791.     }
  9792. #endif /* KTARGET */
  9793.  
  9794. #ifdef __VERSION__
  9795. #ifdef __GNUC__
  9796.     printf("GCC version: %s\n", __VERSION__);
  9797. #else
  9798.     printf("Compiler version: %s\n", __VERSION__);
  9799. #endif /* __GNUC__ */
  9800.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9801. #endif /* __VERSION__ */
  9802.  
  9803. #ifdef __DATE__                /* GNU and other ANSI */
  9804. #ifdef __TIME__
  9805.     printf("Compiled %s %s, options:\n", __DATE__, __TIME__);
  9806. #else
  9807.     printf("Compiled %s, options:\n", __DATE__);
  9808. #endif /* __TIME__ */
  9809. #else /* !__DATE__ */
  9810.     printf("Compiler options:\n");
  9811. #endif /* __DATE__ */
  9812.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  9813.  
  9814.     for (i = 0; i < noptlist; i++)    /* Print sorted option list */
  9815.       if (!prtopt(&lines,optlist[i]))
  9816.     return(0);
  9817.  
  9818.     if (!prtopt(&lines,"")) return(0);    /* Start a new section */
  9819.  
  9820. /* Sizes of data types */
  9821.  
  9822.     sprintf(line,"byte order: %s endian", byteorder ? "little" : "big");
  9823.     if (!prtopt(&lines,line)) return(0);
  9824.     if (!prtopt(&lines,"")) return(0);    /* Start a new section */
  9825.     sprintf(line,"sizeofs: int=%ld",sizeof(int));
  9826.     if (!prtopt(&lines,line)) return(0);
  9827.     sprintf(line,"long=%ld",sizeof(long));
  9828.     if (!prtopt(&lines,line)) return(0);
  9829.     sprintf(line,"short=%ld",sizeof(short));
  9830.     if (!prtopt(&lines,line)) return(0);
  9831.     sprintf(line,"char=%ld",sizeof(char));
  9832.     if (!prtopt(&lines,line)) return(0);
  9833.     sprintf(line,"char*=%ld",sizeof(char *));
  9834.     if (!prtopt(&lines,line)) return(0);
  9835. #ifdef LONG_MAX
  9836.     sprintf(line,"LONG_MAX=%d",LONG_MAX);
  9837. #endif /* LONG_MAX */
  9838. #ifdef CKFLOAT
  9839.     sprintf(line,"float=%ld",sizeof(float));
  9840.     if (!prtopt(&lines,line)) return(0);
  9841.     sprintf(line,"double=%ld",sizeof(double));
  9842.     if (!prtopt(&lines,line)) return(0);
  9843. #ifdef FNFLOAT
  9844.     if (!prtopt(&lines,"")) return(0);    /* Start a new section */
  9845.     if (!prtopt(&lines,"floating-point:")) return(0);
  9846.     sprintf(line,"precision=%d",fp_digits);
  9847.     if (!prtopt(&lines,line)) return(0);
  9848.     sprintf(line,"rounding=%d",fp_rounding);
  9849.     if (!prtopt(&lines,line)) return(0);
  9850. #endif /* FNFLOAT */
  9851. #endif /* CKFLOAT */
  9852.  
  9853.     prtopt(&lines,"");
  9854.     return(0);
  9855. }
  9856. #endif /* NOSHOW */
  9857. #endif /* NOICP */
  9858.