home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku200.tar / ckuus5.c < prev    next >
C/C++ Source or Header  |  2001-12-08  |  315KB  |  11,460 lines

  1. #include "ckcsym.h"
  2.  
  3. int xcmdsrc = 0;
  4.  
  5. #ifdef NOICP
  6. int cmdsrc() { return(0); }
  7. #endif /* 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, 2001,
  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.  
  28. #ifdef DCMDBUF
  29. char *line;                /* Character buffer for anything */
  30. char *tmpbuf;
  31. #else
  32. char line[LINBUFSIZ+1];
  33. char tmpbuf[TMPBUFSIZ+1];        /* Temporary buffer */
  34. #endif /* DCMDBUF */
  35.  
  36. #ifndef NOICP
  37.  
  38. #include "ckcnet.h"
  39. #ifndef NOCSETS
  40. #include "ckcxla.h"
  41. #endif /* NOCSETS */
  42. #ifdef MAC
  43. #include "ckmasm.h"
  44. #endif /* MAC */
  45. #ifdef CK_SSL
  46. #include "ck_ssl.h"
  47. #endif /* CK_SSL */
  48.  
  49. #ifdef OS2
  50. #include "ckoetc.h"
  51. #ifndef NT
  52. #define INCL_NOPM
  53. #define INCL_VIO /* Needed for ckocon.h */
  54. #include <os2.h>
  55. #undef COMMENT
  56. #else /* NT */
  57. #include <windows.h>
  58. #define TAPI_CURRENT_VERSION 0x00010004
  59. #include <tapi.h>
  60. #include <mcx.h>
  61. #include "ckntap.h"
  62. #define APIRET ULONG
  63. extern int DialerHandle;
  64. extern int StartedFromDialer;
  65. #endif /* NT */
  66. #include "ckocon.h"
  67. #include "ckokey.h"
  68. #ifdef putchar
  69. #undef putchar
  70. #endif /* putchar */
  71. #define putchar(x) conoc(x)
  72. extern int cursor_save ;
  73. extern bool cursorena[] ;
  74. #endif /* OS2 */
  75.  
  76. /* For formatted screens, "more?" prompting, etc. */
  77.  
  78. #ifdef FT18
  79. #define isxdigit(c) isdigit(c)
  80. #endif /* FT18 */
  81.  
  82. #ifdef STRATUS                /* Stratus Computer, Inc.  VOS */
  83. #ifdef putchar
  84. #undef putchar
  85. #endif /* putchar */
  86. #define putchar(x) conoc(x)
  87. #ifdef getchar
  88. #undef getchar
  89. #endif /* getchar */
  90. #define getchar(x) coninc(0)
  91. #endif /* STRATUS */
  92.  
  93. /* External variables */
  94.  
  95. extern int carrier, cdtimo, local, quiet, backgrd, bgset, sosi, suspend,
  96.   binary, escape, xargs, flow, cmdmsk, duplex, ckxech, seslog, what,
  97.   inserver, diractive, tlevel, cwdf, nfuncs, msgflg, remappd, hints, mdmtyp,
  98.   zincnt, cmask, rcflag, success, xitsta, pflag, tnlm, tn_nlm, xitwarn,
  99.   debses, xaskmore, parity, saveask, wasclosed, whyclosed, cdactive;
  100.  
  101. #ifndef NOMSEND
  102. extern int addlist;
  103. #endif /* NOMSEND */
  104.  
  105. #ifdef CK_SPEED
  106. extern int prefixing;
  107. #endif /* CK_SPEED */
  108.  
  109. extern int g_matchdot;
  110.  
  111. #ifdef RECURSIVE
  112. extern int recursive;
  113. #endif /* RECURSIVE */
  114. extern int xfiletype;
  115.  
  116. #ifdef IKSDCONF
  117. extern char * iksdconf;
  118. extern int iksdcf;
  119. #endif /* IKSDCONF */
  120.  
  121. #ifdef CK_RECALL
  122. extern int on_recall;
  123. #endif /* CK_RECALL */
  124.  
  125. extern int ngetpath, exitonclose;
  126. extern char * getpath[];
  127. extern CHAR * epktmsg;
  128.  
  129. extern char * snd_move;
  130. extern char * snd_rename;
  131. extern char * rcv_move;
  132. extern char * rcv_rename;
  133. extern char * g_snd_move;
  134. extern char * g_snd_rename;
  135. extern char * g_rcv_move;
  136. extern char * g_rcv_rename;
  137.  
  138. extern char * nm[];
  139.  
  140. #ifdef CK_UTSNAME
  141. extern char unm_mch[];
  142. extern char unm_mod[];
  143. extern char unm_nam[];
  144. extern char unm_rel[];
  145. extern char unm_ver[];
  146. #endif /* CK_UTSNAME */
  147.  
  148. #ifndef NOPUSH
  149. #ifndef NOFRILLS
  150. extern char editor[];
  151. extern char editfile[];
  152. extern char editopts[];
  153. #ifdef BROWSER
  154. extern char browser[];
  155. extern char browsopts[];
  156. extern char browsurl[];
  157. #endif /* BROWSER */
  158. #endif /*  NOFRILLS */
  159. #endif /* NOPUSH */
  160.  
  161. #ifndef NOSERVER
  162. extern char * x_user, * x_passwd, * x_acct;
  163. #endif /* NOSERVER */
  164.  
  165. #ifdef CKLOGDIAL
  166. extern int dialog;
  167. extern char diafil[];
  168. #endif /* CKLOGDIAL */
  169.  
  170. #ifdef CKROOT
  171. extern int ckrooterr;
  172. #endif /* CKROOT */
  173.  
  174. #ifndef NOSPL
  175. extern int cfilef, xxdot;
  176. extern char cmdfil[];
  177.  
  178. struct localvar * localhead[CMDSTKL];
  179. struct localvar * localtail = NULL;
  180. struct localvar * localnext = NULL;
  181.  
  182. _PROTOTYP( VOID shosexp, (void) );
  183. _PROTOTYP( static VOID shoinput, (void) );
  184. _PROTOTYP( static char gettok,   (void) );
  185. _PROTOTYP( static VOID factor,   (void) );
  186. _PROTOTYP( static VOID term,     (void) );
  187. _PROTOTYP( static VOID termp,    (void) );
  188. _PROTOTYP( static VOID exprp,    (void) );
  189. _PROTOTYP( static VOID expr,     (void) );
  190. _PROTOTYP( static VOID simple,   (void) );
  191. _PROTOTYP( static VOID simpler,  (void) );
  192. _PROTOTYP( static VOID simplest, (void) );
  193. _PROTOTYP( static long xparse,   (void) );
  194. #endif /* NOSPL */
  195. #ifndef NOSHOW
  196. _PROTOTYP( int sho_iks, (void) );
  197. #endif /* NOSHOW */
  198.  
  199. #ifdef MAC
  200. char * ckprompt = "Mac-Kermit>";    /* Default prompt for Macintosh */
  201. char * ikprompt = "IKSD>";
  202. #else  /* Not MAC */
  203. #ifdef NOSPL
  204. #ifdef OS2
  205. char * ckprompt = "K-95> ";        /* Default prompt for Win32 */
  206. char * ikprompt = "IKSD> ";
  207. #else
  208. char * ckprompt = "C-Kermit>";
  209. char * ikprompt = "IKSD>";
  210. #endif /* NT */
  211. #else  /* NOSPL */
  212. #ifdef OS2
  213. /* Default prompt for OS/2 and Win32 */
  214. char * ckprompt = "[\\freplace(\\v(dir),/,\\\\)] K-95> ";
  215. char * ikprompt = "[\\freplace(\\v(dir),/,\\\\)] IKSD> ";
  216. #else
  217. #ifdef VMS
  218. char * ckprompt = "\\v(dir) C-Kermit>";    /* Default prompt VMS */
  219. char * ikprompt = "\\v(dir) IKSD>";
  220. #else
  221. char * ckprompt = "(\\v(dir)) C-Kermit>"; /* Default prompt for others */
  222. char * ikprompt = "(\\v(dir)) IKSD>";
  223. #endif /* VMS */
  224. #endif /* NT */
  225. #endif /* NOSPL */
  226. #endif /* MAC */
  227.  
  228. #ifndef CCHMAXPATH
  229. #define CCHMAXPATH 257
  230. #endif /* CCHMAXPATH */
  231. char inidir[CCHMAXPATH] = { NUL, NUL };    /* Directory INI file executed from */
  232.  
  233. #ifdef TNCODE
  234. extern int tn_b_nlm;            /* TELNET BINARY newline mode */
  235. #endif /* TNCODE */
  236.  
  237. #ifndef NOKVERBS
  238. extern struct keytab kverbs[];        /* Table of \Kverbs */
  239. extern int nkverbs;            /* Number of \Kverbs */
  240. #endif /* NOKVERBS */
  241.  
  242. #ifndef NOPUSH
  243. extern int nopush;
  244. #endif /* NOPUSH */
  245.  
  246. #ifdef CK_RECALL
  247. extern int cm_recall;
  248. #endif /* CK_RECALL */
  249.  
  250. extern char *ccntab[];
  251.  
  252. /* Printer stuff */
  253.  
  254. extern char *printername;
  255. extern int printpipe;
  256. #ifdef BPRINT
  257. extern int printbidi, pportparity, pportflow;
  258. extern long pportspeed;
  259. #endif /* BPRINT */
  260.  
  261. #ifdef OS2
  262. _PROTOTYP (int os2getcp, (void) );
  263. _PROTOTYP (int os2getcplist, (int *, int) );
  264. #ifdef OS2MOUSE
  265. extern int tt_mouse;
  266. #endif /* OS2MOUSE */
  267. extern int tt_update, tt_updmode, updmode;
  268. #ifndef IKSDONLY
  269. extern int tt_status[];
  270. #endif /* IKSDONLY */
  271. #ifdef PCFONTS
  272. extern struct keytab term_font[];
  273. #else
  274. #ifdef KUI
  275. extern struct keytab * term_font;
  276. #endif /* KUI */
  277. #endif /* PCFONTS */
  278. extern int ntermfont, tt_font, tt_font_size;
  279. extern unsigned char colornormal, colorunderline, colorstatus,
  280.     colorhelp, colorselect, colorborder, colorgraphic, colordebug,
  281.     colorreverse, colorcmd;
  282. extern int priority;
  283. extern struct keytab prtytab[];
  284. extern int nprty;
  285. char * cmdmac = NULL;
  286. #endif /* OS2 */
  287.  
  288. #ifdef VMS
  289. _PROTOTYP (int zkermini, (char *, int, char *) );
  290. #endif /* VMS */
  291.  
  292. extern long vernum;
  293. extern int inecho, insilence, inbufsize, nvars, inintr;
  294. extern char *protv, *fnsv, *cmdv, *userv, *ckxv, *ckzv, *ckzsys, *xlav,
  295.  *cknetv, *clcmds;
  296. #ifdef CK_AUTHENTICATION
  297. extern char * ckathv;
  298. #endif /* CK_AUTHENTICATION */
  299. #ifdef CK_SSL
  300. extern char * cksslv;
  301. #endif /* CK_SSL */
  302. #ifdef CK_ENCRYPTION
  303. #ifndef CRYPT_DLL
  304. extern char * ckcrpv;
  305. #endif /* CRYPT_DLL */
  306. #endif /* CK_ENCRYPTION */
  307.  
  308. #ifdef TNCODE
  309. extern char *cktelv;
  310. #endif /* TNCODE */
  311. #ifndef NOFTP
  312. #ifndef SYSFTP
  313. extern char * ckftpv;
  314. #endif /* SYSFTP */
  315. #endif /* NOFTP */
  316.  
  317. extern int srvidl;
  318.  
  319. #ifdef OS2
  320. extern char *ckonetv;
  321. extern int interm;
  322. #ifdef CK_NETBIOS
  323. extern char *ckonbiv;
  324. #endif /* CK_NETBIOS */
  325. #ifdef OS2MOUSE
  326. extern char *ckomouv;
  327. #endif /* OS2MOUSE */
  328. #endif /* OS2 */
  329.  
  330. #ifndef NOLOCAL
  331. extern char *connv;
  332. #endif /* NOLOCAL */
  333. #ifndef NODIAL
  334. extern char *dialv;
  335. #endif /* NODIAL */
  336. #ifndef NOSCRIPT
  337. extern char *loginv;
  338. extern int secho;
  339. #endif /* NOSCRIPT */
  340.  
  341. #ifndef NODIAL
  342. extern int nmdm, dirline;
  343. extern struct keytab mdmtab[];
  344. #endif /* NODIAL */
  345.  
  346. extern int network, ttnproto;
  347.  
  348. #ifdef OS2
  349. #ifndef NOTERM
  350. /* SET TERMINAL items... */
  351. extern int tt_type, tt_arrow, tt_keypad, tt_wrap, tt_answer, tt_scrsize[];
  352. extern int tt_bell, tt_roll[], tt_ctstmo, tt_cursor, tt_pacing, tt_type_mode;
  353. extern char answerback[];
  354. extern struct tt_info_rec tt_info[];    /* Indexed by terminal type */
  355. extern int max_tt;
  356. #endif /* NOTERM */
  357. #endif /* OS2 */
  358.  
  359. _PROTOTYP( VOID shotrm, (void) );
  360. _PROTOTYP( int shofea, (void) );
  361.  
  362. #ifdef OS2
  363. extern int tt_rows[], tt_cols[];
  364. #else /* OS2 */
  365. extern int tt_rows, tt_cols;
  366. #endif /* OS2 */
  367. extern int cmd_rows, cmd_cols;
  368.  
  369. #ifdef CK_TMPDIR
  370. extern int f_tmpdir;            /* Directory changed temporarily */
  371. extern char savdir[];            /* Temporary directory */
  372. #endif /* CK_TMPDIR */
  373.  
  374. #ifndef NOLOCAL
  375. extern int tt_crd, tt_escape;
  376. #endif /* NOLOCAL */
  377.  
  378. #ifndef NOCSETS
  379. extern int language, nfilc, tcsr, tcsl, tcs_transp, fcharset;
  380. extern struct keytab fcstab[];
  381. extern struct csinfo fcsinfo[];
  382. #ifndef MAC
  383. extern struct keytab ttcstab[];
  384. #endif /* MAC */
  385. #endif /* NOCSETS */
  386.  
  387. extern long speed;
  388.  
  389. #ifndef NOXMIT
  390. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  391. extern char xmitbuf[];
  392. #endif /* NOXMIT */
  393.  
  394. extern char **xargv, *versio, *ckxsys, *dftty, *lp;
  395.  
  396. #ifdef DCMDBUF
  397. extern char *cmdbuf, *atmbuf;        /* Command buffers */
  398. #ifndef NOSPL
  399. extern char *savbuf;            /* Command buffers */
  400. #endif /* NOSPL */
  401. #else
  402. extern char cmdbuf[], atmbuf[];        /* Command buffers */
  403. #ifndef NOSPL
  404. extern char savbuf[];            /* Command buffers */
  405. #endif /* NOSPL */
  406. #endif /* DCMDBUF */
  407.  
  408. extern char toktab[], ttname[], psave[];
  409. extern CHAR sstate, feol;
  410. extern int cmflgs, techo, repars, ncmd;
  411. extern struct keytab cmdtab[];
  412.  
  413. #ifndef NOSETKEY
  414. KEY *keymap;
  415. #ifndef OS2
  416. #define mapkey(x) keymap[x]
  417. #endif /* OS2 */
  418. MACRO *macrotab;
  419. _PROTOTYP( VOID shostrdef, (CHAR *) );
  420. #endif /* NOSETKEY */
  421.  
  422. extern int cmdlvl;
  423.  
  424. #ifndef NOSPL
  425. extern struct mtab *mactab;
  426. extern struct keytab mackey[];
  427. extern struct keytab vartab[], fnctab[], iftab[];
  428. extern int maclvl, nmac, mecho, fndiags, fnerror, fnsuccess, nif;
  429. #endif /* NOSPL */
  430.  
  431. FILE *tfile[MAXTAKE];            /* TAKE file stack */
  432. char *tfnam[MAXTAKE];
  433. int tfline[MAXTAKE];
  434.  
  435. int topcmd = -1;            /* cmdtab index of current command */
  436. int havetoken = 0;
  437. extern int dblquo;            /* Doublequoting enabled */
  438.  
  439. #ifdef DCMDBUF                /* Initialization filespec */
  440. char *kermrc = NULL;
  441. #else
  442. char kermrcb[KERMRCL];
  443. char *kermrc = kermrcb;
  444. #endif /* DCMDBUF */
  445.  
  446. int noherald = 0;
  447. int cm_retry = 1;            /* Command retry enabled */
  448. xx_strp xxstring = zzstring;
  449.  
  450. #ifndef NOXFER
  451. extern int displa, bye_active, protocol, pktlog, remfile, rempipe, unkcs,
  452.   keep, lf_opts, fncnv, pktpaus, autodl, xfrcan, xfrchr, xfrnum, srvtim,
  453.   srvdis, query, retrans, streamed, reliable, crunched, timeouts,
  454.   fnrpath, autopath, rpackets, spackets, epktrcvd, srvping;
  455.  
  456. #ifdef CK_AUTODL
  457. extern int inautodl, cmdadl;
  458. #endif /* CK_AUTODL */
  459.  
  460. #ifndef NOSERVER
  461. extern int en_asg, en_cwd, en_cpy, en_del, en_dir, en_fin, en_bye, en_ret,
  462.   en_get, en_hos, en_que, en_ren, en_sen, en_set, en_spa, en_typ, en_who,
  463.   en_mai, en_pri, en_mkd, en_rmd, en_xit, en_ena;
  464. #endif /* NOSERVER */
  465.  
  466. extern int atcapr,
  467.   atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,
  468.   attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  469.  
  470. #ifdef STRATUS
  471. extern int atfrmi, atfrmo, atcrei, atcreo, atacti, atacto;
  472. #endif /* STRATUS */
  473.  
  474. #ifdef CK_PERMS
  475. extern int atlpri, atlpro, atgpri, atgpro;
  476. #endif /* CK_PERMS */
  477.  
  478. #ifdef CK_LOGIN
  479. extern char * anonfile;            /* Anonymous login init file */
  480. extern char * anonroot;            /* Anonymous file-system root */
  481. extern char * userfile;                 /* Forbidden user file */
  482. extern int isguest;            /* Flag for anonymous user */
  483. #endif /* CK_LOGIN */
  484. #endif /* NOXFER */
  485.  
  486. #ifdef DCMDBUF
  487. int *xquiet = NULL;
  488. #else
  489. int xquiet[CMDSTKL];
  490. #endif /* DCMDBUF */
  491.  
  492. char * prstring[CMDSTKL];
  493.  
  494. #ifndef NOSPL
  495.  
  496. extern long ck_alarm;
  497. extern char alrm_date[], alrm_time[];
  498.  
  499. /* Local declarations */
  500.  
  501. static int nulcmd = 0;            /* Flag for next cmd to be ignored */
  502.  
  503. /* Definitions for predefined macros */
  504.  
  505. /* First, the single-line macros, installed with addmac()... */
  506.  
  507. /* IBM-LINEMODE macro */
  508. char *m_ibm = "set parity mark, set dupl half, set handsh xon, set flow none";
  509.  
  510. /* FATAL macro */
  511. char *m_fat = "if def \\%1 echo \\%1, if not = \\v(local) 0 hangup, stop 1";
  512.  
  513. #ifdef CK_SPEED
  514. #ifdef IRIX65
  515. char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
  516. #else
  517. #ifdef IRIX
  518. /* Because of bug in telnet server */
  519. char *m_fast = "set window 30, set rec pack 4000, set send pack 4000,\
  520.  set pref cautious";
  521. #else
  522. #ifdef pdp11
  523. char *m_fast = "set win 3, set rec pack 1024, set prefix cautious";
  524. #else
  525. #ifdef BIGBUFOK
  526. char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
  527. #else
  528. char *m_fast = "set win 4, set rec pack 2200, set prefix cautious";
  529. #endif /* BIGBUFOK */
  530. #endif /* IRIX */
  531. #endif /* IRIX65 */
  532. #endif /* pdp11 */
  533. #ifdef pdp11
  534. char *m_cautious = "set win 2, set rec pack 512, set prefixing cautious";
  535. #else
  536. char *m_cautious = "set win 4, set rec pack 1000, set prefixing cautious";
  537. #endif /* pdp11 */
  538. char *m_robust = "set win 1, set rec pack 90, set prefixing all, \
  539. set reliable off, set clearchannel off";
  540. #else
  541. #ifdef BIGBUFOK
  542. #ifdef IRIX65
  543. char *m_fast = "set win 30, set rec pack 4000";
  544. #else
  545. #ifdef IRIX
  546. char *m_fast = "set win 30, set rec pack 4000, set send pack 4000";
  547. #else
  548. char *m_fast = "set win 30, set rec pack 4000";
  549. #endif /* IRIX */
  550. #endif /* IRIX65 */
  551. #else /* Not BIGBUFOK */
  552. char *m_fast = "set win 4, set rec pack 2200";
  553. #endif /* BIGBUFOK */
  554. char *m_cautious = "set win 4, set rec pack 1000";
  555. char *m_robust = "set win 1, set rec pack 90, set reliable off";
  556. #endif /* CK_SPEED */
  557.  
  558. #ifdef VMS
  559. char *m_purge = "run purge \\%*";
  560. #endif /* VMS */
  561.  
  562. #ifdef OS2
  563. char *m_manual = "browse \\v(exedir)docs/manual/kermit95.htm";
  564. #endif /* OS2 */
  565.  
  566. /* Now the multiline macros, defined with addmmac()... */
  567.  
  568. /* FOR macro for \%i-style loop variables (see dofor()...) */
  569.  
  570. char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
  571. "def \\\\\\%1 \\feval(\\%2),:_..top,if \\%5 \\\\\\%1 \\%3 goto _..bot,",
  572. "\\%6,:_..inc,incr \\\\\\%1 \\%4,goto _..top,:_..bot,_putargs},",
  573. "def break goto _..bot, def continue goto _..inc,",
  574. "do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
  575. ""};
  576.  
  577. /* This is the FOR macro when the loop variable is itself a macro */
  578.  
  579. char *foz_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
  580. "def \\%1 \\feval(\\%2),:_..top,if \\%5 \\%1 \\%3 goto _..bot,",
  581. "\\%6,:_..inc,incr \\%1 \\%4,goto _..top,:_..bot,_putargs},",
  582. "def break goto _..bot, def continue goto _..inc,",
  583. "do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
  584. ""};
  585.  
  586. /* WHILE macro */
  587. char *whil_def[] = { "_assign _whi\\v(cmdlevel) {_getargs,",
  588. ":_..inc,\\%1,\\%2,goto _..inc,:_..bot,_putargs},",
  589. "_def break goto _..bot, _def continue goto _..inc,",
  590. "do _whi\\v(cmdlevel),_assign _whi\\v(cmdlevel)",
  591. ""};
  592.  
  593. /* SWITCH macro */
  594. char *sw_def[] = { "_assign _sw_\\v(cmdlevel) {_getargs,",
  595. "_forward \\%1,\\%2,:default,:_..bot,_putargs},_def break goto _..bot,",
  596. "do _sw_\\v(cmdlevel),_assign _sw_\\v(cmdlevel)",
  597. ""};
  598.  
  599. /* XIF macro */
  600. char *xif_def[] = {
  601. "_assign _if\\v(cmdlevel) {_getargs,\\%1,_putargs},",
  602. "do _if\\v(cmdlevel),_assign _if\\v(cmdlevel)",
  603. ""};
  604.  
  605. /*
  606.   Variables declared here for use by other ckuus*.c modules.
  607.   Space is allocated here to save room in ckuusr.c.
  608. */
  609. #ifdef DCMDBUF
  610. struct cmdptr *cmdstk;
  611. int
  612.   *ifcmd  = NULL,
  613.   *count  = NULL,
  614.   *iftest = NULL,
  615.   *intime = NULL,
  616.   *inpcas = NULL,
  617.   *takerr = NULL,
  618.   *merror = NULL;
  619. #else
  620. struct cmdptr cmdstk[CMDSTKL];
  621. int ifcmd[CMDSTKL], count[CMDSTKL], iftest[CMDSTKL], intime[CMDSTKL],
  622.   inpcas[CMDSTKL], takerr[CMDSTKL], merror[CMDSTKL];
  623. #endif /* DCMDBUF */
  624.  
  625. /* Macro stack */
  626.  
  627. #ifdef COMMENT
  628. char *topline = NULL;            /* Program invocation arg line */
  629. char *m_line[MACLEVEL] = { NULL, NULL }; /* Stack of macro invocation lines */
  630. #endif /* COMMENT */
  631.  
  632. char **m_xarg[MACLEVEL];        /* Pointers to arg vector arrays */
  633. int n_xarg[MACLEVEL];            /* Sizes of arg vector arrays */
  634. char *m_arg[MACLEVEL][NARGS];        /* Args of each level */
  635. int macargc[MACLEVEL];            /* Argc of each level */
  636. char *macp[MACLEVEL];            /* Current position in each macro */
  637. char *macx[MACLEVEL];            /* Beginning of each macro def */
  638. char *mrval[MACLEVEL];            /* RETURN value at each level */
  639. int lastcmd[MACLEVEL];            /* Last command at each level */
  640. int topargc = 0;            /* Argc at top level */
  641. char **topxarg = NULL;            /* Argv at top level */
  642. char *toparg[MAXARGLIST+2];
  643.  
  644. /* Global Variables */
  645.  
  646. char *g_var[GVARS+1];            /* Global \%a..z pointers */
  647. extern char varnam[];            /* \%x variable name buffer */
  648.  
  649. /* Arrays -- Dimension must be 'z' - ARRAYBASE + 1 */
  650. /* Note: a_link[x] < 0 means no link; >= 0 is a link */
  651.  
  652. char **a_ptr[32];            /* Array pointers, for arrays a-z */
  653. int a_dim[32];                /* Dimensions for each array */
  654. int a_link[32];                /* Link (index of linked-to-array) */
  655.  
  656. char **aa_ptr[CMDSTKL][32];        /* Array stack for automatic arrays */
  657. int aa_dim[CMDSTKL][32];        /* Dimensions for each array */
  658.  
  659. /* INPUT command buffers and variables */
  660.  
  661. char * inpbuf = NULL;            /* Buffer for INPUT and REINPUT */
  662. extern char * inpbp;            /* Global/static pointer to it  */
  663. char inchar[2] = { NUL, NUL };        /* Last character that was INPUT */
  664. int  incount = 0;            /* INPUT character count */
  665. extern int instatus;            /* INPUT status */
  666. static char * i_text[] = {        /* INPUT status text */
  667.     "success", "timeout", "interrupted", "internal error", "i/o error"
  668. };
  669.  
  670. char lblbuf[LBLSIZ];            /* Buffer for labels */
  671.  
  672. #else  /* NOSPL */
  673.  
  674. int takerr[MAXTAKE];
  675. #endif /* NOSPL */
  676.  
  677. static char *prevdir = NULL;
  678.  
  679. int pacing = 0;                /* OUTPUT pacing */
  680.  
  681. char *tp;                /* Temporary buffer pointer */
  682.  
  683. int timelimit = 0, asktimer = 0;    /* Timers for time-limited commands */
  684.  
  685. #ifdef CK_APC                /* Application Program Command (APC) */
  686. int apcactive = APC_INACTIVE;
  687. int apcstatus = APC_OFF;        /* OFF by default everywhere */
  688. #ifdef DCMDBUF
  689. char *apcbuf;
  690. #else
  691. char apcbuf[APCBUFLEN];
  692. #endif /* DCMDBUF */
  693. #endif /* CK_APC */
  694.  
  695. extern char pktfil[],
  696. #ifdef DEBUG
  697.   debfil[],
  698. #endif /* DEBUG */
  699. #ifdef TLOG
  700.   trafil[],
  701. #endif /* TLOG */
  702.   sesfil[];
  703.  
  704. #ifndef NOFRILLS
  705. extern int rmailf, rprintf;        /* REMOTE MAIL & PRINT items */
  706. extern char optbuf[];
  707. #endif /* NOFRILLS */
  708.  
  709. extern int noinit;
  710.  
  711. #ifndef NOSPL
  712. _PROTOTYP( VOID freelocal, (int) );
  713. _PROTOTYP( static long expon, (long, long) );
  714. _PROTOTYP( static long gcd, (long, long) );
  715. _PROTOTYP( static long fact, (long) );
  716.  
  717. int            /* Initialize macro data structures. */
  718. macini() {        /* Allocate mactab and preset the first element. */
  719.     int i;
  720.     if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX)))
  721.       return(-1);
  722.     mactab[0].kwd = NULL;
  723.     mactab[0].mval = NULL;
  724.     mactab[0].flgs = 0;
  725.     for (i = 0; i < MACLEVEL; i++)
  726.       localhead[i] = NULL;
  727.     return(0);
  728. }
  729. #endif /* NOSPL */
  730.  
  731. /*  C M D S R C  --  Returns current command source  */
  732.  
  733. /*  0 = top level, 1 = file, 2 = macro, -1 = error (shouldn't happen) */
  734.  
  735. /*
  736.   As of 19 Aug 2000 this routine is obsolete.  The scalar global variable
  737.   xcmdsrc can be checked instead to save the overhead of a function call.
  738. */
  739. int
  740. cmdsrc() {
  741. #ifdef COMMENT
  742.     return(xcmdsrc);
  743. #else
  744. #ifndef NOSPL
  745.     if (cmdlvl == 0)
  746.       return(0);
  747.     else if (cmdstk[cmdlvl].src == CMD_MD)
  748.       return(2);
  749.     else if (cmdstk[cmdlvl].src == CMD_TF)
  750.       return(1);
  751.     else
  752.       return(-1);
  753. #else
  754.     if (tlevel < 0)
  755.       return(0);
  756.     else
  757.       return(1);
  758. #endif /* NOSPL */
  759. #endif /* COMMENT */
  760. }
  761.  
  762. /*  C M D I N I  --  Initialize the interactive command parser  */
  763.  
  764. static int cmdinited = 0;        /* Command parser initialized */
  765. extern int cmdint;            /* Interrupts are allowed */
  766. #ifdef CK_AUTODL
  767. int cmdadl = 1;                /* Autodownload */
  768. #else
  769. int cmdadl = 0;
  770. #endif /* CK_AUTODL */
  771.  
  772. char * k_info_dir = NULL;        /* Where to find text files */
  773. #ifdef UNIX
  774. static char * txtdir[] = {
  775.     "/usr/local/doc/",            /* Linux, SunOS, ... */
  776.     "/usr/share/lib/",            /* HP-UX 10.xx... */
  777.     "/usr/share/doc/",            /* Other possibilities... */
  778.     "/usr/local/lib/",            /* NOTE: Each of these is tried */
  779.     "/usr/local/share/",        /* as is, and also with a kermit */
  780.     "/usr/local/share/doc/",        /* subdirectory. */
  781.     "/usr/local/share/lib/",
  782.     "/usr/doc/",
  783.     "/opt/",
  784.     "/doc/",
  785.     ""
  786. };
  787. #endif /* UNIX */
  788.  
  789. /*
  790.   lookup() cache to speed up script execution.
  791.  
  792.   This is a static cache.  Items are stored in decreasing frequency of
  793.   reference based on statistics from a range of scripts.  This gives
  794.   better performance than a dynamic cache, which would require a lot more
  795.   code and also would require system-dependent elements including system
  796.   calls (e.g. to get subsecond times for entry aging).
  797. */
  798. #ifdef USE_LUCACHE            /* Set in ckuusr.h */
  799. #define LUCACHE 32            /* Change this to reduce cache size */
  800. int lusize = 0;
  801. char * lucmd[LUCACHE];
  802. int luval[LUCACHE];
  803. int luidx[LUCACHE];
  804. struct keytab * lutab[LUCACHE];
  805. #endif /* USE_LUCACHE */
  806.  
  807. static VOID
  808. luinit() {                /* Initialize lookup() cache */
  809.     int x, y;
  810.  
  811. #ifdef USE_LUCACHE
  812.     x = lookup(cmdtab,"if",ncmd,&y);
  813.     lucmd[lusize] = "if";
  814.     luval[lusize] = x;
  815.     luidx[lusize] = y;
  816.     lutab[lusize] = cmdtab;
  817.     if (++lusize > LUCACHE) return;
  818.  
  819.     x = lookup(iftab,"not",nif,&y);
  820.     lucmd[lusize] = "not";
  821.     luval[lusize] = x;
  822.     luidx[lusize] = y;
  823.     lutab[lusize] = iftab;
  824.     if (++lusize > LUCACHE) return;
  825.  
  826.     x = lookup(vartab,"cmdlevel",nvars,&y);
  827.     lucmd[lusize] = "cmdlevel";
  828.     luval[lusize] = x;
  829.     luidx[lusize] = y;
  830.     lutab[lusize] = vartab;
  831.     if (++lusize > LUCACHE) return;
  832.  
  833.     x = lookup(cmdtab,"goto",ncmd,&y);
  834.     lucmd[lusize] = "goto";
  835.     luval[lusize] = x;
  836.     luidx[lusize] = y;
  837.     lutab[lusize] = cmdtab;
  838.     if (++lusize > LUCACHE) return;
  839.  
  840.     x = lookup(iftab,">",nif,&y);
  841.     lucmd[lusize] = ">";
  842.     luval[lusize] = x;
  843.     luidx[lusize] = y;
  844.     lutab[lusize] = iftab;
  845.     if (++lusize > LUCACHE) return;
  846.  
  847.     x = lookup(cmdtab,"incr",ncmd,&y);
  848.     lucmd[lusize] = "incr";
  849.     luval[lusize] = x;
  850.     luidx[lusize] = y;
  851.     lutab[lusize] = cmdtab;
  852.     if (++lusize > LUCACHE) return;
  853.  
  854.     x = lookup(cmdtab,"def",ncmd,&y);
  855.     lucmd[lusize] = "def";
  856.     luval[lusize] = x;
  857.     luidx[lusize] = y;
  858.     lutab[lusize] = cmdtab;
  859.     if (++lusize > LUCACHE) return;
  860.  
  861.     x = lookup(cmdtab,"_assign",ncmd,&y);
  862.     lucmd[lusize] = "_assign";
  863.     luval[lusize] = x;
  864.     luidx[lusize] = y;
  865.     lutab[lusize] = cmdtab;
  866.     if (++lusize > LUCACHE) return;
  867.  
  868.     x = lookup(cmdtab,"echo",ncmd,&y);
  869.     lucmd[lusize] = "echo";
  870.     luval[lusize] = x;
  871.     luidx[lusize] = y;
  872.     lutab[lusize] = cmdtab;
  873.     if (++lusize > LUCACHE) return;
  874.  
  875.     x = lookup(fnctab,"eval",nfuncs,&y);
  876.     lucmd[lusize] = "eval";
  877.     luval[lusize] = x;
  878.     luidx[lusize] = y;
  879.     lutab[lusize] = fnctab;
  880.     if (++lusize > LUCACHE) return;
  881.  
  882.     x = lookup(fnctab,"lit",nfuncs,&y);
  883.     lucmd[lusize] = "lit";
  884.     luval[lusize] = x;
  885.     luidx[lusize] = y;
  886.     lutab[lusize] = fnctab;
  887.     if (++lusize > LUCACHE) return;
  888.  
  889.     x = lookup(cmdtab,"do",ncmd,&y);
  890.     lucmd[lusize] = "do";
  891.     luval[lusize] = x;
  892.     luidx[lusize] = y;
  893.     lutab[lusize] = cmdtab;
  894.     if (++lusize > LUCACHE) return;
  895.  
  896.     x = lookup(cmdtab,"_getargs",ncmd,&y);
  897.     lucmd[lusize] = "_getargs";
  898.     luval[lusize] = x;
  899.     luidx[lusize] = y;
  900.     lutab[lusize] = cmdtab;
  901.     if (++lusize > LUCACHE) return;
  902.  
  903.     x = lookup(iftab,"<",nif,&y);
  904.     lucmd[lusize] = "<";
  905.     luval[lusize] = x;
  906.     luidx[lusize] = y;
  907.     lutab[lusize] = iftab;
  908.     if (++lusize > LUCACHE) return;
  909.  
  910.     x = lookup(cmdtab,"_putargs",ncmd,&y);
  911.     lucmd[lusize] = "_putargs";
  912.     luval[lusize] = x;
  913.     luidx[lusize] = y;
  914.     lutab[lusize] = cmdtab;
  915.     if (++lusize > LUCACHE) return;
  916.  
  917.     x = lookup(cmdtab,"asg",ncmd,&y);
  918.     lucmd[lusize] = "asg";
  919.     luval[lusize] = x;
  920.     luidx[lusize] = y;
  921.     lutab[lusize] = cmdtab;
  922.     if (++lusize > LUCACHE) return;
  923.  
  924.     x = lookup(cmdtab,"else",ncmd,&y);
  925.     lucmd[lusize] = "else";
  926.     luval[lusize] = x;
  927.     luidx[lusize] = y;
  928.     lutab[lusize] = cmdtab;
  929. #endif /* USE_LUCACHE */
  930. }
  931.  
  932. VOID
  933. cmdini() {
  934.     int i = 0, x = 0, y = 0, z = 0, skip = 0;
  935.     char * p;
  936. #ifdef TTSPDLIST
  937.     long * ss = NULL;
  938.     extern int nspd;
  939.     extern struct keytab * spdtab;
  940. #endif /* TTSPDLIST */
  941.  
  942. #ifndef NOSPL
  943. /*
  944.   On stack to allow recursion!
  945. */
  946.     char vnambuf[VNAML];        /* Buffer for variable names */
  947. #endif /* NOSPL */
  948.  
  949.     if (cmdinited)            /* Already initialized */
  950.       return;                /* Don't do it again */
  951.  
  952.     for (i = 0; i < CMDSTKL; i++)    /* Prompt strings for each */
  953.       prstring[i] = NULL;        /* command level */
  954.  
  955. #ifndef NOCSETS
  956.     p = getenv("K_CHARSET");        /* Set default file character set */
  957.     if (p) {                /* from environment */
  958.     x = lookup(fcstab,p,nfilc,&y);
  959.     if (x > -1)
  960.       fcharset = x;
  961.     }
  962. #endif /* NOCSETS */
  963.  
  964.     p = getenv("K_INFO_DIRECTORY");    /* Find Kermit info directory */
  965.     if (p && *p && strlen(p) <= CKMAXPATH)
  966.       makestr(&k_info_dir,p);
  967.     if (!k_info_dir) {
  968.         p = getenv("K_INFO_DIR");
  969.         if (p && *p && strlen(p) <= CKMAXPATH)
  970.       makestr(&k_info_dir,p);
  971.     }
  972. #ifdef UNIX
  973.     if (k_info_dir) {            /* Look for Kermit docs directory */
  974.     if (zchki(k_info_dir) == -2) {
  975.         char xbuf[CKMAXPATH+32], *s = "";
  976.         if (ckrchar(k_info_dir) != '/')
  977.           s = "/";
  978.         ckmakmsg(xbuf,CKMAXPATH+32,k_info_dir,s,"ckubwr.txt",NULL);
  979.         if (zchki(xbuf) < 0)
  980.           makestr(&k_info_dir,NULL);
  981.     }
  982.     }
  983.     if (!k_info_dir) {
  984.     char xbuf[CKMAXPATH+32];
  985.     int i;
  986.     for (i = 0; *(txtdir[i]); i++) {
  987.         ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"ckubwr.txt",NULL,NULL);
  988.         if (zchki(xbuf) > 0) {
  989.         makestr(&k_info_dir,txtdir[i]);
  990.         debug(F110,"k_info_dir 1",k_info_dir,0);
  991.         break;
  992.         }
  993.         ckmakmsg(xbuf,CKMAXPATH+32,
  994.              txtdir[i],"kermit/","ckubwr.txt",NULL);
  995.         if (zchki(xbuf) > 0) {
  996.         ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"kermit/",NULL,NULL);
  997.         makestr(&k_info_dir,xbuf);
  998.         debug(F110,"k_info_dir 2",k_info_dir,0);
  999.         break;
  1000.         }
  1001.     }
  1002.     if (k_info_dir) {        /* Make sure it ends with "/" */
  1003.         if (ckrchar(k_info_dir) != '/') {
  1004.         char xbuf[CKMAXPATH+32];
  1005.         ckmakmsg(xbuf,CKMAXPATH+32,k_info_dir,"/",NULL,NULL);
  1006.         makestr(&k_info_dir,xbuf);
  1007.         }
  1008.     }
  1009.     }
  1010. #else
  1011. #ifdef OS2
  1012.     {
  1013.     char xdir[CKMAXPATH+8], *s = "";
  1014.         extern char startupdir[];
  1015.     xdir[0] = NUL;
  1016.     if (ckrchar(startupdir) != '/')
  1017.       s = "/";
  1018.         if (strlen(s) + strlen(startupdir) + 5 < CKMAXPATH + 8 )
  1019.       ckmakmsg(xdir,CKMAXPATH+8,s,startupdir,"DOC/",NULL);
  1020.         makestr(&k_info_dir,xdir);
  1021.     }
  1022. #endif /* OS2 */
  1023. #endif /* UNIX */
  1024.  
  1025. #ifdef TTSPDLIST
  1026.     if (!spdtab && (ss = ttspdlist())) { /* Get speed list if necessary */
  1027.     int j, k, m = 0, n;        /* Create sorted keyword table */
  1028.     char buf[16];
  1029.     char * p;
  1030.     if ((spdtab =
  1031.          (struct keytab *) malloc(sizeof(struct keytab) * ss[0]))) {
  1032.         for (i = 1; i <= ss[0]; i++) { /* ss[0] = number of elements */
  1033.         if (ss[i] < 1L) break;       /* Shouldn't happen */
  1034.         buf[0] = NUL;           /* Make string */
  1035.         sprintf(buf,"%ld",ss[i]);  /* SAFE */
  1036.         if (ss[i] == 8880L)
  1037.           ckstrncpy(buf,"75/1200",sizeof(buf));
  1038.         if (ss[i] == 134L)
  1039.           ckstrncat(buf,".5",16);
  1040.         n = strlen(buf);
  1041.         if ((n > 0) && (p = (char *)malloc(n+1))) {
  1042.             if (m > 0) {    /* Have at least one in list */
  1043.             for (j = 0;    /* Find slot */
  1044.                  j < m && strcmp(buf,spdtab[j].kwd) > 0;
  1045.                  j++
  1046.                  )
  1047.               ;
  1048.             if (j < m) {    /* Must insert */
  1049.                 for (k = m-1; k >= j; k--) { /* Move others down */
  1050.                 spdtab[k+1].kwd = spdtab[k].kwd;
  1051.                 spdtab[k+1].flgs = spdtab[k].flgs;
  1052.                 spdtab[k+1].kwval = spdtab[k].kwval;
  1053.                 }
  1054.             }
  1055.             } else        /* First one */
  1056.               j = 0;
  1057.             ckstrncpy(p,buf,n+1); /* Add new speed */
  1058.             spdtab[j].kwd = p;
  1059.             spdtab[j].flgs = 0;
  1060.             spdtab[j].kwval = (int) ss[i] / 10;
  1061.             m++;        /* Count this one */
  1062.         }
  1063.         }
  1064.     }
  1065.     nspd = m;
  1066.     }
  1067. #endif /* TTSPDLIST */
  1068.  
  1069. #ifndef NOSPL
  1070.     /* Allocate INPUT command buffer */
  1071.     if (!inpbuf) {
  1072.     if (!(inpbuf = (char *) malloc(INPBUFSIZ+1)))
  1073.       fatal("cmdini: no memory for INPUT buffer");
  1074.     }
  1075.     for (x = 0; x < INPBUFSIZ; x++)    /* Initialize it */
  1076.       inpbuf[x] = NUL;
  1077.     inpbp = inpbuf;            /* Initialize pointer */
  1078.     inbufsize = INPBUFSIZ;        /* and size. */
  1079. #endif /* NOSPL */
  1080.  
  1081. #ifdef DCMDBUF
  1082.     if (cmsetup() < 0) fatal("Can't allocate command buffers!");
  1083.  
  1084. #ifndef NOSPL
  1085.     /* Allocate command stack allowing command parser to call itself */
  1086.  
  1087.     if (!(cmdstk = (struct cmdptr *) malloc(sizeof(struct cmdptr)*CMDSTKL)))
  1088.       fatal("cmdini: no memory for cmdstk");
  1089.     if (!(ifcmd = (int *) malloc(sizeof(int)*CMDSTKL)))
  1090.       fatal("cmdini: no memory for ifcmd");
  1091.     if (!(count = (int *) malloc(sizeof(int)*CMDSTKL)))
  1092.       fatal("cmdini: no memory for count");
  1093.     if (!(iftest = (int *) malloc(sizeof(int)*CMDSTKL)))
  1094.       fatal("cmdini: no memory for iftest");
  1095.     if (!(intime = (int *) malloc(sizeof(int)*CMDSTKL)))
  1096.       fatal("cmdini: no memory for intime");
  1097.     if (!(inpcas = (int *) malloc(sizeof(int)*CMDSTKL)))
  1098.       fatal("cmdini: no memory for inpcas");
  1099.     if (!(takerr = (int *) malloc(sizeof(int)*CMDSTKL)))
  1100.       fatal("cmdini: no memory for takerr");
  1101.     if (!(merror = (int *) malloc(sizeof(int)*CMDSTKL)))
  1102.       fatal("cmdini: no memory for merror");
  1103.     if (!(xquiet = (int *) malloc(sizeof(int)*CMDSTKL)))
  1104.       fatal("cmdini: no memory for xquiet");
  1105.     if (!kermrc)
  1106.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1107.     fatal("cmdini: no memory for kermrc");
  1108. #ifdef CK_APC
  1109. /* Application Program Command buffer */
  1110.     if (!(apcbuf = malloc(APCBUFLEN + 1)))
  1111.     fatal("cmdini: no memory for apcbuf");
  1112. #endif /* CK_APC */
  1113. #endif /* NOSPL */
  1114.  
  1115. /* line[] and tmpbuf[] are the two string buffers used by the command parser */
  1116.  
  1117.     if (!(line = malloc(LINBUFSIZ + 1)))
  1118.     fatal("cmdini: no memory for line");
  1119.     if (!(tmpbuf = malloc(LINBUFSIZ + 1)))
  1120.     fatal("cmdini: no memory for tmpbuf");
  1121. #endif /* DCMDBUF */
  1122.  
  1123. #ifndef NOSPL
  1124. #ifdef CK_MINPUT
  1125.     {                    /* Initialize MINPUT pointers */
  1126.     int i;
  1127.     extern char *ms[];
  1128.     for (i = 0; i < MINPMAX; i++)
  1129.       ms[i] = NULL;
  1130.     }
  1131. #endif /* CK_MINPUT */
  1132.  
  1133.     if (macini() < 0)            /* Allocate macro buffers */
  1134.       fatal("Can't allocate macro buffers!");
  1135.  
  1136.     ifcmd[0] = 0;            /* Command-level related variables. */
  1137.     iftest[0] = 0;            /* Initialize variables at top level */
  1138.     count[0] = 0;            /* of stack... */
  1139.     intime[0] = 0;
  1140.     inpcas[0] = 0;
  1141.     takerr[0] = 0;
  1142.     merror[0] = 0;
  1143.     xquiet[0] = quiet;
  1144. #endif /* NOSPL */
  1145.  
  1146. #ifndef NOSPL
  1147.     cmdlvl = 0;                /* Initialize the command stack */
  1148.     xcmdsrc = CMD_KB;
  1149.     cmdstk[cmdlvl].src = CMD_KB;    /* Source is console */
  1150.     cmdstk[cmdlvl].lvl = 0;        /* Level is 0 */
  1151.     cmdstk[cmdlvl].ccflgs = 0;        /* No flags */
  1152. #endif /* NOSPL */
  1153.  
  1154.     tlevel = -1;            /* Take file level = keyboard */
  1155.     for (i = 0; i < MAXTAKE; i++)    /* Initialize command file names */
  1156.       tfnam[i] = NULL;
  1157.  
  1158.     cmsetp(ckprompt);             /* Set up C-Kermit's prompt */
  1159.                                         /* Can't set IKSD prompt here since */
  1160.                                         /* we do not yet know if we are IKSD */
  1161. #ifndef NOSPL
  1162.  
  1163.     initmac();                /* Initialize macro table */
  1164.  
  1165. /* Predefine built-in one-line macros */
  1166.  
  1167.     addmac("ibm-linemode",m_ibm);    /* IBM-LINEMODE */
  1168.     addmac("fatal",m_fat);        /* FATAL macro */
  1169.     y = addmac("fast",m_fast);        /* FAST macro */
  1170.     addmac("cautious",m_cautious);    /* CAUTIOUS macro */
  1171.     addmac("robust",m_robust);        /* ROBUST macro */
  1172. #ifdef OS2
  1173.     addmac("manual",m_manual);          /* MANUAL macro */
  1174. #endif /* OS2 */
  1175. #ifdef VMS
  1176.     addmac("purge",m_purge);        /* PURGE macro */
  1177. #endif /* VMS */
  1178.  
  1179. /*
  1180.   Predefine built-in multiline macros; these are top-level commands
  1181.   that are implemented internally as macros.  NOTE: When adding a new
  1182.   one of these, remember to update the END and RETURN commands to
  1183.   account for it, or else END and RETURN from within it won't work right.
  1184. */
  1185.     x = addmmac("_forx",for_def);    /* FOR macro */
  1186.     if (x > -1) mactab[x].flgs = CM_INV;
  1187.     x = addmmac("_forz",foz_def);    /* Other FOR macro */
  1188.     if (x > -1) mactab[x].flgs = CM_INV;
  1189.     x = addmmac("_xif",xif_def);    /* XIF macro */
  1190.     if (x > -1) mactab[x].flgs = CM_INV;
  1191.     x = addmmac("_while",whil_def);    /* WHILE macro */
  1192.     if (x > -1) mactab[x].flgs = CM_INV;
  1193.     x = addmmac("_switx",sw_def);    /* SWITCH macro */
  1194.     if (x > -1) mactab[x].flgs = CM_INV;
  1195.  
  1196. /* Fill in command-line argument vector */
  1197.  
  1198.     sprintf(vnambuf,"\\&@[%d]",xargs);    /* SAFE */
  1199.     if (inserver) {            /* But hidden in IKSD */
  1200.     y = -1;
  1201.     xargs = 0;
  1202.     } else
  1203.       y = arraynam(vnambuf,&x,&z);    /* goes in array \&@[] */
  1204.  
  1205.     tmpbuf[0] = NUL;
  1206.     if (y > -1) {
  1207.     int j = -1;
  1208.     int yy = 0;
  1209.     dclarray((char)x,z);        /* Declare the array */
  1210. #ifndef NOTAKEARGS
  1211.      /* Macro argument vector */
  1212.     sprintf(vnambuf,"\\&_[%d]",z);    /* SAFE */
  1213.     yy = arraynam(vnambuf,&x,&z);    /* goes in array \&_[] */
  1214.     if (yy > -1)            /* Name is OK */
  1215.       dclarray((char)x,z);        /* Declare the array */
  1216. #endif /* NOTAKEARGS */
  1217.     skip = 0;
  1218.     for (i = 0; i < xargs; i++) {    /* Fill the arrays */
  1219.         sprintf(vnambuf,"\\&@[%d]",i); /* SAFE */
  1220.         addmac(vnambuf,xargv[i]);
  1221.         if (cfilef && i == 0)
  1222.           continue;
  1223. #ifdef KERBANG
  1224.         if (skip) {
  1225.         j = 0;
  1226.         skip = 0;
  1227.         continue;
  1228.         }
  1229. #endif /* KERBANG */
  1230.         if (j < 0 &&        /* Assign items after "=" or "--"*/
  1231.         (!strcmp(xargv[i],"=") || !strcmp(xargv[i],"--"))
  1232.         ) {
  1233.         j = 0;            /* to \%1..\%9 */
  1234. #ifdef KERBANG
  1235.         } else if (j < 0 &&
  1236.                (!strcmp(xargv[i],"+") ||
  1237.             !strncmp(xargv[i],"+ ",2) ||
  1238.             !strncmp(xargv[i],"+\t",2))
  1239.             ) {
  1240.         skip = 1;
  1241.         continue;
  1242. #endif /* KERBANG */
  1243.         } else if (j > -1) {
  1244.         j++;
  1245.         if (j <= 9) {
  1246.             vnambuf[0] = '\\';
  1247.             vnambuf[1] = '%';
  1248.             vnambuf[2] = (char)(j+'0');
  1249.             vnambuf[3] = NUL;
  1250.             addmac(vnambuf,xargv[i]);
  1251.         }
  1252.         if (yy > -1) {
  1253.             char c, * p;
  1254.             int flag = 0;
  1255.             p = xargv[i];
  1256.             makestr(&(toparg[j]),p);
  1257.             while ((c = *p++)) { if (c == SP) { flag++; break; } }
  1258.             if (flag)
  1259.               ckstrncat(tmpbuf,"\"",TMPBUFSIZ);
  1260.             ckstrncat(tmpbuf,xargv[i],TMPBUFSIZ);
  1261.             if (flag)
  1262.               ckstrncat(tmpbuf,"\"",TMPBUFSIZ);
  1263.             ckstrncat(tmpbuf," ",TMPBUFSIZ);
  1264.         }
  1265.         }
  1266.     }
  1267.     if (cfilef) {
  1268.         addmac("\\%0",cmdfil);
  1269.         if (yy > -1)
  1270.           makestr(&(toparg[0]),cmdfil);
  1271.     } else {
  1272.         addmac("\\%0",xargv[0]);
  1273.         if (yy > -1)
  1274.           makestr(&(toparg[0]),xargv[0]);
  1275.     }
  1276.     if (yy > -1) {
  1277.         topargc = (j < 0) ? 1 : j + 1;
  1278.         topxarg = toparg;
  1279. #ifdef COMMENT
  1280.         /* This needs work */
  1281.         if (!cfilef)
  1282.           makestr(&topline,tmpbuf);
  1283. #endif /* COMMENT */
  1284.     } else {
  1285.         topargc = 0;
  1286.         topxarg = NULL;
  1287.     }
  1288.     a_dim[0] = topargc - 1;
  1289.     a_ptr[0] = topxarg;
  1290.     }
  1291.     *vnambuf = NUL;
  1292. #endif /* NOSPL */
  1293.  
  1294.     luinit();                /* Initialize lookup() cache */
  1295.  
  1296. /* Get our home directory now.  This needed in lots of places. */
  1297.  
  1298.     cmdinited = 1;
  1299. }
  1300.  
  1301. VOID
  1302. doinit() {
  1303. #ifdef CKROOT
  1304. extern int ckrooterr;
  1305. #endif /* CKROOT */
  1306.     int x = 0, ok = 0;
  1307. #ifdef OS2
  1308.     char * ptr = 0;
  1309. #endif /* OS2 */
  1310.  
  1311.     if (!cmdinited)
  1312.       cmdini();
  1313.  
  1314. #ifdef MAC
  1315.     return;                /* Mac Kermit has no init file */
  1316.  
  1317. #else /* !MAC */
  1318.  
  1319. /* If skipping init file ('-Y' on Kermit command line), return now. */
  1320.  
  1321.     if (noinit) {
  1322.     kermrc[0] = '\0';
  1323.     inidir[0] = '\0';
  1324. /*
  1325.   But returning from here results in inidir[] never being set to anything.
  1326.   Instead it should be set to wherever the init file *would* have been
  1327.   executed from.  So this bit of code should be removed, and then we should
  1328.   sprinkle "if (noinit)" tests throughout the following code until we have
  1329.   set inidir[], and then return without actually taking the init file.
  1330. */
  1331.     return;
  1332.     }
  1333.  
  1334. #ifdef OS2
  1335. /*
  1336.   The -y init file must be fully specified or in the current directory.
  1337.   KERMRC is looked for via INIT, DPATH and PATH in that order.  Finally, our
  1338.   own executable file path is taken and the .EXE suffix is replaced by .INI
  1339.   and this is tried as the initialization file.
  1340. */
  1341. #ifdef CK_LOGIN
  1342.     debug(F101,"doinit isguest","",isguest);
  1343.     debug(F110,"doinit anonfile",anonfile,0);
  1344.     if (isguest && anonfile)
  1345.       ckstrncpy(line, anonfile, LINBUFSIZ+1);
  1346.     else
  1347. #endif /* CK_LOGIN */
  1348.       if (rcflag) {
  1349.       ckstrncpy(line,kermrc,LINBUFSIZ+1);
  1350. #ifdef IKSD
  1351.     } else if (inserver) {
  1352.         char * homdir;
  1353.         homdir = zhome();
  1354.         line[0] = NUL;
  1355.         if (homdir) {        /* Home directory for init file. */
  1356.             ckstrncpy(line,homdir,KERMRCL);
  1357.             if (line[0] == '/')
  1358.                 ckstrncat(line,"/",KERMRCL);
  1359.         }
  1360.         ckstrncat(line,kermrc,KERMRCL);/* Append the default file name */
  1361. #endif /* IKSD */
  1362.     } else {
  1363.         char * env = 0;
  1364. #ifdef NT
  1365.     env = getenv("K95.KSC");
  1366. #else
  1367.     env = getenv("K2.KSC");
  1368. #endif /* NT */
  1369.         if (!env) {
  1370. #ifdef NT
  1371.             env = getenv("K95.INI");
  1372. #else
  1373.             env = getenv("K2.INI");
  1374. #endif /* NT */
  1375.         }
  1376.     if (!env)
  1377.       env = getenv("CKERMIT.INI");
  1378.     if (!env)
  1379.       env = getenv("CKERMIT_INI");
  1380.         line[0] = '\0';
  1381.  
  1382.     if (env)
  1383.       ckstrncpy(line,env,LINBUFSIZ+1);
  1384.     if (line[0] == 0)
  1385.       _searchenv(kermrc,"INIT",line);
  1386.     if (line[0] == 0)
  1387.       _searchenv(kermrc,"DPATH",line);
  1388.     if (line[0] == 0)
  1389.       _searchenv(kermrc,"PATH",line);
  1390.     if (line[0] == 0) {
  1391.         char *pgmptr = GetLoadPath();
  1392.         if (pgmptr && strlen(pgmptr) < LINBUFSIZ-8) {
  1393.         lp = strrchr(pgmptr, '\\');
  1394.                 if (lp) {
  1395.                     strncpy(line, pgmptr, lp - pgmptr);
  1396. #ifdef NT
  1397.                     strcpy(line + (lp - pgmptr), "/k95.ini");
  1398. #else /* NT */
  1399.                     strcpy(line + (lp - pgmptr), "/k2.ini");
  1400. #endif /* NT */
  1401.                 } else {
  1402.                     lp = strrchr(pgmptr, '.');
  1403.                     if (lp) {
  1404.                         strncpy(line, pgmptr, lp - pgmptr);
  1405.                         strcpy(line + (lp - pgmptr), ".ini");
  1406.                     }
  1407.                 }
  1408.         }
  1409.     }
  1410.     }
  1411.  
  1412. #ifdef CKROOT
  1413.     if (!zinroot(line)) {
  1414.     debug(F110,"doinit setroot violation",line,0);
  1415.     return;
  1416.     }
  1417. #endif /* CKROOT */
  1418.  
  1419.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  1420.     ok = 1;
  1421.         tlevel = 0;
  1422.     tfline[tlevel] = 0;
  1423.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  1424.       strcpy(tfnam[tlevel],line);    /* safe */
  1425. #ifndef NOSPL
  1426.     cmdlvl++;
  1427.     xcmdsrc = CMD_TF;
  1428.     cmdstk[cmdlvl].src = CMD_TF;
  1429.     cmdstk[cmdlvl].lvl = tlevel;
  1430.     cmdstk[cmdlvl].ccflgs = 0;
  1431.     ifcmd[cmdlvl] = 0;
  1432.     iftest[cmdlvl] = 0;
  1433.     count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1434.     intime[cmdlvl] = intime[cmdlvl-1];
  1435.     inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1436.     takerr[cmdlvl] = takerr[cmdlvl-1];
  1437.     merror[cmdlvl] = merror[cmdlvl-1];
  1438.     xquiet[cmdlvl] = quiet;
  1439. #endif /* NOSPL */
  1440.         debug(F110,"doinit init file",line,0);
  1441.     } else {
  1442.         debug(F100,"doinit no init file","",0);
  1443.     }
  1444.     ckstrncpy(kermrc,line,KERMRCL);
  1445.     for (ptr = kermrc; *ptr; ptr++)    /* Convert backslashes to slashes */
  1446.        if (*ptr == '\\')
  1447.          *ptr = '/';
  1448. #else /* not OS2 */
  1449.     lp = line;
  1450.     lp[0] = '\0';
  1451.     debug(F101,"doinit rcflag","",rcflag);
  1452. #ifdef GEMDOS
  1453.     zkermini(line, rcflag, kermrc);
  1454. #else
  1455. #ifdef VMS
  1456.     zkermini(line,LINBUFSIZ,kermrc);
  1457. #else /* not VMS */
  1458. #ifdef CK_LOGIN
  1459.     debug(F101,"doinit isguest","",isguest);
  1460.     if (isguest)
  1461.       ckstrncpy(lp, anonfile ? anonfile : kermrc, LINBUFSIZ);
  1462.     else
  1463. #endif /* CK_LOGIN */
  1464.       if (rcflag) {            /* If init file name from cmd line */
  1465.       ckstrncpy(lp,kermrc,LINBUFSIZ); /* use it, */
  1466.       } else {                /* otherwise... */
  1467. #ifdef CK_INI_A                /* If we've a system-wide init file */
  1468.       /* And it takes precedence over the user's... */
  1469.       ckstrncpy(lp,CK_SYSINI,KERMRCL); /* Use it */
  1470.       if (zchki(lp) < 0) {        /* (if it exists...) */
  1471. #endif /* CK_INI_A */
  1472.           char * homdir;
  1473.               char * env = 0;
  1474.           line[0] = NUL;
  1475.               
  1476.               /* Add support for environment variable */
  1477.               env = getenv("CKERMIT.INI");
  1478.               if (!env)
  1479.         env = getenv("CKERMIT_INI");
  1480.               if (env)
  1481.         ckstrncpy(lp,env,KERMRCL);
  1482.  
  1483.               if (lp[0] == 0) {
  1484.           homdir = zhome();
  1485.           if (homdir) {        /* Home directory for init file. */
  1486.               ckstrncpy(lp,homdir,KERMRCL);
  1487. #ifdef STRATUS
  1488.               ckstrncat(lp,">",KERMRCL);/* VOS dirsep */
  1489. #else
  1490.               if (lp[0] == '/') ckstrncat(lp,"/",KERMRCL);
  1491. #endif /* STRATUS */
  1492.           }
  1493.           ckstrncat(lp,kermrc,KERMRCL);/* Append default file name */
  1494.           }
  1495. #ifdef CK_INI_A
  1496.       }
  1497. #endif /* CK_INI_A */
  1498. #ifdef CK_INI_B                /* System-wide init defined? */
  1499.       /* But user's ini file takes precedence */
  1500.       if (zchki(lp) < 0)        /* If user doesn't have her own, */
  1501.         ckstrncpy(lp,CK_SYSINI,KERMRCL); /* use system-wide one. */
  1502. #endif /* CK_INI_B */
  1503.       }
  1504. #endif /* VMS */
  1505. #endif /* GEMDOS */
  1506.  
  1507. #ifdef AMIGA
  1508.     reqoff();                /* Disable requestors */
  1509. #endif /* AMIGA */
  1510.  
  1511. #ifdef CKROOT
  1512.     if (!zinroot(line)) {
  1513.     debug(F110,"doinit setroot violation",line,0);
  1514.     return;
  1515.     }
  1516. #endif /* CKROOT */
  1517.  
  1518.     debug(F110,"doinit ini file is",line,0);
  1519.     if ((tfile[0] = fopen(line,"r")) != NULL) {    /* Try to open init file. */
  1520.     ok = 1;
  1521.     tlevel = 0;
  1522.     tfline[tlevel] = 0;
  1523.     if ((tfnam[tlevel] = malloc(strlen(line)+1)))
  1524.       strcpy(tfnam[tlevel],line);    /* safe */
  1525.  
  1526.     ckstrncpy(kermrc,line,KERMRCL);
  1527.  
  1528. #ifndef NOSPL
  1529.     cmdlvl++;
  1530.     ifcmd[cmdlvl] = 0;
  1531.     iftest[cmdlvl] = 0;
  1532.     count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1533.     intime[cmdlvl] = intime[cmdlvl-1];
  1534.     inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1535.     takerr[cmdlvl] = takerr[cmdlvl-1];
  1536.     merror[cmdlvl] = merror[cmdlvl-1];
  1537.     xquiet[cmdlvl] = quiet;
  1538.     debug(F101,"doinit open ok","",cmdlvl);
  1539.         xcmdsrc = CMD_TF;
  1540.     cmdstk[cmdlvl].src = CMD_TF;
  1541.     cmdstk[cmdlvl].lvl = tlevel;
  1542.     cmdstk[cmdlvl].ccflgs = 0;
  1543. #endif /* NOSPL */
  1544.     } else if (rcflag) {
  1545.     /* Print an error message only if a specific file was asked for. */
  1546.     printf("?%s - %s\n", ck_errstr(), line);
  1547.     }
  1548.  
  1549. #ifdef datageneral
  1550. /* If CKERMIT.INI not found in home directory, look in searchlist */
  1551.     if (/* homdir && */ (tlevel < 0)) {
  1552.         ckstrncpy(lp,kermrc,LINBUFSIZ);
  1553.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  1554.         ok = 1;
  1555.         tlevel = 0;
  1556.         tfline[tlevel] = 0;
  1557.         if (tfnam[tlevel] = malloc(strlen(line)+1))
  1558.           strcpy(tfnam[tlevel],line); /* safe */
  1559. #ifndef NOSPL
  1560.         cmdlvl++;
  1561.         xcmdsrc = CMD_TF;
  1562.         cmdstk[cmdlvl].src = CMD_TF;
  1563.         cmdstk[cmdlvl].lvl = tlevel;
  1564.         cmdstk[cmdlvl].ccflgs = 0;
  1565.         ifcmd[cmdlvl] = 0;
  1566.         iftest[cmdlvl] = 0;
  1567.         count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1568.         intime[cmdlvl] = intime[cmdlvl-1];
  1569.         inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1570.         takerr[cmdlvl] = takerr[cmdlvl-1];
  1571.         merror[cmdlvl] = merror[cmdlvl-1];
  1572.         xquiet[cmdlvl] = quiet;
  1573. #endif /* NOSPL */
  1574.     }
  1575.     }
  1576. #endif /* datageneral */
  1577.  
  1578. #ifdef AMIGA                /* Amiga... */
  1579.     reqpop();                /* Restore requestors */
  1580. #endif /* AMIGA */
  1581. #endif /* OS2 */
  1582. #endif /* MAC */
  1583.  
  1584.     /* Assign value to inidir */
  1585.  
  1586.     if (!ok) {
  1587.     inidir[0] = NUL;
  1588.     } else {
  1589.     ckstrncpy(inidir, kermrc, CCHMAXPATH);
  1590.     x = strlen(inidir);
  1591.     if (x > 0) {
  1592.         int i;
  1593.         for (i = x - 1; i > 0; i-- ) {
  1594.         if (inidir[i] ==
  1595. #ifdef MAC
  1596.             ':'
  1597. #else
  1598. #ifdef UNIX
  1599.             '/'
  1600. #else
  1601. #ifdef OSK
  1602.             '/'
  1603. #else
  1604. #ifdef STRATUS
  1605.             '>'
  1606. #else
  1607. #ifdef VMS
  1608.             ']' || inidir[i] == ':'
  1609. #else
  1610. #ifdef datageneral
  1611.             ':'
  1612. #else
  1613. #ifdef OS2
  1614.             '/' || inidir[i+1] == '\\'
  1615. #else
  1616. #ifdef AMIGA
  1617.             '/' || inidir[i+1] == ':'
  1618. #endif /* AMIGA */
  1619. #endif /* OS2 */
  1620. #endif /* datageneral */
  1621. #endif /* VMS */
  1622. #endif /* STRATUS */
  1623. #endif /* OSK */
  1624. #endif /* UNIX */
  1625. #endif /* MAC */
  1626.             ) {
  1627.             inidir[i+1] = NUL;
  1628.             break;
  1629.         }
  1630.         }
  1631.     }
  1632. #ifdef NT
  1633.         GetShortPathName(inidir,inidir,CCHMAXPATH);
  1634. #endif /* NT */
  1635.     }
  1636. }
  1637.  
  1638. VOID
  1639. doiksdinit() {
  1640. #ifdef CK_SSL
  1641.     /* IKSD doesn't request client certs */
  1642.     ssl_verify_flag = SSL_VERIFY_NONE;
  1643. #endif /* CK_SSL */
  1644.  
  1645.     if (!cmdinited)
  1646.       cmdini();
  1647.  
  1648. #ifdef IKSDCONF
  1649. #ifdef OS2
  1650.     line[0] = '\0';
  1651.     _searchenv(iksdconf,"INIT",line);
  1652.     if (line[0] == 0)
  1653.       _searchenv(iksdconf,"DPATH",line);
  1654.     if (line[0] == 0)
  1655.       _searchenv(iksdconf,"PATH",line);
  1656.     if (line[0] == 0) {
  1657.         char *pgmptr = GetLoadPath();
  1658.         if (pgmptr && strlen(pgmptr) < LINBUFSIZ-8) {
  1659.             lp = strrchr(pgmptr, '\\');
  1660.             if (lp) {
  1661.                 strncpy(line, pgmptr, lp - pgmptr);
  1662.                 strcpy(line + (lp - pgmptr), "\\");
  1663.                 strcpy(line + (lp - pgmptr + 1), iksdconf);
  1664.             } else {
  1665.                 lp = strrchr(pgmptr, '.');
  1666.                 if (lp) {
  1667.                     strncpy(line, pgmptr, lp - pgmptr);
  1668.                     strcpy(line + (lp - pgmptr), ".ksc");
  1669.                 }
  1670.             }
  1671.         }
  1672.     }
  1673.     debug(F110,"doiksdinit() line",line,0);
  1674.     tfile[0] = fopen(line,"r");
  1675. #else /* OS2 */
  1676.     tfile[0] = fopen(iksdconf,"r");
  1677. #endif /* OS2 */
  1678.     if (tfile[0] != NULL) {
  1679.         tlevel = 0;
  1680.     tfline[tlevel] = 0;
  1681. #ifdef OS2
  1682.     if (tfnam[tlevel] = malloc(strlen(line)+1))
  1683.       strcpy(tfnam[tlevel],line);
  1684. #else /* OS2 */
  1685.     if ((tfnam[tlevel] = malloc(strlen(iksdconf)+1)))
  1686.       strcpy(tfnam[tlevel],iksdconf);
  1687. #endif /* OS2 */
  1688. #ifndef NOSPL
  1689.     cmdlvl++;
  1690.         xcmdsrc = CMD_TF;
  1691.     cmdstk[cmdlvl].src = CMD_TF;
  1692.     cmdstk[cmdlvl].lvl = tlevel;
  1693.     cmdstk[cmdlvl].ccflgs = 0;
  1694.     ifcmd[cmdlvl]  = 0;
  1695.     iftest[cmdlvl] = 0;
  1696.     count[cmdlvl]  = count[cmdlvl-1]; /* Inherit from previous level */
  1697.     intime[cmdlvl] = intime[cmdlvl-1];
  1698.     inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1699.     takerr[cmdlvl] = takerr[cmdlvl-1];
  1700.     merror[cmdlvl] = merror[cmdlvl-1];
  1701.     xquiet[cmdlvl] = quiet;
  1702. #endif /* NOSPL */
  1703.         debug(F110,"doiksdinit file ok",tfnam[tlevel],0);
  1704.     } else {
  1705.         debug(F110,"doiksdinit open failed",tfnam[tlevel],0);
  1706.     }
  1707. #endif /* IKSDCONF */
  1708. }
  1709.  
  1710. #ifndef NOSPL
  1711. /*
  1712.   G E T N C M
  1713.  
  1714.   Get next command from current macro definition.  Command is copied
  1715.   into string pointed to by argument s, max length n.   Returns:
  1716.    0 if a string was copied;
  1717.   -1 if there was no string to copy.
  1718. */
  1719. int
  1720. getncm(s,n) char *s; int n; {
  1721.     int y,                /* Character counter */
  1722.     quote = 0,
  1723.     kp = 0,                /* Brace up-down counter */
  1724.     pp = 0,                /* Parenthesis up-down counter */
  1725. #ifndef NODQMACRO
  1726.     dq = 0;                /* Doublequote counter */
  1727. #endif /* NODQMACRO */
  1728.     char *s2;                /* Copy of destination pointer */
  1729.  
  1730.     s2 = s;                /* Initialize string pointers */
  1731.     *s = NUL;                /* and destination buffer */
  1732.  
  1733.     /* debug(F010,"getncm entry",macp[maclvl],0); */
  1734.  
  1735.     for (y = 0;                /* Loop for n bytes max */
  1736.       macp[maclvl] && *macp[maclvl] && y < n;
  1737.      y++, s++, macp[maclvl]++) {
  1738.  
  1739.     *s = *macp[maclvl];        /* Get next char from macro def */
  1740.  
  1741. #ifndef COMMENT
  1742. /*
  1743.   This is to allow quoting of parentheses, commas, etc, in function
  1744.   arguments, but it breaks just about everything else.  DON'T REMOVE THIS
  1745.   COMMENT!  (Otherwise you'll wind up adding the same code again and breaking
  1746.   everything again.)  <-- The preceding warning should be obsolete since the
  1747.   statements below have been fixed, but in case of fire, remove the "n" from
  1748.   the <#>ifndef above.
  1749. */
  1750.     if (!quote && *s == CMDQ) {
  1751.         quote = 1;
  1752.         continue;
  1753.     }
  1754.     if (quote) {
  1755.         quote = 0;
  1756.         continue;
  1757.     }
  1758. #endif /* COMMENT */
  1759.  
  1760. /*
  1761.   Allow braces around macro definition to prevent commas from being turned to
  1762.   end-of-lines and also treat any commas within parens as text so that
  1763.   multiple-argument functions won't cause the command to break prematurely.
  1764.   19 Oct 2001: Similar treatment was added for doublequotes, so
  1765.  
  1766.      define foo { echo "one, two, three" }
  1767.  
  1768.   would work as expected.  This doesn't seem to have broken anything but
  1769.   if something comes up later, rebuild with NODQMACRO defined.
  1770. */
  1771.     if (*s == '{') kp++;        /* Count braces */
  1772.     if (*s == '}' && kp > 0) kp--;
  1773.     if (*s == '(') pp++;        /* Count parentheses. */
  1774.     if (*s == ')' && pp > 0) pp--;
  1775. #ifndef NODQMACRO
  1776.     if (*s == '"') dq = 1 - dq;    /* Account for doublequotes */
  1777. #endif /* NODQMACRO */
  1778.     if (*s == ',' && pp <= 0 && kp <= 0
  1779. #ifndef NODQMACRO
  1780.         && dq == 0
  1781. #endif /* NODQMACRO */
  1782.         ) {
  1783.         macp[maclvl]++;        /* Comma not in {} or () */
  1784.         /* debug(F110,"next cmd",s,0); */
  1785.         kp = pp = 0;        /* so we have the next command */
  1786.         break;
  1787.     }
  1788.     }                    /* Reached end. */
  1789. #ifdef COMMENT
  1790.     /* DON'T DO THIS - IT BREAKS EVERYTHING */
  1791.     *s = NUL;
  1792. #endif /* COMMENT */
  1793.     if (*s2 == NUL) {            /* If nothing was copied, */
  1794.     /* debug(F100,"getncm eom","",0); */
  1795.     popclvl();            /* pop command level. */
  1796.     return(-1);
  1797.     } else {                /* otherwise, tack CR onto end */
  1798.     *s++ = CR;
  1799.     *s = '\0';
  1800.     if (mecho && pflag)        /* If MACRO ECHO ON, echo the cmd */
  1801.       printf("%s\n",s2);
  1802.     }
  1803.     return(0);
  1804. }
  1805.  
  1806. /*  D O M A C  --  Define and then execute a macro */
  1807.  
  1808. int
  1809. domac(name, def, flags) char *name, *def; int flags; {
  1810.     int x, m;
  1811. #ifndef NOLOCAL
  1812. #ifdef OS2
  1813.     extern int term_io;
  1814.     int term_io_sav = term_io;
  1815.     term_io = 0;            /* Disable Terminal Emulator I/O */
  1816. #endif /* OS2 */
  1817. #endif /* NOLOCAL */
  1818.     m = maclvl;                /* Current macro stack level */
  1819.     x = addmac(name, def);        /* Define a new macro */
  1820.     if (x > -1) {            /* If successful, */
  1821.     dodo(x,NULL,flags);        /* start it (increments maclvl). */
  1822.     while (maclvl > m) {        /* Keep going till done with it, */
  1823.         debug(F101,"domac loop maclvl 1","",maclvl);
  1824.         sstate = (CHAR) parser(1);    /* parsing & executing each command, */
  1825.         debug(F101,"domac loop maclvl 2","",maclvl);
  1826.         if (sstate) proto();    /* including protocol commands. */
  1827.     }
  1828.     debug(F101,"domac loop exit maclvl","",maclvl);
  1829.     }
  1830. #ifndef NOLOCAL
  1831. #ifdef OS2
  1832.     term_io = term_io_sav;
  1833. #endif /* OS2 */
  1834. #endif /* NOLOCAL */
  1835.     return(success);
  1836. }
  1837. #endif /* NOSPL */
  1838.  
  1839. /*
  1840.   G E T N C T
  1841.  
  1842.   Get next command from TAKE (command) file.
  1843.  
  1844.   Call with:
  1845.    s     Pointer to buffer to read into
  1846.    n     Length of buffer
  1847.    f     File descriptor of file to read from
  1848.    flag  0 == keep line terminator on and allow continuation
  1849.          1 == discard line terminator and don't allow continuation
  1850.  
  1851.   Call with flag == 0 to read a command from a TAKE file;
  1852.   Call with flag != 0 to read a line from a dialing or network directory.
  1853.  
  1854.   In both cases, trailing comments and/or trailing whitespace is/are stripped.
  1855.   If flag == 0, continued lines are combined into one line.  A continued line
  1856.   is one that ends in hypen, or any line in a "block", which starts with "{"
  1857.   at the end of a line and ends with a matching "}" at the beginning of a
  1858.   subsequent line; blocks may be nested.
  1859.  
  1860.   Returns:
  1861.    0 if a string was copied,
  1862.   -1 on EOF,
  1863.   -2 on malloc failure
  1864.   -3 if line is not properly terminated
  1865.   -4 if (possibly continued) line is too long.
  1866. */
  1867. static int lpxlen = 0;
  1868.  
  1869. int
  1870. getnct(s,n,f,flag) char *s; int n; FILE *f; int flag; {
  1871.     int i = 0, len = 0, buflen = 0;
  1872.     char c = NUL, cc = NUL, ccl = NUL, ccx = NUL, *s2 = NULL;
  1873.     char *lp = NULL, *lpx = NULL, *lp2 = NULL, *lp3 = NULL, *lastcomma = NULL;
  1874.     char * prev = NULL;
  1875.     int bc = 0;                /* Block counter */
  1876.  
  1877.     s2 = s;                /* Remember original pointer */
  1878.     prev = s2;
  1879.     buflen = n;                /* Remember original buffer length */
  1880.  
  1881.     if (n < 0)
  1882.       return(-2);
  1883.  
  1884.     /* Allocate a line buffer only if we don't have one that's big enough */
  1885.  
  1886.     debug(F111,"getnct",ckitoa(lpxlen),n);
  1887.  
  1888.     if (lpx && (n > lpxlen)) {        /* Have one already */
  1889.     debug(F101,"getnct new buffer","",lpxlen);
  1890.     free(lpx);            /* But it's not big enough */
  1891.     lpx = NULL;            /* Free current one */
  1892.     lpxlen = 0;
  1893.     }
  1894.     if (!lpx) {                /* Get new one */
  1895.     if (!(lpx = (char *) malloc(n))) {
  1896.         debug(F101,"getnct malloc failure","",0);
  1897.         printf("?Memory allocation failure [getnct]\n");
  1898.         return(-2);
  1899.     }
  1900.     lpxlen = n;
  1901.     }
  1902.     lp2 = lpx;
  1903. #ifdef KLUDGE
  1904.     /* NOTE: No longer used as of 14 Aug 2000 */
  1905.     lp2++;
  1906. #endif /* KLUDGE */
  1907.  
  1908.     while (1) {                /* Loop to read lines from file */
  1909.     debug(F101,"getnct while (1)","",n);
  1910.     if (fgets(lp2,n,f) == NULL) {    /* Read a line into lp2 */
  1911.         debug(F110,"getnct EOF",s2,0); /* EOF */
  1912.         free(lpx);            /* Free temporary storage */
  1913.         lpx = NULL;
  1914.         *s = NUL;            /* Make destination be empty */
  1915.         return(-1);            /* Return failure code */
  1916.     }
  1917. #ifndef NODIAL
  1918.     if (flag)            /* Count this line */
  1919.       dirline++;
  1920.     else
  1921. #endif /* NODIAL */
  1922.       tfline[tlevel]++;
  1923.     len = strlen(lp2) - 1;        /* Position of line terminator */
  1924.     if (len == 0 && lp2[0] != '\n') { /* Last line in file has one char */
  1925.         lp2[++len] = '\n';        /* that is not a newline */
  1926.         lp2[len] = NUL;
  1927.     }
  1928.     debug(F010,"getnct",lp2,0);
  1929.     if (len < 0)
  1930.       len = 0;
  1931.     if (techo && pflag)        /* If TAKE ECHO ON, */
  1932.       printf("%3d. %s",        /* echo it this line. */
  1933. #ifndef NODIAL
  1934.          flag ? dirline :
  1935. #endif /* NODIAL */
  1936.          tfline[tlevel],
  1937.          lp2
  1938.          );
  1939.         lp3 = lp2;            /* Working pointer */
  1940.     i = len;            /* Get first nonwhitespace character */
  1941.     while (i > 0 && (*lp3 == SP || *lp3 == HT)) {
  1942.         i--;
  1943.         lp3++;
  1944.     }
  1945.     if (i == 0 && bc > 0)        /* Blank line in {...} block */
  1946.       continue;
  1947.  
  1948.     /* Isolate, remove, and check terminator */
  1949.  
  1950.     c = lp2[len];            /* Value of line terminator */
  1951.     /* debug(F101,"getnct terminator","",c); */
  1952.     if (c < LF || c > CR) {        /* It's not a terminator */
  1953.         /* debug(F111,"getnct bad line",lp2,c); */
  1954.         if (feof(f) && len > 0 && len < n) {
  1955.         /* Kludge Alert... */
  1956.         if (!quiet)
  1957.           printf("WARNING: Last line of %s lacks terminator\n",
  1958.              s2 == cmdbuf ? "command file" : "directory file");
  1959.         c = lp2[++len] = '\n';    /* No big deal - supply one. */
  1960.         } else {            /* Something's wrong, fail. */
  1961.         free(lpx);
  1962.         lpx = NULL;
  1963.         return(-3);
  1964.         }
  1965.     }
  1966.     /* Trim trailing whitespace */
  1967.  
  1968.     for (i = len - 1; i > -1 && lp2[i] <= SP; i--) /* Trim */
  1969.       ;
  1970.     /* debug(F101,"getnct i","",i); */
  1971.     lp2[i+1] = NUL;            /* Terminate the string */
  1972.     /* debug(F110,"getnct lp2",lp2,0); */
  1973.     lp = lp2;            /* Make a working pointer */
  1974.  
  1975.     /* Remove trailing or full-line comment */
  1976.  
  1977.     while ((cc = *lp)) {
  1978.         if (cc == ';' || cc == '#') { /* Comment introducer? */
  1979.         if (lp == lp2) {    /* First char on line */
  1980.             *lp = NUL;
  1981.             break;
  1982.         } else if (*(lp - 1) == SP || *(lp - 1) == HT) {
  1983.             lp--;
  1984.             *lp = NUL;    /* Or preceded by whitespace */
  1985.             break;
  1986.         }
  1987.         }
  1988.         lp++;
  1989.     }
  1990.     if (lp > lp2)
  1991.       lp--;                /* Back up over the NUL */
  1992.  
  1993.     /* Now trim any space that preceded the comment */
  1994.  
  1995.     while ((*lp == SP || *lp == HT) && lp >= lp2) {
  1996.         *lp = NUL;
  1997.         if (lp <= lp2)
  1998.           break;
  1999.         lp--;
  2000.     }
  2001.     /* debug(F110,"getnct comment trimmed",lp2,0); */
  2002.  
  2003.     len = strlen(lp2);        /* Length after trimming */
  2004.  
  2005.     if (n - len < 2) {        /* Check remaining space */
  2006.         debug(F111,"getnct command too long",s2,buflen);
  2007.         printf("?Line too long, maximum length: %d.\n",buflen);
  2008.         free(lpx);
  2009.         return(-4);
  2010.     }
  2011.     ccl = (len > 0) ? lp2[len-1] : 0;     /* Last character in line */
  2012.     ccx = (len > 1) ? lp2[len-2] : 0;     /* Penultimate char in line */
  2013.  
  2014. #ifdef COMMENT
  2015.     /* Line containing only whitespace and ,- */
  2016.     if ((len > 1) && (lp3 == lp2+len-2) && (ccl == '-') && (ccx == ','))
  2017.       continue;
  2018. #endif /* COMMENT */
  2019.  
  2020. #ifdef KLUDGE
  2021. /*
  2022.   If it is a command and it begins with a token (like ! or .) that is not
  2023.   followed by a space, insert a space now; otherwise cmkey() can get mighty
  2024.   confused.
  2025. */
  2026.     if (s == s2 && !flag) {
  2027.         char *p = toktab;
  2028.         while (*p) {
  2029.         if (*p == *lp3 && *(p+1) != SP) {
  2030.             debug(F110,"getnct token",p,0);
  2031.             *lp3-- = SP;
  2032.             *lp3 = *p;
  2033.             if (lp3 < lp2) {
  2034.             lp2--;
  2035.             len++;
  2036.             }
  2037.             break;
  2038.         } else
  2039.           p++;
  2040.         }
  2041.     }
  2042. #endif /* KLUDGE */
  2043.     lp = lp2;
  2044.  
  2045.     while ((*s++ = *lp++))        /* Copy result to target buffer */
  2046.       n--;                /* accounting for length */
  2047.     s--;                /* Back up over the NUL */
  2048.  
  2049.     /* Check whether this line is continued */
  2050.  
  2051.         if (flag)            /* No line continuation when flag=1 */
  2052.       break;            /* So break out of read-lines loop */
  2053.  
  2054. #ifdef COMMENT
  2055.     debug(F000,"getnct first char","",*lp3);
  2056.     debug(F000,"getnct last char","",ccl);
  2057.     debug(F000,"getnct next-to-last char","",ccx);
  2058. #endif /* COMMENT */
  2059.  
  2060.     if (bc > 0 && *lp3 == '}') {    /* First char on line is '}' */
  2061.         bc--;                /* Decrement block counter */
  2062.     }
  2063.  
  2064.     if (bc == 0 &&            /* Line is continued if bc > 0 */
  2065. #ifdef COMMENT
  2066.         /* Not supported as of C-Kermit 6.0 */
  2067.         ccl != CMDQ &&        /* or line ends with CMDQ */
  2068. #endif /* COMMENT */
  2069.         ccl != '-'  &&        /* or line ends with dash */
  2070.         ccl != '{')            /* or line ends with opening brace */
  2071.       break;            /* None of those, we're done. */
  2072.  
  2073.     if (ccl == '-' || ccl == '{')    /* Continuation character */
  2074.       if (ccx == CMDQ)        /* But it's quoted */
  2075.         break;            /* so ignore it */
  2076.  
  2077.     if (ccl == '{') {        /* Last char on line is '{'? */
  2078.         bc++;            /* Count the block opener. */
  2079.     } else if (ccl == '-') {    /* Explicit continue? */
  2080.         char c, * ss;
  2081.         int state = 0, nn;
  2082.         s--;            /* Yes, back up over terminators */
  2083.         n++;            /* and over continuation character */
  2084.         nn = n;            /* Save current count */
  2085.         ss = s;            /* and pointer */
  2086.         s--;            /* Back up over dash */
  2087.         n++;
  2088.         while (state < 2 && s >= prev) { /* Check for "{,-" */
  2089.         n++;
  2090.         c = *s--;
  2091.         if (c <= SP)
  2092.           continue;
  2093.         if (c != ',' && c != '{')
  2094.           break;
  2095.         switch (state) {
  2096.           case 0:        /* Looking for comma */
  2097.             if (c == ',')
  2098.               state = 1;
  2099.             break;
  2100.           case 1:        /* Looking for left brace */
  2101.             if (c == '{') {
  2102.             state = 2;
  2103.             s += 2;
  2104.             *s = NUL;
  2105.             bc++;
  2106.             }
  2107.             break;
  2108.         }
  2109.         }
  2110.         if (state != 2) { s = ss; n = nn; }
  2111.         *s = NUL;
  2112.     } else {            /* None of those but (bc > 0) */
  2113.         lastcomma = s;
  2114.         *s++ = ',';            /* and insert a comma */
  2115.         n--;
  2116.     }
  2117. #ifdef COMMENT
  2118.     debug(F101,"getnct bc","",bc);
  2119.     debug(F100,"getnct continued","",0);
  2120. #endif /* COMMENT */
  2121.  
  2122.         *s = NUL;
  2123.         prev = s;
  2124.  
  2125.     } /* read-lines while loop */
  2126.  
  2127.     if (lastcomma)
  2128.       *lastcomma = SP;
  2129.     if (!flag)                /* Tack line terminator back on */
  2130.       *s++ = c;
  2131.     *s++ = NUL;                /* Terminate the string */
  2132.     untab(s2);                /* Done, convert tabs to spaces */
  2133. #ifdef DEBUG
  2134.     if (!flag) {
  2135.     debug(F010,"CMD(F)",s2,0);
  2136.     }
  2137. #endif /* DEBUG */
  2138.     free(lpx);                /* Free temporary storage */
  2139.     return(0);                /* Return success */
  2140. }
  2141.  
  2142. VOID
  2143. shostack() {                /* Dump the command stack */
  2144.     int i;
  2145.     char *p;
  2146. #ifndef NOSPL
  2147.     for (i = cmdlvl; i > 0; i--) {
  2148.     if (cmdstk[i].src == CMD_TF) {
  2149.         p = tfnam[cmdstk[i].lvl];
  2150.         if (zfnqfp(p,TMPBUFSIZ,tmpbuf))
  2151.           p = tmpbuf;
  2152.         printf(" %2d. File  : %s (line %d)\n",
  2153.            i,
  2154.            p,
  2155.            tfline[cmdstk[i].lvl]
  2156.            );
  2157.     } else if (cmdstk[i].src == CMD_MD) {
  2158.         char * m;
  2159.         m = m_arg[cmdstk[i].lvl][0]; /* Name of this macro */
  2160.         if (i > 0) {         /* Special handling for 2-level */
  2161.         char *s;         /* built-in macros... */
  2162.         s = m_arg[cmdstk[i-1].lvl][0]; /* Name next level up */
  2163.         if (s && cmdstk[i-1].src == CMD_MD) {
  2164.             if (!strcmp(s,"_forx"))
  2165.               m = "FOR";
  2166.             else if (!strcmp(s,"_xif"))
  2167.               m = "XIF";
  2168.             else if (!strcmp(s,"_while"))
  2169.               m = "WHILE";
  2170.             else if (!strcmp(s,"_switx"))
  2171.               m = "SWITCH";
  2172.         }
  2173.         }
  2174.         printf(" %2d. Macro : %s\n",i,m);
  2175.     } else if (cmdstk[i].src == CMD_KB) {
  2176.         printf(" %2d. Prompt:\n",i);
  2177.     } else {
  2178.         printf(" %2d. ERROR : Command source unknown\n",i);
  2179.     }
  2180.     }
  2181. #else
  2182.     for (i = tlevel; i > -1; i--) {
  2183.     p = tfnam[i];
  2184.     if (zfnqfp(p,TMPBUFSIZ,tmpbuf))
  2185.       p = tmpbuf;
  2186.     printf(" %2d. File  : %s (line %d)\n",
  2187.            i,
  2188.            p,
  2189.            tfline[i]
  2190.            );
  2191.     }
  2192. #endif /* NOSPL */
  2193.     if (i == 0)
  2194.       printf(" %2d. Prompt: (top level)\n",0);
  2195. }
  2196.  
  2197.  
  2198. /*  P A R S E R  --  Top-level interactive command parser.  */
  2199.  
  2200. /*
  2201.   Call with:
  2202.     m = 0 for normal behavior: keep parsing and executing commands
  2203.           until an action command is parsed, then return with a
  2204.           Kermit start-state as the value of this function.
  2205.     m = 1 to parse only one command, can also be used to call parser()
  2206.           recursively.
  2207.     m = 2 to read but do not execute one command.
  2208.   In all cases, parser() returns:
  2209.     0     if no Kermit protocol action required
  2210.     > 0   with a Kermit protocol start-state.
  2211.     < 0   upon error.
  2212. */
  2213. int
  2214. parser(m) int m; {
  2215.     int tfcode, xx, yy, zz;        /* Workers */
  2216.     int is_tn = 0;
  2217.     int cdlost = 0;
  2218.  
  2219. #ifndef NOSPL
  2220.     int inlevel;            /* Level we were called at */
  2221.     extern int askflag;
  2222. #endif /* NOSPL */
  2223.     char *cbp;                /* Command buffer pointer */
  2224. #ifdef MAC
  2225.     extern char *lfiles;        /* Fake extern cast */
  2226. #endif /* MAC */
  2227.     extern int interrupted;
  2228. #ifndef NOXFER
  2229.     extern int sndcmd, getcmd, fatalio, clearrq;
  2230. #endif /* NOXFER */
  2231.  
  2232.     debok = 1;                /* Undisable debugging */
  2233.  
  2234. #ifdef AMIGA
  2235.     reqres();                /* Restore AmigaDOS requestors */
  2236. #endif /* AMIGA */
  2237.  
  2238. #ifdef OS2
  2239.     if (cursor_save > -1) {        /* Restore cursor if it was */
  2240.     cursorena[VCMD] = cursor_save;    /* turned off during file transfer */
  2241.     cursor_save = -1;
  2242.     }
  2243. #endif /* OS2 */
  2244.  
  2245. #ifdef IKSDB
  2246.     if (ikdbopen) slotstate(what,"COMMAND PROMPT","",""); /* IKSD database */
  2247. #endif /* IKSDB */
  2248.  
  2249.     is_tn = (local && network && ttnproto == NP_TELNET) ||
  2250.       (!local && sstelnet);
  2251.  
  2252.     if (!xcmdsrc)            /* If at top (interactive) level ... */
  2253.       concb((char)escape);        /* put console in 'cbreak' mode. */
  2254.  
  2255. #ifdef CK_TMPDIR
  2256. /* If we were cd'd temporarily to another device or directory ... */
  2257.     if (f_tmpdir) {
  2258.     int x;
  2259.     x = zchdir((char *) savdir);    /* ... restore previous directory */
  2260.     f_tmpdir = 0;            /* and remember we did it. */
  2261.     debug(F111,"parser tmpdir restoring",savdir,x);
  2262.     }
  2263. #endif /* CK_TMPDIR */
  2264.  
  2265. #ifndef NOSPL
  2266.     inlevel = cmdlvl;        /* Current macro level */
  2267. #ifdef DEBUG
  2268.     if (deblog) {
  2269.     debug(F101,"&parser entry maclvl","",maclvl);
  2270.     debug(F101,"&parser entry inlevel","",inlevel);
  2271.     debug(F101,"&parser entry tlevel","",tlevel);
  2272.     debug(F101,"&parser entry cmdlvl","",cmdlvl);
  2273.     debug(F101,"&parser entry m","",m);
  2274.     }
  2275. #endif /* DEBUG */
  2276. #endif /* NOSPL */
  2277.  
  2278. #ifndef NOXFER
  2279.     ftreset();                /* Reset global file settings */
  2280. #endif /* NOXFER */
  2281. /*
  2282.   sstate becomes nonzero when a command has been parsed that requires some
  2283.   action from the protocol module.  Any non-protocol actions, such as local
  2284.   directory listing or terminal emulation, are invoked directly from below.
  2285. */
  2286.     sstate = 0;                /* Start with no start state. */
  2287.  
  2288. #ifndef NOXFER
  2289. #ifndef NOSPL
  2290.     query = 0;                /* QUERY not active */
  2291. #endif /* NOSPL */
  2292. #ifndef NOHINTS
  2293.     if (!success) {
  2294.     if (local && !network && carrier != CAR_OFF) {
  2295.         int x;            /* Serial connection */
  2296.         x = ttgmdm();        /* with carrier checking */
  2297.         if (x > -1) {
  2298.         if (!(x & BM_DCD)) {
  2299.             cdlost = 1;
  2300.             fatalio = 1;
  2301.         }
  2302.         }
  2303.     }
  2304.     }
  2305. #ifdef DEBUG
  2306.     if (deblog) {
  2307.     debug(F101,"parser top what","",what);
  2308.     debug(F101,"parser top interrupted","",interrupted);
  2309.     debug(F101,"parser top cdlost","",cdlost);
  2310.     debug(F101,"parser top sndcmd","",sndcmd);
  2311.     debug(F101,"parser top getcmd","",getcmd);
  2312.     }
  2313. #endif /* DEBUG */
  2314.     if (cdlost && !interrupted && (sndcmd || getcmd)) {
  2315.     printf("?Connection broken (carrier signal lost)\n");
  2316.     }
  2317.     if (sndcmd && !success && hints && !interrupted && !fatalio && !xcmdsrc) {
  2318.     int x = 0, n = 0;
  2319.         printf("\n*************************\n");
  2320.     printf("SEND-class command failed.\n");
  2321.     printf(" Packets sent: %d\n", spackets);
  2322.     printf(" Retransmissions: %d\n",retrans);
  2323.     printf(" Timeouts: %d\n", timeouts);
  2324.     printf(" Damaged packets: %d\n", crunched);
  2325.     if (epktrcvd) {
  2326.         printf(" Transfer canceled by receiver.\n");
  2327.         printf(" Receiver's message: \"%s\"\n",(char *)epktmsg);
  2328.         n++;
  2329.     } else {
  2330.         if (epktmsg) if (*epktmsg) {
  2331.         printf(" Fatal Kermit Protocol Error: %s\n",epktmsg);
  2332.         n++;
  2333.         }
  2334.     }
  2335.     if (local && !network && carrier != CAR_OFF) {
  2336.         int xx;            /* Serial connection */
  2337.         xx = ttgmdm();        /* with carrier checking */
  2338.         if (xx > -1) {
  2339.         if (!(xx & BM_DCD))
  2340.           cdlost = 1;
  2341.         }
  2342.     }
  2343.  
  2344. #ifdef UNIX
  2345.     if (errno != 0)
  2346. #endif /* UNIX */
  2347.       {
  2348.           printf(" Most recent local OS error: \"%s\"\n",ck_errstr());
  2349.           n++;
  2350.       }
  2351.     printf(
  2352.    "\nHINTS... If the preceding error message%s not explain the failure:\n",
  2353.            (n > 1) ? "s do" : " does"
  2354.            );
  2355. #ifndef NOLOCAL
  2356.     if (local) {
  2357.         if (rpackets == 0) {
  2358.         printf(" . Did you start a Kermit receiver on the far end?\n");
  2359.         } else {
  2360.         printf(
  2361.         " . Try changing the remote Kermit's FLOW-CONTROL setting.\n");
  2362.         if (!network && mdmtyp > 0)
  2363.           if ((3 * crunched) > spackets)
  2364.             printf(
  2365.             " . Try placing a new call to get a cleaner connection.\n");
  2366.         }
  2367.     } else if (rpackets > 0) {
  2368.         if (flow == FLO_NONE)
  2369.          printf(" . Give me a SET FLOW XON/XOFF command and try again.\n");
  2370.         else
  2371.          printf(" . Give me a SET FLOW NONE command and try again.\n");
  2372.     }
  2373.     x++;
  2374. #endif /* NOLOCAL */
  2375.  
  2376.     if ((3 * timeouts) > spackets)
  2377.       printf(" . Adjust the timeout method (see HELP SET SEND).\n");
  2378.     if ((3 * retrans) > spackets)
  2379.       printf(" . Increase the retry limit (see HELP SET RETRY).\n");
  2380.  
  2381. #ifdef CK_SPEED
  2382.     if (prefixing != PX_ALL && rpackets > 2) {
  2383.         printf(" . Try it again with SET PREFIXING ALL.\n");
  2384.         x++;
  2385.     }
  2386. #endif /* CK_SPEED */
  2387. #ifdef STREAMING
  2388.     if (streamed) {
  2389.         printf(" . Try it again with SET STREAMING OFF.\n");
  2390.         x++;
  2391.     } else if (reliable) {
  2392.         printf(" . Try it again with SET RELIABLE OFF.\n");
  2393.         x++;
  2394.     }
  2395. #endif /* STREAMING */
  2396.  
  2397. #ifdef CK_SPEED
  2398.         if (clearrq > 0 && prefixing == PX_NON) {
  2399.         printf(" . Try it again with SET CLEAR-CHANNEL OFF.\n");
  2400.         x++;
  2401.         }
  2402. #endif /* CK_SPEED */
  2403.     if (!parity) {
  2404.         printf(" . Try it again with SET PARITY SPACE.\n");
  2405.         x++;
  2406.     }
  2407.     printf(" . %sive a ROBUST command and try again.\n",
  2408.            (x > 0) ? "As a last resort, g" : "G"
  2409.            );
  2410.     printf("Also:\n");
  2411.         printf(" . Be sure the source file has read permission.\n");
  2412.     printf(" . Be sure the target directory has write permission.\n");
  2413.     printf("(Use SET HINTS OFF to suppress hints.)\n");
  2414.     printf("*************************\n\n");
  2415.     }
  2416.     debug(F101,"topcmd","",topcmd);
  2417.     if (getcmd && !success && hints && !interrupted && !fatalio && !xcmdsrc) {
  2418.     int x = 0;
  2419.     extern int urpsiz, wslotr;
  2420.         printf("\n*************************\n");
  2421.     printf("RECEIVE- or GET-class command failed.\n");
  2422.     printf(" Packets received: %d\n", rpackets);
  2423.     printf(" Damaged packets: %d\n", crunched);
  2424.     printf(" Timeouts: %d\n", timeouts);
  2425.     if (rpackets > 0)
  2426.       printf(" Packet length: %d\n", urpsiz);
  2427.     if (epktrcvd) {
  2428.         printf(" Transfer canceled by sender.\n");
  2429.         printf(" Sender's message: \"%s\"\n",(char *)epktmsg);
  2430.     }
  2431. #ifdef UNIX
  2432.     if (errno != 0)
  2433. #endif /* UNIX */
  2434.       printf(" Most recent local error: \"%s\"\n",ck_errstr());
  2435.     printf(
  2436.    "\nHINTS... If the preceding error message%s not explain the failure:\n",
  2437.            epktrcvd ? "s do" : " does"
  2438.            );
  2439. #ifndef NOLOCAL
  2440.     if (local) {
  2441.         if (topcmd == XXGET)
  2442.           printf(" . Did you start a Kermit SERVER on the far end?\n");
  2443.         if (rpackets == 0) {
  2444.         if (topcmd != XXGET)
  2445.           printf(" . Did you start a Kermit SENDer on the far end?\n");
  2446.         } else {
  2447.         printf(
  2448.         " . Choose a different FLOW-CONTROL setting and try again.\n");
  2449.         }
  2450.     } else if (topcmd == XXGET)
  2451.       printf(" . Is the other Kermit in (or does it have) SERVER mode?\n");
  2452.     if (rpackets > 0 && urpsiz > 90)
  2453.       printf(" . Try smaller packets (SET RECEIVE PACKET-LENGTH).\n");
  2454.     if (rpackets > 0 && wslotr > 1 && !streamed)
  2455.       printf(" . Try a smaller window size (SET WINDOW).\n");
  2456.     if (!local && rpackets > 0) {
  2457.         if (flow == FLO_NONE)
  2458.          printf(" . Give me a SET FLOW XON/XOFF command and try again.\n");
  2459.         else
  2460.          printf(" . Give me a SET FLOW NONE command and try again.\n");
  2461.     }
  2462.     x++;
  2463. #endif /* NOLOCAL */
  2464. #ifdef STREAMING
  2465.     if (streamed) {
  2466.         printf(" . Try it again with SET STREAMING OFF.\n");
  2467.         x++;
  2468.     } else if (reliable && local) {
  2469.         printf(" . Try it again with SET RELIABLE OFF.\n");
  2470.         x++;
  2471.         } else
  2472. #endif /* STREAMING */
  2473.     if (!parity) {
  2474.         printf(" . Try it again with SET PARITY SPACE.\n");
  2475.         x++;
  2476.     }
  2477.     printf((x > 0) ?
  2478.            " . As a last resort, give a ROBUST command and try again.\n" :
  2479.            " . Give a ROBUST command and try again.\n"
  2480.            );
  2481.     printf("Also:\n");
  2482.     printf(" . Be sure the target directory has write permission.\n");
  2483.         printf(" . Try telling the %s to SET PREFIXING ALL.\n",
  2484.            topcmd == XXGET ? "server" : "sender"
  2485.            );
  2486.     printf(" . Try giving a ROBUST command to the %s.\n",
  2487.            topcmd == XXGET ? "server" : "sender"
  2488.            );
  2489.     printf("(Use SET HINTS OFF to suppress hints.)\n");
  2490.     printf("*************************\n\n");
  2491.     }
  2492. #endif /* NOHINTS */
  2493.     getcmd = 0;
  2494.     sndcmd = 0;
  2495.     interrupted = 0;
  2496. #endif /* NOXFER */
  2497.  
  2498.     what = W_COMMAND;            /* Now we're parsing commands. */
  2499.  
  2500.     while (sstate == 0) {        /* Parse cmds until action requested */
  2501.     debug(F100,"parse top","",0);
  2502. #ifdef OS2
  2503.         if (apcactive == APC_INACTIVE)
  2504.       WaitCommandModeSem(-1);
  2505. #endif /* OS2 */
  2506. #ifdef IKS_OPTION
  2507.         if ((local &&
  2508.          !xcmdsrc &&
  2509.          is_tn &&
  2510.          TELOPT_ME(TELOPT_KERMIT) &&
  2511.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start) ||
  2512.         (!local &&
  2513.          !cmdadl &&
  2514.          TELOPT_ME(TELOPT_KERMIT) &&
  2515.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2516.         ) {
  2517.             tn_siks(KERMIT_STOP);
  2518.         }
  2519. #endif /* IKS_OPTION */
  2520.  
  2521. #ifndef NOXFER
  2522.     if (autopath) {
  2523.         fnrpath = PATH_AUTO;
  2524.         autopath = 0;
  2525.     }
  2526.     remfile = 0;            /* Clear these in case REMOTE */
  2527.     remappd = 0;            /* command was interrupted... */
  2528.     rempipe = 0;
  2529.     makestr(&snd_move,g_snd_move);    /* Restore these */
  2530.     makestr(&rcv_move,g_rcv_move);
  2531.     makestr(&snd_rename,g_snd_rename);
  2532.     makestr(&rcv_rename,g_rcv_rename);
  2533. #endif /* NOXFER */
  2534.     xaskmore = saveask;        /* Restore global more-prompting */
  2535.     diractive = 0;
  2536.     cdactive = 0;
  2537.  
  2538. #ifndef NOSPL
  2539.     askflag = 0;
  2540. #endif /* NOSPL */
  2541.  
  2542.     /* Take requested action if there was an error in the previous command */
  2543.  
  2544.     setint();
  2545.     debug(F101,"parser tlevel","",tlevel);
  2546.     debug(F101,"parser cmd_rows","",cmd_rows);
  2547.  
  2548. #ifndef NOLOCAL
  2549.     debug(F101,"parser wasclosed","",wasclosed);
  2550.     if (wasclosed) {        /* If connection was just closed */
  2551. #ifndef NOSPL
  2552.         int k;
  2553.         k = mlook(mactab,"on_close",nmac); /* Look up "on_close" */
  2554.         if (k >= 0) {        /* If found, */
  2555.         /* printf("ON_CLOSE CMD LOOP\n"); */
  2556.         dodo(k,ckitoa(whyclosed),0); /* Set it up */
  2557.         }
  2558. #endif /* NOSPL */
  2559.         whyclosed = WC_REMO;
  2560.         wasclosed = 0;
  2561.         }
  2562. #endif /* NOLOCAL */
  2563.  
  2564. #ifndef NOSPL
  2565.     xxdot = 0;            /* Clear this... */
  2566.  
  2567.     debug(F101,"parser success","",success);
  2568.     if (success == 0) {
  2569.         if (cmdstk[cmdlvl].src == CMD_TF && takerr[cmdlvl]) {
  2570.         printf("Command file terminated by error.\n");
  2571.         popclvl();
  2572.         if (cmdlvl == 0) return(0);
  2573.         }
  2574.         if (cmdstk[cmdlvl].src == CMD_MD && merror[cmdlvl]) {
  2575.         printf("Command error: macro terminated.\n");
  2576.         popclvl();
  2577.         if (m && (cmdlvl < inlevel))
  2578.           return((int) sstate);
  2579.         }
  2580.     }
  2581.     nulcmd = (m == 2);
  2582.     debug(F101,"parser nulcmd","",nulcmd);
  2583. #else
  2584.     if (success == 0 && tlevel > -1 && takerr[tlevel]) {
  2585.         printf("Command file terminated by error.\n");
  2586.         popclvl();
  2587.         cmini(ckxech);        /* Clear the cmd buffer. */
  2588.         if (tlevel < 0)         /* Just popped out of cmd files? */
  2589.           return(0);        /* End of init file or whatever. */
  2590.     }
  2591. #endif /* NOSPL */
  2592.  
  2593. #ifdef MAC
  2594.     /* Check for TAKE initiated by menu. */
  2595.     if ((tlevel == -1) && lfiles)
  2596.         startlfile();
  2597. #endif /* MAC */
  2598.  
  2599.         /* If in TAKE file, check for EOF */
  2600. #ifndef NOSPL
  2601. #ifdef MAC
  2602.     if
  2603. #else
  2604.     while
  2605. #endif /* MAC */
  2606.       ((cmdstk[cmdlvl].src == CMD_TF)  /* If end of take file */
  2607.            && (tlevel > -1)
  2608.            && feof(tfile[tlevel])) {
  2609.         popclvl();            /* pop command level */
  2610.         cmini(ckxech);        /* and clear the cmd buffer. */
  2611.         if (cmdlvl == 0) {        /* Just popped out of all cmd files? */
  2612.         return(0);        /* End of init file or whatever. */
  2613.         }
  2614.     }
  2615. #ifdef MAC
  2616.     miniparser(1);
  2617.     if (sstate == 'a') {        /* if cmd-. cancel */
  2618.         debug(F100, "parser: cancel take due to sstate", "", sstate);
  2619.         sstate = '\0';
  2620.         dostop();
  2621.         return(0);            /* End of init file or whatever. */
  2622.     }
  2623. #endif /*  MAC */
  2624.  
  2625. #else /* NOSPL */
  2626.     if ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
  2627.         popclvl();            /* Pop up one level. */
  2628.         cmini(ckxech);        /* and clear the cmd buffer. */
  2629.         if (tlevel < 0)         /* Just popped out of cmd files? */
  2630.           return(0);        /* End of init file or whatever. */
  2631.      }
  2632. #endif /* NOSPL */
  2633.  
  2634.  
  2635. #ifndef NOSPL
  2636.     debug(F101,"parser cmdlvl","",cmdlvl);
  2637.     debug(F101,"parser cmdsrc","",cmdstk[cmdlvl].src);
  2638.  
  2639.         if (cmdstk[cmdlvl].src == CMD_MD) { /* Executing a macro? */
  2640.         debug(F100,"parser macro","",0);
  2641.         maclvl = cmdstk[cmdlvl].lvl; /* Get current level */
  2642.         debug(F101,"parser maclvl","",maclvl);
  2643.         cbp = cmdbuf;        /* Copy next cmd to command buffer. */
  2644.         *cbp = NUL;
  2645.         if (*savbuf) {        /* In case then-part of 'if' command */
  2646.         ckstrncpy(cbp,savbuf,CMDBL); /* was saved, restore it. */
  2647.         *savbuf = '\0';
  2648.         } else {            /* Else get next cmd from macro def */
  2649.         if (getncm(cbp,CMDBL) < 0) {
  2650. #ifdef DEBUG
  2651.             if (deblog) {
  2652.             debug(F101,"parser end of macro m","",m);
  2653.             debug(F101,"parser end of macro cmdlvl","",cmdlvl);
  2654.             debug(F101,"parser end of macro inlevel","",inlevel);
  2655.             }
  2656. #endif /* DEBUG */
  2657.             if (m && (cmdlvl < inlevel))
  2658.               return((int) sstate);
  2659.             else /* if (!m) */ continue;
  2660.         }
  2661.         }
  2662.         debug(F010,"CMD(M)",cmdbuf,0);
  2663.  
  2664.     } else if (cmdstk[cmdlvl].src == CMD_TF)
  2665. #else
  2666.       if (tlevel > -1)
  2667. #endif /* NOSPL */
  2668.       {
  2669. #ifndef NOSPL
  2670.         debug(F111,"parser savbuf",savbuf,tlevel);
  2671.         if (*savbuf) {        /* In case THEN-part of IF command */
  2672.         ckstrncpy(cmdbuf,savbuf,CMDBL);    /* was saved, restore it. */
  2673.         *savbuf = '\0';
  2674.         } else
  2675. #endif /* NOSPL */
  2676.  
  2677.           /* Get next line from TAKE file */
  2678.  
  2679.           if ((tfcode = getnct(cmdbuf,CMDBL,tfile[tlevel],0)) < 0) {
  2680.           debug(F111,"parser tfcode",tfile[tlevel],tfcode); 
  2681.           if (tfcode < -1) {    /* Error */
  2682.               printf("?Error in TAKE command file: %s\n",
  2683.                  (tfcode == -2) ? "Memory allocation failure" :
  2684.                  "Line too long or contains NUL characters"
  2685.                  );
  2686.               dostop();
  2687.           }
  2688.           continue;        /* -1 means EOF */
  2689.           }
  2690.  
  2691.         /* If interactive, get next command from user. */
  2692.  
  2693.     } else {            /* User types it in. */
  2694.         if (pflag) prompt(xxstring);
  2695.         cmini(ckxech);
  2696.         }
  2697.  
  2698.     /* Now we know where next command is coming from. Parse and execute it. */
  2699.  
  2700.     repars = 1;            /* 1 = command needs parsing */
  2701. #ifndef NOXFER
  2702.     displa = 0;            /* Assume no file transfer display */
  2703. #endif /* NOXFER */
  2704.  
  2705.     while (repars) {        /* Parse this cmd until entered. */
  2706.  
  2707.         debug(F101,"parser top of while loop","",0);
  2708.  
  2709. #ifdef RECURSIVE
  2710.         /* In case of "send /recursive ./?<Ctrl-U>" etc */
  2711.         recursive = 0;        /* This is never sticky */
  2712. #endif /* RECURSIVE */
  2713.         xfiletype = -1;        /* Reset this between each command */
  2714. #ifndef NOMSEND
  2715.             addlist = 0;
  2716. #endif /* NOMSEND */
  2717. #ifdef CK_RECALL
  2718.         on_recall = 1;
  2719. #endif /* CK_RECALL */
  2720.         /* This might have been changed by a switch */
  2721.         if (g_matchdot > -1) {
  2722.         matchdot = g_matchdot;
  2723.         g_matchdot = -1;
  2724.         }
  2725.         cmres();            /* Reset buffer pointers. */
  2726.  
  2727. #ifdef OS2
  2728. #ifdef COMMENT
  2729.         /* we check to see if a macro is waiting to be executed */
  2730.         /* if so, we call domac on it */
  2731.         if (cmdmac) {
  2732.         ckstrncpy(cmdbuf, cmdmac, CMDBL);
  2733.         free(cmdmac);
  2734.         cmdmac = NULL;
  2735.         }
  2736. #endif /* COMMENT */
  2737. #endif /* OS2 */
  2738. #ifndef NOXFER
  2739.         bye_active = 0;
  2740. #endif /* NOXFER */
  2741.         havetoken = 0;
  2742.         xx = cmkey2(cmdtab,ncmd,"Command","",toktab,xxstring,1);
  2743.         debug(F101,"top-level cmkey2","",xx);
  2744.         if (xx == -5) {
  2745.         yy = chktok(toktab);
  2746.         debug(F101,"top-level cmkey token","",yy);
  2747. #ifndef COMMENT
  2748.         /* Either way makes absolutely no difference */
  2749.         debug(F110,"NO UNGWORD",atmbuf,0);
  2750.         /* ungword(); */
  2751. #else
  2752.         debug(F110,"TOKEN UNGWORD",atmbuf,0);
  2753.         ungword();
  2754. #endif /* COMMENT */
  2755.         switch (yy) {
  2756.           case '#': xx = XXCOM; break; /* Comment */
  2757.           case ';': xx = XXCOM; break; /* Comment */
  2758. #ifndef NOSPL
  2759.           case '.': xx = XXDEF; xxdot = 1; break; /* Assignment */
  2760.           case ':': xx = XXLBL; break; /* GOTO label */
  2761. #endif /* NOSPL */
  2762.  
  2763. #ifndef NOPUSH
  2764. #ifdef CK_REDIR
  2765.                   case '<':
  2766. #endif /* CK_REDIR */
  2767.                   case '@':
  2768.                   case '!':
  2769.             if (nopush) {
  2770.             char *s; int x;
  2771.             if ((x = cmtxt("Text to be ignored","",&s,NULL)) < 0)
  2772.               return(x);
  2773.             success = 0;
  2774.             xx = XXCOM;
  2775.             } else {
  2776.             switch(yy) {
  2777. #ifdef CK_REDIR
  2778.               case '<': xx = XXFUN; break; /* REDIRECT */
  2779. #endif /* CK_REDIR */
  2780.               case '@':
  2781.               case '!': xx = XXSHE; break; /* Shell escape */
  2782.             }
  2783.             }
  2784.             break;
  2785. #endif /* NOPUSH */
  2786. #ifdef CK_RECALL
  2787.           case '^': xx = XXREDO;  break;
  2788. #endif /* CK_RECALL */
  2789. #ifndef NOSPL
  2790.           case '{': xx = XXMACRO; break;
  2791.           case '(': xx = XXSEXP;  break;
  2792. #endif /* NOSPL */
  2793.  
  2794.           default:
  2795.             if (!quiet) {
  2796.             printf("\n?Invalid - \"%s\"\n",cmdbuf);
  2797. #ifdef COMMENT
  2798. #ifndef NOSPL
  2799.             if (maclvl > -1 && xcmdsrc == 2)
  2800.               printf("Macro: %s; ",
  2801.                  m_arg[maclvl][0] ?
  2802.                  m_arg[maclvl][0] : "");
  2803. #endif /* NOSPL */
  2804.             if (tlevel > -1) {
  2805.                 printf("Command file: %s, line %d\n",
  2806.                    tfnam[tlevel] ? tfnam[tlevel] : "",
  2807.                    tfline[tlevel]
  2808.                    );
  2809.             }
  2810. #else
  2811.             if (xcmdsrc > 0) {
  2812.                 printf("Command stack:\n");
  2813.                 shostack();
  2814.             }
  2815. #endif /* COMMENT */
  2816.  
  2817.             }
  2818.             xx = -2;
  2819.         }
  2820.         havetoken = 1;
  2821.         debug(F101,"HAVE TOKEN","",xx);
  2822.         }
  2823.         if (xx > -1) {
  2824.         topcmd = xx;        /* Top-level command index */
  2825. #ifndef NOSPL
  2826.         if (maclvl > -1)
  2827.           lastcmd[maclvl] = xx;
  2828. #endif /* NOSPL */
  2829.         debug(F101,"topcmd","",topcmd);
  2830.         debug(F101,"cmflgs","",cmflgs);
  2831.         }
  2832.  
  2833. #ifndef NOSPL
  2834.             /* Special handling for IF..ELSE */
  2835.  
  2836.             debug(F101,"cmdlvl","",cmdlvl);
  2837.             debug(F101,"ifcmd[cmdlvl]","",ifcmd[cmdlvl]);
  2838.  
  2839.         if (ifcmd[cmdlvl])        /* Count stmts after IF */
  2840.           ifcmd[cmdlvl]++;
  2841.         if (ifcmd[cmdlvl] > 2 && xx != XXELS && xx != XXCOM)
  2842.           ifcmd[cmdlvl] = 0;
  2843.  
  2844.         /* Execute the command and take action based on return code. */
  2845.  
  2846.         if (nulcmd) {        /* Ignoring this command? */
  2847.         xx = XXCOM;        /* Make this command a comment. */
  2848.         }
  2849.         fnsuccess = 1;        /* For catching \function() errors */
  2850. #endif /* NOSPL */
  2851.  
  2852.             debug(F101,"calling docmd()","",xx);
  2853.         zz = docmd(xx);        /* Parse rest of command & execute. */
  2854.  
  2855. #ifndef NOSPL
  2856.         if (fnerror && !fnsuccess)
  2857.           success = 0;
  2858. #endif /* NOSPL */
  2859.         debug(F101,"docmd returns","",zz);
  2860.         /* debug(F011,"cmdbuf",cmdbuf,30); */
  2861.         /* debug(F011,"atmbuf",atmbuf,30); */
  2862. #ifdef MAC
  2863.         if (tlevel > -1) {
  2864.         if (sstate == 'a') {    /* if cmd-. cancel */
  2865.             debug(F110, "parser: cancel take, sstate:", "a", 0);
  2866.             sstate = '\0';
  2867.             dostop();
  2868.             return(0);        /* End of init file or whatever. */
  2869.         }
  2870.         }
  2871. #endif /* MAC */
  2872.         switch (zz) {
  2873.           case -4:            /* EOF (e.g. on redirected stdin) */
  2874.         doexit(GOOD_EXIT,xitsta); /* ...exit successfully */
  2875.           case -1:            /* Reparse needed */
  2876.         repars = 1;        /* Just set reparse flag and... */
  2877.         continue;
  2878. #ifdef OS2
  2879.           case -7:            /* They typed a disk letter */
  2880.         if (!zchdir((char *)cmdbuf)) {
  2881.             perror((char *)cmdbuf);
  2882.             success = 0;
  2883.         } else success = 1;
  2884.         repars = 0;
  2885.         continue;
  2886.  
  2887. #endif /* OS2 */
  2888.           case -6:            /* Invalid command given w/no args */
  2889.           case -2:            /* Invalid command given w/args */
  2890. #ifdef COMMENT
  2891. #ifndef NOSPL
  2892.             /* This is going to be really ugly... */
  2893.             yy = mlook(mactab,atmbuf,nmac); /* Look in macro table */
  2894.             if (yy > -1) {                /* If it's there */
  2895.             if (zz == -2) {                /* insert "do" */
  2896.                 char *mp;
  2897.                 mp = malloc((int)strlen(cmdbuf) + 5);
  2898.                 if (!mp) {
  2899.                 printf("?malloc error 1\n");
  2900.                 return(-2);
  2901.                 }
  2902.                 sprintf(mp,"do %s ",cmdbuf); /* SAFE (checked) */
  2903.                 ckstrncpy(cmdbuf,mp,CMDBL);
  2904.                 free(mp);
  2905.                 mp = NULL;
  2906.             } else {
  2907.                 if (((int)strlen(atmbuf) + 5) < CMDBL)
  2908.                   sprintf(cmdbuf,"do %s %c",atmbuf, CR); /* SAFE */
  2909.                 else
  2910.                   ckstrncpy(cmdbuf,"echo ?Too long\r",CMDBL);
  2911.             }
  2912.             if (ifcmd[cmdlvl] == 2)    /* This one doesn't count! */
  2913.               ifcmd[cmdlvl]--;
  2914.             debug(F111,"stuff cmdbuf",cmdbuf,zz);
  2915.             repars = 1;    /* Go for reparse */
  2916.             continue;
  2917.             } else {
  2918.             char *p;
  2919.             int n;
  2920.             p = cmdbuf;
  2921.             lp = line;
  2922.             n = LINBUFSIZ;
  2923.             if (cmflgs == 0) printf("\n");
  2924.             if (zzstring(p,&lp,&n) > -1)
  2925.               printf("?Invalid: %s\n",line);
  2926.             else
  2927.               printf("?Invalid: %s\n",cmdbuf);
  2928.             } /* (fall thru...) */
  2929. #else
  2930.             printf("?Invalid: %s\n",cmdbuf);
  2931. #endif /* NOSPL */
  2932. #else /* Not COMMENT */
  2933.             printf("?Invalid: %s\n",cmdbuf);
  2934. #endif /* COMMENT */
  2935.  
  2936.         case -9:        /* Bad, error message already done */
  2937.             success = 0;
  2938.             debug(F110,"top-level cmkey failed",cmdbuf,0);
  2939.             /* If in background w/ commands coming stdin, terminate */
  2940.             if (pflag == 0 && tlevel < 0)
  2941.               fatal("Kermit command error in background execution");
  2942. /*
  2943.   Command retry feature, edit 190.  If we're at interactive prompting level,
  2944.   reprompt the user with as much of the command as didn't fail.
  2945. */
  2946. #ifdef CK_RECALL
  2947.             if (cm_retry && !xcmdsrc) { /* If at top level */
  2948.             int len;
  2949.             char *p, *s;
  2950.             len = strlen(cmdbuf); /* Length of command buffer */
  2951.             p = malloc(len + 1);  /* Allocate space for copy */
  2952.             if (p) {          /* If we got the space copy */
  2953.                 strcpy(p,cmdbuf); /* the command buffer (SAFE). */
  2954.                 /* Chop off final field, the one that failed. */
  2955.                 s = p + len - 1;          /* Point to end */
  2956.                 while (*s == SP && s > p) /* Trim blanks */
  2957.                   s--;
  2958.                 while (*s != SP && s > p) /* Trim last field */
  2959.                   s--;
  2960.                 if (s > p)        /* Keep the space */
  2961.                   s++;          /* after last good field */
  2962.                 if (s >= p)          /* Cut off remainder */
  2963.                   *s = NUL;
  2964.                 cmini(ckxech);    /* Reinitialize the parser */
  2965.                 ckstrncpy(cmdbuf,p,CMDBL); /* Copy result back */
  2966.                 free(p);          /* Free temporary storage */
  2967.                 p = NULL;
  2968.                 prompt(xxstring); /* Reprint the prompt */
  2969.                 printf("%s",cmdbuf); /* Reprint partial command */
  2970.                 repars = 1;          /* Force reparse */
  2971.                 continue;
  2972.             }
  2973.             } else
  2974. #endif /* CK_RECALL */
  2975.               if (!quiet) {
  2976. #ifdef COMMENT
  2977. #ifndef NOSPL
  2978.               if (maclvl > -1)
  2979.                 printf("Macro: %s; ",
  2980.                    m_arg[maclvl][0] ?
  2981.                    m_arg[maclvl][0] : "");
  2982. #endif /* NOSPL */
  2983.               if (tlevel > -1)
  2984.                 printf("Command file: %s, line %d\n",
  2985.                    tfnam[tlevel] ? tfnam[tlevel] : "",
  2986.                    tfline[tlevel]
  2987.                    );
  2988. #else
  2989.               if (xcmdsrc > 0) {
  2990.                   printf("Command stack:\n");
  2991.                   shostack();
  2992.               }
  2993. #endif /* COMMENT */
  2994.               }
  2995.               cmini(ckxech);    /* (fall thru) */
  2996.  
  2997.              case -3:        /* Empty command OK at top level */
  2998.             repars = 0;        /* Don't need to reparse. */
  2999.             continue;        /* Go back and get another command. */
  3000.  
  3001.         default:        /* Command was successful. */
  3002. #ifndef NOSPL
  3003.             debug(F101,"parser preparing to continue","",maclvl);
  3004. #endif /* NOSPL */
  3005.             debug(F101,"parser success","",success);
  3006.             repars = 0;        /* Don't need to reparse. */
  3007.             continue;        /* Go back and get another command. */
  3008.         }
  3009.     }
  3010. #ifndef NOSPL
  3011.     debug(F101,"parser breaks out of while loop","",maclvl);
  3012.     if (m && (cmdlvl < inlevel))  return((int) sstate);
  3013. #endif /* NOSPL */
  3014.     }
  3015.  
  3016. /* Got an action command, return start state. */
  3017.  
  3018.     return((int) sstate);
  3019. }
  3020.  
  3021. #ifndef NOSPL
  3022. /*
  3023.   OUTPUT command.
  3024.   Buffering and pacing added by L.I. Kirby, 5A(189), June 1993.
  3025. */
  3026. #define OBSIZE 80            /* Size of local character buffer */
  3027.  
  3028. static int obn;                /* Buffer offset (high water mark) */
  3029. static char obuf[OBSIZE+1];        /* OUTPUT buffer. */
  3030. static char *obp;            /* Pointer to output buffer. */
  3031. _PROTOTYP( static int oboc, (char) );
  3032. _PROTOTYP( static int xxout, (char *, int) );
  3033.  
  3034. static int
  3035. #ifdef CK_ANSIC
  3036. xxout(char *obuf, int obsize)
  3037. #else
  3038. xxout(obuf, obsize) char *obuf; int obsize;
  3039. #endif /* CK_ANSIC */
  3040. /* xxout */ {                /* OUTPUT command's output function */
  3041.     int i, rc;
  3042.  
  3043.     debug(F101,"xxout obsize","",obsize);
  3044.     debug(F101,"xxout pacing","",pacing);
  3045.     debug(F111,"xxout string",obuf,strlen(obuf));
  3046.  
  3047.     rc = 0;                /* Initial return code. */
  3048.     if (!obuf || (obsize <= 0))        /* Nothing to output. */
  3049.       goto xxout_x;            /* Return successfully */
  3050.  
  3051.     rc = -1;                  /* Now assume failure */
  3052.     if (pacing == 0) {              /* Is pacing enabled? */
  3053.     if ((local ?               /* No, write entire string at once */
  3054.          ttol((CHAR *)obuf, obsize) : /* to communications device */
  3055.          conxo(obsize, obuf))      /* or to console */
  3056.         != obsize)
  3057.       goto xxout_x;
  3058.     } else {
  3059.     for (i = 0; i < obsize; i++) {    /* Write individual chars */
  3060.         if ((local ? ttoc(obuf[i]) : conoc(obuf[i])) < 0)
  3061.           goto xxout_x;
  3062.         msleep(pacing);
  3063.     }
  3064.     }
  3065.     if (duplex) {
  3066. #ifdef OS2
  3067.         if (inecho && local) {
  3068. #ifndef NOLOCAL
  3069.             for (i = 0; i < obsize; i++) { /* Write to emulator */
  3070.                 scriptwrtbuf((USHORT)obuf[i]); /* which also logs session */
  3071.             }
  3072. #endif /* NOLOCAL */
  3073.             conxo(obsize,obuf);
  3074.         } else if (seslog) {        /* or log session here */
  3075.             logstr((char *) obuf, obsize);
  3076.         }
  3077. #else /* OS2 */
  3078.         if (seslog) {
  3079.             logstr((char *) obuf, obsize);
  3080.     }
  3081.         if (inecho && local) {
  3082.             conxo(obsize,obuf);
  3083.         }
  3084. #endif /* OS2 */
  3085.     }
  3086.     rc = 0;                /* Success */
  3087.   xxout_x:
  3088.     obn = 0;                /* Reset count */
  3089.     obp = obuf;                /* and pointers */
  3090.     return(rc);                /* return our return code */
  3091. }
  3092.  
  3093. #ifdef COMMENT
  3094. /*
  3095.   Macros for OUTPUT command execution, to make it go faster.
  3096. */
  3097. #define obfls() ((xxout(obuf,obn)<0)?-1:0)
  3098. #define oboc(c) ((*obp++=(char)(c)),*obp=0,(((++obn)>=OBSIZE)?obfls():0))
  3099.  
  3100. #else /* The macros cause some compilers to generate bad code. */
  3101.  
  3102. static int
  3103. #ifdef CK_ANSIC
  3104. oboc(char c)
  3105. #else
  3106. oboc(c) char c;
  3107. #endif /* CK_ANSIC */
  3108. /* oboc */ {                /* OUTPUT command's output function */
  3109.  
  3110.     *obp++ = c;                /* Deposit character */
  3111.     *obp = NUL;                /* Flush buffer if it's now full */
  3112.  
  3113.     return(((++obn) >= OBSIZE) ? xxout(obuf,obn) : 0);
  3114. }
  3115. #endif /* COMMENT */
  3116.  
  3117. /*  Routines for handling local variables -- also see popclvl().  */
  3118.  
  3119. VOID
  3120. freelocal(m) int m; {            /* Free local variables */
  3121.     struct localvar * v, * tv;        /* at macro level m... */
  3122.     debug(F101,"freelocal level","",m);
  3123.     if (m < 0) return;
  3124.     v = localhead[m];            /* List head for level m */
  3125.     while (v) {
  3126.     if (v->lv_name)            /* Variable name */
  3127.       free(v->lv_name);
  3128.     if (v->lv_value)        /* Value */
  3129.       free(v->lv_value);
  3130.     tv = v;                /* Save pointer to this node */
  3131.     v = v->lv_next;            /* Get next one */
  3132.     if (tv)                /* Free this one */
  3133.       free((char *)tv);
  3134.     }
  3135.     localhead[m] = (struct localvar *) NULL; /* Done, set list head to NULL */
  3136. }
  3137.  
  3138. #define MAXLOCALVAR 64
  3139.  
  3140. /* Return a pointer to the definition of a user-defined variable */
  3141.  
  3142. static char *
  3143. vardef(s,isarray,x1,x2) char * s; int * isarray, * x1, * x2; {
  3144.     char * p;
  3145.     char c;
  3146.     *isarray = 0;
  3147.     if (!s) return(NULL);
  3148.     if (!*s) return(NULL);
  3149.     p = s;
  3150.     if (*s == CMDQ) {
  3151.     p++;
  3152.     if (!*p)
  3153.       return(NULL);
  3154.         if ((c = *p) == '%') {          /* Scalar variable. */
  3155.             c = *++p;                   /* Get ID character. */
  3156.             p = "";                     /* Assume definition is empty */
  3157.             if (!c)
  3158.           return(NULL);
  3159.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  3160.                 if (maclvl < 0)         /* Digit variables are global */
  3161.                   return(g_var[c]);    /* if no macro is active */
  3162.                 else                    /* otherwise */
  3163.                   return(m_arg[maclvl][c - '0']); /* they're on the stack */
  3164.             } else if (isalpha(c)) {
  3165.                 if (isupper(c)) c -= ('a'-'A');
  3166.                 return(g_var[c]);           /* Letter for global variable */
  3167.             } else
  3168.           return(NULL);
  3169.         } else if (c == '&') {        /* Array reference. */
  3170.             int x, vbi, d;
  3171.         x = arraynam(p,&vbi,&d);    /* Get name and subscript */
  3172.         if (x > -1 || d == -17) {
  3173.         *isarray = 1;
  3174.         *x1 = vbi;
  3175.         *x2 = (d == -17) ? 0 : d;
  3176.         }
  3177.             if (x < 0)
  3178.           return(NULL);
  3179.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  3180.                 vbi -= ARRAYBASE;       /* Convert name to index */
  3181.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  3182.                     char **ap;
  3183.             ap = a_ptr[vbi];
  3184.             return((ap) ? ap[d] : NULL);
  3185.                 }
  3186.             }
  3187.         }
  3188.     return(NULL);
  3189.     } else {
  3190.     int k;
  3191.         k = mxlook(mactab,s,nmac);
  3192.     return((k > -1) ? mactab[k].mval : NULL);
  3193.     }
  3194. }
  3195.  
  3196.  
  3197. int
  3198. addlocal(p) char * p; {
  3199.     int x, z, isarray = 0;
  3200.     char * s;
  3201.     struct localvar * v, *prev = (struct localvar *)NULL;
  3202.     extern int tra_asg; int tra_tmp;
  3203.  
  3204.     tra_tmp = tra_asg;
  3205.  
  3206.     s = vardef(p,&isarray,&x,&z);    /* Get definition of variable */
  3207.     if (isarray) {            /* Arrays are handled specially */
  3208.     pusharray(x,z);
  3209.     return(0);
  3210.     }
  3211.     if (!s) s = "";
  3212.     if ((v = localhead[cmdlvl])) {    /* Already have some at this level? */
  3213.     while (v) {            /* Find end of list */
  3214.         prev = v;
  3215.         v = v->lv_next;
  3216.     }
  3217.     }
  3218.     v = (struct localvar *) malloc(sizeof(struct localvar));
  3219.     if (!v) {
  3220.     printf("?Failure to allocate storage for local variables");
  3221.     return(-9);
  3222.     }
  3223.     if (!localhead[cmdlvl])        /* If first, set list head */
  3224.       localhead[cmdlvl] = v;
  3225.     else                /* Otherwise link previous to this */
  3226.       prev->lv_next = v;
  3227.     prev = v;                /* And make this previous */
  3228.     v->lv_next = (struct localvar *) NULL; /* No next yet */
  3229.  
  3230.     if (!(v->lv_name = (char *) malloc((int) strlen(p) + 1)))
  3231.       return(-1);
  3232.     strcpy(v->lv_name, p);        /* Copy name into new node (SAFE) */
  3233.  
  3234.     if (*s) {
  3235.     if (!(v->lv_value = (char *) malloc((int) strlen(s) + 1)))
  3236.       return(-1);
  3237.     strcpy(v->lv_value, s);        /* Copy value into new node (SAFE) */
  3238.     } else
  3239.       v->lv_value = NULL;
  3240.  
  3241.     tra_asg = 0;
  3242.     delmac(p,1);            /* Delete the original macro */
  3243.     tra_asg = tra_tmp;
  3244.     return(0);
  3245. }
  3246.  
  3247. int
  3248. dolocal() {                /* Do the LOCAL command */
  3249.     int i, x;
  3250.     char * s;
  3251.     char * list[MAXLOCALVAR+2];        /* Up to 64 variables per line */
  3252.  
  3253.     if ((x = cmtxt("Variable name(s)","",&s,NULL)) < 0)
  3254.       return(x);
  3255.  
  3256.     xwords(s,MAXLOCALVAR,list,0);    /* Break up line into "words" */
  3257.  
  3258.     /* Note: Arrays do not use the localhead list, but have their own stack */
  3259.  
  3260.     for (i = 1; i < MAXLOCALVAR && list[i]; i++) { /* Go through the list */
  3261.     if (addlocal(list[i]) < 0)
  3262.       goto localbad;
  3263.     }
  3264.     return(success = 1);
  3265.  
  3266.   localbad:
  3267.     printf("?Failure to allocate storage for local variables");
  3268.     freelocal(cmdlvl);
  3269.     return(-9);
  3270. }
  3271.  
  3272. /*  D O O U T P U T  --  Returns 0 on failure, 1 on success */
  3273.  
  3274. #ifndef NOKVERBS
  3275. #define K_BUFLEN 30
  3276. #define SEND_BUFLEN 255
  3277. #define sendbufd(x) { osendbuf[sendndx++] = x;\
  3278.  if (sendndx == SEND_BUFLEN) {dooutput(s,cx); sendndx = 0;}}
  3279. #endif /* NOKVERBS */
  3280.  
  3281. int outesc = 1;                /* Process special OUTPUT escapes */
  3282.  
  3283. int
  3284. dooutput(s, cx) char *s; int cx; {
  3285.  
  3286.     int x, xx, y, quote;        /* Workers */
  3287.     int is_tn = 0;
  3288.  
  3289.     is_tn = (local && network && ttnproto == NP_TELNET) ||
  3290.       (!local && sstelnet);
  3291.  
  3292.     debug(F111,"dooutput s",s,(int)strlen(s));
  3293.  
  3294.     if (local) {            /* Condition external line */
  3295. #ifdef NOLOCAL
  3296.     goto outerr;
  3297. #else
  3298.     if (ttchk() < 0) {
  3299.         printf("?Connection %s %s is not open.\n",
  3300.            network ? "to" : "on",
  3301.            ttname
  3302.            );
  3303.         return(0);
  3304.     }
  3305.     if (ttvt(speed,flow) < 0) {
  3306.         printf("?OUTPUT initialization error\n");
  3307.         return(0);
  3308.     }
  3309. #endif /* NOLOCAL */
  3310.     }
  3311.     if (!cmdgquo()) {            /* COMMAND QUOTING OFF */
  3312.     x = strlen(s);            /* Just send the string literally */
  3313.     xx = local ? ttol((CHAR *)s,x) : conxo(x,s);
  3314.     return(success = (xx == x) ? 1 : 0);
  3315.     }
  3316.     quote = 0;                /* Initialize backslash (\) quote */
  3317.     obn = 0;                /* Reset count */
  3318.     obp = obuf;                /* and pointers */
  3319.  
  3320.   outagain:
  3321.     while ((x = *s++)) {        /* Loop through the string */
  3322.     y = 0;                /* Error code, 0 = no error. */
  3323.     debug(F000,"dooutput","",x);
  3324.     if (quote) {            /* This character is quoted */
  3325. #ifndef NOKVERBS
  3326.            if (x == 'k' || x == 'K') {    /* \k or \K */
  3327.                extern struct keytab kverbs[];
  3328.                extern int nkverbs;
  3329.                extern char * keydefptr;
  3330.                extern int keymac;
  3331.                extern int keymacx;
  3332.                int x, y, brace = 0;
  3333.                int pause;
  3334.                char * p, * b;
  3335.                char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  3336.            char osendbuf[SEND_BUFLEN +1];
  3337.                int  sendndx = 0;
  3338.  
  3339.            if (xxout(obuf,obn) < 0) /* Flush buffer */
  3340.          goto outerr;
  3341.            debug(F100,"OUTPUT KVERB","",0); /* Send a KVERB */
  3342.                {            /* Have K verb? */
  3343.            if (!*s) {
  3344.                        break;
  3345.                    }
  3346. /*
  3347.   We assume that the verb name is {braced}, or it extends to the end of the
  3348.   string, s, or it ends with a space, control character, or backslash.
  3349. */
  3350.                    p = kbuf;        /* Copy verb name into local buffer */
  3351.                    x = 0;
  3352.                    while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  3353.                        if (brace && *s == '}') {
  3354.                            break;
  3355.                        }
  3356.                        *p++ = *s++;
  3357.                    }
  3358.                    if (*s && !brace)    /* If we broke because of \, etc, */
  3359.                      s--;        /*  back up so we get another look. */
  3360.                    brace = 0;
  3361.                    *p = NUL;        /* Terminate. */
  3362.                    p = kbuf;        /* Point back to beginning */
  3363.                    debug(F110,"dooutput kverb",p,0);
  3364.                    y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  3365.                    debug(F101,"dooutput lookup",0,y);
  3366.                    if (y > -1) {
  3367.                        if (sendndx) {
  3368.                            dooutput(osendbuf,cx);
  3369.                            sendndx = 0;
  3370.                        }
  3371.                        dokverb(VCMD,y);
  3372. #ifndef NOSPL
  3373.                    } else {        /* Is it a macro? */
  3374.                        y = mxlook(mactab,p,nmac);
  3375.                        if (y > -1) {
  3376.                            cmpush();
  3377.                            keymac = 1;    /* Flag for key macro active */
  3378.                            keymacx = y;    /* Key macro index */
  3379.                            keydefptr = s; /* Where to resume next time */
  3380.                            debug(F111,"dooutput mxlook",keydefptr,y);
  3381.                            parser(1);
  3382.                            cmpop();
  3383.                        }
  3384. #endif /* NOSPL */
  3385.                    }
  3386.                }
  3387.                quote = 0;
  3388.            continue;
  3389.        } else
  3390. #endif /* NOKVERBS */
  3391.          if (outesc && (x == 'n' || x == 'N')) { /* \n or \N */
  3392.          if (xxout(obuf,obn) < 0) /* Flush buffer */
  3393.            goto outerr;
  3394.          debug(F100,"OUTPUT NUL","",0); /* Send a NUL */
  3395.          if (local)
  3396.            ttoc(NUL);
  3397.          else
  3398.            conoc(NUL);
  3399.          quote = 0;
  3400.          continue;
  3401.  
  3402.          } else if (outesc && (x == 'b' || x == 'B')) { /* \b or \B */
  3403.  
  3404.         if (xxout(obuf,obn) < 0) /* Flush buffer first */
  3405.           goto outerr;
  3406.         debug(F100,"OUTPUT BREAK","",0);
  3407. #ifndef NOLOCAL
  3408.         ttsndb();        /* Send BREAK signal */
  3409. #else
  3410.          if (local)
  3411.            ttoc(NUL);
  3412.          else
  3413.            conoc(NUL);
  3414. #endif /* NOLOCAL */
  3415.         quote = 0;        /* Turn off quote flag */
  3416.         continue;        /* and not the b or B */
  3417. #ifdef CK_LBRK
  3418.          } else if (outesc && (x == 'l' || x == 'L')) { /* \l or \L */
  3419.          if (xxout(obuf,obn) < 0) /* Flush buffer first */
  3420.            goto outerr;
  3421.          debug(F100,"OUTPUT Long BREAK","",0);
  3422. #ifndef NOLOCAL
  3423.          ttsndlb();        /* Send Long BREAK signal */
  3424. #else
  3425.          if (local)
  3426.            ttoc(NUL);
  3427.          else
  3428.            conoc(NUL);
  3429. #endif /* NOLOCAL */
  3430.          quote = 0;        /* Turn off quote flag */
  3431.          continue;        /* and not the l or L */
  3432. #endif /* CK_LBRK */
  3433.  
  3434.          } else if (x == CMDQ) {    /* Backslash itself */
  3435.          debug(F100,"OUTPUT CMDQ","",0);
  3436.          xx = oboc(dopar(CMDQ)); /* Output the backslash. */
  3437.          if (xx < 0)
  3438.            goto outerr;
  3439.          quote = 0;
  3440.          continue;
  3441.  
  3442.          } else {            /* if \ not followed by special esc */
  3443.         /* Note: Atari ST compiler won't allow macro call in "if ()" */
  3444.          xx = oboc(dopar(CMDQ)); /* Output the backslash. */
  3445.          if (xx < 0)
  3446.            goto outerr;
  3447.          quote = 0;        /* Turn off quote flag */
  3448.          }
  3449.     } else if (x == CMDQ) {        /* This is the quote character */
  3450.             quote = 1;            /* Go back and get next character */
  3451.         continue;            /* which is quoted */
  3452.     }
  3453.     xx = oboc(dopar((char)x));    /* Output this character */
  3454.     debug(F111,"dooutput",obuf,obn);
  3455.     if (xx < 0)
  3456.       goto outerr;
  3457. #ifdef COMMENT
  3458.         if (seslog && duplex) {        /* Log the character if log is on */
  3459.             logchar((char)x);
  3460.         }
  3461. #endif /* COMMENT */
  3462.     if (x == '\015') {        /* String contains carriage return */
  3463.         int stuff = -1, stuff2 = -1;
  3464.         if (tnlm) {            /* TERMINAL NEWLINE ON */
  3465.         stuff = LF;        /* Stuff LF */
  3466.         }
  3467. #ifdef TNCODE
  3468.         /* TELNET NEWLINE ON/OFF/RAW */
  3469.         if (is_tn) {
  3470.         switch (TELOPT_ME(TELOPT_BINARY) ? /* NVT or BINARY */
  3471.             tn_b_nlm :
  3472.             tn_nlm
  3473.             ) {
  3474.           case TNL_CR:
  3475.                     break;
  3476.           case TNL_CRNUL:
  3477.                     stuff2 = stuff;
  3478.                     stuff  = NUL;
  3479.                     break;
  3480.           case TNL_CRLF:
  3481.                     stuff2 = stuff;
  3482.                     stuff = LF;
  3483.                     break;
  3484.                 }
  3485.             }
  3486. #endif /* TNCODE */
  3487.         if (stuff > -1) {        /* Stuffing another character... */
  3488.         xx = oboc(dopar((CHAR)stuff));
  3489.         if (xx < 0)
  3490.           goto outerr;
  3491. #ifdef COMMENT
  3492.         if (seslog && duplex) {    /* Log stuffed char if appropriate */
  3493.                     logchar((char)stuff);
  3494.                 }
  3495. #endif /* COMMENT */
  3496.         }
  3497.         if (stuff2 > -1) {        /* Stuffing another character... */
  3498.         xx = oboc(dopar((CHAR)stuff2));
  3499.         if (xx < 0)
  3500.           goto outerr;
  3501. #ifdef COMMENT
  3502.         if (seslog && duplex) {    /* Log stuffed char if appropriate */
  3503.                     logchar((char)stuff2);
  3504.                 }
  3505. #endif /* COMMENT */
  3506.         }
  3507.         if (xxout(obuf,obn) < 0)    /* Flushing is required here! */
  3508.           goto outerr;
  3509.     }
  3510.     }
  3511.     if (cx == XXLNOUT) {
  3512.     s = "\015";
  3513.     cx = 0;
  3514.     goto outagain;
  3515.     }
  3516.     if (quote == 1)            /* String ended with backslash */
  3517.       xx = oboc(dopar(CMDQ));
  3518.  
  3519.     if (obn > 0)            /* OUTPUT done */
  3520.       if (xxout(obuf,obn) < 0)        /* Flush the buffer if necessary. */
  3521.     goto outerr;
  3522.     return(1);
  3523.  
  3524. outerr:                    /* OUTPUT command error handler */
  3525.     if (msgflg) printf("?OUTPUT execution error\n");
  3526.     return(0);
  3527.  
  3528. /* Remove "local" OUTPUT macro defininitions */
  3529.  
  3530. #ifdef COMMENT
  3531. /* No more macros ... */
  3532. #undef oboc
  3533. #undef obfls
  3534. #endif /* COMMENT */
  3535. }
  3536. #endif /* NOSPL */
  3537.  
  3538. /* Display version herald and initial prompt */
  3539.  
  3540. VOID
  3541. herald() {
  3542.     int x = 0, i;
  3543.     extern int srvcdmsg;
  3544.     extern char * cdmsgfile[];
  3545. #ifndef NOCMDL
  3546.     extern char * bannerfile;
  3547.     if (bannerfile) {
  3548.     concb((char)escape);
  3549.     if (dotype(bannerfile,1,0,0,NULL,0,NULL,0,0,NULL,0) > 0) {
  3550.         if (srvcdmsg) {
  3551.         for (i = 0; i < 8; i++) {
  3552.             if (zchki(cdmsgfile[i]) > -1) {
  3553.             printf("\n");
  3554.             dotype(cdmsgfile[i],
  3555.                    xaskmore,0,0,NULL,0,NULL,0,0,NULL,0);
  3556.             break;
  3557.             }
  3558.         }
  3559.         }
  3560.             return;
  3561.         }
  3562.     }
  3563. #endif /* NOCMDL */
  3564.  
  3565. #ifdef COMMENT
  3566.     /* The following generates bad code in SCO compilers. */
  3567.     /* Observed in both OSR5 and Unixware 2 -- after executing this */
  3568.     /* statement when all conditions are false, x has a value of -32. */
  3569.     if (noherald || bgset > 0 || (bgset != 0 && backgrd != 0)) x = 1;
  3570. #else
  3571.     x = 0;
  3572.     if (noherald)
  3573.       x = 1;
  3574.     else if (bgset > 0)
  3575.       x = 1;
  3576.     else if (bgset < 0 && backgrd > 0)
  3577.       x = 1;
  3578. #endif /* COMMENT */
  3579.  
  3580.     if (x == 0) {
  3581. #ifdef datageneral
  3582.     printf("%s, for%s\n",versio,ckxsys);
  3583. #else
  3584. #ifdef OSK
  3585.     printf("%s, for%s\n",versio,ckxsys);
  3586. #else
  3587.     printf("%s, for%s\n\r",versio,ckxsys);
  3588. #endif /* OSK */
  3589. #endif /* datageneral */
  3590.     printf(" Copyright (C) 1985, 2001,\n");
  3591.     printf("  Trustees of Columbia University in the City of New York.\n");
  3592.  
  3593. #ifdef OS2
  3594.        shoreg();
  3595. #endif /* OS2 */
  3596.  
  3597.     if (!quiet && !backgrd) {
  3598. #ifdef COMMENT
  3599. /* "Default file-transfer mode is AUTOMATIC" is useless information... */
  3600.         char * s;
  3601.         extern int xfermode;
  3602. #ifdef VMS
  3603.         s = "AUTOMATIC";
  3604. #else
  3605.         if (xfermode == XMODE_A) {
  3606.         s = "AUTOMATIC";
  3607.         } else {
  3608.         s = gfmode(binary,1);
  3609.         }
  3610.         if (!s) s = "";
  3611. #endif /* VMS */
  3612.         if (*s)
  3613.           printf("Default file-transfer mode is %s\n", s);
  3614. #endif /* COMMENT */
  3615.  
  3616.         if (srvcdmsg) {
  3617.         for (i = 0; i < 8; i++) {
  3618.             if (zchki(cdmsgfile[i]) > -1) {
  3619.             printf("\n");
  3620.             dotype(cdmsgfile[i],
  3621.                    xaskmore,0,0,NULL,0,NULL,0,0,NULL,0);
  3622.             break;
  3623.             }
  3624.         }
  3625.         }
  3626.         printf("Type ? or HELP for help.\n");
  3627.     }
  3628.     }
  3629. }
  3630.  
  3631. /*  G F M O D E  --  Get File (transfer) Mode  */
  3632.  
  3633. char *
  3634. gfmode(binary,upcase) int binary, upcase; {
  3635.     char * s;
  3636.     switch (binary) {
  3637.       case XYFT_T: s = upcase ? "TEXT" : "text"; break;
  3638. #ifdef VMS
  3639.       case XYFT_B: s = upcase ? "BINARY FIXED" : "binary fixed"; break;
  3640.       case XYFT_I: s = upcase ? "IMAGE" : "image"; break;
  3641.       case XYFT_L: s = upcase ? "LABELED" : "labeled"; break;
  3642.       case XYFT_U: s = upcase ? "BINARY UNDEF" : "binary undef"; break;
  3643. #else
  3644. #ifdef MAC
  3645.       case XYFT_B: s = upcase ? "BINARY" : "binary"; break;
  3646.       case XYFT_M: s = upcase ? "MACBINARY" : "macbinary"; break;
  3647. #else
  3648.       case XYFT_B: s = upcase ? "BINARY" : "binary"; break;
  3649. #ifdef CK_LABELED
  3650.       case XYFT_L: s = upcase ? "LABELED" : "labeled"; break;
  3651. #endif /* CK_LABELED */
  3652. #endif /* MAC */
  3653. #endif /* VMS */
  3654.       case XYFT_X: s = upcase ? "TENEX" : "tenex"; break;
  3655.       default: s = "";
  3656.     }
  3657.     return(s);
  3658. }
  3659.  
  3660. #ifndef NOSPL
  3661. static int
  3662. isaa(s) char * s; {            /* Is associative array */
  3663.     char c;
  3664.     int x;
  3665.     if (!s) s = "";
  3666.     if (!*s) return(0);
  3667.     s++;
  3668.     while ((c = *s++)) {
  3669.     if (c == '<') {
  3670.         x = strlen(s);
  3671.         return ((*(s+x-1) == '>') ? 1 : 0);
  3672.     }
  3673.     }
  3674.     return(0);
  3675. }
  3676.  
  3677. /*  M L O O K  --  Lookup the macro name in the macro table  */
  3678.  
  3679. /*
  3680.   Call this way:  v = mlook(table,word,n);
  3681.  
  3682.     table - a 'struct mtab' table.
  3683.     word  - the target string to look up in the table.
  3684.     n     - the number of elements in the table.
  3685.  
  3686.   The keyword table must be arranged in ascending alphabetical order, and
  3687.   all letters must be lowercase.
  3688.  
  3689.   Returns the table index, 0 or greater, if the name was found, or:
  3690.  
  3691.    -3 if nothing to look up (target was null),
  3692.    -2 if ambiguous,
  3693.    -1 if not found.
  3694.  
  3695.   A match is successful if the target matches a keyword exactly, or if
  3696.   the target is a prefix of exactly one keyword.  It is ambiguous if the
  3697.   target matches two or more keywords from the table.
  3698. */
  3699. int
  3700. mlook(table,cmd,n) struct mtab table[]; char *cmd; int n; {
  3701.     register int i;
  3702.     int v, w, cmdlen = 0;
  3703.     char c = 0, c1, * s;
  3704.     if (!cmd) cmd = "";
  3705.  
  3706.     for (s = cmd; *s; s++) cmdlen++;    /* (instead of strlen) */
  3707.     debug(F111,"MLOOK",cmd,cmdlen);
  3708.  
  3709.     c1 = *cmd;
  3710.     if (isupper(c1))
  3711.       c1 = tolower(c1);
  3712.     if (cmdlen < 1)
  3713.       return(-3);
  3714.  
  3715. /* Not null, look it up */
  3716.  
  3717.     if (n < 12) {            /* Not worth it for small tables */
  3718.     i = 0;
  3719.     } else {                /* Binary search for where to start */
  3720.     int lo = 0;
  3721.     int hi = n;
  3722.     int count = 0;
  3723.     while (lo+2 < hi && ++count < 12) {
  3724.         i = lo + ((hi - lo) / 2);
  3725.         c = *(table[i].kwd);
  3726.         if (isupper(c)) c = tolower(c);
  3727.         if (c < c1) {
  3728.         lo = i;
  3729.         } else {
  3730.         hi = i;
  3731.         }
  3732.     }
  3733.     i = (c < c1) ? lo+1 : lo;
  3734.     }
  3735.     for ( ; i < n-1; i++) {
  3736.     s = table[i].kwd;
  3737.     if (!s) s = "";
  3738.     if (!*s) continue;        /* Empty table entry */
  3739.     c = *s;
  3740.     if (isupper(c)) c = tolower(c);
  3741.     if (c1 != c) continue;        /* First char doesn't match */
  3742.     if (!ckstrcmp(s,cmd,-1,0))    /* Have exact match? */
  3743.       return(i);
  3744.     v = !ckstrcmp(s,cmd,cmdlen,0);
  3745.     w = ckstrcmp(table[i+1].kwd,cmd,cmdlen,0);
  3746.     if (v && w)            /* Have abbreviated match? */
  3747.       return(i);
  3748.         if (v)                /* Ambiguous? */
  3749.       return(-2);
  3750.     if (w > 0)            /* Past our alphabetic area? */
  3751.       return(-1);
  3752.     }
  3753.  
  3754. /* Last (or only) element */
  3755.  
  3756.     if (!ckstrcmp(table[n-1].kwd,cmd,cmdlen,0))
  3757.       return(n-1);
  3758.  
  3759.     return(-1);
  3760. }
  3761.  
  3762. /* mxlook is like mlook, but an exact full-length match is required */
  3763.  
  3764. int
  3765. mxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  3766.     register int i;
  3767.     int w, cmdlen = 0, one = 0;
  3768.     register char c = 0, c1, * s;
  3769.  
  3770.     if (!cmd) cmd = "";            /* Check args */
  3771.  
  3772.     for (s = cmd; *s; s++) cmdlen++;    /* (instead of strlen) */
  3773.     debug(F111,"MXLOOK",cmd,cmdlen);
  3774.  
  3775.     c1 = *cmd;                /* First char of string to look up */
  3776.     if (isupper(c1))
  3777.       c1 = tolower(c1);
  3778.     if (!*(cmd+1))            /* Special handling for 1-char names */
  3779.       one = 1;
  3780.  
  3781.     if (cmdlen < 1)            /* Nothing to look up */
  3782.       return(-3);
  3783.  
  3784.     if (n < 12) {            /* Not worth it for small tables */
  3785.     i = 0;
  3786.     } else {                /* Binary search for where to start */
  3787.     int lo = 0;
  3788.     int hi = n;
  3789.     int count = 0;
  3790.     while (lo+2 < hi && ++count < 12) {
  3791.         i = lo + ((hi - lo) / 2);
  3792.         c = *(table[i].kwd);
  3793.         if (isupper(c)) c = tolower(c);
  3794.         if (c < c1) {
  3795.         lo = i;
  3796.         } else {
  3797.         hi = i;
  3798.         }
  3799.     }
  3800.     i = (c < c1) ? lo+1 : lo;
  3801.     }
  3802.     for ( ; i < n; i++) {        /* Look thru table */
  3803.     s = table[i].kwd;        /* This entry */
  3804.     if (!s) s = "";
  3805.     if (!*s) continue;        /* Empty table entry */
  3806.     c = *s;
  3807.     if (isupper(c)) c = tolower(c);
  3808.     if (c1 != c) continue;        /* First char doesn't match */
  3809.     if (one) {            /* Name is one char long */
  3810.         if (!*(s+1))
  3811.           return(i);        /* So is table entry */
  3812.     }
  3813. #ifdef COMMENT
  3814.     if (((int)strlen(s) == cmdlen) &&
  3815.         (!ckstrcmp(s,cmd,cmdlen,0))) return(i);
  3816. #else
  3817.     w = ckstrcmp(s,cmd,-1,0);
  3818.     if (!w) return(i);
  3819.     if (w > 0) return(-1);
  3820. #endif /* COMMENT */
  3821.     }
  3822.     return(-1);
  3823. }
  3824.  
  3825. /* mxxlook is like mxlook, but case-sensitive */
  3826.  
  3827. int
  3828. mxxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  3829.     int i, cmdlen;
  3830.     if (!cmd) cmd = "";
  3831.     if (((cmdlen = strlen(cmd)) < 1) || (n < 1)) return(-3);
  3832.     /* debug(F111,"mxxlook target",cmd,n); */
  3833.     for (i = 0; i < n; i++) {
  3834.     if (((int)strlen(table[i].kwd) == cmdlen) &&
  3835.         (!strncmp(table[i].kwd,cmd,cmdlen)))
  3836.       return(i);
  3837.     }
  3838.     return(-1);
  3839. }
  3840.  
  3841. static int
  3842. traceval(nam, val) char * nam, * val; {    /* For TRACE command */
  3843.     if (val)
  3844.       printf(">>> %s: \"%s\"\n", nam, val);
  3845.     else
  3846.       printf(">>> %s: (undef)\n", nam);
  3847.     return(0);
  3848. }
  3849.  
  3850. #ifdef USE_VARLEN            /* Not used */
  3851.  
  3852. /*  V A R L E N  --  Get length of variable's value.
  3853.  
  3854.   Given a variable name, return the length of its definition or 0 if the
  3855.   variable is not defined.  If it is defined, set argument s to point to its
  3856.   definition.  Otherwise set s to NULL.
  3857. */
  3858. int
  3859. varlen(nam,s) char *nam; char **s; {    /* Length of value of variable */
  3860.     int x, z;
  3861.     char *p = NULL, c;
  3862.  
  3863.     *s = NULL;
  3864.     if (!nam) return(0);        /* Watch out for null pointer */
  3865.     if (*nam == CMDQ) {
  3866.     nam++;
  3867.     if (*nam == '%') {        /* If it's a variable name */
  3868.         if (!(c = *(nam+1))) return(0); /* Get letter or digit */
  3869.         p = (char *)0;        /* Initialize value pointer */
  3870.         if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */
  3871.         p = m_arg[maclvl][c - '0']; /* Pointer from macro-arg table */
  3872.         } else {            /* It's a global variable */
  3873.         if (c < 33 || c > GVARS) return(0);
  3874.         p = g_var[c];        /* Get pointer from global-var table */
  3875.         }
  3876.     } else if (*nam == '&') {        /* An array reference? */
  3877.         char **q;
  3878.         if (arraynam(nam,&x,&z) < 0) /* If syntax is bad */
  3879.           return(-1);        /* return -1. */
  3880.         x -= ARRAYBASE;        /* Convert name to number. */
  3881.         if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  3882.           return(0);        /* return -2. */
  3883.         if (z > a_dim[x])        /* If subscript out of range, */
  3884.           return(0);        /* return -3. */
  3885.         p = q[z];
  3886.     }
  3887.     } else {                /* Macro */
  3888.     z = isaa(nam);
  3889.     x = z ? mxxlook(mactab,nam,nmac) : mlook(mactab,nam,nmac);
  3890.     if (x < 0)
  3891.       return(0);
  3892.     p = mactab[x].mval;
  3893.     }
  3894.     if (p)
  3895.       *s = p;
  3896.     else
  3897.       p = "";
  3898.     return((int)strlen(p));
  3899. }
  3900. #endif /* USE_VARLEN */
  3901.  
  3902. /*
  3903.   This routine is for the benefit of those compilers that can't handle
  3904.   long string constants or continued lines within them.  Long predefined
  3905.   macros like FOR, WHILE, and XIF have their contents broken up into
  3906.   arrays of string pointers.  This routine concatenates them back into a
  3907.   single string again, and then calls the real addmac() routine to enter
  3908.   the definition into the macro table.
  3909. */
  3910. int
  3911. addmmac(nam,s) char *nam, *s[]; {    /* Add a multiline macro definition */
  3912.     int i, x, y; char *p;
  3913.     x = 0;                /* Length counter */
  3914.     for (i = 0; (y = (int)strlen(s[i])) > 0; i++) { /* Add up total length */
  3915.         debug(F111,"addmmac line",s[i],y);
  3916.     x += y;
  3917.     }
  3918.     debug(F101,"addmmac lines","",i);
  3919.     debug(F101,"addmmac loop exit","",y);
  3920.     debug(F111,"addmmac length",nam,x);
  3921.     if (x < 0) return(-1);
  3922.  
  3923.     p = malloc(x+1);            /* Allocate space for all of it. */
  3924.     if (!p) {
  3925.     printf("?addmmac malloc error: %s\n",nam);
  3926.     debug(F110,"addmmac malloc error",nam,0);
  3927.     return(-1);
  3928.     }
  3929.     *p = '\0';                /* Start off with null string. */
  3930.     for (i = 0; *s[i]; i++)        /* Concatenate them all together. */
  3931.       ckstrncat(p,s[i],x+1);
  3932.     y = (int)strlen(p);            /* Final precaution. */
  3933.     debug(F111,"addmmac constructed string",p,y);
  3934.     if (y == x) {
  3935.     y = addmac(nam,p);        /* Add result to the macro table. */
  3936.     } else {
  3937.     debug(F100,"addmmac length mismatch","",0);
  3938.     printf("\n!addmmac internal error!\n");
  3939.     y = -1;
  3940.     }
  3941.     free(p);                /* Free the temporary copy. */
  3942.     return(y);
  3943. }
  3944.  
  3945. /* Here is the real addmac routine. */
  3946.  
  3947. /* Returns -1 on failure, macro table index >= 0 on success. */
  3948.  
  3949. int mtchanged = 0;
  3950.  
  3951. int
  3952. addmac(nam,def) char *nam, *def; {    /* Add a macro to the macro table */
  3953.     int i, x, y, z, namlen, deflen, flag = 0;
  3954.     int replacing = 0, deleting = 0;
  3955.     char * p = NULL, c, *s;
  3956.     extern int tra_asg; int tra_tmp;
  3957.  
  3958.     if (!nam) return(-1);
  3959.     if (!*nam) return(-1);
  3960.  
  3961. #ifdef IKSD
  3962.     if (inserver &&
  3963. #ifdef IKSDCONF
  3964.     iksdcf
  3965. #else /* IKSDCONF */
  3966.     1
  3967. #endif /* IKSDCONF */
  3968.     ) {
  3969.         if (!ckstrcmp("on_exit",nam,-1,0) ||
  3970.             !ckstrcmp("on_logout",nam,-1,0))
  3971.       return(-1);
  3972.     }
  3973. #endif /* IKSD */
  3974.  
  3975.     namlen = 0;
  3976.     p = nam;
  3977.     while (*p++) namlen++;        /* (instead of strlen) */
  3978.  
  3979.     tra_tmp = tra_asg;            /* trace... */
  3980.     debug(F111,"addmac nam",nam,namlen);
  3981.     if (!def) {                /* Watch out for null pointer */
  3982.     deflen = 0;
  3983.     debug(F111,"addmac def","(null pointer)",deflen);
  3984.     } else {
  3985.     deflen = 0;
  3986.     p = def;
  3987.     while (*p++) deflen++;        /* (instead of strlen) */
  3988.     debug(F010,"addmac def",def,0);
  3989.     }
  3990. #ifdef USE_VARLEN            /* NOT USED */
  3991.     /* This does not boost performance much because varlen() does a lot */
  3992.     x = varlen(nam,&s);
  3993.     if (x > 0 && x >= deflen) {
  3994.     strcpy(s,def);            /* NOT USED */
  3995.     flag = 1;
  3996.     p = s;
  3997.     }
  3998. #endif /* USE_VARLEN */
  3999.  
  4000.     if (*nam == CMDQ) nam++;        /* Backslash quote? */
  4001.     if (*nam == '%') {            /* Yes, if it's a variable name, */
  4002.     if (!(c = *(nam + 1))) return(-1); /* Variable name letter or digit */
  4003.     if (!flag) {
  4004.         tra_asg = 0;
  4005.         delmac(nam,0);        /* Delete any old value. */
  4006.         tra_asg = tra_tmp;
  4007.     }
  4008.     if (deflen < 1) {        /* Null definition */
  4009.         p = NULL;            /* Better not malloc or strcpy! */
  4010.     } else if (!flag) {        /* A substantial definition */
  4011.         p = malloc(deflen + 1);    /* Allocate space for it */
  4012.         if (!p) {
  4013.         printf("?addmac malloc error 2\n");
  4014.         return(-1);
  4015.         } else strcpy(p,def);    /* Copy def into new space (SAFE) */
  4016.     }
  4017.  
  4018.     /* Now p points to the definition, or is a null pointer */
  4019.  
  4020.     if (c >= '0' && c <= '9') {    /* \%0-9 variable */
  4021.         if (maclvl < 0) {        /* Are we calling or in a macro? */
  4022.         g_var[c] = p;        /* No, it's top level one */
  4023.         makestr(&(toparg[c - '0']),p); /* Take care \&_[] too */
  4024.         } else {            /* Yes, it's a macro argument */
  4025.         m_arg[maclvl][c - '0'] = p; /* Assign the value */
  4026.         makestr(&(m_xarg[maclvl][c - '0']),p); /* And a copy here */
  4027.         }
  4028.     } else {            /* It's a \%a-z variable */
  4029.         if (c < 33 || (unsigned int)c > GVARS) return(-1);
  4030.         if (isupper(c)) c = (char) tolower(c);
  4031.         g_var[c] = p;        /* Put pointer in global-var table */
  4032.     }
  4033.     if (tra_asg) traceval(nam,p);
  4034.     return(0);
  4035.     } else if (*nam == '&') {        /* An array reference? */
  4036.     char **q = NULL;
  4037.     int rc = 0;
  4038.     if ((y = arraynam(nam,&x,&z)) < 0) /* If syntax is bad */
  4039.       return(-1);            /* return -1. */
  4040.     if (chkarray(x,z) < 0)        /* If array not declared or */
  4041.       rc = -2;            /* subscript out of range, ret -2 */
  4042.     if (!flag) {
  4043.         tra_asg = 0;
  4044.         delmac(nam,0);        /* Delete any old value. */
  4045.         tra_asg = tra_tmp;
  4046.     }
  4047.     x -= ARRAYBASE;            /* Convert name letter to index. */
  4048.     if (x > 'z' - ARRAYBASE + 1)
  4049.       rc = -1;
  4050.     if (rc != -1) {
  4051.         if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  4052.           return(-3);        /* return -3. */
  4053.     }
  4054.     if (rc < 0)
  4055.       return(rc);
  4056.     if (!flag) {
  4057.         if (deflen > 0) {
  4058.         if ((p = malloc(deflen+1)) == NULL) { /* Allocate space */
  4059.             printf("addmac macro error 7: %s\n",nam);
  4060.             return(-4);        /* for new def, return -4 on fail. */
  4061.         }
  4062.         strcpy(p,def);        /* Copy def into new space (SAFE). */
  4063.         } else p = NULL;
  4064.     }
  4065.     q[z] = p;            /* Store pointer to it. */
  4066.     if (x == 0) {            /* Arg vector array */
  4067.         if (z >= 0 && z <= 9) {    /* Copy values to corresponding  */
  4068.         if (maclvl < 0) {    /* \%1..9 variables. */
  4069.             makestr(&(toparg[z]),p);
  4070.         } else {
  4071.             makestr(&(m_arg[maclvl][z]),p);
  4072.         }
  4073.         }
  4074.     }
  4075.     if (tra_asg) traceval(nam,p);
  4076.     return(0);            /* Done. */
  4077.     }
  4078.  
  4079. /* Not a macro argument or a variable, so it's a macro definition */
  4080.  
  4081. #ifdef USE_VARLEN
  4082.     if (flag) {
  4083.     if (tra_asg) traceval(nam,p);
  4084.     return(0);
  4085.     }
  4086. #endif /* USE_VARLEN */
  4087.     x = isaa(nam) ?            /* If it's an associative array */
  4088.       mxxlook(mactab,nam,nmac) :    /* look it up this way */
  4089.     mxlook(mactab,nam,nmac);    /* otherwise this way. */
  4090.     if (x > -1) {            /* If found... */
  4091.     if (deflen > 0)            /* and a new definition was given */
  4092.       replacing = 1;        /* we're replacing */
  4093.     else                /* otherwise */
  4094.       deleting = 1;            /* we're deleting */
  4095.     }
  4096.     if (deleting) {            /* Deleting... */
  4097.     if (delmac(nam,0) < 0)
  4098.       return(-1);
  4099.     mtchanged++;
  4100.     if (tra_asg) traceval(nam,p);
  4101.     return(0);
  4102.     } else if (deflen < 1)        /* New macro with no definition */
  4103.       return(0);            /* Nothing to do. */
  4104.  
  4105.     if (replacing) {            /* Replacing an existing macro */
  4106.     if (mactab[x].mval) {        /* If it currently has a definition, */
  4107.         free(mactab[x].mval);    /* free it. */
  4108.         mactab[x].mval = NULL;
  4109.     }
  4110.     mtchanged++;
  4111.     y = x;                /* Replacement index. */
  4112.  
  4113.     } else {                /* Adding a new macro... */
  4114.     char c1, c2;            /* Use fast lookup to find the */
  4115.     c1 = *nam;            /* alphabetical slot. */
  4116.     if (isupper(c1)) c1 = (char) tolower(c1);
  4117.  
  4118.     if (nmac < 5) {            /* Not worth it for small tables */
  4119.         y = 0;
  4120.     } else {            /* First binary search to find */
  4121.         int lo = 0;            /* where to start */
  4122.         int hi = nmac;
  4123.         int count = 0;
  4124.         char c = 0;
  4125.         while (lo+2 < hi && ++count < 12) {
  4126.         y = lo + ((hi - lo) / 2);
  4127.         c = *(mactab[y].kwd);
  4128.         if (isupper(c)) c = (char) tolower(c);
  4129.         if (c < c1) {
  4130.             lo = y;
  4131.         } else {
  4132.             hi = y;
  4133.         }
  4134.         }
  4135.         y = (c < c1) ? lo+1 : lo;
  4136.     }
  4137.     /* Now search linearly from starting location */
  4138.     for ( ; y < MAC_MAX && mactab[y].kwd != NULL; y++) {
  4139.         c2 = *(mactab[y].kwd);
  4140.         if (isupper(c2)) c2 = (char) tolower(c2);
  4141.         if (c1 > c2)
  4142.           continue;
  4143.         if (c1 < c2)
  4144.           break;
  4145.         if (ckstrcmp(nam,mactab[y].kwd,-1,0) <= 0)
  4146.           break;
  4147.     }
  4148.     if (y == MAC_MAX) {        /* Macro table is full. */
  4149.         debug(F101,"addmac table overflow","",y);
  4150.         printf("?Macro table overflow\n");
  4151.         return(-1);
  4152.     }
  4153.     if (mactab[y].kwd != NULL) {    /* Must insert */
  4154.         for (i = nmac; i > y; i--) { /* Move the rest down one slot */
  4155.         mactab[i].kwd = mactab[i-1].kwd;
  4156.         mactab[i].mval = mactab[i-1].mval;
  4157.         mactab[i].flgs = mactab[i-1].flgs;
  4158.         }
  4159.     }
  4160.     mtchanged++;
  4161.     p = malloc(namlen + 1);        /* Allocate space for name */
  4162.     if (!p) {
  4163.         printf("?Addmac: Out of memory - \"%s\"\n",nam);
  4164.         return(-1);
  4165.     }
  4166.     strcpy(p,nam);            /* Copy name into new space (SAFE) */
  4167.     mactab[y].kwd = p;        /* Add pointer to table */
  4168.     }
  4169.     if (deflen > 0) {            /* If we have a definition */
  4170.     p = malloc(deflen + 1);        /* Get space */
  4171.     if (p == NULL) {
  4172.         printf("?Space exhausted - \"%s\"\n", nam);
  4173.         if (mactab[y].kwd) {
  4174.         free(mactab[y].kwd);
  4175.         mactab[y].kwd = NULL;
  4176.         }
  4177.         return(-1);
  4178.     } else {
  4179.         strcpy(p,def);        /* Copy the definition (SAFE) */
  4180.     }
  4181.     } else {                /* definition is empty */
  4182.     p = NULL;
  4183.     }
  4184.     mactab[y].mval = p;            /* Macro points to definition */
  4185.     mactab[y].flgs = 0;            /* No flags */
  4186.     if (!replacing)            /* If new macro */
  4187.       nmac++;                /* count it */
  4188.     if (tra_asg) traceval(nam,p);
  4189.     return(y);
  4190. }
  4191.  
  4192. int
  4193. xdelmac(x) int x; {            /* Delete a macro given its index */
  4194.     int i;
  4195.     extern int tra_asg;
  4196.     if (x < 0) return(x);
  4197.     if (tra_asg)
  4198.       traceval(mactab[x].kwd,NULL);
  4199.  
  4200.     if (mactab[x].kwd) {        /* Free the storage for the name */
  4201.     free(mactab[x].kwd);
  4202.     mactab[x].kwd = NULL;
  4203.     }
  4204.     if (mactab[x].mval) {        /* and for the definition */
  4205.     free(mactab[x].mval);
  4206.     mactab[x].mval = NULL;
  4207.     }
  4208.     for (i = x; i < nmac; i++) {    /* Now move up the others. */
  4209.     mactab[i].kwd = mactab[i+1].kwd;
  4210.     mactab[i].mval = mactab[i+1].mval;
  4211.     mactab[i].flgs = mactab[i+1].flgs;
  4212.     }
  4213.     nmac--;                /* One less macro */
  4214.  
  4215.     mactab[nmac].kwd = NULL;        /* Delete last item from table */
  4216.     mactab[nmac].mval = NULL;
  4217.     mactab[nmac].flgs = 0;
  4218.     mtchanged++;
  4219.     return(0);
  4220. }
  4221.  
  4222. int
  4223. delmac(nam,exact) char *nam; int exact; { /* Delete the named macro */
  4224.     int x, z;
  4225.     char *p, c;
  4226.     extern int tra_asg;
  4227.  
  4228.     if (!nam) return(0);        /* Watch out for null pointer */
  4229.     debug(F110,"delmac nam",nam,0);
  4230. #ifdef IKSD
  4231.     if ( inserver &&
  4232. #ifdef IKSDCONF
  4233.     iksdcf
  4234. #else /* IKSDCONF */
  4235.     1
  4236. #endif /* IKSDCONF */
  4237.     ) {
  4238.         if (!ckstrcmp("on_exit",nam,-1,0) ||
  4239.             !ckstrcmp("on_logout",nam,-1,0))
  4240.       return(-1);
  4241.     }
  4242. #endif /* IKSD */
  4243.  
  4244.     if (*nam == CMDQ) nam++;
  4245.     if (*nam == '%') {            /* If it's a variable name */
  4246.     if (!(c = *(nam+1))) return(0);    /* Get variable name letter or digit */
  4247.     p = (char *)0;            /* Initialize value pointer */
  4248.     if (maclvl < 0 && c >= '0' && c <= '9') { /* Top-level digit? */
  4249.         p = toparg[c - '0'];
  4250.         if (p) if (p != g_var[c]) {
  4251.         free(p);
  4252.         toparg[c - '0'] = NULL;
  4253.         }
  4254.         p = g_var[c];
  4255.         g_var[c] = NULL;        /* Zero the table entry */
  4256.     } else if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */
  4257.         p = m_xarg[maclvl][c - '0'];
  4258.         if (p) if (p != g_var[c]) {
  4259.         free(p);
  4260.         m_xarg[maclvl][c - '0'] = NULL;
  4261.         }
  4262.         p = m_arg[maclvl][c - '0'];    /* Get pointer from macro-arg table */
  4263.         m_arg[maclvl][c - '0'] = NULL; /* Zero the table pointer */
  4264.     } else {            /* It's a global variable */
  4265.         if (c < 33 || (unsigned int)c > GVARS) return(0);
  4266.         p = g_var[c];        /* Get pointer from global-var table */
  4267.         g_var[c] = NULL;        /* Zero the table entry */
  4268.     }
  4269.     if (p) {
  4270.         debug(F010,"delmac def",p,0);
  4271.         free(p);            /* Free the storage */
  4272.         p = NULL;
  4273.     } else debug(F110,"delmac def","(null pointer)",0);
  4274.     if (tra_asg) traceval(nam,NULL);
  4275.     return(0);
  4276.     }
  4277.     if (*nam == '&') {            /* An array reference? */
  4278.     char **q;
  4279.     if (arraynam(nam,&x,&z) < 0)    /* If syntax is bad */
  4280.       return(-1);            /* return -1. */
  4281.     x -= ARRAYBASE;            /* Convert name to number. */
  4282.     if ((q = a_ptr[x]) == NULL)    /* If array not declared, */
  4283.       return(-2);            /* return -2. */
  4284.     if (z > a_dim[x])        /* If subscript out of range, */
  4285.       return(-3);            /* return -3. */
  4286.     if (q[z]) {            /* If there is an old value, */
  4287.         debug(F010,"delmac def",q[z],0);
  4288.         if (x != 0)            /* Macro arg vector is just a copy */
  4289.           free(q[z]);        /* Others are real so free them */
  4290.         q[z] = NULL;
  4291.         if (x == 0) {        /* Arg vector array */
  4292.         if (z >= 0 && z <= 9) {    /* Copy values to corresponding  */
  4293.             if (maclvl < 0) {    /* \%1..9 variables. */
  4294.             makestr(&(toparg[z]),NULL);
  4295.             } else {
  4296.             makestr(&(m_arg[maclvl][z]),NULL);
  4297.             }
  4298.         }
  4299.         }
  4300.         if (tra_asg) traceval(nam,NULL);
  4301.     } else debug(F010,"delmac def","(null pointer)",0);
  4302.     }
  4303.  
  4304.    /* Not a variable or an array, so it must be a macro. */
  4305.  
  4306.     z = isaa(nam);
  4307.     debug(F111,"delmac isaa",nam,z);
  4308.     x = z ? mxxlook(mactab,nam,nmac) :
  4309.       exact ? mxlook(mactab,nam,nmac) :
  4310.     mlook(mactab,nam,nmac);
  4311.     if (x < 0) {
  4312.     debug(F111,"delmac mlook",nam,x);
  4313.     return(x);
  4314.     }
  4315.     return(xdelmac(x));
  4316. }
  4317.  
  4318. VOID
  4319. initmac() {                /* Init macro & variable tables */
  4320.     int i, j, x;
  4321.  
  4322.     nmac = 0;                /* No macros */
  4323.     for (i = 0; i < MAC_MAX; i++) {    /* Initialize the macro table */
  4324.     mactab[i].kwd = NULL;
  4325.     mactab[i].mval = NULL;
  4326.     mactab[i].flgs = 0;
  4327.     }
  4328.     mtchanged++;
  4329.     x = (MAXARGLIST + 1) * sizeof(char **);
  4330.     for (i = 0; i < MACLEVEL; i++) {    /* Init the macro argument tables */
  4331.     m_xarg[i] = (char **) malloc(x);
  4332.     mrval[i] = NULL;        /* Macro return value */
  4333.     /* Pointer to entire argument vector, level i, for \&_[] array */
  4334.     for (j = 0; j <= MAXARGLIST; j++) { /* Macro argument list */
  4335.         if (j < 10)            /* For the \%0..\%9 variables */
  4336.           m_arg[i][j] = NULL;    /* Pointer to arg j, level i. */
  4337.         if (m_xarg[i])        /* For \&_[] - all args. */
  4338.           m_xarg[i][j] = NULL;
  4339.     }
  4340.     }
  4341.     for (i = 0; i < GVARS; i++) {    /* And the global variables table */
  4342.     g_var[i] = NULL;
  4343.     }
  4344.     /* And the table of arrays */
  4345.     for (i = 0; i < (int) 'z' - ARRAYBASE + 1; i++) {
  4346.     a_ptr[i] = (char **) NULL;    /* Null pointer for each */
  4347.     a_dim[i] = 0;            /* and a dimension of zero */
  4348.     a_link[i] = -1;
  4349.     for (j = 0; j < CMDSTKL; j++) {
  4350.         aa_ptr[j][i] = (char **) NULL;
  4351.         aa_dim[j][i] = 0;
  4352.     }
  4353.     }
  4354. }
  4355.  
  4356. int
  4357. popclvl() {                /* Pop command level, return cmdlvl */
  4358.     extern int tra_cmd;
  4359.     struct localvar * v;
  4360.     int i, topcmd;
  4361.     debug(F101,"popclvl cmdlvl","",cmdlvl);
  4362.     if (cmdlvl > 0) {
  4363.     if ((v = localhead[cmdlvl])) {    /* Did we save any variables? */
  4364.         while (v) {            /* Yes */
  4365.         if (v->lv_value)    /* Copy old ones back */
  4366.           addmac(v->lv_name,v->lv_value);
  4367.         else
  4368.           delmac(v->lv_name,0);
  4369.         v = v->lv_next;
  4370.         }
  4371.         freelocal(cmdlvl);        /* Free local storage */
  4372.     }
  4373.     /* Automatic arrays do not use the localhead list */
  4374.  
  4375.     for (i = 0; i < 28; i++) {    /* Free any local arrays */
  4376.         if (aa_ptr[cmdlvl][i]) { /* Does this one exist? */
  4377.         dclarray((char)(i+ARRAYBASE),0); /* Destroy global one */
  4378.         a_ptr[i] = aa_ptr[cmdlvl][i];
  4379.         a_dim[i] = aa_dim[cmdlvl][i];
  4380.         aa_ptr[cmdlvl][i] = (char **)NULL;
  4381.         aa_dim[cmdlvl][i] = 0;
  4382.         } else if (aa_dim[cmdlvl][i] == -23) { /* Secret code */
  4383.         dclarray((char)(i+ARRAYBASE),0); /* (see pusharray()) */
  4384.         aa_ptr[cmdlvl][i] = (char **)NULL;
  4385.         aa_dim[cmdlvl][i] = 0;
  4386.         }
  4387.         /* Otherwise do nothing - it is a local array that was declared */
  4388.         /* at a level above this one so leave it alone. */
  4389.     }
  4390.     }
  4391.     if (cmdlvl < 1) {            /* If we're already at top level */
  4392.     cmdlvl = 0;            /* just make sure all the */
  4393.     tlevel = -1;            /* stack pointers are set right */
  4394.     maclvl = -1;            /* and return */
  4395.     } else if (cmdstk[cmdlvl].src == CMD_TF) { /* Reading from TAKE file? */
  4396.     debug(F101,"popclvl tlevel","",tlevel);
  4397.     if (tlevel > -1) {        /* Yes, */
  4398.         fclose(tfile[tlevel]);    /* close it */
  4399.  
  4400.         if (tra_cmd)
  4401.           printf("[%d] -F: \"%s\"\n",cmdlvl,tfnam[tlevel]);
  4402.         debug(F111,"CMD -F",tfnam[tlevel],cmdlvl);
  4403.         if (tfnam[tlevel]) {    /* free storage for name */
  4404.         free(tfnam[tlevel]);
  4405.         tfnam[tlevel] = NULL;
  4406.         }
  4407.         tlevel--;            /* and pop take level */
  4408.         cmdlvl--;            /* and command level */
  4409.         quiet = xquiet[cmdlvl];
  4410.     } else
  4411.       tlevel = -1;
  4412.     } else if (cmdstk[cmdlvl].src == CMD_MD) { /* In a macro? */
  4413.     topcmd = lastcmd[maclvl];
  4414.     debug(F101,"popclvl maclvl","",maclvl);
  4415.     if (maclvl > -1) {        /* Yes, */
  4416. #ifdef COMMENT
  4417.         int i;
  4418.         char **q;
  4419. #endif /* COMMENT */
  4420.         macp[maclvl] = "";        /* set macro pointer to null string */
  4421.         *cmdbuf = '\0';        /* clear the command buffer */
  4422.  
  4423.         if ((maclvl > 0) &&        /* 2 May 1999 */
  4424.         (m_arg[maclvl-1][0]) &&
  4425.         (!strncmp(m_arg[maclvl-1][0],"_xif",4) ||
  4426.          !strncmp(m_arg[maclvl-1][0],"_for",4) ||
  4427.          !strncmp(m_arg[maclvl-1][0],"_swi",4) ||
  4428.          !strncmp(m_arg[maclvl-1][0],"_whi",4)) &&
  4429.         mrval[maclvl+1]) {
  4430.         makestr(&(mrval[maclvl-1]),mrval[maclvl+1]);
  4431.         }
  4432.         if (maclvl+1 < MACLEVEL) {
  4433.         if (mrval[maclvl+1]) {    /* Free any deeper return values. */
  4434.             free(mrval[maclvl+1]);
  4435.             mrval[maclvl+1] = NULL;
  4436.         }
  4437.         }
  4438.         if (tra_cmd)
  4439.           printf("[%d] -M: \"%s\"\n",cmdlvl,m_arg[cmdstk[cmdlvl].lvl][0]);
  4440.         debug(F111,"CMD -M",m_arg[cmdstk[cmdlvl].lvl][0],cmdlvl);
  4441.  
  4442.         maclvl--;            /* Pop macro level */
  4443.         cmdlvl--;            /* and command level */
  4444.         debug(F101,"popclvl mac new maclvl","",maclvl);
  4445.         debug(F010,"popclvl mac mrval[maclvl+1]",mrval[maclvl+2],0);
  4446.  
  4447.         quiet = xquiet[cmdlvl];
  4448.         if (maclvl > -1) {
  4449.         a_ptr[0] = m_xarg[maclvl];
  4450.         a_dim[0] = n_xarg[maclvl] - 1;
  4451.         } else {
  4452.         a_ptr[0] = topxarg;
  4453.         a_dim[0] = topargc - 1;
  4454.         }
  4455.     } else {
  4456.         maclvl = -1;
  4457.     }
  4458. #ifndef    NOSEXP
  4459.     debug(F101,"popclvl topcmd","",topcmd);
  4460.     if (topcmd == XXSEXP) {
  4461.         extern char * sexpval;
  4462.         makestr(&(mrval[maclvl+1]),sexpval);
  4463.     }
  4464. #endif /* NOSEXP */
  4465.     } else {
  4466.     cmdlvl--;
  4467.     }
  4468.     debug(F101,"popclvl cmdlvl","",cmdlvl);
  4469.     if (prstring[cmdlvl]) {
  4470.     cmsetp(prstring[cmdlvl]);
  4471.     makestr(&(prstring[cmdlvl]),NULL);
  4472.     }
  4473. #ifndef MAC
  4474.     if (cmdlvl < 1 || xcmdsrc == CMD_KB) { /* If at prompt */
  4475.     setint();
  4476.     concb((char)escape);        /* Go into cbreak mode */
  4477.     }
  4478. #endif /* MAC */
  4479.     xcmdsrc = cmdstk[cmdlvl].src;
  4480.     debug(F101,"popclvl xcmdsrc","",xcmdsrc);
  4481.     debug(F101,"popclvl tlevel","",tlevel);
  4482.     return(cmdlvl < 1 ? 0 : cmdlvl);    /* Return command level */
  4483. }
  4484. #else /* No script programming language */
  4485. int popclvl() {                /* Just close current take file. */
  4486.     if (tlevel > -1) {            /* if any... */
  4487.     if (tfnam[tlevel]) {
  4488.         free(tfnam[tlevel]);
  4489.         tfnam[tlevel] = NULL;
  4490.     }
  4491.     fclose(tfile[tlevel--]);
  4492.     }
  4493.     if (tlevel == -1) {            /* And if back at top level */
  4494.     setint();
  4495.         concb((char)escape);        /* and go back into cbreak mode. */
  4496.     }
  4497.     xcmdsrc = tlevel > -1 ? CMD_TF : 0;
  4498.     return(tlevel + 1);
  4499. }
  4500. #endif /* NOSPL */
  4501.  
  4502.  
  4503. #ifndef NOSPL
  4504. static int
  4505. iseom(m) char * m; {            /* Test if at end of macro def */
  4506.     if (!m)
  4507.       m = "";
  4508.     debug(F111,"iseom",m,maclvl);
  4509.     while (*m) {
  4510.     /* Anything but Space and Comma means more macro is left */
  4511.     if ((*m > SP) && (*m != ',')) {
  4512.         debug(F111,"iseom return",m,0);
  4513.         return(0);
  4514.     }
  4515.     m++;
  4516.     }
  4517.     debug(F111,"iseom return",m,1);
  4518.     return(1);                /* Nothing left */
  4519. }
  4520. #endif /* NOSPL */
  4521.  
  4522. /* Pop all command levels that can be popped */
  4523.  
  4524. int
  4525. prepop() {
  4526.     if (cmdlvl > 0) {            /* If command level is > 0 and... */
  4527.     while (
  4528. #ifndef NOSPL
  4529.            ((cmdstk[cmdlvl].src == CMD_TF) && /* Command source is file */
  4530. #endif /* NOSPL */
  4531.         (tlevel > -1) &&
  4532.         feof(tfile[tlevel]))    /* And at end of file... */
  4533. #ifndef NOSPL
  4534.            /* Or command source is macro... */
  4535.            || ((cmdstk[cmdlvl].src == CMD_MD) &&
  4536.         (maclvl > -1) &&
  4537.         !iseom(macp[maclvl])))    /* and at end of macro, then... */
  4538. #endif /* NOSPL */
  4539.     {            
  4540.           popclvl();        /* pop command level. */
  4541.     }
  4542.     }
  4543.     return(cmdlvl < 1 ? 0 : cmdlvl);    /* Return command level */
  4544. }
  4545.  
  4546. /* STOP - get back to C-Kermit prompt, no matter where from. */
  4547.  
  4548. int
  4549. dostop() {
  4550.     extern int cmddep;
  4551.     while (popclvl()) ;        /* Pop all macros & take files */
  4552. #ifndef NOSPL
  4553.     if (cmddep > -1)        /* And all recursive cmd pkg invocations */
  4554.       while (cmpop() > -1) ;
  4555. #endif /* NOSPL */
  4556.     cmini(ckxech);        /* Clear the command buffer. */
  4557.     return(0);
  4558. }
  4559.  
  4560. /* Close the given log */
  4561.  
  4562. int
  4563. doclslog(x) int x; {
  4564.     int y;
  4565.     switch (x) {
  4566. #ifdef DEBUG
  4567.       case LOGD:
  4568.     if (deblog <= 0) {
  4569.         printf("?Debugging log wasn't open\n");
  4570.         return(0);
  4571.     }
  4572.     debug(F100,"Debug Log Closed","",0L);
  4573.     *debfil = '\0';
  4574.     deblog = 0;
  4575.     return(zclose(ZDFILE));
  4576. #endif /* DEBUG */
  4577.  
  4578. #ifndef NOXFER
  4579.       case LOGP:
  4580.     if (pktlog <= 0) {
  4581.         printf("?Packet log wasn't open\n");
  4582.         return(0);
  4583.     }
  4584.     *pktfil = '\0';
  4585.     pktlog = 0;
  4586.     return(zclose(ZPFILE));
  4587. #endif /* NOXFER */
  4588.  
  4589. #ifndef NOLOCAL
  4590.       case LOGS:
  4591.     if (seslog <= 0) {
  4592.         printf("?Session log wasn't open\n");
  4593.         return(0);
  4594.     }
  4595.     *sesfil = '\0';
  4596.     seslog = 0;
  4597.     return(zclose(ZSFILE));
  4598. #endif /* NOLOCAL */
  4599.  
  4600. #ifdef TLOG
  4601.       case LOGT: {
  4602. #ifdef IKSD
  4603.       extern int iklogopen, xferlog;
  4604. #endif /* IKSD */
  4605.       if (tralog <= 0
  4606. #ifdef IKSD
  4607.           && !iklogopen
  4608. #endif /* IKSD */
  4609.           ) {
  4610.           if (msgflg)
  4611.         printf("?Transaction log wasn't open\n");
  4612.           return(0);
  4613.       }
  4614. #ifdef IKSD
  4615.       if (iklogopen && !inserver) {
  4616.           close(xferlog);
  4617.           iklogopen = 0;
  4618.       }
  4619. #endif /* IKSD */
  4620.       if (tralog) {
  4621.           tlog(F100,"Transaction Log Closed","",0L);
  4622.           zclose(ZTFILE);
  4623.       }
  4624.       *trafil = '\0';
  4625.       tralog = 0;
  4626.       return(1);
  4627.       }
  4628. #endif /* TLOG */
  4629.  
  4630. #ifdef CKLOGDIAL
  4631.       case LOGM:
  4632.     if (dialog <= 0) {
  4633.         if (msgflg) printf("?Connection log wasn't open\n");
  4634.         return(0);
  4635.     }
  4636.     *diafil = '\0';
  4637.     dialog = 0;
  4638.     return(zclose(ZDIFIL));
  4639. #endif /* CKLOGDIAL */
  4640.  
  4641. #ifndef NOSPL
  4642.       case LOGW:            /* WRITE file */
  4643.       case LOGR:            /* READ file */
  4644.     y = (x == LOGR) ? ZRFILE : ZWFILE;
  4645.     if (chkfn(y) < 1)        /* If no file to close */
  4646.       return(1);            /* succeed silently. */
  4647.     return(zclose(y));        /* Otherwise, close the file. */
  4648. #endif /* NOSPL */
  4649.  
  4650.       default:
  4651.     printf("\n?Unexpected log designator - %d\n", x);
  4652.     return(0);
  4653.     }
  4654. }
  4655.  
  4656. static int slc = 0;            /* Screen line count */
  4657.  
  4658. char *
  4659. showstring(s) char * s; {
  4660.     return(s ? s : "(null)");
  4661. }
  4662.  
  4663. char *
  4664. showoff(x) int x; {
  4665.     return(x ? "on" : "off");
  4666. }
  4667.  
  4668. char *
  4669. showooa(x) int x; {
  4670.     switch (x) {
  4671.       case SET_OFF:  return("off");
  4672.       case SET_ON:   return("on");
  4673.       case SET_AUTO: return("automatic");
  4674.       default:       return("(unknown)");
  4675.     }
  4676. }
  4677.  
  4678. #ifdef GEMDOS
  4679. isxdigit(c) int c; {
  4680.     return(isdigit(c) ||
  4681.        (c >= 'a' && c <= 'f') ||
  4682.        (c >= 'A' && c <= 'F'));
  4683. }
  4684. #endif /* GEMDOS */
  4685.  
  4686. #ifndef NOSETKEY
  4687. #ifdef OS2
  4688. static struct keytab shokeytab[] = {    /* SHOW KEY modes */
  4689.     "all",    1, 0,
  4690.     "one",    0, 0
  4691. };
  4692. static int nshokey = (sizeof(shokeytab) / sizeof(struct keytab));
  4693.  
  4694. #define SHKEYDEF TT_MAX+5
  4695. struct keytab shokeymtab[] = {
  4696.     "adm3a",     TT_ADM3A,   0,         /* LSI ADM-3A */
  4697.     "aixterm",   TT_AIXTERM, 0,         /* IBM AIXterm */
  4698.     "ansi-bbs",  TT_ANSI,    0,        /* ANSI.SYS (BBS) */
  4699.     "at386",     TT_AT386,   0,        /* Unixware ANSI */
  4700.     "avatar/0+", TT_ANSI,    0,         /* AVATAR/0+ */
  4701.     "ba80",      TT_BA80,    0,         /* Nixdorf BA80 */
  4702.     "be",        TT_BEOS,    CM_INV|CM_ABR,
  4703.     "beos-ansi", TT_BEOS,    CM_INV,    /* BeOS ANSI */
  4704.     "beterm",    TT_BEOS,    0,         /* BeOS Console */
  4705.     "d200",      TT_DG200,   CM_INV|CM_ABR, /* Data General DASHER 200 */
  4706.     "d210",      TT_DG210,   CM_INV|CM_ABR, /* Data General DASHER 210 */
  4707.     "d217",      TT_DG217,   CM_INV|CM_ABR, /* Data General DASHER 217 */
  4708.     "default",   SHKEYDEF,   0,
  4709.     "dg200",     TT_DG200,   0,        /* Data General DASHER 200 */
  4710.     "dg210",     TT_DG210,   0,        /* Data General DASHER 210 */
  4711.     "dg217",     TT_DG217,   0,        /* Data General DASHER 217 */
  4712.     "emacs",     TT_KBM_EMACS,   0,     /* Emacs mode */
  4713.     "h19",       TT_H19,     CM_INV,    /* Heath-19 */
  4714.     "heath19",   TT_H19,     0,        /* Heath-19 */
  4715.     "hebrew",    TT_KBM_HEBREW, 0,      /* Hebrew mode */
  4716.     "hft",       TT_HFT,     0,         /* IBM HFT */
  4717.     "hp2621a",   TT_HP2621,  0,        /* HP 2621A */
  4718.     "hpterm",    TT_HPTERM,  0,        /* HP TERM */
  4719.     "hz1500",    TT_HZL1500, 0,        /* Hazeltine 1500 */
  4720.     "ibm3151",   TT_IBM31,   0,        /* IBM 3101-xx,3161 */
  4721.     "linux",     TT_LINUX,   0,         /* Linux */
  4722.     "qansi",     TT_QANSI,   0,         /* QNX ANSI */
  4723.     "qnx",       TT_QNX,     0,         /* QNX */
  4724.     "russian",   TT_KBM_RUSSIAN, 0,     /* Russian mode */
  4725.     "scoansi",   TT_SCOANSI, 0,        /* SCO ANSI */
  4726.     "sni-97801", TT_97801,   0,         /* Sinix 97801 */
  4727. #ifdef OS2PM
  4728. #ifdef COMMENT
  4729.     "tek4014", TT_TEK40, 0,
  4730. #endif /* COMMENT */
  4731. #endif /* OS2PM */
  4732.     "tty",     TT_NONE,  0,
  4733.     "tvi910+", TT_TVI910, 0,
  4734.     "tvi925",  TT_TVI925, 0,
  4735.     "tvi950",  TT_TVI950, 0,
  4736.     "vc404",   TT_VC4404, 0,
  4737.     "vc4404",  TT_VC4404, CM_INV,
  4738.     "vip7809", TT_VIP7809, 0,
  4739.     "vt100",   TT_VT100, 0,
  4740.     "vt102",   TT_VT102, 0,
  4741.     "vt220",   TT_VT220, 0,
  4742.     "vt220pc", TT_VT220PC, 0,
  4743.     "vt320",   TT_VT320, 0,
  4744.     "vt320pc", TT_VT320PC, 0,
  4745.     "vt52",    TT_VT52,  0,
  4746.     "wp",      TT_KBM_WP, 0,
  4747.     "wy160",   TT_WY160,  0,
  4748.     "wy30",    TT_WY30,  0,
  4749.     "wy370",   TT_WY370, 0,
  4750.     "wy50",    TT_WY50,  0,
  4751.     "wy60",    TT_WY60,  0,
  4752.     "wyse30",  TT_WY30,  CM_INV,
  4753.     "wyse370", TT_WY370, CM_INV,
  4754.     "wyse50",  TT_WY50,  CM_INV,
  4755.     "wyse60",  TT_WY60,  CM_INV
  4756. };
  4757. int nshokeym = (sizeof(shokeymtab) / sizeof(struct keytab));
  4758. #endif /* OS2 */
  4759.  
  4760. VOID
  4761. #ifdef OS2
  4762. shokeycode(c,m) int c, m;
  4763. #else
  4764. shokeycode(c) int c;
  4765. #endif
  4766. /* shokeycode */ {
  4767.     KEY ch;
  4768.     CHAR *s;
  4769. #ifdef OS2
  4770.     int i;
  4771.     con_event km;
  4772. #else /* OS2 */
  4773.     int km;
  4774. #endif /* OS2 */
  4775.  
  4776. #ifdef OS2
  4777.     extern int mskkeys;
  4778.     char * mstr = "";
  4779.  
  4780.     if (c >= KMSIZE) {
  4781.     bleep(BP_FAIL);
  4782.     return;
  4783.     }
  4784. #else /* OS2 */
  4785.     printf(" Key code \\%d => ", c);
  4786. #endif /* OS2 */
  4787.  
  4788. #ifndef OS2
  4789.     km = mapkey(c);
  4790.  
  4791. #ifndef NOKVERBS
  4792.     if (IS_KVERB(km)) {            /* \Kverb? */
  4793.     int i, kv;
  4794.     kv = km & ~(F_KVERB);
  4795.     printf("Verb: ");
  4796.     for (i = 0; i < nkverbs; i++)
  4797.       if (kverbs[i].kwval == kv) {
  4798.           printf("\\K%s",kverbs[i].kwd);
  4799.           break;
  4800.       }
  4801.     printf("\n");
  4802.     } else
  4803. #endif /* NOKVERBS */
  4804.       if (IS_CSI(km)) {
  4805.       int xkm = km & 0xFF;
  4806.       if (xkm <= 32 || xkm >= 127)
  4807.         printf("String: \\{27}[\\{%d}\n",xkm);
  4808.       else
  4809.         printf("String: \\{27}[%c\n",xkm);
  4810.       } else if (IS_ESC(km)) {
  4811.       int xkm = km & 0xFF;
  4812.       if (xkm <= 32 || xkm >= 127)
  4813.         printf("String: \\{27}\\{%d}\n",xkm);
  4814.       else
  4815.         printf("String: \\{27}%c\n",xkm);
  4816.       } else if (macrotab[c]) {        /* See if there's a macro */
  4817.       printf("String: ");        /* If so, display its definition */
  4818.       s = macrotab[c];
  4819.       shostrdef(s);
  4820.       printf("\n");
  4821. #ifndef NOKVERBS
  4822.     } else if (km >= 0x100) {        /* This means "undefined" */
  4823.     printf("Undefined\n");
  4824. #endif /* NOKVERBS */
  4825.     } else {                /* No macro, show single character */
  4826.     printf("Character: ");
  4827.     ch = km;
  4828.     if (ch < 32 || ch == 127
  4829. #ifdef OS2
  4830.         || ch > 255
  4831. #endif /* OS2 */
  4832. #ifndef NEXT
  4833. #ifndef AUX
  4834. #ifndef XENIX
  4835. #ifndef OS2
  4836.         || (ch > 127 && ch < 160)
  4837. #endif /* OS2 */
  4838. #endif /* XENIX */
  4839. #endif /* AUX */
  4840. #endif /* NEXT */
  4841.         )
  4842. /*
  4843.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  4844.   %u is supposed to be totally portable.
  4845. */
  4846.       printf("\\%u",(unsigned int) ch);
  4847.     else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  4848.     if (ch == (KEY) c)
  4849.       printf(" (self, no translation)\n");
  4850.     else
  4851.       printf("\n");
  4852.     }
  4853. #else /* OS2 */
  4854.     if (m < 0) {
  4855.         km = mapkey(c);
  4856.         mstr = "default";
  4857.     } else {
  4858.         km = maptermkey(c,m);
  4859.         for (i = 0; i < nshokeym; i++) {
  4860.             if (m == shokeymtab[i].kwval) {
  4861.                 mstr = shokeymtab[i].kwd;
  4862.                 break;
  4863.             }
  4864.         }
  4865.     }
  4866.     s = keyname(c);
  4867.     debug(F111,"shokeycode mstr",mstr,m);
  4868.     debug(F111,"shokeycode keyname",s,c);
  4869.     printf(" %sKey code \\%d %s (%s) => ",
  4870.             mskkeys ? "mskermit " : "",
  4871.             mskkeys ? cktomsk(c) : c,
  4872.         s == NULL ? "" : s, mstr);
  4873.  
  4874.     switch (km.type) {
  4875. #ifndef NOKVERBS
  4876.       case kverb: {
  4877.       int i, kv;
  4878.       kv = km.kverb.id & ~(F_KVERB);
  4879.       printf("Verb: ");
  4880.       for (i = 0; i < nkverbs; i++) {
  4881.           if (kverbs[i].kwval == kv) {
  4882.           printf("\\K%s",kverbs[i].kwd);
  4883.           break;
  4884.           }
  4885.       }
  4886.       printf("\n");
  4887.       break;
  4888.       }
  4889. #endif /* NOKVERBS */
  4890.       case csi: {
  4891.       int xkm = km.csi.key & 0xFF;
  4892.       if (xkm <= 32 || xkm >= 127)
  4893.         printf("String: \\{27}[\\{%d}\n",xkm);
  4894.       else
  4895.         printf("String: \\{27}[%c\n",xkm);
  4896.       break;
  4897.       }
  4898.       case esc: {
  4899.       int xkm = km.esc.key & 0xFF;
  4900.       if (xkm <= 32 || xkm >= 127)
  4901.         printf("String: \\{%d}\\{%d}\n",ISDG200(tt_type)?30:27,xkm);
  4902.       else
  4903.         printf("String: \\{%d}%c\n",ISDG200(tt_type)?30:27,xkm);
  4904.       break;
  4905.       }
  4906.       case macro: {
  4907.       printf("String: ");        /* Macro, display its definition */
  4908.       shostrdef(km.macro.string);
  4909.       printf("\n");
  4910.       break;
  4911.       }
  4912.       case literal: {
  4913.           printf("Literal string: ");    /* Literal, display its definition */
  4914.           shostrdef(km.literal.string);
  4915.           printf("\n");
  4916.           break;
  4917.       }
  4918.       case error: {
  4919.       if (c >= 0x100) {
  4920.           printf("Undefined\n");
  4921.       } else {
  4922.           printf("Character: ");
  4923.           ch = c;
  4924.           if (ch < 32 || ch == 127 || ch > 255
  4925. #ifndef NEXT
  4926. #ifndef AUX
  4927. #ifndef XENIX
  4928. #ifndef OS2
  4929.            || (ch > 127 && ch < 160)
  4930. #endif /* OS2 */
  4931. #endif /* XENIX */
  4932. #endif /* AUX */
  4933. #endif /* NEXT */
  4934.            )
  4935. /*
  4936.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  4937.   %u is supposed to be totally portable.
  4938. */
  4939.           printf("\\%u",(unsigned int) ch);
  4940.           else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  4941.           printf(" (self, no translation)\n");
  4942.       }
  4943.       break;
  4944.       }
  4945.       case key: {
  4946.       printf("Character: ");
  4947.       ch = km.key.scancode;
  4948.       if (ch < 32 || ch == 127 || ch > 255
  4949. #ifndef NEXT
  4950. #ifndef AUX
  4951. #ifndef XENIX
  4952. #ifndef OS2
  4953.           || (ch > 127 && ch < 160)
  4954. #else
  4955.                || (ch > 127)
  4956. #endif /* OS2 */
  4957. #endif /* XENIX */
  4958. #endif /* AUX */
  4959. #endif /* NEXT */
  4960.           )
  4961. /*
  4962.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  4963.   %u is supposed to be totally portable.
  4964. */
  4965.         printf("\\%u",(unsigned int) ch);
  4966.       else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  4967.       if (ch == (KEY) c)
  4968.         printf(" (self, no translation)\n");
  4969.       else
  4970.         printf("\n");
  4971.       break;
  4972.       }
  4973.     }
  4974. #endif /* OS2 */
  4975. }
  4976. #endif /* NOSETKEY */
  4977.  
  4978. VOID
  4979. shostrdef(s) CHAR * s; {
  4980.     CHAR ch;
  4981.     if (!s) s = (CHAR *)"";
  4982.     while ((ch = *s++)) {
  4983.     if (ch < 32 || ch == 127 || ch == 255
  4984. /*
  4985.   Systems whose native character sets have graphic characters in C1...
  4986. */
  4987. #ifndef NEXT                /* NeXT */
  4988. #ifndef AUX                /* Macintosh */
  4989. #ifndef XENIX                /* IBM PC */
  4990. #ifdef OS2
  4991. /*
  4992.   It doesn't matter whether the local host can display 8-bit characters;
  4993.   they are not portable among character-sets and fonts.  Who knows what
  4994.   would be displayed...
  4995. */
  4996.         || (ch > 127)
  4997. #else /* OS2 */
  4998.         || (ch > 127 && ch < 160)
  4999. #endif /* OS2 */
  5000. #endif /* XENIX */
  5001. #endif /* AUX */
  5002. #endif /* NEXT */
  5003.         )
  5004.       printf("\\{%d}",ch);        /* Display control characters */
  5005.     else putchar((char) ch);    /* in backslash notation */
  5006.     }
  5007. }
  5008.  
  5009. #define xxdiff(v,sys) strncmp(v,sys,strlen(sys))
  5010.  
  5011. #ifndef NOSHOW
  5012. VOID
  5013. shover() {
  5014. #ifdef OS2
  5015.     extern char ckxsystem[];
  5016. #endif /* OS2 */
  5017.     extern char *ck_patch, * cklibv;
  5018.     printf("\nVersions:\n %s\n",versio);
  5019.     printf(" Numeric: %ld\n",vernum);
  5020. #ifdef OS2
  5021.     printf(" Operating System: %s\n", ckxsystem);
  5022. #else /* OS2 */
  5023.     printf(" Built for: %s\n", ckxsys);
  5024. #ifdef CK_UTSNAME
  5025.     if (unm_nam[0])
  5026.       printf(" Running on: %s %s %s %s\n", unm_nam,unm_ver,unm_rel,unm_mch);
  5027. #endif /* CK_UTSNAME */
  5028.     printf(" Patches: %s\n", *ck_patch ? ck_patch : "(none)");
  5029. #endif /* OS2 */
  5030.     if (xxdiff(ckxv,ckxsys))
  5031.       printf(" %s for%s\n",ckxv,ckxsys);
  5032.     else
  5033.       printf(" %s\n",ckxv);
  5034.     if (xxdiff(ckzv,ckzsys))
  5035.       printf(" %s for%s\n",ckzv,ckzsys);
  5036.     else
  5037.       printf(" %s\n",ckzv);
  5038.     printf(" %s\n",cklibv);
  5039.     printf(" %s\n",protv);
  5040.     printf(" %s\n",fnsv);
  5041.     printf(" %s\n %s\n",cmdv,userv);
  5042. #ifndef NOCSETS
  5043.     printf(" %s\n",xlav);
  5044. #endif /* NOCSETS */
  5045. #ifndef MAC
  5046. #ifndef NOLOCAL
  5047.     printf(" %s\n",connv);
  5048. #endif /* NOLOCAL */
  5049. #endif /* MAC */
  5050. #ifndef NODIAL
  5051.     printf(" %s\n",dialv);
  5052. #endif /* NODIAL */
  5053. #ifndef NOSCRIPT
  5054.     printf(" %s\n",loginv);
  5055. #endif /* NOSCRIPT */
  5056. #ifdef NETCONN
  5057.     printf(" %s\n",cknetv);
  5058. #ifdef OS2
  5059.     printf(" %s\n",ckonetv);
  5060. #ifdef CK_NETBIOS
  5061.     printf(" %s\n",ckonbiv);
  5062. #endif /* CK_NETBIOS */
  5063. #endif /* OS2 */
  5064. #endif /* NETCONN */
  5065. #ifdef TNCODE
  5066.     printf(" %s\n",cktelv);
  5067. #endif /* TNCODE */
  5068. #ifdef OS2
  5069. #ifdef OS2MOUSE
  5070.     printf(" %s\n",ckomouv);
  5071. #endif /* OS2MOUSE */
  5072. #endif /* OS2 */
  5073. #ifdef NEWFTP
  5074.     printf(" %s\n",ckftpv);
  5075. #endif /* NEWFTP */
  5076. #ifdef CK_AUTHENTICATION
  5077.     printf(" %s\n",ckathv);
  5078. #endif /* CK_AUTHENTICATION */
  5079. #ifdef CK_ENCRYPTION
  5080. #ifdef CRYPT_DLL
  5081.     printf(" %s\n",ck_crypt_dll_version());
  5082. #else /* CRYPT_DLL */
  5083.     printf(" %s\n",ckcrpv);
  5084. #endif /* CRYPT_DLL */
  5085. #endif /* CK_ENCRYPTION */
  5086. #ifdef CK_SSL
  5087.     printf(" %s\n",cksslv);
  5088. #endif /* CK_SSL */
  5089.     printf("\n");
  5090. }
  5091.  
  5092. #ifdef CK_LABELED
  5093. VOID
  5094. sholbl() {
  5095. #ifdef VMS
  5096.     printf("VMS Labeled File Features:\n");
  5097.     printf(" acl %s (ACL info %s)\n",
  5098.        showoff(lf_opts & LBL_ACL),
  5099.        lf_opts & LBL_ACL ? "preserved" : "discarded");
  5100.     printf(" backup-date %s (backup date/time %s)\n",
  5101.        showoff(lf_opts & LBL_BCK),
  5102.        lf_opts & LBL_BCK ? "preserved" : "discarded");
  5103.     printf(" name %s (original filename %s)\n",
  5104.        showoff(lf_opts & LBL_NAM),
  5105.        lf_opts & LBL_NAM ? "preserved" : "discarded");
  5106.     printf(" owner %s (original file owner id %s)\n",
  5107.        showoff(lf_opts & LBL_OWN),
  5108.        lf_opts & LBL_OWN ? "preserved" : "discarded");
  5109.     printf(" path %s (original file's disk:[directory] %s)\n",
  5110.        showoff(lf_opts & LBL_PTH),
  5111.        lf_opts & LBL_PTH ? "preserved" : "discarded");
  5112. #else
  5113. #ifdef OS2
  5114.     printf("OS/2 Labeled File features (attributes):\n");
  5115.     printf(" archive:   %s\n", showoff(lf_opts & LBL_ARC));
  5116.     printf(" extended:  %s\n", showoff(lf_opts & LBL_EXT));
  5117.     printf(" hidden:    %s\n", showoff(lf_opts & LBL_HID));
  5118.     printf(" read-only: %s\n", showoff(lf_opts & LBL_RO ));
  5119.     printf(" system:    %s\n", showoff(lf_opts & LBL_SYS));
  5120. #endif /* OS2 */
  5121. #endif /* VMS */
  5122. }
  5123. #endif /* CK_LABELED */
  5124.  
  5125. VOID
  5126. shotcs(csl,csr) int csl, csr; {        /* Show terminal character set */
  5127. #ifndef NOCSETS
  5128. #ifdef OS2
  5129. #ifndef NOTERM
  5130.     extern struct _vtG G[4], *GL, *GR;
  5131.     extern int decnrcm, sni_chcode;
  5132.     extern int tt_utf8, dec_nrc, dec_kbd, dec_lang;
  5133.  
  5134.     printf(" Terminal character-sets:\n");
  5135.     if (IS97801(tt_type_mode)) {
  5136.     if (cmask == 0377)
  5137.       printf("     Mode: 8-bit Mode\n");
  5138.     else
  5139.       printf("     Mode: 7-bit Mode\n");
  5140.     printf("     CH.CODE is %s\n",sni_chcode?"On":"Off");
  5141.     } else if (ISVT100(tt_type_mode)) {
  5142.     if (decnrcm)
  5143.       printf("     Mode: 7-bit National Mode\n");
  5144.     else
  5145.       printf("     Mode: 8-bit Multinational Mode\n");
  5146.     }
  5147.     if ( isunicode() )
  5148.         printf("    Local: Unicode display / %s input\n",
  5149.                 csl == TX_TRANSP ? "transparent" :
  5150.                 csl == TX_UNDEF ? "undefined" : txrinfo[csl]->keywd);
  5151.     else
  5152.         printf("    Local: %s\n",
  5153.                 csl == TX_TRANSP ? "transparent" :
  5154.                 csl == TX_UNDEF ? "undefined" : txrinfo[csl]->keywd);
  5155.  
  5156.     if ( tt_utf8 ) {
  5157.         printf("   Remote: UTF-8\n");
  5158.     } else {
  5159.         printf("   Remote: %sG0: %s (%s)\n",
  5160.        GL == &G[0] ? "GL->" : GR == &G[0] ? "GR->" : "    ",
  5161.        txrinfo[G[0].designation]->keywd,
  5162.            G[0].designation == TX_TRANSP ? "" :
  5163.        G[0].size == cs94 ? "94 chars" :
  5164.        G[0].size == cs96 ? "96 chars" : "multi-byte");
  5165.     printf("           %sG1: %s (%s)\n",
  5166.        GL == &G[1] ? "GL->" : GR == &G[1] ? "GR->" : "    ",
  5167.        txrinfo[G[1].designation]->keywd,
  5168.            G[1].designation == TX_TRANSP ? "" :
  5169.            G[1].size == cs94 ? "94 chars" :
  5170.            G[1].size == cs96 ? "96 chars" : "multi-byte");
  5171.     printf("           %sG2: %s (%s)\n",
  5172.        GL == &G[2] ? "GL->" : GR == &G[2] ? "GR->" : "    ",
  5173.        txrinfo[G[2].designation]->keywd,
  5174.            G[2].designation == TX_TRANSP ? "" :
  5175.            G[2].size == cs94 ? "94 chars" :
  5176.        G[2].size == cs96 ? "96 chars" : "multi-byte");
  5177.     printf("           %sG3: %s (%s)\n",
  5178.        GL == &G[3] ? "GL->" : GR == &G[3] ? "GR->" : "    ",
  5179.        txrinfo[G[3].designation]->keywd,
  5180.            G[3].designation == TX_TRANSP ? "" :
  5181.            G[3].size == cs94 ? "94 chars" :
  5182.        G[3].size == cs96 ? "96 chars" : "multi-byte");
  5183.     }
  5184.     printf("\n");
  5185.     printf(" Keyboard character-sets:\n");
  5186.     printf("   Multinational: %s\n",txrinfo[dec_kbd]->keywd);
  5187.     printf("        National: %s\n",txrinfo[dec_nrc]->keywd);
  5188. #endif /* NOTERM */
  5189. #else /* OS2 */
  5190. #ifndef MAC
  5191.     char *s;
  5192.  
  5193.     debug(F101,"TERM LOCAL CSET","",csl);
  5194.     debug(F101,"TERM REMOTE CSET","",csr);
  5195.     printf(" Terminal character-set: ");
  5196.     if (tcs_transp) {            /* No translation */
  5197.     printf("transparent\n");
  5198.     } else {                /* Translation */
  5199.     printf("%s (remote) %s (local)\n",
  5200.            fcsinfo[csr].keyword,fcsinfo[csl].keyword);
  5201.     if (csr != csl) {
  5202.         switch(gettcs(csr,csl)) {
  5203.           case TC_USASCII:  s = "ascii";        break;
  5204.           case TC_1LATIN:   s = "latin1-iso";   break;
  5205.           case TC_2LATIN:   s = "latin2-iso";   break;
  5206.           case TC_CYRILL:   s = "cyrillic-iso"; break;
  5207.           case TC_JEUC:     s = "japanese-euc"; break;
  5208.           case TC_HEBREW:   s = "hebrew-iso";   break;
  5209.           case TC_GREEK:    s = "greek-iso";    break;
  5210.           case TC_9LATIN:   s = "latin9-iso";   break;
  5211.           default:          s = "transparent";  break;
  5212.         }
  5213.         if (strcmp(s,fcsinfo[csl].keyword) &&
  5214.         strcmp(s,fcsinfo[csr].keyword))
  5215.           printf("                         (via %s)\n",s);
  5216.     }
  5217.     }
  5218. #endif /* MAC */
  5219. #endif /* OS2 */
  5220. #endif /* NOCSETS */
  5221. }
  5222.  
  5223. #ifndef NOLOCAL
  5224. #ifdef OS2
  5225. extern char htab[];
  5226. VOID
  5227. shotabs() {
  5228.     int i;
  5229.  
  5230.     printf("Tab Stops:\n\n");
  5231.     for (i = 1; i <= 70; i++)
  5232.       printf("%c",htab[i]=='T'?'T':'-');
  5233.     printf("\n1.......10........20........30........40........50........60\
  5234. ........70\n\n");
  5235.     for (; i <= 140; i++)
  5236.       printf("%c",htab[i]=='T'?'T':'-');
  5237.     printf("\n........80........90.......100.......110.......120.......130\
  5238. .......140\n\n");
  5239.     for (; i <= 210; i++)
  5240.       printf("%c",htab[i]=='T'?'T':'-');
  5241.     printf("\n.......150.......160.......170.......180.......190.......200\
  5242. .......210\n\n");
  5243.     for (; i <= 255; i++)
  5244.       printf("%c",htab[i]=='T'?'T':'-');
  5245.     printf("\n.......220.......230.......240.......250..255\n");
  5246. }
  5247. #endif /* OS2 */
  5248. #endif /* NOLOCAL */
  5249.  
  5250. #ifdef OS2MOUSE
  5251. VOID
  5252. shomou() {
  5253.     int button, event, id, i;
  5254.     char * name = "";
  5255.  
  5256.     printf("Mouse settings:\n");
  5257.     printf("   Button Count:   %d\n",mousebuttoncount());
  5258.     printf("   Active:         %s\n\n",showoff(tt_mouse));
  5259.  
  5260.     for (button = 0; button < MMBUTTONMAX; button++)
  5261.       for (event = 0; event < MMEVENTSIZE; event++)
  5262.     if (mousemap[button][event].type != error)
  5263.       switch (mousemap[button][event].type) {
  5264.         case key:
  5265.           printf("   %s = Character: %c \\%d\n",
  5266.              mousename(button,event),
  5267.              mousemap[button][event].key.scancode,
  5268.              mousemap[button][event].key.scancode );
  5269.           break;
  5270.         case kverb:
  5271.           id = mousemap[button][event].kverb.id & ~(F_KVERB);
  5272.           if (id != K_IGNORE) {
  5273.           for (i = 0; i< nkverbs; i++)
  5274.             if (id == kverbs[i].kwval) {
  5275.             name = kverbs[i].kwd;
  5276.             break;
  5277.             }
  5278.           printf("   %s = Kverb: \\K%s\n",
  5279.              mousename(button,event),
  5280.              name
  5281.              );
  5282.           }
  5283.           break;
  5284.         case macro:
  5285.           printf("   %s = Macro: ",
  5286.              mousename(button,event) );
  5287.           shostrdef(mousemap[button][event].macro.string);
  5288.           printf("\n");
  5289.           break;
  5290.       }
  5291. }
  5292. #endif /* OS2MOUSE */
  5293.  
  5294. #ifndef NOLOCAL
  5295. VOID
  5296. shotrm() {
  5297.     char *s;
  5298.     extern char * getiact();
  5299.     extern int tt_print, adl_err;
  5300. #ifndef NOTRIGGER
  5301.     extern char * tt_trigger[];
  5302. #endif /* NOTRIGGER */
  5303. #ifdef CKTIDLE
  5304.     extern char * tt_idlesnd_str;
  5305.     extern int tt_idlesnd_tmo;
  5306.     extern int tt_idlelimit, tt_idleact;
  5307. #endif /* CKTIDLE */
  5308. #ifdef OS2
  5309.     extern int wy_autopage, autoscroll, sgrcolors, colorreset, user_erasemode,
  5310.       decscnm, decscnm_usr, tt_diff_upd, tt_senddata,
  5311.       wy_blockend, marginbell, marginbellcol, tt_modechg, dgunix;
  5312.     int lines = 0;
  5313.  
  5314. #ifdef PCFONTS
  5315.     int i;
  5316.     char *font;
  5317.  
  5318.     if (IsOS2FullScreen()) {        /* Determine the font name */
  5319.         if (!os2LoadPCFonts()) {
  5320.             for (i = 0; i < ntermfont; i++) {
  5321.                 if (tt_font == term_font[i].kwval) {
  5322.             font = term_font[i].kwd;
  5323.             break;
  5324.         }
  5325.         }
  5326.     } else {
  5327.             font = "(DLL not available)";
  5328.     }
  5329.     } else {
  5330.         font =     "(full screen only)";
  5331.     }
  5332. #endif /* PCFONTS */
  5333. #ifdef KUI
  5334.     char * font = "(unknown)";
  5335.     char * fontsize = ckitoa(tt_font_size);
  5336.     if ( ntermfont > 0 )
  5337.         font = term_font[tt_font].kwd;
  5338. #endif /* KUI */
  5339.  
  5340.     printf("Terminal parameters:\n");
  5341.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5342.     printf(" %19s: %1d%-12s  %13s: %1d%-14s\n",
  5343.        "Bytesize: Command",
  5344.            (cmdmsk == 0377) ? 8 : 7,
  5345.            " bits","Terminal",
  5346.            (cmask == 0377) ? 8 : 7," bits");
  5347.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5348.     printf(" %19s: %-13s","Type",
  5349.        (tt_type >= 0 && tt_type <= max_tt) ?
  5350.        tt_info[tt_type].x_name :
  5351.        "unknown" );
  5352.     if (tt_type >= 0 && tt_type <= max_tt)
  5353.       if (strlen(tt_info[tt_type].x_id))
  5354.     printf("  %13s: <ESC>%s","ID",tt_info[tt_type].x_id);
  5355.     printf("\n");
  5356.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5357.     printf(" %19s: %-13s  %13s: %-15s\n","Echo",
  5358.        duplex ? "local" : "remote","Locking-shift",showoff(sosi));
  5359.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5360.     printf(" %19s: %-13s  %13s: %-15s\n","Newline-mode",
  5361.        showoff(tnlm),"Cr-display",tt_crd ? "crlf" : "normal");
  5362.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5363.     printf(" %19s: %-13s  %13s: %-15s\n","Cursor",
  5364.        (tt_cursor == 2) ? "full" :
  5365.        (tt_cursor == 1) ? "half" : "underline",
  5366. #ifdef CK_AUTODL
  5367.        "autodownload",autodl ?
  5368.        (adl_err ? "on, error stop" : "on, error continue") : "off"
  5369. #else /* CK_AUTODL */
  5370.        "", ""
  5371. #endif /* CK_AUTODL */
  5372.        );
  5373.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5374.     printf(" %19s: %-13s  %13s: %-15s\n","Arrow-keys",
  5375.        tt_arrow ? "application" : "cursor",
  5376.            "Keypad-mode", tt_keypad ? "application" : "numeric"
  5377.        );
  5378.  
  5379.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5380.  
  5381.     /* Just to make sure we are using current info */
  5382.     updanswerbk();
  5383.  
  5384.     /*
  5385.        This line doesn't end with '\n' because the answerback string
  5386.        is terminated with a newline
  5387.     */
  5388.     printf(" %19s: %-13s  %13s: %-15s","Answerback",
  5389.        showoff(tt_answer),"response",answerback);
  5390.     switch (tt_bell) {
  5391.       case XYB_NONE:
  5392.     s = "none";
  5393.     break;
  5394.       case XYB_VIS:
  5395.     s= "visible";
  5396.     break;
  5397.       case XYB_AUD | XYB_BEEP:
  5398.     s="beep";
  5399.     break;
  5400.       case XYB_AUD | XYB_SYS:
  5401.     s="system sounds";
  5402.     break;
  5403.       default:
  5404.     s="(unknown)";
  5405.     }
  5406.     printf(" %19s: %-13s  %13s: %-15s\n","Bell",s,
  5407.        "Wrap",showoff(tt_wrap));
  5408.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5409.     printf(" %19s: %-13s  %13s: %-15s\n","Autopage",showoff(wy_autopage),
  5410.        "Autoscroll",showoff(autoscroll));
  5411.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5412.     printf(" %19s: %-13s  %13s: %-15s\n","SGR Colors",showoff(sgrcolors),
  5413.        "ESC[0m color",colorreset?"default-color":"current-color");
  5414.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5415.     printf(" %19s: %-13s  %13s: %-15s\n",
  5416.             "Erase color",user_erasemode?"default-color":"current-color",
  5417.        "Screen mode",decscnm?"reverse":"normal");
  5418.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5419.  
  5420.     printf(" %19s: %-13d  %13s: %-15d\n","Transmit-timeout",tt_ctstmo,
  5421.        "Output-pacing",tt_pacing);
  5422.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5423.  
  5424.     printf(" %19s: %-13d  %13s: %s\n","Idle-timeout",tt_idlelimit,
  5425.        "Idle-action", getiact());
  5426.  
  5427.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5428.     printf(" %19s: %-13s  %13s: %-15s\n","Send data",
  5429.       showoff(tt_senddata),"End of Block", wy_blockend?"crlf/etx":"us/cr");
  5430.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5431. #ifndef NOTRIGGER
  5432.     printf(" %19s: %-13s  %13s: %d seconds\n","Auto-exit trigger",
  5433.        tt_trigger[0],"Output pacing",tt_pacing );
  5434.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5435. #endif /* NOTRIGGER */
  5436.     printf(" %19s: %-13s  %13s: %-15d\n","Margin bell",
  5437.        showoff(marginbell),"at column", marginbellcol);
  5438.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5439.     switch (tt_modechg) {
  5440.       case TVC_DIS: s = "disabled"; break;
  5441.       case TVC_ENA: s = "enabled";  break;
  5442.       case TVC_W95: s = "win95-restricted"; break;
  5443.       default: s = "(unknown)";
  5444.     }
  5445.     printf(" %19s: %-13s  %13s: %-15s\n","DG Unix mode",
  5446.        showoff(dgunix),"Video change", s);
  5447.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5448.  
  5449. #ifdef CK_APC
  5450.     if (apcstatus == APC_ON) s = "on";
  5451.     else if (apcstatus == APC_OFF) s = "off";
  5452.     else if (apcstatus == APC_ON|APC_UNCH) s = "unchecked";
  5453.     else if (apcstatus == APC_ON|APC_NOINP) s = "no-input";
  5454.     else if (apcstatus == APC_ON|APC_UNCH|APC_NOINP) s = "unchecked-no-input";
  5455.     printf(" %19s: %-13s  %13s: %-15s\n",
  5456.        "APC", s,
  5457. #ifdef PCFONTS
  5458.        "Font (VGA)",font
  5459. #else /* PCFONTS */
  5460. #ifdef KUI
  5461.            "Font",font
  5462. #else
  5463.        "Font (VGA)","(not supported)"
  5464. #endif /* KUI */
  5465. #endif /* PCFONTS */
  5466.  
  5467.        );
  5468. #endif /* CK_APC */
  5469.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5470.  
  5471. #ifdef CK_TTGWSIZ            /* Console terminal screen size */
  5472.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  5473.       ttgwsiz();            /* Try to get latest size */
  5474. #endif /* CK_TTGWSIZ */
  5475.     printf(" %19s: %-13d  %13s: %-15d\n","Height",tt_rows[VTERM],
  5476.            "Width",tt_cols[VTERM]);
  5477.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5478.     printf(" %19s: %-13s  %13s: %d lines\n","Roll-mode",
  5479.       tt_roll[VTERM]?"insert":"overwrite","Scrollback", tt_scrsize[VTERM]);
  5480.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5481.  
  5482.     if (updmode == tt_updmode)
  5483.       if (updmode == TTU_FAST)
  5484.     s = "fast (fast)";
  5485.       else
  5486.     s = "smooth (smooth)";
  5487.     else
  5488.       if (updmode == TTU_FAST)
  5489.     s = "fast (smooth)";
  5490.       else
  5491.     s = "smooth (fast)";
  5492.  
  5493.     printf(" %19s: %-13s  %13s: %d ms\n","Screen-update: mode",s,
  5494.        "interval",tt_update);
  5495.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5496.     printf(" %19s: %-13s  %13s: %-15s\n",
  5497.        "Screen-optimization",showoff(tt_diff_upd),
  5498.        "Status line",showoff(tt_status[VTERM]));
  5499.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5500.     printf(" %19s: %-13s  %13s: %-15s\n","Debug",
  5501.        showoff(debses),"Session log", seslog? sesfil : "(none)" );
  5502.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5503.  
  5504.     /* Display colors (should become SHOW COLORS) */
  5505.     {
  5506.         USHORT row, col;
  5507.         char * colors[16] = {
  5508.             "black","blue","green","cyan","red","magenta","brown","lgray",
  5509.             "dgray","lblue","lgreen","lcyan","lred","lmagent","yellow","white"
  5510.     };
  5511.         printf("\n");
  5512.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5513.  
  5514.         printf(" Color:");
  5515. #ifndef ONETERMUPD
  5516.         GetCurPos(&row, &col);
  5517.         WrtCharStrAtt("border",    6, row, 9, &colorborder );
  5518.     WrtCharStrAtt("debug",     5, row, 17, &colordebug );
  5519.         WrtCharStrAtt("helptext",  8, row, 25, &colorhelp );
  5520.     WrtCharStrAtt("reverse",   7, row, 34, &colorreverse );
  5521.         WrtCharStrAtt("select",    6, row, 42, &colorselect );
  5522.         WrtCharStrAtt("status",    6, row, 50, &colorstatus );
  5523.         WrtCharStrAtt("terminal",  8, row, 58, &colornormal );
  5524.     WrtCharStrAtt("underline",  9, row, 67, &colorunderline );
  5525. #endif /* ONETERMUPD */
  5526.         row = VscrnGetCurPos(VCMD)->y+1;
  5527.         VscrnWrtCharStrAtt(VCMD, "border",    6, row, 9, &colorborder );
  5528.     VscrnWrtCharStrAtt(VCMD, "debug",     5, row, 17, &colordebug );
  5529.         VscrnWrtCharStrAtt(VCMD, "helptext",  8, row, 25, &colorhelp );
  5530.     VscrnWrtCharStrAtt(VCMD, "reverse",   7, row, 34, &colorreverse );
  5531.         VscrnWrtCharStrAtt(VCMD, "select",    6, row, 42, &colorselect );
  5532.         VscrnWrtCharStrAtt(VCMD, "status",    6, row, 50, &colorstatus );
  5533.         VscrnWrtCharStrAtt(VCMD, "terminal",  8, row, 58, &colornormal );
  5534.     VscrnWrtCharStrAtt(VCMD, "underline",  9, row, 67, &colorunderline );
  5535.         printf("\n");
  5536.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5537.  
  5538.         /* Foreground color names */
  5539.         printf("%6s: %-8s%-8s%-9s%-8s%-8s%-8s%-9s%-9s\n","fore",
  5540.         "",
  5541.         colors[colordebug&0x0F],
  5542.         colors[colorhelp&0x0F],
  5543.         colors[colorreverse&0x0F],
  5544.         colors[colorselect&0x0F],
  5545.         colors[colorstatus&0x0F],
  5546.         colors[colornormal&0x0F],
  5547.         colors[colorunderline&0x0F] );
  5548.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5549.  
  5550.         /* Background color names */
  5551.         printf("%6s: %-8s%-8s%-9s%-8s%-8s%-8s%-9s%-9s\n","back",
  5552.         colors[colorborder],
  5553.         colors[colordebug>>4],
  5554.         colors[colorhelp>>4],
  5555.         colors[colorreverse>>4],
  5556.         colors[colorselect>>4],
  5557.         colors[colorstatus>>4],
  5558.         colors[colornormal>>4],
  5559.         colors[colorunderline>>4] );
  5560.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5561.         printf("\n");
  5562.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5563.         printf(" Color:");
  5564. #ifndef ONETERMUPD
  5565.         GetCurPos(&row, &col);
  5566.         WrtCharStrAtt("graphic",   7, row, 9, &colorgraphic );
  5567.     WrtCharStrAtt("command",   7, row, 17, &colorcmd );
  5568. #endif /* ONETERMUPD */
  5569.         row = VscrnGetCurPos(VCMD)->y+1;
  5570.         VscrnWrtCharStrAtt(VCMD, "graphic",   7, row, 9,  &colorgraphic );
  5571.     VscrnWrtCharStrAtt(VCMD, "command",   7, row, 17, &colorcmd );
  5572.         printf("\n");
  5573.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5574.  
  5575.         /* Foreground color names */
  5576.         printf("%6s: %-8s%-8s\n","fore",
  5577.         colors[colorgraphic&0x0F],
  5578.         colors[colorcmd&0x0F] );
  5579.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5580.  
  5581.         /* Background color names */
  5582.         printf("%6s: %-8s%-8s\n","back",
  5583.         colors[colorgraphic>>4],
  5584.         colors[colorcmd>>4] );
  5585.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5586.     }
  5587.     printf("\n");
  5588.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5589.     {
  5590.         extern int trueblink, truereverse, trueunderline;
  5591.         printf(" Attribute:  blink: %-3s  reverse: %-3s  underline: %-3s\n",
  5592.                 trueblink?"on":"off", truereverse?"on":"off",
  5593.                 trueunderline?"on":"off");
  5594.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5595.     }
  5596.     {
  5597.         extern vtattrib WPattrib;
  5598.         printf(" ASCII Protected chars: %s%s%s%s%s%s\n",
  5599.                 WPattrib.blinking?"blink ":"",
  5600.                 WPattrib.reversed?"reverse ":"",
  5601.                 WPattrib.underlined?"underline ":"",
  5602.                 WPattrib.bold?"bold ":"",
  5603.                 WPattrib.dim?"dim ":"",
  5604.                 WPattrib.invisible?"invisible ":"");
  5605.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5606.     }
  5607.  
  5608.     printf("\n");
  5609.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5610.  
  5611.     printf(" CONNECT-mode escape character: %d (Ctrl-%c, %s): %s\n",
  5612.        escape,ctl(escape),(escape == 127 ? "DEL" : ccntab[escape]),
  5613.        nm[tt_escape]);
  5614.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5615.     printf(" See SHOW CHARACTER-SETS for character-set info\n");
  5616.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5617.  
  5618. #else /* OS2 */   /* Beginning of new non-OS2 version */
  5619.  
  5620.     printf("\n");
  5621.     printf("Terminal parameters:\n");
  5622.     printf(" %19s: %1d%-12s  %13s: %1d%-14s\n",
  5623.        "Bytesize: Command",
  5624.            (cmdmsk == 0377) ? 8 : 7,
  5625.            " bits","Terminal",
  5626.            (cmask == 0377) ? 8 : 7," bits");
  5627.     s = getenv("TERM");
  5628. #ifdef XPRINT
  5629.     printf(" %19s: %-13s  %13s: %-15s\n",
  5630.        "Type",
  5631.        s ? s : "(unknown)",
  5632.        "Print",
  5633.        showoff(tt_print)
  5634.        );
  5635. #else
  5636.     printf(" %19s: %-13s\n","Type", s ? s : "(unknown)");
  5637. #endif /* XPRINT */
  5638.     printf(" %19s: %-13s  %13s: %-15s\n","Echo",
  5639.        duplex ? "local" : "remote","Locking-shift",showoff(sosi));
  5640.     printf(" %19s: %-13s  %13s: %-15s\n","Newline-mode",
  5641.        showoff(tnlm),"Cr-display",tt_crd ? "crlf" : "normal");
  5642.  
  5643. #ifdef CK_APC
  5644.     if (apcstatus == APC_ON) s = "on";
  5645.     else if (apcstatus == APC_OFF) s = "off";
  5646.     else if (apcstatus == APC_ON|APC_UNCH) s = "unchecked";
  5647.     else if (apcstatus == APC_ON|APC_NOINP) s = "no-input";
  5648.     else if (apcstatus == APC_ON|APC_UNCH|APC_NOINP) s = "unchecked-no-input";
  5649.     printf(" %19s: %-13s  %13s: %-15s\n",
  5650.        "APC", s,
  5651. #ifdef CK_AUTODL
  5652.        "Autodownload", autodl ?
  5653.        (adl_err ? "on, error stop" : "on, error continue") : "off"
  5654. #else
  5655.        "",""
  5656. #endif /* CK_AUTODL */
  5657.        );
  5658. #endif /* CK_APC */
  5659.  
  5660. #ifdef CK_TTGWSIZ            /* Console terminal screen size */
  5661.     ttgwsiz();                /* Try to get latest size */
  5662.     printf(" %19s: %-13d  %13s: %-15d\n","Height",tt_rows, "Width", tt_cols);
  5663. #endif /* CK_TTGWSIZ */
  5664.  
  5665.     printf(" %19s: %-13s  %13s: %-15s\n","Debug",
  5666.        showoff(debses),"Session log", seslog? sesfil : "(none)" );
  5667.  
  5668. #ifdef CKTIDLE
  5669.     printf(" %19s: %-13d  %13s: %s\n","Idle-timeout",tt_idlelimit,
  5670.        "Idle-action", getiact());
  5671. #endif /* CKTIDLE */
  5672.  
  5673. #ifndef NOTRIGGER
  5674.     printf(" %19s: %-13s\n","Trigger",
  5675.        tt_trigger[0] ? tt_trigger[0] : "(none)");
  5676. #endif /* NOTRIGGER */
  5677. #ifdef UNIX
  5678. #ifndef NOJC
  5679.     printf(" %19s: %-13s\n\n","Suspend", showoff(suspend));
  5680. #endif /* NOJC */
  5681. #endif /* UNIX */
  5682.  
  5683.     printf("\n");
  5684.     printf(" CONNECT-mode escape character: %d (Ctrl-%c, %s): %s\n",
  5685.        escape,ctl(escape),(escape == 127 ? "DEL" : ccntab[escape]),
  5686.        nm[tt_escape]
  5687.        );
  5688. #ifndef NOCSETS
  5689.     shotcs(tcsl,tcsr);        /* Show terminal character sets */
  5690. #endif /* NOCSETS */
  5691.  
  5692. #endif /* OS2 */
  5693. }
  5694.  
  5695. VOID
  5696. shmdmlin() {                /* Briefly show modem & line */
  5697. #ifndef NODIAL
  5698. #ifndef MINIDIAL
  5699. #ifdef OLDTBCODE
  5700.     extern int tbmodel;
  5701.     _PROTOTYP( char * gtbmodel, (void) );
  5702. #endif /* OLDTBCODE */
  5703. #endif /* MINIDIAL */
  5704. #endif /* NODIAL */
  5705.     if (local)
  5706. #ifdef OS2
  5707.       printf(" Port: %s, Modem type: ",ttname);
  5708. #else
  5709.       printf(" Line: %s, Modem type: ",ttname);
  5710. #endif /* OS2 */
  5711.     else
  5712.       printf(
  5713. #ifdef OS2
  5714. " Communication device not yet selected with SET PORT\n Modem type: "
  5715. #else
  5716. " Communication device not yet selected with SET LINE\n Modem type: "
  5717. #endif /* OS2 */
  5718.          );
  5719. #ifndef NODIAL
  5720.     printf("%s",gmdmtyp());
  5721. #ifndef MINIDIAL
  5722. #ifdef OLDTBCODE
  5723.     if (tbmodel) printf(" (%s)",gtbmodel()); /* Telebit model info */
  5724. #endif /* OLDTBCODE */
  5725. #endif /* MINIDIAL */
  5726. #else
  5727.     printf("(disabled)");
  5728. #endif /* NODIAL */
  5729. }
  5730.  
  5731. #ifdef CK_TAPI
  5732. void
  5733. shotapi(int option) {
  5734.     int rc=0,k ;
  5735.     char *s=NULL;
  5736.     LPDEVCFG        lpDevCfg = NULL;
  5737.     LPCOMMCONFIG    lpCommConfig = NULL;
  5738.     LPMODEMSETTINGS lpModemSettings = NULL;
  5739.     DCB *           lpDCB = NULL;
  5740.     extern struct keytab * tapiloctab;    /* Microsoft TAPI Locations */
  5741.     extern int ntapiloc;
  5742.     extern struct keytab * tapilinetab;    /* Microsoft TAPI Line Devices */
  5743.     extern int ntapiline;
  5744.     extern int tttapi;            /* TAPI in use */
  5745.     extern int tapipass;        /* TAPI Passthrough mode */
  5746.     extern int tapiconv;        /* TAPI Conversion mode */
  5747.     extern int tapilights;
  5748.     extern int tapipreterm;
  5749.     extern int tapipostterm;
  5750.     extern int tapimanual;
  5751.     extern int tapiinactivity;
  5752.     extern int tapibong;
  5753.     extern int tapiusecfg;
  5754.     extern char tapiloc[];
  5755.     extern int tapilocid;
  5756.     extern int TAPIAvail;
  5757.  
  5758.     if (!TAPIAvail) {
  5759.         printf("TAPI Support not enabled\r\n");
  5760.         return;
  5761.     }
  5762.     switch (option) {
  5763.       case 0:
  5764.     printf("TAPI Settings:\n");
  5765.     printf("  Line:                      %s\n",
  5766.            tttapi ? ttname : "(none in use)");
  5767.  
  5768.     cktapiBuildLocationTable(&tapiloctab, &ntapiloc);
  5769.     if (tapilocid == -1)
  5770.       tapilocid = cktapiGetCurrentLocationID();
  5771.  
  5772.     /* Find the current tapiloc entry */
  5773.     /* and use it as the default. */
  5774.     for (k = 0; k < ntapiloc; k++) {
  5775.         if (tapiloctab[k].kwval == tapilocid)
  5776.           break;
  5777.     }
  5778.     if (k >= 0 && k < ntapiloc)
  5779.       s = tapiloctab[k].kwd;
  5780.     else
  5781.       s = "(unknown)";
  5782.     printf("  Location:                  %s\n",s);
  5783.     printf("  Modem-dialing:             %s\n",tapipass?"off":"on");
  5784.     printf("  Phone-number-conversions:  %s\n",
  5785.         tapiconv==CK_ON?"on":tapiconv==CK_AUTO?"auto":"off");
  5786.     printf("  Modem-lights:              %s %s\n",tapilights?"on ":"off",
  5787.         tapipass?"(n/a)":"");
  5788.     printf("  Predial-terminal:          %s %s\n",tapipreterm?"on ":"off",
  5789.         tapipass?"(n/a)":"");
  5790.     printf("  Postdial-terminal:         %s %s\n",tapipostterm?"on ":"off",
  5791.         tapipass?"(n/a)":"");
  5792.     printf("  Manual-dial:               %s %s\n",tapimanual?"on ":"off",
  5793.         tapipass?"(n/a)":"");
  5794.     printf("  Inactivity-timeout:        %d seconds %s\n",tapiinactivity,
  5795.         tapipass?"(n/a)":"");
  5796.     printf("  Wait-for-bong:             %d seconds %s\n",tapibong,
  5797.         tapipass?"(n/a)":"");
  5798.     printf("  Use-windows-configuration: %s %s\n",
  5799.         tapiusecfg?"on ":"off", tapipass?"(n/a)":"");
  5800.     printf("\n");
  5801.  
  5802. #ifdef BETATEST
  5803.     if (tapipass) {
  5804. printf("K-95 uses the TAPI Line in an exclusive mode.  Other applications\n");
  5805. printf("may open the device but may not place calls nor answer calls.\n");
  5806. printf("Dialing is performed using the K-95 dialing procedures.  SET MODEM\n");
  5807. printf("TYPE TAPI after the SET TAPI LINE command to activate the modem\n");
  5808. printf("definition associated with the active TAPI LINE device.\n\n");
  5809.  
  5810.     } else {
  5811.  
  5812. printf("K-95 uses the TAPI Line in a cooperative mode.  Other applications\n");
  5813. printf("may open the device, place and answer calls.  Dialing is performed\n");
  5814. printf("by TAPI.  K-95 SET MODEM commands are not used.\n\n");
  5815.     }
  5816.  
  5817.     if (tapiconv == CK_ON ||
  5818.         tapiconv == CK_AUTO && !tapipass) {
  5819. printf(
  5820. "Phone numbers are converted from canonical to dialable form by TAPI\n");
  5821. printf("using the dialing rules specified in the TAPI Dialing Properties\n");
  5822. printf("dialog.\n\n");
  5823.  
  5824.     } else {
  5825.  
  5826. printf(
  5827. "Phone numbers are converted from canonical to dialable form by K-95\n");
  5828. printf(
  5829. "using the dialing rules specified with the SET DIAL commands.  TAPI\n");
  5830. printf(
  5831. "Dialing Properties are imported automaticly upon startup and whenever\n");
  5832. printf("the TAPI Dialing Properties are altered or when the TAPI Location\n");
  5833. printf("is changed.\n\n");
  5834.         }
  5835. #endif /* BETATEST */
  5836.  
  5837.     if (tapipass) {
  5838.         printf("Type SHOW MODEM to see MODEM configuration.\n");
  5839.         if (tapiconv == CK_ON)
  5840.           printf("Type SHOW DIAL to see DIAL-related items.\n");
  5841.     } else {
  5842.         if (tapiconv == CK_ON || tapiconv == CK_AUTO)
  5843.           printf("Type SHOW DIAL to see DIAL-related items.\n");
  5844.     }
  5845.     break;
  5846.       case 1:
  5847.     cktapiDisplayTapiLocationInfo();
  5848.     break;
  5849.       case 2:
  5850.         rc = cktapiGetModemSettings(&lpDevCfg,&lpModemSettings,
  5851.                      &lpCommConfig,&lpDCB);
  5852.         if (rc) {
  5853.         cktapiDisplayModemSettings(lpDevCfg,lpModemSettings,
  5854.                      lpCommConfig,lpDCB);
  5855.     } else {
  5856.         printf("?Unable to retrieve Modem Settings\n");
  5857.     }
  5858.         break;
  5859.       case 3: {
  5860.       HANDLE hModem = GetModemHandleFromLine((HLINE)0);
  5861.       if (hModem)
  5862.         DisplayCommProperties(hModem);
  5863.       else
  5864.         printf("?Unable to retrieve a valid Modem Handle\n");
  5865.       CloseHandle(hModem);
  5866.       break;
  5867.       }
  5868.     }
  5869.     printf("\n");
  5870. }
  5871. #endif /* CK_TAPI */
  5872. #endif /* NOLOCAL */
  5873.  
  5874. #ifdef PATTERNS
  5875. static VOID
  5876. shopat() {
  5877.     extern char * binpatterns[], * txtpatterns[];
  5878.     extern int patterns, filepeek;
  5879.     char **p, *s;
  5880.     int i, j, k, n, flag, width;
  5881. #ifdef CK_TTGWSIZ
  5882.     ttgwsiz();                /* Try to get latest size */
  5883. #ifdef OS2
  5884.     width = tt_cols[VCMD];
  5885. #else /* OS2 */
  5886.     width = tt_cols;
  5887. #endif /* OS2 */
  5888.     if (width < 1)
  5889. #endif /* CK_TTGWSIZ */
  5890.       width = 80;
  5891.     printf("\n");
  5892.     printf(" Set file type:            %s\n",gfmode(binary,1));
  5893.     printf(" Set file patterns:        %s", showooa(patterns));
  5894. #ifdef CK_LABELED
  5895.     if (binary == XYFT_L)
  5896.       printf(" (but SET FILE TYPE LABELED overrides)\n");
  5897.     else
  5898. #endif /* CK_LABELED */
  5899. #ifdef VMS
  5900.     if (binary == XYFT_I)
  5901.       printf(" (but SET FILE TYPE IMAGE overrides)\n");
  5902.     else
  5903. #endif /* VMS */
  5904.     if (filepeek)
  5905.       printf(" (but SET FILE SCAN ON overrides)\n");
  5906.     else
  5907.       printf("\n");
  5908.     printf(" Maximum patterns allowed: %d\n", FTPATTERNS);
  5909.     for (k = 0; k < 2; k++) {        /* For each kind of patter */
  5910.     printf("\n");
  5911.     if (k == 0) {            /* binary... */
  5912.         printf(" File binary-patterns: ");
  5913.         p = binpatterns;
  5914.     } else {            /* text... */
  5915.         printf(" File text-patterns:   ");
  5916.         p = txtpatterns;
  5917.     }
  5918.     if (!p[0]) {
  5919.         printf("(none)\n");
  5920.     } else {
  5921.         printf("\n ");
  5922.         n = 2;
  5923.         for (i = 0; i < FTPATTERNS; i++) { /* For each pattern */
  5924.         if (!p[i])        /* Done */
  5925.           break;
  5926.         s = p[i];        /* Look for embedded space */
  5927.         for (j = 0, flag = 1; *s; s++, j++) /* and also get length */
  5928.           if (*s == SP)
  5929.             flag = 3;
  5930.         n += j + flag;        /* Length of this line */
  5931.         if (n >= width - 1) {
  5932.             printf("\n ");
  5933.             n = j+2;
  5934.         }
  5935.         printf(flag == 3 ? " {%s}" : " %s", p[i]);
  5936.         }
  5937.         if (n > 2)
  5938.           printf("\n");
  5939.     }
  5940.     }
  5941.     printf("\n");
  5942. }
  5943. #endif /* PATTERNS */
  5944.  
  5945. #ifndef NOSPL
  5946. static VOID
  5947. shooutput() {
  5948.     printf(" Output pacing:          %d (milliseconds)\n",pacing);
  5949.     printf(" Output special-escapes: %s\n", showoff(outesc));
  5950. }
  5951.  
  5952. static VOID
  5953. shoinput() {
  5954. #ifdef CK_AUTODL
  5955.     printf(" Input autodownload:     %s\n", showoff(inautodl));
  5956. #endif /* CK_AUTODL */
  5957.     printf(" Input cancellation:     %s\n", showoff(inintr));
  5958.     printf(" Input case:             %s\n", inpcas[cmdlvl] ?
  5959.        "observe" : "ignore");
  5960.     printf(" Input buffer-length:    %d\n", inbufsize);
  5961.     printf(" Input echo:             %s\n", showoff(inecho));
  5962.     printf(" Input silence:          %d (seconds)\n", insilence);
  5963. #ifdef OS2
  5964.     printf(" Input terminal:         %s\n", showoff(interm));
  5965. #endif /* OS2 */
  5966.     printf(" Input timeout:          %s\n", intime[cmdlvl] ?
  5967.        "quit" : "proceed");
  5968.     if (instatus < 0)
  5969.       printf(" Last INPUT:             -1 (INPUT command not yet given)\n");
  5970.     else
  5971.       printf(" Last INPUT:             %d (%s)\n", instatus,i_text[instatus]);
  5972. }
  5973. #endif /* NOSPL */
  5974.  
  5975. #ifndef NOSPL
  5976. int
  5977. showarray() {
  5978. #ifdef COMMENT
  5979.     char * p, * q, ** ap;
  5980.     int i;
  5981. #endif /* COMMENT */
  5982.     char *s; int x = 0, y;
  5983.     int range[2];
  5984.  
  5985.     if ((y = cmfld("Array name","",&s,NULL)) < 0)
  5986.       if (y != -3)
  5987.     return(y);
  5988.     ckstrncpy(line,s,LINBUFSIZ);
  5989.     s = line;
  5990.     if ((y = cmcfm()) < 0)
  5991.       return(y);
  5992.     if (*s) {
  5993.     char ** ap;
  5994.     if ((x = arraybounds(s,&(range[0]),&(range[1]))) < 0) {
  5995.         printf("?Bad array: %s\n",s);
  5996.         return(-9);
  5997.     }
  5998.     ap = a_ptr[x];
  5999.     if (!ap) {
  6000.         printf("Array not declared: %s\n", s);
  6001.         return(success = 1);
  6002.     } else {
  6003.         int i, n, max;
  6004.         max = (range[1] > 0) ?
  6005.           range[1] :
  6006.         ((range[0] > 0) ? range[0] : a_dim[x]);
  6007.         if (range[0] < 0)
  6008.           range[0] = 0;
  6009.         if (max > a_dim[x])
  6010.           max = a_dim[x];
  6011.         n = 1;
  6012.         printf("\\&%c[]: Dimension = %d",arrayitoa(x),a_dim[x]);
  6013.         if (a_link[x] > -1)
  6014.           printf(" (Link to \\&%c[])",arrayitoa(a_link[x]));
  6015.         printf("\n");
  6016.         for (i = range[0]; i <= max; i++) {
  6017.         if (ap[i]) {
  6018.             printf("%3d. %s\n",i,ap[i]);
  6019.             if (xaskmore) {
  6020.             if (cmd_cols > 0) {
  6021.                 x = strlen(ap[i]) + 5;
  6022.                 y = (x % cmd_cols) ? 1 : 0;
  6023.                 n += (x / cmd_cols) + y;
  6024.             } else {
  6025.                 n++;
  6026.             }
  6027.             if (n > (cmd_rows - 3)) {
  6028.                 if (!askmore())
  6029.                   break;
  6030.                 else
  6031.                   n = 0;
  6032.             }
  6033.             }
  6034.         }
  6035.         }
  6036.     }
  6037.     return(1);
  6038.     }
  6039.  
  6040.     /* All arrays - just show name and dimension */
  6041.  
  6042.     for (y = 0; y < (int) 'z' - ARRAYBASE + 1; y++) {
  6043.     if (a_ptr[y]) {
  6044.         if (x == 0) printf("Declared arrays:\n");
  6045.         x = 1;
  6046.         printf(" \\&%c[%d]",
  6047.            (y == 1) ? 64 : y + ARRAYBASE, a_dim[y]);
  6048.         if (a_link[y] > -1)
  6049.           printf(" => \\&%c[]",arrayitoa(a_link[y]));
  6050.         printf("\n");
  6051.     }
  6052.     if (!x) printf(" No arrays declared\n");
  6053.     }
  6054.     return(1);
  6055. }
  6056. #endif /* NOSPL */
  6057.  
  6058. int
  6059. doshow(x) int x; {
  6060.     int y, z, i; long zz;
  6061.     extern int optlines;
  6062.     char *s;
  6063. #ifdef OS2
  6064.     extern int os2gks;
  6065.     extern int tt_kb_mode;
  6066. #endif /* OS2 */
  6067.     extern int srvcdmsg;
  6068.     extern char * cdmsgstr, * ckcdpath;
  6069.  
  6070. #ifndef NOSETKEY
  6071.     if (x == SHKEY) {            /* SHOW KEY */
  6072.         int c;
  6073. #ifdef OS2
  6074.         if ((x = cmkey(shokeytab,nshokey,"How many keys should be shown?",
  6075.                         "one",xxstring)) < 0) return(x);
  6076.     switch (tt_kb_mode) {
  6077.       case KBM_EM:
  6078.         s = "emacs";
  6079.         break;
  6080.       case KBM_HE:
  6081.         s = "hebrew";
  6082.         break;
  6083.       case KBM_RU:
  6084.         s = "russian";
  6085.         break;
  6086.       case KBM_EN:
  6087.       default:
  6088.         s = "default";
  6089.         break;
  6090.     }
  6091.         if ((z = cmkey(shokeymtab,nshokeym,"Which definition should be shown?",
  6092.                         s,xxstring)) < 0) return(z);
  6093.     if (z == SHKEYDEF)
  6094.       z = -1;
  6095. #endif /* OS2 */
  6096.         if ((y = cmcfm()) < 0) return(y);
  6097. #ifdef IKSD
  6098.         if (inserver) {
  6099.             printf("Sorry, command disabled.\r\n");
  6100.             return(success = 0);
  6101.         }
  6102. #endif /* IKSD */
  6103.  
  6104. #ifdef MAC
  6105.     printf("Not implemented\n");
  6106.     return(0);
  6107. #else /* Not MAC */
  6108. #ifdef OS2
  6109.         if (x) {
  6110.         con_event evt;
  6111.         for (c = 0; c < KMSIZE; c++) {
  6112.         evt = (z < 0) ? mapkey(c) : maptermkey(c,z);
  6113.         if (evt.type != error) {
  6114.             shokeycode(c,z);
  6115.         }
  6116.         }
  6117.         } else {
  6118. #endif /* OS2 */
  6119.         printf(" Press key: ");
  6120. #ifdef UNIX
  6121. #ifdef NOSETBUF
  6122.         fflush(stdout);
  6123. #endif /* NOSETBUF */
  6124. #endif /* UNIX */
  6125.         conbin((char)escape);    /* Put terminal in binary mode */
  6126. #ifdef OS2
  6127.         os2gks = 0;            /* Raw scancode processing */
  6128. #endif /* OS2 */
  6129.         c = congks(0);        /* Get character or scan code */
  6130. #ifdef OS2
  6131.         os2gks = 1;            /* Cooked scancode processing */
  6132. #endif /* OS2 */
  6133.         concb((char)escape);    /* Restore terminal to cbreak mode */
  6134.         if (c < 0) {        /* Check for error */
  6135.         printf("?Error reading key\n");
  6136.         return(0);
  6137.         }
  6138. #ifndef OS2
  6139. /*
  6140.   Do NOT mask when it can be a raw scan code, perhaps > 255
  6141. */
  6142.         c &= cmdmsk;        /* Apply command mask */
  6143. #endif /* OS2 */
  6144.         printf("\n");
  6145. #ifdef OS2
  6146.         shokeycode(c,z);
  6147. #else /* OS2 */
  6148.         shokeycode(c);
  6149. #endif /* OS2 */
  6150. #ifdef OS2
  6151.         }
  6152. #endif /* OS2 */
  6153.     return(1);
  6154. #endif /* MAC */
  6155.     }
  6156. #ifndef NOKVERBS
  6157.     if (x == SHKVB) {            /* SHOW KVERBS */
  6158.     if ((y = cmcfm()) < 0) return(y);
  6159. #ifdef IKSD
  6160.         if (inserver) {
  6161.             printf("Sorry, command disabled.\r\n");
  6162.             return(success = 0);
  6163.         }
  6164. #endif /* IKSD */
  6165.     printf("\nThe following %d keyboard verbs are available:\n\n",nkverbs);
  6166.     kwdhelp(kverbs,nkverbs,"","\\K","",3,0);
  6167.     printf("\n");
  6168.     return(1);
  6169.     }
  6170. #ifdef OS2
  6171.     if (x == SHUDK) {            /* SHOW UDKs */
  6172.     extern void showudk(void);
  6173.     if ((y = cmcfm()) < 0) return(y);
  6174. #ifdef IKSD
  6175.         if (inserver) {
  6176.             printf("Sorry, command disabled.\r\n");
  6177.             return(success = 0);
  6178.         }
  6179. #endif /* IKSD */
  6180.     showudk();
  6181.     return(1);
  6182.     }
  6183. #endif /* OS2 */
  6184. #endif /* NOKVERBS */
  6185. #endif /* NOSETKEY */
  6186.  
  6187. #ifndef NOSPL
  6188.     if (x == SHMAC) {            /* SHOW MACRO */
  6189.     struct FDB kw, fl, cm;
  6190.     int i, k, n = 0, left, flag, confirmed = 0;
  6191.     char * p, *q[64];
  6192.     for (i = 0; i < nmac; i++) {    /* copy the macro table */
  6193.         mackey[i].kwd = mactab[i].kwd; /* into a regular keyword table */
  6194.         mackey[i].kwval = i;    /* with value = pointer to macro tbl */
  6195.         mackey[i].flgs = mactab[i].flgs;
  6196.     }
  6197.     p = line;
  6198.     left = LINBUFSIZ;
  6199.     while (!confirmed && n < 64) {
  6200.         cmfdbi(&kw,            /* First FDB - macro table */
  6201.            _CMKEY,        /* fcode */
  6202.            "Macro name",    /* hlpmsg */
  6203.            "",            /* default */
  6204.            "",            /* addtl string data */
  6205.            nmac,        /* addtl numeric data 1: tbl size */
  6206.            0,            /* addtl numeric data 2: 4 = cmswi */
  6207.            xxstring,        /* Processing function */
  6208.            mackey,        /* Keyword table */
  6209.            &fl            /* Pointer to next FDB */
  6210.            );
  6211.         cmfdbi(&fl,            /* 2nd FDB - something not in mactab */
  6212.            _CMFLD,        /* fcode */
  6213.            "",            /* hlpmsg */
  6214.            "",            /* default */
  6215.            "",            /* addtl string data */
  6216.            0,            /* addtl numeric data 1 */
  6217.            0,            /* addtl numeric data 2 */
  6218.            xxstring,
  6219.            NULL,
  6220.            &cm
  6221.            );
  6222.         cmfdbi(&cm,            /* 3rd FDB - Confirmation */
  6223.            _CMCFM,        /* fcode */
  6224.            "",            /* hlpmsg */
  6225.            "",            /* default */
  6226.            "",            /* addtl string data */
  6227.            0,            /* addtl numeric data 1 */
  6228.            0,            /* addtl numeric data 2 */
  6229.            NULL,
  6230.            NULL,
  6231.            NULL
  6232.            );
  6233.         x = cmfdb(&kw);        /* Parse something */
  6234.         if (x < 0)
  6235.           return(x);
  6236.         s = atmbuf;            /* What the user typed */
  6237.         switch (cmresult.fcode) {
  6238.           case _CMKEY:        /* If it was a keyword */
  6239.         y = mlook(mactab,atmbuf,nmac); /* get full name */
  6240.         if (y > -1)
  6241.           s = mactab[y].kwd;    /* (fall thru on purpose...) */
  6242.           case _CMFLD:
  6243.         k = ckstrncpy(p,s,left) + 1; /* Copy result to list */
  6244.         left -= k;
  6245.         if (left <= 0) {
  6246.             *p = NUL;
  6247.             break;
  6248.         }
  6249.         q[n++] = p;        /* Point to this item */
  6250.         p += k;            /* Move buffer pointer past it */
  6251.         break;
  6252.           case _CMCFM:        /* End of command */
  6253.         confirmed++;
  6254.           default:
  6255.         break;
  6256.         }
  6257.     }
  6258.     if (n == 0) {
  6259.         printf("Macros:\n");
  6260.         slc = 1;
  6261.         for (y = 0; y < nmac; y++)
  6262.           if (shomac(mactab[y].kwd,mactab[y].mval) < 0) break;
  6263.         return(1);
  6264.     }
  6265.     slc = 0;
  6266.     for (i = 0; i < n; i++) {
  6267.         flag = 0;
  6268.         s = q[i];
  6269.         if (!s) s = "";
  6270.         if (!*s) continue;
  6271.         if (iswild(s)) {        /* Pattern match */
  6272.         for (k = 0, x = 0; x < nmac; x++) {
  6273.             if (ckmatch(s,mactab[x].kwd,0,1)) {
  6274.             shomac(mactab[x].kwd,mactab[x].mval);
  6275.             k++;
  6276.             }
  6277.         }
  6278.         if (!k)
  6279.           x = -1;
  6280.         else
  6281.           continue;
  6282.         } else {            /* Exact match */
  6283.         x = mxlook(mactab,s,nmac);
  6284.         flag = 1;
  6285.         }
  6286.         if (flag && x == -1)
  6287.           x = mlook(mactab,s,nmac);
  6288.         switch (x) {
  6289.           case -3:            /* Nothing to look up */
  6290.           case -1:            /* Not found */
  6291.         printf("%s - (not defined)\n",s);
  6292.         break;
  6293.           case -2:            /* Ambiguous, matches more than one */
  6294.         printf("%s - ambiguous\n",s);
  6295.         break;
  6296.           default:            /* Matches one exactly */
  6297.         shomac(mactab[x].kwd,mactab[x].mval);
  6298.         break;
  6299.         }
  6300.     }
  6301.     return(1);
  6302.     }
  6303. #endif /* NOSPL */
  6304.  
  6305. /*
  6306.   Other SHOW commands only have two fields.  Get command confirmation here,
  6307.   then handle with big switch() statement.
  6308. */
  6309. #ifndef NOSPL
  6310.     if (x != SHBUI && x != SHARR)
  6311. #endif /* NOSPL */
  6312.       if ((y = cmcfm()) < 0)
  6313.     return(y);
  6314.  
  6315. #ifdef COMMENT
  6316.     /* This restriction is too general. */
  6317. #ifdef IKSD
  6318.     if (inserver &&
  6319. #ifdef CK_LOGIN
  6320.     isguest
  6321. #else
  6322.     0
  6323. #endif /* CK_LOGIN */
  6324.     ) {
  6325.     printf("Sorry, command disabled.\r\n");
  6326.     return(success = 0);
  6327.     }
  6328. #endif /* IKSD */
  6329. #endif /* COMMENT */
  6330.  
  6331.     switch (x) {
  6332.  
  6333. #ifdef ANYX25
  6334. #ifndef IBMX25
  6335.       case SHPAD:
  6336.     shopad(0);
  6337.     break;
  6338. #endif /* IBMX25 */
  6339. #endif /* ANYX25 */
  6340.  
  6341.       case SHNET:
  6342. #ifdef NOLOCAL
  6343.     printf(" No network support in this version of C-Kermit.\n");
  6344. #else
  6345. #ifndef NETCONN
  6346.     printf(" No network support in this version of C-Kermit.\n");
  6347. #else
  6348.     shonet();
  6349. #endif /* NETCONN */
  6350. #endif /* NOLOCAL */
  6351.     break;
  6352.  
  6353.       case SHPAR:
  6354.     shopar();
  6355.     break;
  6356.  
  6357. #ifndef NOXFER
  6358.       case SHATT:
  6359.     shoatt();
  6360.     break;
  6361. #endif /* NOXFER */
  6362.  
  6363. #ifndef NOSPL
  6364.       case SHCOU:
  6365.     printf(" %d\n",count[cmdlvl]);
  6366.     break;
  6367. #endif /* NOSPL */
  6368.  
  6369. #ifndef NOSERVER
  6370.       case SHSER:            /* Show Server */
  6371.     i = 0;
  6372. #ifndef NOFRILLS
  6373.     printf("Function:          Status:\n");
  6374.     i++;
  6375.     printf(" GET                %s\n",nm[en_get]);
  6376.     i++;
  6377.     printf(" SEND               %s\n",nm[en_sen]);
  6378.     i++;
  6379.     printf(" MAIL               %s\n",nm[inserver ? 0 : en_mai]);
  6380.     i++;
  6381.     printf(" PRINT              %s\n",nm[inserver ? 0 : en_pri]);
  6382.     i++;
  6383. #ifndef NOSPL
  6384.     printf(" REMOTE ASSIGN      %s\n",nm[en_asg]);
  6385.     i++;
  6386. #endif /* NOSPL */
  6387.     printf(" REMOTE CD/CWD      %s\n",nm[en_cwd]);
  6388.     i++;
  6389. #ifdef ZCOPY
  6390.     printf(" REMOTE COPY        %s\n",nm[en_cpy]);
  6391.     i++;
  6392. #endif /* ZCOPY */
  6393.     printf(" REMOTE DELETE      %s\n",nm[en_del]);
  6394.     printf(" REMOTE DIRECTORY   %s\n",nm[en_dir]);
  6395.     printf(" REMOTE HOST        %s\n",nm[inserver ? 0 : en_hos]);
  6396.     i += 3;
  6397. #ifndef NOSPL
  6398.     printf(" REMOTE QUERY       %s\n",nm[en_que]);
  6399.     i++;
  6400. #endif /* NOSPL */
  6401.     printf(" REMOTE MKDIR       %s\n",nm[en_mkd]);
  6402.     printf(" REMOTE RMDIR       %s\n",nm[en_rmd]);
  6403.     printf(" REMOTE RENAME      %s\n",nm[en_ren]);
  6404.     printf(" REMOTE SET         %s\n",nm[en_set]);
  6405.     printf(" REMOTE SPACE       %s\n",nm[en_spa]);
  6406.     printf(" REMOTE TYPE        %s\n",nm[en_typ]);
  6407.     printf(" REMOTE WHO         %s\n",nm[inserver ? 0 : en_who]);
  6408.     printf(" BYE                %s\n",nm[en_bye]);
  6409.     printf(" FINISH             %s\n",nm[en_fin]);
  6410.     printf(" EXIT               %s\n",nm[en_xit]);
  6411.     printf(" ENABLE             %s\n",nm[en_ena]);
  6412.     i += 11;
  6413. #endif /* NOFRILLS */
  6414.     if (i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6415.     printf("Server timeout:      %d\n",srvtim);
  6416.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6417.         printf("Server idle-timeout: %d\n",srvidl);
  6418.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6419.     printf("Server keepalive     %s\n", showoff(srvping));
  6420.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6421.     printf("Server cd-message    %s\n", showoff(srvcdmsg));
  6422.     if (srvcdmsg && cdmsgstr)
  6423.       printf("Server cd-message    %s\n", cdmsgstr);
  6424.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6425.     printf("Server display:      %s\n", showoff(srvdis));
  6426.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6427.         printf("Server login:        ");
  6428.     if (!x_user) {
  6429.         printf("(none)\n");
  6430.     } else {
  6431.         printf("\"%s\", \"%s\", \"%s\"\n",
  6432.            x_user,
  6433.            x_passwd ? x_passwd : "",
  6434.            x_acct ? x_acct : ""
  6435.            );
  6436.     }
  6437.     if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6438.     printf("Server get-path: ");
  6439.     if (ngetpath == 0) {
  6440.         printf("    (none)\n");
  6441.     } else {
  6442.         printf("\n");
  6443.         i += 3;
  6444.         for (x = 0; x < ngetpath; x++) {
  6445.         if (getpath[x]) printf(" %d. %s\n", x, getpath[x]);
  6446.         if (++i > (cmd_rows - 3)) { /* More than a screenful... */
  6447.             if (!askmore())
  6448.               break;
  6449.             else
  6450.               i = 0;
  6451.         }
  6452.         }
  6453.     }
  6454.     break;
  6455. #endif /* NOSERVER */
  6456.  
  6457.       case SHSTA:            /* Status of last command */
  6458.     printf(" %s\n", success ? "SUCCESS" : "FAILURE");
  6459.     return(0);            /* Don't change it */
  6460.  
  6461.       case SHSTK: {            /* Stack for MAC debugging */
  6462. #ifdef MAC
  6463.       long sp;
  6464.       sp = -1;
  6465.       loadA0 ((char *)&sp);        /* set destination address */
  6466.       SPtoaA0();            /* move SP to destination */
  6467.       printf("Stack at 0x%x\n", sp);
  6468.       show_queue();            /* more debugging */
  6469.       break;
  6470. #else
  6471.       shostack();
  6472. #endif /* MAC */
  6473.       break;
  6474.       }
  6475.  
  6476.  
  6477. #ifndef NOLOCAL
  6478. #ifdef OS2
  6479.       case SHTAB:            /* SHOW TABS */
  6480. #ifdef IKSD
  6481.         if (inserver) {
  6482.             printf("Sorry, command disabled.\r\n");
  6483.             return(success = 0);
  6484.         }
  6485. #endif /* IKSD */
  6486.         shotabs();
  6487.         break;
  6488. #endif /* OS2 */
  6489.  
  6490.       case SHTER:            /* SHOW TERMINAL */
  6491. #ifdef IKSD
  6492.         if (inserver) {
  6493.             printf("Sorry, command disabled.\r\n");
  6494.             return(success = 0);
  6495.         }
  6496. #endif /* IKSD */
  6497.     shotrm();
  6498.     break;
  6499.  
  6500. #ifdef OS2
  6501.       case SHVSCRN:            /* SHOW Virtual Screen - for debug */
  6502.     shovscrn();
  6503.         break;
  6504. #endif /* OS2 */
  6505. #endif /* NOLOCAL */
  6506.  
  6507. #ifdef OS2MOUSE
  6508.       case SHMOU:            /* SHOW MOUSE */
  6509. #ifdef IKSD
  6510.         if (inserver) {
  6511.             printf("Sorry, command disabled.\r\n");
  6512.             return(success = 0);
  6513.         }
  6514. #endif /* IKSD */
  6515.         shomou();
  6516.         break;
  6517. #endif /* OS2MOUSE */
  6518.  
  6519. #ifndef NOFRILLS
  6520.       case SHVER:
  6521.     shover();
  6522.     break;
  6523. #endif /* NOFRILLS */
  6524.  
  6525. #ifndef NOSPL
  6526.       case SHBUI:            /* Built-in variables */
  6527.     if ((y = cmtxt("Variable name or pattern","",&s,xxstring)) < 0)
  6528.       return(y);
  6529.     ckstrncpy(line,s,LINBUFSIZ);
  6530.     if (line[0]) ckstrncat(line,"*",LINBUFSIZ);
  6531.  
  6532.       case SHFUN:            /* or built-in functions */
  6533. #ifdef CK_TTGWSIZ
  6534. #ifdef OS2
  6535.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6536.       ttgwsiz();
  6537. #else /* OS2 */
  6538.     if (ttgwsiz() > 0) {        /* Get current screen size */
  6539.         if (tt_rows > 0 && tt_cols > 0) {
  6540.         cmd_rows = tt_rows;
  6541.         cmd_cols = tt_cols;
  6542.         }
  6543.     }
  6544. #endif /* OS2 */
  6545. #endif /* CK_TTGWSIZ */
  6546.  
  6547.     if (x == SHFUN) {        /* Functions */
  6548.         printf("\nThe following functions are available:\n\n");
  6549.         kwdhelp(fnctab,nfuncs,"","\\F","()",3,0);
  6550.         printf("\n");
  6551. #ifndef NOHELP
  6552.         printf(
  6553. "HELP FUNCTION <name> gives the calling conventions of the given function.\n\n"
  6554.            );
  6555. #endif /* NOHELP */
  6556.         break;
  6557.     } else {            /* Variables */
  6558.         i = 0;
  6559.         for (y = 0; y < nvars; y++) {
  6560.         if ((vartab[y].flgs & CM_INV))
  6561.           continue;
  6562.         if (line[0])
  6563.           if (!ckmatch(line,vartab[y].kwd,0,1))
  6564.             continue;
  6565.         s = nvlook(vartab[y].kwd);
  6566.         printf(" \\v(%s) = ",vartab[y].kwd);
  6567.         if (vartab[y].kwval == VN_NEWL) { /* \v(newline) */
  6568.             while (*s)        /* Show control chars symbolically */
  6569.               printf("\\{%d}",*s++);
  6570.             printf("\n");
  6571.         } else if (vartab[y].kwval == VN_IBUF  || /* \v(input) */
  6572.                vartab[y].kwval == VN_QUE   || /* \v(query) */
  6573. #ifdef OS2
  6574.                vartab[y].kwval == VN_SELCT || /* \v(select) */
  6575. #endif /* OS2 */
  6576.                (vartab[y].kwval >= VN_M_AAA && /* modem ones */
  6577.                 vartab[y].kwval <= VN_M_ZZZ)
  6578.                ) {
  6579.             int r = 12;    /* This one can wrap around */
  6580.             char buf[10];
  6581.             while (*s) {
  6582.             if (isprint(*s)) {
  6583.                 buf[0] = *s;
  6584.                 buf[1] = NUL;
  6585.                 r++;
  6586.             } else {
  6587.                 sprintf(buf,"\\{%d}",*s); /* SAFE */
  6588.                 r += (int) strlen(buf);
  6589.             }
  6590.             if (r >= cmd_cols - 1) {
  6591.                 printf("\n");
  6592.                 r = 0;
  6593.                 i++;
  6594.             }
  6595.             printf("%s",buf);
  6596.             s++;
  6597.             }
  6598.             printf("\n");
  6599.         } else
  6600.           printf("%s\n",s);
  6601.         if (++i > (cmd_rows - 3)) { /* More than a screenful... */
  6602.             if ((y >= nvars - 1) || !askmore())
  6603.               break;
  6604.             else
  6605.               i = 0;
  6606.         }
  6607.         }
  6608.     }
  6609.     break;
  6610.  
  6611.       case SHVAR:            /* Global variables */
  6612.     x = 0;                /* Variable count */
  6613.     slc = 1;            /* Screen line count for "more?" */
  6614.     for (y = 33; y < GVARS; y++)
  6615.       if (g_var[y]) {
  6616.           if (x++ == 0) printf("Global variables:\n");
  6617.           sprintf(line," \\%%%c",y); /* SAFE */
  6618.           if (shomac(line,g_var[y]) < 0) break;
  6619.       }
  6620.     if (!x) printf(" No variables defined\n");
  6621.     break;
  6622.  
  6623.       case SHARG: {            /* Args */
  6624.       char * s1, * s2;
  6625.       if (maclvl > -1) {
  6626.           printf("Macro arguments at level %d (\\v(argc) = %d):\n",
  6627.              maclvl,
  6628.              macargc[maclvl]
  6629.              );
  6630.           for (y = 0; y < macargc[maclvl]; y++) {
  6631.           s1 = m_arg[maclvl][y];
  6632.           if (!s1) s1 = "(NULL)";
  6633.           s2 = m_xarg[maclvl][y];
  6634.           if (!s2) s2 = "(NULL)";
  6635.           if (y < 10)
  6636.             printf(" \\%%%d = %s\n",y,s1);
  6637.           else
  6638.             printf(" \\&_[%d] = %s\n",y,s2);
  6639.           }
  6640.       } else {
  6641.           printf("Top-level arguments (\\v(argc) = %d):\n", topargc);
  6642.           for (y = 0; y < topargc; y++) {
  6643.           s1 = g_var[y + '0'];
  6644.           if (!s1) s1 = "(NULL)";
  6645.           s2 = toparg[y];
  6646.           if (!s2) s2 = "(NULL)";
  6647.           if (y < 10 && g_var[y])
  6648.             printf(" \\%%%d = %s\n",y,s1);
  6649.           if (toparg[y])
  6650.             printf(" \\&_[%d] = %s\n",y,s2);
  6651.           }
  6652.       }
  6653.         }
  6654.     break;
  6655.  
  6656.       case SHARR:            /* Arrays */
  6657.     return(showarray());
  6658. #endif /* NOSPL */
  6659.  
  6660. #ifndef NOXFER
  6661.       case SHPRO:            /* Protocol parameters */
  6662.     shoparp();
  6663.     printf("\n");
  6664.     break;
  6665. #endif /* NOXFER */
  6666.  
  6667. #ifndef NOLOCAL
  6668.       case SHCOM:            /* Communication parameters */
  6669.     printf("\n");
  6670.     shoparc();
  6671. #ifdef OS2
  6672.     {
  6673.         int i;
  6674.         char *s = "(unknown)";
  6675.         for (i = 0; i < nprty; i++)
  6676.           if (prtytab[i].kwval == priority) {
  6677.           s = prtytab[i].kwd;
  6678.           break;
  6679.           }
  6680.         printf(" Priority: %s\n", s );
  6681.     }
  6682. #endif /* OS2 */
  6683.  
  6684.     printf("\n");
  6685. #ifdef NETCONN
  6686.     if (!network
  6687. #ifdef IKSD
  6688.              && !inserver
  6689. #endif /* IKSD */
  6690.              ) {
  6691. #endif /* NETCONN */
  6692.         shomdm();
  6693.         printf("\n");
  6694. #ifdef NETCONN
  6695.     }
  6696. #endif /* NETCONN */
  6697.  
  6698. #ifndef NODIAL
  6699. #ifdef IKSD
  6700.         if ( !inserver )
  6701. #endif /* IKSD */
  6702.         {
  6703.         printf("Type SHOW DIAL to see DIAL-related items.\n");
  6704.         printf("Type SHOW MODEM to see modem-related items.\n");
  6705. #ifdef CK_TAPI
  6706.         printf("Type SHOW TAPI to see TAPI-related items.\n");
  6707. #endif /* CK_TAPI */
  6708.         printf("\n");
  6709.     }
  6710. #endif /* NODIAL */
  6711.     break;
  6712. #endif /* NOLOCAL */
  6713.  
  6714.       case SHFIL:            /* File parameters */
  6715.     shofil();
  6716.     /* printf("\n"); */        /* (out o' space) */
  6717.     break;
  6718.  
  6719. #ifndef NOCSETS
  6720.       case SHLNG:            /* Languages */
  6721.     shoparl();
  6722.     break;
  6723. #endif /* NOCSETS */
  6724.  
  6725. #ifndef NOSPL
  6726.       case SHSCR:            /* Scripts */
  6727.     printf(" Command quoting:        %s\n", showoff(cmdgquo()));
  6728.     printf(" Take  echo:             %s\n", showoff(techo));
  6729.     printf(" Take  error:            %s\n", showoff(takerr[cmdlvl]));
  6730.     printf(" Macro echo:             %s\n", showoff(mecho));
  6731.     printf(" Macro error:            %s\n", showoff(merror[cmdlvl]));
  6732.         printf(" Quiet:                  %s\n", showoff(quiet));
  6733.         printf(" Function diagnostics:   %s\n", showoff(fndiags));
  6734.         printf(" Function error:         %s\n", showoff(fnerror));
  6735. #ifdef CKLEARN
  6736.     {
  6737.         extern char * learnfile;
  6738.         extern int learning;
  6739.         if (learnfile) {
  6740.         printf(" LEARN file:             %s (%s)\n",
  6741.                learnfile,
  6742.                learning ? "ON" : "OFF"
  6743.                );
  6744.         } else
  6745.           printf(" LEARN file:             (none)\n");
  6746.     }
  6747. #endif /* CKLEARN */
  6748.     shoinput();
  6749.     shooutput();
  6750. #ifndef NOSCRIPT
  6751.     printf(" Script echo:            %s\n", showoff(secho));
  6752. #endif /* NOSCRIPT */
  6753.     printf(" Command buffer length:  %d\n", CMDBL);
  6754.     printf(" Atom buffer length:     %d\n", ATMBL);
  6755.     break;
  6756. #endif /* NOSPL */
  6757.  
  6758. #ifndef NOXMIT
  6759.       case SHXMI:
  6760.     printf("\n");
  6761.     printf(" File type:                       %s\n",
  6762.            binary ? "binary" : "text");
  6763. #ifndef NOCSETS
  6764.     printf(" File character-set:              %s\n",
  6765.            fcsinfo[fcharset].keyword);
  6766.     printf(" Terminal character-set (remote): %s\n",
  6767.            fcsinfo[tcsr].keyword);
  6768.     printf(" Terminal character-set (local):  %s\n",
  6769.            fcsinfo[tcsl].keyword);
  6770. #endif /* NOCSETS */
  6771.     printf(" Terminal bytesize:               %d\n",
  6772.            (cmask == 0xff) ? 8 : 7);
  6773.     printf(" Terminal echo:                   %s\n",
  6774.            duplex ? "local" : "remote");
  6775.     printf(" Transmit EOF:                    ");
  6776.     if (*xmitbuf == NUL) {
  6777.         printf("(none)\n");
  6778.     } else {
  6779.         char *p;
  6780.         p = xmitbuf;
  6781.         while (*p) {
  6782.         if (*p < SP)
  6783.           printf("^%c",ctl(*p));
  6784.         else
  6785.           printf("%c",*p);
  6786.         p++;
  6787.         }
  6788.         printf("\n");
  6789.     }
  6790.     if (xmitf)
  6791.       printf(" Transmit Fill:                   %d\n", xmitf);
  6792.     else
  6793.       printf(" Transmit Fill:                   (none)\n");
  6794.     printf(" Transmit Linefeed:               %s\n",showoff(xmitl));
  6795.     if (xmitp)
  6796.       printf(" Transmit Prompt:                 %d (%s)\n",
  6797.          xmitp,
  6798.          chartostr(xmitp)
  6799.          );
  6800.     else
  6801.       printf(" Transmit Prompt:                 (none)\n");
  6802.     printf(" Transmit Echo:                   %s\n", showoff(xmitx));
  6803.     printf(" Transmit Locking-Shift:          %s\n", showoff(xmits));
  6804.     printf(" Transmit Pause:                  %d (millisecond%s)\n",
  6805.            xmitw,
  6806.            (xmitw == 1) ? "" : "s"
  6807.            );
  6808.     printf(" Transmit Timeout:                %d (second%s)\n",
  6809.            xmitt,
  6810.            (xmitt == 1) ? "" : "s"
  6811.            );
  6812.     printf("\n");
  6813.     break;
  6814. #endif /* NOXMIT */
  6815.  
  6816. #ifndef NODIAL
  6817.       case SHMOD:            /* SHOW MODEM */
  6818. #ifdef IKSD
  6819.         if (inserver) {
  6820.             printf("Sorry, command disabled.\r\n");
  6821.             return(success = 0);
  6822.         }
  6823. #endif /* IKSD */
  6824.     shomodem();            /* Show SET MODEM items */
  6825.     break;
  6826. #endif /* NODIAL */
  6827.  
  6828. #ifndef MAC
  6829.       case SHDFLT:
  6830.         printf("%s\n",zgtdir());
  6831.     break;
  6832. #endif /* MAC */
  6833.  
  6834. #ifndef NOLOCAL
  6835.       case SHESC:
  6836. #ifdef IKSD
  6837.         if (inserver) {
  6838.             printf("Sorry, command disabled.\r\n");
  6839.             return(success = 0);
  6840.         }
  6841. #endif /* IKSD */
  6842.     printf(" Escape character: Ctrl-%c (ASCII %d, %s): %s\r\n",
  6843.            ctl(escape), escape, (escape == 127 ? "DEL" : ccntab[escape]),
  6844.        nm[tt_escape]
  6845.        );
  6846.     break;
  6847.  
  6848. #ifndef NODIAL
  6849.       case SHDIA:            /* SHOW DIAL */
  6850. #ifdef IKSD
  6851.         if (inserver) {
  6852.             printf("Sorry, command disabled.\r\n");
  6853.             return(success = 0);
  6854.         }
  6855. #endif /* IKSD */
  6856.     shmdmlin();
  6857.     printf(", speed: ");
  6858.     if ((zz = ttgspd()) < 0) {
  6859.         printf("unknown");
  6860.     } else {
  6861.         if (zz == 8880) printf("75/1200"); else printf("%ld",zz);
  6862.     }
  6863.     if (carrier == CAR_OFF) s = "off";
  6864.     else if (carrier == CAR_ON) s = "on";
  6865.     else if (carrier == CAR_AUT) s = "auto";
  6866.     else s = "unknown";
  6867.     printf(", carrier: %s", s);
  6868.     if (carrier == CAR_ON) {
  6869.         if (cdtimo) printf(", timeout: %d sec", cdtimo);
  6870.         else printf(", timeout: none");
  6871.     }
  6872.     printf("\n");
  6873.     doshodial();
  6874.     if (local
  6875. #ifdef NETCONN
  6876.         && !network
  6877. #endif /* NETCONN */
  6878.         ) {
  6879.         printf("Type SHOW MODEM to see modem settings.\n");
  6880. #ifdef CK_TAPI
  6881.             printf("Type SHOW TAPI to see TAPI-related items\n");
  6882. #endif /* CK_TAPI */
  6883.         printf("Type SHOW COMMUNICATIONS to see modem signals.\n");
  6884.     }
  6885.     break;
  6886. #endif /* NODIAL */
  6887. #endif /* NOLOCAL */
  6888.  
  6889. #ifndef NOXFER
  6890. #ifdef CK_LABELED
  6891.       case SHLBL:            /* Labeled file info */
  6892.     sholbl();
  6893.     break;
  6894. #endif /* CK_LABELED */
  6895. #endif /* NOXFER */
  6896.  
  6897.       case SHCSE:            /* Character sets */
  6898. #ifdef NOCSETS
  6899.     printf(
  6900. " Character set translation is not supported in this version of C-Kermit\n");
  6901. #else
  6902.     shocharset();
  6903. #ifndef NOXFER
  6904.     printf("\n Unknown-Char-Set: %s\n",
  6905.            unkcs ? "Keep" : "Discard");
  6906. #endif /* NOXFER */
  6907. #ifdef OS2
  6908.         printf("\n");
  6909. #endif /* OS2 */
  6910.         shotcs(tcsl,tcsr);
  6911.     printf("\n");
  6912. #ifdef OS2
  6913.         /* PC Code Page information */
  6914.         {
  6915.             char cpbuf[128];
  6916.             int cplist[16], cps;
  6917.             int activecp;
  6918.             cps = os2getcplist(cplist, sizeof(cplist));
  6919.  
  6920.             sprintf(cpbuf,        /* SAFE */
  6921.             "%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d",
  6922.                      cps > 1 ? cplist[1] : 0,
  6923.                      cps > 2 ? cplist[2] : 0, cps > 3 ? cplist[3] : 0,
  6924.                      cps > 4 ? cplist[4] : 0, cps > 5 ? cplist[5] : 0,
  6925.                      cps > 6 ? cplist[6] : 0, cps > 7 ? cplist[7] : 0,
  6926.                      cps > 8 ? cplist[8] : 0, cps > 9 ? cplist[9] : 0,
  6927.                      cps > 10 ? cplist[10] : 0, cps > 11 ? cplist[11] : 0,
  6928.                      cps > 12 ? cplist[12] : 0
  6929.                      );
  6930.             printf(" Code Pages:\n");
  6931.             activecp = os2getcp();
  6932.             if ( activecp ) {
  6933.               printf("     Active: %d\n",activecp);
  6934.               if (!isWin95())
  6935.                 printf("  Available: %s\n",cpbuf);
  6936.             } else
  6937.               printf("     Active: n/a\n");
  6938.             printf("\n");
  6939.         }
  6940. #endif /* OS2 */
  6941. #endif /* NOCSETS */
  6942.     break;
  6943.  
  6944.       case SHFEA:            /* Features */
  6945.     shofea();
  6946.     break;
  6947.  
  6948. #ifdef CK_SPEED
  6949.       case SHCTL:            /* Control-Prefix table */
  6950.     shoctl();
  6951.     break;
  6952. #endif /* CK_SPEED */
  6953.  
  6954.       case SHEXI: {
  6955.       extern int exithangup;
  6956.       printf("\n Exit warning %s\n", xitwarn ?
  6957.          (xitwarn == 1 ? "on" : "always") : "off");
  6958.       printf(" Exit on-disconnect: %s\n", showoff(exitonclose));
  6959.       printf(" Exit hangup: %s\n", showoff(exithangup));
  6960.       printf(" Current exit status: %d\n\n", xitsta);
  6961.       break;
  6962.       }
  6963.       case SHPRT: {
  6964. #ifdef PRINTSWI
  6965.       extern int printtimo, printertype, noprinter;
  6966.       extern char * printterm, * printsep;
  6967. #ifdef BPRINT
  6968.       extern int printbidi;
  6969. #endif /* BPRINT */
  6970. #endif /* PRINTSWI */
  6971.  
  6972. #ifdef IKSD
  6973.         if (inserver &&
  6974. #ifdef CK_LOGIN
  6975.             isguest
  6976. #else /* CK_LOGIN */
  6977.             0
  6978. #endif /* CK_LOGIN */
  6979.              ) {
  6980.             printf("Sorry, command disabled.\r\n");
  6981.             return(success = 0);
  6982.         }
  6983. #endif /* IKSD */
  6984. #ifdef PRINTSWI
  6985.       if (noprinter) {
  6986.           printf("Printer: (none)\n\n");
  6987.           break;
  6988.       }
  6989. #endif /* PRINTSWI */
  6990.  
  6991.       printf("Printer: %s%s\n",
  6992.  
  6993.          printpipe ? "| " : "",
  6994.          printername ? printername :
  6995. #ifdef OS2
  6996.          "PRN"
  6997. #else
  6998.          "(default)"
  6999. #endif /* OS2 */
  7000.          );
  7001. #ifdef PRINTSWI
  7002. #ifdef BPRINT
  7003.       if (printbidi) {
  7004.           printf(" /BIDIRECTIONAL\n");
  7005.           if (pportspeed > 0)
  7006.         printf(" /SPEED:%ld\n",pportspeed);
  7007.           printf(" /PARITY:%s\n",parnam((char)pportparity));
  7008.           printf(" /FLOW:%s\n",
  7009.              pportflow == FLO_NONE ? "NONE" :
  7010.              (pportflow == FLO_RTSC ? "RTS/CTS" : "XON/XOFF")
  7011.              );
  7012.       } else
  7013.         printf(" /OUTPUT-ONLY\n");
  7014. #endif /* BPRINT */
  7015.       switch (printertype) {
  7016.         case PRT_NON: printf(" /NONE\n"); break;
  7017.         case PRT_FIL: printf(" /FILE\n"); break;
  7018.         case PRT_PIP: printf(" /PIPE\n"); break;
  7019.         case PRT_DOS: printf(" /DOS-DEVICE\n"); break;
  7020.         case PRT_WIN: printf(" /WINDOWS-QUEUE\n"); break;
  7021.       }
  7022.       printf(" /TIMEOUT:%d\n",printtimo);
  7023.           if (printterm) {
  7024.               printf(" /END-OF-JOB-STRING:");
  7025.               shostrdef(printterm);
  7026.               printf("\n");
  7027.           } else
  7028.         printf(" /END-OF-JOB-STRING:(none)\n");
  7029.       printf(" /JOB-HEADER-FILE:%s\n",printsep ? printsep : "(none)");
  7030. #endif /* PRINTSWI */
  7031.       printf("\n");
  7032.       break;
  7033.       }
  7034.  
  7035.       case SHCMD: {
  7036. #ifdef DOUBLEQUOTING
  7037.       extern int dblquo;
  7038. #endif /* DOUBLEQUOTING */
  7039. #ifdef CK_AUTODL
  7040.       printf(" Command autodownload: %s\n",showoff(cmdadl));
  7041. #else
  7042.       printf(" Command autodownload: (not available)\n");
  7043. #endif /* CK_AUTODL */
  7044.       printf(" Command bytesize: %d bits\n", (cmdmsk == 0377) ? 8 : 7);
  7045. #ifdef CK_RECALL
  7046.       printf(" Command recall-buffer-size: %d\n",cm_recall);
  7047. #else
  7048.       printf(" Command recall-buffer not available in this version\n");
  7049. #endif /* CK_RECALL */
  7050. #ifdef CK_RECALL
  7051.       printf(" Command retry: %s\n",showoff(cm_retry));
  7052. #else
  7053.       printf(" Command retry not available in this version\n");
  7054. #endif /* CK_RECALL */
  7055.       printf(" Command interruption: %s\n", showoff(cmdint));
  7056.       printf(" Command quoting: %s\n", showoff(cmdgquo()));
  7057. #ifdef DOUBLEQUOTING
  7058.       printf(" Command doublequoting: %s\n", showoff(dblquo));
  7059. #endif /* DOUBLEQUOTING */
  7060.       printf(" Command more-prompting: %s\n", showoff(xaskmore));
  7061.       printf(" Command height: %d\n", cmd_rows);
  7062.       printf(" Command width:  %d\n", cmd_cols);
  7063. #ifndef IKSDONLY
  7064. #ifdef OS2
  7065.       printf(" Command statusline: %s\n",showoff(tt_status[VCMD]));
  7066. #endif /* OS2 */
  7067. #endif /* IKSDONLY */
  7068.       printf(" Hints:          %s\n", showoff(hints));
  7069.       printf(" Quiet:          %s\n", showoff(quiet));
  7070.       printf(" Maximum command length: %d\n", CMDBL);
  7071. #ifndef NOSPL
  7072.       {
  7073.           char * s;
  7074.           int k;
  7075.           printf(" Maximum number of macros: %d\n", MAC_MAX);
  7076.           printf(" Macros defined: %d\n", nmac);
  7077.           printf(" Maximum macro depth: %d\n", MACLEVEL);
  7078.           printf(" Maximum TAKE depth: %d\n", MAXTAKE);
  7079.           s = "(not defined)";
  7080.           k = mlook(mactab,"on_unknown_command",nmac);
  7081.           if (k > -1) if (mactab[k].mval) s = mactab[k].mval;
  7082.           printf(" ON_UNKNOWN_COMMAND: %s\n",s);
  7083.       }
  7084. #endif /* NOSPL */
  7085. #ifdef UNIX
  7086. #ifndef NOJC
  7087.       printf(" Suspend: %s\n", showoff(suspend));
  7088. #endif /* NOJC */
  7089. #endif /* UNIX */
  7090.       printf(" Access to external commands and programs%s allowed\n",
  7091. #ifndef NOPUSH
  7092.          !nopush ? "" :
  7093. #endif /* NOPUSH */
  7094.                   " not");
  7095.       break;
  7096.       }
  7097.  
  7098. #ifndef NOSPL
  7099.       case SHALRM:
  7100.     if (ck_alarm)
  7101.       printf("Alarm at %s %s\n",alrm_date,alrm_time);
  7102.     else
  7103.       printf("(no alarm set)\n");
  7104.     break;
  7105. #endif /* NOSPL */
  7106.  
  7107. #ifndef NOMSEND
  7108.       case SHSFL: {
  7109.       extern struct filelist * filehead;
  7110.       if (!filehead) {
  7111.           printf("send-list is empty\n");
  7112.       } else {
  7113.           struct filelist * flp;
  7114.           char * s;
  7115.           flp = filehead;
  7116.           while (flp) {
  7117.           s = flp->fl_alias;
  7118.           if (!s) s = "(none)";
  7119.           printf("%s, mode: %s, alias: %s\n",
  7120.              flp->fl_name,
  7121.              gfmode(flp->fl_mode,0),
  7122.              s
  7123.              );
  7124.           flp = flp->fl_next;
  7125.           }
  7126.       }
  7127.       }
  7128.       break;
  7129. #endif /* NOMSEND */
  7130.  
  7131. #ifdef CKXXCHAR
  7132.       case SHDBL:
  7133.     shodbl();
  7134.     break;
  7135. #endif /* CKXXCHAR */
  7136.  
  7137. #ifndef NOPUSH
  7138. #ifndef NOFRILLS
  7139.       case SHEDIT:
  7140.     if (!editor[0]) {
  7141.         s = getenv("EDITOR");
  7142.         if (s) ckstrncpy(editor,s,CKMAXPATH);
  7143.     }
  7144.     printf("\n editor:  %s\n", editor[0] ? editor : "(none)");
  7145.     if (editor[0]) {
  7146.         printf(" options: %s\n", editopts[0] ? editopts : "(none)");
  7147.         printf(" file:    %s\n", editfile[0] ? editfile : "(none)");
  7148.         }
  7149.     printf("\n");
  7150.     break;
  7151.  
  7152. #ifdef BROWSER
  7153.       case SHBROWSE:
  7154.     if (!browser[0]) {
  7155.         s = getenv("BROWSER");
  7156.         if (s) ckstrncpy(browser,s,CKMAXPATH);
  7157.     }
  7158.     printf("\n browser: %s\n", browser[0] ? browser : "(none)");
  7159.     if (browser[0]) {
  7160.         printf(" options: %s\n", browsopts[0] ? browsopts : "(none)");
  7161.         printf(" url:     %s\n", browsurl[0] ? browsurl : "(none)");
  7162.     }
  7163.     printf("\n");
  7164.     break;
  7165. #endif /* BROWSER */
  7166. #endif /*  NOFRILLS */
  7167. #endif /* NOPUSH */
  7168.  
  7169. #ifndef NOLOCAL
  7170. #ifdef CK_TAPI
  7171.       case SHTAPI:            /* TAPI options */
  7172. #ifdef IKSD
  7173.         if (inserver) {
  7174.             printf("Sorry, command disabled.\r\n");
  7175.             return(success = 0);
  7176.         }
  7177. #endif /* IKSD */
  7178.     shotapi(0);
  7179.     break;
  7180.       case SHTAPI_L:            /* TAPI Locations */
  7181. #ifdef IKSD
  7182.         if (inserver) {
  7183.             printf("Sorry, command disabled.\r\n");
  7184.             return(success = 0);
  7185.         }
  7186. #endif /* IKSD */
  7187.     shotapi(1);
  7188.     break;
  7189.       case SHTAPI_M:            /* TAPI Modem */
  7190. #ifdef IKSD
  7191.         if (inserver) {
  7192.             printf("Sorry, command disabled.\r\n");
  7193.             return(success = 0);
  7194.         }
  7195. #endif /* IKSD */
  7196.     shotapi(2);
  7197.     break;
  7198.       case SHTAPI_C:            /* TAPI Comm */
  7199. #ifdef IKSD
  7200.         if (inserver) {
  7201.             printf("Sorry, command disabled.\r\n");
  7202.             return(success = 0);
  7203.         }
  7204. #endif /* IKSD */
  7205.     shotapi(3);
  7206.     break;
  7207. #endif /* CK_TAPI */
  7208.  
  7209.       case SHTCP:                       /* SHOTCP */
  7210.         printf("\n");
  7211.         shotcp(0);
  7212.         printf("\n");
  7213.         break;
  7214.  
  7215. #ifdef TNCODE
  7216.       case SHTEL:            /* TELNET */
  7217.     printf("\n");
  7218.     shotel(0);
  7219.     printf("\n");
  7220.     break;
  7221.  
  7222.       case SHTOPT:            /* TELNET OPTIONS */
  7223.         printf("\n");
  7224.         shotopt(0);
  7225.         printf("\n");
  7226.         break;
  7227. #endif /* TNCODE */
  7228.  
  7229. #ifdef CK_TRIGGER
  7230.       case SHTRIG: {
  7231.       extern char * tt_trigger[], * triggerval;
  7232.       int i;
  7233.       if (!tt_trigger[0]) {
  7234.           printf(" Triggers: (none)\n");
  7235.       } else {
  7236.           printf(" Triggers:\n");
  7237.           for (i = 0; i < TRIGGERS; i++) {
  7238.           if (!tt_trigger[i])
  7239.             break;
  7240.           printf("  \"%s\"\n",tt_trigger[i]);
  7241.           }
  7242.           printf(" Most recent trigger encountered: ");
  7243.           if (triggerval)
  7244.         printf("\"%s\"\n",triggerval);
  7245.           else
  7246.         printf("(none)\n");
  7247.       }
  7248.       break;
  7249.       }
  7250. #endif /* CK_TRIGGER */
  7251. #endif /* NOLOCAL */
  7252.  
  7253. #ifndef NOSPL
  7254.       case SHINP:
  7255.     shoinput();
  7256.     break;
  7257. #endif /* NOSPL */
  7258.  
  7259.       case SHLOG: {
  7260. #ifndef MAC
  7261. #ifdef IKSD
  7262.           if (inserver &&
  7263. #ifdef CK_LOGIN
  7264.               isguest
  7265. #else /* CK_LOGIN */
  7266.               0
  7267. #endif /* CK_LOGIN */
  7268.              ) {
  7269.             printf("Sorry, command disabled.\r\n");
  7270.             return(success = 0);
  7271.         }
  7272. #endif /* IKSD */
  7273. #ifdef DEBUG
  7274.       printf("\n Debug log:       %s\n", deblog ? debfil : "(none)");
  7275. #endif /* DEBUG */
  7276. #ifndef NOXFER
  7277.       printf(" Packet log:      %s\n",   pktlog ? pktfil : "(none)");
  7278. #endif /* NOXFER */
  7279. #ifndef NOLOCAL
  7280.       printf(" Session log:     %s\n",   seslog ? sesfil : "(none)");
  7281. #endif /* NOLOCAL */
  7282. #ifdef TLOG
  7283.       printf(" Transaction log: %s (%s)\n",
  7284.          (tralog ? (*trafil ? trafil : "(none)") : "(none)"),
  7285.          (tlogfmt ? ((tlogfmt == 2) ? "ftp" : "verbose") : "brief")
  7286.          );
  7287. #endif /* TLOG */
  7288. #ifdef CKLOGDIAL
  7289.           printf(" Connection log:  %s\n", dialog ? diafil : "(none)");
  7290. #endif /* CKLOGDIAL */
  7291.       printf("\n");
  7292. #endif /* MAC */
  7293.       break;
  7294.       }
  7295.  
  7296. #ifndef NOSPL
  7297.       case SHOUTP:            /* OUTPUT */
  7298.     shooutput();
  7299.     break;
  7300. #endif /* NOSPL */
  7301.  
  7302. #ifdef PATTERNS
  7303.       case SHOPAT:            /* PATTERNS */
  7304.     shopat();
  7305.     break;
  7306. #endif /* PATTERNS */
  7307.  
  7308. #ifdef STREAMING
  7309.       case SHOSTR: {            /* STREAMING */
  7310.       extern int streamrq, clearrq, cleared;
  7311.       extern long tfcps;
  7312.       debug(F101,"SHOW RELIABLE reliable","",reliable);
  7313.       printf("\n Reliable:     %s\n",showooa(reliable));
  7314.       printf(" Clearchannel: %s\n",showooa(clearrq));
  7315.       printf(" Streaming:    %s\n\n",showooa(streamrq));
  7316.       if ((!local && (streamrq == SET_ON)) ||
  7317.           (streamrq == SET_AUTO && reliable))
  7318.         printf(" Streaming will be done if requested.\n");
  7319.       else if ((streamrq == SET_OFF) ||
  7320.            ((streamrq == SET_AUTO) && !reliable))
  7321.         printf(" Streaming will not be requested and will not be done.\n");
  7322.       else if ((streamrq == SET_ON) ||
  7323.            ((streamrq == SET_AUTO) && reliable))
  7324.         printf(
  7325. " Streaming will be requested and will be done if the other Kermit agrees.\n");
  7326.       printf(" Last transfer: %sstreaming%s, %ld cps.\n",
  7327.          streamed > 0 ? "" : "no ",
  7328.          cleared ? ", clearchannel" : "",
  7329.          tfcps
  7330.          );
  7331.       printf("\n");
  7332.       break;
  7333.       }
  7334. #endif /* STREAMING */
  7335.  
  7336.       case SHOIKS:
  7337.     return(sho_iks());
  7338.         break;
  7339.  
  7340. #ifdef CK_AUTHENTICATION
  7341.       case SHOAUTH:
  7342.     return(sho_auth(0));
  7343. #endif /* CK_AUTHENTICATION */
  7344.  
  7345. #ifndef NOFTP
  7346.       case SHOFTP: {
  7347. #ifdef IKSD
  7348.         if (inserver) {
  7349.             printf("Sorry, command disabled.\r\n");
  7350.             return(success = 0);
  7351.         }
  7352. #endif /* IKSD */
  7353. #ifdef SYSFTP
  7354.     {
  7355.         extern char ftpapp[], ftpopts[];
  7356.         printf(" ftp-client:  %s\n", ftpapp[0] ? ftpapp : "(none)");
  7357.         if (ftpapp[0])
  7358.           printf(" ftp options: %s\n", ftpopts[0] ? ftpopts : "(none)");
  7359.     }
  7360. #else
  7361. #ifdef NEWFTP
  7362.     shoftp(0);
  7363. #else
  7364.     printf("(No FTP client included in this version of Kermit.)\n");
  7365. #endif /* NEWFTP */
  7366. #endif /* SYSFTP */
  7367.     break;
  7368.       }
  7369. #endif /* NOFTP */
  7370.  
  7371. #ifndef NOCMDL
  7372.       case SHXOPT: {
  7373. #ifdef IKSDB
  7374.       extern int dbenabled;
  7375.       extern char * dbfile, * dbdir;
  7376. #endif /* IKSDB */
  7377. #ifdef CKWTMP
  7378.       extern int ckxwtmp;
  7379.       extern char * wtmpfile;
  7380. #endif /* CKWTMP */
  7381. #ifdef CK_LOGIN
  7382.       extern int ckxanon, xferlog, logintimo;
  7383.       extern char * xferfile;
  7384. #ifdef UNIX
  7385.           extern int ckxpriv;
  7386. #endif /* UNIX */
  7387. #ifdef CK_PERMS
  7388.           extern int ckxperms;
  7389. #endif /* CK_PERMS */
  7390. #endif /* CK_LOGIN */
  7391.       extern char * bannerfile, * helpfile;
  7392.  
  7393. #ifdef IKSD
  7394.           if (inserver &&
  7395. #ifdef CK_LOGIN
  7396.               isguest
  7397. #else /* CK_LOGIN */
  7398.               0
  7399. #endif /* CK_LOGIN */
  7400.           ) {
  7401.           printf("Sorry, command disabled.\r\n");
  7402.           return(success = 0);
  7403.       }
  7404. #endif /* IKSD */
  7405.       printf("\n");
  7406.       if (!cmdint)
  7407.         printf(" --nointerrupts\n");
  7408.       printf(" --bannerfile=%s\n",bannerfile ? bannerfile : "(null)");
  7409.       printf(" --cdfile:%s\n",cdmsgstr ? cdmsgstr : "(null)");
  7410.       printf(" --cdmessage:%d\n",srvcdmsg);
  7411.       printf(" --helpfile:%d\n",helpfile);
  7412.       if (inserver) {
  7413.           printf("\n");
  7414.           break;
  7415.       }
  7416. #ifdef CKSYSLOG
  7417. #ifdef SYSLOGLEVEL
  7418.       printf(" --syslog:%d (forced)\n",ckxsyslog);
  7419. #else
  7420.       printf(" --syslog:%d\n",ckxsyslog);
  7421. #endif /* SYSLOGLEVEL */
  7422. #endif /* CKSYSLOG */
  7423. #ifdef CKWTMP
  7424.       printf(" --wtmplog:%d\n",ckxwtmp);
  7425.       printf(" --wtmpfile=%s\n",wtmpfile ? wtmpfile : "(null)");
  7426. #endif /* CKWTMP */
  7427. #ifdef IKSD
  7428. #ifdef CK_LOGIN
  7429.       printf(" --anonymous:%d\n",ckxanon);
  7430. #ifdef UNIX
  7431.       printf(" --privid:%d\n",ckxpriv);
  7432. #endif /* UNIX */
  7433. #ifdef CK_PERMS
  7434.       printf(" --permission:%04o\n",ckxperms);
  7435. #endif /* CK_PERMS */
  7436.       printf(" --initfile:%s\n",anonfile ? anonfile : "(null)");
  7437.       printf(" --userfile:%s\n",userfile ? userfile : "(null)");
  7438.       printf(" --root:%s\n",anonroot ? anonroot : "(null)");
  7439.       printf(" --xferlog=%d\n",xferlog);
  7440.       printf(" --xferfile=%s\n",xferfile ? xferfile : "(null)");
  7441.       printf(" --timeout=%d\n",logintimo);
  7442. #endif /* CK_LOGIN */
  7443. #ifdef IKSDB
  7444.       printf(" --database=%d\n",dbenabled);
  7445.       printf(" --dbfile=%s\n",dbfile ? dbfile : "(null)");
  7446.       if (dbdir)
  7447.         printf("   (db directory=[%s])\n",dbdir);
  7448. #endif /* IKSDB */
  7449. #ifdef IKSDCONF
  7450.       printf(" IKSD conf=%s\n",iksdconf);
  7451. #endif /* IKSDCONF */
  7452. #endif /* IKSD */
  7453.       printf("\n");
  7454.       break;
  7455.       }
  7456. #endif /* NOCMDL */
  7457.  
  7458.       case SHCD:
  7459.     s = getenv("CDPATH");
  7460.     if (!s) s = "(none)";
  7461.         printf("\n current directory:  %s\n", zgtdir());
  7462.         printf(" previous directory: %s\n", prevdir ? prevdir : "(none)");
  7463.         printf(" cd path:            %s\n", ckcdpath ? ckcdpath : s);
  7464.     printf(" cd message:         %s\n", showoff(srvcdmsg & 2));
  7465.     printf(" server cd-message:  %s\n", showoff(srvcdmsg & 1));
  7466.     printf(" cd message file:    %s\n\n", cdmsgstr ? cdmsgstr : "(none)");
  7467.     break;
  7468.  
  7469. #ifndef NOCSETS
  7470.       case SHASSOC:
  7471.     (VOID) showassoc();
  7472.     break;
  7473. #endif /* NOCSETS */
  7474.  
  7475. #ifdef CKLOGDIAL
  7476.       case SHCONNX:
  7477. #ifdef NEWFTP
  7478.     if (ftpisconnected()) {
  7479.         extern char cxlogbuf[];
  7480.         dologshow(W_FTP | 1);
  7481.         if (cxlogbuf[0])
  7482.           dologshow(1);
  7483.     } else {
  7484. #endif /* NEWFTP */
  7485.         dologshow(1);
  7486. #ifdef NEWFTP
  7487.     }
  7488. #endif /* NEWFTP */
  7489.     break;
  7490. #endif /* CKLOGDIAL */
  7491.  
  7492.       case SHOPTS:
  7493.     optlines = 0;
  7494. #ifndef NOFRILLS
  7495.     (VOID) showdelopts();
  7496. #endif /* NOFRILLS */
  7497. #ifdef DOMYDIR
  7498.     (VOID) showdiropts();
  7499. #endif /* DOMYDIR */
  7500. #ifdef CKPURGE
  7501.     (VOID) showpurgopts();
  7502. #endif /* CKPURGE */
  7503.     (VOID) showtypopts();
  7504.     break;
  7505.  
  7506. #ifndef NOLOCAL
  7507.       case SHOFLO:
  7508.     (VOID) shoflow();
  7509.     break;
  7510. #endif /* NOLOCAL */
  7511.  
  7512. #ifndef NOXFER
  7513.       case SHOXFER:
  7514.     (VOID) shoxfer();
  7515.     break;
  7516. #endif /* NOXFER */
  7517.  
  7518. #ifdef CK_RECALL
  7519.       case SHHISTORY:
  7520.     (VOID) cmhistory();
  7521.     break;
  7522. #endif /* CK_RECALL */
  7523.  
  7524. #ifndef NOSEXP
  7525. #ifndef NOSPL
  7526.       case SHSEXP:
  7527.     (VOID) shosexp();
  7528.     break;
  7529. #endif /* NOSPL */
  7530. #endif /* NOSEXP */
  7531.  
  7532. #ifdef ANYSSH
  7533.       case SHOSSH:
  7534.     (VOID) shossh();
  7535.     break;
  7536. #endif /* ANYSSH */
  7537.  
  7538.       default:
  7539.     printf("\nNothing to show...\n");
  7540.     return(-2);
  7541.     }
  7542.     return(success = 1);
  7543. }
  7544.  
  7545. #ifndef NOXFER
  7546. int
  7547. shoatt() {
  7548.     printf("Attributes: %s\n", showoff(atcapr));
  7549.     if (!atcapr) return(0);
  7550.     printf(" Blocksize: %s\n", showoff(atblki));
  7551.     printf(" Date: %s\n", showoff(atdati));
  7552.     printf(" Disposition: %s\n", showoff(atdisi));
  7553.     printf(" Encoding (Character Set): %s\n", showoff(atenci));
  7554.     printf(" Length: %s\n", showoff(atleni));
  7555.     printf(" Type (text/binary): %s\n", showoff(attypi));
  7556.     printf(" System ID: %s\n", showoff(atsidi));
  7557.     printf(" System Info: %s\n", showoff(atsysi));
  7558. #ifdef CK_PERMS
  7559.     printf(" Protection: %s\n", showoff(atlpri));
  7560. #endif /* CK_PERMS */
  7561. #ifdef STRATUS
  7562.     printf(" Format: %s\n", showoff(atfrmi));
  7563.     printf(" Creator: %s\n", showoff(atcrei));
  7564.     printf(" Account: %s\n", showoff(atacti));
  7565. #endif /* STRATUS */
  7566.     return(0);
  7567. }
  7568. #endif /* NOXFER */
  7569.  
  7570. #ifndef NOSPL
  7571. int                    /* SHOW MACROS */
  7572. shomac(s1, s2) char *s1, *s2; {
  7573.     int x, n, pp;
  7574.     pp = 0;                /* Parenthesis counter */
  7575.  
  7576.     debug(F110,"shomac s1",s1,0);
  7577.     debug(F110,"shomac s2",s2,0);
  7578.  
  7579. #ifdef IKSD
  7580.     if ( inserver &&
  7581. #ifdef IKSDCONF
  7582.     iksdcf
  7583. #else /* IKSDCONF */
  7584.     1
  7585. #endif /* IKSDCONF */
  7586.     ) {
  7587.         if (!ckstrcmp("on_exit",s1,-1,0) ||
  7588.             !ckstrcmp("on_logout",s1,-1,0))
  7589.       return(0);
  7590.     }
  7591. #endif /* IKSD */
  7592.  
  7593.     if (!s1)
  7594.       return(0);
  7595.     else
  7596.       printf("%s = ",s1);        /* Print blank line and macro name */
  7597.     n = (int)strlen(s1) + 4;        /* Width of current line */
  7598.     if (!s2) s2 = "(not defined)";
  7599.  
  7600.     while ((x = *s2++)) {        /* Loop thru definition */
  7601.     if (x == '(') pp++;        /* Treat commas within parens */
  7602.     if (x == ')') pp--;        /* as ordinary text */
  7603.     if (pp < 0) pp = 0;        /* Outside parens, */
  7604.     if (x == ',' && pp == 0) {    /* comma becomes comma-dash-NL. */
  7605.         putchar(',');
  7606.         putchar('-');
  7607.         x = '\n';
  7608.     }
  7609.         if (inserver && (x == '\n'))    /* Send CR before LF */
  7610.       putchar(CR);
  7611.     putchar((CHAR)x);        /* Output the character */
  7612.     if (x == '\n') {        /* If it was a newline */
  7613. #ifdef UNIX
  7614. #ifdef NOSETBUF
  7615.         fflush(stdout);
  7616. #endif /* NOSETBUF */
  7617. #endif /* UNIX */
  7618.         putchar(' ');        /* Indent the next line 1 space */
  7619.         while(*s2 == ' ') s2++;    /* skip past leading blanks */
  7620.         n = 2;            /* restart the character counter */
  7621.         slc++;            /* and increment the line counter. */
  7622.     } else if (++n > (cmd_cols - 1)) { /* If line is too wide */
  7623.         putchar('-');        /* output a dash */
  7624.             if (inserver)
  7625.           putchar(CR);        /* and a carriage return */
  7626.         putchar(NL);        /* and a newline */
  7627. #ifdef UNIX
  7628. #ifdef NOSETBUF
  7629.         fflush(stdout);
  7630. #endif /* NOSETBUF */
  7631. #endif /* UNIX */
  7632.         n = 1;            /* and restart the char counter */
  7633.         slc++;            /* and increment the line counter */
  7634.     }
  7635.     if (n < 3 && slc > (cmd_rows - 3)) { /* If new line and screen full */
  7636.         if (!askmore()) return(-1);    /* ask if they want more. */
  7637.         n = 1;            /* They do, start a new line */
  7638.         slc = 0;            /* and restart line counter */
  7639.     }
  7640.     }
  7641.     if (inserver)
  7642.       putchar(CR);
  7643.     putchar(NL);            /* End of definition */
  7644.     if (++slc > (cmd_rows - 3)) {
  7645.     if (!askmore()) return(-1);
  7646.     slc = 0;
  7647.     }
  7648.     return(0);
  7649. }
  7650. #endif /* NOSPL */
  7651. #endif /* NOSHOW */
  7652.  
  7653. int x_ifnum = 0;            /* Flag for IF NUMERIC active */
  7654.  
  7655. #ifndef NOSPL
  7656. /* Evaluate an arithmetic expression. */
  7657. /* Code adapted from ev, by Howie Kaye of Columbia U & others. */
  7658.  
  7659. static int xerror = 0;
  7660. int divbyzero = 0;
  7661. static char *cp;
  7662. static long tokval;
  7663. static char curtok;
  7664. static long expval;
  7665.  
  7666. #define LONGBITS (8*sizeof (long))
  7667. #define NUMBER 'N'
  7668. #define N_EOT 'E'
  7669.  
  7670. /*
  7671.  Replacement for strchr() and index(), neither of which seem to be universal.
  7672. */
  7673.  
  7674. static char *
  7675. #ifdef CK_ANSIC
  7676. windex(char * s, char c)
  7677. #else
  7678. windex(s,c) char *s, c;
  7679. #endif /* CK_ANSIC */
  7680. /* windex */ {
  7681.     while (*s != NUL && *s != c) s++;
  7682.     if (*s == c) return(s); else return(NULL);
  7683. }
  7684.  
  7685.  
  7686. /*
  7687.  g e t t o k
  7688.  
  7689.  Returns the next token.  If token is a NUMBER, sets tokval appropriately.
  7690. */
  7691. static char
  7692. gettok() {
  7693.     char tbuf[80] /* ,*tp */ ;        /* Buffer to accumulate number */
  7694.  
  7695.     while (isspace(*cp))        /* Skip past leading spaces */
  7696.       cp++;
  7697.  
  7698.     debug(F110,"GETTOK",cp,0);
  7699.  
  7700.     switch (*cp) {
  7701.       case '$':                /* ??? */
  7702.       case '+':                /* Add */
  7703.       case '-':                /* Subtract or Negate */
  7704.       case '@':                /* Greatest Common Divisor */
  7705.       case '*':                /* Multiply */
  7706.       case '/':                /* Divide */
  7707.       case '%':                /* Modulus */
  7708.       case '<':                /* Left shift */
  7709.       case '>':                /* Right shift */
  7710.       case '&':                /* And */
  7711.       case '|':                /* Or */
  7712.       case '#':                /* Exclusive Or */
  7713.       case '~':                /* Not */
  7714.       case '^':                /* Exponent */
  7715.       case '!':                /* Factorial */
  7716.       case '(':                /* Parens for grouping */
  7717.       case ')': return(*cp++);        /* operator, just return it */
  7718.       case '\n':
  7719.       case '\0': return(N_EOT);        /* End of line, return that */
  7720.     }
  7721. #ifdef COMMENT
  7722. /* This is the original code, which allows only integer numbers. */
  7723.  
  7724.     if (isxdigit(*cp)) {        /* Digit, must be a number */
  7725.     int radix = 10;            /* Default radix */
  7726.     for (tp = tbuf; isxdigit(*cp); cp++)
  7727.       *tp++ = (char) (isupper(*cp) ? tolower(*cp) : *cp);
  7728.     *tp = '\0';            /* End number */
  7729.     switch(isupper(*cp) ? tolower(*cp) : *cp) { /* Examine break char */
  7730.       case 'h':
  7731.       case 'x': radix = 16; cp++; break; /* if radix signifier... */
  7732.       case 'o':
  7733.       case 'q': radix = 8; cp++; break;
  7734.       case 't': radix = 2; cp++; break;
  7735.     }
  7736.     for (tp = tbuf, tokval = 0; *tp != '\0'; tp++)  {
  7737.         int dig;
  7738.         dig = *tp - '0';        /* Convert number */
  7739.         if (dig > 10) dig -= 'a'-'0'-10;
  7740.         if (dig >= radix) {
  7741.         if (cmdlvl == 0 && !x_ifnum && !xerror)
  7742.           printf("?Invalid digit '%c' in number\n",*tp);
  7743.         xerror = 1;
  7744.         return(NUMBER);
  7745.         }
  7746.         tokval = radix*tokval + dig;
  7747.     }
  7748.     return(NUMBER);
  7749.     }
  7750.     if (cmdlvl == 0 && !x_ifnum && !xerror)
  7751.       printf("Invalid character '%c' in input\n",*cp);
  7752.     xerror = 1;
  7753.     cp++;
  7754.     return(gettok());
  7755. #else
  7756. /* This code allows non-numbers to be treated as macro names */
  7757.     {
  7758.     int i, x;
  7759.     char * s, * cp1;
  7760.     cp1 = cp;
  7761.     tp = tbuf;
  7762.     for (i = 0; i < 80; i++) {
  7763.         /* Look ahead to next break character */
  7764.         /* pretty much anything that is not in the switch() above. */
  7765.         if (isalpha(*cp) || isdigit(*cp) ||
  7766.         *cp == '_' || *cp == ':' || *cp == '.' ||
  7767.         *cp == '[' || *cp == ']' ||
  7768.         *cp == '{' || *cp == '}'
  7769.         )
  7770.           tbuf[i] = *cp++;
  7771.         else
  7772.           break;
  7773.     }
  7774.     if (i >= 80) {
  7775.         printf("Too long - \"%s\"\n", cp1);
  7776.         xerror = 1;
  7777.         cp++;
  7778.         return(gettok());
  7779.     }
  7780.     if (xerror) return(NUMBER);
  7781.  
  7782.     tbuf[i] = NUL;
  7783.     s = tbuf;
  7784.     if (!isdigit(tbuf[0])) {
  7785.         char * s2 = NULL;
  7786.         x = mxlook(mactab,tbuf,nmac);
  7787.         debug(F111,"gettok mxlook",tbuf,x);
  7788.             if (x < 0) {
  7789.         if (cmdlvl == 0 && !x_ifnum && !xerror)
  7790.           printf("Bad number - \"%s\"\n",tbuf);
  7791.         xerror = 1;
  7792.         cp++;
  7793.         return(gettok());
  7794.         }
  7795.         s2 = mactab[x].mval;
  7796.         if (!s2) s2 = "";
  7797.         if (*s2) s = s2;
  7798.     }
  7799. #ifdef CKFLOAT
  7800.     x = isfloat(s,0);
  7801. #else
  7802.     x = chknum(s);
  7803. #endif /* CKFLOAT */
  7804.     if (x > 0) {
  7805.         tokval = atoi(s);
  7806.     } else {
  7807.         if (cmdlvl == 0 && !x_ifnum && !xerror)
  7808.           printf("Bad number - \"%s\"\n",tbuf);
  7809.         xerror = 1;
  7810.         cp++;
  7811.         return(gettok());
  7812.     }
  7813.     return(NUMBER);
  7814.     }
  7815. #endif /* COMMENT */
  7816. }
  7817.  
  7818. static long
  7819. #ifdef CK_ANSIC
  7820. expon(long x, long y)
  7821. #else
  7822. expon(x,y) long x,y;
  7823. #endif /* CK_ANSIC */
  7824. /* expon */ {
  7825.     long result = 1;
  7826.     int sign = 1;
  7827.     if (y < 0) return(0);
  7828.     if (x < 0) {
  7829.     x = -x;
  7830.     if (y & 1) sign = -1;
  7831.     }
  7832.     while (y != 0) {
  7833.     if (y & 1) result *= x;
  7834.     y >>= 1;
  7835.     if (y != 0) x *= x;
  7836.   }
  7837.   return(result * sign);
  7838. }
  7839.  
  7840. /*
  7841.  * factor ::= simple | simple ^ factor
  7842.  *
  7843.  */
  7844. static VOID
  7845. factor() {
  7846.     long oldval;
  7847.     simple();
  7848.     if (curtok == '^') {
  7849.     oldval = expval;
  7850.     curtok = gettok();
  7851.     factor();
  7852.     expval = expon(oldval,expval);
  7853.     }
  7854. }
  7855.  
  7856. /*
  7857.  * termp ::= NULL | {*,/,%,&} factor termp
  7858.  *
  7859.  */
  7860. static VOID
  7861. termp() {
  7862.     while (curtok == '*' || curtok == '/' || curtok == '%' || curtok == '&') {
  7863.     long oldval;
  7864.     char op;
  7865.     op = curtok;
  7866.     curtok = gettok();        /* skip past operator */
  7867.     oldval = expval;
  7868.     factor();
  7869.     switch(op) {
  7870.       case '*': expval = oldval * expval; break;
  7871.       case '/':
  7872.       case '%':
  7873.         if (expval == 0) {
  7874.         if (!x_ifnum)
  7875.           printf("?Divide by zero\n");
  7876.         xerror = 1;
  7877.         divbyzero = 1;
  7878.         expval = -1;
  7879.         } else
  7880.           expval = (op == '/') ? (oldval / expval) : (oldval % expval);
  7881.         break;
  7882.       case '&':
  7883.         expval = oldval & expval; break;
  7884.     }
  7885.     }
  7886. }
  7887.  
  7888. static long
  7889. #ifdef CK_ANSIC
  7890. fact(long x)
  7891. #else
  7892. fact(x) long x;
  7893. #endif /* CK_ANSIC */
  7894. /* fact */ {                /* factorial */
  7895.     long result = 1;
  7896.     while (x > 1)
  7897.       result *= x--;
  7898.     return(result);
  7899. }
  7900.  
  7901. /*
  7902.  * term ::= factor termp
  7903.  *
  7904.  */
  7905. static VOID
  7906. term() {
  7907.     factor();
  7908.     termp();
  7909. }
  7910.  
  7911. static long
  7912. #ifdef CK_ANSIC
  7913. gcd(long x, long y)
  7914. #else
  7915. gcd(x,y) long x,y;
  7916. #endif /* CK_ANSIC */
  7917. /* gcd */ {                /* Greatest Common Divisor */
  7918.     int nshift = 0;
  7919.     if (x < 0) x = -x;
  7920.     if (y < 0) y = -y;            /* validate arguments */
  7921.     if (x == 0 || y == 0) return(x + y);    /* this is bogus */
  7922.  
  7923.     while (!((x & 1) | (y & 1))) {    /* get rid of powers of 2 */
  7924.     nshift++;
  7925.     x >>= 1;
  7926.     y >>= 1;
  7927.     }
  7928.     while (x != 1 && y != 1 && x != 0 && y != 0) {
  7929.     while (!(x & 1)) x >>= 1;    /* eliminate unnecessary */
  7930.     while (!(y & 1)) y >>= 1;    /* powers of 2 */
  7931.     if (x < y) {            /* force x to be larger */
  7932.         long t;
  7933.         t = x;
  7934.         x = y;
  7935.         y = t;
  7936.     }
  7937.     x -= y;
  7938.     }
  7939.     if (x == 0 || y == 0) return((x + y) << nshift); /* gcd is non-zero one */
  7940.     else return((long) 1 << nshift);    /* else gcd is 1 */
  7941. }
  7942.  
  7943. /*
  7944.  * exprp ::= NULL | {+,-,|,...} term exprp
  7945.  *
  7946.  */
  7947. static VOID
  7948. exprp() {
  7949.     while (windex("+-|<>#@",curtok) != NULL) {
  7950.     long oldval;
  7951.     char op;
  7952.     op = curtok;
  7953.     curtok = gettok();        /* skip past operator */
  7954.     oldval = expval;
  7955.     term();
  7956.     switch(op) {
  7957.       case '+' : expval = oldval + expval; break;
  7958.       case '-' : expval = oldval - expval; break;
  7959.       case '|' : expval = oldval | expval; break;
  7960.       case '#' : expval = oldval ^ expval; break;
  7961.       case '@' : expval = gcd(oldval,expval); break;
  7962.       case '<' : expval = oldval << expval; break;
  7963.       case '>' : expval = oldval >> expval; break;
  7964.     }
  7965.     }
  7966. }
  7967.  
  7968. /*
  7969.  * expr ::= term exprp
  7970.  *
  7971.  */
  7972. static VOID
  7973. expr() {
  7974.     term();
  7975.     exprp();
  7976. }
  7977.  
  7978. static long
  7979. xparse() {
  7980.     curtok = gettok();
  7981.     expr();
  7982. #ifdef COMMENT
  7983.     if (curtok == '$') {
  7984.     curtok = gettok();
  7985.     if (curtok != NUMBER) {
  7986.         if (cmdlvl == 0 && !x_ifnum)
  7987.           printf("?Illegal radix\n");
  7988.         xerror = 1;
  7989.         return(0);
  7990.     }
  7991.     curtok = gettok();
  7992.     }
  7993. #endif /* COMMENT */
  7994.     if (curtok != N_EOT) {
  7995.     if (cmdlvl == 0 && !x_ifnum && !xerror)
  7996.       printf("?Extra characters after expression\n");
  7997.     xerror = 1;
  7998.     }
  7999.     return(expval);
  8000. }
  8001.  
  8002. char *                    /* Silent front end for evala() */
  8003. evalx(s) char *s; {
  8004.     char * p;
  8005.     int t;
  8006.     t = x_ifnum;
  8007.     x_ifnum = 1;
  8008.     p = evala(s);
  8009.     x_ifnum = t;
  8010.     return(p);
  8011. }
  8012.  
  8013. char *
  8014. evala(s) char *s; {
  8015.     long v;                /* Numeric value */
  8016.     if (!s) return("");
  8017.     xerror = 0;                /* Start out with no error */
  8018.     divbyzero = 0;
  8019.     cp = s;                /* Make the argument global */
  8020.     v = xparse();            /* Parse the string */
  8021.     return(xerror ? "" : ckltoa(v));    /* Return empty string on error */
  8022. }
  8023.  
  8024. /*
  8025.  * simplest ::= NUMBER | ( expr )
  8026.  *
  8027.  */
  8028. static VOID
  8029. simplest() {
  8030.     char * p;
  8031.     p = cp;
  8032.     if (curtok == NUMBER)
  8033.       expval = tokval;
  8034.     else if (curtok == '(') {
  8035.     curtok = gettok();        /* skip over paren */
  8036.     expr();
  8037.     if (curtok != ')') {
  8038.         if (cmdlvl == 0 && !x_ifnum && !xerror)
  8039.           printf("?Missing right parenthesis\n");
  8040.         xerror = 1;
  8041.     }
  8042.     debug(F110,"GETTOK SIMPLEST ()",p,0);
  8043.  
  8044.     } else {
  8045.     if (cmdlvl == 0 && !x_ifnum && !xerror)
  8046.       printf("?Operator unexpected\n");
  8047.     xerror = 1;
  8048.     }
  8049.     curtok = gettok();
  8050. }
  8051.  
  8052. /*
  8053.  * simpler ::= simplest | simplest !
  8054.  *
  8055.  */
  8056. static VOID
  8057. simpler() {
  8058.     simplest();
  8059.     if (curtok == '!') {
  8060.     curtok = gettok();
  8061.     expval = fact(expval);
  8062.     }
  8063. }
  8064.  
  8065. /*
  8066.  * simple ::= {-,~,!} simpler | simpler
  8067.  *
  8068.  */
  8069.  
  8070. static VOID
  8071. simple() {
  8072.     if (curtok == '-' || curtok == '~' || curtok == '!' || curtok == '+') {
  8073.     int op = curtok;
  8074.     curtok = gettok();        /* skip over - sign */
  8075.     simpler();            /* parse the factor again */
  8076.     if (op != '+')
  8077.       expval = (op == '-') ? -expval : ((op == '!') ? !expval : ~expval);
  8078.     } else simpler();
  8079. }
  8080.  
  8081. /*  D C L A R R A Y  --  Declare an array  */
  8082. /*
  8083.   Call with:
  8084.    char a = single character designator for the array, e.g. "a".
  8085.    int  n = size of array.
  8086.   Returns:
  8087.    0 or greater on success, having created the requested array with
  8088.      with n+1 elements, 0..n.  If an array of the same name existed
  8089.      previously, it is destroyed.  The new array has all its elements
  8090.      initialized to NULL pointers.
  8091.   -1 on failure (because 'a' out of range or malloc failure).
  8092. */
  8093. int
  8094. #ifdef CK_ANSIC
  8095. dclarray(char a, int n)
  8096. #else
  8097. dclarray(a,n) char a; int n;
  8098. #endif /* CK_ANSIC */
  8099. /* dclarray */ {
  8100.     char c, **p; int i, n2, rc;
  8101.  
  8102.     if (a > 63 && a < 91) a += 32;    /* Convert letters to lowercase */
  8103.     if (a < ARRAYBASE || a > 122)    /* Verify name */
  8104.       return(-1);
  8105.     c = a;
  8106.     a -= ARRAYBASE;            /* Convert name to number */
  8107.     rc = a;
  8108.     if ((p = a_ptr[a]) != NULL) {    /* Delete old array of same name */
  8109.     if (a_link[a] > -1) {        /* Is it a link? */
  8110.         if (n == 0) {        /* If we're just deleting it */
  8111.         a_ptr[a] = (char **) NULL; /* clear all the info. */
  8112.         a_dim[a] = 0;
  8113.         a_link[a] = -1;
  8114.         return(0);
  8115.         }                /* Not deleting */
  8116.         a = a_link[a];        /* Switch to linked-to array */
  8117.     }
  8118.     n2 = a_dim[a];            /* Real array */
  8119.     for (i = 0; i <= n2; i++) {    /* First delete its elements */
  8120.         if (p[i]) {
  8121.         free(p[i]);
  8122.         p[i] = NULL;
  8123.         }
  8124.     }
  8125.     free((char *)a_ptr[a]);        /* Then the element list */
  8126.     if (n == 0) {            /* If undeclaring this array... */
  8127.         for (i = 0; i < 122 - ARRAYBASE; i++) { /* Any linked arrays? */
  8128.         if (i != a && a_link[i] == a) {     /* Find them */
  8129.             a_ptr[i] = (char **) NULL;      /* and remove them */
  8130.             a_dim[i] = 0;
  8131.             a_link[i] = -1;
  8132.         }
  8133.         }
  8134.     }
  8135.     a_ptr[a] = (char **) NULL;    /* Remove pointer to element list */
  8136.     a_dim[a] = 0;            /* Set dimension at zero. */
  8137.     a_link[a] = -1;            /* Unset link word */
  8138.     if (n == 0)
  8139.       return(0);            /* If dimension 0, just deallocate. */
  8140.     }
  8141.     p = (char **) malloc((n+1) * sizeof(char **)); /* Allocate for new array */
  8142.     if (p == NULL) return(-1);        /* Check */
  8143.     a_ptr[a] = p;            /* Save pointer to member list */
  8144.     a_dim[a] = n;            /* Save dimension */
  8145.     for (i = 0; i <= n; i++)        /* Initialize members to null */
  8146.       p[i] = NULL;
  8147.     for (i = 0; i < (int) 'z' - ARRAYBASE; i++) { /* Any linked arrays? */
  8148.     if (i != a && a_link[i] == a) {    /* Find and update them */
  8149.         a_ptr[i] = p;
  8150.         a_dim[i] = n;
  8151.     }
  8152.     }
  8153.     return(rc);
  8154. }
  8155.  
  8156. /*  X A R R A Y  -- Convert array name to array index  */
  8157.  
  8158. int
  8159. xarray(s) char * s; {
  8160.     char buf[8];
  8161.     int x;
  8162.     char c;
  8163.  
  8164.     if (!s) s = "";
  8165.     if (!*s)
  8166.       return(-1);
  8167.     x = strlen(s);
  8168.  
  8169.     buf[0] = NUL;
  8170.     buf[1] = NUL;
  8171.     buf[2] = s[0];
  8172.     buf[3] = (x > 0) ? s[1] : NUL;
  8173.     buf[4] = (x > 1) ? s[2] : NUL;
  8174.     buf[5] = (x > 2) ? s[3] : NUL;
  8175.     buf[6] = NUL;
  8176.     s = buf+2;
  8177.     if (*s == '&') {
  8178.     buf[1] = CMDQ;
  8179.     s--;
  8180.     } else if (*s != CMDQ) {
  8181.     if (isupper(*s))
  8182.       *s = tolower(*s);
  8183.     buf[0] = CMDQ;
  8184.     buf[1] = '&';
  8185.     s = buf;
  8186.     }
  8187.     c = *(s+2);
  8188.     if (c == '@')
  8189.       c = 96;
  8190.     x = (int)c - ARRAYBASE;
  8191.     if (*(s+3) == '[')
  8192.       *(s+3) = NUL;
  8193.     return((x < 0 || x > 'z' - ARRAYBASE || *(s+3)) ? -1 : x);
  8194. }
  8195.  
  8196. /*  A R R A Y B O U N D S  --  Parse array segment notation \&a[n:m]  */
  8197.  
  8198. /*
  8199.   Call with s = array reference, plus two pointers to ints.
  8200.   Returns -1 on error, or array index, with the two ints set as follows:
  8201.    \&a[]     -1, -1
  8202.    \&a[3]     3, -1
  8203.    \&a[3:17]  3, 17
  8204.   The array need not be declared -- this routine is just for parsing.
  8205. */
  8206. int
  8207. arraybounds(s,lo,hi) char * s; int * lo, * hi; {
  8208.     int i, x, y, range[2];
  8209.     char buf[256], * p, * q;
  8210.     char * tmp = NULL;
  8211.  
  8212.     *lo = -1;                /* Default bounds */
  8213.     *hi = -1;
  8214.  
  8215.     if (!s) s = "";            /* Defense de null args */
  8216.     if (!*s)
  8217.       return(-1);
  8218.  
  8219.     x = xarray(s);            /* Check basic structure */
  8220.  
  8221.     if (x < 0)                /* Not OK, fail. */
  8222.       return(-1);
  8223.     range[0] = -1;            /* It's OK -- get contents */
  8224.     range[1] = -1;            /* of subscript brackets */
  8225.     makestr(&tmp,s);            /* Make a pokeable copy */
  8226.     s = tmp;
  8227.     p = s;
  8228.     for (p = s, q = NULL; *p; p++) {    /* First find the brackets */
  8229.     if (*p == '[') {
  8230.         q = p+1;
  8231.     } else if (*p == ']')
  8232.       break;
  8233.     }
  8234.     if (q && *p == ']') {        /* If we have brackets... */
  8235.     int quitnow = 0;
  8236.     for (i = 0; i < 2 && !quitnow; i++) { /* Loop thru their contents */
  8237.         for (p = q; *p; p++) {
  8238.         if ((i == 0 && *p == ':') || *p == ']') {
  8239.             if (*p == ']')
  8240.               quitnow = 1;
  8241.             *p = NUL;
  8242.             if (*q) {        /* We have something */
  8243.             y = 255;    /* Expand variables, etc. */
  8244.             s = buf;
  8245.             zzstring(q,&s,&y);
  8246.             s = evalx(buf);    /* Evaluate it arithmetically */
  8247.             if (s) if (*s)
  8248.               ckstrncpy(buf,s,256);
  8249.             if (!chknum(buf)) { /* Did we get a number? */
  8250.                 makestr(&tmp,NULL);    /* No, fail. */
  8251.                 return(-1);
  8252.             }
  8253.             q = (i == 0) ? p+1 : NULL; /* Point to next if any */
  8254.             range[i] = atoi(buf); /* Set this one */
  8255.             }
  8256.             break;
  8257.         }
  8258.         }
  8259.     }
  8260.     }
  8261.     makestr(&tmp,NULL);            /* Free temporary poked string */
  8262.     *lo = range[0];            /* Return what we got */
  8263.     *hi = range[1];
  8264.     return(x);
  8265. }
  8266.  
  8267. /*  A R R A Y N A M  --  Parse an array name  */
  8268.  
  8269. /*
  8270.   Call with pointer to string that starts with the array reference.
  8271.   String may begin with either \& or just &.
  8272.   On success,
  8273.     Returns letter ID (always lowercase) in argument c,
  8274.       which can also be accent grave (` = 96; '@' is converted to grave);
  8275.     Dimension or subscript in argument n;
  8276.     IMPORTANT: These arguments must be provided by the caller as addresses
  8277.     of ints (not chars), for example:
  8278.       char *s; int x, y;
  8279.       arraynam(s,&x,&y);
  8280.   On failure, returns a negative number, with args n and c set to zero.
  8281. */
  8282. int
  8283. arraynam(ss,c,n) char *ss; int *c; int *n; {
  8284.     int i, y, pp, len;
  8285.     char x;
  8286.     char *s, *p, *sx, *vnp;
  8287.     /* On stack to allow for recursive calls... */
  8288.     char vnbuf[ARRAYREFLEN+1];        /* Entire array reference */
  8289.     char ssbuf[ARRAYREFLEN+1];        /* Subscript in "plain text" */
  8290.     char sxbuf[16];            /* Evaluated subscript */
  8291.  
  8292.     *c = *n = 0;            /* Initialize return values */
  8293.     len = strlen(ss);
  8294.     for (pp = 0,i = 0; i < len; i++) {        /* Check length */
  8295.     if (ss[i] == '[') {
  8296.         pp++;
  8297.     } else if (ss[i] == ']') {
  8298.         if (--pp == 0)
  8299.           break;
  8300.     }        
  8301.     }
  8302.     if (i > ARRAYREFLEN) {
  8303.     printf("?Array reference too long - %s\n",ss);
  8304.     return(-9);
  8305.     }
  8306.     ckstrncpy(vnbuf,ss,ARRAYREFLEN);
  8307.     vnp = vnbuf;
  8308.     if (vnbuf[0] == CMDQ && vnbuf[1] == '&') vnp++;
  8309.     if (*vnp != '&') {
  8310.     printf("?Not an array - %s\n",vnbuf);
  8311.     return(-9);
  8312.     }
  8313.     x = *(vnp + 1);            /* Fold case of array name */
  8314.  
  8315.     /* We don't use isupper & tolower here on purpose because these */
  8316.     /* would produce undesired effects with accented letters. */
  8317.     if (x > 63 && x < 91) x  = *(vnp + 1) = (char) (x + 32);
  8318.     if ((x < ARRAYBASE) || (x > 122) || (*(vnp+2) != '[')) {
  8319.     if (msgflg) {
  8320.         printf("?Invalid format for array name - %s\n",vnbuf);
  8321.         return(-9);
  8322.     } else
  8323.       return(-2);
  8324.     }
  8325.     *c = x;                /* Return the array name */
  8326.     s = vnp+3;                /* Get dimension */
  8327.     p = ssbuf;
  8328.     pp = 1;                /* Bracket counter */
  8329.     for (i = 0; i < ARRAYREFLEN && *s != NUL; i++) { /* Copy up to ] */
  8330.     if (*s == '[') pp++;
  8331.     if (*s == ']' && --pp == 0) break;
  8332.     *p++ = *s++;
  8333.     }
  8334.     if (*s != ']') {
  8335.     printf("?No closing bracket on array dimension - %s\n",vnbuf);
  8336.     return(-9);
  8337.     }
  8338.     p--;                /* Trim whitespace from end */
  8339.     while (*p == SP || *p == HT)
  8340.       p--;
  8341.     p++;
  8342.     *p = NUL;                /* Terminate subscript with null */
  8343.     p = ssbuf;                /* Point to beginning of subscript */
  8344.     while (*p == SP || *p == HT)    /* Trim whitespace from beginning */
  8345.       p++;
  8346.     sx = sxbuf;                /* Where to put expanded subscript */
  8347.     y = 16;
  8348.     zzstring(p,&sx,&y);            /* Convert variables, etc. */
  8349.     sx = sxbuf;
  8350.     while (*sx == SP) sx++;
  8351.     debug(F110,"arraynam sx","",sx);
  8352.     if (!*sx) {                /* Empty brackets... */
  8353.     *n = -17;            /* (Secret code :-) */
  8354.     return(-2);
  8355.     }
  8356.     p = evala(sx);            /* Run it thru \fneval()... */
  8357.     if (p) if (*p) ckstrncpy(sxbuf,p,16); /* We know it has to be a number. */
  8358.  
  8359.     if (!chknum(sxbuf)) {        /* Make sure it's all digits */
  8360.     if (msgflg) {
  8361.         printf("?Array dimension or subscript missing or not numeric\n");
  8362.         return(-9);
  8363.     } else
  8364.       return(-2);
  8365.     }
  8366.     if ((y = atoi(sxbuf)) < 0) {
  8367.         if (cmflgs == 0) printf("\n");
  8368.     if (msgflg) {
  8369.         printf("?Array dimension or subscript not positive or zero\n");
  8370.         return(-9);
  8371.     } else
  8372.       return(-2);
  8373.     }
  8374.     *n = y;                /* Return the subscript or dimension */
  8375.     return(0);
  8376. }
  8377.  
  8378. int
  8379. chkarray(a,i) int a, i; {        /* Check if array is declared */
  8380.     int x;                /* and if subscript is in range */
  8381.     if (a == 64) a = 96;        /* Convert atsign to grave accent */
  8382.     x = a - ARRAYBASE;            /* Values must be in range 95-122 */
  8383. #ifdef COMMENT
  8384.     if (x == 0 && maclvl < 0)        /* Macro arg vector but no macro */
  8385.       return(0);
  8386. #endif /* COMMENT */
  8387.     if (x < 0 || x > 'z' - ARRAYBASE)    /* Not in range */
  8388.       return(-2);
  8389.     if (a_ptr[x] == NULL) return(-1);    /* Not declared */
  8390.     if (i > a_dim[x]) return(-2);    /* Declared but out of range. */
  8391.     return(a_dim[x]);            /* All ok, return dimension */
  8392. }
  8393.  
  8394. #ifdef COMMENT                /* This isn't used. */
  8395. char *
  8396. arrayval(a,i) int a, i; {        /* Return value of \&a[i] */
  8397.     int x; char **p;            /* (possibly NULL) */
  8398.     if (a == 64) a = 96;        /* Convert atsign to grave accent */
  8399.     x = a - ARRAYBASE;            /* Values must be in range 95-122 */
  8400.     if (x < 0 || x > 27) return(NULL);    /* Not in range */
  8401.     if ((x > 0) && (p = a_ptr[x]) == NULL) /* Array not declared */
  8402.       return(NULL);
  8403.     if (i > a_dim[x])            /* Subscript out of range. */
  8404.       return(NULL);
  8405.     return(p[i]);            /* All ok, return pointer to value. */
  8406. }
  8407. #endif /* COMMENT */
  8408.  
  8409. /*
  8410.   pusharray() is called when an array name is included in a LOCAL statement.
  8411.   It moves the pointers from the global definition to the stack, and removes
  8412.   the global definition.  Later, if the same array is declared in the local
  8413.   context, it occupies the global definition in the normal way.  But when
  8414.   popclvl() is called, it replaces the global definition with the one saved
  8415.   here.  The "secret code" is used to indicate to popclv() that it should
  8416.   remove the global array when popping through this level -- otherwise if a
  8417.   local array were declared that had no counterpart at any higher level, it
  8418.   would never be deleted.  This allows Algol-like inheritance to work both
  8419.   on the way down and on the way back up.
  8420. */
  8421. int
  8422. pusharray(x,z) int x, z; {
  8423.     int y;
  8424.     debug(F000,"pusharray x","",x);
  8425.     debug(F101,"pusharray z","",z);
  8426.     y = chkarray(x,z);
  8427.     debug(F101,"pusharray y","",y);
  8428.     x -= ARRAYBASE;            /* Convert name letter to index. */
  8429.     if (x < 0 || x > 27)
  8430.       return(-1);
  8431.     if (y < 0) {
  8432.     aa_ptr[cmdlvl][x] = (char **) NULL;
  8433.     aa_dim[cmdlvl][x] = -23;    /* Secret code (see popclvl()) */
  8434.     } else {
  8435.     aa_ptr[cmdlvl][x] = a_ptr[x];
  8436.     aa_dim[cmdlvl][x] = y;
  8437.     }
  8438.     a_ptr[x] = (char **) NULL;
  8439.     a_dim[x] = 0;
  8440.     return(0);
  8441. }
  8442.  
  8443. /*  P A R S E V A R  --  Parse a variable name or array reference.  */
  8444. /*
  8445.  Call with:
  8446.    s  = pointer to candidate variable name or array reference.
  8447.    *c = address of integer in which to return variable ID.
  8448.    *i = address of integer in which to return array subscript.
  8449.  Returns:
  8450.    -2:  syntax error in variable name or array reference.
  8451.     1:  successful parse of a simple variable, with ID in c.
  8452.     2:  successful parse of an array reference, w/ID in c and subscript in i.
  8453. */
  8454. int
  8455. parsevar(s,c,i) char *s; int *c, *i; {
  8456.     char *p;
  8457.     int x,y,z;
  8458.  
  8459.     p = s;
  8460.     if (*s == CMDQ) s++;        /* Point after backslash */
  8461.  
  8462.     if (*s != '%' && *s != '&') {    /* Make sure it's % or & */
  8463.     printf("?Not a variable name - %s\n",p);
  8464.     return(-9);
  8465.     }
  8466.     if ((int)strlen(s) < 2) {
  8467.     printf("?Incomplete variable name - %s\n",p);
  8468.     return(-9);
  8469.     }
  8470.     if (*s == '%' && *(s+2) != '\0') {
  8471.     printf("?Only one character after '%%' in variable name, please\n");
  8472.     return(-9);
  8473.     }
  8474.     if (*s == '&' && *(s+2) != '[') {
  8475.     printf("?Array subscript expected - %s\n",p);
  8476.     return(-9);
  8477.     }
  8478.     if (*s == '%') {            /* Simple variable. */
  8479.     y = *(s+1);            /* Get variable ID letter/char */
  8480.     if (isupper(y)) y -= ('a'-'A');    /* Convert upper to lower case */
  8481.     *c = y;                /* Set the return values. */
  8482.     *i = -1;            /* No array subscript. */
  8483.     return(1);            /* Return 1 = simple variable */
  8484.     }
  8485.     if (*s == '&') {            /* Array reference. */
  8486.     y = arraynam(s,&x,&z);        /* Go parse it. */
  8487.     debug(F101,"parsevar arraynam","",y);
  8488.     if ((y) < 0) {
  8489.         if (y == -2)
  8490.           return(pusharray(x,z));
  8491.         if (y != -9)
  8492.           printf("?Invalid array reference - %s\n",p);
  8493.         return(-9);
  8494.     }
  8495.     if (chkarray(x,z) < 0) {    /* Check if declared, etc. */
  8496.         printf("?Array not declared or subscript out of range\n");
  8497.         return(-9);
  8498.     }
  8499.     *c = x;                /* Return array letter */
  8500.     *i = z;                /* and subscript. */
  8501.     return(2);
  8502.     }
  8503.     return(-2);                /* None of the above. */
  8504. }
  8505.  
  8506.  
  8507. #define VALN 32
  8508.  
  8509. /* Get the numeric value of a variable */
  8510. /*
  8511.   Call with pointer to variable name, pointer to int for return value.
  8512.   Returns:
  8513.     0 on success with second arg containing the value.
  8514.    -1 on failure (bad variable syntax, variable not defined or not numeric).
  8515. */
  8516. int
  8517. varval(s,v) char *s; int *v; {
  8518.     char valbuf[VALN+1];        /* s is pointer to variable name */
  8519.     char name[256];
  8520.     char *p;
  8521.     int y;
  8522.  
  8523.     if (*s != CMDQ) {            /* Handle macro names too */
  8524.     ckmakmsg(name,256,"\\m(",s,")",NULL);
  8525.     s = name;
  8526.     }
  8527.     p = valbuf;                /* Expand variable into valbuf. */
  8528.     y = VALN;
  8529.     if (zzstring(s,&p,&y) < 0) return(-1);
  8530.     p = valbuf;                /* Make sure value is numeric  */
  8531.     if (!*p) {                /* Be nice -- let an undefined */
  8532.     valbuf[0] = '0';        /* variable be treated as 0.   */
  8533.     valbuf[1] = NUL;
  8534.     }
  8535.     if (chknum(p)) {            /* Convert numeric string to int */
  8536.     *v = atoi(p);            /* OK */
  8537.     } else {                /* Not OK */
  8538.     p = evala(p);            /* Maybe it's an expression */
  8539.     if (!chknum(p))            /* Did it evaluate? */
  8540.       return(-1);            /* No, failure. */
  8541.     else                /* Yes, */
  8542.       *v = atoi(p);            /* success */
  8543.     }
  8544.     return(0);
  8545. }
  8546.  
  8547. /* Increment or decrement a variable */
  8548. /* Returns -1 on failure, 0 on success */
  8549.  
  8550. int
  8551. incvar(s,x,z) char *s; int x; int z; {    /* Increment a numeric variable */
  8552.     int n;                /* s is pointer to variable name */
  8553.                     /* x is amount to increment by */
  8554.                     /* z != 0 means add */
  8555.                     /* z = 0 means subtract */
  8556.     if (varval(s,&n) < 0)        /* Convert numeric string to int */
  8557.       return(-1);
  8558.     if (z)                /* Increment it by the given amount */
  8559.       n += x;
  8560.     else                /* or decrement as requested. */
  8561.       n -= x;
  8562.     addmac(s,ckitoa(n));        /* Replace old variable */
  8563.     return(0);
  8564. }
  8565.  
  8566. /* D O D O  --  Do a macro */
  8567.  
  8568. /*
  8569.   Call with x = macro table index, s = pointer to arguments.
  8570.   Returns 0 on failure, 1 on success.
  8571. */
  8572.  
  8573. int
  8574. dodo(x,s,flags) int x; char *s; int flags; {
  8575.     int y;
  8576.     extern int tra_asg, tra_cmd; int tra_tmp;
  8577. #ifndef NOLOCAL
  8578. #ifdef OS2
  8579.     extern int term_io;
  8580.     int term_io_sav = term_io;
  8581. #endif /* OS2 */
  8582. #endif /* NOLOCAL */
  8583.  
  8584.     if (x < 0)                /* It can happen! */
  8585.       return(-1);
  8586.  
  8587.     tra_tmp = tra_asg;
  8588.  
  8589.     if (++maclvl >= MACLEVEL) {        /* Make sure we have storage */
  8590.         debug(F101,"dodo maclvl too deep","",maclvl);
  8591.     --maclvl;
  8592.     printf("Macros nested too deeply\n");
  8593.     return(0);
  8594.     }
  8595.     macp[maclvl] = mactab[x].mval;    /* Point to the macro body */
  8596.     macx[maclvl] = mactab[x].mval;    /* Remember where the beginning is */
  8597.  
  8598. #ifdef COMMENT
  8599.     makestr(&(m_line[maclvl]),s);    /* Entire arg string for "\%*" */
  8600. #endif /* COMMENT */
  8601.  
  8602.     cmdlvl++;                /* Entering a new command level */
  8603.     if (cmdlvl >= CMDSTKL) {        /* Too many macros + TAKE files? */
  8604.         debug(F101,"dodo cmdlvl too deep","",cmdlvl);
  8605.     cmdlvl--;
  8606.     printf("?TAKE files and DO commands nested too deeply\n");
  8607.     return(0);
  8608.     }
  8609. #ifdef DEBUG
  8610.     if (deblog) {
  8611.     debug(F111,"CMD +M",mactab[x].kwd,cmdlvl);
  8612.     debug(F010,"CMD ->",s,0);
  8613.     }
  8614. #endif /* DEBUG */
  8615.  
  8616. #ifdef VMS
  8617.     conres();                /* So Ctrl-C, etc, will work. */
  8618. #endif /* VMS */
  8619. #ifndef NOLOCAL
  8620. #ifdef OS2
  8621.     term_io = 0;            /* Disable terminal emulator I/O */
  8622. #endif /* OS2 */
  8623. #endif /* NOLOCAL */
  8624.     ifcmd[cmdlvl] = 0;
  8625.     iftest[cmdlvl] = 0;
  8626.     count[cmdlvl] = count[cmdlvl-1];    /* Inherit COUNT from previous level */
  8627.     intime[cmdlvl] = intime[cmdlvl-1];    /* Inherit previous INPUT TIMEOUT */
  8628.     inpcas[cmdlvl] = inpcas[cmdlvl-1];    /*   and INPUT CASE */
  8629.     takerr[cmdlvl] = takerr[cmdlvl-1];    /*   and TAKE ERROR */
  8630.     merror[cmdlvl] = merror[cmdlvl-1];    /*   and MACRO ERROR */
  8631.     xquiet[cmdlvl] = quiet;
  8632.     xcmdsrc = CMD_MD;
  8633.     cmdstk[cmdlvl].src = CMD_MD;    /* Say we're in a macro */
  8634.     cmdstk[cmdlvl].lvl = maclvl;    /* and remember the macro level */
  8635.     cmdstk[cmdlvl].ccflgs = flags & ~CF_IMAC; /* Set flags */
  8636.  
  8637.     /* Initialize return value except in FOR, WHILE, IF, and SWITCH macros */
  8638.  
  8639.     if (!(flags & CF_IMAC) && mrval[maclvl]) {
  8640.     free(mrval[maclvl]);
  8641.     mrval[maclvl] = NULL;
  8642.     }
  8643.  
  8644.     /* Clear old %0..%9 arguments */
  8645.  
  8646.     addmac("%0",mactab[x].kwd);        /* Define %0 = name of macro */
  8647.     makestr(&(m_xarg[maclvl][0]),mactab[x].kwd);
  8648.     varnam[0] = '%';
  8649.     varnam[2] = '\0';
  8650.     tra_asg = 0;
  8651.     for (y = 1; y < 10; y++) {        /* Clear args %1..%9 */
  8652.     if (m_arg[maclvl][y]) {        /* Don't call delmac() unless */
  8653.         varnam[1] = (char) (y + '0'); /* we have to... */
  8654.         delmac(varnam,0);
  8655.     }
  8656.     }
  8657.     tra_asg = tra_tmp;
  8658.  
  8659. /* Assign the new args one word per arg, allowing braces to group words */
  8660.  
  8661.     xwords(s,MAXARGLIST,NULL,0);
  8662.  
  8663. #ifndef NOLOCAL
  8664. #ifdef OS2
  8665.     term_io = term_io_sav;
  8666. #endif /* OS2 */
  8667. #endif /* NOLOCAL */
  8668.     if (tra_cmd)
  8669.       printf("[%d] +M: \"%s\"\n",cmdlvl,mactab[x].kwd);
  8670.     return(1);
  8671. }
  8672.  
  8673. /* Insert "literal" quote around each comma-separated command to prevent */
  8674. /* its premature expansion.  Only do this if object command is surrounded */
  8675. /* by braces. */
  8676.  
  8677. static char* flit = "\\flit(";
  8678.  
  8679. int
  8680. litcmd(src,dest,n) char **src, **dest; int n; {
  8681.     int bc = 0, pp = 0;
  8682.     char c, *s, *lp, *ss;
  8683.  
  8684.     s = *src;
  8685.     lp = *dest;
  8686.  
  8687.     debug(F010,"litcmd",s,0);
  8688.  
  8689.     while (*s == SP) s++;        /* Strip extra leading spaces */
  8690.  
  8691.     if (*s == '{') {            /* Starts with brace */
  8692.         pp = 0;                /* Paren counter */
  8693.     bc = 1;                /* Count leading brace */
  8694.     *lp++ = *s++;            /* Copy it */
  8695.     if (--n < 1) return(-1);    /* Check space */
  8696.     while (*s == SP) s++;        /* Strip interior leading spaces */
  8697.     ss = flit;            /* Point to "\flit(" */
  8698.     while ((*lp++ = *ss++))        /* Copy it */
  8699.       if (--n < 1)            /* and check space */
  8700.         return(-1);
  8701.     lp--;                /* Back up over null */
  8702.  
  8703.     while (*s) {            /* Go thru rest of text */
  8704.         c = *s;
  8705.         if (c == '{') bc++;        /* Count brackets */
  8706.         if (c == '(') pp++;        /* and parens */
  8707.         if (c == ')') {        /* Right parenthesis. */
  8708.         pp--;            /* Count it. */
  8709.         if (pp < 0) {        /* An unbalanced right paren... */
  8710. #ifdef COMMENT
  8711. /*
  8712.   The problem here is that "\{" appears to be a quoted brace and therefore
  8713.   isn't counted; then the "}" matches an earlier opening brace, causing
  8714.   (e.g.) truncation of macros by getncm().
  8715. */
  8716.             if (n < 5)        /* Out of space in dest buffer? */
  8717.               return(-1);    /* If so, give up. */
  8718.             *lp++ = CMDQ;    /* Must be quoted to prevent */
  8719.             *lp++ = '}';    /* premature termination of */
  8720.             *lp++ = '4';    /* \flit(...) */
  8721.             *lp++ = '1';
  8722.             *lp++ = '}';
  8723.             n -= 5;
  8724. #else
  8725. /* Here we rely on the fact the \nnn never takes more than 3 digits */
  8726.             if (n < 4)        /* Out of space in dest buffer? */
  8727.               return(-1);    /* If so, give up. */
  8728.             *lp++ = CMDQ;    /* Must be quoted to prevent */
  8729.             *lp++ = '0';    /* premature termination of */
  8730.             *lp++ = '4';    /* \flit(...) */
  8731.             *lp++ = '1';
  8732.             n -= 4;
  8733. #endif /* COMMENT */
  8734.             pp++;        /* Uncount it. */
  8735.             s++;
  8736.             continue;
  8737.         }
  8738.         }
  8739.         if (c == '}') {        /* Closing brace. */
  8740.         if (--bc == 0) {    /* Final one? */
  8741.             *lp++ = ')';    /* Add closing paren for "\flit()" */
  8742.             if (--n < 1) return(-1);
  8743.             *lp++ = c;
  8744.             if (--n < 1) return(-1);
  8745.             s++;
  8746.             break;
  8747.         }
  8748.         }
  8749.             *lp++ = c;            /* General case */
  8750.         if (--n < 1) return(-1);
  8751.         s++;
  8752.         }
  8753.     *lp = NUL;
  8754.     } else {                /* No brackets around, */
  8755.     while ((*lp++ = *s++))        /* just copy. */
  8756.       if (--n < 1)
  8757.         return(-1);
  8758.     lp--;
  8759.     }
  8760.     *src = s;                /* Return updated source */
  8761.     *dest = lp;                /* and destination pointers */
  8762.     if (bc)                /* Fail if braces unbalanced */
  8763.       return(-1);
  8764.     else                /* Otherwise succeed. */
  8765.       return(0);
  8766. }
  8767. #endif /* NOSPL */
  8768.  
  8769. /* Functions moved here from ckuusr.c to even out the module sizes... */
  8770.  
  8771. /*
  8772.   Breaks up string s -- IN PLACE! -- into a list of up to max words.
  8773.   Pointers to each word go into the array list[].
  8774.   max is the maximum number of words (pointers).
  8775.   If list is NULL, then they are added to the macro table.
  8776.   flag = 0 means the last field is to be one word, like all the other fields,
  8777.          so anything after it is discarded.
  8778.   flag = 1 means the last field extends to the end of the string, even if
  8779.          there are lots of words left, so the last field contains the
  8780.          remainder of the string.
  8781. */
  8782. VOID
  8783. xwords(s,max,list,flag) char *s; int max; char *list[]; int flag; {
  8784.     char *p;
  8785.     int b, i, k, q, y, z;
  8786. #ifndef NOSPL
  8787.     int macro;
  8788.     macro = (list == NULL);
  8789.     debug(F010,"xwords",s,0);
  8790. #endif /* NOSPL */
  8791.  
  8792. #ifdef XWORDSDEBUG
  8793.     printf("XWORDS string=%s\n",s);
  8794.     printf("XWORDS max=%d\n",max);
  8795. #endif /* XWORDSDEBUG */
  8796.     p = s;                /* Pointer to beginning of string */
  8797.     q = 0;                /* Flag for doublequote removal */
  8798.     b = 0;                /* Flag for outer brace removal */
  8799.     k = 0;                /* Flag for in-word */
  8800.     y = 0;                /* Brace nesting level */
  8801.     z = 0;                /* "Word" counter, 0 thru max */
  8802.  
  8803.     if (list)
  8804.       for (i = 0; i <= max; i++)    /* Initialize pointers */
  8805.     list[i] = NULL;
  8806.  
  8807.     if (flag) max--;
  8808.  
  8809.     while (1) {                /* Go thru word list */
  8810.     if (!s || (*s == '\0')) {    /* No more characters? */
  8811.         if (k != 0) {        /* Was I in a word? */
  8812.         if (z == max) break;    /* Yes, only go up to max. */
  8813.         z++;            /* Count this word. */
  8814. #ifdef XWORDSDEBUG
  8815.         printf("1 z++ = %d\n", z);
  8816. #endif /* XWORDSDEBUG */
  8817. #ifndef NOSPL
  8818.         if (macro) {        /* Doing macro args */
  8819.             if (z < 10) {
  8820.             varnam[1] = (char) (z + '0'); /* Assign last arg */
  8821.             addmac(varnam,p);
  8822.             }
  8823.             if (z <= max) {
  8824. #ifdef COMMENT
  8825.             if (maclvl < 0)
  8826.               addmac(varnam,p);
  8827.             else
  8828. #endif /* COMMENT */
  8829.               makestr(&(m_xarg[maclvl][z]),p);
  8830.             }
  8831.         } else {        /* Not doing macro args */
  8832. #endif /* NOSPL */
  8833.             list[z] = p;    /* Assign pointer. */
  8834. #ifdef XWORDSDEBUG
  8835.             printf("[1]LIST[%d]=\"%s\"\n",z,list[z]);
  8836. #endif /* XWORDSDEBUG */
  8837. #ifndef NOSPL
  8838.         }
  8839. #endif /* NOSPL */
  8840.         break;            /* And get out. */
  8841.         } else break;        /* Was not in a word */
  8842.     }
  8843.     if (k == 0 && (*s == SP || *s == HT)) { /* Eat leading blanks */
  8844.         s++;
  8845.         continue;
  8846.     } else if (q == 0 && *s == '{') { /* An opening brace */
  8847.         if (k == 0 && y == 0) {    /* If leading brace */
  8848.         p = s+1;        /* point past it */
  8849.         b = 1;            /* and flag that we did this */
  8850.         }
  8851.         k = 1;            /* Flag that we're in a word */
  8852.         y++;            /* Count the brace. */
  8853.     } else if (q == 0 && *s == '}') { /* A closing brace. */
  8854.         y--;            /* Count it. */
  8855.         if (y <= 0 && b != 0) {    /* If it matches the leading brace */
  8856.         char c;
  8857.         c = *(s+1);
  8858.         if (!c || c == SP || c == HT) { /* at EOL or followed by SP */
  8859.             *s = SP;        /* change it to a space */
  8860.             b = 0;        /* and we're not in braces any more */
  8861.         }
  8862.         }
  8863. #ifdef DOUBLEQUOTING
  8864.     /* Opening doublequote */
  8865.     } else if (k == 0 && b == 0 && *s == '"' && dblquo) {
  8866.         y++;
  8867.         p = s+1;            /* point past it */
  8868.         q = 1;            /* and flag that we did this */
  8869.         k = 1;            /* Flag that we're in a word */
  8870.         /* Closing double quote */
  8871.     } else if (q > 0 && k > 0 && b == 0 && *s == '"' && dblquo) {
  8872.         char c;
  8873.         c = *(s+1);
  8874.         if (!c || c == SP || c == HT) { /* at EOL or followed by SP */
  8875.         y--;
  8876.         *s = SP;        /* change it to a space */
  8877.         q = 0;            /* and we're not in quotes any more */
  8878.         }
  8879. #endif /* DOUBLEQUOTING */
  8880.  
  8881.     } else if (*s != SP && *s != HT) { /* Nonspace means we're in a word */
  8882.         if (k == 0) {        /* If we weren't in a word before, */
  8883.         p = s;            /* Mark the beginning */
  8884.         if (flag && z == max) {    /* Want last word to be remainder? */
  8885.             z++;
  8886. #ifdef XWORDSDEBUG
  8887.             printf("1 z++ = %d\n", z);
  8888. #endif /* XWORDSDEBUG */
  8889.             list[z] = p;    /* Yes, point to it */
  8890. #ifdef XWORDSDEBUG
  8891.             printf("[4]LIST[%d]=\"%s\"\n",z,list[z]);
  8892. #endif /* XWORDSDEBUG */
  8893.             break;        /* and quit */
  8894.         }
  8895.         k = 1;            /* Set in-word flag */
  8896.         }
  8897.     }
  8898.     /* If we're not inside a braced quantity, and we are in a word, and */
  8899.     /* we have hit whitespace, then we have a word. */
  8900.     if ((y < 1) && (k != 0) && (*s == SP || *s == HT) && !b) {
  8901.         if (!flag || z < max)    /* if we don't want to keep rest */
  8902.           *s = '\0';        /* terminate the arg with null */
  8903.         k = 0;            /* say we're not in a word any more */
  8904.         y = 0;            /* start braces off clean again */
  8905.         if (z == max) break;    /* Only go up to max. */
  8906.         z++;            /* count this arg */
  8907. #ifdef XWORDSDEBUG
  8908.         printf("1 z++ = %d\n", z);
  8909. #endif /* XWORDSDEBUG */
  8910.  
  8911. #ifndef NOSPL
  8912.         if (macro) {
  8913.         if (z < 10) {
  8914.             varnam[1] = (char) (z + '0'); /* compute its name */
  8915.             addmac(varnam,p);    /* add it to the macro table */
  8916.         }
  8917.         if (z <= max) {
  8918. #ifdef COMMENT
  8919.             if (maclvl < 0)
  8920.               addmac(varnam,p);
  8921.             else
  8922. #endif /* COMMENT */
  8923.               makestr(&(m_xarg[maclvl][z]),p);
  8924.         }
  8925.         } else {
  8926. #endif /* NOSPL */
  8927.         list[z] = p;
  8928. #ifdef XWORDSDEBUG
  8929.         printf("[2]LIST[%d]=\"%s\"\n",z,list[z]);
  8930. #endif /* XWORDSDEBUG */
  8931. #ifndef NOSPL
  8932.         }
  8933. #endif /* NOSPL */
  8934.         p = s+1;
  8935.     }
  8936.     s++;                /* Point past this character */
  8937.     }
  8938.     if ((z == 0) && (y > 1)) {        /* Extra closing brace(s) at end */
  8939.     z++;
  8940. #ifndef NOSPL
  8941.     if (macro) {
  8942.         if (z < 10) {
  8943.         varnam[1] = z + '0';    /* compute its name */
  8944.         addmac(varnam,p);    /* Add rest of line to last arg */
  8945.         }
  8946.         if (z <= max) {
  8947. #ifdef COMMENT
  8948.         if (maclvl < 0)
  8949.           addmac(varnam,p);
  8950.         else
  8951. #endif /* COMMENT */
  8952.           makestr(&(m_xarg[maclvl][z]),p);
  8953.         }
  8954.     } else {
  8955. #endif /* NOSPL */
  8956.         list[z] = p;
  8957. #ifdef XWORDSDEBUG
  8958.         printf("[3]LIST[%d]=\"%s\"\n",z,list[z]);
  8959. #endif /* XWORDSDEBUG */
  8960. #ifndef NOSPL
  8961.     }
  8962. #endif /* NOSPL */
  8963.     }
  8964. #ifndef NOSPL
  8965.     if (macro) {            /* Macro */
  8966.     if (maclvl < 0) {
  8967.         a_dim[0] = z;        /* Array dimension is one less */
  8968.         topargc = z + 1;        /* than \v(argc) */
  8969.     } else {
  8970.         macargc[maclvl] = z + 1;    /* Set \v(argc) variable */
  8971.         n_xarg[maclvl] = z + 1;    /* This is the actual number */
  8972.         a_ptr[0] = m_xarg[maclvl];    /* Point \&_[] at the args */
  8973.         a_dim[0] = z;        /* And give it this dimension */
  8974.     }
  8975.     }
  8976. #endif /* NOSPL */
  8977.     return;
  8978. }
  8979.  
  8980. #ifndef NOSPL
  8981.  
  8982. /*  D O S H I F T  --  Do the SHIFT Command; shift macro args left by n */
  8983.  
  8984. /*  Note: at some point let's consolidate m_arg[][] and m_xarg[][]. */
  8985.  
  8986. int
  8987. doshift(n) int n; {            /* n = shift count */
  8988.     int i, top, level;
  8989.     char /* *s, *m, */ buf[6];        /* Buffer to build scalar names */
  8990.     char * sx = tmpbuf;
  8991.     int nx = TMPBUFSIZ;
  8992.  
  8993.     debug(F101,"SHIFT count","",n);
  8994.     debug(F101,"SHIFT topargc","",topargc);
  8995.  
  8996.     if (n < 1)                /* Stay in range */
  8997.       return(n == 0 ? 1 : 0);
  8998.  
  8999.     level = maclvl;
  9000.     top = (level < 0) ? topargc : macargc[level];
  9001.  
  9002.     if (n >= top)
  9003.       n = top - 1;
  9004.  
  9005. #ifdef DEBUG
  9006.     if (deblog) {
  9007.     debug(F101,"SHIFT count 2","",n);
  9008.     debug(F101,"SHIFT level","",level);
  9009.     if (level > -1)
  9010.       debug(F101,"SHIFT macargc[level]","",macargc[level]);
  9011.     }
  9012. #endif /* DEBUG */
  9013.  
  9014.     buf[0] = '\\';            /* Initialize name template */
  9015.     buf[1] = '%';
  9016.     buf[2] = NUL;
  9017.     buf[3] = NUL;
  9018.  
  9019.     for (i = 1; i <= n; i++) {        /* Free shifted-over args */
  9020.     if (level < 0) {
  9021.         makestr(&(toparg[i]),NULL);
  9022.     } else {
  9023.         makestr(&(m_xarg[level][i]),NULL);
  9024.     }
  9025.     if (i < 10) {            /* Is this necessary? */
  9026.         buf[2] = (char)(i+'0');
  9027.         delmac(buf,0);
  9028.     }
  9029.     }
  9030.     for (i = 1; i <= top-n; i++) {    /* Shift remaining args */
  9031.     if (level < 0) {
  9032. #ifdef COMMENT
  9033.         toparg[i] = toparg[i+n];    /* Full vector */
  9034. #else
  9035.         makestr(&(toparg[i]),toparg[i+n]); /* Full vector */
  9036. #endif /* COMMENT */
  9037.         if (i < 10)            /* Scalars... */
  9038.           makestr(&(g_var[i+'0']),toparg[i+n]);
  9039.     } else {
  9040. #ifdef COMMENT
  9041.         m_xarg[level][i] = m_xarg[level][i+n];
  9042. #else
  9043.         makestr(&(m_xarg[level][i]),m_xarg[level][i+n]);
  9044. #endif /* COMMENT */
  9045.         if (i < 10) {
  9046.         buf[2] = (char)(i+'0');
  9047.         debug(F010,"SHIFT buf",buf,0);
  9048.         addmac(buf,m_xarg[level][i+n]);
  9049.         }
  9050.     }
  9051.     }
  9052.     for (i = top-n; i <= top; i++) {    /* Clear n args from the end */
  9053.     if (level < 0) {
  9054. #ifdef COMMENT
  9055.         toparg[i] = NULL;
  9056. #else
  9057.         makestr(&(toparg[i]),NULL);
  9058. #endif /* COMMENt */
  9059.         if (i < 10)
  9060.           makestr(&(g_var[i+'0']),NULL);
  9061.     } else {
  9062. #ifdef COMMENT
  9063.         m_xarg[level][i] = NULL;
  9064. #else
  9065.         makestr(&(m_xarg[level][i]),NULL);
  9066. #endif /* COMMENt */
  9067.         if (i < 10) {
  9068.         buf[2] = (char)(i+'0');
  9069.         delmac(buf,0);
  9070.         }
  9071.     }
  9072.     }
  9073.     if (level > -1) {            /* Macro args */
  9074.     macargc[level] -= n;        /* Adjust count */
  9075.     n_xarg[maclvl] = macargc[level]; /* Here too */
  9076.     a_dim[0] = macargc[level] - 1;    /* Adjust array dimension */
  9077.     zzstring("\\fjoin(&_[],{ },1)",&sx,&nx); /* Handle \%* */
  9078. #ifdef COMMENT
  9079.     makestr(&(m_line[level]),tmpbuf);
  9080. #endif /* COMMENT */
  9081.     } else {                /* Ditto for top level */
  9082.     topargc -= n;
  9083.     a_dim[0] = topargc - 1;
  9084.     zzstring("\\fjoin(&_[],{ },1)",&sx,&nx);
  9085. #ifdef COMMENT
  9086.     makestr(&topline,tmpbuf);
  9087. #endif /* COMMENT */
  9088.     }
  9089.     return(1);
  9090. }
  9091. #endif /* NOSPL */
  9092.  
  9093. int
  9094. docd(cx) int cx; {            /* Do the CD command */
  9095.     int x;
  9096.     extern int server, srvcdmsg, cdactive;
  9097.     extern char * cdmsgfile[], * ckcdpath;
  9098.     char *s, *p;
  9099. #ifdef MAC
  9100.     char temp[34];
  9101. #endif /* MAC */
  9102. #ifdef IKSDCONF
  9103. extern int iksdcf;
  9104. #endif /* IKSDCONF */
  9105.  
  9106. #ifndef NOFRILLS
  9107.     if (cx == XXBACK) {
  9108.     if ((x = cmcfm()) < 0)
  9109.     cwdf = 1;
  9110.     if (prevdir) {
  9111.         s = zgtdir();
  9112.         if (!zchdir(prevdir)) {
  9113.         cwdf = 0;
  9114.         perror(s);
  9115.         } else {
  9116.         makestr(&prevdir,s);
  9117.         }
  9118.     }
  9119.     return(cwdf);
  9120.     }
  9121. #endif /* NOFRILLS */
  9122.  
  9123.     if (cx == XXCDUP) {
  9124. #ifdef VMS
  9125.     s = "[-]";
  9126. #else
  9127. #ifdef datageneral
  9128.     s = "^";
  9129. #else
  9130.     s = "..";
  9131. #endif /* datageneral */
  9132. #endif /* VMS */
  9133.     ckstrncpy(line,s,LINBUFSIZ);
  9134.     goto gocd;
  9135.     }
  9136.  
  9137.     cdactive = 1;
  9138. #ifdef GEMDOS
  9139.     if ((x = cmdir("Name of local directory, or carriage return",
  9140.            zhome(),
  9141.            &s,
  9142.            NULL
  9143.            )
  9144.      ) < 0 )
  9145.       return(x);
  9146. #else
  9147. #ifdef OS2
  9148.     if ((x = cmdirp("Name of PC disk and/or directory,\n\
  9149.        or press the Enter key for the default",
  9150.             zhome(),
  9151.             &s,
  9152.             ckcdpath ? ckcdpath : getenv("CDPATH"),
  9153.             xxstring
  9154.             )
  9155.      ) < 0 )
  9156.       return(x);
  9157. #else
  9158. #ifdef MAC
  9159.     x = ckstrncpy(temp,zhome(),32);
  9160.     if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  9161.     if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  9162.  or press the Return key for the desktop on the boot disk",
  9163.            temp,&s, xxstring)) < 0 )
  9164.       return(x);
  9165. #else
  9166.     if ((x = cmdirp("Carriage return for home directory,\n\
  9167. or name of directory on this computer",
  9168. #ifdef VMS
  9169.             "SYS$LOGIN",    /* With no colon */
  9170. #else
  9171.             zhome(),        /* In VMS this is "SYS$LOGIN:" */
  9172. #endif /* VMS */
  9173.             &s,
  9174.             ckcdpath ? ckcdpath : getenv("CDPATH"),
  9175.             xxstring
  9176.             )) < 0)
  9177.       return(x);
  9178. #endif /* MAC */
  9179. #endif /* OS2 */
  9180. #endif /* GEMDOS */
  9181.     ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy */
  9182.     s = line;
  9183. #ifdef VMS
  9184.     if (ckmatch("*.DIR;1$",s,0,0))
  9185.       if (cvtdir(s,tmpbuf,TMPBUFSIZ) > 0)
  9186.     s = tmpbuf;
  9187. #endif /* VMS */
  9188.     debug(F110,"docd",s,0);
  9189. #ifndef MAC
  9190.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  9191.       return(x);
  9192. #endif /* MAC */
  9193.  
  9194.   gocd:
  9195.  
  9196. #ifdef datageneral
  9197.     x = strlen(line);            /* homdir ends in colon, */
  9198.     if (x > 1 && line[x-1] == ':')    /* and "dir" doesn't like that... */
  9199.       line[x-1] = NUL;
  9200. #endif /* datageneral */
  9201.  
  9202. #ifdef MAC
  9203.     cwdf = 1;
  9204.     if (!zchdir(s)) {
  9205.     cwdf = 0;
  9206.     if (*s != ':') {        /* If it failed, */
  9207.         char *p;            /* supply leading colon */
  9208.         int len = (int)strlen(s) + 2;
  9209.         p = malloc(len);        /* and try again... */
  9210.         if (p) {
  9211.         strcpy(p,":");        /* safe */
  9212.         strcat(p,s);        /* safe */
  9213.         if (zchdir(p))
  9214.           cwdf = 1;
  9215.         free(p);
  9216.         p = NULL;
  9217.         }
  9218.     }
  9219.     }
  9220.     if (!cwdf)
  9221.       perror(s);
  9222. #else
  9223.     p = zgtdir();
  9224.     if (!zchdir(s)) {
  9225.     cwdf = 0;
  9226. #ifdef CKROOT
  9227.     if (ckrooterr)
  9228.       printf("?Off limits: \"%s\"\n",s);
  9229.     else
  9230. #endif /* CKROOT */
  9231.       perror(s);
  9232.     } else cwdf = 1;
  9233. #endif /* MAC */
  9234.  
  9235.     x = 0;
  9236.     if (cwdf) {
  9237.     makestr(&prevdir,p);
  9238.     if (srvcdmsg
  9239. #ifdef IKSDCONF
  9240.         && !(inserver && !iksdcf)
  9241. #endif /* IKSDCONF */
  9242.         ) {
  9243.         int i;
  9244.         for (i = 0; i < 8; i++) {
  9245.         if (zchki(cdmsgfile[i]) > -1) {
  9246.             x = 1;
  9247.             dotype(cdmsgfile[i],xaskmore,0,0,NULL,0,NULL,0,0,NULL,0);
  9248.             break;
  9249.         }
  9250.         }
  9251.     }
  9252.     }
  9253. /* xdocd: */
  9254.     if (!x && srvcdmsg && !server
  9255. #ifdef IKSDCONF
  9256.     && !(inserver && !iksdcf)
  9257. #endif /* IKSDCONF */
  9258.     && !quiet && !xcmdsrc)
  9259.       printf("%s\n", zgtdir());
  9260.  
  9261.     return(cwdf);
  9262. }
  9263.  
  9264. static int on_ctrlc = 0;
  9265.  
  9266. VOID
  9267. fixcmd() {            /* Fix command parser after interruption */
  9268. #ifndef NOSPL
  9269. #ifndef NOONCTRLC
  9270.     if (nmac) {                /* Any macros defined? */
  9271.         int k;                          /* Yes */
  9272.         char * s = "on_ctrlc";        /* Name of Ctrl-C handling macro */
  9273.         k = mlook(mactab,s,nmac);    /* Look it up. */
  9274.         if (k >= 0) {                   /* If found, */
  9275.         if (on_ctrlc++ == 0) {    /* if not already executing, */
  9276.         if (dodo(k,"",0) > -1)    /* set it up, */
  9277.           parser(1);        /* execute it, */
  9278.         }
  9279.         delmac(s,1);        /* and undefine it. */
  9280.         }
  9281.     }
  9282.     on_ctrlc = 0;
  9283. #endif /* NOONCTRLC */
  9284. #endif /* NOSPL */
  9285.     dostop();            /* Back to top level (also calls conint()). */
  9286.     bgchk();            /* Check background status */
  9287.     if (*psave) {        /* If old prompt saved, */
  9288.     cmsetp(psave);        /* restore it. */
  9289.     *psave = NUL;
  9290.     }
  9291.     success = 0;        /* Tell parser last command failed */
  9292. }
  9293.  
  9294. #ifndef NOSHOW                /* SHOW FEATURES */
  9295. /*
  9296.   Note, presently optlist[] index overflow is not checked.
  9297.   There is plenty of room (less than 360 entries for 1000 slots).
  9298.   When space starts to get tight, check for noptlist >= NOPTLIST
  9299.   every time noptlist is incremented.
  9300. */
  9301. #define NOPTLIST 1024
  9302. static int noptlist = 0;
  9303. static char * optlist[NOPTLIST+1];
  9304. static int hpos = 0;
  9305.  
  9306. int
  9307. prtopt(lines,s) int * lines; char *s; {    /* Print an option */
  9308.     int y, i;                /* Does word wrap. */
  9309.     if (!s) s = "";
  9310.     i = *lines;
  9311.     if (!*s) {                /* Empty argument */
  9312.     if (hpos > 0) {            /* means to end this line. */
  9313.         printf("\n");        /* Not needed if already at */
  9314.         if (++i > (cmd_rows - 3)) {    /* beginning of new line. */
  9315.         if (!askmore())
  9316.           return(0);
  9317.         else
  9318.           i = 0;
  9319.         }
  9320.     }
  9321.     printf("\n");            /* And then make a blank line */
  9322.     if (++i > (cmd_rows - 3)) {
  9323.         if (!askmore())
  9324.           return(0);
  9325.         else
  9326.           i = 0;
  9327.     }
  9328.     hpos = 0;
  9329.     *lines = i;
  9330.     return(1);
  9331.     }
  9332.     y = (int)strlen(s) + 1;
  9333.     hpos += y;
  9334.     debug(F101,"prtopt hpos","",hpos);
  9335.     debug(F101,"prtopt cmd_cols","",cmd_cols);
  9336.  
  9337.     if (
  9338. #ifdef OS2
  9339.     hpos > ((cmd_cols > 40) ? (cmd_cols - 1) : 79)
  9340. #else /* OS2 */
  9341.     hpos > ((tt_cols > 40) ? (tt_cols - 1) : 79)
  9342. #endif /* OS2 */
  9343.     ) {
  9344.     printf("\n");
  9345.     if (++i > (cmd_rows - 3)) {
  9346.         if (!askmore())
  9347.           return(0);
  9348.         else
  9349.           i = 0;
  9350.     }
  9351.     printf(" %s",s);
  9352.     hpos = y;
  9353.     } else
  9354.       printf(" %s",s);
  9355.     *lines = i;
  9356.     return(1);
  9357. }
  9358.  
  9359. static VOID
  9360. initoptlist() {
  9361.     int i;
  9362.     if (noptlist > 0)
  9363.       return;
  9364.     for (i = 0; i < NOPTLIST; i++)
  9365.       optlist[i] = NULL;
  9366.  
  9367. #ifdef MAC
  9368. #ifdef MPW
  9369.     makestr(&(optlist[noptlist++]),"MPW");
  9370. #endif /* MPW */
  9371. #endif /* MAC */
  9372.  
  9373. #ifdef MAC
  9374. #ifdef THINK_C
  9375.     makestr(&(optlist[noptlist++]),"THINK_C");
  9376. #endif /* THINK_C */
  9377. #endif /* MAC */
  9378.  
  9379. #ifdef __386__
  9380.     makestr(&(optlist[noptlist++]),"__386__");
  9381. #endif /* __386__ */
  9382.  
  9383. /* Memory models... */
  9384.  
  9385. #ifdef __FLAT__
  9386.     makestr(&(optlist[noptlist++]),"__FLAT__");
  9387. #endif /* __FLAT__ */
  9388. #ifdef __SMALL__
  9389.     makestr(&(optlist[noptlist++]),"__SMALL__");
  9390. #endif /* __SMALL__ */
  9391. #ifdef __MEDIUM__
  9392.     makestr(&(optlist[noptlist++]),"__MEDIUM__");
  9393. #endif /* __MEDIUM__ */
  9394. #ifdef __COMPACT__
  9395.     makestr(&(optlist[noptlist++]),"__COMPACT__");
  9396. #endif /* __COMPACT__ */
  9397. #ifdef __LARGE__
  9398.     makestr(&(optlist[noptlist++]),"__LARGE__");
  9399. #endif /* __LARGE__ */
  9400.  
  9401. #ifdef DEBUG
  9402. #ifdef IFDEBUG
  9403.     makestr(&(optlist[noptlist++]),"IFDEBUG");
  9404. #else
  9405.     makestr(&(optlist[noptlist++]),"DEBUG");
  9406. #endif /* IFDEBUG */
  9407. #endif /* DEBUG */
  9408. #ifdef TLOG
  9409.     makestr(&(optlist[noptlist++]),"TLOG");
  9410. #endif /* TLOG */
  9411. #ifdef BIGBUFOK
  9412.     makestr(&(optlist[noptlist++]),"BIGBUFOK");
  9413. #endif /* BIGBUFOK */
  9414. #ifdef INPBUFSIZ
  9415.     sprintf(line,"INPBUFSIZ=%d",INPBUFSIZ); /* SAFE */
  9416.     makestr(&(optlist[noptlist++]),line);
  9417. #endif /* INPBUFSIZE */
  9418. #ifdef INBUFSIZE
  9419.     sprintf(line,"INBUFSIZE=%d",INBUFSIZE); /* SAFE */
  9420.     makestr(&(optlist[noptlist++]),line);
  9421. #endif /* INBUFSIZE */
  9422. #ifdef OBUFSIZE
  9423.     sprintf(line,"OBUFSIZE=%d",OBUFSIZE); /* SAFE */
  9424.     makestr(&(optlist[noptlist++]),line);
  9425. #endif /* OBUFSIZE */
  9426. #ifdef FD_SETSIZE
  9427.     sprintf(line,"FD_SETSIZE=%d",FD_SETSIZE); /* SAFE */
  9428.     makestr(&(optlist[noptlist++]),line);
  9429. #endif /* FD_SETSIZE */
  9430. #ifdef XFRCAN
  9431.     makestr(&(optlist[noptlist++]),"XFRCAN");
  9432. #endif /* XFRCAN */
  9433. #ifdef XPRINT
  9434.     makestr(&(optlist[noptlist++]),"XPRINT");
  9435. #endif /* XPRINT */
  9436. #ifdef PIPESEND
  9437.     makestr(&(optlist[noptlist++]),"PIPESEND");
  9438. #endif /* PIPESEND */
  9439. #ifdef CK_SPEED
  9440.     makestr(&(optlist[noptlist++]),"CK_SPEED");
  9441. #endif /* CK_SPEED */
  9442. #ifdef CK_FAST
  9443.     makestr(&(optlist[noptlist++]),"CK_FAST");
  9444. #endif /* CK_FAST */
  9445. #ifdef CK_APC
  9446.     makestr(&(optlist[noptlist++]),"CK_APC");
  9447. #endif /* CK_APC */
  9448. #ifdef CK_AUTODL
  9449.     makestr(&(optlist[noptlist++]),"CK_AUTODL");
  9450. #endif /* CK_AUTODL */
  9451. #ifdef CK_MKDIR
  9452.     makestr(&(optlist[noptlist++]),"CK_MKDIR");
  9453. #endif /* CK_MKDIR */
  9454. #ifdef NOMKDIR
  9455.     makestr(&(optlist[noptlist++]),"NOMKDIR");
  9456. #endif /* NOMKDIR */
  9457. #ifdef CK_LABELED
  9458.     makestr(&(optlist[noptlist++]),"CK_LABELED");
  9459. #endif /* CK_LABELED */
  9460. #ifdef NODIAL
  9461.     makestr(&(optlist[noptlist++]),"NODIAL");
  9462. #endif /* NODIAL */
  9463. #ifdef MINIDIAL
  9464.     makestr(&(optlist[noptlist++]),"MINIDIAL");
  9465. #endif /* MINIDIAL */
  9466. #ifdef WHATAMI
  9467.     makestr(&(optlist[noptlist++]),"WHATAMI");
  9468. #endif /* WHATAMI */
  9469. #ifdef DYNAMIC
  9470.     makestr(&(optlist[noptlist++]),"DYNAMIC");
  9471. #endif /* IFDEBUG */
  9472. #ifndef NOSPL
  9473.     sprintf(line,"CMDDEP=%d",CMDDEP);    /* SAFE */
  9474.     makestr(&(optlist[noptlist++]),line);
  9475. #endif /* NOSPL */
  9476.  
  9477. #ifdef MAXPATHLEN
  9478.     sprintf(line,"MAXPATHLEN=%d",MAXPATHLEN); /* SAFE */
  9479.     makestr(&(optlist[noptlist++]),line);
  9480. #endif /* MAXPATHLEN */
  9481.  
  9482. #ifdef DEVNAMLEN
  9483.     sprintf(line,"DEVNAMLEN=%d",DEVNAMLEN); /* SAFE */
  9484.     makestr(&(optlist[noptlist++]),line);
  9485. #endif /* DEVNAMLEN */
  9486.  
  9487. #ifdef NO_PARAM_H
  9488.     makestr(&(optlist[noptlist++]),"NO_PARAM_H");
  9489. #endif /* NO_PARAM_H */
  9490.  
  9491. #ifdef INCL_PARAM_H
  9492.     makestr(&(optlist[noptlist++]),"INCL_PARAM_H");
  9493. #endif /* INCL_PARAM_H */
  9494.  
  9495.     sprintf(line,"CKMAXPATH=%d",CKMAXPATH); /* SAFE */
  9496.     makestr(&(optlist[noptlist++]),line);
  9497.  
  9498.     sprintf(line,"CKMAXOPEN=%d",CKMAXOPEN); /* SAFE */
  9499.     makestr(&(optlist[noptlist++]),line);
  9500.  
  9501.     sprintf(line,"Z_MAXCHAN=%d",Z_MAXCHAN); /* SAFE */
  9502.     makestr(&(optlist[noptlist++]),line);
  9503.  
  9504. #ifdef OPEN_MAX
  9505.     sprintf(line,"OPEN_MAX=%d",OPEN_MAX); /* SAFE */
  9506.     makestr(&(optlist[noptlist++]),line);
  9507. #endif /* OPEN_MAX */
  9508.  
  9509. #ifdef _POSIX_OPEN_MAX
  9510.     sprintf(line,"_POSIX_OPEN_MAX=%d",_POSIX_OPEN_MAX);    /* SAFE */
  9511.     makestr(&(optlist[noptlist++]),line);
  9512. #endif /* _POSIX_OPEN_MAX */
  9513.  
  9514. #ifdef CKCHANNELIO
  9515.     {
  9516.     extern int z_maxchan;
  9517. #ifdef UNIX
  9518.     extern int ckmaxfiles;
  9519.     sprintf(line,"ckmaxfiles=%d",ckmaxfiles); /* SAFE */
  9520.     makestr(&(optlist[noptlist++]),line);
  9521. #endif /* UNIX */
  9522.     sprintf(line,"z_maxchan=%d",z_maxchan);    /* SAFE */
  9523.     makestr(&(optlist[noptlist++]),line);
  9524.     }
  9525. #endif /* CKCHANNELIO */
  9526.  
  9527. #ifdef FOPEN_MAX
  9528.     sprintf(line,"FOPEN_MAX=%d",FOPEN_MAX); /* SAFE */
  9529.     makestr(&(optlist[noptlist++]),line);
  9530. #endif /* FOPEN_MAX */
  9531.  
  9532. #ifdef MAXGETPATH
  9533.     sprintf(line,"MAXGETPATH=%d",MAXGETPATH); /* SAFE */
  9534.     makestr(&(optlist[noptlist++]),line);
  9535. #endif /* MAXGETPATH */
  9536.  
  9537. #ifdef CMDBL
  9538.     sprintf(line,"CMDBL=%d",CMDBL);    /* SAFE */
  9539.     makestr(&(optlist[noptlist++]),line);
  9540. #endif /* CMDBL */
  9541.  
  9542. #ifdef VNAML
  9543.     sprintf(line,"VNAML=%d",VNAML);    /* SAFE */
  9544.     makestr(&(optlist[noptlist++]),line);
  9545. #endif /* VNAML */
  9546.  
  9547. #ifdef ARRAYREFLEN
  9548.     sprintf(line,"ARRAYREFLEN=%d",ARRAYREFLEN);    /* SAFE */
  9549.     makestr(&(optlist[noptlist++]),line);
  9550. #endif /* ARRAYREFLEN */
  9551.  
  9552. #ifdef UIDBUFLEN
  9553.     sprintf(line,"UIDBUFLEN=%d",UIDBUFLEN); /* SAFE */
  9554.     makestr(&(optlist[noptlist++]),line);
  9555. #endif /* UIDBUFLEN */
  9556.  
  9557. #ifdef FORDEPTH
  9558.     sprintf(line,"FORDEPTH=%d",FORDEPTH); /* SAFE */
  9559.     makestr(&(optlist[noptlist++]),line);
  9560. #endif /* FORDEPTH */
  9561.  
  9562. #ifdef MAXTAKE
  9563.     sprintf(line,"MAXTAKE=%d",MAXTAKE);    /* SAFE */
  9564.     makestr(&(optlist[noptlist++]),line);
  9565. #endif /* MAXTAKE */
  9566.  
  9567. #ifdef MACLEVEL
  9568.     sprintf(line,"MACLEVEL=%d",MACLEVEL); /* SAFE */
  9569.     makestr(&(optlist[noptlist++]),line);
  9570. #endif /* MACLEVEL */
  9571.  
  9572. #ifdef MAC_MAX
  9573.     sprintf(line,"MAC_MAX=%d",MAC_MAX); /* SAFE */
  9574.     makestr(&(optlist[noptlist++]),line);
  9575. #endif /* MAC_MAX */
  9576.  
  9577. #ifdef MINPUTMAX
  9578.     sprintf(line,"MINPUTMAX=%d",MINPUTMAX); /* SAFE */
  9579.     makestr(&(optlist[noptlist++]),line);
  9580. #endif /* MINPUTMAX */
  9581.  
  9582. #ifdef MAXWLD
  9583.     sprintf(line,"MAXWLD=%d",MAXWLD); /* SAFE */
  9584.     makestr(&(optlist[noptlist++]),line);
  9585. #else
  9586. #ifdef OS2
  9587.     makestr(&(optlist[noptlist++]),"MAXWLD=unlimited");
  9588. #endif /* OS2 */
  9589. #endif /* MAXWLD */
  9590.  
  9591. #ifdef MSENDMAX
  9592.     sprintf(line,"MSENDMAX=%d",MSENDMAX); /* SAFE */
  9593.     makestr(&(optlist[noptlist++]),line);
  9594. #endif /* MSENDMAX */
  9595.  
  9596. #ifdef MAXDDIR
  9597.     sprintf(line,"MAXDDIR=%d",MAXDDIR); /* SAFE */
  9598.     makestr(&(optlist[noptlist++]),line);
  9599. #endif /* MAXDDIR */
  9600.  
  9601. #ifdef MAXDNUMS
  9602.     sprintf(line,"MAXDNUMS=%d",MAXDNUMS); /* SAFE */
  9603.     makestr(&(optlist[noptlist++]),line);
  9604. #endif /* MAXDNUMS */
  9605.  
  9606. #ifdef UNIX
  9607.     makestr(&(optlist[noptlist++]),"UNIX");
  9608. #endif /* UNIX */
  9609. #ifdef VMS
  9610.     makestr(&(optlist[noptlist++]),"VMS");
  9611. #ifdef __VMS_VER
  9612.     sprintf(line,"__VMS_VER=%d",__VMS_VER); /* SAFE */
  9613.     makestr(&(optlist[noptlist++]),line);
  9614. #endif /* __VMS_VER */
  9615. #ifdef VMSV70
  9616.     makestr(&(optlist[noptlist++]),"VMSV70");
  9617. #endif /* VMSV70 */
  9618. #endif /* VMS */
  9619. #ifdef OLD_VMS
  9620.     makestr(&(optlist[noptlist++]),"OLD_VMS");
  9621. #endif /* OLD_VMS */
  9622. #ifdef vms
  9623.     makestr(&(optlist[noptlist++]),"vms");
  9624. #endif /* vms */
  9625. #ifdef VMSSHARE
  9626.     makestr(&(optlist[noptlist++]),"VMSSHARE");
  9627. #endif /* VMSSHARE */
  9628. #ifdef NOVMSSHARE
  9629.     makestr(&(optlist[noptlist++]),"NOVMSSHARE");
  9630. #endif /* NOVMSSHARE */
  9631. #ifdef datageneral
  9632.     makestr(&(optlist[noptlist++]),"datageneral");
  9633. #endif /* datageneral */
  9634. #ifdef apollo
  9635.     makestr(&(optlist[noptlist++]),"apollo");
  9636. #endif /* apollo */
  9637. #ifdef aegis
  9638.     makestr(&(optlist[noptlist++]),"aegis");
  9639. #endif /* aegis */
  9640. #ifdef A986
  9641.     makestr(&(optlist[noptlist++]),"A986");
  9642. #endif /* A986 */
  9643. #ifdef AMIGA
  9644.     makestr(&(optlist[noptlist++]),"AMIGA");
  9645. #endif /* AMIGA */
  9646. #ifdef CONVEX9
  9647.     makestr(&(optlist[noptlist++]),"CONVEX9");
  9648. #endif /* CONVEX9 */
  9649. #ifdef CONVEX10
  9650.     makestr(&(optlist[noptlist++]),"CONVEX10");
  9651. #endif /* CONVEX9 */
  9652. #ifdef MAC
  9653.     makestr(&(optlist[noptlist++]),"MAC");
  9654. #endif /* MAC */
  9655. #ifdef AUX
  9656.     makestr(&(optlist[noptlist++]),"AUX");
  9657. #endif /* AUX */
  9658. #ifdef OS2
  9659.     makestr(&(optlist[noptlist++]),"OS2");
  9660. #ifdef NT
  9661.     makestr(&(optlist[noptlist++]),"NT");
  9662. #endif /* NT */
  9663. #endif /* OS2 */
  9664. #ifdef OSK
  9665.     makestr(&(optlist[noptlist++]),"OS9");
  9666. #endif /* OSK */
  9667. #ifdef MSDOS
  9668.     makestr(&(optlist[noptlist++]),"MSDOS");
  9669. #endif /* MSDOS */
  9670. #ifdef DIRENT
  9671.     makestr(&(optlist[noptlist++]),"DIRENT");
  9672. #endif /* DIRENT */
  9673. #ifdef SDIRENT
  9674.     makestr(&(optlist[noptlist++]),"SDIRENT");
  9675. #endif /* SDIRENT */
  9676. #ifdef NDIR
  9677.     makestr(&(optlist[noptlist++]),"NDIR");
  9678. #endif /* NDIR */
  9679. #ifdef XNDIR
  9680.     makestr(&(optlist[noptlist++]),"XNDIR");
  9681. #endif /* XNDIR */
  9682. #ifdef SAVEDUID
  9683.     makestr(&(optlist[noptlist++]),"SAVEDUID");
  9684. #endif /* SAVEDUID */
  9685. #ifdef RENAME
  9686.     makestr(&(optlist[noptlist++]),"RENAME");
  9687. #endif /* RENAME */
  9688. #ifdef CK_TMPDIR
  9689.     makestr(&(optlist[noptlist++]),"CK_TMPDIR");
  9690. #endif /* CK_TMPDIR */
  9691. #ifdef NOCCTRAP
  9692.     makestr(&(optlist[noptlist++]),"NOCCTRAP");
  9693. #endif /* NOCCTRAP */
  9694. #ifdef NOCOTFMC
  9695.     makestr(&(optlist[noptlist++]),"NOCOTFMC");
  9696. #endif /* NOCOTFMC */
  9697. #ifdef NOFRILLS
  9698.     makestr(&(optlist[noptlist++]),"NOFRILLS");
  9699. #endif /* NOFRILLS */
  9700. #ifdef PARSENSE
  9701.     makestr(&(optlist[noptlist++]),"PARSENSE");
  9702. #endif /* PARSENSE */
  9703. #ifdef TIMEH
  9704.     makestr(&(optlist[noptlist++]),"TIMEH");
  9705. #endif /* TIMEH */
  9706. #ifdef NOTIMEH
  9707.     makestr(&(optlist[noptlist++]),"TIMEH");
  9708. #endif /* NOTIMEH */
  9709.  
  9710. #ifdef SYSTIMEH
  9711.     makestr(&(optlist[noptlist++]),"SYSTIMEH");
  9712. #endif /* SYSTIMEH */
  9713. #ifdef NOSYSTIMEH
  9714.     makestr(&(optlist[noptlist++]),"SYSTIMEH");
  9715. #endif /* NOSYSTIMEH */
  9716.  
  9717. #ifdef SYSTIMEBH
  9718.     makestr(&(optlist[noptlist++]),"SYSTIMEBH");
  9719. #endif /* SYSTIMEBH */
  9720. #ifdef NOSYSTIMEBH
  9721.     makestr(&(optlist[noptlist++]),"SYSTIMEBH");
  9722. #endif /* NOSYSTIMEBH */
  9723. #ifdef UTIMEH
  9724.     makestr(&(optlist[noptlist++]),"UTIMEH");
  9725. #endif /* UTIMEH */
  9726. #ifdef SYSUTIMEH
  9727.     makestr(&(optlist[noptlist++]),"SYSUTIMEH");
  9728. #endif /* SYSUTIMEH */
  9729.  
  9730. #ifdef CK_NEED_SIG
  9731.     makestr(&(optlist[noptlist++]),"CK_NEED_SIG");
  9732. #endif /* CK_NEED_SIG */
  9733. #ifdef CK_TTYFD
  9734.     makestr(&(optlist[noptlist++]),"CK_TTYFD");
  9735. #endif /* CK_TTYFD */
  9736. #ifdef NETCONN
  9737.     makestr(&(optlist[noptlist++]),"NETCONN");
  9738. #endif /* NETCONN */
  9739. #ifdef TCPSOCKET
  9740.     makestr(&(optlist[noptlist++]),"TCPSOCKET");
  9741. #ifdef NOTCPOPTS
  9742.     makestr(&(optlist[noptlist++]),"NOTCPOPTS");
  9743. #endif /* NOTCPOPTS */
  9744. #ifdef CK_DNS_SRV
  9745.     makestr(&(optlist[noptlist++]),"CK_DNS_SRV");
  9746. #endif /* CK_DNS_SRV */
  9747. #ifdef NO_DNS_SRV
  9748.     makestr(&(optlist[noptlist++]),"NO_DNS_SRV");
  9749. #endif /* NO_DNS_SRV */
  9750. #ifdef CKGHNLHOST
  9751.     makestr(&(optlist[noptlist++]),"CKGHNLHOST");
  9752. #endif /* CKGHNLHOST */
  9753. #ifdef NOLISTEN
  9754.     makestr(&(optlist[noptlist++]),"NOLISTEN");
  9755. #endif /* NOLISTEN */
  9756. #ifdef SOL_SOCKET
  9757.     makestr(&(optlist[noptlist++]),"SOL_SOCKET");
  9758. #endif /* SOL_SOCKET */
  9759. #ifdef SO_OOBINLINE
  9760.     makestr(&(optlist[noptlist++]),"SO_OOBINLINE");
  9761. #endif /* SO_OOBINLNE */
  9762. #ifdef SO_DONTROUTE
  9763.     makestr(&(optlist[noptlist++]),"SO_DONTROUTE");
  9764. #endif /* SO_DONTROUTE */
  9765. #ifdef SO_KEEPALIVE
  9766.     makestr(&(optlist[noptlist++]),"SO_KEEPALIVE");
  9767. #endif /* SO_KEEPALIVE */
  9768. #ifdef SO_LINGER
  9769.     makestr(&(optlist[noptlist++]),"SO_LINGER");
  9770. #endif /* SO_LINGER */
  9771. #ifdef TCP_NODELAY
  9772.     makestr(&(optlist[noptlist++]),"TCP_NODELAY");
  9773. #endif /* TCP_NODELAY */
  9774. #ifdef SO_SNDBUF
  9775.     makestr(&(optlist[noptlist++]),"SO_SNDBUF");
  9776. #endif /* SO_SNDBUF */
  9777. #ifdef SO_RCVBUF
  9778.     makestr(&(optlist[noptlist++]),"SO_RCVBUF");
  9779. #endif /* SO_RCVBUF */
  9780. #ifdef h_addr
  9781.     makestr(&(optlist[noptlist++]),"h_addr");
  9782. #endif /* h_addr */
  9783. #ifdef HADDRLIST
  9784.     makestr(&(optlist[noptlist++]),"HADDRLIST");
  9785. #endif /* HADDRLIST */
  9786. #ifdef CK_SOCKS
  9787.     makestr(&(optlist[noptlist++]),"CK_SOCKS");
  9788. #ifdef CK_SOCKS5
  9789.     makestr(&(optlist[noptlist++]),"CK_SOCKS5");
  9790. #endif /* CK_SOCKS5 */
  9791. #ifdef CK_SOCKS_NS
  9792.     makestr(&(optlist[noptlist++]),"CK_SOCKS_NS");
  9793. #endif /* CK_SOCKS_NS */
  9794. #endif /* CK_SOCKS */
  9795. #ifdef RLOGCODE
  9796.     makestr(&(optlist[noptlist++]),"RLOGCODE");
  9797. #endif /* RLOGCODE */
  9798. #ifdef NETCMD
  9799.     makestr(&(optlist[noptlist++]),"NETCMD");
  9800. #endif /* NETCMD */
  9801. #ifdef NONETCMD
  9802.     makestr(&(optlist[noptlist++]),"NONETCMD");
  9803. #endif /* NONETCMD */
  9804. #ifdef NETPTY
  9805.     makestr(&(optlist[noptlist++]),"NETPTY");
  9806. #endif /* NETPTY */
  9807. #ifdef CK_ENVIRONMENT
  9808.     makestr(&(optlist[noptlist++]),"CK_ENVIRONMENT");
  9809. #endif /* CK_ENVIRONMENT */
  9810. #endif /* TCPSOCKET */
  9811. #ifdef TNCODE
  9812.     makestr(&(optlist[noptlist++]),"TNCODE");
  9813. #endif /* TNCODE */
  9814. #ifdef CK_FORWARD_X
  9815.     makestr(&(optlist[noptlist++]),"CK_FORWARD_X");
  9816. #endif /* CK_FORWARD_X */
  9817. #ifdef TN_COMPORT
  9818.     makestr(&(optlist[noptlist++]),"TN_COMPORT");
  9819. #endif /* TN_COMPORT */
  9820. #ifdef MULTINET
  9821.     makestr(&(optlist[noptlist++]),"MULTINET");
  9822. #endif /* MULTINET */
  9823. #ifdef DEC_TCPIP
  9824.     makestr(&(optlist[noptlist++]),"DEC_TCPIP");
  9825. #endif /* DEC_TCPIP */
  9826. #ifdef TCPWARE
  9827.     makestr(&(optlist[noptlist++]),"TCPWARE");
  9828. #endif /* TCPWARE */
  9829. #ifdef UCX50
  9830.     makestr(&(optlist[noptlist++]),"UCX50");
  9831. #endif /* UCX50 */
  9832. #ifdef TTLEBUF
  9833.     makestr(&(optlist[noptlist++]),"TTLEBUF");
  9834. #endif /* TTLEBUF */
  9835. #ifdef NETLEBUF
  9836.     makestr(&(optlist[noptlist++]),"NETLEBUF");
  9837. #endif /* NETLEBUF */
  9838. #ifdef IKS_OPTION
  9839.     makestr(&(optlist[noptlist++]),"IKS_OPTION");
  9840. #endif /* IKS_OPTION */
  9841. #ifdef IKSDB
  9842.     makestr(&(optlist[noptlist++]),"IKSDB");
  9843. #endif /* IKSDB */
  9844. #ifdef IKSDCONF
  9845.     makestr(&(optlist[noptlist++]),"IKSDCONF");
  9846. #endif /* IKSDCONF */
  9847. #ifdef CK_LOGIN
  9848.     makestr(&(optlist[noptlist++]),"CK_LOGIN");
  9849. #endif /* CK_LOGIN */
  9850. #ifdef CK_PAM
  9851.     makestr(&(optlist[noptlist++]),"CK_PAM");
  9852. #endif /* CK_PAM */
  9853. #ifdef CK_SHADOW
  9854.     makestr(&(optlist[noptlist++]),"CK_SHADOW");
  9855. #endif /* CK_SHADOW */
  9856. #ifdef CONGSPD
  9857.     makestr(&(optlist[noptlist++]),"CONGSPD");
  9858. #endif /* CONGSPD */
  9859. #ifdef SUNX25
  9860.     makestr(&(optlist[noptlist++]),"SUNX25");
  9861. #endif /* SUNX25 */
  9862. #ifdef IBMX25
  9863.     makestr(&(optlist[noptlist++]),"IBMX25");
  9864. #endif /* IBMX25 */
  9865. #ifdef HPX25
  9866.     makestr(&(optlist[noptlist++]),"HPX25");
  9867. #endif /* HPX25 */
  9868. #ifdef DECNET
  9869.     makestr(&(optlist[noptlist++]),"DECNET");
  9870. #endif /* DECNET */
  9871. #ifdef SUPERLAT
  9872.     makestr(&(optlist[noptlist++]),"SUPERLAT");
  9873. #endif /* SUPERLAT */
  9874. #ifdef NPIPE
  9875.     makestr(&(optlist[noptlist++]),"NPIPE");
  9876. #endif /* NPIPE */
  9877. #ifdef CK_NETBIOS
  9878.     makestr(&(optlist[noptlist++]),"CK_NETBIOS");
  9879. #endif /* CK_NETBIOS */
  9880. #ifdef ATT7300
  9881.     makestr(&(optlist[noptlist++]),"ATT7300");
  9882. #endif /* ATT7300 */
  9883. #ifdef ATT6300
  9884.     makestr(&(optlist[noptlist++]),"ATT6300");
  9885. #endif /* ATT6300 */
  9886. #ifdef HDBUUCP
  9887.     makestr(&(optlist[noptlist++]),"HDBUUCP");
  9888. #endif /* HDBUUCP */
  9889. #ifdef USETTYLOCK
  9890.     makestr(&(optlist[noptlist++]),"USETTYLOCK");
  9891. #endif /* USETTYLOCK */
  9892. #ifdef NOUUCP
  9893.     makestr(&(optlist[noptlist++]),"NOUUCP");
  9894. #endif /* NOUUCP */
  9895. #ifdef LONGFN
  9896.     makestr(&(optlist[noptlist++]),"LONGFN");
  9897. #endif /* LONGFN */
  9898. #ifdef RDCHK
  9899.     makestr(&(optlist[noptlist++]),"RDCHK");
  9900. #endif /* RDCHK */
  9901. #ifdef SELECT
  9902.     makestr(&(optlist[noptlist++]),"SELECT");
  9903. #endif /* SELECT */
  9904. #ifdef USLEEP
  9905.     makestr(&(optlist[noptlist++]),"USLEEP");
  9906. #endif /* USLEEP */
  9907. #ifdef NAP
  9908.     makestr(&(optlist[noptlist++]),"NAP");
  9909. #endif /* NAP */
  9910. #ifdef NAPHACK
  9911.     makestr(&(optlist[noptlist++]),"NAPHACK");
  9912. #endif /* NAPHACK */
  9913. #ifdef CK_POLL
  9914.     makestr(&(optlist[noptlist++]),"CK_POLL");
  9915. #endif /* CK_POLL */
  9916. #ifdef NOIEXTEN
  9917.     makestr(&(optlist[noptlist++]),"NOIEXTEN");
  9918. #endif /* NOIEXTEN */
  9919. #ifdef EXCELAN
  9920.     makestr(&(optlist[noptlist++]),"EXCELAN");
  9921. #endif /* EXCELAN */
  9922. #ifdef INTERLAN
  9923.     makestr(&(optlist[noptlist++]),"INTERLAN");
  9924. #endif /* INTERLAN */
  9925. #ifdef NOFILEH
  9926.     makestr(&(optlist[noptlist++]),"NOFILEH");
  9927. #endif /* NOFILEH */
  9928. #ifdef NOSYSIOCTLH
  9929.     makestr(&(optlist[noptlist++]),"NOSYSIOCTLH");
  9930. #endif /* NOSYSIOCTLH */
  9931. #ifdef DCLPOPEN
  9932.     makestr(&(optlist[noptlist++]),"DCLPOPEN");
  9933. #endif /* DCLPOPEN */
  9934. #ifdef NOSETBUF
  9935.     makestr(&(optlist[noptlist++]),"NOSETBUF");
  9936. #endif /* NOSETBUF */
  9937. #ifdef NOXFER
  9938.     makestr(&(optlist[noptlist++]),"NOXFER");
  9939. #endif /* NOXFER */
  9940. #ifdef NOCURSES
  9941.     makestr(&(optlist[noptlist++]),"NOCURSES");
  9942. #endif /* NOCURSES */
  9943. #ifdef NOSERVER
  9944.     makestr(&(optlist[noptlist++]),"NOSERVER");
  9945. #endif /* NOSERVER */
  9946. #ifdef NOPATTERNS
  9947.     makestr(&(optlist[noptlist++]),"NOPATTERNS");
  9948. #else
  9949. #ifdef PATTERNS
  9950.     makestr(&(optlist[noptlist++]),"PATTERNS");
  9951. #endif /* PATTERNS */
  9952. #endif /* NOPATTERNS */
  9953. #ifdef NOCKEXEC
  9954.     makestr(&(optlist[noptlist++]),"NOCKEXEC");
  9955. #else
  9956. #ifdef CKEXEC
  9957.     makestr(&(optlist[noptlist++]),"CKEXEC");
  9958. #endif /* CKEXEC */
  9959. #endif /* NOCKEXEC */
  9960. #ifdef NOAUTODL
  9961.     makestr(&(optlist[noptlist++]),"NOAUTODL");
  9962. #endif /* NOAUTODL */
  9963. #ifdef NOMSEND
  9964.     makestr(&(optlist[noptlist++]),"NOMSEND");
  9965. #endif /* NOMSEND */
  9966. #ifdef NOFDZERO
  9967.     makestr(&(optlist[noptlist++]),"NOFDZERO");
  9968. #endif /* NOFDZERO */
  9969. #ifdef NOPOPEN
  9970.     makestr(&(optlist[noptlist++]),"NOPOPEN");
  9971. #endif /* NOPOPEN */
  9972. #ifdef NOPARTIAL
  9973.     makestr(&(optlist[noptlist++]),"NOPARTIAL");
  9974. #endif /* NOPARTIAL */
  9975. #ifdef NOKVERBS
  9976.     makestr(&(optlist[noptlist++]),"NOKVERBS");
  9977. #endif /* NOKVERBS */
  9978. #ifdef NOSETREU
  9979.     makestr(&(optlist[noptlist++]),"NOSETREU");
  9980. #endif /* NOSETREU */
  9981. #ifdef LCKDIR
  9982.     makestr(&(optlist[noptlist++]),"LCKDIR");
  9983. #endif /* LCKDIR */
  9984. #ifdef ACUCNTRL
  9985.     makestr(&(optlist[noptlist++]),"ACUCNTRL");
  9986. #endif /* ACUCNTRL */
  9987. #ifdef BSD4
  9988.     makestr(&(optlist[noptlist++]),"BSD4");
  9989. #endif /* BSD4 */
  9990. #ifdef BSD44
  9991.     makestr(&(optlist[noptlist++]),"BSD44");
  9992. #endif /* BSD44 */
  9993. #ifdef BSD41
  9994.     makestr(&(optlist[noptlist++]),"BSD41");
  9995. #endif /* BSD41 */
  9996. #ifdef BSD43
  9997.     makestr(&(optlist[noptlist++]),"BSD43");
  9998. #endif /* BSD43 */
  9999. #ifdef BSD29
  10000.     makestr(&(optlist[noptlist++]),"BSD29");
  10001. #endif /* BSD29 */
  10002. #ifdef BSDI
  10003.     makestr(&(optlist[noptlist++]),"BSDI");
  10004. #endif /* BSDI */
  10005. #ifdef __bsdi__
  10006.     makestr(&(optlist[noptlist++]),"__bsdi__");
  10007. #endif /* __bsdi__ */
  10008. #ifdef __NetBSD__
  10009.     makestr(&(optlist[noptlist++]),"__NetBSD__");
  10010. #endif /* __NetBSD__ */
  10011. #ifdef __OpenBSD__
  10012.     makestr(&(optlist[noptlist++]),"__OpenBSD__");
  10013. #endif /* __OpenBSD__ */
  10014. #ifdef __FreeBSD__
  10015.     makestr(&(optlist[noptlist++]),"__FreeBSD__");
  10016. #endif /* __FreeBSD__ */
  10017. #ifdef __linux__
  10018.     makestr(&(optlist[noptlist++]),"__linux__");
  10019. #endif /* __linux__ */
  10020. #ifdef LINUX_HI_SPD
  10021.     makestr(&(optlist[noptlist++]),"LINUX_HI_SPD");
  10022. #endif /* LINUX_HI_SPD */
  10023. #ifdef LYNXOS
  10024.     makestr(&(optlist[noptlist++]),"LYNXOS");
  10025. #endif /* LYNXOS */
  10026. #ifdef V7
  10027.     makestr(&(optlist[noptlist++]),"V7");
  10028. #endif /* V7 */
  10029. #ifdef AIX370
  10030.     makestr(&(optlist[noptlist++]),"AIX370");
  10031. #endif /* AIX370 */
  10032. #ifdef RTAIX
  10033.     makestr(&(optlist[noptlist++]),"RTAIX");
  10034. #endif /* RTAIX */
  10035. #ifdef HPUX
  10036.     makestr(&(optlist[noptlist++]),"HPUX");
  10037. #endif /* HPUX */
  10038. #ifdef HPUXPRE65
  10039.     makestr(&(optlist[noptlist++]),"HPUXPRE65");
  10040. #endif /* HPUXPRE65 */
  10041. #ifdef DGUX
  10042.     makestr(&(optlist[noptlist++]),"DGUX");
  10043. #endif /* DGUX */
  10044. #ifdef DGUX430
  10045.     makestr(&(optlist[noptlist++]),"DGUX430");
  10046. #endif /* DGUX430 */
  10047. #ifdef DGUX540
  10048.     makestr(&(optlist[noptlist++]),"DGUX540");
  10049. #endif /* DGUX540 */
  10050. #ifdef DGUX543
  10051.     makestr(&(optlist[noptlist++]),"DGUX543");
  10052. #endif /* DGUX543 */
  10053. #ifdef DGUX54410
  10054.     makestr(&(optlist[noptlist++]),"DGUX54410");
  10055. #endif /* DGUX54410 */
  10056. #ifdef DGUX54411
  10057.     makestr(&(optlist[noptlist++]),"DGUX54411");
  10058. #endif /* DGUX54411 */
  10059. #ifdef sony_news
  10060.     makestr(&(optlist[noptlist++]),"sony_news");
  10061. #endif /* sony_news */
  10062. #ifdef CIE
  10063.     makestr(&(optlist[noptlist++]),"CIE");
  10064. #endif /* CIE */
  10065. #ifdef XENIX
  10066.     makestr(&(optlist[noptlist++]),"XENIX");
  10067. #endif /* XENIX */
  10068. #ifdef SCO_XENIX
  10069.     makestr(&(optlist[noptlist++]),"SCO_XENIX");
  10070. #endif /* SCO_XENIX */
  10071. #ifdef ISIII
  10072.     makestr(&(optlist[noptlist++]),"ISIII");
  10073. #endif /* ISIII */
  10074. #ifdef I386IX
  10075.     makestr(&(optlist[noptlist++]),"I386IX");
  10076. #endif /* I386IX */
  10077. #ifdef RTU
  10078.     makestr(&(optlist[noptlist++]),"RTU");
  10079. #endif /* RTU */
  10080. #ifdef PROVX1
  10081.     makestr(&(optlist[noptlist++]),"PROVX1");
  10082. #endif /* PROVX1 */
  10083. #ifdef PYRAMID
  10084.     makestr(&(optlist[noptlist++]),"PYRAMID");
  10085. #endif /* PYRAMID */
  10086. #ifdef TOWER1
  10087.     makestr(&(optlist[noptlist++]),"TOWER1");
  10088. #endif /* TOWER1 */
  10089. #ifdef UTEK
  10090.     makestr(&(optlist[noptlist++]),"UTEK");
  10091. #endif /* UTEK */
  10092. #ifdef ZILOG
  10093.     makestr(&(optlist[noptlist++]),"ZILOG");
  10094. #endif /* ZILOG */
  10095. #ifdef TRS16
  10096.     makestr(&(optlist[noptlist++]),"TRS16");
  10097. #endif /* TRS16 */
  10098. #ifdef MINIX
  10099.     makestr(&(optlist[noptlist++]),"MINIX");
  10100. #endif /* MINIX */
  10101. #ifdef C70
  10102.     makestr(&(optlist[noptlist++]),"C70");
  10103. #endif /* C70 */
  10104. #ifdef AIXPS2
  10105.     makestr(&(optlist[noptlist++]),"AIXPS2");
  10106. #endif /* AIXPS2 */
  10107. #ifdef AIXRS
  10108.     makestr(&(optlist[noptlist++]),"AIXRS");
  10109. #endif /* AIXRS */
  10110. #ifdef UTSV
  10111.     makestr(&(optlist[noptlist++]),"UTSV");
  10112. #endif /* UTSV */
  10113. #ifdef ATTSV
  10114.     makestr(&(optlist[noptlist++]),"ATTSV");
  10115. #endif /* ATTSV */
  10116. #ifdef SVR3
  10117.     makestr(&(optlist[noptlist++]),"SVR3");
  10118. #endif /* SVR3 */
  10119. #ifdef SVR4
  10120.     makestr(&(optlist[noptlist++]),"SVR4");
  10121. #endif /* SVR4 */
  10122. #ifdef DELL_SVR4
  10123.     makestr(&(optlist[noptlist++]),"DELL_SVR4");
  10124. #endif /* DELL_SVR4 */
  10125. #ifdef ICL_SVR4
  10126.     makestr(&(optlist[noptlist++]),"ICL_SVR4");
  10127. #endif /* ICL_SVR4 */
  10128. #ifdef OSF
  10129.     makestr(&(optlist[noptlist++]),"OSF");
  10130. #endif /* OSF */
  10131. #ifdef OSF1
  10132.     makestr(&(optlist[noptlist++]),"OSF1");
  10133. #endif /* OSF1 */
  10134. #ifdef __OSF
  10135.     makestr(&(optlist[noptlist++]),"__OSF");
  10136. #endif /* __OSF */
  10137. #ifdef __OSF__
  10138.     makestr(&(optlist[noptlist++]),"__OSF__");
  10139. #endif /* __OSF__ */
  10140. #ifdef __osf__
  10141.     makestr(&(optlist[noptlist++]),"__osf__");
  10142. #endif /* __osf__ */
  10143. #ifdef __OSF1
  10144.     makestr(&(optlist[noptlist++]),"__OSF1");
  10145. #endif /* __OSF1 */
  10146. #ifdef __OSF1__
  10147.     makestr(&(optlist[noptlist++]),"__OSF1__");
  10148. #endif /* __OSF1__ */
  10149. #ifdef PTX
  10150.     makestr(&(optlist[noptlist++]),"PTX");
  10151. #endif /* PTX */
  10152. #ifdef POSIX
  10153.     makestr(&(optlist[noptlist++]),"POSIX");
  10154. #endif /* POSIX */
  10155. #ifdef BSD44ORPOSIX
  10156.     makestr(&(optlist[noptlist++]),"BSD44ORPOSIX");
  10157. #endif /* BSD44ORPOSIX */
  10158. #ifdef SVORPOSIX
  10159.     makestr(&(optlist[noptlist++]),"SVORPOSIX");
  10160. #endif /* SVORPOSIX */
  10161. #ifdef SVR4ORPOSIX
  10162.     makestr(&(optlist[noptlist++]),"SVR4ORPOSIX");
  10163. #endif /* SVR4ORPOSIX */
  10164. #ifdef OS2ORVMS
  10165.     makestr(&(optlist[noptlist++]),"OS2ORVMS");
  10166. #endif /* OS2ORVMS */
  10167. #ifdef OS2ORUNIX
  10168.     makestr(&(optlist[noptlist++]),"OS2ORUNIX");
  10169. #endif /* OS2ORUNIX */
  10170. #ifdef VMSORUNIX
  10171.     makestr(&(optlist[noptlist++]),"VMSORUNIX");
  10172. #endif /* VMSORUNIX */
  10173. #ifdef _POSIX_SOURCE
  10174.     makestr(&(optlist[noptlist++]),"_POSIX_SOURCE");
  10175. #endif /* _POSIX_SOURCE */
  10176. #ifdef _XOPEN_SOURCE
  10177.     makestr(&(optlist[noptlist++]),"_XOPEN_SOURCE");
  10178. #endif
  10179. #ifdef _ALL_SOURCE
  10180.     makestr(&(optlist[noptlist++]),"_ALL_SOURCE");
  10181. #endif
  10182. #ifdef _SVID3
  10183.     makestr(&(optlist[noptlist++]),"_SVID3");
  10184. #endif /* _SVID3 */
  10185. #ifdef Plan9
  10186.     makestr(&(optlist[noptlist++]),"Plan9");
  10187. #endif /* Plan9 */
  10188. #ifdef SOLARIS
  10189.     makestr(&(optlist[noptlist++]),"SOLARIS");
  10190. #ifdef SOLARIS24
  10191.     makestr(&(optlist[noptlist++]),"SOLARIS24");
  10192. #endif /* SOLARIS24 */
  10193. #ifdef SOLARIS25
  10194.     makestr(&(optlist[noptlist++]),"SOLARIS25");
  10195. #endif /* SOLARIS25 */
  10196. #ifdef SOLARIS26
  10197.     makestr(&(optlist[noptlist++]),"SOLARIS26");
  10198. #endif /* SOLARIS26 */
  10199. #ifdef SOLARIS7
  10200.     makestr(&(optlist[noptlist++]),"SOLARIS7");
  10201. #endif /* SOLARIS7 */
  10202. #ifdef SOLARIS8
  10203.     makestr(&(optlist[noptlist++]),"SOLARIS8");
  10204. #endif /* SOLARIS8 */
  10205. #endif /* SOLARIS */
  10206.  
  10207. #ifdef SUNOS4
  10208.     makestr(&(optlist[noptlist++]),"SUNOS4");
  10209. #endif /* SUNOS4 */
  10210. #ifdef SUN4S5
  10211.     makestr(&(optlist[noptlist++]),"SUN4S5");
  10212. #endif /* SUN4S5 */
  10213. #ifdef IRIX
  10214.     makestr(&(optlist[noptlist++]),"IRIX");
  10215. #endif /* IRIX */
  10216. #ifdef ENCORE
  10217.     makestr(&(optlist[noptlist++]),"ENCORE");
  10218. #endif /* ENCORE */
  10219. #ifdef ultrix
  10220.     makestr(&(optlist[noptlist++]),"ultrix");
  10221. #endif
  10222. #ifdef sxaE50
  10223.     makestr(&(optlist[noptlist++]),"sxaE50");
  10224. #endif
  10225. #ifdef mips
  10226.     makestr(&(optlist[noptlist++]),"mips");
  10227. #endif
  10228. #ifdef MIPS
  10229.     makestr(&(optlist[noptlist++]),"MIPS");
  10230. #endif
  10231. #ifdef vax
  10232.     makestr(&(optlist[noptlist++]),"vax");
  10233. #endif
  10234. #ifdef VAX
  10235.     makestr(&(optlist[noptlist++]),"VAX");
  10236. #endif
  10237. #ifdef alpha
  10238.     makestr(&(optlist[noptlist++]),"alpha");
  10239. #endif
  10240. #ifdef ALPHA
  10241.     makestr(&(optlist[noptlist++]),"ALPHA");
  10242. #endif
  10243. #ifdef __ALPHA
  10244.     makestr(&(optlist[noptlist++]),"__ALPHA");
  10245. #endif
  10246. #ifdef __alpha
  10247.     makestr(&(optlist[noptlist++]),"__alpha");
  10248. #endif
  10249. #ifdef __AXP
  10250.     makestr(&(optlist[noptlist++]),"__AXP");
  10251. #endif
  10252. #ifdef AXP
  10253.     makestr(&(optlist[noptlist++]),"AXP");
  10254. #endif
  10255. #ifdef axp
  10256.     makestr(&(optlist[noptlist++]),"axp");
  10257. #endif
  10258. #ifdef __ALPHA__
  10259.     makestr(&(optlist[noptlist++]),"__ALPHA__");
  10260. #endif
  10261. #ifdef __alpha__
  10262.     makestr(&(optlist[noptlist++]),"__alpha__");
  10263. #endif
  10264. #ifdef sun
  10265.     makestr(&(optlist[noptlist++]),"sun");
  10266. #endif
  10267. #ifdef sun3
  10268.     makestr(&(optlist[noptlist++]),"sun3");
  10269. #endif
  10270. #ifdef sun386
  10271.     makestr(&(optlist[noptlist++]),"sun386");
  10272. #endif
  10273. #ifdef _SUN
  10274.     makestr(&(optlist[noptlist++]),"_SUN");
  10275. #endif
  10276. #ifdef sun4
  10277.     makestr(&(optlist[noptlist++]),"sun4");
  10278. #endif
  10279. #ifdef sparc
  10280.     makestr(&(optlist[noptlist++]),"sparc");
  10281. #endif
  10282. #ifdef _CRAY
  10283.     makestr(&(optlist[noptlist++]),"_CRAY");
  10284. #endif /* _CRAY */
  10285. #ifdef NEXT33
  10286.     makestr(&(optlist[noptlist++]),"NEXT33");
  10287. #endif
  10288. #ifdef NEXT
  10289.     makestr(&(optlist[noptlist++]),"NEXT");
  10290. #endif
  10291. #ifdef NeXT
  10292.     makestr(&(optlist[noptlist++]),"NeXT");
  10293. #endif
  10294. #ifdef MACH
  10295.     makestr(&(optlist[noptlist++]),"MACH");
  10296. #endif
  10297. #ifdef sgi
  10298.     makestr(&(optlist[noptlist++]),"sgi");
  10299. #endif
  10300. #ifdef M_SYS5
  10301.     makestr(&(optlist[noptlist++]),"M_SYS5");
  10302. #endif
  10303. #ifdef __SYSTEM_FIVE
  10304.     makestr(&(optlist[noptlist++]),"__SYSTEM_FIVE");
  10305. #endif
  10306. #ifdef sysV
  10307.     makestr(&(optlist[noptlist++]),"sysV");
  10308. #endif
  10309. #ifdef M_XENIX                /* SCO Xenix V and UNIX/386 */
  10310.     makestr(&(optlist[noptlist++]),"M_XENIX");
  10311. #endif
  10312. #ifdef M_UNIX                /* SCO UNIX */
  10313.     makestr(&(optlist[noptlist++]),"M_UNIX");
  10314. #endif
  10315. #ifdef _M_UNIX                /* SCO UNIX 3.2v4 = ODT 2.0 */
  10316.     makestr(&(optlist[noptlist++]),"_M_UNIX");
  10317. #endif
  10318. #ifdef CK_SCOV5
  10319.     makestr(&(optlist[noptlist++]),"CK_SCOV5");
  10320. #endif
  10321. #ifdef SCO_OSR504
  10322.     makestr(&(optlist[noptlist++]),"SCO_OSR504");
  10323. #endif
  10324. #ifdef M_IA64
  10325.     makestr(&(optlist[noptlist++]),"M_IA64");
  10326. #endif
  10327. #ifdef _M_IA64
  10328.     makestr(&(optlist[noptlist++]),"_M_IA64");
  10329. #endif
  10330. #ifdef ia64
  10331.     makestr(&(optlist[noptlist++]),"ia64");
  10332. #endif
  10333. #ifdef _ia64
  10334.     makestr(&(optlist[noptlist++]),"_ia64");
  10335. #endif
  10336. #ifdef _ia64_
  10337.     makestr(&(optlist[noptlist++]),"_ia64_");
  10338. #endif
  10339. #ifdef M_I686
  10340.     makestr(&(optlist[noptlist++]),"M_I686");
  10341. #endif
  10342. #ifdef _M_I686
  10343.     makestr(&(optlist[noptlist++]),"_M_I686");
  10344. #endif
  10345. #ifdef i686
  10346.     makestr(&(optlist[noptlist++]),"i686");
  10347. #endif
  10348. #ifdef M_I586
  10349.     makestr(&(optlist[noptlist++]),"M_I586");
  10350. #endif
  10351. #ifdef _M_I586
  10352.     makestr(&(optlist[noptlist++]),"_M_I586");
  10353. #endif
  10354. #ifdef i586
  10355.     makestr(&(optlist[noptlist++]),"i586");
  10356. #endif
  10357. #ifdef M_I486
  10358.     makestr(&(optlist[noptlist++]),"M_I486");
  10359. #endif
  10360. #ifdef _M_I486
  10361.     makestr(&(optlist[noptlist++]),"_M_I486");
  10362. #endif
  10363. #ifdef i486
  10364.     makestr(&(optlist[noptlist++]),"i486");
  10365. #endif
  10366. #ifdef M_I386
  10367.     makestr(&(optlist[noptlist++]),"M_I386");
  10368. #endif
  10369. #ifdef _M_I386
  10370.     makestr(&(optlist[noptlist++]),"_M_I386");
  10371. #endif
  10372. #ifdef i386
  10373.     makestr(&(optlist[noptlist++]),"i386");
  10374. #endif
  10375. #ifdef i286
  10376.     makestr(&(optlist[noptlist++]),"i286");
  10377. #endif
  10378. #ifdef M_I286
  10379.     makestr(&(optlist[noptlist++]),"M_I286");
  10380. #endif
  10381. #ifdef mc68000
  10382.     makestr(&(optlist[noptlist++]),"mc68000");
  10383. #endif
  10384. #ifdef mc68010
  10385.     makestr(&(optlist[noptlist++]),"mc68010");
  10386. #endif
  10387. #ifdef mc68020
  10388.     makestr(&(optlist[noptlist++]),"mc68020");
  10389. #endif
  10390. #ifdef mc68030
  10391.     makestr(&(optlist[noptlist++]),"mc68030");
  10392. #endif
  10393. #ifdef mc68040
  10394.     makestr(&(optlist[noptlist++]),"mc68040");
  10395. #endif
  10396. #ifdef M_68000
  10397.     makestr(&(optlist[noptlist++]),"M_68000");
  10398. #endif
  10399. #ifdef M_68010
  10400.     makestr(&(optlist[noptlist++]),"M_68010");
  10401. #endif
  10402. #ifdef M_68020
  10403.     makestr(&(optlist[noptlist++]),"M_68020");
  10404. #endif
  10405. #ifdef M_68030
  10406.     makestr(&(optlist[noptlist++]),"M_68030");
  10407. #endif
  10408. #ifdef M_68040
  10409.     makestr(&(optlist[noptlist++]),"M_68040");
  10410. #endif
  10411. #ifdef m68k
  10412.     makestr(&(optlist[noptlist++]),"m68k");
  10413. #endif
  10414. #ifdef m88k
  10415.     makestr(&(optlist[noptlist++]),"m88k");
  10416. #endif
  10417. #ifdef pdp11
  10418.     makestr(&(optlist[noptlist++]),"pdp11");
  10419. #endif
  10420. #ifdef iAPX
  10421.     makestr(&(optlist[noptlist++]),"iAPX");
  10422. #endif
  10423. #ifdef hpux
  10424.     makestr(&(optlist[noptlist++]),"hpux");
  10425. #endif
  10426. #ifdef __hpux
  10427.     makestr(&(optlist[noptlist++]),"__hpux");
  10428. #endif
  10429. #ifdef __hp9000s800
  10430.     makestr(&(optlist[noptlist++]),"__hp9000s800");
  10431. #endif
  10432. #ifdef __hp9000s700
  10433.     makestr(&(optlist[noptlist++]),"__hp9000s700");
  10434. #endif
  10435. #ifdef __hp9000s500
  10436.     makestr(&(optlist[noptlist++]),"__hp9000s500");
  10437. #endif
  10438. #ifdef __hp9000s300
  10439.     makestr(&(optlist[noptlist++]),"__hp9000s300");
  10440. #endif
  10441. #ifdef __hp9000s200
  10442.     makestr(&(optlist[noptlist++]),"__hp9000s200");
  10443. #endif
  10444. #ifdef AIX
  10445.     makestr(&(optlist[noptlist++]),"AIX");
  10446. #endif
  10447. #ifdef _AIXFS
  10448.     makestr(&(optlist[noptlist++]),"_AIXFS");
  10449. #endif
  10450. #ifdef u370
  10451.     makestr(&(optlist[noptlist++]),"u370");
  10452. #endif
  10453. #ifdef u3b
  10454.     makestr(&(optlist[noptlist++]),"u3b");
  10455. #endif
  10456. #ifdef u3b2
  10457.     makestr(&(optlist[noptlist++]),"u3b2");
  10458. #endif
  10459. #ifdef multimax
  10460.     makestr(&(optlist[noptlist++]),"multimax");
  10461. #endif
  10462. #ifdef balance
  10463.     makestr(&(optlist[noptlist++]),"balance");
  10464. #endif
  10465. #ifdef ibmrt
  10466.     makestr(&(optlist[noptlist++]),"ibmrt");
  10467. #endif
  10468. #ifdef _IBMRT
  10469.     makestr(&(optlist[noptlist++]),"_IBMRT");
  10470. #endif
  10471. #ifdef ibmrs6000
  10472.     makestr(&(optlist[noptlist++]),"ibmrs6000");
  10473. #endif
  10474. #ifdef _AIX
  10475.     makestr(&(optlist[noptlist++]),"_AIX");
  10476. #endif /* _AIX */
  10477. #ifdef _IBMR2
  10478.     makestr(&(optlist[noptlist++]),"_IBMR2");
  10479. #endif
  10480. #ifdef UNIXWARE
  10481.     makestr(&(optlist[noptlist++]),"UNIXWARE");
  10482. #endif
  10483. #ifdef QNX
  10484.     makestr(&(optlist[noptlist++]),"QNX");
  10485. #ifdef __QNX__
  10486.     makestr(&(optlist[noptlist++]),"__QNX__");
  10487. #ifdef __16BIT__
  10488.     makestr(&(optlist[noptlist++]),"__16BIT__");
  10489. #endif
  10490. #ifdef CK_QNX16
  10491.     makestr(&(optlist[noptlist++]),"CK_QNX16");
  10492. #endif
  10493. #ifdef __32BIT__
  10494.     makestr(&(optlist[noptlist++]),"__32BIT__");
  10495. #endif
  10496. #ifdef CK_QNX32
  10497.     makestr(&(optlist[noptlist++]),"CK_QNX32");
  10498. #endif
  10499. #endif /* __QNX__ */
  10500. #endif /* QNX */
  10501.  
  10502. #ifdef __STRICT_BSD__
  10503.     makestr(&(optlist[noptlist++]),"__STRICT_BSD__");
  10504. #endif
  10505. #ifdef __STRICT_ANSI__
  10506.     makestr(&(optlist[noptlist++]),"__STRICT_ANSI__");
  10507. #endif
  10508. #ifdef _ANSI_C_SOURCE
  10509.     makestr(&(optlist[noptlist++]),"_ANSI_C_SOURCE");
  10510. #endif
  10511. #ifdef __STDC__
  10512.     makestr(&(optlist[noptlist++]),"__STDC__");
  10513. #endif
  10514. #ifdef __DECC
  10515.     makestr(&(optlist[noptlist++]),"__DECC");
  10516. #ifdef __DECC_VER
  10517.     sprintf(line,"__DECC_VER=%d",__DECC_VER); /* SAFE */
  10518.     makestr(&(optlist[noptlist++]),line);
  10519. #endif /* __DECC_VER */
  10520. #endif /* __DECC */
  10521. #ifdef __CRTL_VER
  10522.     sprintf(line,"__CRTL_VER=%d",__CRTL_VER); /* SAFE */
  10523.     makestr(&(optlist[noptlist++]),line);
  10524. #endif /* __CRTL_VER */
  10525. #ifdef __GNUC__                /* gcc in ansi mode */
  10526.     makestr(&(optlist[noptlist++]),"__GNUC__");
  10527. #endif
  10528. #ifdef GNUC                /* gcc in traditional mode */
  10529.     makestr(&(optlist[noptlist++]),"GNUC");
  10530. #endif
  10531. #ifdef __EGCS__                /* egcs in ansi mode */
  10532.     makestr(&(optlist[noptlist++]),"__EGCS__");
  10533. #endif
  10534. #ifdef __egcs__                /* egcs in ansi mode */
  10535.     makestr(&(optlist[noptlist++]),"__egcs__");
  10536. #endif
  10537. #ifdef __WATCOMC__
  10538.     makestr(&(optlist[noptlist++]),"__WATCOMC__");
  10539. #endif
  10540. #ifdef CK_ANSIC
  10541.     makestr(&(optlist[noptlist++]),"CK_ANSIC");
  10542. #endif
  10543. #ifdef CK_ANSILIBS
  10544.     makestr(&(optlist[noptlist++]),"CK_ANSILIBS");
  10545. #endif
  10546. #ifdef CKCONINTB4CB
  10547.     makestr(&(optlist[noptlist++]),"CKCONINTB4CB");
  10548. #endif /* CKCONINTB4CB */
  10549. #ifdef NOTERMCAP
  10550.     makestr(&(optlist[noptlist++]),"NOTERMCAP");
  10551. #endif /* NOTERMCAP */
  10552. #ifdef __GLIBC__
  10553.     makestr(&(optlist[noptlist++]),"__GLIBC__");
  10554. #endif
  10555. #ifdef _SC_JOB_CONTROL
  10556.     makestr(&(optlist[noptlist++]),"_SC_JOB_CONTROL");
  10557. #endif
  10558. #ifdef _POSIX_JOB_CONTROL
  10559.     makestr(&(optlist[noptlist++]),"_POSIX_JOB_CONTROL");
  10560. #endif
  10561. #ifdef SIG_I
  10562.     makestr(&(optlist[noptlist++]),"SIG_I");
  10563. #endif /* SIG_I */
  10564. #ifdef SIG_V
  10565.     makestr(&(optlist[noptlist++]),"SIG_V");
  10566. #endif /* SIG_V */
  10567. #ifdef CK_POSIX_SIG
  10568.     makestr(&(optlist[noptlist++]),"CK_POSIX_SIG");
  10569. #endif
  10570. #ifdef SVR3JC
  10571.     makestr(&(optlist[noptlist++]),"SVR3JC");
  10572. #endif
  10573. #ifdef _386BSD
  10574.     makestr(&(optlist[noptlist++]),"_386BSD");
  10575. #endif
  10576. #ifdef _BSD
  10577.     makestr(&(optlist[noptlist++]),"_BSD");
  10578. #endif
  10579. #ifdef USE_MEMCPY
  10580.     makestr(&(optlist[noptlist++]),"USE_MEMCPY");
  10581. #endif /* USE_MEMCPY */
  10582. #ifdef USE_LSTAT
  10583.     makestr(&(optlist[noptlist++]),"USE_LSTAT");
  10584. #endif /* USE_LSTAT */
  10585. #ifdef TERMIOX
  10586.     makestr(&(optlist[noptlist++]),"TERMIOX");
  10587. #endif /* TERMIOX */
  10588. #ifdef STERMIOX
  10589.     makestr(&(optlist[noptlist++]),"STERMIOX");
  10590. #endif /* STERMIOX */
  10591. #ifdef CK_CURSES
  10592.     makestr(&(optlist[noptlist++]),"CK_CURSES");
  10593. #endif /* CK_CURSES */
  10594. #ifdef CK_NEWTERM
  10595.     makestr(&(optlist[noptlist++]),"CK_NEWTERM");
  10596. #endif /* CK_NEWTERM */
  10597. #ifdef CK_WREFRESH
  10598.     makestr(&(optlist[noptlist++]),"CK_WREFRESH");
  10599. #endif /* CK_WREFRESH */
  10600. #ifdef CK_PCT_BAR
  10601.     makestr(&(optlist[noptlist++]),"CK_PCT_BAR");
  10602. #endif /* CK_PCT_BAR */
  10603. #ifdef CK_DTRCD
  10604.     makestr(&(optlist[noptlist++]),"CK_DTRCD");
  10605. #endif /* CK_DTRCD */
  10606. #ifdef CK_DTRCTS
  10607.     makestr(&(optlist[noptlist++]),"CK_DTRCTS");
  10608. #endif /* CK_DTRCTS */
  10609. #ifdef CK_RTSCTS
  10610.     makestr(&(optlist[noptlist++]),"CK_RTSCTS");
  10611. #endif /* CK_RTSCTS */
  10612. #ifdef POSIX_CRTSCTS
  10613.     makestr(&(optlist[noptlist++]),"POSIX_CRTSCTS");
  10614. #endif /* POSIX_CRTSCTS */
  10615. #ifdef FIXCRTSCTS
  10616.     makestr(&(optlist[noptlist++]),"FIXCRTSCTS");
  10617. #endif /* FIXCRTSCTS */
  10618. #ifdef HWPARITY
  10619.     makestr(&(optlist[noptlist++]),"HWPARITY");
  10620. #endif /* HWPARITY */
  10621. #ifdef CK_SYSINI
  10622. #ifdef CK_INI_A
  10623.     makestr(&(optlist[noptlist++]),"CK_INI_A");
  10624.     ckmakmsg(line,LINBUFSIZ,"CK_SYSINI=\"",CK_SYSINI,"\"",NULL);
  10625.     makestr(&(optlist[noptlist++]),line);
  10626. #else
  10627. #ifdef CK_INI_B
  10628.     makestr(&(optlist[noptlist++]),"CK_INI_B");
  10629.     ckmakmsg(line,LINBUFSIZ,"CK_SYSINI=\"",CK_SYSINI,"\"",NULL);
  10630.     makestr(&(optlist[noptlist++]),line);
  10631. #else
  10632.     makestr(&(optlist[noptlist++]),"CK_SYSINI");
  10633. #endif /* CK_INI_B */
  10634. #endif /* CK_INI_A */
  10635. #endif /* CK_DSYSINI */
  10636. #ifdef CK_DSYSINI
  10637.     makestr(&(optlist[noptlist++]),"CK_DSYSINI");
  10638. #endif /* CK_DSYSINI */
  10639. #ifdef CK_TTGWSIZ
  10640.     makestr(&(optlist[noptlist++]),"CK_TTGWSIZ");
  10641. #endif /* CK_TTGWSIZ */
  10642. #ifdef CK_NAWS
  10643.     makestr(&(optlist[noptlist++]),"CK_NAWS");
  10644. #endif /* CK_NAWS */
  10645. #ifdef MDMHUP
  10646.     makestr(&(optlist[noptlist++]),"MDMHUP");
  10647. #endif /* MDMHUP */
  10648. #ifdef HUP_CLOSE_POSIX
  10649.     makestr(&(optlist[noptlist++]),"HUP_CLOSE_POSIX");
  10650. #endif /* HUP_CLOSE_POSIX */
  10651. #ifdef NO_HUP_CLOSE_POSIX
  10652.     makestr(&(optlist[noptlist++]),"NO_HUP_CLOSE_POSIX");
  10653. #endif /* NO_HUP_CLOSE_POSIX */
  10654. #ifdef DCMDBUF
  10655.     makestr(&(optlist[noptlist++]),"DCMDBUF");
  10656. #endif /* DCMDBUF */
  10657. #ifdef CK_RECALL
  10658.     makestr(&(optlist[noptlist++]),"CK_RECALL");
  10659. #endif /* CK_RECALL */
  10660. #ifdef BROWSER
  10661.     makestr(&(optlist[noptlist++]),"BROWSER");
  10662. #endif /* BROWSER */
  10663. #ifdef CLSOPN
  10664.     makestr(&(optlist[noptlist++]),"CLSOPN");
  10665. #endif /* CLSOPN */
  10666. #ifdef STRATUS
  10667.     makestr(&(optlist[noptlist++]),"STRATUS");
  10668. #endif /* STRATUS */
  10669. #ifdef __VOS__
  10670.     makestr(&(optlist[noptlist++]),"__VOS__");
  10671. #endif /* __VOS__ */
  10672. #ifdef STRATUSX25
  10673.     makestr(&(optlist[noptlist++]),"STRATUSX25");
  10674. #endif /* STRATUSX25 */
  10675. #ifdef OS2MOUSE
  10676.     makestr(&(optlist[noptlist++]),"OS2MOUSE");
  10677. #endif /* OS2MOUSE */
  10678. #ifdef CK_REXX
  10679.     makestr(&(optlist[noptlist++]),"CK_REXX");
  10680. #endif /* CK_REXX */
  10681. #ifdef CK_TIMERS
  10682.     makestr(&(optlist[noptlist++]),"CK_TIMERS");
  10683. #endif /* CK_TIMERS */
  10684. #ifdef TTSPDLIST
  10685.     makestr(&(optlist[noptlist++]),"TTSPDLIST");
  10686. #endif /* TTSPDLIST */
  10687. #ifdef CK_PERMS
  10688.     makestr(&(optlist[noptlist++]),"CK_PERMS");
  10689. #endif /* CK_PERMS */
  10690. #ifdef CKTUNING
  10691.     makestr(&(optlist[noptlist++]),"CKTUNING");
  10692. #endif /* CKTUNING */
  10693. #ifdef NEWFTP
  10694.     makestr(&(optlist[noptlist++]),"NEWFTP");
  10695. #endif /* NEWFTP */
  10696. #ifdef SYSFTP
  10697.     makestr(&(optlist[noptlist++]),"SYSFTP");
  10698. #endif /* SYSFTP */
  10699. #ifdef NOFTP
  10700.     makestr(&(optlist[noptlist++]),"NOFTP");
  10701. #endif /* NOFTP */
  10702. #ifdef CKHTTP
  10703.     makestr(&(optlist[noptlist++]),"CKHTTP");
  10704. #endif /* CKHTTP */
  10705. #ifdef NOHTTP
  10706.     makestr(&(optlist[noptlist++]),"NOHTTP");
  10707. #endif /* NOHTTP */
  10708. #ifdef CKROOT
  10709.     makestr(&(optlist[noptlist++]),"CKROOT");
  10710. #endif /* CKROOT */
  10711. #ifdef CKREALPATH
  10712.     makestr(&(optlist[noptlist++]),"CKREALPATH");
  10713. #endif /* CKREALPATH */
  10714. #ifdef STREAMING
  10715.     makestr(&(optlist[noptlist++]),"STREAMING");
  10716. #endif /* STREAMING */
  10717. #ifdef UNPREFIXZERO
  10718.     makestr(&(optlist[noptlist++]),"UNPREFIXZERO");
  10719. #endif /* UNPREFIXZERO */
  10720. #ifdef CKREGEX
  10721.     makestr(&(optlist[noptlist++]),"CKREGEX");
  10722. #endif /* CKREGEX */
  10723. #ifdef ZXREWIND
  10724.     makestr(&(optlist[noptlist++]),"ZXREWIND");
  10725. #endif /* ZXREWIND */
  10726. #ifdef CKSYSLOG
  10727.     makestr(&(optlist[noptlist++]),"CKSYSLOG");
  10728. #endif /* CKSYSLOG */
  10729. #ifdef SYSLOGLEVEL
  10730.     sprintf(line,"SYSLOGLEVEL=%d",SYSLOGLEVEL);    /* SAFE */
  10731.     makestr(&(optlist[noptlist++]),line);
  10732. #endif /* SYSLOGLEVEL */
  10733. #ifdef NOSEXP
  10734.     makestr(&(optlist[noptlist++]),"NOSEXP");
  10735. #endif /* NOSEXP */
  10736. #ifdef CKLEARN
  10737.     makestr(&(optlist[noptlist++]),"CKLEARN");
  10738. #else
  10739. #ifdef NOLOEARN
  10740.     makestr(&(optlist[noptlist++]),"NOLOEARN");
  10741. #endif /* NOLOEARN */
  10742. #endif /* CKLEARN */
  10743. #ifdef NOFLOAT
  10744.     makestr(&(optlist[noptlist++]),"NOFLOAT");
  10745. #else
  10746. #ifdef FNFLOAT
  10747.     makestr(&(optlist[noptlist++]),"FNFLOAT");
  10748. #endif /* FNFLOAT */
  10749. #ifdef CKFLOAT
  10750. #ifdef GFTIMER
  10751.     makestr(&(optlist[noptlist++]),"GFTIMER");
  10752. #endif /* GFTIMER */
  10753. #ifdef CKFLOAT_S
  10754.     ckmakmsg(line,LINBUFSIZ,"CKFLOAT=",CKFLOAT_S,NULL,NULL);
  10755.     makestr(&(optlist[noptlist++]),line);
  10756. #else
  10757.     makestr(&(optlist[noptlist++]),"CKFLOAT");
  10758. #endif /* CKFLOAT_S */
  10759. #endif /* CKFLOAT */
  10760. #endif /* NOFLOAT */
  10761.  
  10762. #ifdef SSH
  10763.     makestr(&(optlist[noptlist++]),"SSH");
  10764. #endif /* SSH */
  10765. #ifdef NETDLL
  10766.     makestr(&(optlist[noptlist++]),"NETDLL");
  10767. #endif /* NETDLL */
  10768. #ifdef NETFILE
  10769.     makestr(&(optlist[noptlist++]),"NETFILE");
  10770. #endif /* NETFILE */
  10771. #ifdef CK_TAPI
  10772.     makestr(&(optlist[noptlist++]),"CK_TAPI");
  10773. #endif /* CK_TAPI */
  10774. #ifdef CK_SSL
  10775.     makestr(&(optlist[noptlist++]),"CK_SSL");
  10776. #endif /* CK_SSL */
  10777.  
  10778.     debug(F101,"initoptlist noptlist","",noptlist);
  10779.     sh_sort(optlist,NULL,noptlist,0,0,0);
  10780. }
  10781.  
  10782. int
  10783. shofea() {
  10784.     int i;
  10785.     int flag = 0;
  10786.     int lines = 1;
  10787. #ifdef FNFLOAT
  10788.     extern int fp_digits, fp_rounding;
  10789. #endif /* FNFLOAT */
  10790.     extern int byteorder;
  10791.     printf("%s\n",versio);
  10792.     if (inserver)
  10793.       return(1);
  10794.     debug(F101,"shofea NOPTLIST","",NOPTLIST);
  10795.     initoptlist();
  10796.     debug(F101,"shofea noptlist","",noptlist);
  10797. #ifdef OS2
  10798. #ifdef NT
  10799. #ifdef _M_ALPHA
  10800.     printf("Microsoft Windows Operating Systems for Alpha CPUs.\n");
  10801. #else /* _M_ALPHA */
  10802. #ifdef _M_PPC
  10803.     printf("Microsoft Windows Operating Systems for PowerPC CPUs.\n");
  10804. #else /* _M_PPC */
  10805. #ifdef _M_MRX000
  10806.     printf("Microsoft Windows Operating Systems for MIPS CPUs.\n");
  10807. #else /* _M_MRX000 */
  10808. #ifdef _M_IX86
  10809.     printf("Microsoft Windows Operating Systems for 32-bit Intel CPUs.\n");
  10810. #else /* _M_IX86 */
  10811.     UNKNOWN WINDOWS PLATFORM
  10812. #endif /* _M_IX86 */
  10813. #endif /* _M_MRX000 */
  10814. #endif /* _M_PPC */
  10815. #endif /* _M_ALPHA */
  10816. #else /* NT */
  10817. #ifdef M_I286
  10818.     printf("IBM OS/2 16-bit.\n");
  10819. #else
  10820.     printf("IBM OS/2 32-bit.\n");
  10821. #endif /* M_I286 */
  10822. #endif /* NT */
  10823.     lines++;
  10824. #endif /* OS2 */
  10825.     printf("\n");
  10826.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10827.     printf("Major optional features included:\n");
  10828.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10829.  
  10830. #ifdef NETCONN
  10831.     printf(" Network support (type SHOW NET for further info)\n");
  10832.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10833. #ifdef IKS_OPTION
  10834.     printf(" Telnet Kermit Option\n");
  10835.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10836. #endif /* IKS_OPTION */
  10837. #ifdef CK_AUTHENTICATION
  10838.     printf(" Telnet Authentication Option\n");
  10839.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10840. #ifdef CK_KERBEROS
  10841. #ifdef KRB4
  10842. #ifdef KRB5
  10843.     printf(" Kerberos(TM) IV and Kerberos V authentication\n");
  10844.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10845. #else /* KRB5 */
  10846.     printf(" Kerberos(TM) IV authentication\n");
  10847.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10848. #endif /* KRB5 */
  10849. #else /* KRB4 */
  10850. #ifdef KRB5
  10851.     printf(" Kerberos(TM) V authentication\n");
  10852.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10853. #endif /* KRB5 */
  10854. #endif /* KRB4 */
  10855. #endif /* CK_KERBEROS */
  10856. #ifdef CK_SRP
  10857.     printf(" SRP(TM) (Secure Remote Password) authentication\n");
  10858.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10859. #endif /* CK_SRP */
  10860. #ifdef CK_SSL
  10861.     printf(" Secure Sockets Layer (SSL)\n");
  10862.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10863.     printf(" Transport Layer Security (TLS)\n");
  10864.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10865. #endif /* CK_SSL */
  10866. #ifdef SSHBUILTIN
  10867.     printf(" Secure Shell (SSH) [internal]\n");
  10868.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10869. #endif /* SSHBUILTIN */
  10870. #ifdef SSHCMD
  10871.     printf(" Secure Shell (SSH) [external]\n");
  10872.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10873. #endif /* SSHCMD */
  10874. #ifdef CK_ENCRYPTION
  10875.     printf(" Telnet Encryption Option\n");
  10876.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10877. #ifdef CK_DES
  10878.     printf(" DES Encryption\n");
  10879.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10880. #endif /* CK_DES */
  10881. #ifdef CK_CAST
  10882.     printf(" CAST Encryption\n");
  10883.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10884. #endif /* CK_CAST */
  10885. #endif /* CK_ENCRYPTION */
  10886. #endif /* CK_AUTHENTICATION */
  10887. #ifdef CK_FORWARD_X
  10888.     printf(" X Windows forwarding\n");
  10889.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10890. #endif /* CK_FORWARD_X */
  10891. #ifdef TN_COMPORT
  10892.     printf(" Telnet Remote Com Port Control Option\n");
  10893.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10894. #endif /* TN_COMPORT */
  10895. #ifdef CK_SOCKS
  10896. #ifdef CK_SOCKS5
  10897.     printf(" SOCKS 5\n");
  10898.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10899. #else /* CK_SOCKS5 */
  10900.     printf(" SOCKS 4\n");
  10901.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10902. #endif /* CK_SOCKS5 */
  10903. #endif /* CK_SOCKS */
  10904. #ifdef NEWFTP
  10905.     printf(" Built-in FTP client\n");
  10906.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10907. #endif /* NEWFTP */
  10908. #ifdef CKHTTP
  10909.     printf(" Built-in HTTP client\n");
  10910.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10911. #endif /* CKHTTP */
  10912. #endif /* NETCONN */
  10913.  
  10914. #ifdef CK_RTSCTS
  10915.     printf(" Hardware flow control\n");
  10916.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10917. #endif /* CK_RTSCTS */
  10918.  
  10919. #ifdef CK_XYZ
  10920. #ifdef XYZ_INTERNAL
  10921.     printf(" Built-in XYZMODEM protocols\n");
  10922. #else
  10923.     printf(" External XYZMODEM protocol support\n");
  10924. #endif /* XYZ_INTERNAL */
  10925.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10926. #endif /* CK_XYZ */
  10927.  
  10928. #ifndef NOCSETS
  10929.     printf(" Latin-1 (West European) character-set translation\n");
  10930.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10931. #ifdef LATIN2
  10932.     printf(" Latin-2 (East European) character-set translation\n");
  10933.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10934. #endif /* LATIN2 */
  10935. #ifdef CYRILLIC
  10936.     printf(" Cyrillic (Russian, Ukrainian, etc) character-set translation\n");
  10937.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10938. #endif /* CYRILLIC */
  10939. #ifdef GREEK
  10940.     printf(" Greek character-set translation\n");
  10941.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10942. #endif /* GREEK */
  10943. #ifdef HEBREW
  10944.     printf(" Hebrew character-set translation\n");
  10945.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10946. #endif /* HEBREW */
  10947. #ifdef KANJI
  10948.     printf(" Japanese character-set translation\n");
  10949.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10950. #endif /* KANJI */
  10951. #ifdef UNICODE
  10952.     printf(" Unicode character-set translation\n");
  10953.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10954. #endif /* UNICODE */
  10955. #ifdef CKOUNI
  10956.     if (isunicode())
  10957.       printf(" Unicode support for ISO-2022 Terminal Emulation\n");
  10958.     else
  10959.       printf(" Unicode translation for Terminal Character-Sets\n");
  10960.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10961. #endif /* CKOUNI */
  10962. #endif /* NOCSETS */
  10963.  
  10964. #ifdef NETPTY
  10965.     printf(" Pseudoterminal control\n");
  10966.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10967. #endif /* NETPTY */
  10968.  
  10969. #ifdef CK_REDIR
  10970.     printf(" REDIRECT command\n");
  10971.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10972. #endif /* CK_REDIR */
  10973.  
  10974. #ifdef CK_RESEND
  10975.     printf(" RESEND command\n");
  10976.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10977. #endif /* CK_RESEND */
  10978.  
  10979. #ifndef NOXFER
  10980. #ifdef CK_CURSES
  10981.     printf(" Fullscreen file transfer display\n");
  10982.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10983. #endif /* CK_CURSES */
  10984. #endif /* NOXFER */
  10985.  
  10986. #ifdef CK_SPEED
  10987.     printf(" Control-character unprefixing\n");
  10988.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10989. #endif /* CK_SPEED */
  10990.  
  10991. #ifdef STREAMING
  10992.     printf(" Streaming\n");
  10993.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10994. #endif /* STREAMING */
  10995.  
  10996. #ifdef CK_AUTODL
  10997.     printf(" Autodownload\n");
  10998.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  10999. #endif /* CK_AUTODL */
  11000.  
  11001. #ifdef OS2MOUSE
  11002.     printf(" Mouse support\n");
  11003.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11004. #endif /* OS2MOUSE */
  11005.  
  11006. #ifdef CK_REXX
  11007.     printf(" REXX script language interface\n");
  11008.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11009. #endif /* CK_REXX */
  11010.  
  11011. #ifdef IKSD
  11012. #ifdef CK_LOGIN
  11013.     printf(" Internet Kermit Service with user login support\n");
  11014. #else /* CK_LOGIN */
  11015.     printf(" Internet Kermit Service without user login support\n");
  11016. #endif /* CK_LOGIN */
  11017.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11018. #endif /* IKSD */
  11019.  
  11020.     printf("\n");
  11021.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11022.     printf("Major optional features not included:\n");
  11023.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11024.  
  11025. #ifdef NOXFER
  11026.     printf(" No file-transfer protocols\n");
  11027.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11028.     flag = 1;
  11029. #else
  11030. #ifndef CK_CURSES
  11031. #ifndef MAC
  11032.     printf(" No fullscreen file transfer display\n");
  11033.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11034.     flag = 1;
  11035. #endif /* MAC */
  11036. #endif /* CK_CURSES */
  11037.  
  11038. #ifdef NOSERVER
  11039.     printf(" No server mode\n");
  11040.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11041.     flag = 1;
  11042. #endif /* NOSERVER */
  11043.  
  11044. #ifndef CK_SPEED
  11045.     printf(" No control-character unprefixing\n");
  11046.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11047.     flag = 1;
  11048. #endif /* CK_SPEED */
  11049.  
  11050. #ifndef STREAMING
  11051.     printf(" No streaming\n");
  11052.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11053.     flag = 1;
  11054. #endif /* STREAMING */
  11055.  
  11056. #ifndef CK_AUTODL
  11057.     printf(" No autodownload\n");
  11058.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11059.     flag = 1;
  11060. #endif /* CK_AUTODL */
  11061.  
  11062. #ifndef CK_XYZ
  11063.     printf(" No built-in XYZMODEM protocols\n");
  11064.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11065.     flag = 1;
  11066. #endif /* CK_XYZ */
  11067.  
  11068. #ifdef NOTLOG
  11069.     printf(" No transaction log\n");
  11070.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11071.     flag = 1;
  11072. #endif /* NOTLOG */
  11073. #endif /* NOXFER */
  11074.  
  11075. #ifdef NODEBUG
  11076.     printf(" No debugging\n");
  11077.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11078.     flag = 1;
  11079. #endif /* NODEBUG */
  11080.  
  11081. #ifdef NOHELP
  11082.     printf(" No built-in help\n");
  11083.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11084.     flag = 1;
  11085. #endif /* NOHELP */
  11086.  
  11087. #ifdef NOLOCAL
  11088.     printf(" No making connections\n");
  11089.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11090.     flag = 1;
  11091. #else
  11092. #ifndef NETCONN
  11093.     printf(" No network support\n");
  11094.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11095.     flag = 1;
  11096. #else /* NETCONN */
  11097. #ifndef IKS_OPTION
  11098.     printf(" No Telnet Kermit Option\n");
  11099.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11100.     flag = 1;
  11101. #endif /* IKS_OPTION */
  11102. #endif /* NETCONN */
  11103.  
  11104. #ifdef NOSSH
  11105.     printf(" No Secure Shell (SSH)\n");
  11106.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11107. #endif /* NOSSH */
  11108. #ifndef CK_AUTHENTICATION
  11109.     printf(" No Kerberos(TM) authentication\n");
  11110.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11111.     printf(" No SRP(TM) (Secure Remote Password) protocol\n");
  11112.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11113.     printf(" No Secure Sockets Layer (SSL) protocol\n");
  11114.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11115.     printf(" No Transport Layer Security (TLS) protocol\n");
  11116.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11117.     printf(" No encryption\n");
  11118.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11119.     flag = 1;
  11120. #else /* CK_AUTHENTICATION */
  11121. #ifndef CK_KERBEROS
  11122.     printf(" No Kerberos(TM) authentication\n");
  11123.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11124.     flag = 1;
  11125. #else /* CK_KERBEROS */
  11126. #ifndef KRB4
  11127.     printf(" No Kerberos(TM) IV authentication\n");
  11128.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11129.     flag = 1;
  11130. #endif /* KRB4 */
  11131. #ifndef KRB5
  11132.     printf(" No Kerberos(TM) V authentication\n");
  11133.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11134.     flag = 1;
  11135. #endif /* KRB5 */
  11136. #endif /* CK_KERBEROS */
  11137. #ifndef CK_SRP
  11138.     printf(" No SRP(TM) (Secure Remote Password) authentication\n");
  11139.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11140.     flag = 1;
  11141. #endif /* CK_SRP */
  11142. #ifndef CK_SSL
  11143.     printf(" No Secure Sockets Layer (SSL) protocol\n");
  11144.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11145.     printf(" No Transport Layer Security (TLS) protocol\n");
  11146.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11147.     flag = 1;
  11148. #endif /* CK_SSL */
  11149. #ifndef CK_ENCRYPTION
  11150.     printf(" No encryption\n");
  11151.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11152.     flag = 1;
  11153. #else /* CK_ENCRYPTION */
  11154. #ifndef OS2
  11155. #ifndef CK_DES
  11156.     printf(" No DES encryption\n");
  11157.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11158.     flag = 1;
  11159. #endif /* CK_DES */
  11160. #ifndef CK_CAST
  11161.     printf(" No CAST encryption\n");
  11162.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11163.     flag = 1;
  11164. #endif /* CK_CAST */
  11165. #endif /* OS2 */
  11166. #endif /* CK_ENCRYPTION */
  11167. #endif /* CK_AUTHENTICATION */
  11168. #ifndef CK_FORWARD_X
  11169.     printf(" No X Windows forwarding\n");
  11170.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11171. #endif /* CK_FORWARD_X */
  11172. #ifndef TN_COMPORT
  11173.     printf(" No Telnet Remote Com Port Control Option\n");
  11174.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11175. #endif /* TN_COMPORT */
  11176. #ifndef CK_SOCKS
  11177.     printf(" No SOCKS\n");
  11178.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11179. #endif /* CK_SOCKS */
  11180. #ifndef NEWFTP
  11181.     printf(" No built-in FTP client\n");
  11182.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11183. #endif /* NEWFTP */
  11184. #ifdef NOHTTP
  11185.     printf(" No built-in HTTP client\n");
  11186.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11187. #endif /* NOHTTP */
  11188.  
  11189. #ifdef NODIAL
  11190.     printf(" No DIAL command\n");
  11191.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11192.     flag = 1;
  11193. #else
  11194. #ifdef MINIDIAL
  11195.     printf(" Support for most modem types excluded\n");
  11196.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11197.     flag = 1;
  11198. #endif /* MINIDIAL */
  11199. #endif /* NODIAL */
  11200. #endif /* NOLOCAL */
  11201.  
  11202. #ifndef CK_RTSCTS
  11203. #ifndef MAC
  11204.     printf(" No hardware flow control\n");
  11205.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11206.     flag = 1;
  11207. #endif /* MAC */
  11208. #endif /* CK_RTSCTS */
  11209.  
  11210. #ifdef NOXMIT
  11211.     printf(" No TRANSMIT command\n");
  11212.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11213.     flag = 1;
  11214. #endif /* NOXMIT */
  11215.  
  11216. #ifdef NOSCRIPT
  11217.     printf(" No SCRIPT command\n");
  11218.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11219.     flag = 1;
  11220. #endif /* NOSCRIPT */
  11221.  
  11222. #ifdef NOSPL
  11223.     printf(" No script programming features\n");
  11224.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11225.     flag = 1;
  11226. #endif /* NOSPL */
  11227.  
  11228. #ifdef NOCSETS
  11229.     printf(" No character-set translation\n");
  11230.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11231.     flag = 1;
  11232. #else
  11233.  
  11234. #ifndef LATIN2
  11235.     printf(" No Latin-2 character-set translation\n");
  11236.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11237.     flag = 1;
  11238. #endif /* LATIN2 */
  11239.  
  11240. #ifdef NOGREEK
  11241.     printf(" No Greek character-set translation\n");
  11242.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11243.     flag = 1;
  11244. #endif /* NOGREEK */
  11245.  
  11246. #ifdef NOHEBREW
  11247.     printf(" No Hebrew character-set translation\n");
  11248.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11249.     flag = 1;
  11250. #endif /* NOHEBREW */
  11251.  
  11252. #ifdef NOUNICODE
  11253.     printf(" No Unicode character-set translation\n");
  11254.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11255.     flag = 1;
  11256. #endif /* NOUNICODE */
  11257.  
  11258. #ifdef NOCYRIL
  11259.     printf(" No Cyrillic character-set translation\n");
  11260.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11261.     flag = 1;
  11262. #endif /* NOCYRIL */
  11263.  
  11264. #ifndef KANJI
  11265.     printf(" No Kanji character-set translation\n");
  11266.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11267.     flag = 1;
  11268. #endif /* KANJI */
  11269. #endif /* NOCSETS */
  11270.  
  11271. #ifdef NOCMDL
  11272.     printf(" No command-line arguments\n");
  11273.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11274.     flag = 1;
  11275. #endif /* NOCMDL */
  11276.  
  11277. #ifdef NOPUSH
  11278.     printf(" No escape to system\n");
  11279.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11280.     flag = 1;
  11281. #endif /* NOPUSH */
  11282.  
  11283. #ifdef NOJC
  11284. #ifdef UNIX
  11285.     printf(" No UNIX job control\n");
  11286.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11287.     flag = 1;
  11288. #endif /* UNIX */
  11289. #endif /* NOJC */
  11290.  
  11291. #ifdef NOSETKEY
  11292.     printf(" No SET KEY command\n");
  11293.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11294.     flag = 1;
  11295. #endif /* NOSETKEY */
  11296.  
  11297. #ifndef CK_REDIR
  11298.     printf(" No REDIRECT or PIPE command\n");
  11299.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11300.     flag = 1;
  11301. #endif /* CK_REDIR */
  11302.  
  11303. #ifdef UNIX
  11304. #ifndef NETPTY
  11305.     printf(" No pseudoterminal control\n");
  11306.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11307.     flag = 1;
  11308. #endif /* NETPTY */
  11309. #endif /* UNIX */
  11310.  
  11311. #ifndef CK_RESEND
  11312.     printf(" No RESEND command\n");
  11313.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11314.     flag = 1;
  11315. #endif /* CK_RESEND */
  11316.  
  11317. #ifdef OS2
  11318. #ifdef __32BIT__
  11319. #ifndef OS2MOUSE
  11320.     printf(" No Mouse support\n");
  11321.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11322.     flag = 1;
  11323. #endif /* __32BIT__ */
  11324. #endif /* OS2 */
  11325. #endif /* OS2MOUSE */
  11326.  
  11327. #ifdef OS2
  11328. #ifndef NT
  11329. #ifndef CK_REXX
  11330.     printf(" No REXX script language interface\n");
  11331.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11332.     flag = 1;
  11333. #endif /* CK_REXX */
  11334. #endif /* NT */
  11335. #endif /* OS2 */
  11336.  
  11337. #ifndef IKSD
  11338.     printf(" No Internet Kermit Service\n");
  11339.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11340.     flag = 1;
  11341. #endif /* IKSD */
  11342.  
  11343.     if (flag == 0) {
  11344.     printf(" None\n");
  11345.     if (++lines > cmd_rows - 3)
  11346.       { if (!askmore()) return(1); else lines = 0; }
  11347.     }
  11348.     printf("\n");
  11349.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11350.  
  11351. #ifdef CK_UTSNAME
  11352.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11353.     printf("Host info:\n");
  11354.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11355.     printf(" Machine:    %s\n",unm_mch[0] ? unm_mch : "(unknown)");
  11356.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11357.     printf(" Model:      %s\n",unm_mod[0] ? unm_mod : "(unknown)");
  11358.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11359.     printf(" OS:         %s\n",unm_nam[0] ? unm_nam : "(unknown)");
  11360.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11361.     printf(" OS Release: %s\n",unm_rel[0] ? unm_rel : "(unknown)");
  11362.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11363.     printf(" OS Version: %s\n",unm_ver[0] ? unm_ver : "(unknown)");
  11364.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11365.     printf("\n");
  11366.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11367. #endif /* CK_UTSNAME */
  11368.  
  11369. /*
  11370.   Print compile-time (-D) options, as well as C preprocessor
  11371.   predefined symbols that might affect us...
  11372. */
  11373. #ifdef KTARGET
  11374.     {
  11375.     char * s;            /* Makefile target */
  11376.     s = KTARGET;
  11377.     if (!s) s = "";
  11378.     if (!*s) s = "(unknown)";
  11379.     printf("\n");
  11380.     if (++lines > cmd_rows - 3) {
  11381.         if (!askmore()) return(1); else lines = 0;
  11382.     }
  11383.     printf("Target: %s\n", s);
  11384.     if (++lines > cmd_rows - 3) {
  11385.         if (!askmore()) return(1); else lines = 0;
  11386.     }
  11387.     }
  11388. #endif /* KTARGET */
  11389.  
  11390. #ifdef __VERSION__
  11391. #ifdef __GNUC__
  11392.     printf("GCC version: %s\n", __VERSION__);
  11393. #else
  11394.     printf("Compiler version: %s\n", __VERSION__);
  11395. #endif /* __GNUC__ */
  11396.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11397. #endif /* __VERSION__ */
  11398.  
  11399. #ifdef __DATE__                /* GNU and other ANSI */
  11400. #ifdef __TIME__
  11401.     printf("Compiled %s %s, options:\n", __DATE__, __TIME__);
  11402. #else
  11403.     printf("Compiled %s, options:\n", __DATE__);
  11404. #endif /* __TIME__ */
  11405. #else /* !__DATE__ */
  11406.     printf("Compiler options:\n");
  11407. #endif /* __DATE__ */
  11408.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11409.  
  11410.     for (i = 0; i < noptlist; i++)    /* Print sorted option list */
  11411.       if (!prtopt(&lines,optlist[i]))
  11412.     return(0);
  11413.  
  11414.     if (!prtopt(&lines,"")) return(0);    /* Start a new section */
  11415.  
  11416. /* Sizes of data types */
  11417.  
  11418.     ckmakmsg(line,
  11419.          LINBUFSIZ,
  11420.          "byte order: ",
  11421.          byteorder ? "little" : "big",
  11422.          " endian",
  11423.          NULL
  11424.          );
  11425.     if (!prtopt(&lines,line)) return(0);
  11426.     if (!prtopt(&lines,"")) return(0);    /* Start a new section */
  11427.     sprintf(line,"sizeofs: int=%ld",sizeof(int)); /* SAFE */
  11428.     if (!prtopt(&lines,line)) return(0);
  11429.     sprintf(line,"long=%ld",sizeof(long)); /* SAFE */
  11430.     if (!prtopt(&lines,line)) return(0);
  11431.     sprintf(line,"short=%ld",sizeof(short)); /* SAFE */
  11432.     if (!prtopt(&lines,line)) return(0);
  11433.     sprintf(line,"char=%ld",sizeof(char)); /* SAFE */
  11434.     if (!prtopt(&lines,line)) return(0);
  11435.     sprintf(line,"char*=%ld",sizeof(char *)); /* SAFE */
  11436.     if (!prtopt(&lines,line)) return(0);
  11437. #ifdef LONG_MAX
  11438.     sprintf(line,"LONG_MAX=%d",LONG_MAX); /* SAFE */
  11439. #endif /* LONG_MAX */
  11440. #ifdef CKFLOAT
  11441.     sprintf(line,"float=%ld",sizeof(float)); /* SAFE */
  11442.     if (!prtopt(&lines,line)) return(0);
  11443.     sprintf(line,"double=%ld",sizeof(double)); /* SAFE */
  11444.     if (!prtopt(&lines,line)) return(0);
  11445. #ifdef FNFLOAT
  11446.     if (!prtopt(&lines,"")) return(0);    /* Start a new section */
  11447.     if (!prtopt(&lines,"floating-point:")) return(0);
  11448.     sprintf(line,"precision=%d",fp_digits); /* SAFE */
  11449.     if (!prtopt(&lines,line)) return(0);
  11450.     sprintf(line,"rounding=%d",fp_rounding); /* SAFE */
  11451.     if (!prtopt(&lines,line)) return(0);
  11452. #endif /* FNFLOAT */
  11453. #endif /* CKFLOAT */
  11454.  
  11455.     prtopt(&lines,"");
  11456.     return(0);
  11457. }
  11458. #endif /* NOSHOW */
  11459. #endif /* NOICP */
  11460.