home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku206.zip / ckuus5.c < prev    next >
C/C++ Source or Header  |  2002-10-18  |  383KB  |  11,709 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, 2002,
  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 KUI
  69. #include "ikui.h"
  70. #endif /* KUI */
  71. #ifdef putchar
  72. #undef putchar
  73. #endif /* putchar */
  74. #define putchar(x) conoc(x)
  75. extern int cursor_save ;
  76. extern bool cursorena[] ;
  77. #endif /* OS2 */
  78.  
  79. /* For formatted screens, "more?" prompting, etc. */
  80.  
  81. #ifdef FT18
  82. #define isxdigit(c) isdigit(c)
  83. #endif /* FT18 */
  84.  
  85. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  86. #ifdef putchar
  87. #undef putchar
  88. #endif /* putchar */
  89. #define putchar(x) conoc(x)
  90. #ifdef getchar
  91. #undef getchar
  92. #endif /* getchar */
  93. #define getchar(x) coninc(0)
  94. #endif /* STRATUS */
  95.  
  96. /* External variables */
  97.  
  98. extern int carrier, cdtimo, local, quiet, backgrd, bgset, sosi, suspend,
  99.   binary, escape, xargs, flow, cmdmsk, duplex, ckxech, seslog, what,
  100.   inserver, diractive, tlevel, cwdf, nfuncs, msgflg, remappd, hints, mdmtyp,
  101.   zincnt, cmask, rcflag, success, xitsta, pflag, tnlm, tn_nlm, xitwarn,
  102.   debses, xaskmore, parity, saveask, wasclosed, whyclosed, cdactive,
  103.   rcdactive;
  104.  
  105. #ifdef LOCUS
  106. extern int locus, autolocus;
  107. #endif /* LOCUS */
  108.  
  109. #ifndef NOMSEND
  110. extern int addlist;
  111. #endif /* NOMSEND */
  112.  
  113. #ifdef CK_SPEED
  114. extern int prefixing;
  115. #endif /* CK_SPEED */
  116.  
  117. extern int g_matchdot;
  118.  
  119. #ifdef RECURSIVE
  120. extern int recursive;
  121. #endif /* RECURSIVE */
  122. extern int xfiletype;
  123.  
  124. #ifdef IKSDCONF
  125. extern char * iksdconf;
  126. extern int iksdcf;
  127. #endif /* IKSDCONF */
  128.  
  129. #ifdef CK_RECALL
  130. extern int on_recall;
  131. #endif /* CK_RECALL */
  132.  
  133. extern int ngetpath, exitonclose;
  134. extern char * getpath[];
  135. extern CHAR * epktmsg;
  136.  
  137. extern char * snd_move;
  138. extern char * snd_rename;
  139. extern char * rcv_move;
  140. extern char * rcv_rename;
  141. extern char * g_snd_move;
  142. extern char * g_snd_rename;
  143. extern char * g_rcv_move;
  144. extern char * g_rcv_rename;
  145.  
  146. extern char * nm[];
  147.  
  148. #ifdef CK_UTSNAME
  149. extern char unm_mch[];
  150. extern char unm_mod[];
  151. extern char unm_nam[];
  152. extern char unm_rel[];
  153. extern char unm_ver[];
  154. #endif /* CK_UTSNAME */
  155.  
  156. #ifndef NOPUSH
  157. #ifndef NOFRILLS
  158. extern char editor[];
  159. extern char editfile[];
  160. extern char editopts[];
  161. #ifdef BROWSER
  162. extern char browser[];
  163. extern char browsopts[];
  164. extern char browsurl[];
  165. #endif /* BROWSER */
  166. #endif /*  NOFRILLS */
  167. #endif /* NOPUSH */
  168.  
  169. #ifndef NOSERVER
  170. extern char * x_user, * x_passwd, * x_acct;
  171. #endif /* NOSERVER */
  172.  
  173. #ifdef CKLOGDIAL
  174. extern int dialog;
  175. extern char diafil[];
  176. #endif /* CKLOGDIAL */
  177.  
  178. #ifdef CKROOT
  179. extern int ckrooterr;
  180. #endif /* CKROOT */
  181.  
  182. #ifndef NOSPL
  183. extern int cfilef, xxdot;
  184. extern char cmdfil[];
  185.  
  186. struct localvar * localhead[CMDSTKL];
  187. struct localvar * localtail = NULL;
  188. struct localvar * localnext = NULL;
  189.  
  190. _PROTOTYP( VOID shosexp, (void) );
  191. _PROTOTYP( static VOID shoinput, (void) );
  192. _PROTOTYP( static char gettok,   (void) );
  193. _PROTOTYP( static VOID factor,   (void) );
  194. _PROTOTYP( static VOID term,     (void) );
  195. _PROTOTYP( static VOID termp,    (void) );
  196. _PROTOTYP( static VOID exprp,    (void) );
  197. _PROTOTYP( static VOID expr,     (void) );
  198. _PROTOTYP( static VOID simple,   (void) );
  199. _PROTOTYP( static VOID simpler,  (void) );
  200. _PROTOTYP( static VOID simplest, (void) );
  201. _PROTOTYP( static long xparse,   (void) );
  202. #endif /* NOSPL */
  203. #ifndef NOSHOW
  204. _PROTOTYP( int sho_iks, (void) );
  205. #endif /* NOSHOW */
  206.  
  207. #ifdef MAC
  208. char * ckprompt = "Mac-Kermit>";        /* Default prompt for Macintosh */
  209. char * ikprompt = "IKSD>";
  210. #else  /* Not MAC */
  211. #ifdef NOSPL
  212. #ifdef OS2
  213. char * ckprompt = "K-95> ";             /* Default prompt for Win32 */
  214. char * ikprompt = "IKSD> ";
  215. #else
  216. char * ckprompt = "C-Kermit>";
  217. char * ikprompt = "IKSD>";
  218. #endif /* NT */
  219. #else  /* NOSPL */
  220. #ifdef OS2
  221. /* Default prompt for OS/2 and Win32 */
  222. #ifdef NT
  223. char * ckprompt = "[\\freplace(\\flongpath(\\v(dir)),/,\\\\)] K-95> ";
  224. char * ikprompt = "[\\freplace(\\flongpath(\\v(dir)),/,\\\\)] IKSD> ";
  225. #else  /* NT */
  226. char * ckprompt = "[\\freplace(\\v(dir),/,\\\\)] K-95> ";
  227. char * ikprompt = "[\\freplace(\\v(dir),/,\\\\)] IKSD> ";
  228. #endif /* NT */
  229. #else  /* OS2 */
  230. #ifdef VMS
  231. char * ckprompt = "\\v(dir) C-Kermit>"; /* Default prompt VMS */
  232. char * ikprompt = "\\v(dir) IKSD>";
  233. #else
  234. char * ckprompt = "(\\v(dir)) C-Kermit>"; /* Default prompt for others */
  235. char * ikprompt = "(\\v(dir)) IKSD>";
  236. #endif /* VMS */
  237. #endif /* NT */
  238. #endif /* NOSPL */
  239. #endif /* MAC */
  240.  
  241. #ifndef CCHMAXPATH
  242. #define CCHMAXPATH 257
  243. #endif /* CCHMAXPATH */
  244. char inidir[CCHMAXPATH] = { NUL, NUL }; /* Directory INI file executed from */
  245.  
  246. #ifdef TNCODE
  247. extern int tn_b_nlm;                    /* TELNET BINARY newline mode */
  248. #endif /* TNCODE */
  249.  
  250. #ifndef NOKVERBS
  251. extern struct keytab kverbs[];          /* Table of \Kverbs */
  252. extern int nkverbs;                     /* Number of \Kverbs */
  253. #endif /* NOKVERBS */
  254.  
  255. #ifndef NOPUSH
  256. extern int nopush;
  257. #endif /* NOPUSH */
  258.  
  259. #ifdef CK_RECALL
  260. extern int cm_recall;
  261. #endif /* CK_RECALL */
  262.  
  263. extern char *ccntab[];
  264.  
  265. /* Printer stuff */
  266.  
  267. extern char *printername;
  268. extern int printpipe;
  269. #ifdef BPRINT
  270. extern int printbidi, pportparity, pportflow;
  271. extern long pportspeed;
  272. #endif /* BPRINT */
  273.  
  274. #ifdef OS2
  275. _PROTOTYP (int os2getcp, (void) );
  276. _PROTOTYP (int os2getcplist, (int *, int) );
  277. #ifdef OS2MOUSE
  278. extern int tt_mouse;
  279. #endif /* OS2MOUSE */
  280. extern int tt_update, tt_updmode, updmode;
  281. #ifndef IKSDONLY
  282. extern int tt_status[];
  283. #endif /* IKSDONLY */
  284. #ifdef PCFONTS
  285. extern struct keytab term_font[];
  286. #else
  287. #ifdef KUI
  288. extern struct keytab * term_font;
  289. #endif /* KUI */
  290. #endif /* PCFONTS */
  291. extern int ntermfont, tt_font, tt_font_size;
  292. extern unsigned char colornormal, colorunderline, colorstatus,
  293.     colorhelp, colorselect, colorborder, colorgraphic, colordebug,
  294.     colorreverse, colorcmd, coloritalic;
  295. extern int priority;
  296. extern struct keytab prtytab[];
  297. extern int nprty;
  298. char * cmdmac = NULL;
  299. #endif /* OS2 */
  300.  
  301. #ifdef VMS
  302. _PROTOTYP (int zkermini, (char *, int, char *) );
  303. #endif /* VMS */
  304.  
  305. extern long vernum;
  306. extern int inecho, insilence, inbufsize, nvars, inintr;
  307. extern char *protv, *fnsv, *cmdv, *userv, *ckxv, *ckzv, *ckzsys, *xlav,
  308.  *cknetv, *clcmds;
  309. #ifdef OS2
  310. extern char *ckyv;
  311. #endif /* OS2 */
  312. #ifdef CK_AUTHENTICATION
  313. extern char * ckathv;
  314. #endif /* CK_AUTHENTICATION */
  315. #ifdef CK_SSL
  316. extern char * cksslv;
  317. #endif /* CK_SSL */
  318. #ifdef CK_ENCRYPTION
  319. #ifndef CRYPT_DLL
  320. extern char * ckcrpv;
  321. #endif /* CRYPT_DLL */
  322. #endif /* CK_ENCRYPTION */
  323.  
  324. #ifdef TNCODE
  325. extern char *cktelv;
  326. #endif /* TNCODE */
  327. #ifndef NOFTP
  328. #ifndef SYSFTP
  329. extern char * ckftpv;
  330. #endif /* SYSFTP */
  331. #endif /* NOFTP */
  332.  
  333. extern int srvidl;
  334.  
  335. #ifdef OS2
  336. extern char *ckonetv;
  337. extern int interm;
  338. #ifdef CK_NETBIOS
  339. extern char *ckonbiv;
  340. #endif /* CK_NETBIOS */
  341. #ifdef OS2MOUSE
  342. extern char *ckomouv;
  343. #endif /* OS2MOUSE */
  344. #endif /* OS2 */
  345.  
  346. #ifndef NOLOCAL
  347. extern char *connv;
  348. #endif /* NOLOCAL */
  349. #ifndef NODIAL
  350. extern char *dialv;
  351. #endif /* NODIAL */
  352. #ifndef NOSCRIPT
  353. extern char *loginv;
  354. extern int secho;
  355. #endif /* NOSCRIPT */
  356.  
  357. #ifndef NODIAL
  358. extern int nmdm, dirline;
  359. extern struct keytab mdmtab[];
  360. #endif /* NODIAL */
  361.  
  362. extern int network, nettype, ttnproto;
  363.  
  364. #ifdef OS2
  365. #ifndef NOTERM
  366. /* SET TERMINAL items... */
  367. extern int tt_type, tt_arrow, tt_keypad, tt_wrap, tt_answer, tt_scrsize[];
  368. extern int tt_bell, tt_roll[], tt_ctstmo, tt_cursor, tt_pacing, tt_type_mode;
  369. extern char answerback[];
  370. extern struct tt_info_rec tt_info[];    /* Indexed by terminal type */
  371. extern int max_tt;
  372. #endif /* NOTERM */
  373. #endif /* OS2 */
  374.  
  375. _PROTOTYP( VOID shotrm, (void) );
  376. _PROTOTYP( int shofea, (void) );
  377.  
  378. #ifdef OS2
  379. extern int tt_rows[], tt_cols[];
  380. #else /* OS2 */
  381. extern int tt_rows, tt_cols;
  382. #endif /* OS2 */
  383. extern int cmd_rows, cmd_cols;
  384.  
  385. #ifdef CK_TMPDIR
  386. extern int f_tmpdir;                    /* Directory changed temporarily */
  387. extern char savdir[];                   /* Temporary directory */
  388. #endif /* CK_TMPDIR */
  389.  
  390. #ifndef NOLOCAL
  391. extern int tt_crd, tt_escape;
  392. #endif /* NOLOCAL */
  393.  
  394. #ifndef NOCSETS
  395. extern int language, nfilc, tcsr, tcsl, tcs_transp, fcharset;
  396. extern struct keytab fcstab[];
  397. extern struct csinfo fcsinfo[];
  398. #ifndef MAC
  399. extern struct keytab ttcstab[];
  400. #endif /* MAC */
  401. #endif /* NOCSETS */
  402.  
  403. extern long speed;
  404.  
  405. #ifndef NOXMIT
  406. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  407. extern char xmitbuf[];
  408. #endif /* NOXMIT */
  409.  
  410. extern char **xargv, *versio, *ckxsys, *dftty, *lp;
  411.  
  412. #ifdef DCMDBUF
  413. extern char *cmdbuf, *atmbuf;           /* Command buffers */
  414. #ifndef NOSPL
  415. extern char *savbuf;                    /* Command buffers */
  416. #endif /* NOSPL */
  417. #else
  418. extern char cmdbuf[], atmbuf[];         /* Command buffers */
  419. #ifndef NOSPL
  420. extern char savbuf[];                   /* Command buffers */
  421. #endif /* NOSPL */
  422. #endif /* DCMDBUF */
  423.  
  424. extern char toktab[], ttname[], psave[];
  425. extern CHAR sstate, feol;
  426. extern int cmflgs, techo, repars, ncmd;
  427. extern struct keytab cmdtab[];
  428.  
  429. #ifndef NOSETKEY
  430. KEY *keymap;
  431. #ifndef OS2
  432. #define mapkey(x) keymap[x]
  433. #endif /* OS2 */
  434. MACRO *macrotab;
  435. _PROTOTYP( VOID shostrdef, (CHAR *) );
  436. #endif /* NOSETKEY */
  437.  
  438. extern int cmdlvl;
  439.  
  440. #ifndef NOSPL
  441. extern struct mtab *mactab;
  442. extern struct keytab mackey[];
  443. extern struct keytab vartab[], fnctab[], iftab[];
  444. extern int maclvl, nmac, mecho, fndiags, fnerror, fnsuccess, nif;
  445. #endif /* NOSPL */
  446.  
  447. FILE *tfile[MAXTAKE];                   /* TAKE file stack */
  448. char *tfnam[MAXTAKE];
  449. int tfline[MAXTAKE];
  450.  
  451. int topcmd = -1;                        /* cmdtab index of current command */
  452. int havetoken = 0;
  453. extern int dblquo;                      /* Doublequoting enabled */
  454.  
  455. #ifdef DCMDBUF                          /* Initialization filespec */
  456. char *kermrc = NULL;
  457. #else
  458. char kermrcb[KERMRCL];
  459. char *kermrc = kermrcb;
  460. #endif /* DCMDBUF */
  461.  
  462. int noherald = 0;
  463. int cm_retry = 1;                       /* Command retry enabled */
  464. xx_strp xxstring = zzstring;
  465.  
  466. #ifndef NOXFER
  467. extern int displa, bye_active, protocol, pktlog, remfile, rempipe, unkcs,
  468.   keep, lf_opts, fncnv, pktpaus, autodl, xfrcan, xfrchr, xfrnum, srvtim,
  469.   srvdis, query, retrans, streamed, reliable, crunched, timeouts,
  470.   fnrpath, autopath, rpackets, spackets, epktrcvd, srvping;
  471.  
  472. #ifdef CK_AUTODL
  473. extern int inautodl, cmdadl;
  474. #endif /* CK_AUTODL */
  475.  
  476. #ifndef NOSERVER
  477. extern int en_asg, en_cwd, en_cpy, en_del, en_dir, en_fin, en_bye, en_ret,
  478.   en_get, en_hos, en_que, en_ren, en_sen, en_set, en_spa, en_typ, en_who,
  479.   en_mai, en_pri, en_mkd, en_rmd, en_xit, en_ena;
  480. #endif /* NOSERVER */
  481.  
  482. extern int atcapr,
  483.   atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,
  484.   attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  485.  
  486. #ifdef STRATUS
  487. extern int atfrmi, atfrmo, atcrei, atcreo, atacti, atacto;
  488. #endif /* STRATUS */
  489.  
  490. #ifdef CK_PERMS
  491. extern int atlpri, atlpro, atgpri, atgpro;
  492. #endif /* CK_PERMS */
  493.  
  494. #ifdef CK_LOGIN
  495. extern char * anonfile;                 /* Anonymous login init file */
  496. extern char * anonroot;                 /* Anonymous file-system root */
  497. extern char * userfile;                 /* Forbidden user file */
  498. extern int isguest;                     /* Flag for anonymous user */
  499. #endif /* CK_LOGIN */
  500. #endif /* NOXFER */
  501.  
  502. #ifdef DCMDBUF
  503. int *xquiet = NULL;
  504. #else
  505. int xquiet[CMDSTKL];
  506. #endif /* DCMDBUF */
  507.  
  508. char * prstring[CMDSTKL];
  509.  
  510. #ifndef NOSPL
  511.  
  512. extern long ck_alarm;
  513. extern char alrm_date[], alrm_time[];
  514.  
  515. /* Local declarations */
  516.  
  517. static int nulcmd = 0;                  /* Flag for next cmd to be ignored */
  518.  
  519. /* Definitions for predefined macros */
  520.  
  521. /* First, the single-line macros, installed with addmac()... */
  522.  
  523. /* IBM-LINEMODE macro */
  524. char *m_ibm = "set parity mark, set dupl half, set handsh xon, set flow none";
  525.  
  526. /* FATAL macro */
  527. char *m_fat = "if def \\%1 echo \\%1, if not = \\v(local) 0 hangup, stop 1";
  528.  
  529. #ifdef CK_SPEED
  530. #ifdef IRIX65
  531. char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
  532. #else
  533. #ifdef IRIX
  534. /* Because of bug in telnet server */
  535. char *m_fast = "set window 30, set rec pack 4000, set send pack 4000,\
  536.  set pref cautious";
  537. #else
  538. #ifdef pdp11
  539. char *m_fast = "set win 3, set rec pack 1024, set prefix cautious";
  540. #else
  541. #ifdef BIGBUFOK
  542. char *m_fast = "set win 30, set rec pack 4000, set prefix cautious";
  543. #else
  544. char *m_fast = "set win 4, set rec pack 2200, set prefix cautious";
  545. #endif /* BIGBUFOK */
  546. #endif /* IRIX */
  547. #endif /* IRIX65 */
  548. #endif /* pdp11 */
  549. #ifdef pdp11
  550. char *m_cautious = "set win 2, set rec pack 512, set prefixing cautious";
  551. #else
  552. char *m_cautious = "set win 4, set rec pack 1000, set prefixing cautious";
  553. #endif /* pdp11 */
  554. char *m_robust = "set win 1, set rec pack 90, set prefixing all, \
  555. set reliable off, set clearchannel off";
  556. #else
  557. #ifdef BIGBUFOK
  558. #ifdef IRIX65
  559. char *m_fast = "set win 30, set rec pack 4000";
  560. #else
  561. #ifdef IRIX
  562. char *m_fast = "set win 30, set rec pack 4000, set send pack 4000";
  563. #else
  564. char *m_fast = "set win 30, set rec pack 4000";
  565. #endif /* IRIX */
  566. #endif /* IRIX65 */
  567. #else /* Not BIGBUFOK */
  568. char *m_fast = "set win 4, set rec pack 2200";
  569. #endif /* BIGBUFOK */
  570. char *m_cautious = "set win 4, set rec pack 1000";
  571. char *m_robust = "set win 1, set rec pack 90, set reliable off";
  572. #endif /* CK_SPEED */
  573.  
  574. #ifdef VMS
  575. char *m_purge = "run purge \\%*";
  576. #endif /* VMS */
  577.  
  578. #ifdef OS2
  579. char *m_manual = "browse \\v(exedir)docs/manual/kermit95.htm";
  580. #endif /* OS2 */
  581.  
  582. /* Now the multiline macros, defined with addmmac()... */
  583.  
  584. /* FOR macro for \%i-style loop variables (see dofor()...) */
  585.  
  586. char *for_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
  587. "def \\\\\\%1 \\feval(\\%2),:_..top,if \\%5 \\\\\\%1 \\%3 goto _..bot,",
  588. "\\%6,:_..inc,incr \\\\\\%1 \\%4,goto _..top,:_..bot,_putargs},",
  589. "def break goto _..bot, def continue goto _..inc,",
  590. "do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
  591. ""};
  592.  
  593. /* This is the FOR macro when the loop variable is itself a macro */
  594.  
  595. char *foz_def[] = { "_assign _for\\v(cmdlevel) { _getargs,",
  596. "def \\%1 \\feval(\\%2),:_..top,if \\%5 \\%1 \\%3 goto _..bot,",
  597. "\\%6,:_..inc,incr \\%1 \\%4,goto _..top,:_..bot,_putargs},",
  598. "def break goto _..bot, def continue goto _..inc,",
  599. "do _for\\v(cmdlevel) \\%1 \\%2 \\%3 \\%4 { \\%5 },_assign _for\\v(cmdlevel)",
  600. ""};
  601.  
  602. /* WHILE macro */
  603. char *whil_def[] = { "_assign _whi\\v(cmdlevel) {_getargs,",
  604. ":_..inc,\\%1,\\%2,goto _..inc,:_..bot,_putargs},",
  605. "_def break goto _..bot, _def continue goto _..inc,",
  606. "do _whi\\v(cmdlevel),_assign _whi\\v(cmdlevel)",
  607. ""};
  608.  
  609. /* SWITCH macro */
  610. char *sw_def[] = { "_assign _sw_\\v(cmdlevel) {_getargs,",
  611. "_forward \"\\%1\",\\%2,:default,:_..bot,_putargs},_def break goto _..bot,",
  612. "do _sw_\\v(cmdlevel),_assign _sw_\\v(cmdlevel)",
  613. ""};
  614.  
  615. /* XIF macro */
  616. char *xif_def[] = {
  617. "_assign _if\\v(cmdlevel) {_getargs,\\%1,_putargs},",
  618. "do _if\\v(cmdlevel),_assign _if\\v(cmdlevel)",
  619. ""};
  620.  
  621. /*
  622.   Variables declared here for use by other ckuus*.c modules.
  623.   Space is allocated here to save room in ckuusr.c.
  624. */
  625. #ifdef DCMDBUF
  626. struct cmdptr *cmdstk;
  627. int
  628.   *ifcmd  = NULL,
  629.   *count  = NULL,
  630.   *iftest = NULL,
  631.   *intime = NULL,
  632.   *inpcas = NULL,
  633.   *takerr = NULL,
  634.   *merror = NULL;
  635. #else
  636. struct cmdptr cmdstk[CMDSTKL];
  637. int ifcmd[CMDSTKL], count[CMDSTKL], iftest[CMDSTKL], intime[CMDSTKL],
  638.   inpcas[CMDSTKL], takerr[CMDSTKL], merror[CMDSTKL];
  639. #endif /* DCMDBUF */
  640.  
  641. /* Macro stack */
  642.  
  643. #ifdef COMMENT
  644. char *topline = NULL;                   /* Program invocation arg line */
  645. char *m_line[MACLEVEL] = { NULL, NULL }; /* Stack of macro invocation lines */
  646. #endif /* COMMENT */
  647.  
  648. char **m_xarg[MACLEVEL];                /* Pointers to arg vector arrays */
  649. int n_xarg[MACLEVEL];                   /* Sizes of arg vector arrays */
  650. char *m_arg[MACLEVEL][NARGS];           /* Args of each level */
  651. int macargc[MACLEVEL];                  /* Argc of each level */
  652. char *macp[MACLEVEL];                   /* Current position in each macro */
  653. char *macx[MACLEVEL];                   /* Beginning of each macro def */
  654. char *mrval[MACLEVEL];                  /* RETURN value at each level */
  655. int lastcmd[MACLEVEL];                  /* Last command at each level */
  656. int topargc = 0;                        /* Argc at top level */
  657. char **topxarg = NULL;                  /* Argv at top level */
  658. char *toparg[MAXARGLIST+2];
  659.  
  660. /* Global Variables */
  661.  
  662. char *g_var[GVARS+1];                   /* Global \%a..z pointers */
  663. extern char varnam[];                   /* \%x variable name buffer */
  664.  
  665. /* Arrays -- Dimension must be 'z' - ARRAYBASE + 1 */
  666. /* Note: a_link[x] < 0 means no link; >= 0 is a link */
  667.  
  668. char **a_ptr[32];                       /* Array pointers, for arrays a-z */
  669. int a_dim[32];                          /* Dimensions for each array */
  670. int a_link[32];                         /* Link (index of linked-to-array) */
  671.  
  672. char **aa_ptr[CMDSTKL][32];             /* Array stack for automatic arrays */
  673. int aa_dim[CMDSTKL][32];                /* Dimensions for each array */
  674.  
  675. /* INPUT command buffers and variables */
  676.  
  677. char * inpbuf = NULL;                   /* Buffer for INPUT and REINPUT */
  678. extern char * inpbp;                    /* Global/static pointer to it  */
  679. char inchar[2] = { NUL, NUL };          /* Last character that was INPUT */
  680. int  incount = 0;                       /* INPUT character count */
  681. extern int instatus;                    /* INPUT status */
  682. static char * i_text[] = {              /* INPUT status text */
  683.     "success", "timeout", "interrupted", "internal error", "i/o error"
  684. };
  685.  
  686. char lblbuf[LBLSIZ];                    /* Buffer for labels */
  687.  
  688. #else  /* NOSPL */
  689.  
  690. int takerr[MAXTAKE];
  691. #endif /* NOSPL */
  692.  
  693. static char *prevdir = NULL;
  694.  
  695. int pacing = 0;                         /* OUTPUT pacing */
  696.  
  697. char *tp;                               /* Temporary buffer pointer */
  698.  
  699. int timelimit = 0, asktimer = 0;        /* Timers for time-limited commands */
  700.  
  701. #ifdef CK_APC                           /* Application Program Command (APC) */
  702. int apcactive = APC_INACTIVE;
  703. int apcstatus = APC_OFF;                /* OFF by default everywhere */
  704. #ifdef DCMDBUF
  705. char *apcbuf;
  706. #else
  707. char apcbuf[APCBUFLEN];
  708. #endif /* DCMDBUF */
  709. #endif /* CK_APC */
  710.  
  711. extern char pktfil[],
  712. #ifdef DEBUG
  713.   debfil[],
  714. #endif /* DEBUG */
  715. #ifdef TLOG
  716.   trafil[],
  717. #endif /* TLOG */
  718.   sesfil[];
  719.  
  720. #ifndef NOFRILLS
  721. extern int rmailf, rprintf;             /* REMOTE MAIL & PRINT items */
  722. extern char optbuf[];
  723. #endif /* NOFRILLS */
  724.  
  725. extern int noinit;            /* Flat to skip init file */
  726.  
  727. #ifndef NOSPL
  728. static struct keytab kcdtab[] = {    /* Symbolic directory names */
  729. #ifdef NT
  730.     { "appdata",  VN_APPDATA,   0 },
  731.     { "common",   VN_COMMON,    0 },
  732.     { "desktop",  VN_DESKTOP,   0 },
  733. #endif /* NT */
  734.     { "download", VN_DLDIR,     0 },
  735. #ifdef OS2ORUNIX
  736.     { "exedir",   VN_EXEDIR,    0 },
  737. #endif /* OS2ORUNIX */
  738.     { "home",     VN_HOME,      0 },
  739.     { "inidir",   VN_INI,       0 },
  740. #ifdef UNIX
  741.     { "lockdir",  VN_LCKDIR,    0 },
  742. #endif /* UNIX */
  743. #ifdef NT
  744.     { "personal", VN_PERSONAL,  0 },
  745. #endif /* NT */
  746.     { "startup",  VN_STAR,      0 },
  747.     { "textdir",  VN_TXTDIR,    0 },
  748.     { "tmpdir",   VN_TEMP,      0 }
  749. };
  750. static int nkcdtab = (sizeof(kcdtab) / sizeof(struct keytab));
  751. #endif /* NOSPL */
  752.  
  753. #ifndef NOSPL
  754. _PROTOTYP( VOID freelocal, (int) );
  755. _PROTOTYP( static long expon, (long, long) );
  756. _PROTOTYP( static long gcd, (long, long) );
  757. _PROTOTYP( static long fact, (long) );
  758.  
  759. int                     /* Initialize macro data structures. */
  760. macini() {              /* Allocate mactab and preset the first element. */
  761.     int i;
  762.     if (!(mactab = (struct mtab *) malloc(sizeof(struct mtab) * MAC_MAX)))
  763.       return(-1);
  764.     mactab[0].kwd = NULL;
  765.     mactab[0].mval = NULL;
  766.     mactab[0].flgs = 0;
  767.     for (i = 0; i < MACLEVEL; i++)
  768.       localhead[i] = NULL;
  769.     return(0);
  770. }
  771. #endif /* NOSPL */
  772.  
  773. /*  C M D S R C  --  Returns current command source  */
  774.  
  775. /*  0 = top level, 1 = file, 2 = macro, -1 = error (shouldn't happen) */
  776.  
  777. /*
  778.   As of 19 Aug 2000 this routine is obsolete.  The scalar global variable
  779.   xcmdsrc can be checked instead to save the overhead of a function call.
  780. */
  781. int
  782. cmdsrc() {
  783. #ifdef COMMENT
  784.     return(xcmdsrc);
  785. #else
  786. #ifndef NOSPL
  787.     if (cmdlvl == 0)
  788.       return(0);
  789.     else if (cmdstk[cmdlvl].src == CMD_MD)
  790.       return(2);
  791.     else if (cmdstk[cmdlvl].src == CMD_TF)
  792.       return(1);
  793.     else
  794.       return(-1);
  795. #else
  796.     if (tlevel < 0)
  797.       return(0);
  798.     else
  799.       return(1);
  800. #endif /* NOSPL */
  801. #endif /* COMMENT */
  802. }
  803.  
  804. /*  C M D I N I  --  Initialize the interactive command parser  */
  805.  
  806. static int cmdinited = 0;               /* Command parser initialized */
  807. extern int cmdint;                      /* Interrupts are allowed */
  808. #ifdef CK_AUTODL
  809. int cmdadl = 1;                         /* Autodownload */
  810. #else
  811. int cmdadl = 0;
  812. #endif /* CK_AUTODL */
  813.  
  814. char * k_info_dir = NULL;               /* Where to find text files */
  815. #ifdef UNIX
  816. static char * txtdir[] = {
  817.     "/usr/local/doc/",                  /* Linux, SunOS, ... */
  818.     "/usr/share/lib/",                  /* HP-UX 10.xx... */
  819.     "/usr/share/doc/",                  /* Other possibilities... */
  820.     "/usr/local/lib/",                  /* NOTE: Each of these is tried */
  821.     "/usr/local/share/",                /* as is, and also with a kermit */
  822.     "/usr/local/share/doc/",            /* subdirectory. */
  823.     "/usr/local/share/lib/",
  824.     "/opt/kermit/",                     /* Solaris */
  825.     "/opt/kermit/doc/",
  826.     "/opt/",
  827.     "/usr/doc/",
  828.     "/doc/",
  829.     ""
  830. };
  831. #endif /* UNIX */
  832.  
  833. /*
  834.   lookup() cache to speed up script execution.
  835.  
  836.   This is a static cache.  Items are stored in decreasing frequency of
  837.   reference based on statistics from a range of scripts.  This gives
  838.   better performance than a dynamic cache, which would require a lot more
  839.   code and also would require system-dependent elements including system
  840.   calls (e.g. to get subsecond times for entry aging).
  841. */
  842. #ifdef USE_LUCACHE                      /* Set in ckuusr.h */
  843. #define LUCACHE 32                      /* Change this to reduce cache size */
  844. int lusize = 0;
  845. char * lucmd[LUCACHE];
  846. int luval[LUCACHE];
  847. int luidx[LUCACHE];
  848. struct keytab * lutab[LUCACHE];
  849. #endif /* USE_LUCACHE */
  850.  
  851. static VOID
  852. luinit() {                              /* Initialize lookup() cache */
  853.     int x, y;
  854.  
  855. #ifdef USE_LUCACHE
  856.     x = lookup(cmdtab,"if",ncmd,&y);
  857.     lucmd[lusize] = "if";
  858.     luval[lusize] = x;
  859.     luidx[lusize] = y;
  860.     lutab[lusize] = cmdtab;
  861.     if (++lusize > LUCACHE) return;
  862.  
  863.     x = lookup(iftab,"not",nif,&y);
  864.     lucmd[lusize] = "not";
  865.     luval[lusize] = x;
  866.     luidx[lusize] = y;
  867.     lutab[lusize] = iftab;
  868.     if (++lusize > LUCACHE) return;
  869.  
  870.     x = lookup(vartab,"cmdlevel",nvars,&y);
  871.     lucmd[lusize] = "cmdlevel";
  872.     luval[lusize] = x;
  873.     luidx[lusize] = y;
  874.     lutab[lusize] = vartab;
  875.     if (++lusize > LUCACHE) return;
  876.  
  877.     x = lookup(cmdtab,"goto",ncmd,&y);
  878.     lucmd[lusize] = "goto";
  879.     luval[lusize] = x;
  880.     luidx[lusize] = y;
  881.     lutab[lusize] = cmdtab;
  882.     if (++lusize > LUCACHE) return;
  883.  
  884.     x = lookup(iftab,">",nif,&y);
  885.     lucmd[lusize] = ">";
  886.     luval[lusize] = x;
  887.     luidx[lusize] = y;
  888.     lutab[lusize] = iftab;
  889.     if (++lusize > LUCACHE) return;
  890.  
  891.     x = lookup(cmdtab,"incr",ncmd,&y);
  892.     lucmd[lusize] = "incr";
  893.     luval[lusize] = x;
  894.     luidx[lusize] = y;
  895.     lutab[lusize] = cmdtab;
  896.     if (++lusize > LUCACHE) return;
  897.  
  898.     x = lookup(cmdtab,"def",ncmd,&y);
  899.     lucmd[lusize] = "def";
  900.     luval[lusize] = x;
  901.     luidx[lusize] = y;
  902.     lutab[lusize] = cmdtab;
  903.     if (++lusize > LUCACHE) return;
  904.  
  905.     x = lookup(cmdtab,"_assign",ncmd,&y);
  906.     lucmd[lusize] = "_assign";
  907.     luval[lusize] = x;
  908.     luidx[lusize] = y;
  909.     lutab[lusize] = cmdtab;
  910.     if (++lusize > LUCACHE) return;
  911.  
  912.     x = lookup(cmdtab,"echo",ncmd,&y);
  913.     lucmd[lusize] = "echo";
  914.     luval[lusize] = x;
  915.     luidx[lusize] = y;
  916.     lutab[lusize] = cmdtab;
  917.     if (++lusize > LUCACHE) return;
  918.  
  919.     x = lookup(fnctab,"eval",nfuncs,&y);
  920.     lucmd[lusize] = "eval";
  921.     luval[lusize] = x;
  922.     luidx[lusize] = y;
  923.     lutab[lusize] = fnctab;
  924.     if (++lusize > LUCACHE) return;
  925.  
  926.     x = lookup(fnctab,"lit",nfuncs,&y);
  927.     lucmd[lusize] = "lit";
  928.     luval[lusize] = x;
  929.     luidx[lusize] = y;
  930.     lutab[lusize] = fnctab;
  931.     if (++lusize > LUCACHE) return;
  932.  
  933.     x = lookup(cmdtab,"do",ncmd,&y);
  934.     lucmd[lusize] = "do";
  935.     luval[lusize] = x;
  936.     luidx[lusize] = y;
  937.     lutab[lusize] = cmdtab;
  938.     if (++lusize > LUCACHE) return;
  939.  
  940.     x = lookup(cmdtab,"_getargs",ncmd,&y);
  941.     lucmd[lusize] = "_getargs";
  942.     luval[lusize] = x;
  943.     luidx[lusize] = y;
  944.     lutab[lusize] = cmdtab;
  945.     if (++lusize > LUCACHE) return;
  946.  
  947.     x = lookup(iftab,"<",nif,&y);
  948.     lucmd[lusize] = "<";
  949.     luval[lusize] = x;
  950.     luidx[lusize] = y;
  951.     lutab[lusize] = iftab;
  952.     if (++lusize > LUCACHE) return;
  953.  
  954.     x = lookup(cmdtab,"_putargs",ncmd,&y);
  955.     lucmd[lusize] = "_putargs";
  956.     luval[lusize] = x;
  957.     luidx[lusize] = y;
  958.     lutab[lusize] = cmdtab;
  959.     if (++lusize > LUCACHE) return;
  960.  
  961.     x = lookup(cmdtab,"asg",ncmd,&y);
  962.     lucmd[lusize] = "asg";
  963.     luval[lusize] = x;
  964.     luidx[lusize] = y;
  965.     lutab[lusize] = cmdtab;
  966.     if (++lusize > LUCACHE) return;
  967.  
  968.     x = lookup(cmdtab,"else",ncmd,&y);
  969.     lucmd[lusize] = "else";
  970.     luval[lusize] = x;
  971.     luidx[lusize] = y;
  972.     lutab[lusize] = cmdtab;
  973. #endif /* USE_LUCACHE */
  974. }
  975.  
  976. VOID
  977. cmdini() {
  978.     int i = 0, x = 0, y = 0, z = 0, skip = 0;
  979.     char * p;
  980. #ifdef TTSPDLIST
  981.     long * ss = NULL;
  982.     extern int nspd;
  983.     extern struct keytab * spdtab;
  984. #endif /* TTSPDLIST */
  985.  
  986. #ifndef NOSPL
  987. /*
  988.   On stack to allow recursion!
  989. */
  990.     char vnambuf[VNAML];                /* Buffer for variable names */
  991. #endif /* NOSPL */
  992.  
  993.     if (cmdinited)                      /* Already initialized */
  994.       return;                           /* Don't do it again */
  995.  
  996.     for (i = 0; i < CMDSTKL; i++)       /* Prompt strings for each */
  997.       prstring[i] = NULL;               /* command level */
  998.  
  999. #ifndef NOCSETS
  1000.     p = getenv("K_CHARSET");            /* Set default file character set */
  1001.     if (p) {                            /* from environment */
  1002.         x = lookup(fcstab,p,nfilc,&y);
  1003.         if (x > -1)
  1004.           fcharset = x;
  1005.     }
  1006. #endif /* NOCSETS */
  1007.  
  1008.     p = getenv("K_INFO_DIRECTORY");     /* Find Kermit info directory */
  1009.     if (p && *p && strlen(p) <= CKMAXPATH)
  1010.       makestr(&k_info_dir,p);
  1011.     if (!k_info_dir) {
  1012.         p = getenv("K_INFO_DIR");
  1013.         if (p && *p && strlen(p) <= CKMAXPATH)
  1014.           makestr(&k_info_dir,p);
  1015.     }
  1016. #ifdef UNIX
  1017.     if (k_info_dir) {                   /* Look for Kermit docs directory */
  1018.         if (zchki(k_info_dir) == -2) {
  1019.             char xbuf[CKMAXPATH+32], *s = "";
  1020.             if (ckrchar(k_info_dir) != '/')
  1021.               s = "/";
  1022.             ckmakmsg(xbuf,CKMAXPATH+32,k_info_dir,s,"ckubwr.txt",NULL);
  1023.             if (zchki(xbuf) < 0)
  1024.               makestr(&k_info_dir,NULL);
  1025.         }
  1026.     }
  1027.     if (!k_info_dir) {
  1028.         char xbuf[CKMAXPATH+32];
  1029.         int i;
  1030.         for (i = 0; *(txtdir[i]); i++) {
  1031.             ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"ckubwr.txt",NULL,NULL);
  1032.             if (zchki(xbuf) > 0) {
  1033.                 makestr(&k_info_dir,txtdir[i]);
  1034.                 debug(F110,"k_info_dir 1",k_info_dir,0);
  1035.                 break;
  1036.             }
  1037.             ckmakmsg(xbuf,CKMAXPATH+32,
  1038.                      txtdir[i],"kermit/","ckubwr.txt",NULL);
  1039.             if (zchki(xbuf) > 0) {
  1040.                 ckmakmsg(xbuf,CKMAXPATH+32,txtdir[i],"kermit/",NULL,NULL);
  1041.                 makestr(&k_info_dir,xbuf);
  1042.                 debug(F110,"k_info_dir 2",k_info_dir,0);
  1043.                 break;
  1044.             }
  1045.         }
  1046.         if (k_info_dir) {               /* Make sure it ends with "/" */
  1047.             if (ckrchar(k_info_dir) != '/') {
  1048.                 char xbuf[CKMAXPATH+32];
  1049.                 ckmakmsg(xbuf,CKMAXPATH+32,k_info_dir,"/",NULL,NULL);
  1050.                 makestr(&k_info_dir,xbuf);
  1051.             }
  1052.         }
  1053.     }
  1054. #else
  1055. #ifdef OS2
  1056.     {
  1057.         char xdir[CKMAXPATH+8], *s = "";
  1058.         extern char startupdir[];
  1059.         xdir[0] = NUL;
  1060.         if (ckrchar(startupdir) != '/')
  1061.           s = "/";
  1062.         if (strlen(s) + strlen(startupdir) + 5 < CKMAXPATH + 8 )
  1063.           ckmakmsg(xdir,CKMAXPATH+8,s,startupdir,"DOC/",NULL);
  1064.         makestr(&k_info_dir,xdir);
  1065.     }
  1066. #endif /* OS2 */
  1067. #endif /* UNIX */
  1068.  
  1069. #ifdef TTSPDLIST
  1070.     if (!spdtab && (ss = ttspdlist())) { /* Get speed list if necessary */
  1071.         int j, k, m = 0, n;             /* Create sorted keyword table */
  1072.         char buf[16];
  1073.         char * p;
  1074.         if ((spdtab =
  1075.              (struct keytab *) malloc(sizeof(struct keytab) * ss[0]))) {
  1076.             for (i = 1; i <= ss[0]; i++) { /* ss[0] = number of elements */
  1077.                 if (ss[i] < 1L) break;     /* Shouldn't happen */
  1078.                 buf[0] = NUL;              /* Make string */
  1079.                 sprintf(buf,"%ld",ss[i]);  /* SAFE */
  1080.                 if (ss[i] == 8880L)
  1081.                   ckstrncpy(buf,"75/1200",sizeof(buf));
  1082.                 if (ss[i] == 134L)
  1083.                   ckstrncat(buf,".5",16);
  1084.                 n = strlen(buf);
  1085.                 if ((n > 0) && (p = (char *)malloc(n+1))) {
  1086.                     if (m > 0) {        /* Have at least one in list */
  1087.                         for (j = 0;     /* Find slot */
  1088.                              j < m && strcmp(buf,spdtab[j].kwd) > 0;
  1089.                              j++
  1090.                              )
  1091.                           ;
  1092.                         if (j < m) {    /* Must insert */
  1093.                             for (k = m-1; k >= j; k--) { /* Move others down */
  1094.                                 spdtab[k+1].kwd = spdtab[k].kwd;
  1095.                                 spdtab[k+1].flgs = spdtab[k].flgs;
  1096.                                 spdtab[k+1].kwval = spdtab[k].kwval;
  1097.                             }
  1098.                         }
  1099.                     } else              /* First one */
  1100.                       j = 0;
  1101.                     ckstrncpy(p,buf,n+1); /* Add new speed */
  1102.                     spdtab[j].kwd = p;
  1103.                     spdtab[j].flgs = 0;
  1104.                     spdtab[j].kwval = (int) ss[i] / 10;
  1105.                     m++;                /* Count this one */
  1106.                 }
  1107.             }
  1108.         }
  1109.         nspd = m;
  1110.     }
  1111. #endif /* TTSPDLIST */
  1112.  
  1113. #ifndef NOSPL
  1114.     /* Allocate INPUT command buffer */
  1115.     if (!inpbuf) {
  1116.         if (!(inpbuf = (char *) malloc(INPBUFSIZ+1)))
  1117.           fatal("cmdini: no memory for INPUT buffer");
  1118.     }
  1119.     for (x = 0; x < INPBUFSIZ; x++)     /* Initialize it */
  1120.       inpbuf[x] = NUL;
  1121.     inpbp = inpbuf;                     /* Initialize pointer */
  1122.     inbufsize = INPBUFSIZ;              /* and size. */
  1123. #endif /* NOSPL */
  1124.  
  1125. #ifdef DCMDBUF
  1126.     if (cmsetup() < 0) fatal("Can't allocate command buffers!");
  1127.  
  1128. #ifndef NOSPL
  1129.     /* Allocate command stack allowing command parser to call itself */
  1130.  
  1131.     if (!(cmdstk = (struct cmdptr *) malloc(sizeof(struct cmdptr)*CMDSTKL)))
  1132.       fatal("cmdini: no memory for cmdstk");
  1133.     if (!(ifcmd = (int *) malloc(sizeof(int)*CMDSTKL)))
  1134.       fatal("cmdini: no memory for ifcmd");
  1135.     if (!(count = (int *) malloc(sizeof(int)*CMDSTKL)))
  1136.       fatal("cmdini: no memory for count");
  1137.     if (!(iftest = (int *) malloc(sizeof(int)*CMDSTKL)))
  1138.       fatal("cmdini: no memory for iftest");
  1139.     if (!(intime = (int *) malloc(sizeof(int)*CMDSTKL)))
  1140.       fatal("cmdini: no memory for intime");
  1141.     if (!(inpcas = (int *) malloc(sizeof(int)*CMDSTKL)))
  1142.       fatal("cmdini: no memory for inpcas");
  1143.     if (!(takerr = (int *) malloc(sizeof(int)*CMDSTKL)))
  1144.       fatal("cmdini: no memory for takerr");
  1145.     if (!(merror = (int *) malloc(sizeof(int)*CMDSTKL)))
  1146.       fatal("cmdini: no memory for merror");
  1147.     if (!(xquiet = (int *) malloc(sizeof(int)*CMDSTKL)))
  1148.       fatal("cmdini: no memory for xquiet");
  1149.     if (!kermrc)
  1150.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1151.         fatal("cmdini: no memory for kermrc");
  1152. #ifdef CK_APC
  1153. /* Application Program Command buffer */
  1154.     if (!(apcbuf = malloc(APCBUFLEN + 1)))
  1155.         fatal("cmdini: no memory for apcbuf");
  1156. #endif /* CK_APC */
  1157. #endif /* NOSPL */
  1158.  
  1159. /* line[] and tmpbuf[] are the two string buffers used by the command parser */
  1160.  
  1161.     if (!(line = malloc(LINBUFSIZ + 1)))
  1162.         fatal("cmdini: no memory for line");
  1163.     if (!(tmpbuf = malloc(LINBUFSIZ + 1)))
  1164.         fatal("cmdini: no memory for tmpbuf");
  1165. #endif /* DCMDBUF */
  1166.  
  1167. #ifndef NOSPL
  1168. #ifdef CK_MINPUT
  1169.     {                                   /* Initialize MINPUT pointers */
  1170.         int i;
  1171.         extern char *ms[];
  1172.         for (i = 0; i < MINPMAX; i++)
  1173.           ms[i] = NULL;
  1174.     }
  1175. #endif /* CK_MINPUT */
  1176.  
  1177.     if (macini() < 0)                   /* Allocate macro buffers */
  1178.       fatal("Can't allocate macro buffers!");
  1179.  
  1180.     ifcmd[0] = 0;                       /* Command-level related variables. */
  1181.     iftest[0] = 0;                      /* Initialize variables at top level */
  1182.     count[0] = 0;                       /* of stack... */
  1183.     intime[0] = 0;
  1184.     inpcas[0] = 0;
  1185.     takerr[0] = 0;
  1186.     merror[0] = 0;
  1187.     xquiet[0] = quiet;
  1188. #endif /* NOSPL */
  1189.  
  1190. #ifndef NOSPL
  1191.     cmdlvl = 0;                         /* Initialize the command stack */
  1192.     xcmdsrc = CMD_KB;
  1193.     cmdstk[cmdlvl].src = CMD_KB;        /* Source is console */
  1194.     cmdstk[cmdlvl].lvl = 0;             /* Level is 0 */
  1195.     cmdstk[cmdlvl].ccflgs = 0;          /* No flags */
  1196. #endif /* NOSPL */
  1197.  
  1198.     tlevel = -1;                        /* Take file level = keyboard */
  1199.     for (i = 0; i < MAXTAKE; i++)       /* Initialize command file names */
  1200.       tfnam[i] = NULL;
  1201.  
  1202.     cmsetp(ckprompt);                   /* Set up C-Kermit's prompt */
  1203.                                         /* Can't set IKSD prompt here since */
  1204.                                         /* we do not yet know if we are IKSD */
  1205. #ifndef NOSPL
  1206.  
  1207.     initmac();                          /* Initialize macro table */
  1208.  
  1209. /* Predefine built-in one-line macros */
  1210.  
  1211.     addmac("ibm-linemode",m_ibm);       /* IBM-LINEMODE */
  1212.     addmac("fatal",m_fat);              /* FATAL macro */
  1213.     y = addmac("fast",m_fast);          /* FAST macro */
  1214.     addmac("cautious",m_cautious);      /* CAUTIOUS macro */
  1215.     addmac("robust",m_robust);          /* ROBUST macro */
  1216. #ifdef OS2
  1217.     addmac("manual",m_manual);          /* MANUAL macro */
  1218. #endif /* OS2 */
  1219. #ifdef VMS
  1220.     addmac("purge",m_purge);            /* PURGE macro */
  1221. #endif /* VMS */
  1222.  
  1223. /*
  1224.   Predefine built-in multiline macros; these are top-level commands
  1225.   that are implemented internally as macros.  NOTE: When adding a new
  1226.   one of these, remember to update the END and RETURN commands to
  1227.   account for it, or else END and RETURN from within it won't work right.
  1228. */
  1229.     x = addmmac("_forx",for_def);       /* FOR macro */
  1230.     if (x > -1) mactab[x].flgs = CM_INV;
  1231.     x = addmmac("_forz",foz_def);       /* Other FOR macro */
  1232.     if (x > -1) mactab[x].flgs = CM_INV;
  1233.     x = addmmac("_xif",xif_def);        /* XIF macro */
  1234.     if (x > -1) mactab[x].flgs = CM_INV;
  1235.     x = addmmac("_while",whil_def);     /* WHILE macro */
  1236.     if (x > -1) mactab[x].flgs = CM_INV;
  1237.     x = addmmac("_switx",sw_def);       /* SWITCH macro */
  1238.     if (x > -1) mactab[x].flgs = CM_INV;
  1239.  
  1240. /* Fill in command-line argument vector */
  1241.  
  1242.     sprintf(vnambuf,"\\&@[%d]",xargs);  /* SAFE */
  1243.     if (inserver) {                     /* But hidden in IKSD */
  1244.         y = -1;
  1245.         xargs = 0;
  1246.     } else
  1247.       y = arraynam(vnambuf,&x,&z);      /* goes in array \&@[] */
  1248.  
  1249.     tmpbuf[0] = NUL;
  1250.     if (y > -1) {
  1251.         int j = -1;
  1252.         int yy = 0;
  1253.         dclarray((char)x,z);            /* Declare the array */
  1254. #ifndef NOTAKEARGS
  1255.         /* Macro argument vector */
  1256.         sprintf(vnambuf,"\\&_[%d]",z);  /* SAFE */
  1257.         yy = arraynam(vnambuf,&x,&z);   /* goes in array \&_[] */
  1258.         if (yy > -1)                    /* Name is OK */
  1259.           dclarray((char)x,z);          /* Declare the array */
  1260. #endif /* NOTAKEARGS */
  1261.         skip = 0;
  1262.         for (i = 0; i < xargs; i++) {   /* Fill the arrays */
  1263.             sprintf(vnambuf,"\\&@[%d]",i); /* SAFE */
  1264.             addmac(vnambuf,xargv[i]);
  1265.             if (cfilef && i == 0)
  1266.               continue;
  1267. #ifdef KERBANG
  1268.             if (skip) {
  1269.                 j = 0;
  1270.                 skip = 0;
  1271.                 continue;
  1272.             }
  1273. #endif /* KERBANG */
  1274.             if (j < 0 &&                /* Assign items after "=" or "--"*/
  1275.                 (!strcmp(xargv[i],"=") || !strcmp(xargv[i],"--"))
  1276.                 ) {
  1277.                 j = 0;                  /* to \%1..\%9 */
  1278. #ifdef KERBANG
  1279.             } else if (j < 0 &&
  1280.                        (!strcmp(xargv[i],"+") ||
  1281.                         !strncmp(xargv[i],"+ ",2) ||
  1282.                         !strncmp(xargv[i],"+\t",2))
  1283.                         ) {
  1284.                 skip = 1;
  1285.                 continue;
  1286. #endif /* KERBANG */
  1287.             } else if (j > -1) {
  1288.                 j++;
  1289.                 if (j <= 9) {
  1290.                     vnambuf[0] = '\\';
  1291.                     vnambuf[1] = '%';
  1292.                     vnambuf[2] = (char)(j+'0');
  1293.                     vnambuf[3] = NUL;
  1294.                     addmac(vnambuf,xargv[i]);
  1295.                 }
  1296.                 if (yy > -1) {
  1297.                     char c, * p;
  1298.                     int flag = 0;
  1299.                     p = xargv[i];
  1300.                     makestr(&(toparg[j]),p);
  1301.                     while ((c = *p++)) { if (c == SP) { flag++; break; } }
  1302.                     if (flag)
  1303.                       ckstrncat(tmpbuf,"\"",TMPBUFSIZ);
  1304.                     ckstrncat(tmpbuf,xargv[i],TMPBUFSIZ);
  1305.                     if (flag)
  1306.                       ckstrncat(tmpbuf,"\"",TMPBUFSIZ);
  1307.                     ckstrncat(tmpbuf," ",TMPBUFSIZ);
  1308.                 }
  1309.             }
  1310.         }
  1311.         if (cfilef) {
  1312.             addmac("\\%0",cmdfil);
  1313.             if (yy > -1)
  1314.               makestr(&(toparg[0]),cmdfil);
  1315.         } else {
  1316.             addmac("\\%0",xargv[0]);
  1317.             if (yy > -1)
  1318.               makestr(&(toparg[0]),xargv[0]);
  1319.         }
  1320.         if (yy > -1) {
  1321.             topargc = (j < 0) ? 1 : j + 1;
  1322.             topxarg = toparg;
  1323. #ifdef COMMENT
  1324.             /* This needs work */
  1325.             if (!cfilef)
  1326.               makestr(&topline,tmpbuf);
  1327. #endif /* COMMENT */
  1328.         } else {
  1329.             topargc = 0;
  1330.             topxarg = NULL;
  1331.         }
  1332.         a_dim[0] = topargc - 1;
  1333.         a_ptr[0] = topxarg;
  1334.     debug(F111,"a_dim[0]","A",a_dim[0]);
  1335.     }
  1336.     *vnambuf = NUL;
  1337. #endif /* NOSPL */
  1338.  
  1339.     luinit();                           /* Initialize lookup() cache */
  1340.  
  1341. /* Get our home directory now.  This needed in lots of places. */
  1342.  
  1343.     cmdinited = 1;
  1344. }
  1345.  
  1346. #ifdef NT
  1347. _PROTOTYP(char * GetAppData,(int));
  1348. #endif /* NT */
  1349.  
  1350. VOID
  1351. doinit() {
  1352. #ifdef CKROOT
  1353. extern int ckrooterr;
  1354. #endif /* CKROOT */
  1355.     int x = 0, ok = 0;
  1356. #ifdef OS2
  1357.     char * ptr = 0;
  1358. #endif /* OS2 */
  1359.  
  1360.     if (!cmdinited)
  1361.       cmdini();
  1362.  
  1363. #ifdef MAC
  1364.     return;                             /* Mac Kermit has no init file */
  1365.  
  1366. #else /* !MAC */
  1367.  
  1368. /* If skipping init file ('-Y' on Kermit command line), return now. */
  1369.  
  1370.     if (noinit) {
  1371.         kermrc[0] = '\0';
  1372.         inidir[0] = '\0';
  1373. /*
  1374.   But returning from here results in inidir[] never being set to anything.
  1375.   Instead it should be set to wherever the init file *would* have been
  1376.   executed from.  So this bit of code should be removed, and then we should
  1377.   sprinkle "if (noinit)" tests throughout the following code until we have
  1378.   set inidir[], and then return without actually taking the init file.
  1379. */
  1380.         return;
  1381.     }
  1382.  
  1383. #ifdef OS2
  1384. /*
  1385.   The -y init file must be fully specified or in the current directory.
  1386.   KERMRC is looked for via INIT, DPATH and PATH in that order.  Finally, our
  1387.   own executable file path is taken and the .EXE suffix is replaced by .INI
  1388.   and this is tried as the initialization file.
  1389. */
  1390. #ifdef CK_LOGIN
  1391.     debug(F101,"doinit inserver","",inserver);
  1392.     debug(F101,"doinit isguest","",isguest);
  1393.     debug(F110,"doinit anonfile",anonfile,0);
  1394.  
  1395.     if (isguest && anonfile) {
  1396.       ckstrncpy(line, anonfile, LINBUFSIZ+1);
  1397.     } else
  1398. #endif /* CK_LOGIN */
  1399.       if (rcflag) {
  1400.           ckstrncpy(line,kermrc,LINBUFSIZ+1);
  1401. #ifdef CK_LOGIN
  1402.       } else if (inserver) {
  1403.           char * appdata = NULL;
  1404. #ifdef NT
  1405.           appdata = GetAppData(1);
  1406.           if ( appdata ) {
  1407.               ckmakmsg(line,LINBUFSIZ+1,appdata,
  1408.                         "Kermit 95/k95.ini",NULL,NULL);
  1409.               if ( zchki(line) < 0 )
  1410.                   line[0] = '\0';
  1411.           }
  1412.           if (line[0] == 0) {
  1413.               appdata = GetAppData(0);
  1414.               if ( appdata ) {
  1415.                   ckmakmsg(line,LINBUFSIZ+1,appdata,
  1416.                             "Kermit 95/k95.ini",NULL,NULL);
  1417.                   if ( zchki(line) < 0 )
  1418.                       line[0] = '\0';
  1419.               }
  1420.           }
  1421. #endif /* NT */
  1422.           if (line[0] == 0) {
  1423.               appdata = zhome();
  1424.               if ( appdata ) {
  1425.                   ckmakmsg(line,LINBUFSIZ+1,appdata,
  1426. #ifdef NT
  1427.                           "k95.ini",
  1428. #else /* NT */
  1429.                           "k2.ini",
  1430. #endif /* NT */
  1431.                            NULL,NULL);
  1432.                   if ( zchki(line) < 0 )
  1433.                       line[0] = '\0';
  1434.               }
  1435.           }
  1436.           debug(F110,"doinit inserver inifile",line,0);
  1437. #endif /* CK_LOGIN */
  1438.     } else {
  1439.         char * env = 0;
  1440. #ifdef NT
  1441.         env = getenv("K95.KSC");
  1442. #else
  1443.         env = getenv("K2.KSC");
  1444. #endif /* NT */
  1445.         if (!env) {
  1446. #ifdef NT
  1447.             env = getenv("K95.INI");
  1448. #else
  1449.             env = getenv("K2.INI");
  1450. #endif /* NT */
  1451.         }
  1452.         if (!env)
  1453.           env = getenv("CKERMIT.INI");
  1454.         if (!env)
  1455.           env = getenv("CKERMIT_INI");
  1456.         line[0] = '\0';
  1457.  
  1458.         debug(F110,"doinit env",env,0);
  1459.         if (env)
  1460.           ckstrncpy(line,env,LINBUFSIZ+1);
  1461.  
  1462. #ifdef NT
  1463.         if (line[0] == 0) {
  1464.             env = GetAppData(1);
  1465.             if ( env ) {
  1466.                 ckmakmsg(line,LINBUFSIZ+1,env,"Kermit 95/k95.ini",NULL,NULL);
  1467.                 if ( zchki(line) < 0 )
  1468.                     line[0] = '\0';
  1469.             }
  1470.         }
  1471.         if (line[0] == 0) {
  1472.             env = GetAppData(0);
  1473.             if ( env ) {
  1474.                 ckmakmsg(line,LINBUFSIZ+1,env,"Kermit 95/k95.ini",NULL,NULL);
  1475.                 if ( zchki(line) < 0 )
  1476.                     line[0] = '\0';
  1477.             }
  1478.         }
  1479. #endif /* NT */
  1480.  
  1481.         if (line[0] == 0) {
  1482.             env = zhome();
  1483.             if ( env ) {
  1484.                 ckmakmsg(line,LINBUFSIZ+1,env,
  1485. #ifdef NT
  1486.                           "k95.ini",
  1487. #else /* NT */
  1488.                           "k2.ini",
  1489. #endif /* NT */
  1490.                           NULL,NULL);
  1491.                 if ( zchki(line) < 0 )
  1492.                     line[0] = '\0';
  1493.             }
  1494.         }
  1495.  
  1496.         if (line[0] == 0)
  1497.           _searchenv(kermrc,"INIT",line);
  1498.         if (line[0] == 0)
  1499.           _searchenv(kermrc,"DPATH",line);
  1500.         if (line[0] == 0)
  1501.           _searchenv(kermrc,"PATH",line);
  1502.         if (line[0] == 0) {
  1503.             char *pgmptr = GetLoadPath();
  1504.             if (pgmptr && strlen(pgmptr) < LINBUFSIZ-8) {
  1505.                 lp = strrchr(pgmptr, '\\');
  1506.                 if (lp) {
  1507.                     strncpy(line, pgmptr, lp - pgmptr);
  1508. #ifdef NT
  1509.                     strcpy(line + (lp - pgmptr), "/k95.ini");
  1510. #else /* NT */
  1511.                     strcpy(line + (lp - pgmptr), "/k2.ini");
  1512. #endif /* NT */
  1513.                 } else {
  1514.                     lp = strrchr(pgmptr, '.');
  1515.                     if (lp) {
  1516.                         strncpy(line, pgmptr, lp - pgmptr);
  1517.                         strcpy(line + (lp - pgmptr), ".ini");
  1518.                     }
  1519.                 }
  1520.             }
  1521.         }
  1522.     }
  1523.  
  1524. #ifdef CKROOT
  1525.     if (!zinroot(line)) {
  1526.         debug(F110,"doinit setroot violation",line,0);
  1527.         return;
  1528.     }
  1529. #endif /* CKROOT */
  1530.  
  1531.     debug(F110,"doinit fopen()",line,0);
  1532.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  1533.         ok = 1;
  1534.         tlevel = 0;
  1535.         tfline[tlevel] = 0;
  1536.         if (tfnam[tlevel] = malloc(strlen(line)+1))
  1537.           strcpy(tfnam[tlevel],line);   /* safe */
  1538. #ifndef NOSPL
  1539.         cmdlvl++;
  1540.         xcmdsrc = CMD_TF;
  1541.         cmdstk[cmdlvl].src = CMD_TF;
  1542.         cmdstk[cmdlvl].lvl = tlevel;
  1543.         cmdstk[cmdlvl].ccflgs = 0;
  1544.         ifcmd[cmdlvl] = 0;
  1545.         iftest[cmdlvl] = 0;
  1546.         count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1547.         intime[cmdlvl] = intime[cmdlvl-1];
  1548.         inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1549.         takerr[cmdlvl] = takerr[cmdlvl-1];
  1550.         merror[cmdlvl] = merror[cmdlvl-1];
  1551.         xquiet[cmdlvl] = quiet;
  1552. #endif /* NOSPL */
  1553.         debug(F110,"doinit init file",line,0);
  1554.     } else {
  1555.         debug(F100,"doinit no init file","",0);
  1556.     }
  1557.     ckstrncpy(kermrc,line,KERMRCL);
  1558.     for (ptr = kermrc; *ptr; ptr++)     /* Convert backslashes to slashes */
  1559.        if (*ptr == '\\')
  1560.          *ptr = '/';
  1561. #else /* not OS2 */
  1562.     lp = line;
  1563.     lp[0] = '\0';
  1564.     debug(F101,"doinit rcflag","",rcflag);
  1565. #ifdef GEMDOS
  1566.     zkermini(line, rcflag, kermrc);
  1567. #else
  1568. #ifdef VMS
  1569.     {
  1570.     int x;
  1571.     x = zkermini(line,LINBUFSIZ,kermrc);
  1572.     debug(F111,"CUSTOM zkermini",line,x);
  1573.     if (x == 0)
  1574.       line[0] = NUL;
  1575.     }
  1576. #else /* not VMS */
  1577. #ifdef CK_LOGIN
  1578.     debug(F101,"doinit isguest","",isguest);
  1579.     if (isguest)
  1580.       ckstrncpy(lp, anonfile ? anonfile : kermrc, LINBUFSIZ);
  1581.     else
  1582. #endif /* CK_LOGIN */
  1583.       if (rcflag) {                     /* If init file name from cmd line */
  1584.           ckstrncpy(lp,kermrc,LINBUFSIZ); /* use it, */
  1585.       } else {                          /* otherwise... */
  1586. #ifdef CK_INI_A                         /* If we've a system-wide init file */
  1587.           /* And it takes precedence over the user's... */
  1588.           ckstrncpy(lp,CK_SYSINI,KERMRCL); /* Use it */
  1589.           if (zchki(lp) < 0) {          /* (if it exists...) */
  1590. #endif /* CK_INI_A */
  1591.               char * homdir;
  1592.               char * env = 0;
  1593.               line[0] = NUL;
  1594.  
  1595.               /* Add support for environment variable */
  1596.               env = getenv("CKERMIT.INI");
  1597.               if (!env)
  1598.                 env = getenv("CKERMIT_INI");
  1599.               if (env)
  1600.                 ckstrncpy(lp,env,KERMRCL);
  1601.  
  1602.               if (lp[0] == 0) {
  1603.                   homdir = zhome();
  1604.                   if (homdir) {         /* Home directory for init file. */
  1605.                       ckstrncpy(lp,homdir,KERMRCL);
  1606. #ifdef STRATUS
  1607.                       ckstrncat(lp,">",KERMRCL);/* VOS dirsep */
  1608. #else
  1609.                       if (lp[0] == '/') ckstrncat(lp,"/",KERMRCL);
  1610. #endif /* STRATUS */
  1611.                   }
  1612.                   ckstrncat(lp,kermrc,KERMRCL);/* Append default file name */
  1613.               }
  1614. #ifdef CK_INI_A
  1615.           }
  1616. #endif /* CK_INI_A */
  1617. #ifdef CK_INI_B                         /* System-wide init defined? */
  1618.           /* But user's ini file takes precedence */
  1619.           if (zchki(lp) < 0)            /* If user doesn't have her own, */
  1620.             ckstrncpy(lp,CK_SYSINI,KERMRCL); /* use system-wide one. */
  1621. #endif /* CK_INI_B */
  1622.       }
  1623. #endif /* VMS */
  1624. #endif /* GEMDOS */
  1625.  
  1626. #ifdef AMIGA
  1627.     reqoff();                           /* Disable requestors */
  1628. #endif /* AMIGA */
  1629.  
  1630. #ifdef USE_CUSTOM
  1631.     /* If no init file was found, execute the customization file */
  1632.     debug(F110,"CUSTOM 1",line,0);
  1633.     if (!line[0] || zchki(line) < 0) {
  1634.     int x;
  1635. #ifdef OS2
  1636.     x = ckmakestr(line,LINBUFSIZ,GetAppData(1),"/","K95CUSTOM.INI",NULL);
  1637.     debug(F111,"CUSTOM 2",line,x);
  1638.     if (zchki(line) < 0) {
  1639.         x = ckmakestr(line,LINBUFSIZ,GetAppData(0),"/","K95USER.INI",NULL);
  1640.         debug(F111,"CUSTOM 3",line,x);
  1641.     }
  1642. #else  /* OS2 */
  1643.     x = ckstrncpy(line,zhome(),LINBUFSIZ);
  1644. #ifndef VMS
  1645.     /* VMS zhome() returns "SYS$LOGIN:" */
  1646.     if (line[x-1] != DIRSEP) {
  1647.         line[x++] = DIRSEP;
  1648.         line[x] = NUL;
  1649.     }
  1650. #endif /* VMS */
  1651.     x = ckstrncat(line,MYCUSTOM,LINBUFSIZ);
  1652.     debug(F111,"CUSTOM 4",line,x);
  1653. #endif /* OS2 */
  1654.     }
  1655.     debug(F110,"CUSTOM 5",line,0);
  1656. #endif /* USE_CUSTOM */
  1657.  
  1658. #ifdef CKROOT
  1659.     if (!zinroot(line)) {
  1660.         debug(F110,"doinit setroot violation",line,0);
  1661.         return;
  1662.     }
  1663. #endif /* CKROOT */
  1664.  
  1665.     debug(F110,"doinit ini file is",line,0);
  1666.     if ((tfile[0] = fopen(line,"r")) != NULL) { /* Try to open init file. */
  1667.         ok = 1;
  1668.         tlevel = 0;
  1669.         tfline[tlevel] = 0;
  1670.         if ((tfnam[tlevel] = malloc(strlen(line)+1)))
  1671.           strcpy(tfnam[tlevel],line);   /* safe */
  1672.  
  1673.         ckstrncpy(kermrc,line,KERMRCL);
  1674.  
  1675. #ifndef NOSPL
  1676.         cmdlvl++;
  1677.         ifcmd[cmdlvl] = 0;
  1678.         iftest[cmdlvl] = 0;
  1679.         count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1680.         intime[cmdlvl] = intime[cmdlvl-1];
  1681.         inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1682.         takerr[cmdlvl] = takerr[cmdlvl-1];
  1683.         merror[cmdlvl] = merror[cmdlvl-1];
  1684.         xquiet[cmdlvl] = quiet;
  1685.         debug(F101,"doinit open ok","",cmdlvl);
  1686.         xcmdsrc = CMD_TF;
  1687.         cmdstk[cmdlvl].src = CMD_TF;
  1688.         cmdstk[cmdlvl].lvl = tlevel;
  1689.         cmdstk[cmdlvl].ccflgs = 0;
  1690. #endif /* NOSPL */
  1691.     } else if (rcflag) {
  1692.         /* Print an error message only if a specific file was asked for. */
  1693.         printf("?%s - %s\n", ck_errstr(), line);
  1694.     }
  1695.  
  1696. #ifdef datageneral
  1697. /* If CKERMIT.INI not found in home directory, look in searchlist */
  1698.     if (/* homdir && */ (tlevel < 0)) {
  1699.         ckstrncpy(lp,kermrc,LINBUFSIZ);
  1700.         if ((tfile[0] = fopen(line,"r")) != NULL) {
  1701.             ok = 1;
  1702.             tlevel = 0;
  1703.             tfline[tlevel] = 0;
  1704.             if (tfnam[tlevel] = malloc(strlen(line)+1))
  1705.               strcpy(tfnam[tlevel],line); /* safe */
  1706. #ifndef NOSPL
  1707.             cmdlvl++;
  1708.             xcmdsrc = CMD_TF;
  1709.             cmdstk[cmdlvl].src = CMD_TF;
  1710.             cmdstk[cmdlvl].lvl = tlevel;
  1711.             cmdstk[cmdlvl].ccflgs = 0;
  1712.             ifcmd[cmdlvl] = 0;
  1713.             iftest[cmdlvl] = 0;
  1714.             count[cmdlvl] =  count[cmdlvl-1]; /* Inherit from previous level */
  1715.             intime[cmdlvl] = intime[cmdlvl-1];
  1716.             inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1717.             takerr[cmdlvl] = takerr[cmdlvl-1];
  1718.             merror[cmdlvl] = merror[cmdlvl-1];
  1719.             xquiet[cmdlvl] = quiet;
  1720. #endif /* NOSPL */
  1721.         }
  1722.     }
  1723. #endif /* datageneral */
  1724.  
  1725. #ifdef AMIGA                            /* Amiga... */
  1726.     reqpop();                           /* Restore requestors */
  1727. #endif /* AMIGA */
  1728. #endif /* OS2 */
  1729. #endif /* MAC */
  1730.  
  1731.     /* Assign value to inidir */
  1732.  
  1733.     if (!ok) {
  1734.         inidir[0] = NUL;
  1735.     } else {
  1736.         ckstrncpy(inidir, kermrc, CCHMAXPATH);
  1737.         x = strlen(inidir);
  1738.         if (x > 0) {
  1739.             int i;
  1740.             for (i = x - 1; i > 0; i-- ) {
  1741.                 if (ISDIRSEP(inidir[i])) {
  1742.                     inidir[i+1] = NUL;
  1743.                     break;
  1744.                 }
  1745.             }
  1746.         }
  1747. #ifdef NT
  1748.         GetShortPathName(inidir,inidir,CCHMAXPATH);
  1749. #endif /* NT */
  1750.     }
  1751. }
  1752.  
  1753. VOID
  1754. doiksdinit() {
  1755. #ifdef CK_SSL
  1756.     /* IKSD doesn't request client certs */
  1757.     ssl_verify_flag = SSL_VERIFY_NONE;
  1758. #endif /* CK_SSL */
  1759.  
  1760.     if (!cmdinited)
  1761.       cmdini();
  1762.  
  1763. #ifdef IKSDCONF
  1764. #ifdef OS2
  1765.     line[0] = '\0';
  1766.     _searchenv(iksdconf,"INIT",line);
  1767.     if (line[0] == 0)
  1768.       _searchenv(iksdconf,"DPATH",line);
  1769.     if (line[0] == 0)
  1770.       _searchenv(iksdconf,"PATH",line);
  1771.     if (line[0] == 0) {
  1772.         char *pgmptr = GetLoadPath();
  1773.         if (pgmptr && strlen(pgmptr) < LINBUFSIZ-8) {
  1774.             lp = strrchr(pgmptr, '\\');
  1775.             if (lp) {
  1776.                 strncpy(line, pgmptr, lp - pgmptr);
  1777.                 strcpy(line + (lp - pgmptr), "\\");
  1778.                 strcpy(line + (lp - pgmptr + 1), iksdconf);
  1779.             } else {
  1780.                 lp = strrchr(pgmptr, '.');
  1781.                 if (lp) {
  1782.                     strncpy(line, pgmptr, lp - pgmptr);
  1783.                     strcpy(line + (lp - pgmptr), ".ksc");
  1784.                 }
  1785.             }
  1786.         }
  1787.     }
  1788.     debug(F110,"doiksdinit() line",line,0);
  1789.     tfile[0] = fopen(line,"r");
  1790. #else /* OS2 */
  1791.     tfile[0] = fopen(iksdconf,"r");
  1792. #endif /* OS2 */
  1793.     if (tfile[0] != NULL) {
  1794.         tlevel = 0;
  1795.         tfline[tlevel] = 0;
  1796. #ifdef OS2
  1797.         if (tfnam[tlevel] = malloc(strlen(line)+1))
  1798.           strcpy(tfnam[tlevel],line);
  1799. #else /* OS2 */
  1800.         if ((tfnam[tlevel] = malloc(strlen(iksdconf)+1)))
  1801.           strcpy(tfnam[tlevel],iksdconf);
  1802. #endif /* OS2 */
  1803. #ifndef NOSPL
  1804.         cmdlvl++;
  1805.         xcmdsrc = CMD_TF;
  1806.         cmdstk[cmdlvl].src = CMD_TF;
  1807.         cmdstk[cmdlvl].lvl = tlevel;
  1808.         cmdstk[cmdlvl].ccflgs = 0;
  1809.         ifcmd[cmdlvl]  = 0;
  1810.         iftest[cmdlvl] = 0;
  1811.         count[cmdlvl]  = count[cmdlvl-1]; /* Inherit from previous level */
  1812.         intime[cmdlvl] = intime[cmdlvl-1];
  1813.         inpcas[cmdlvl] = inpcas[cmdlvl-1];
  1814.         takerr[cmdlvl] = takerr[cmdlvl-1];
  1815.         merror[cmdlvl] = merror[cmdlvl-1];
  1816.         xquiet[cmdlvl] = quiet;
  1817. #endif /* NOSPL */
  1818.         debug(F110,"doiksdinit file ok",tfnam[tlevel],0);
  1819.     } else {
  1820.         debug(F110,"doiksdinit open failed",tfnam[tlevel],0);
  1821.     }
  1822. #endif /* IKSDCONF */
  1823. }
  1824.  
  1825. #ifndef NOSPL
  1826. /*
  1827.   G E T N C M
  1828.  
  1829.   Get next command from current macro definition.  Command is copied
  1830.   into string pointed to by argument s, max length n.   Returns:
  1831.    0 if a string was copied;
  1832.   -1 if there was no string to copy.
  1833. */
  1834. int
  1835. getncm(s,n) char *s; int n; {
  1836.     int y,                              /* Character counter */
  1837.     quote = 0,
  1838.     kp = 0,                             /* Brace up-down counter */
  1839.     pp = 0,                             /* Parenthesis up-down counter */
  1840. #ifndef NODQMACRO
  1841.     dq = 0;                             /* Doublequote counter */
  1842. #endif /* NODQMACRO */
  1843.     char *s2;                           /* Copy of destination pointer */
  1844.  
  1845.     s2 = s;                             /* Initialize string pointers */
  1846.     *s = NUL;                           /* and destination buffer */
  1847.  
  1848.     /* debug(F010,"getncm entry",macp[maclvl],0); */
  1849.  
  1850.     for (y = 0;                         /* Loop for n bytes max */
  1851.          macp[maclvl] && *macp[maclvl] && y < n;
  1852.          y++, s++, macp[maclvl]++) {
  1853.  
  1854.         *s = *macp[maclvl];             /* Get next char from macro def */
  1855.  
  1856. #ifndef COMMENT
  1857. /*
  1858.   This is to allow quoting of parentheses, commas, etc, in function
  1859.   arguments, but it breaks just about everything else.  DON'T REMOVE THIS
  1860.   COMMENT!  (Otherwise you'll wind up adding the same code again and breaking
  1861.   everything again.)  <-- The preceding warning should be obsolete since the
  1862.   statements below have been fixed, but in case of fire, remove the "n" from
  1863.   the <#>ifndef above.  NEW WARNING: code added 12 Apr 2002 to exempt the
  1864.   opening brace in \{nnn} from being treated as a quoted brace.
  1865. */
  1866.         if (!quote && *s == CMDQ) {
  1867.             quote = 1;
  1868.             continue;
  1869.         }
  1870.         if (quote) {
  1871.         int notquote = 0;
  1872.             quote = 0;
  1873.         if (*s == '{') {        /* Check for \{nnn} (8.0.203) */
  1874.         char c, * p;
  1875.         p = macp[maclvl] + 1;
  1876.         while ((c = *p++)) {
  1877.             if (isdigit(c))
  1878.               continue;
  1879.             else if (c == '}') {
  1880.             notquote++;
  1881.             break;
  1882.             } else {
  1883.             break;
  1884.             }
  1885.         }
  1886.         }
  1887.         if (notquote == 0)
  1888.           continue;
  1889.         }
  1890. #endif /* COMMENT */
  1891.  
  1892. /*
  1893.   Allow braces around macro definition to prevent commas from being turned to
  1894.   end-of-lines and also treat any commas within parens as text so that
  1895.   multiple-argument functions won't cause the command to break prematurely.
  1896.   19 Oct 2001: Similar treatment was added for doublequotes, so
  1897.  
  1898.      define foo { echo "one, two, three" }
  1899.  
  1900.   would work as expected.  This doesn't seem to have broken anything but
  1901.   if something comes up later, rebuild with NODQMACRO defined.
  1902. */
  1903.         if (*s == '{') kp++;            /* Count braces */
  1904.         if (*s == '}' && kp > 0) kp--;
  1905.         if (*s == '(') pp++;            /* Count parentheses. */
  1906.         if (*s == ')' && pp > 0) pp--;
  1907. #ifndef NODQMACRO
  1908.         if (*s == '"') dq = 1 - dq;     /* Account for doublequotes */
  1909. #endif /* NODQMACRO */
  1910.         if (*s == ',' && pp <= 0 && kp <= 0
  1911. #ifndef NODQMACRO
  1912.             && dq == 0
  1913. #endif /* NODQMACRO */
  1914.             ) {
  1915.             macp[maclvl]++;             /* Comma not in {} or () */
  1916.             /* debug(F110,"next cmd",s,0); */
  1917.             kp = pp = 0;                /* so we have the next command */
  1918.             break;
  1919.         }
  1920.     }                                   /* Reached end. */
  1921. #ifdef COMMENT
  1922.     /* DON'T DO THIS - IT BREAKS EVERYTHING */
  1923.     *s = NUL;
  1924. #endif /* COMMENT */
  1925.     if (*s2 == NUL) {                   /* If nothing was copied, */
  1926.         /* debug(F100,"getncm eom","",0); */
  1927.         popclvl();                      /* pop command level. */
  1928.         return(-1);
  1929.     } else {                            /* otherwise, tack CR onto end */
  1930.         *s++ = CR;
  1931.         *s = '\0';
  1932.         if (mecho && pflag)             /* If MACRO ECHO ON, echo the cmd */
  1933.           printf("%s\n",s2);
  1934.     }
  1935.     return(0);
  1936. }
  1937.  
  1938. /*  D O M A C  --  Define and then execute a macro */
  1939.  
  1940. int
  1941. domac(name, def, flags) char *name, *def; int flags; {
  1942.     int x, m;
  1943. #ifndef NOLOCAL
  1944. #ifdef OS2
  1945.     extern int term_io;
  1946.     int term_io_sav = term_io;
  1947.     term_io = 0;                        /* Disable Terminal Emulator I/O */
  1948. #endif /* OS2 */
  1949. #endif /* NOLOCAL */
  1950.     m = maclvl;                         /* Current macro stack level */
  1951.     x = addmac(name, def);              /* Define a new macro */
  1952.     if (x > -1) {                       /* If successful, */
  1953.         dodo(x,NULL,flags);             /* start it (increments maclvl). */
  1954.         while (maclvl > m) {            /* Keep going till done with it, */
  1955.             debug(F101,"domac loop maclvl 1","",maclvl);
  1956.             sstate = (CHAR) parser(1);  /* parsing & executing each command, */
  1957.             debug(F101,"domac loop maclvl 2","",maclvl);
  1958.             if (sstate) proto();        /* including protocol commands. */
  1959.         }
  1960.         debug(F101,"domac loop exit maclvl","",maclvl);
  1961.     }
  1962. #ifndef NOLOCAL
  1963. #ifdef OS2
  1964.     term_io = term_io_sav;
  1965. #endif /* OS2 */
  1966. #endif /* NOLOCAL */
  1967.     return(success);
  1968. }
  1969. #endif /* NOSPL */
  1970.  
  1971. /*
  1972.   G E T N C T
  1973.  
  1974.   Get next command from TAKE (command) file.
  1975.  
  1976.   Call with:
  1977.    s     Pointer to buffer to read into
  1978.    n     Length of buffer
  1979.    f     File descriptor of file to read from
  1980.    flag  0 == keep line terminator on and allow continuation
  1981.          1 == discard line terminator and don't allow continuation
  1982.  
  1983.   Call with flag == 0 to read a command from a TAKE file;
  1984.   Call with flag != 0 to read a line from a dialing or network directory.
  1985.  
  1986.   In both cases, trailing comments and/or trailing whitespace is/are stripped.
  1987.   If flag == 0, continued lines are combined into one line.  A continued line
  1988.   is one that ends in hypen, or any line in a "block", which starts with "{"
  1989.   at the end of a line and ends with a matching "}" at the beginning of a
  1990.   subsequent line; blocks may be nested.
  1991.  
  1992.   Returns:
  1993.    0 if a string was copied,
  1994.   -1 on EOF,
  1995.   -2 on malloc failure
  1996.   -3 if line is not properly terminated
  1997.   -4 if (possibly continued) line is too long.
  1998. */
  1999. static int lpxlen = 0;
  2000.  
  2001. int
  2002. getnct(s,n,f,flag) char *s; int n; FILE *f; int flag; {
  2003.     int i = 0, len = 0, buflen = 0;
  2004.     char c = NUL, cc = NUL, ccl = NUL, ccx = NUL, *s2 = NULL;
  2005.     char *lp = NULL, *lpx = NULL, *lp2 = NULL, *lp3 = NULL, *lastcomma = NULL;
  2006.     char * prev = NULL;
  2007.     int bc = 0;                         /* Block counter */
  2008.  
  2009.     s2 = s;                             /* Remember original pointer */
  2010.     prev = s2;
  2011.     buflen = n;                         /* Remember original buffer length */
  2012.  
  2013.     if (n < 0)
  2014.       return(-2);
  2015.  
  2016.     /* Allocate a line buffer only if we don't have one that's big enough */
  2017.  
  2018.     debug(F111,"getnct",ckitoa(lpxlen),n);
  2019.  
  2020.     if (lpx && (n > lpxlen)) {          /* Have one already */
  2021.         debug(F101,"getnct new buffer","",lpxlen);
  2022.         free(lpx);                      /* But it's not big enough */
  2023.         lpx = NULL;                     /* Free current one */
  2024.         lpxlen = 0;
  2025.     }
  2026.     if (!lpx) {                         /* Get new one */
  2027.         if (!(lpx = (char *) malloc(n))) {
  2028.             debug(F101,"getnct malloc failure","",0);
  2029.             printf("?Memory allocation failure [getnct]\n");
  2030.             return(-2);
  2031.         }
  2032.         lpxlen = n;
  2033.     }
  2034.     lp2 = lpx;
  2035. #ifdef KLUDGE
  2036.     /* NOTE: No longer used as of 14 Aug 2000 */
  2037.     lp2++;
  2038. #endif /* KLUDGE */
  2039.  
  2040.     while (1) {                         /* Loop to read lines from file */
  2041.         debug(F101,"getnct while (1)","",n);
  2042.         if (fgets(lp2,n,f) == NULL) {   /* Read a line into lp2 */
  2043.             debug(F110,"getnct EOF",s2,0); /* EOF */
  2044.             free(lpx);                  /* Free temporary storage */
  2045.             lpx = NULL;
  2046.             *s = NUL;                   /* Make destination be empty */
  2047.             return(-1);                 /* Return failure code */
  2048.         }
  2049. #ifndef NODIAL
  2050.         if (flag)                       /* Count this line */
  2051.           dirline++;
  2052.         else
  2053. #endif /* NODIAL */
  2054.           tfline[tlevel]++;
  2055.         len = strlen(lp2) - 1;          /* Position of line terminator */
  2056.         if (len == 0 && lp2[0] != '\n') { /* Last line in file has one char */
  2057.             lp2[++len] = '\n';          /* that is not a newline */
  2058.             lp2[len] = NUL;
  2059.         }
  2060.         debug(F010,"getnct",lp2,0);
  2061.         if (len < 0)
  2062.           len = 0;
  2063.         if (techo && pflag)             /* If TAKE ECHO ON, */
  2064.           printf("%3d. %s",             /* echo it this line. */
  2065. #ifndef NODIAL
  2066.                  flag ? dirline :
  2067. #endif /* NODIAL */
  2068.                  tfline[tlevel],
  2069.                  lp2
  2070.                  );
  2071.         lp3 = lp2;                      /* Working pointer */
  2072.         i = len;                        /* Get first nonwhitespace character */
  2073.         while (i > 0 && (*lp3 == SP || *lp3 == HT)) {
  2074.             i--;
  2075.             lp3++;
  2076.         }
  2077.         if (i == 0 && bc > 0)           /* Blank line in {...} block */
  2078.           continue;
  2079.  
  2080.         /* Isolate, remove, and check terminator */
  2081.  
  2082.         c = lp2[len];                   /* Value of line terminator */
  2083.         /* debug(F101,"getnct terminator","",c); */
  2084.         if (c < LF || c > CR) {         /* It's not a terminator */
  2085.             /* debug(F111,"getnct bad line",lp2,c); */
  2086.             if (feof(f) && len > 0 && len < n) {
  2087.                 /* Kludge Alert... */
  2088.                 if (!quiet)
  2089.                   printf("WARNING: Last line of %s lacks terminator\n",
  2090.                          s2 == cmdbuf ? "command file" : "directory file");
  2091.                 c = lp2[++len] = '\n';  /* No big deal - supply one. */
  2092.             } else {                    /* Something's wrong, fail. */
  2093.                 free(lpx);
  2094.                 lpx = NULL;
  2095.                 return(-3);
  2096.             }
  2097.         }
  2098.         /* Trim trailing whitespace */
  2099.  
  2100.         for (i = len - 1; i > -1 && lp2[i] <= SP; i--) /* Trim */
  2101.           ;
  2102.         /* debug(F101,"getnct i","",i); */
  2103.         lp2[i+1] = NUL;                 /* Terminate the string */
  2104.         /* debug(F110,"getnct lp2",lp2,0); */
  2105.         lp = lp2;                       /* Make a working pointer */
  2106.  
  2107.         /* Remove trailing or full-line comment */
  2108.  
  2109.         while ((cc = *lp)) {
  2110.             if (cc == ';' || cc == '#') { /* Comment introducer? */
  2111.                 if (lp == lp2) {        /* First char on line */
  2112.                     *lp = NUL;
  2113.                     break;
  2114.                 } else if (*(lp - 1) == SP || *(lp - 1) == HT) {
  2115.                     lp--;
  2116.                     *lp = NUL;  /* Or preceded by whitespace */
  2117.                     break;
  2118.                 }
  2119.             }
  2120.             lp++;
  2121.         }
  2122.         if (lp > lp2)
  2123.           lp--;                         /* Back up over the NUL */
  2124.  
  2125.         /* Now trim any space that preceded the comment */
  2126.  
  2127.         while ((*lp == SP || *lp == HT) && lp >= lp2) {
  2128.             *lp = NUL;
  2129.             if (lp <= lp2)
  2130.               break;
  2131.             lp--;
  2132.         }
  2133.         /* debug(F110,"getnct comment trimmed",lp2,0); */
  2134.  
  2135.         len = strlen(lp2);              /* Length after trimming */
  2136.  
  2137.         if (n - len < 2) {              /* Check remaining space */
  2138.             debug(F111,"getnct command too long",s2,buflen);
  2139.             printf("?Line too long, maximum length: %d.\n",buflen);
  2140.             free(lpx);
  2141.             return(-4);
  2142.         }
  2143.         ccl = (len > 0) ? lp2[len-1] : 0;     /* Last character in line */
  2144.         ccx = (len > 1) ? lp2[len-2] : 0;     /* Penultimate char in line */
  2145.  
  2146. #ifdef COMMENT
  2147.         /* Line containing only whitespace and ,- */
  2148.         if ((len > 1) && (lp3 == lp2+len-2) && (ccl == '-') && (ccx == ','))
  2149.           continue;
  2150. #endif /* COMMENT */
  2151.  
  2152. #ifdef KLUDGE
  2153. /*
  2154.   If it is a command and it begins with a token (like ! or .) that is not
  2155.   followed by a space, insert a space now; otherwise cmkey() can get mighty
  2156.   confused.
  2157. */
  2158.         if (s == s2 && !flag) {
  2159.             char *p = toktab;
  2160.             while (*p) {
  2161.                 if (*p == *lp3 && *(p+1) != SP) {
  2162.                     debug(F110,"getnct token",p,0);
  2163.                     *lp3-- = SP;
  2164.                     *lp3 = *p;
  2165.                     if (lp3 < lp2) {
  2166.                         lp2--;
  2167.                         len++;
  2168.                     }
  2169.                     break;
  2170.                 } else
  2171.                   p++;
  2172.             }
  2173.         }
  2174. #endif /* KLUDGE */
  2175.         lp = lp2;
  2176.  
  2177.         while ((*s++ = *lp++))          /* Copy result to target buffer */
  2178.           n--;                          /* accounting for length */
  2179.         s--;                            /* Back up over the NUL */
  2180.  
  2181.         /* Check whether this line is continued */
  2182.  
  2183.         if (flag)                       /* No line continuation when flag=1 */
  2184.           break;                        /* So break out of read-lines loop */
  2185.  
  2186. #ifdef COMMENT
  2187.         debug(F000,"getnct first char","",*lp3);
  2188.         debug(F000,"getnct last char","",ccl);
  2189.         debug(F000,"getnct next-to-last char","",ccx);
  2190. #endif /* COMMENT */
  2191.  
  2192.         if (bc > 0 && *lp3 == '}') {    /* First char on line is '}' */
  2193.             bc--;                               /* Decrement block counter */
  2194.         }
  2195.  
  2196.         if (bc == 0 &&                  /* Line is continued if bc > 0 */
  2197. #ifdef COMMENT
  2198.             /* Not supported as of C-Kermit 6.0 */
  2199.             ccl != CMDQ &&              /* or line ends with CMDQ */
  2200. #endif /* COMMENT */
  2201.             ccl != '-'  &&              /* or line ends with dash */
  2202.             ccl != '{')                 /* or line ends with opening brace */
  2203.           break;                        /* None of those, we're done. */
  2204.  
  2205.         if (ccl == '-' || ccl == '{')   /* Continuation character */
  2206.           if (ccx == CMDQ)              /* But it's quoted */
  2207.             break;                      /* so ignore it */
  2208.  
  2209.         if (ccl == '{') {               /* Last char on line is '{'? */
  2210.             bc++;                       /* Count the block opener. */
  2211.         } else if (ccl == '-') {        /* Explicit continue? */
  2212.             char c, * ss;
  2213.             int state = 0, nn;
  2214.             s--;                        /* Yes, back up over terminators */
  2215.             n++;                        /* and over continuation character */
  2216.             nn = n;                     /* Save current count */
  2217.             ss = s;                     /* and pointer */
  2218.             s--;                        /* Back up over dash */
  2219.             n++;
  2220.             while (state < 2 && s >= prev) { /* Check for "{,-" */
  2221.                 n++;
  2222.                 c = *s--;
  2223.                 if (c <= SP)
  2224.                   continue;
  2225.                 if (c != ',' && c != '{')
  2226.                   break;
  2227.                 switch (state) {
  2228.                   case 0:               /* Looking for comma */
  2229.                     if (c == ',')
  2230.                       state = 1;
  2231.                     break;
  2232.                   case 1:               /* Looking for left brace */
  2233.                     if (c == '{') {
  2234.                         state = 2;
  2235.                         s += 2;
  2236.                         *s = NUL;
  2237.                         bc++;
  2238.                     }
  2239.                     break;
  2240.                 }
  2241.             }
  2242.             if (state != 2) { s = ss; n = nn; }
  2243.             *s = NUL;
  2244.         } else {                        /* None of those but (bc > 0) */
  2245.             lastcomma = s;
  2246.             *s++ = ',';                 /* and insert a comma */
  2247.             n--;
  2248.         }
  2249. #ifdef COMMENT
  2250.         debug(F101,"getnct bc","",bc);
  2251.         debug(F100,"getnct continued","",0);
  2252. #endif /* COMMENT */
  2253.  
  2254.         *s = NUL;
  2255.         prev = s;
  2256.  
  2257.     } /* read-lines while loop */
  2258.  
  2259.     if (lastcomma)
  2260.       *lastcomma = SP;
  2261.     if (!flag)                          /* Tack line terminator back on */
  2262.       *s++ = c;
  2263.     *s++ = NUL;                         /* Terminate the string */
  2264.     untab(s2);                          /* Done, convert tabs to spaces */
  2265. #ifdef DEBUG
  2266.     if (!flag) {
  2267.         debug(F010,"CMD(F)",s2,0);
  2268.     }
  2269. #endif /* DEBUG */
  2270.     free(lpx);                          /* Free temporary storage */
  2271.     return(0);                          /* Return success */
  2272. }
  2273.  
  2274. VOID
  2275. shostack() {                            /* Dump the command stack */
  2276.     int i;
  2277.     char *p;
  2278. #ifndef NOSPL
  2279.     for (i = cmdlvl; i > 0; i--) {
  2280.         if (cmdstk[i].src == CMD_TF) {
  2281.             p = tfnam[cmdstk[i].lvl];
  2282.             if (zfnqfp(p,TMPBUFSIZ,tmpbuf))
  2283.               p = tmpbuf;
  2284.             printf(" %2d. File  : %s (line %d)\n",
  2285.                    i,
  2286.                    p,
  2287.                    tfline[cmdstk[i].lvl]
  2288.                    );
  2289.         } else if (cmdstk[i].src == CMD_MD) {
  2290.             char * m;
  2291.             m = m_arg[cmdstk[i].lvl][0]; /* Name of this macro */
  2292.             if (i > 0) {                 /* Special handling for 2-level */
  2293.                 char *s;                 /* built-in macros... */
  2294.                 s = m_arg[cmdstk[i-1].lvl][0]; /* Name next level up */
  2295.                 if (s && cmdstk[i-1].src == CMD_MD) {
  2296.                     if (!strcmp(s,"_forx"))
  2297.                       m = "FOR";
  2298.                     else if (!strcmp(s,"_xif"))
  2299.                       m = "XIF";
  2300.                     else if (!strcmp(s,"_while"))
  2301.                       m = "WHILE";
  2302.                     else if (!strcmp(s,"_switx"))
  2303.                       m = "SWITCH";
  2304.                 }
  2305.             }
  2306.             printf(" %2d. Macro : %s\n",i,m);
  2307.         } else if (cmdstk[i].src == CMD_KB) {
  2308.             printf(" %2d. Prompt:\n",i);
  2309.         } else {
  2310.             printf(" %2d. ERROR : Command source unknown\n",i);
  2311.         }
  2312.     }
  2313. #else
  2314.     for (i = tlevel; i > -1; i--) {
  2315.         p = tfnam[i];
  2316.         if (zfnqfp(p,TMPBUFSIZ,tmpbuf))
  2317.           p = tmpbuf;
  2318.         printf(" %2d. File  : %s (line %d)\n",
  2319.                i,
  2320.                p,
  2321.                tfline[i]
  2322.                );
  2323.     }
  2324. #endif /* NOSPL */
  2325.     if (i == 0)
  2326.       printf(" %2d. Prompt: (top level)\n",0);
  2327. }
  2328.  
  2329.  
  2330. /*  P A R S E R  --  Top-level interactive command parser.  */
  2331.  
  2332. /*
  2333.   Call with:
  2334.     m = 0 for normal behavior: keep parsing and executing commands
  2335.           until an action command is parsed, then return with a
  2336.           Kermit start-state as the value of this function.
  2337.     m = 1 to parse only one command, can also be used to call parser()
  2338.           recursively.
  2339.     m = 2 to read but do not execute one command.
  2340.   In all cases, parser() returns:
  2341.     0     if no Kermit protocol action required
  2342.     > 0   with a Kermit protocol start-state.
  2343.     < 0   upon error.
  2344. */
  2345. int
  2346. parser(m) int m; {
  2347.     int tfcode, xx, yy, zz;             /* Workers */
  2348.     int is_tn = 0;
  2349.     int cdlost = 0;
  2350.  
  2351. #ifndef NOSPL
  2352.     int inlevel;                        /* Level we were called at */
  2353.     extern int askflag;
  2354. #endif /* NOSPL */
  2355.     char *cbp;                          /* Command buffer pointer */
  2356. #ifdef MAC
  2357.     extern char *lfiles;                /* Fake extern cast */
  2358. #endif /* MAC */
  2359.     extern int interrupted;
  2360. #ifndef NOXFER
  2361.     extern int sndcmd, getcmd, fatalio, clearrq;
  2362. #endif /* NOXFER */
  2363.  
  2364.     debok = 1;                          /* Undisable debugging */
  2365.  
  2366. #ifdef AMIGA
  2367.     reqres();                           /* Restore AmigaDOS requestors */
  2368. #endif /* AMIGA */
  2369.  
  2370. #ifdef OS2
  2371.     if (cursor_save > -1) {             /* Restore cursor if it was */
  2372.         cursorena[VCMD] = cursor_save;  /* turned off during file transfer */
  2373.         cursor_save = -1;
  2374.     }
  2375. #endif /* OS2 */
  2376.  
  2377. #ifdef IKSDB
  2378.     if (ikdbopen) slotstate(what,"COMMAND PROMPT","",""); /* IKSD database */
  2379. #endif /* IKSDB */
  2380.  
  2381.     is_tn = (local && network && IS_TELNET()) ||
  2382.       (!local && sstelnet);
  2383.  
  2384.     if (!xcmdsrc)                       /* If at top (interactive) level ... */
  2385.       concb((char)escape);              /* put console in 'cbreak' mode. */
  2386.  
  2387. #ifdef CK_TMPDIR
  2388. /* If we were cd'd temporarily to another device or directory ... */
  2389.     if (f_tmpdir) {
  2390.         int x;
  2391.         x = zchdir((char *) savdir);    /* ... restore previous directory */
  2392.         f_tmpdir = 0;                   /* and remember we did it. */
  2393.         debug(F111,"parser tmpdir restoring",savdir,x);
  2394.     }
  2395. #endif /* CK_TMPDIR */
  2396.  
  2397. #ifndef NOSPL
  2398.     inlevel = cmdlvl;           /* Current macro level */
  2399. #ifdef DEBUG
  2400.     if (deblog) {
  2401.         debug(F101,"&parser entry maclvl","",maclvl);
  2402.         debug(F101,"&parser entry inlevel","",inlevel);
  2403.         debug(F101,"&parser entry tlevel","",tlevel);
  2404.         debug(F101,"&parser entry cmdlvl","",cmdlvl);
  2405.         debug(F101,"&parser entry m","",m);
  2406.     }
  2407. #endif /* DEBUG */
  2408. #endif /* NOSPL */
  2409.  
  2410. #ifndef NOXFER
  2411.     ftreset();                          /* Reset global file settings */
  2412. #endif /* NOXFER */
  2413. /*
  2414.   sstate becomes nonzero when a command has been parsed that requires some
  2415.   action from the protocol module.  Any non-protocol actions, such as local
  2416.   directory listing or terminal emulation, are invoked directly from below.
  2417. */
  2418.     sstate = 0;                         /* Start with no start state. */
  2419.  
  2420. #ifndef NOXFER
  2421. #ifndef NOSPL
  2422.     query = 0;                          /* QUERY not active */
  2423. #endif /* NOSPL */
  2424. #ifndef NOHINTS
  2425.     if (!success) {
  2426.         if (local && !network && carrier != CAR_OFF) {
  2427.             int x;                      /* Serial connection */
  2428.             x = ttgmdm();               /* with carrier checking */
  2429.             if (x > -1) {
  2430.                 if (!(x & BM_DCD)) {
  2431.                     cdlost = 1;
  2432.                     fatalio = 1;
  2433.                 }
  2434.             }
  2435.         }
  2436.     }
  2437. #ifdef DEBUG
  2438.     if (deblog) {
  2439.         debug(F101,"parser top what","",what);
  2440.         debug(F101,"parser top interrupted","",interrupted);
  2441.         debug(F101,"parser top cdlost","",cdlost);
  2442.         debug(F101,"parser top sndcmd","",sndcmd);
  2443.         debug(F101,"parser top getcmd","",getcmd);
  2444.     }
  2445. #endif /* DEBUG */
  2446.     if (cdlost && !interrupted && (sndcmd || getcmd)) {
  2447.         printf("?Connection broken (carrier signal lost)\n");
  2448.     }
  2449.     if (sndcmd && !success && hints && !interrupted && !fatalio && !xcmdsrc) {
  2450.         int x = 0, n = 0;
  2451.         printf("\n*************************\n");
  2452.         printf("SEND-class command failed.\n");
  2453.         printf(" Packets sent: %d\n", spackets);
  2454.         printf(" Retransmissions: %d\n",retrans);
  2455.         printf(" Timeouts: %d\n", timeouts);
  2456.         printf(" Damaged packets: %d\n", crunched);
  2457.         if (epktrcvd) {
  2458.             printf(" Transfer canceled by receiver.\n");
  2459.             printf(" Receiver's message: \"%s\"\n",(char *)epktmsg);
  2460.             n++;
  2461.         } else {
  2462.             if (epktmsg) if (*epktmsg) {
  2463.                 printf(" Fatal Kermit Protocol Error: %s\n",epktmsg);
  2464.                 n++;
  2465.             }
  2466.         }
  2467.         if (local && !network && carrier != CAR_OFF) {
  2468.             int xx;                     /* Serial connection */
  2469.             xx = ttgmdm();              /* with carrier checking */
  2470.             if (xx > -1) {
  2471.                 if (!(xx & BM_DCD))
  2472.                   cdlost = 1;
  2473.             }
  2474.         }
  2475.  
  2476. #ifdef UNIX
  2477.         if (errno != 0)
  2478. #endif /* UNIX */
  2479.           {
  2480.               printf(" Most recent local OS error: \"%s\"\n",ck_errstr());
  2481.               n++;
  2482.           }
  2483.         printf(
  2484.    "\nHINTS... If the preceding error message%s not explain the failure:\n",
  2485.                (n > 1) ? "s do" : " does"
  2486.                );
  2487. #ifndef NOLOCAL
  2488.         if (local) {
  2489.             if (rpackets == 0) {
  2490.                 printf(" . Did you start a Kermit receiver on the far end?\n");
  2491.             } else {
  2492.                 printf(
  2493.                 " . Try changing the remote Kermit's FLOW-CONTROL setting.\n");
  2494.                 if (!network && mdmtyp > 0)
  2495.                   if ((3 * crunched) > spackets)
  2496.                     printf(
  2497.                 " . Try placing a new call to get a cleaner connection.\n");
  2498.             }
  2499.         } else if (rpackets > 0) {
  2500.             if (flow == FLO_NONE)
  2501.              printf(" . Give me a SET FLOW XON/XOFF command and try again.\n");
  2502.             else
  2503.              printf(" . Give me a SET FLOW NONE command and try again.\n");
  2504.         }
  2505.         x++;
  2506. #endif /* NOLOCAL */
  2507.  
  2508.         if ((3 * timeouts) > spackets)
  2509.           printf(" . Adjust the timeout method (see HELP SET SEND).\n");
  2510.         if ((3 * retrans) > spackets)
  2511.           printf(" . Increase the retry limit (see HELP SET RETRY).\n");
  2512.  
  2513. #ifdef CK_SPEED
  2514.         if (prefixing != PX_ALL && rpackets > 2) {
  2515.             printf(" . Try it again with SET PREFIXING ALL.\n");
  2516.             x++;
  2517.         }
  2518. #endif /* CK_SPEED */
  2519. #ifdef STREAMING
  2520.         if (streamed) {
  2521.             printf(" . Try it again with SET STREAMING OFF.\n");
  2522.             x++;
  2523.         } else if (reliable) {
  2524.             printf(" . Try it again with SET RELIABLE OFF.\n");
  2525.             x++;
  2526.         }
  2527. #endif /* STREAMING */
  2528.  
  2529. #ifdef CK_SPEED
  2530.         if (clearrq > 0 && prefixing == PX_NON) {
  2531.             printf(" . Try it again with SET CLEAR-CHANNEL OFF.\n");
  2532.             x++;
  2533.         }
  2534. #endif /* CK_SPEED */
  2535.         if (!parity) {
  2536.             printf(" . Try it again with SET PARITY SPACE.\n");
  2537.             x++;
  2538.         }
  2539.         printf(" . %sive a ROBUST command and try again.\n",
  2540.                (x > 0) ? "As a last resort, g" : "G"
  2541.                );
  2542.         printf("Also:\n");
  2543.         printf(" . Be sure the source file has read permission.\n");
  2544.         printf(" . Be sure the target directory has write permission.\n");
  2545.         printf("(Use SET HINTS OFF to suppress hints.)\n");
  2546.         printf("*************************\n\n");
  2547.     }
  2548.     debug(F101,"topcmd","",topcmd);
  2549.     if (getcmd && !success && hints && !interrupted && !fatalio && !xcmdsrc) {
  2550.         int x = 0;
  2551.         extern int urpsiz, wslotr;
  2552.         printf("\n*************************\n");
  2553.         printf("RECEIVE- or GET-class command failed.\n");
  2554.         printf(" Packets received: %d\n", rpackets);
  2555.         printf(" Damaged packets: %d\n", crunched);
  2556.         printf(" Timeouts: %d\n", timeouts);
  2557.         if (rpackets > 0)
  2558.           printf(" Packet length: %d\n", urpsiz);
  2559.         if (epktrcvd) {
  2560.             printf(" Transfer canceled by sender.\n");
  2561.             printf(" Sender's message: \"%s\"\n",(char *)epktmsg);
  2562.         }
  2563. #ifdef UNIX
  2564.         if (errno != 0)
  2565. #endif /* UNIX */
  2566.           printf(" Most recent local error: \"%s\"\n",ck_errstr());
  2567.         printf(
  2568.    "\nHINTS... If the preceding error message%s not explain the failure:\n",
  2569.                epktrcvd ? "s do" : " does"
  2570.                );
  2571. #ifndef NOLOCAL
  2572.         if (local) {
  2573.             if (topcmd == XXGET)
  2574.               printf(" . Did you start a Kermit SERVER on the far end?\n");
  2575.             if (rpackets == 0) {
  2576.                 if (topcmd != XXGET)
  2577.                   printf(" . Did you start a Kermit SENDer on the far end?\n");
  2578.             } else {
  2579.                 printf(
  2580.                 " . Choose a different FLOW-CONTROL setting and try again.\n");
  2581.             }
  2582.         } else if (topcmd == XXGET)
  2583.           printf(" . Is the other Kermit in (or does it have) SERVER mode?\n");
  2584.         if (rpackets > 0 && urpsiz > 90)
  2585.           printf(" . Try smaller packets (SET RECEIVE PACKET-LENGTH).\n");
  2586.         if (rpackets > 0 && wslotr > 1 && !streamed)
  2587.           printf(" . Try a smaller window size (SET WINDOW).\n");
  2588.         if (!local && rpackets > 0) {
  2589.             if (flow == FLO_NONE)
  2590.              printf(" . Give me a SET FLOW XON/XOFF command and try again.\n");
  2591.             else
  2592.              printf(" . Give me a SET FLOW NONE command and try again.\n");
  2593.         }
  2594.         x++;
  2595. #endif /* NOLOCAL */
  2596. #ifdef STREAMING
  2597.         if (streamed) {
  2598.             printf(" . Try it again with SET STREAMING OFF.\n");
  2599.             x++;
  2600.         } else if (reliable && local) {
  2601.             printf(" . Try it again with SET RELIABLE OFF.\n");
  2602.             x++;
  2603.         } else
  2604. #endif /* STREAMING */
  2605.         if (!parity) {
  2606.             printf(" . Try it again with SET PARITY SPACE.\n");
  2607.             x++;
  2608.         }
  2609.         printf((x > 0) ?
  2610.                " . As a last resort, give a ROBUST command and try again.\n" :
  2611.                " . Give a ROBUST command and try again.\n"
  2612.                );
  2613.         printf("Also:\n");
  2614.         printf(" . Be sure the target directory has write permission.\n");
  2615.         printf(" . Try telling the %s to SET PREFIXING ALL.\n",
  2616.                topcmd == XXGET ? "server" : "sender"
  2617.                );
  2618.         printf(" . Try giving a ROBUST command to the %s.\n",
  2619.                topcmd == XXGET ? "server" : "sender"
  2620.                );
  2621.         printf("(Use SET HINTS OFF to suppress hints.)\n");
  2622.         printf("*************************\n\n");
  2623.     }
  2624. #endif /* NOHINTS */
  2625.     getcmd = 0;
  2626.     sndcmd = 0;
  2627.     interrupted = 0;
  2628. #endif /* NOXFER */
  2629.  
  2630.     while (sstate == 0) {               /* Parse cmds until action requested */
  2631.         debug(F100,"parse top","",0);
  2632.     what = W_COMMAND;        /* Now we're parsing commands. */
  2633.     rcdactive = 0;            /* REMOTE CD not active */
  2634.  
  2635. #ifdef OS2
  2636.         if (apcactive == APC_INACTIVE)
  2637.           WaitCommandModeSem(-1);
  2638. #endif /* OS2 */
  2639. #ifdef IKS_OPTION
  2640.         if ((local &&
  2641.              !xcmdsrc &&
  2642.              is_tn &&
  2643.              TELOPT_ME(TELOPT_KERMIT) &&
  2644.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start) ||
  2645.             (!local &&
  2646.              !cmdadl &&
  2647.              TELOPT_ME(TELOPT_KERMIT) &&
  2648.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2649.             ) {
  2650.             tn_siks(KERMIT_STOP);
  2651.         }
  2652. #endif /* IKS_OPTION */
  2653.  
  2654. #ifndef NOXFER
  2655.         if (autopath) {
  2656.             fnrpath = PATH_AUTO;
  2657.             autopath = 0;
  2658.         }
  2659.         remfile = 0;                    /* Clear these in case REMOTE */
  2660.         remappd = 0;                    /* command was interrupted... */
  2661.         rempipe = 0;
  2662.         makestr(&snd_move,g_snd_move);  /* Restore these */
  2663.         makestr(&rcv_move,g_rcv_move);
  2664.         makestr(&snd_rename,g_snd_rename);
  2665.         makestr(&rcv_rename,g_rcv_rename);
  2666. #endif /* NOXFER */
  2667.         xaskmore = saveask;             /* Restore global more-prompting */
  2668.         diractive = 0;
  2669.         cdactive = 0;
  2670.  
  2671. #ifndef NOSPL
  2672.         askflag = 0;
  2673. #endif /* NOSPL */
  2674.  
  2675.     /* Take requested action if there was an error in the previous command */
  2676.  
  2677.         setint();
  2678.         debug(F101,"parser tlevel","",tlevel);
  2679.         debug(F101,"parser cmd_rows","",cmd_rows);
  2680.  
  2681. #ifndef NOLOCAL
  2682.         debug(F101,"parser wasclosed","",wasclosed);
  2683.         if (wasclosed) {                /* If connection was just closed */
  2684. #ifndef NOSPL
  2685.             int k;
  2686.             k = mlook(mactab,"on_close",nmac); /* Look up "on_close" */
  2687.             if (k >= 0) {               /* If found, */
  2688.                 /* printf("ON_CLOSE CMD LOOP\n"); */
  2689.                 dodo(k,ckitoa(whyclosed),0); /* Set it up */
  2690.             }
  2691. #endif /* NOSPL */
  2692.             whyclosed = WC_REMO;
  2693.             wasclosed = 0;
  2694.         }
  2695. #endif /* NOLOCAL */
  2696.  
  2697. #ifndef NOSPL
  2698.         xxdot = 0;                      /* Clear this... */
  2699.  
  2700.         debug(F101,"parser success","",success);
  2701.         if (success == 0) {
  2702.             if (cmdstk[cmdlvl].src == CMD_TF && takerr[cmdlvl]) {
  2703.                 printf("Command file terminated by error.\n");
  2704.                 popclvl();
  2705.                 if (cmdlvl == 0) return(0);
  2706.             }
  2707.             if (cmdstk[cmdlvl].src == CMD_MD && merror[cmdlvl]) {
  2708.                 printf("Command error: macro terminated.\n");
  2709.                 popclvl();
  2710.                 if (m && (cmdlvl < inlevel))
  2711.                   return((int) sstate);
  2712.             }
  2713.         }
  2714.         nulcmd = (m == 2);
  2715.         debug(F101,"parser nulcmd","",nulcmd);
  2716. #else
  2717.         if (success == 0 && tlevel > -1 && takerr[tlevel]) {
  2718.             printf("Command file terminated by error.\n");
  2719.             popclvl();
  2720.             cmini(ckxech);              /* Clear the cmd buffer. */
  2721.             if (tlevel < 0)             /* Just popped out of cmd files? */
  2722.               return(0);                /* End of init file or whatever. */
  2723.         }
  2724. #endif /* NOSPL */
  2725.  
  2726. #ifdef MAC
  2727.         /* Check for TAKE initiated by menu. */
  2728.         if ((tlevel == -1) && lfiles)
  2729.             startlfile();
  2730. #endif /* MAC */
  2731.  
  2732.         /* If in TAKE file, check for EOF */
  2733. #ifndef NOSPL
  2734. #ifdef MAC
  2735.         if
  2736. #else
  2737.         while
  2738. #endif /* MAC */
  2739.           ((cmdstk[cmdlvl].src == CMD_TF)  /* If end of take file */
  2740.                && (tlevel > -1)
  2741.                && feof(tfile[tlevel])) {
  2742.             popclvl();                  /* pop command level */
  2743.             cmini(ckxech);              /* and clear the cmd buffer. */
  2744.             if (cmdlvl == 0) {          /* Just popped out of all cmd files? */
  2745.                 return(0);              /* End of init file or whatever. */
  2746.             }
  2747.         }
  2748. #ifdef MAC
  2749.         miniparser(1);
  2750.         if (sstate == 'a') {            /* if cmd-. cancel */
  2751.             debug(F100, "parser: cancel take due to sstate", "", sstate);
  2752.             sstate = '\0';
  2753.             dostop();
  2754.             return(0);                  /* End of init file or whatever. */
  2755.         }
  2756. #endif /*  MAC */
  2757.  
  2758. #else /* NOSPL */
  2759.         if ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
  2760.             popclvl();                  /* Pop up one level. */
  2761.             cmini(ckxech);              /* and clear the cmd buffer. */
  2762.             if (tlevel < 0)             /* Just popped out of cmd files? */
  2763.               return(0);                /* End of init file or whatever. */
  2764.         }
  2765. #endif /* NOSPL */
  2766.  
  2767.  
  2768. #ifndef NOSPL
  2769.         debug(F101,"parser cmdlvl","",cmdlvl);
  2770.         debug(F101,"parser cmdsrc","",cmdstk[cmdlvl].src);
  2771.  
  2772.         if (cmdstk[cmdlvl].src == CMD_MD) { /* Executing a macro? */
  2773.             debug(F100,"parser macro","",0);
  2774.             maclvl = cmdstk[cmdlvl].lvl; /* Get current level */
  2775.             debug(F101,"parser maclvl","",maclvl);
  2776.             cbp = cmdbuf;               /* Copy next cmd to command buffer. */
  2777.             *cbp = NUL;
  2778.             if (*savbuf) {              /* In case then-part of 'if' command */
  2779.                 ckstrncpy(cbp,savbuf,CMDBL); /* was saved, restore it. */
  2780.                 *savbuf = '\0';
  2781.             } else {                    /* Else get next cmd from macro def */
  2782.                 if (getncm(cbp,CMDBL) < 0) {
  2783. #ifdef DEBUG
  2784.                     if (deblog) {
  2785.                         debug(F101,"parser end of macro m","",m);
  2786.                         debug(F101,"parser end of macro cmdlvl","",cmdlvl);
  2787.                         debug(F101,"parser end of macro inlevel","",inlevel);
  2788.                     }
  2789. #endif /* DEBUG */
  2790.                     if (m && (cmdlvl < inlevel))
  2791.                       return((int) sstate);
  2792.                     else /* if (!m) */ continue;
  2793.                 }
  2794.             }
  2795.             debug(F010,"CMD(M)",cmdbuf,0);
  2796.  
  2797.         } else if (cmdstk[cmdlvl].src == CMD_TF)
  2798. #else
  2799.           if (tlevel > -1)
  2800. #endif /* NOSPL */
  2801.           {
  2802. #ifndef NOSPL
  2803.             debug(F111,"parser savbuf",savbuf,tlevel);
  2804.             if (*savbuf) {              /* In case THEN-part of IF command */
  2805.                 ckstrncpy(cmdbuf,savbuf,CMDBL); /* was saved, restore it. */
  2806.                 *savbuf = '\0';
  2807.             } else
  2808. #endif /* NOSPL */
  2809.  
  2810.               /* Get next line from TAKE file */
  2811.  
  2812.               if ((tfcode = getnct(cmdbuf,CMDBL,tfile[tlevel],0)) < 0) {
  2813.                   debug(F111,"parser tfcode",tfile[tlevel],tfcode);
  2814.                   if (tfcode < -1) {    /* Error */
  2815.                       printf("?Error in TAKE command file: %s\n",
  2816.                              (tfcode == -2) ? "Memory allocation failure" :
  2817.                              "Line too long or contains NUL characters"
  2818.                              );
  2819.                       dostop();
  2820.                   }
  2821.                   continue;             /* -1 means EOF */
  2822.               }
  2823.  
  2824.         /* If interactive, get next command from user. */
  2825.  
  2826.         } else {                        /* User types it in. */
  2827.             if (pflag) prompt(xxstring);
  2828.             cmini(ckxech);
  2829.         }
  2830.  
  2831.     /* Now we know where next command is coming from. Parse and execute it. */
  2832.  
  2833.         repars = 1;                     /* 1 = command needs parsing */
  2834. #ifndef NOXFER
  2835.         displa = 0;                     /* Assume no file transfer display */
  2836. #endif /* NOXFER */
  2837.  
  2838.         while (repars) {                /* Parse this cmd until entered. */
  2839.  
  2840.             debug(F101,"parser top of while loop","",0);
  2841.  
  2842. #ifdef RECURSIVE
  2843.             /* In case of "send /recursive ./?<Ctrl-U>" etc */
  2844.             recursive = 0;              /* This is never sticky */
  2845. #endif /* RECURSIVE */
  2846.             xfiletype = -1;             /* Reset this between each command */
  2847. #ifndef NOMSEND
  2848.             addlist = 0;
  2849. #endif /* NOMSEND */
  2850. #ifdef CK_RECALL
  2851.             on_recall = 1;
  2852. #endif /* CK_RECALL */
  2853.             /* This might have been changed by a switch */
  2854.             if (g_matchdot > -1) {
  2855.                 matchdot = g_matchdot;
  2856.                 g_matchdot = -1;
  2857.             }
  2858.             cmres();                    /* Reset buffer pointers. */
  2859.  
  2860. #ifdef OS2
  2861. #ifdef COMMENT
  2862.             /* we check to see if a macro is waiting to be executed */
  2863.             /* if so, we call domac on it */
  2864.             if (cmdmac) {
  2865.                 ckstrncpy(cmdbuf, cmdmac, CMDBL);
  2866.                 free(cmdmac);
  2867.                 cmdmac = NULL;
  2868.             }
  2869. #endif /* COMMENT */
  2870. #endif /* OS2 */
  2871. #ifndef NOXFER
  2872.             bye_active = 0;
  2873. #endif /* NOXFER */
  2874.             havetoken = 0;
  2875.             xx = cmkey2(cmdtab,ncmd,"Command","",toktab,xxstring,1);
  2876.             debug(F101,"top-level cmkey2","",xx);
  2877.             if (xx == -5) {
  2878.                 yy = chktok(toktab);
  2879.                 debug(F101,"top-level cmkey token","",yy);
  2880. #ifndef COMMENT
  2881.                 /* Either way makes absolutely no difference */
  2882.                 debug(F110,"NO UNGWORD",atmbuf,0);
  2883.                 /* ungword(); */
  2884. #else
  2885.                 debug(F110,"TOKEN UNGWORD",atmbuf,0);
  2886.                 ungword();
  2887. #endif /* COMMENT */
  2888.                 switch (yy) {
  2889.                   case '#': xx = XXCOM; break; /* Comment */
  2890.                   case ';': xx = XXCOM; break; /* Comment */
  2891. #ifndef NOSPL
  2892.                   case '.': xx = XXDEF; xxdot = 1; break; /* Assignment */
  2893.                   case ':': xx = XXLBL; break; /* GOTO label */
  2894. #endif /* NOSPL */
  2895.  
  2896. #ifndef NOPUSH
  2897. #ifdef CK_REDIR
  2898.                   case '<':
  2899. #endif /* CK_REDIR */
  2900.                   case '@':
  2901.                   case '!':
  2902.                     if (nopush) {
  2903.                         char *s; int x;
  2904.                         if ((x = cmtxt("Text to be ignored","",&s,NULL)) < 0)
  2905.                           return(x);
  2906.                         success = 0;
  2907.                         xx = XXCOM;
  2908.                     } else {
  2909.                         switch(yy) {
  2910. #ifdef CK_REDIR
  2911.                           case '<': xx = XXFUN; break; /* REDIRECT */
  2912. #endif /* CK_REDIR */
  2913.                           case '@':
  2914.                           case '!': xx = XXSHE; break; /* Shell escape */
  2915.                         }
  2916.                     }
  2917.                     break;
  2918. #endif /* NOPUSH */
  2919. #ifdef CK_RECALL
  2920.                   case '^': xx = XXREDO;  break;
  2921. #endif /* CK_RECALL */
  2922. #ifndef NOSPL
  2923.                   case '{': xx = XXMACRO; break;
  2924.                   case '(': xx = XXSEXP;  break;
  2925. #endif /* NOSPL */
  2926.  
  2927.                   default:
  2928.                     if (!quiet) {
  2929.                         printf("\n?Invalid - \"%s\"\n",cmdbuf);
  2930. #ifdef COMMENT
  2931. #ifndef NOSPL
  2932.                         if (maclvl > -1 && xcmdsrc == 2)
  2933.                           printf("Macro: %s; ",
  2934.                                  m_arg[maclvl][0] ?
  2935.                                  m_arg[maclvl][0] : "");
  2936. #endif /* NOSPL */
  2937.                         if (tlevel > -1) {
  2938.                             printf("Command file: %s, line %d\n",
  2939.                                    tfnam[tlevel] ? tfnam[tlevel] : "",
  2940.                                    tfline[tlevel]
  2941.                                    );
  2942.                         }
  2943. #else
  2944.                         if (xcmdsrc > 0) {
  2945.                             printf("Command stack:\n");
  2946.                             shostack();
  2947.                         }
  2948. #endif /* COMMENT */
  2949.  
  2950.                     }
  2951.                     xx = -2;
  2952.                 }
  2953.                 havetoken = 1;
  2954.                 debug(F101,"HAVE TOKEN","",xx);
  2955.             }
  2956.             if (xx > -1) {
  2957.                 topcmd = xx;            /* Top-level command index */
  2958. #ifndef NOSPL
  2959.                 if (maclvl > -1)
  2960.                   lastcmd[maclvl] = xx;
  2961. #endif /* NOSPL */
  2962.                 debug(F101,"topcmd","",topcmd);
  2963.                 debug(F101,"cmflgs","",cmflgs);
  2964.             }
  2965.  
  2966. #ifndef NOSPL
  2967.             /* Special handling for IF..ELSE */
  2968.  
  2969.             debug(F101,"cmdlvl","",cmdlvl);
  2970.             debug(F101,"ifcmd[cmdlvl]","",ifcmd[cmdlvl]);
  2971.  
  2972.             if (ifcmd[cmdlvl])          /* Count stmts after IF */
  2973.               ifcmd[cmdlvl]++;
  2974.             if (ifcmd[cmdlvl] > 2 && xx != XXELS && xx != XXCOM)
  2975.               ifcmd[cmdlvl] = 0;
  2976.  
  2977.             /* Execute the command and take action based on return code. */
  2978.  
  2979.             if (nulcmd) {               /* Ignoring this command? */
  2980.                 xx = XXCOM;             /* Make this command a comment. */
  2981.             }
  2982.             fnsuccess = 1;              /* For catching \function() errors */
  2983. #endif /* NOSPL */
  2984.  
  2985.             debug(F101,"calling docmd()","",xx);
  2986.             zz = docmd(xx);             /* Parse rest of command & execute. */
  2987.  
  2988. #ifndef NOSPL
  2989.             if (fnerror && !fnsuccess)
  2990.               success = 0;
  2991. #endif /* NOSPL */
  2992.             debug(F101,"docmd returns","",zz);
  2993.             /* debug(F011,"cmdbuf",cmdbuf,30); */
  2994.             /* debug(F011,"atmbuf",atmbuf,30); */
  2995. #ifdef MAC
  2996.             if (tlevel > -1) {
  2997.                 if (sstate == 'a') {    /* if cmd-. cancel */
  2998.                     debug(F110, "parser: cancel take, sstate:", "a", 0);
  2999.                     sstate = '\0';
  3000.                     dostop();
  3001.                     return(0);          /* End of init file or whatever. */
  3002.                 }
  3003.             }
  3004. #endif /* MAC */
  3005.             switch (zz) {
  3006.               case -4:                  /* EOF (e.g. on redirected stdin) */
  3007.                 doexit(GOOD_EXIT,xitsta); /* ...exit successfully */
  3008.               case -1:                  /* Reparse needed */
  3009.                 repars = 1;             /* Just set reparse flag and... */
  3010.                 continue;
  3011. #ifdef OS2
  3012.               case -7:                  /* They typed a disk letter */
  3013.                 if (!zchdir((char *)cmdbuf)) {
  3014.                     perror((char *)cmdbuf);
  3015.                     success = 0;
  3016.                 } else success = 1;
  3017.                 repars = 0;
  3018.                 continue;
  3019.  
  3020. #endif /* OS2 */
  3021.               case -6:                  /* Invalid command given w/no args */
  3022.               case -2:                  /* Invalid command given w/args */
  3023. #ifdef COMMENT
  3024. #ifndef NOSPL
  3025.                     /* This is going to be really ugly... */
  3026.                     yy = mlook(mactab,atmbuf,nmac); /* Look in macro table */
  3027.                     if (yy > -1) {                  /* If it's there */
  3028.                         if (zz == -2) {             /* insert "do" */
  3029.                             char *mp;
  3030.                             mp = malloc((int)strlen(cmdbuf) + 5);
  3031.                             if (!mp) {
  3032.                                 printf("?malloc error 1\n");
  3033.                                 return(-2);
  3034.                             }
  3035.                             sprintf(mp,"do %s ",cmdbuf); /* SAFE (checked) */
  3036.                             ckstrncpy(cmdbuf,mp,CMDBL);
  3037.                             free(mp);
  3038.                             mp = NULL;
  3039.                         } else {
  3040.                             if (((int)strlen(atmbuf) + 5) < CMDBL)
  3041.                               sprintf(cmdbuf,"do %s %c",atmbuf, CR); /* SAFE */
  3042.                             else
  3043.                               ckstrncpy(cmdbuf,"echo ?Too long\r",CMDBL);
  3044.                         }
  3045.                         if (ifcmd[cmdlvl] == 2) /* This one doesn't count! */
  3046.                           ifcmd[cmdlvl]--;
  3047.                         debug(F111,"stuff cmdbuf",cmdbuf,zz);
  3048.                         repars = 1;     /* Go for reparse */
  3049.                         continue;
  3050.                     } else {
  3051.                         char *p;
  3052.                         int n;
  3053.                         p = cmdbuf;
  3054.                         lp = line;
  3055.                         n = LINBUFSIZ;
  3056.                         if (cmflgs == 0) printf("\n");
  3057.                         if (zzstring(p,&lp,&n) > -1)
  3058.                           printf("?Invalid: %s\n",line);
  3059.                         else
  3060.                           printf("?Invalid: %s\n",cmdbuf);
  3061.                     } /* (fall thru...) */
  3062. #else
  3063.                     printf("?Invalid: %s\n",cmdbuf);
  3064. #endif /* NOSPL */
  3065. #else /* Not COMMENT */
  3066.                     printf("?Invalid: %s\n",cmdbuf);
  3067. #endif /* COMMENT */
  3068.  
  3069.                 case -9:                /* Bad, error message already done */
  3070.                     success = 0;
  3071.                     debug(F110,"top-level cmkey failed",cmdbuf,0);
  3072.                     /* If in background w/ commands coming stdin, terminate */
  3073.                     if (pflag == 0 && tlevel < 0)
  3074.                       fatal("Kermit command error in background execution");
  3075. /*
  3076.   Command retry feature, edit 190.  If we're at interactive prompting level,
  3077.   reprompt the user with as much of the command as didn't fail.
  3078. */
  3079. #ifdef CK_RECALL
  3080.                     if (cm_retry && !xcmdsrc) { /* If at top level */
  3081.                         int len;
  3082.                         char *p, *s;
  3083.                         len = strlen(cmdbuf); /* Length of command buffer */
  3084.                         p = malloc(len + 1);  /* Allocate space for copy */
  3085.                         if (p) {              /* If we got the space copy */
  3086.                             strcpy(p,cmdbuf); /* the command buffer (SAFE). */
  3087.                             /* Chop off final field, the one that failed. */
  3088.                             s = p + len - 1;          /* Point to end */
  3089.                             while (*s == SP && s > p) /* Trim blanks */
  3090.                               s--;
  3091.                             while (*s != SP && s > p) /* Trim last field */
  3092.                               s--;
  3093.                             if (s > p)        /* Keep the space */
  3094.                               s++;            /* after last good field */
  3095.                             if (s >= p)       /* Cut off remainder */
  3096.                               *s = NUL;
  3097.                             cmini(ckxech);    /* Reinitialize the parser */
  3098.                             ckstrncpy(cmdbuf,p,CMDBL); /* Copy result back */
  3099.                             free(p);          /* Free temporary storage */
  3100.                             p = NULL;
  3101.                             prompt(xxstring); /* Reprint the prompt */
  3102.                             printf("%s",cmdbuf); /* Reprint partial command */
  3103.                             repars = 1;          /* Force reparse */
  3104.                             continue;
  3105.                         }
  3106.                     } else
  3107. #endif /* CK_RECALL */
  3108.                       if (!quiet) {
  3109. #ifdef COMMENT
  3110. #ifndef NOSPL
  3111.                           if (maclvl > -1)
  3112.                             printf("Macro: %s; ",
  3113.                                    m_arg[maclvl][0] ?
  3114.                                    m_arg[maclvl][0] : "");
  3115. #endif /* NOSPL */
  3116.                           if (tlevel > -1)
  3117.                             printf("Command file: %s, line %d\n",
  3118.                                    tfnam[tlevel] ? tfnam[tlevel] : "",
  3119.                                    tfline[tlevel]
  3120.                                    );
  3121. #else
  3122.                           if (xcmdsrc > 0) {
  3123.                               printf("Command stack:\n");
  3124.                               shostack();
  3125.                           }
  3126. #endif /* COMMENT */
  3127.                       }
  3128.                       cmini(ckxech);    /* (fall thru) */
  3129.  
  3130.                 case -3:                /* Empty command OK at top level */
  3131.                     repars = 0;         /* Don't need to reparse. */
  3132.                     continue;           /* Go back and get another command. */
  3133.  
  3134.                 default:                /* Command was successful. */
  3135. #ifndef NOSPL
  3136.                     debug(F101,"parser preparing to continue","",maclvl);
  3137. #endif /* NOSPL */
  3138.                     debug(F101,"parser success","",success);
  3139.                     repars = 0;         /* Don't need to reparse. */
  3140.                     continue;           /* Go back and get another command. */
  3141.                 }
  3142.         }
  3143. #ifndef NOSPL
  3144.         debug(F101,"parser breaks out of while loop","",maclvl);
  3145.         if (m && (cmdlvl < inlevel))  return((int) sstate);
  3146. #endif /* NOSPL */
  3147.     }
  3148.  
  3149. /* Got an action command, return start state. */
  3150.  
  3151.     return((int) sstate);
  3152. }
  3153.  
  3154. #ifndef NOSPL
  3155. /*
  3156.   OUTPUT command.
  3157.   Buffering and pacing added by L.I. Kirby, 5A(189), June 1993.
  3158. */
  3159. #define OBSIZE 80                       /* Size of local character buffer */
  3160.  
  3161. static int obn;                         /* Buffer offset (high water mark) */
  3162. static char obuf[OBSIZE+1];             /* OUTPUT buffer. */
  3163. static char *obp;                       /* Pointer to output buffer. */
  3164. _PROTOTYP( static int oboc, (char) );
  3165. _PROTOTYP( static int xxout, (char *, int) );
  3166.  
  3167. static int
  3168. #ifdef CK_ANSIC
  3169. xxout(char *obuf, int obsize)
  3170. #else
  3171. xxout(obuf, obsize) char *obuf; int obsize;
  3172. #endif /* CK_ANSIC */
  3173. /* xxout */ {                           /* OUTPUT command's output function */
  3174.     int i, rc;
  3175.  
  3176.     debug(F101,"xxout obsize","",obsize);
  3177.     debug(F101,"xxout pacing","",pacing);
  3178.     debug(F111,"xxout string",obuf,strlen(obuf));
  3179.  
  3180.     rc = 0;                             /* Initial return code. */
  3181.     if (!obuf || (obsize <= 0))         /* Nothing to output. */
  3182.       goto xxout_x;                     /* Return successfully */
  3183.  
  3184.     rc = -1;                              /* Now assume failure */
  3185.     if (pacing == 0) {                    /* Is pacing enabled? */
  3186.         if ((local ?                      /* No, write entire string at once */
  3187.              ttol((CHAR *)obuf, obsize) : /* to communications device */
  3188.              conxo(obsize, obuf))         /* or to console */
  3189.             != obsize)
  3190.           goto xxout_x;
  3191.     } else {
  3192.         for (i = 0; i < obsize; i++) {  /* Write individual chars */
  3193.             if ((local ? ttoc(obuf[i]) : conoc(obuf[i])) < 0)
  3194.               goto xxout_x;
  3195.             msleep(pacing);
  3196.         }
  3197.     }
  3198.     if (duplex) {
  3199. #ifdef OS2
  3200.         if (inecho && local) {
  3201. #ifndef NOLOCAL
  3202.             for (i = 0; i < obsize; i++) { /* Write to emulator */
  3203.                 scriptwrtbuf((USHORT)obuf[i]); /* which also logs session */
  3204.             }
  3205. #endif /* NOLOCAL */
  3206.             conxo(obsize,obuf);
  3207.         } else if (seslog) {            /* or log session here */
  3208.             logstr((char *) obuf, obsize);
  3209.         }
  3210. #else /* OS2 */
  3211.         if (seslog) {
  3212.             logstr((char *) obuf, obsize);
  3213.         }
  3214.         if (inecho && local) {
  3215.             conxo(obsize,obuf);
  3216.         }
  3217. #endif /* OS2 */
  3218.     }
  3219.     rc = 0;                             /* Success */
  3220.   xxout_x:
  3221.     obn = 0;                            /* Reset count */
  3222.     obp = obuf;                         /* and pointers */
  3223.     return(rc);                         /* return our return code */
  3224. }
  3225.  
  3226. #ifdef COMMENT
  3227. /*
  3228.   Macros for OUTPUT command execution, to make it go faster.
  3229. */
  3230. #define obfls() ((xxout(obuf,obn)<0)?-1:0)
  3231. #define oboc(c) ((*obp++=(char)(c)),*obp=0,(((++obn)>=OBSIZE)?obfls():0))
  3232.  
  3233. #else /* The macros cause some compilers to generate bad code. */
  3234.  
  3235. static int
  3236. #ifdef CK_ANSIC
  3237. oboc(char c)
  3238. #else
  3239. oboc(c) char c;
  3240. #endif /* CK_ANSIC */
  3241. /* oboc */ {                            /* OUTPUT command's output function */
  3242.  
  3243.     *obp++ = c;                         /* Deposit character */
  3244.     *obp = NUL;                         /* Flush buffer if it's now full */
  3245.  
  3246.     return(((++obn) >= OBSIZE) ? xxout(obuf,obn) : 0);
  3247. }
  3248. #endif /* COMMENT */
  3249.  
  3250. /*  Routines for handling local variables -- also see popclvl().  */
  3251.  
  3252. VOID
  3253. freelocal(m) int m; {                   /* Free local variables */
  3254.     struct localvar * v, * tv;          /* at macro level m... */
  3255.     debug(F101,"freelocal level","",m);
  3256.     if (m < 0) return;
  3257.     v = localhead[m];                   /* List head for level m */
  3258.     while (v) {
  3259.         if (v->lv_name)                 /* Variable name */
  3260.           free(v->lv_name);
  3261.         if (v->lv_value)                /* Value */
  3262.           free(v->lv_value);
  3263.         tv = v;                         /* Save pointer to this node */
  3264.         v = v->lv_next;                 /* Get next one */
  3265.         if (tv)                         /* Free this one */
  3266.           free((char *)tv);
  3267.     }
  3268.     localhead[m] = (struct localvar *) NULL; /* Done, set list head to NULL */
  3269. }
  3270.  
  3271. #define MAXLOCALVAR 64
  3272.  
  3273. /* Return a pointer to the definition of a user-defined variable */
  3274.  
  3275. static char *
  3276. vardef(s,isarray,x1,x2) char * s; int * isarray, * x1, * x2; {
  3277.     char * p;
  3278.     char c;
  3279.     *isarray = 0;
  3280.     if (!s) return(NULL);
  3281.     if (!*s) return(NULL);
  3282.     p = s;
  3283.     if (*s == CMDQ) {
  3284.         p++;
  3285.         if (!*p)
  3286.           return(NULL);
  3287.         if ((c = *p) == '%') {          /* Scalar variable. */
  3288.             c = *++p;                   /* Get ID character. */
  3289.             p = "";                     /* Assume definition is empty */
  3290.             if (!c)
  3291.               return(NULL);
  3292.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  3293.                 if (maclvl < 0)         /* Digit variables are global */
  3294.                   return(g_var[c]);     /* if no macro is active */
  3295.                 else                    /* otherwise */
  3296.                   return(m_arg[maclvl][c - '0']); /* they're on the stack */
  3297.             } else if (isalpha(c)) {
  3298.                 if (isupper(c)) c -= ('a'-'A');
  3299.                 return(g_var[c]);           /* Letter for global variable */
  3300.             } else
  3301.               return(NULL);
  3302.         } else if (c == '&') {          /* Array reference. */
  3303.             int x, vbi, d;
  3304.             x = arraynam(p,&vbi,&d);    /* Get name and subscript */
  3305.             if (x > -1 || d == -17) {
  3306.                 *isarray = 1;
  3307.                 *x1 = vbi;
  3308.                 *x2 = (d == -17) ? 0 : d;
  3309.             }
  3310.             if (x < 0)
  3311.               return(NULL);
  3312.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  3313.                 vbi -= ARRAYBASE;       /* Convert name to index */
  3314.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  3315.                     char **ap;
  3316.                     ap = a_ptr[vbi];
  3317.                     return((ap) ? ap[d] : NULL);
  3318.                 }
  3319.             }
  3320.         }
  3321.         return(NULL);
  3322.     } else {
  3323.         int k;
  3324.         k = mxlook(mactab,s,nmac);
  3325.         return((k > -1) ? mactab[k].mval : NULL);
  3326.     }
  3327. }
  3328.  
  3329.  
  3330. int
  3331. addlocal(p) char * p; {
  3332.     int x, z, isarray = 0;
  3333.     char * s;
  3334.     struct localvar * v, *prev = (struct localvar *)NULL;
  3335.     extern int tra_asg; int tra_tmp;
  3336.  
  3337.     tra_tmp = tra_asg;
  3338.  
  3339.     s = vardef(p,&isarray,&x,&z);       /* Get definition of variable */
  3340.     if (isarray) {                      /* Arrays are handled specially */
  3341.         pusharray(x,z);
  3342.         return(0);
  3343.     }
  3344.     if (!s) s = "";
  3345.     if ((v = localhead[cmdlvl])) {      /* Already have some at this level? */
  3346.         while (v) {                     /* Find end of list */
  3347.             prev = v;
  3348.             v = v->lv_next;
  3349.         }
  3350.     }
  3351.     v = (struct localvar *) malloc(sizeof(struct localvar));
  3352.     if (!v) {
  3353.         printf("?Failure to allocate storage for local variables");
  3354.         return(-9);
  3355.     }
  3356.     if (!localhead[cmdlvl])             /* If first, set list head */
  3357.       localhead[cmdlvl] = v;
  3358.     else                                /* Otherwise link previous to this */
  3359.       prev->lv_next = v;
  3360.     prev = v;                           /* And make this previous */
  3361.     v->lv_next = (struct localvar *) NULL; /* No next yet */
  3362.  
  3363.     if (!(v->lv_name = (char *) malloc((int) strlen(p) + 1)))
  3364.       return(-1);
  3365.     strcpy(v->lv_name, p);              /* Copy name into new node (SAFE) */
  3366.  
  3367.     if (*s) {
  3368.         if (!(v->lv_value = (char *) malloc((int) strlen(s) + 1)))
  3369.           return(-1);
  3370.         strcpy(v->lv_value, s);         /* Copy value into new node (SAFE) */
  3371.     } else
  3372.       v->lv_value = NULL;
  3373.  
  3374.     tra_asg = 0;
  3375.     delmac(p,1);                        /* Delete the original macro */
  3376.     tra_asg = tra_tmp;
  3377.     return(0);
  3378. }
  3379.  
  3380. int
  3381. dolocal() {                             /* Do the LOCAL command */
  3382.     int i, x;
  3383.     char * s;
  3384.     char * list[MAXLOCALVAR+2];         /* Up to 64 variables per line */
  3385.  
  3386.     if ((x = cmtxt("Variable name(s)","",&s,NULL)) < 0)
  3387.       return(x);
  3388.  
  3389.     xwords(s,MAXLOCALVAR,list,0);       /* Break up line into "words" */
  3390.  
  3391.     /* Note: Arrays do not use the localhead list, but have their own stack */
  3392.  
  3393.     for (i = 1; i < MAXLOCALVAR && list[i]; i++) { /* Go through the list */
  3394.         if (addlocal(list[i]) < 0)
  3395.           goto localbad;
  3396.     }
  3397.     return(success = 1);
  3398.  
  3399.   localbad:
  3400.     printf("?Failure to allocate storage for local variables");
  3401.     freelocal(cmdlvl);
  3402.     return(-9);
  3403. }
  3404.  
  3405. /*  D O O U T P U T  --  Returns 0 on failure, 1 on success */
  3406.  
  3407. #ifndef NOKVERBS
  3408. #define K_BUFLEN 30
  3409. #define SEND_BUFLEN 255
  3410. #define sendbufd(x) { osendbuf[sendndx++] = x;\
  3411.  if (sendndx == SEND_BUFLEN) {dooutput(s,cx); sendndx = 0;}}
  3412. #endif /* NOKVERBS */
  3413.  
  3414. int outesc = 1;                         /* Process special OUTPUT escapes */
  3415.  
  3416. int
  3417. dooutput(s, cx) char *s; int cx; {
  3418.  
  3419.     int x, xx, y, quote;                /* Workers */
  3420.     int is_tn = 0;
  3421.  
  3422.     is_tn = (local && network && IS_TELNET()) ||
  3423.       (!local && sstelnet);
  3424.  
  3425.     debug(F111,"dooutput s",s,(int)strlen(s));
  3426.  
  3427.     if (local) {                        /* Condition external line */
  3428. #ifdef NOLOCAL
  3429.         goto outerr;
  3430. #else
  3431.         if (ttchk() < 0) {
  3432.             printf("?Connection %s %s is not open.\n",
  3433.                    network ? "to" : "on",
  3434.                    ttname
  3435.                    );
  3436.             return(0);
  3437.         }
  3438.         if (ttvt(speed,flow) < 0) {
  3439.             printf("?OUTPUT initialization error\n");
  3440.             return(0);
  3441.         }
  3442. #endif /* NOLOCAL */
  3443.     }
  3444.     if (!cmdgquo()) {                   /* COMMAND QUOTING OFF */
  3445.         x = strlen(s);                  /* Just send the string literally */
  3446.         xx = local ? ttol((CHAR *)s,x) : conxo(x,s);
  3447.         return(success = (xx == x) ? 1 : 0);
  3448.     }
  3449.     quote = 0;                          /* Initialize backslash (\) quote */
  3450.     obn = 0;                            /* Reset count */
  3451.     obp = obuf;                         /* and pointers */
  3452.  
  3453.   outagain:
  3454.     while ((x = *s++)) {                /* Loop through the string */
  3455.         y = 0;                          /* Error code, 0 = no error. */
  3456.         debug(F000,"dooutput","",x);
  3457.         if (quote) {                    /* This character is quoted */
  3458. #ifndef NOKVERBS
  3459.            if (x == 'k' || x == 'K') {  /* \k or \K */
  3460.                extern struct keytab kverbs[];
  3461.                extern int nkverbs;
  3462.                extern char * keydefptr;
  3463.                extern int keymac;
  3464.                extern int keymacx;
  3465.                int x, y, brace = 0;
  3466.                int pause;
  3467.                char * p, * b;
  3468.                char kbuf[K_BUFLEN + 1]; /* Key verb name buffer */
  3469.                char osendbuf[SEND_BUFLEN +1];
  3470.                int  sendndx = 0;
  3471.  
  3472.                if (xxout(obuf,obn) < 0) /* Flush buffer */
  3473.                  goto outerr;
  3474.                debug(F100,"OUTPUT KVERB","",0); /* Send a KVERB */
  3475.                {                        /* Have K verb? */
  3476.                    if (!*s) {
  3477.                        break;
  3478.                    }
  3479. /*
  3480.   We assume that the verb name is {braced}, or it extends to the end of the
  3481.   string, s, or it ends with a space, control character, or backslash.
  3482. */
  3483.                    p = kbuf;            /* Copy verb name into local buffer */
  3484.                    x = 0;
  3485.                    while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  3486.                        if (brace && *s == '}') {
  3487.                            break;
  3488.                        }
  3489.                        *p++ = *s++;
  3490.                    }
  3491.                    if (*s && !brace)    /* If we broke because of \, etc, */
  3492.                      s--;               /*  back up so we get another look. */
  3493.                    brace = 0;
  3494.                    *p = NUL;            /* Terminate. */
  3495.                    p = kbuf;            /* Point back to beginning */
  3496.                    debug(F110,"dooutput kverb",p,0);
  3497.                    y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  3498.                    debug(F101,"dooutput lookup",0,y);
  3499.                    if (y > -1) {
  3500.                        if (sendndx) {
  3501.                            dooutput(osendbuf,cx);
  3502.                            sendndx = 0;
  3503.                        }
  3504.                        dokverb(VCMD,y);
  3505. #ifndef NOSPL
  3506.                    } else {             /* Is it a macro? */
  3507.                        y = mxlook(mactab,p,nmac);
  3508.                        if (y > -1) {
  3509.                            cmpush();
  3510.                            keymac = 1;  /* Flag for key macro active */
  3511.                            keymacx = y; /* Key macro index */
  3512.                            keydefptr = s; /* Where to resume next time */
  3513.                            debug(F111,"dooutput mxlook",keydefptr,y);
  3514.                            parser(1);
  3515.                            cmpop();
  3516.                        }
  3517. #endif /* NOSPL */
  3518.                    }
  3519.                }
  3520.                quote = 0;
  3521.                continue;
  3522.            } else
  3523. #endif /* NOKVERBS */
  3524.              if (outesc && (x == 'n' || x == 'N')) { /* \n or \N */
  3525.                  if (xxout(obuf,obn) < 0) /* Flush buffer */
  3526.                    goto outerr;
  3527.                  debug(F100,"OUTPUT NUL","",0); /* Send a NUL */
  3528.                  if (local)
  3529.                    ttoc(NUL);
  3530.                  else
  3531.                    conoc(NUL);
  3532.                  quote = 0;
  3533.                  continue;
  3534.  
  3535.              } else if (outesc && (x == 'b' || x == 'B')) { /* \b or \B */
  3536.  
  3537.                 if (xxout(obuf,obn) < 0) /* Flush buffer first */
  3538.                   goto outerr;
  3539.                 debug(F100,"OUTPUT BREAK","",0);
  3540. #ifndef NOLOCAL
  3541.                 ttsndb();               /* Send BREAK signal */
  3542. #else
  3543.                  if (local)
  3544.                    ttoc(NUL);
  3545.                  else
  3546.                    conoc(NUL);
  3547. #endif /* NOLOCAL */
  3548.                 quote = 0;              /* Turn off quote flag */
  3549.                 continue;               /* and not the b or B */
  3550. #ifdef CK_LBRK
  3551.              } else if (outesc && (x == 'l' || x == 'L')) { /* \l or \L */
  3552.                  if (xxout(obuf,obn) < 0) /* Flush buffer first */
  3553.                    goto outerr;
  3554.                  debug(F100,"OUTPUT Long BREAK","",0);
  3555. #ifndef NOLOCAL
  3556.                  ttsndlb();             /* Send Long BREAK signal */
  3557. #else
  3558.                  if (local)
  3559.                    ttoc(NUL);
  3560.                  else
  3561.                    conoc(NUL);
  3562. #endif /* NOLOCAL */
  3563.                  quote = 0;             /* Turn off quote flag */
  3564.                  continue;              /* and not the l or L */
  3565. #endif /* CK_LBRK */
  3566.  
  3567.              } else if (x == CMDQ) {    /* Backslash itself */
  3568.                  debug(F100,"OUTPUT CMDQ","",0);
  3569.                  xx = oboc(dopar(CMDQ)); /* Output the backslash. */
  3570.                  if (xx < 0)
  3571.                    goto outerr;
  3572.                  quote = 0;
  3573.                  continue;
  3574.  
  3575.              } else {                   /* if \ not followed by special esc */
  3576.                 /* Note: Atari ST compiler won't allow macro call in "if ()" */
  3577.                  xx = oboc(dopar(CMDQ)); /* Output the backslash. */
  3578.                  if (xx < 0)
  3579.                    goto outerr;
  3580.                  quote = 0;             /* Turn off quote flag */
  3581.              }
  3582.         } else if (x == CMDQ) {         /* This is the quote character */
  3583.             quote = 1;                  /* Go back and get next character */
  3584.             continue;                   /* which is quoted */
  3585.         }
  3586.         xx = oboc(dopar((char)x));      /* Output this character */
  3587.         debug(F111,"dooutput",obuf,obn);
  3588.         if (xx < 0)
  3589.           goto outerr;
  3590. #ifdef COMMENT
  3591.         if (seslog && duplex) {         /* Log the character if log is on */
  3592.             logchar((char)x);
  3593.         }
  3594. #endif /* COMMENT */
  3595.         if (x == '\015') {              /* String contains carriage return */
  3596.             int stuff = -1, stuff2 = -1;
  3597.             if (tnlm) {                 /* TERMINAL NEWLINE ON */
  3598.                 stuff = LF;             /* Stuff LF */
  3599.             }
  3600. #ifdef TNCODE
  3601.             /* TELNET NEWLINE ON/OFF/RAW */
  3602.             if (is_tn) {
  3603.                 switch (TELOPT_ME(TELOPT_BINARY) ? /* NVT or BINARY */
  3604.                         tn_b_nlm :
  3605.                         tn_nlm
  3606.                         ) {
  3607.                   case TNL_CR:
  3608.                     break;
  3609.                   case TNL_CRNUL:
  3610.                     stuff2 = stuff;
  3611.                     stuff  = NUL;
  3612.                     break;
  3613.                   case TNL_CRLF:
  3614.                     stuff2 = stuff;
  3615.                     stuff = LF;
  3616.                     break;
  3617.                 }
  3618.             }
  3619. #endif /* TNCODE */
  3620.             if (stuff > -1) {           /* Stuffing another character... */
  3621.                 xx = oboc(dopar((CHAR)stuff));
  3622.                 if (xx < 0)
  3623.                   goto outerr;
  3624. #ifdef COMMENT
  3625.                 if (seslog && duplex) { /* Log stuffed char if appropriate */
  3626.                     logchar((char)stuff);
  3627.                 }
  3628. #endif /* COMMENT */
  3629.             }
  3630.             if (stuff2 > -1) {          /* Stuffing another character... */
  3631.                 xx = oboc(dopar((CHAR)stuff2));
  3632.                 if (xx < 0)
  3633.                   goto outerr;
  3634. #ifdef COMMENT
  3635.                 if (seslog && duplex) { /* Log stuffed char if appropriate */
  3636.                     logchar((char)stuff2);
  3637.                 }
  3638. #endif /* COMMENT */
  3639.             }
  3640.             if (xxout(obuf,obn) < 0)    /* Flushing is required here! */
  3641.               goto outerr;
  3642.         }
  3643.     }
  3644.     if (cx == XXLNOUT) {
  3645.         s = "\015";
  3646.         cx = 0;
  3647.         goto outagain;
  3648.     }
  3649.     if (quote == 1)                     /* String ended with backslash */
  3650.       xx = oboc(dopar(CMDQ));
  3651.  
  3652.     if (obn > 0)                        /* OUTPUT done */
  3653.       if (xxout(obuf,obn) < 0)          /* Flush the buffer if necessary. */
  3654.         goto outerr;
  3655.     return(1);
  3656.  
  3657. outerr:                                 /* OUTPUT command error handler */
  3658.     if (msgflg) printf("?OUTPUT execution error\n");
  3659.     return(0);
  3660.  
  3661. /* Remove "local" OUTPUT macro defininitions */
  3662.  
  3663. #ifdef COMMENT
  3664. /* No more macros ... */
  3665. #undef oboc
  3666. #undef obfls
  3667. #endif /* COMMENT */
  3668. }
  3669. #endif /* NOSPL */
  3670.  
  3671. /* Display version herald and initial prompt */
  3672.  
  3673. VOID
  3674. herald() {
  3675.     int x = 0, i;
  3676.     extern int srvcdmsg;
  3677.     extern char * cdmsgfile[];
  3678. #ifndef NOCMDL
  3679.     extern char * bannerfile;
  3680.     if (bannerfile) {
  3681.         concb((char)escape);
  3682.         if (dotype(bannerfile,1,0,0,NULL,0,NULL,0,0,NULL,0) > 0) {
  3683.             if (srvcdmsg) {
  3684.                 for (i = 0; i < 8; i++) {
  3685.                     if (zchki(cdmsgfile[i]) > -1) {
  3686.                         printf("\n");
  3687.                         dotype(cdmsgfile[i],
  3688.                                xaskmore,0,0,NULL,0,NULL,0,0,NULL,0);
  3689.                         break;
  3690.                     }
  3691.                 }
  3692.             }
  3693.             return;
  3694.         }
  3695.     }
  3696. #endif /* NOCMDL */
  3697.  
  3698. #ifdef COMMENT
  3699.     /* The following generates bad code in SCO compilers. */
  3700.     /* Observed in both OSR5 and Unixware 2 -- after executing this */
  3701.     /* statement when all conditions are false, x has a value of -32. */
  3702.     if (noherald || bgset > 0 || (bgset != 0 && backgrd != 0)) x = 1;
  3703. #else
  3704.     x = 0;
  3705.     if (noherald)
  3706.       x = 1;
  3707.     else if (bgset > 0)
  3708.       x = 1;
  3709.     else if (bgset < 0 && backgrd > 0)
  3710.       x = 1;
  3711. #endif /* COMMENT */
  3712.  
  3713.     if (x == 0) {
  3714. #ifdef datageneral
  3715.         printf("%s, for%s\n",versio,ckxsys);
  3716. #else
  3717. #ifdef OSK
  3718.         printf("%s, for%s\n",versio,ckxsys);
  3719. #else
  3720.         printf("%s, for%s\n\r",versio,ckxsys);
  3721. #endif /* OSK */
  3722. #endif /* datageneral */
  3723.         printf(" Copyright (C) 1985, 2002,\n");
  3724.         printf("  Trustees of Columbia University in the City of New York.\n");
  3725.  
  3726. #ifdef OS2
  3727.        shoreg();
  3728. #endif /* OS2 */
  3729.  
  3730.         if (!quiet && !backgrd) {
  3731. #ifdef COMMENT
  3732. /* "Default file-transfer mode is AUTOMATIC" is useless information... */
  3733.             char * s;
  3734.             extern int xfermode;
  3735. #ifdef VMS
  3736.             s = "AUTOMATIC";
  3737. #else
  3738.             if (xfermode == XMODE_A) {
  3739.                 s = "AUTOMATIC";
  3740.             } else {
  3741.                 s = gfmode(binary,1);
  3742.             }
  3743.             if (!s) s = "";
  3744. #endif /* VMS */
  3745.             if (*s)
  3746.               printf("Default file-transfer mode is %s\n", s);
  3747. #endif /* COMMENT */
  3748.  
  3749.             if (srvcdmsg) {
  3750.                 for (i = 0; i < 8; i++) {
  3751.                     if (zchki(cdmsgfile[i]) > -1) {
  3752.                         printf("\n");
  3753.                         dotype(cdmsgfile[i],
  3754.                                xaskmore,0,0,NULL,0,NULL,0,0,NULL,0);
  3755.                         break;
  3756.                     }
  3757.                 }
  3758.             }
  3759.             printf("Type ? or HELP for help.\n");
  3760.         }
  3761.     }
  3762. }
  3763.  
  3764. /*  G F M O D E  --  Get File (transfer) Mode  */
  3765.  
  3766. char *
  3767. gfmode(binary,upcase) int binary, upcase; {
  3768.     char * s;
  3769.     switch (binary) {
  3770.       case XYFT_T: s = upcase ? "TEXT" : "text"; break;
  3771. #ifdef VMS
  3772.       case XYFT_B: s = upcase ? "BINARY FIXED" : "binary fixed"; break;
  3773.       case XYFT_I: s = upcase ? "IMAGE" : "image"; break;
  3774.       case XYFT_L: s = upcase ? "LABELED" : "labeled"; break;
  3775.       case XYFT_U: s = upcase ? "BINARY UNDEF" : "binary undef"; break;
  3776. #else
  3777. #ifdef MAC
  3778.       case XYFT_B: s = upcase ? "BINARY" : "binary"; break;
  3779.       case XYFT_M: s = upcase ? "MACBINARY" : "macbinary"; break;
  3780. #else
  3781.       case XYFT_B: s = upcase ? "BINARY" : "binary"; break;
  3782. #ifdef CK_LABELED
  3783.       case XYFT_L: s = upcase ? "LABELED" : "labeled"; break;
  3784. #endif /* CK_LABELED */
  3785. #endif /* MAC */
  3786. #endif /* VMS */
  3787.       case XYFT_X: s = upcase ? "TENEX" : "tenex"; break;
  3788.       default: s = "";
  3789.     }
  3790.     return(s);
  3791. }
  3792.  
  3793. #ifndef NOSPL
  3794. static int
  3795. isaa(s) char * s; {                     /* Is associative array */
  3796.     char c;
  3797.     int x;
  3798.     if (!s) s = "";
  3799.     if (!*s) return(0);
  3800.     s++;
  3801.     while ((c = *s++)) {
  3802.         if (c == '<') {
  3803.             x = strlen(s);
  3804.             return ((*(s+x-1) == '>') ? 1 : 0);
  3805.         }
  3806.     }
  3807.     return(0);
  3808. }
  3809.  
  3810. /*  M L O O K  --  Lookup the macro name in the macro table  */
  3811.  
  3812. /*
  3813.   Call this way:  v = mlook(table,word,n);
  3814.  
  3815.     table - a 'struct mtab' table.
  3816.     word  - the target string to look up in the table.
  3817.     n     - the number of elements in the table.
  3818.  
  3819.   The keyword table must be arranged in ascending alphabetical order, and
  3820.   all letters must be lowercase.
  3821.  
  3822.   Returns the table index, 0 or greater, if the name was found, or:
  3823.  
  3824.    -3 if nothing to look up (target was null),
  3825.    -2 if ambiguous,
  3826.    -1 if not found.
  3827.  
  3828.   A match is successful if the target matches a keyword exactly, or if
  3829.   the target is a prefix of exactly one keyword.  It is ambiguous if the
  3830.   target matches two or more keywords from the table.
  3831. */
  3832. int
  3833. mlook(table,cmd,n) struct mtab table[]; char *cmd; int n; {
  3834.     register int i;
  3835.     int v, w, cmdlen = 0;
  3836.     char c = 0, c1, * s;
  3837.     if (!cmd) cmd = "";
  3838.  
  3839.     for (s = cmd; *s; s++) cmdlen++;    /* (instead of strlen) */
  3840.     debug(F111,"MLOOK",cmd,cmdlen);
  3841.  
  3842.     c1 = *cmd;
  3843.     if (isupper(c1))
  3844.       c1 = tolower(c1);
  3845.     if (cmdlen < 1)
  3846.       return(-3);
  3847.  
  3848. /* Not null, look it up */
  3849.  
  3850.     if (n < 12) {                       /* Not worth it for small tables */
  3851.         i = 0;
  3852.     } else {                            /* Binary search for where to start */
  3853.         int lo = 0;
  3854.         int hi = n;
  3855.         int count = 0;
  3856.         while (lo+2 < hi && ++count < 12) {
  3857.             i = lo + ((hi - lo) / 2);
  3858.             c = *(table[i].kwd);
  3859.             if (isupper(c)) c = tolower(c);
  3860.             if (c < c1) {
  3861.                 lo = i;
  3862.             } else {
  3863.                 hi = i;
  3864.             }
  3865.         }
  3866.         i = (c < c1) ? lo+1 : lo;
  3867.     }
  3868.     for ( ; i < n-1; i++) {
  3869.         s = table[i].kwd;
  3870.         if (!s) s = "";
  3871.         if (!*s) continue;              /* Empty table entry */
  3872.         c = *s;
  3873.         if (isupper(c)) c = tolower(c);
  3874.         if (c1 != c) continue;          /* First char doesn't match */
  3875.         if (!ckstrcmp(s,cmd,-1,0))      /* Have exact match? */
  3876.           return(i);
  3877.         v = !ckstrcmp(s,cmd,cmdlen,0);
  3878.         w = ckstrcmp(table[i+1].kwd,cmd,cmdlen,0);
  3879.         if (v && w)                     /* Have abbreviated match? */
  3880.           return(i);
  3881.         if (v)                          /* Ambiguous? */
  3882.           return(-2);
  3883.         if (w > 0)                      /* Past our alphabetic area? */
  3884.           return(-1);
  3885.     }
  3886.  
  3887. /* Last (or only) element */
  3888.  
  3889.     if (!ckstrcmp(table[n-1].kwd,cmd,cmdlen,0))
  3890.       return(n-1);
  3891.  
  3892.     return(-1);
  3893. }
  3894.  
  3895. /* mxlook is like mlook, but an exact full-length match is required */
  3896.  
  3897. int
  3898. mxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  3899.     register int i;
  3900.     int w, cmdlen = 0, one = 0;
  3901.     register char c = 0, c1, * s;
  3902.  
  3903.     if (!cmd) cmd = "";                 /* Check args */
  3904.  
  3905.     for (s = cmd; *s; s++) cmdlen++;    /* (instead of strlen) */
  3906.     debug(F111,"MXLOOK",cmd,cmdlen);
  3907.  
  3908.     c1 = *cmd;                          /* First char of string to look up */
  3909.     if (isupper(c1))
  3910.       c1 = tolower(c1);
  3911.     if (!*(cmd+1))                      /* Special handling for 1-char names */
  3912.       one = 1;
  3913.  
  3914.     if (cmdlen < 1)                     /* Nothing to look up */
  3915.       return(-3);
  3916.  
  3917.     if (n < 12) {                       /* Not worth it for small tables */
  3918.         i = 0;
  3919.     } else {                            /* Binary search for where to start */
  3920.         int lo = 0;
  3921.         int hi = n;
  3922.         int count = 0;
  3923.         while (lo+2 < hi && ++count < 12) {
  3924.             i = lo + ((hi - lo) / 2);
  3925.             c = *(table[i].kwd);
  3926.             if (isupper(c)) c = tolower(c);
  3927.             if (c < c1) {
  3928.                 lo = i;
  3929.             } else {
  3930.                 hi = i;
  3931.             }
  3932.         }
  3933.         i = (c < c1) ? lo+1 : lo;
  3934.     }
  3935.     for ( ; i < n; i++) {               /* Look thru table */
  3936.         s = table[i].kwd;               /* This entry */
  3937.         if (!s) s = "";
  3938.         if (!*s) continue;              /* Empty table entry */
  3939.         c = *s;
  3940.         if (isupper(c)) c = tolower(c);
  3941.         if (c1 != c) continue;          /* First char doesn't match */
  3942.         if (one) {                      /* Name is one char long */
  3943.             if (!*(s+1))
  3944.               return(i);                /* So is table entry */
  3945.         }
  3946. #ifdef COMMENT
  3947.         if (((int)strlen(s) == cmdlen) &&
  3948.             (!ckstrcmp(s,cmd,cmdlen,0))) return(i);
  3949. #else
  3950.         w = ckstrcmp(s,cmd,-1,0);
  3951.         if (!w) return(i);
  3952.         if (w > 0) return(-1);
  3953. #endif /* COMMENT */
  3954.     }
  3955.     return(-1);
  3956. }
  3957.  
  3958. /* mxxlook is like mxlook, but case-sensitive */
  3959.  
  3960. int
  3961. mxxlook(table,cmd,n) char *cmd; struct mtab table[]; int n; {
  3962.     int i, cmdlen;
  3963.     if (!cmd) cmd = "";
  3964.     if (((cmdlen = strlen(cmd)) < 1) || (n < 1)) return(-3);
  3965.     /* debug(F111,"mxxlook target",cmd,n); */
  3966.     for (i = 0; i < n; i++) {
  3967.         if (((int)strlen(table[i].kwd) == cmdlen) &&
  3968.             (!strncmp(table[i].kwd,cmd,cmdlen)))
  3969.           return(i);
  3970.     }
  3971.     return(-1);
  3972. }
  3973.  
  3974. static int
  3975. traceval(nam, val) char * nam, * val; { /* For TRACE command */
  3976.     if (val)
  3977.       printf(">>> %s: \"%s\"\n", nam, val);
  3978.     else
  3979.       printf(">>> %s: (undef)\n", nam);
  3980.     return(0);
  3981. }
  3982.  
  3983. #ifdef USE_VARLEN                       /* Not used */
  3984.  
  3985. /*  V A R L E N  --  Get length of variable's value.
  3986.  
  3987.   Given a variable name, return the length of its definition or 0 if the
  3988.   variable is not defined.  If it is defined, set argument s to point to its
  3989.   definition.  Otherwise set s to NULL.
  3990. */
  3991. int
  3992. varlen(nam,s) char *nam; char **s; {    /* Length of value of variable */
  3993.     int x, z;
  3994.     char *p = NULL, c;
  3995.  
  3996.     *s = NULL;
  3997.     if (!nam) return(0);                /* Watch out for null pointer */
  3998.     if (*nam == CMDQ) {
  3999.         nam++;
  4000.         if (*nam == '%') {              /* If it's a variable name */
  4001.             if (!(c = *(nam+1))) return(0); /* Get letter or digit */
  4002.             p = (char *)0;              /* Initialize value pointer */
  4003.             if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */
  4004.                 p = m_arg[maclvl][c - '0']; /* Pointer from macro-arg table */
  4005.             } else {                    /* It's a global variable */
  4006.                 if (c < 33 || c > GVARS) return(0);
  4007.                 p = g_var[c];           /* Get pointer from global-var table */
  4008.             }
  4009.         } else if (*nam == '&') {               /* An array reference? */
  4010.             char **q;
  4011.             if (arraynam(nam,&x,&z) < 0) /* If syntax is bad */
  4012.               return(-1);               /* return -1. */
  4013.             x -= ARRAYBASE;             /* Convert name to number. */
  4014.             if ((q = a_ptr[x]) == NULL) /* If array not declared, */
  4015.               return(0);                /* return -2. */
  4016.             if (z > a_dim[x])           /* If subscript out of range, */
  4017.               return(0);                /* return -3. */
  4018.             p = q[z];
  4019.         }
  4020.     } else {                            /* Macro */
  4021.         z = isaa(nam);
  4022.         x = z ? mxxlook(mactab,nam,nmac) : mlook(mactab,nam,nmac);
  4023.         if (x < 0)
  4024.           return(0);
  4025.         p = mactab[x].mval;
  4026.     }
  4027.     if (p)
  4028.       *s = p;
  4029.     else
  4030.       p = "";
  4031.     return((int)strlen(p));
  4032. }
  4033. #endif /* USE_VARLEN */
  4034.  
  4035. /*
  4036.   This routine is for the benefit of those compilers that can't handle
  4037.   long string constants or continued lines within them.  Long predefined
  4038.   macros like FOR, WHILE, and XIF have their contents broken up into
  4039.   arrays of string pointers.  This routine concatenates them back into a
  4040.   single string again, and then calls the real addmac() routine to enter
  4041.   the definition into the macro table.
  4042. */
  4043. int
  4044. addmmac(nam,s) char *nam, *s[]; {       /* Add a multiline macro definition */
  4045.     int i, x, y; char *p;
  4046.     x = 0;                              /* Length counter */
  4047.     for (i = 0; (y = (int)strlen(s[i])) > 0; i++) { /* Add up total length */
  4048.         debug(F111,"addmmac line",s[i],y);
  4049.         x += y;
  4050.     }
  4051.     debug(F101,"addmmac lines","",i);
  4052.     debug(F101,"addmmac loop exit","",y);
  4053.     debug(F111,"addmmac length",nam,x);
  4054.     if (x < 0) return(-1);
  4055.  
  4056.     p = malloc(x+1);                    /* Allocate space for all of it. */
  4057.     if (!p) {
  4058.         printf("?addmmac malloc error: %s\n",nam);
  4059.         debug(F110,"addmmac malloc error",nam,0);
  4060.         return(-1);
  4061.     }
  4062.     *p = '\0';                          /* Start off with null string. */
  4063.     for (i = 0; *s[i]; i++)             /* Concatenate them all together. */
  4064.       ckstrncat(p,s[i],x+1);
  4065.     y = (int)strlen(p);                 /* Final precaution. */
  4066.     debug(F111,"addmmac constructed string",p,y);
  4067.     if (y == x) {
  4068.         y = addmac(nam,p);              /* Add result to the macro table. */
  4069.     } else {
  4070.         debug(F100,"addmmac length mismatch","",0);
  4071.         printf("\n!addmmac internal error!\n");
  4072.         y = -1;
  4073.     }
  4074.     free(p);                            /* Free the temporary copy. */
  4075.     return(y);
  4076. }
  4077.  
  4078. /* Here is the real addmac routine. */
  4079.  
  4080. /* Returns -1 on failure, macro table index >= 0 on success. */
  4081.  
  4082. int mtchanged = 0;
  4083.  
  4084. int
  4085. addmac(nam,def) char *nam, *def; {      /* Add a macro to the macro table */
  4086.     int i, x, y, z, namlen, deflen, flag = 0;
  4087.     int replacing = 0, deleting = 0;
  4088.     char * p = NULL, c, *s;
  4089.     extern int tra_asg; int tra_tmp;
  4090.  
  4091.     if (!nam) return(-1);
  4092.     if (!*nam) return(-1);
  4093.  
  4094. #ifdef IKSD
  4095.     if (inserver &&
  4096. #ifdef IKSDCONF
  4097.         iksdcf
  4098. #else /* IKSDCONF */
  4099.         1
  4100. #endif /* IKSDCONF */
  4101.         ) {
  4102.         if (!ckstrcmp("on_exit",nam,-1,0) ||
  4103.             !ckstrcmp("on_logout",nam,-1,0))
  4104.           return(-1);
  4105.     }
  4106. #endif /* IKSD */
  4107.  
  4108.     namlen = 0;
  4109.     p = nam;
  4110.     while (*p++) namlen++;              /* (instead of strlen) */
  4111.  
  4112.     tra_tmp = tra_asg;                  /* trace... */
  4113.     debug(F111,"addmac nam",nam,namlen);
  4114.     if (!def) {                         /* Watch out for null pointer */
  4115.         deflen = 0;
  4116.         debug(F111,"addmac def","(null pointer)",deflen);
  4117.     } else {
  4118.         deflen = 0;
  4119.         p = def;
  4120.         while (*p++) deflen++;          /* (instead of strlen) */
  4121.         debug(F010,"addmac def",def,0);
  4122.     }
  4123. #ifdef USE_VARLEN                       /* NOT USED */
  4124.     /* This does not boost performance much because varlen() does a lot */
  4125.     x = varlen(nam,&s);
  4126.     if (x > 0 && x >= deflen) {
  4127.         strcpy(s,def);                  /* NOT USED */
  4128.         flag = 1;
  4129.         p = s;
  4130.     }
  4131. #endif /* USE_VARLEN */
  4132.  
  4133.     if (*nam == CMDQ) nam++;            /* Backslash quote? */
  4134.     if (*nam == '%') {                  /* Yes, if it's a variable name, */
  4135.         if (!(c = *(nam + 1))) return(-1); /* Variable name letter or digit */
  4136.         if (!flag) {
  4137.             tra_asg = 0;
  4138.             delmac(nam,0);              /* Delete any old value. */
  4139.             tra_asg = tra_tmp;
  4140.         }
  4141.         if (deflen < 1) {               /* Null definition */
  4142.             p = NULL;                   /* Better not malloc or strcpy! */
  4143.         } else if (!flag) {             /* A substantial definition */
  4144.             p = malloc(deflen + 1);     /* Allocate space for it */
  4145.             if (!p) {
  4146.                 printf("?addmac malloc error 2\n");
  4147.                 return(-1);
  4148.             } else strcpy(p,def);       /* Copy def into new space (SAFE) */
  4149.         }
  4150.  
  4151.         /* Now p points to the definition, or is a null pointer */
  4152.  
  4153.         if (c >= '0' && c <= '9') {     /* \%0-9 variable */
  4154.             if (maclvl < 0) {           /* Are we calling or in a macro? */
  4155.                 g_var[c] = p;           /* No, it's top level one */
  4156.                 makestr(&(toparg[c - '0']),p); /* Take care \&_[] too */
  4157.             } else {                    /* Yes, it's a macro argument */
  4158.                 m_arg[maclvl][c - '0'] = p; /* Assign the value */
  4159.                 makestr(&(m_xarg[maclvl][c - '0']),p); /* And a copy here */
  4160.             }
  4161.         } else {                        /* It's a \%a-z variable */
  4162.             if (c < 33 || (unsigned int)c > GVARS) return(-1);
  4163.             if (isupper(c)) c = (char) tolower(c);
  4164.             g_var[c] = p;               /* Put pointer in global-var table */
  4165.         }
  4166.         if (tra_asg) traceval(nam,p);
  4167.         return(0);
  4168.     } else if (*nam == '&') {           /* An array reference? */
  4169.         char **q = NULL;
  4170.         int rc = 0;
  4171.         if ((y = arraynam(nam,&x,&z)) < 0) /* If syntax is bad */
  4172.           return(-1);                   /* return -1. */
  4173.         if (chkarray(x,z) < 0)          /* If array not declared or */
  4174.           rc = -2;                      /* subscript out of range, ret -2 */
  4175.         if (!flag) {
  4176.             tra_asg = 0;
  4177.             delmac(nam,0);              /* Delete any old value. */
  4178.             tra_asg = tra_tmp;
  4179.         }
  4180.         x -= ARRAYBASE;                 /* Convert name letter to index. */
  4181.         if (x > 'z' - ARRAYBASE + 1)
  4182.           rc = -1;
  4183.         if (rc != -1) {
  4184.             if ((q = a_ptr[x]) == NULL) /* If array not declared, */
  4185.               return(-3);               /* return -3. */
  4186.         }
  4187.         if (rc < 0)
  4188.           return(rc);
  4189.         if (!flag) {
  4190.             if (deflen > 0) {
  4191.                 if ((p = malloc(deflen+1)) == NULL) { /* Allocate space */
  4192.                     printf("addmac macro error 7: %s\n",nam);
  4193.                     return(-4);         /* for new def, return -4 on fail. */
  4194.                 }
  4195.                 strcpy(p,def);          /* Copy def into new space (SAFE). */
  4196.             } else p = NULL;
  4197.         }
  4198.         q[z] = p;                       /* Store pointer to it. */
  4199.         if (x == 0) {                   /* Arg vector array */
  4200.             if (z >= 0 && z <= 9) {     /* Copy values to corresponding  */
  4201.                 if (maclvl < 0) {       /* \%1..9 variables. */
  4202.                     makestr(&(toparg[z]),p);
  4203.                 } else {
  4204.                     makestr(&(m_arg[maclvl][z]),p);
  4205.                 }
  4206.             }
  4207.         }
  4208.         if (tra_asg) traceval(nam,p);
  4209.         return(0);                      /* Done. */
  4210.     }
  4211.  
  4212. /* Not a macro argument or a variable, so it's a macro definition */
  4213.  
  4214. #ifdef USE_VARLEN
  4215.     if (flag) {
  4216.         if (tra_asg) traceval(nam,p);
  4217.         return(0);
  4218.     }
  4219. #endif /* USE_VARLEN */
  4220.     x = isaa(nam) ?                     /* If it's an associative array */
  4221.       mxxlook(mactab,nam,nmac) :        /* look it up this way */
  4222.         mxlook(mactab,nam,nmac);        /* otherwise this way. */
  4223.     if (x > -1) {                       /* If found... */
  4224.         if (deflen > 0)                 /* and a new definition was given */
  4225.           replacing = 1;                /* we're replacing */
  4226.         else                            /* otherwise */
  4227.           deleting = 1;                 /* we're deleting */
  4228.     }
  4229.     if (deleting) {                     /* Deleting... */
  4230.         if (delmac(nam,0) < 0)
  4231.           return(-1);
  4232.         mtchanged++;
  4233.         if (tra_asg) traceval(nam,p);
  4234.         return(0);
  4235.     } else if (deflen < 1)              /* New macro with no definition */
  4236.       return(0);                        /* Nothing to do. */
  4237.  
  4238.     if (replacing) {                    /* Replacing an existing macro */
  4239.         if (mactab[x].mval) {           /* If it currently has a definition, */
  4240.             free(mactab[x].mval);       /* free it. */
  4241.             mactab[x].mval = NULL;
  4242.         }
  4243.         mtchanged++;
  4244.         y = x;                          /* Replacement index. */
  4245.  
  4246.     } else {                            /* Adding a new macro... */
  4247.         char c1, c2;                    /* Use fast lookup to find the */
  4248.         c1 = *nam;                      /* alphabetical slot. */
  4249.         if (isupper(c1)) c1 = (char) tolower(c1);
  4250.  
  4251.         if (nmac < 5) {                 /* Not worth it for small tables */
  4252.             y = 0;
  4253.         } else {                        /* First binary search to find */
  4254.             int lo = 0;                 /* where to start */
  4255.             int hi = nmac;
  4256.             int count = 0;
  4257.             char c = 0;
  4258.             while (lo+2 < hi && ++count < 12) {
  4259.                 y = lo + ((hi - lo) / 2);
  4260.                 c = *(mactab[y].kwd);
  4261.                 if (isupper(c)) c = (char) tolower(c);
  4262.                 if (c < c1) {
  4263.                     lo = y;
  4264.                 } else {
  4265.                     hi = y;
  4266.                 }
  4267.             }
  4268.             y = (c < c1) ? lo+1 : lo;
  4269.         }
  4270.         /* Now search linearly from starting location */
  4271.         for ( ; y < MAC_MAX && mactab[y].kwd != NULL; y++) {
  4272.             c2 = *(mactab[y].kwd);
  4273.             if (isupper(c2)) c2 = (char) tolower(c2);
  4274.             if (c1 > c2)
  4275.               continue;
  4276.             if (c1 < c2)
  4277.               break;
  4278.             if (ckstrcmp(nam,mactab[y].kwd,-1,0) <= 0)
  4279.               break;
  4280.         }
  4281.         if (y == MAC_MAX) {             /* Macro table is full. */
  4282.             debug(F101,"addmac table overflow","",y);
  4283.             printf("?Macro table overflow\n");
  4284.             return(-1);
  4285.         }
  4286.         if (mactab[y].kwd != NULL) {    /* Must insert */
  4287.             for (i = nmac; i > y; i--) { /* Move the rest down one slot */
  4288.                 mactab[i].kwd = mactab[i-1].kwd;
  4289.                 mactab[i].mval = mactab[i-1].mval;
  4290.                 mactab[i].flgs = mactab[i-1].flgs;
  4291.             }
  4292.         }
  4293.         mtchanged++;
  4294.         p = malloc(namlen + 1);         /* Allocate space for name */
  4295.         if (!p) {
  4296.             printf("?Addmac: Out of memory - \"%s\"\n",nam);
  4297.             return(-1);
  4298.         }
  4299.         strcpy(p,nam);                  /* Copy name into new space (SAFE) */
  4300.         mactab[y].kwd = p;              /* Add pointer to table */
  4301.     }
  4302.     if (deflen > 0) {                   /* If we have a definition */
  4303.         p = malloc(deflen + 1);         /* Get space */
  4304.         if (p == NULL) {
  4305.             printf("?Space exhausted - \"%s\"\n", nam);
  4306.             if (mactab[y].kwd) {
  4307.                 free(mactab[y].kwd);
  4308.                 mactab[y].kwd = NULL;
  4309.             }
  4310.             return(-1);
  4311.         } else {
  4312.             strcpy(p,def);              /* Copy the definition (SAFE) */
  4313.         }
  4314.     } else {                            /* definition is empty */
  4315.         p = NULL;
  4316.     }
  4317.     mactab[y].mval = p;                 /* Macro points to definition */
  4318.     mactab[y].flgs = 0;                 /* No flags */
  4319.     if (!replacing)                     /* If new macro */
  4320.       nmac++;                           /* count it */
  4321.     if (tra_asg) traceval(nam,p);
  4322.     return(y);
  4323. }
  4324.  
  4325. int
  4326. xdelmac(x) int x; {                     /* Delete a macro given its index */
  4327.     int i;
  4328.     extern int tra_asg;
  4329.     if (x < 0) return(x);
  4330.     if (tra_asg)
  4331.       traceval(mactab[x].kwd,NULL);
  4332.  
  4333.     if (mactab[x].kwd) {                /* Free the storage for the name */
  4334.         free(mactab[x].kwd);
  4335.         mactab[x].kwd = NULL;
  4336.     }
  4337.     if (mactab[x].mval) {               /* and for the definition */
  4338.         free(mactab[x].mval);
  4339.         mactab[x].mval = NULL;
  4340.     }
  4341.     for (i = x; i < nmac; i++) {        /* Now move up the others. */
  4342.         mactab[i].kwd = mactab[i+1].kwd;
  4343.         mactab[i].mval = mactab[i+1].mval;
  4344.         mactab[i].flgs = mactab[i+1].flgs;
  4345.     }
  4346.     nmac--;                             /* One less macro */
  4347.  
  4348.     mactab[nmac].kwd = NULL;            /* Delete last item from table */
  4349.     mactab[nmac].mval = NULL;
  4350.     mactab[nmac].flgs = 0;
  4351.     mtchanged++;
  4352.     return(0);
  4353. }
  4354.  
  4355. int
  4356. delmac(nam,exact) char *nam; int exact; { /* Delete the named macro */
  4357.     int x, z;
  4358.     char *p, c;
  4359.     extern int tra_asg;
  4360.  
  4361.     if (!nam) return(0);                /* Watch out for null pointer */
  4362.     debug(F110,"delmac nam",nam,0);
  4363. #ifdef IKSD
  4364.     if ( inserver &&
  4365. #ifdef IKSDCONF
  4366.         iksdcf
  4367. #else /* IKSDCONF */
  4368.         1
  4369. #endif /* IKSDCONF */
  4370.         ) {
  4371.         if (!ckstrcmp("on_exit",nam,-1,0) ||
  4372.             !ckstrcmp("on_logout",nam,-1,0))
  4373.           return(-1);
  4374.     }
  4375. #endif /* IKSD */
  4376.  
  4377.     if (*nam == CMDQ) nam++;
  4378.     if (*nam == '%') {                  /* If it's a variable name */
  4379.         if (!(c = *(nam+1))) return(0); /* Get variable name letter or digit */
  4380.         p = (char *)0;                  /* Initialize value pointer */
  4381.         if (maclvl < 0 && c >= '0' && c <= '9') { /* Top-level digit? */
  4382.             p = toparg[c - '0'];
  4383.             if (p) if (p != g_var[c]) {
  4384.                 free(p);
  4385.                 toparg[c - '0'] = NULL;
  4386.             }
  4387.             p = g_var[c];
  4388.             g_var[c] = NULL;            /* Zero the table entry */
  4389.         } else if (maclvl > -1 && c >= '0' && c <= '9') { /* Digit? */
  4390.             p = m_xarg[maclvl][c - '0'];
  4391.             if (p) if (p != g_var[c]) {
  4392.                 free(p);
  4393.                 m_xarg[maclvl][c - '0'] = NULL;
  4394.             }
  4395.             p = m_arg[maclvl][c - '0']; /* Get pointer from macro-arg table */
  4396.             m_arg[maclvl][c - '0'] = NULL; /* Zero the table pointer */
  4397.         } else {                        /* It's a global variable */
  4398.             if (c < 33 || (unsigned int)c > GVARS) return(0);
  4399.             p = g_var[c];               /* Get pointer from global-var table */
  4400.             g_var[c] = NULL;            /* Zero the table entry */
  4401.         }
  4402.         if (p) {
  4403.             debug(F010,"delmac def",p,0);
  4404.             free(p);                    /* Free the storage */
  4405.             p = NULL;
  4406.         } else debug(F110,"delmac def","(null pointer)",0);
  4407.         if (tra_asg) traceval(nam,NULL);
  4408.         return(0);
  4409.     }
  4410.     if (*nam == '&') {                  /* An array reference? */
  4411.         char **q;
  4412.         if (arraynam(nam,&x,&z) < 0)    /* If syntax is bad */
  4413.           return(-1);                   /* return -1. */
  4414.         x -= ARRAYBASE;                 /* Convert name to number. */
  4415.         if ((q = a_ptr[x]) == NULL)     /* If array not declared, */
  4416.           return(-2);                   /* return -2. */
  4417.         if (z > a_dim[x])               /* If subscript out of range, */
  4418.           return(-3);                   /* return -3. */
  4419.         if (q[z]) {                     /* If there is an old value, */
  4420.             debug(F010,"delmac def",q[z],0);
  4421.             if (x != 0)                 /* Macro arg vector is just a copy */
  4422.               free(q[z]);               /* Others are real so free them */
  4423.             q[z] = NULL;
  4424.             if (x == 0) {               /* Arg vector array */
  4425.                 if (z >= 0 && z <= 9) { /* Copy values to corresponding  */
  4426.                     if (maclvl < 0) {   /* \%1..9 variables. */
  4427.                         makestr(&(toparg[z]),NULL);
  4428.                     } else {
  4429.                         makestr(&(m_arg[maclvl][z]),NULL);
  4430.                     }
  4431.                 }
  4432.             }
  4433.             if (tra_asg) traceval(nam,NULL);
  4434.         } else debug(F010,"delmac def","(null pointer)",0);
  4435.     }
  4436.  
  4437.    /* Not a variable or an array, so it must be a macro. */
  4438.  
  4439.     z = isaa(nam);
  4440.     debug(F111,"delmac isaa",nam,z);
  4441.     debug(F111,"delmac exact",nam,exact);
  4442.     x = z ? mxxlook(mactab,nam,nmac) :
  4443.       exact ? mxlook(mactab,nam,nmac) :
  4444.         mlook(mactab,nam,nmac);
  4445.     if (x < 0) {
  4446.         debug(F111,"delmac mlook",nam,x);
  4447.         return(x);
  4448.     }
  4449.     return(xdelmac(x));
  4450. }
  4451.  
  4452. VOID
  4453. initmac() {                             /* Init macro & variable tables */
  4454.     int i, j, x;
  4455.  
  4456.     nmac = 0;                           /* No macros */
  4457.     for (i = 0; i < MAC_MAX; i++) {     /* Initialize the macro table */
  4458.         mactab[i].kwd = NULL;
  4459.         mactab[i].mval = NULL;
  4460.         mactab[i].flgs = 0;
  4461.     }
  4462.     mtchanged++;
  4463.     x = (MAXARGLIST + 1) * sizeof(char **);
  4464.     for (i = 0; i < MACLEVEL; i++) {    /* Init the macro argument tables */
  4465.         m_xarg[i] = (char **) malloc(x);
  4466.         mrval[i] = NULL;                /* Macro return value */
  4467.         /* Pointer to entire argument vector, level i, for \&_[] array */
  4468.         for (j = 0; j <= MAXARGLIST; j++) { /* Macro argument list */
  4469.             if (j < 10)                 /* For the \%0..\%9 variables */
  4470.               m_arg[i][j] = NULL;       /* Pointer to arg j, level i. */
  4471.             if (m_xarg[i])              /* For \&_[] - all args. */
  4472.               m_xarg[i][j] = NULL;
  4473.         }
  4474.     }
  4475.     for (i = 0; i < GVARS; i++) {       /* And the global variables table */
  4476.         g_var[i] = NULL;
  4477.     }
  4478.     /* And the table of arrays */
  4479.     for (i = 0; i < (int) 'z' - ARRAYBASE + 1; i++) {
  4480.         a_ptr[i] = (char **) NULL;      /* Null pointer for each */
  4481.         a_dim[i] = 0;                   /* and a dimension of zero */
  4482.         a_link[i] = -1;
  4483.         for (j = 0; j < CMDSTKL; j++) {
  4484.             aa_ptr[j][i] = (char **) NULL;
  4485.             aa_dim[j][i] = 0;
  4486.         }
  4487.     }
  4488. }
  4489.  
  4490. int
  4491. popclvl() {                             /* Pop command level, return cmdlvl */
  4492.     extern int tra_cmd;
  4493.     struct localvar * v;
  4494.     int i, topcmd;
  4495.     debug(F101,"popclvl cmdlvl","",cmdlvl);
  4496.     if (cmdlvl > 0) {
  4497.         if ((v = localhead[cmdlvl])) {  /* Did we save any variables? */
  4498.             while (v) {                 /* Yes */
  4499.                 if (v->lv_value)        /* Copy old ones back */
  4500.                   addmac(v->lv_name,v->lv_value);
  4501.                 else
  4502.                   delmac(v->lv_name,1);
  4503.                 v = v->lv_next;
  4504.             }
  4505.             freelocal(cmdlvl);          /* Free local storage */
  4506.         }
  4507.         /* Automatic arrays do not use the localhead list */
  4508.  
  4509.         for (i = 0; i < 28; i++) {      /* Free any local arrays */
  4510.             if (aa_ptr[cmdlvl][i]) { /* Does this one exist? */
  4511.                 dclarray((char)(i+ARRAYBASE),0); /* Destroy global one */
  4512.                 a_ptr[i] = aa_ptr[cmdlvl][i];
  4513.                 a_dim[i] = aa_dim[cmdlvl][i];
  4514.                 aa_ptr[cmdlvl][i] = (char **)NULL;
  4515.                 aa_dim[cmdlvl][i] = 0;
  4516.             } else if (aa_dim[cmdlvl][i] == -23) { /* Secret code */
  4517.                 dclarray((char)(i+ARRAYBASE),0); /* (see pusharray()) */
  4518.                 aa_ptr[cmdlvl][i] = (char **)NULL;
  4519.                 aa_dim[cmdlvl][i] = 0;
  4520.             }
  4521.             /* Otherwise do nothing - it is a local array that was declared */
  4522.             /* at a level above this one so leave it alone. */
  4523.         }
  4524.     }
  4525.     if (cmdlvl < 1) {                   /* If we're already at top level */
  4526.         cmdlvl = 0;                     /* just make sure all the */
  4527.         tlevel = -1;                    /* stack pointers are set right */
  4528.         maclvl = -1;                    /* and return */
  4529.     } else if (cmdstk[cmdlvl].src == CMD_TF) { /* Reading from TAKE file? */
  4530.         debug(F101,"popclvl tlevel","",tlevel);
  4531.         if (tlevel > -1) {              /* Yes, */
  4532.             fclose(tfile[tlevel]);      /* close it */
  4533.  
  4534.             if (tra_cmd)
  4535.               printf("[%d] -F: \"%s\"\n",cmdlvl,tfnam[tlevel]);
  4536.             debug(F111,"CMD -F",tfnam[tlevel],cmdlvl);
  4537.             if (tfnam[tlevel]) {        /* free storage for name */
  4538.                 free(tfnam[tlevel]);
  4539.                 tfnam[tlevel] = NULL;
  4540.             }
  4541.             tlevel--;                   /* and pop take level */
  4542.             cmdlvl--;                   /* and command level */
  4543.             quiet = xquiet[cmdlvl];
  4544.         } else
  4545.           tlevel = -1;
  4546.     } else if (cmdstk[cmdlvl].src == CMD_MD) { /* In a macro? */
  4547.         topcmd = lastcmd[maclvl];
  4548.         debug(F101,"popclvl maclvl","",maclvl);
  4549.         if (maclvl > -1) {              /* Yes, */
  4550. #ifdef COMMENT
  4551.             int i;
  4552.             char **q;
  4553. #endif /* COMMENT */
  4554.             macp[maclvl] = "";          /* set macro pointer to null string */
  4555.             *cmdbuf = '\0';             /* clear the command buffer */
  4556.  
  4557.             if ((maclvl > 0) &&         /* 2 May 1999 */
  4558.                 (m_arg[maclvl-1][0]) &&
  4559.                 (!strncmp(m_arg[maclvl-1][0],"_xif",4) ||
  4560.                  !strncmp(m_arg[maclvl-1][0],"_for",4) ||
  4561.                  !strncmp(m_arg[maclvl-1][0],"_swi",4) ||
  4562.                  !strncmp(m_arg[maclvl-1][0],"_whi",4)) &&
  4563.                 mrval[maclvl+1]) {
  4564.                 makestr(&(mrval[maclvl-1]),mrval[maclvl+1]);
  4565.             }
  4566.             if (maclvl+1 < MACLEVEL) {
  4567.                 if (mrval[maclvl+1]) {  /* Free any deeper return values. */
  4568.                     free(mrval[maclvl+1]);
  4569.                     mrval[maclvl+1] = NULL;
  4570.                 }
  4571.             }
  4572.             if (tra_cmd)
  4573.               printf("[%d] -M: \"%s\"\n",cmdlvl,m_arg[cmdstk[cmdlvl].lvl][0]);
  4574.             debug(F111,"CMD -M",m_arg[cmdstk[cmdlvl].lvl][0],cmdlvl);
  4575.  
  4576.             maclvl--;                   /* Pop macro level */
  4577.             cmdlvl--;                   /* and command level */
  4578.             debug(F101,"popclvl mac new maclvl","",maclvl);
  4579.             debug(F010,"popclvl mac mrval[maclvl+1]",mrval[maclvl+2],0);
  4580.  
  4581.             quiet = xquiet[cmdlvl];
  4582.             if (maclvl > -1) {
  4583.                 a_ptr[0] = m_xarg[maclvl];
  4584.                 a_dim[0] = n_xarg[maclvl] - 1;
  4585.         debug(F111,"a_dim[0]","B",a_dim[0]);
  4586.             } else {
  4587.                 a_ptr[0] = topxarg;
  4588.                 a_dim[0] = topargc - 1;
  4589.         debug(F111,"a_dim[0]","C",a_dim[0]);
  4590.             }
  4591.         } else {
  4592.             maclvl = -1;
  4593.         }
  4594. #ifndef NOSEXP
  4595.         debug(F101,"popclvl topcmd","",topcmd);
  4596.         if (topcmd == XXSEXP) {
  4597.             extern char * sexpval;
  4598.             makestr(&(mrval[maclvl+1]),sexpval);
  4599.         }
  4600. #endif /* NOSEXP */
  4601.     } else {
  4602.         cmdlvl--;
  4603.     }
  4604.     debug(F101,"popclvl cmdlvl","",cmdlvl);
  4605.     if (prstring[cmdlvl]) {
  4606.         cmsetp(prstring[cmdlvl]);
  4607.         makestr(&(prstring[cmdlvl]),NULL);
  4608.     }
  4609. #ifndef MAC
  4610.     if (cmdlvl < 1 || xcmdsrc == CMD_KB) { /* If at prompt */
  4611.         setint();
  4612.         concb((char)escape);            /* Go into cbreak mode */
  4613.     }
  4614. #endif /* MAC */
  4615.     xcmdsrc = cmdstk[cmdlvl].src;
  4616.     debug(F101,"popclvl xcmdsrc","",xcmdsrc);
  4617.     debug(F101,"popclvl tlevel","",tlevel);
  4618.     return(cmdlvl < 1 ? 0 : cmdlvl);    /* Return command level */
  4619. }
  4620. #else /* No script programming language */
  4621. int popclvl() {                         /* Just close current take file. */
  4622.     if (tlevel > -1) {                  /* if any... */
  4623.         if (tfnam[tlevel]) {
  4624.             free(tfnam[tlevel]);
  4625.             tfnam[tlevel] = NULL;
  4626.         }
  4627.         fclose(tfile[tlevel--]);
  4628.     }
  4629.     if (tlevel == -1) {                 /* And if back at top level */
  4630.         setint();
  4631.         concb((char)escape);            /* and go back into cbreak mode. */
  4632.     }
  4633.     xcmdsrc = tlevel > -1 ? CMD_TF : 0;
  4634.     return(tlevel + 1);
  4635. }
  4636. #endif /* NOSPL */
  4637.  
  4638.  
  4639. #ifndef NOSPL
  4640. static int
  4641. iseom(m) char * m; {                    /* Test if at end of macro def */
  4642.     if (!m)
  4643.       m = "";
  4644.     debug(F111,"iseom",m,maclvl);
  4645.     while (*m) {
  4646.         /* Anything but Space and Comma means more macro is left */
  4647.         if ((*m > SP) && (*m != ',')) {
  4648.             debug(F111,"iseom return",m,0);
  4649.             return(0);
  4650.         }
  4651.         m++;
  4652.     }
  4653.     debug(F111,"iseom return",m,1);
  4654.     return(1);                          /* Nothing left */
  4655. }
  4656. #endif /* NOSPL */
  4657.  
  4658. /* Pop all command levels that can be popped */
  4659.  
  4660. int
  4661. prepop() {
  4662.     if (cmdlvl > 0) {                   /* If command level is > 0 and... */
  4663.         while (
  4664. #ifndef NOSPL
  4665.                ((cmdstk[cmdlvl].src == CMD_TF) && /* Command source is file */
  4666. #endif /* NOSPL */
  4667.             (tlevel > -1) &&
  4668.             feof(tfile[tlevel]))        /* And at end of file... */
  4669. #ifndef NOSPL
  4670.                /* Or command source is macro... */
  4671.                || ((cmdstk[cmdlvl].src == CMD_MD) &&
  4672.                 (maclvl > -1) &&
  4673.                 iseom(macp[maclvl])))  /* and at end of macro, then... */
  4674. #endif /* NOSPL */
  4675.         {
  4676.               popclvl();                /* pop command level. */
  4677.         }
  4678.     }
  4679.     return(cmdlvl < 1 ? 0 : cmdlvl);    /* Return command level */
  4680. }
  4681.  
  4682. /* STOP - get back to C-Kermit prompt, no matter where from. */
  4683.  
  4684. int
  4685. dostop() {
  4686.     extern int cmddep;
  4687.     while (popclvl()) ;         /* Pop all macros & take files */
  4688. #ifndef NOSPL
  4689.     if (cmddep > -1)            /* And all recursive cmd pkg invocations */
  4690.       while (cmpop() > -1) ;
  4691. #endif /* NOSPL */
  4692.     cmini(ckxech);              /* Clear the command buffer. */
  4693.     return(0);
  4694. }
  4695.  
  4696. /* Close the given log */
  4697.  
  4698. int
  4699. doclslog(x) int x; {
  4700.     int y;
  4701.     switch (x) {
  4702. #ifdef DEBUG
  4703.       case LOGD:
  4704.         if (deblog <= 0) {
  4705.             printf("?Debugging log wasn't open\n");
  4706.             return(0);
  4707.         }
  4708.         debug(F100,"Debug Log Closed","",0L);
  4709.         *debfil = '\0';
  4710.         deblog = 0;
  4711.         return(zclose(ZDFILE));
  4712. #endif /* DEBUG */
  4713.  
  4714. #ifndef NOXFER
  4715.       case LOGP:
  4716.         if (pktlog <= 0) {
  4717.             printf("?Packet log wasn't open\n");
  4718.             return(0);
  4719.         }
  4720.         *pktfil = '\0';
  4721.         pktlog = 0;
  4722.         return(zclose(ZPFILE));
  4723. #endif /* NOXFER */
  4724.  
  4725. #ifndef NOLOCAL
  4726.       case LOGS:
  4727.         if (seslog <= 0) {
  4728.             printf("?Session log wasn't open\n");
  4729.             return(0);
  4730.         }
  4731.         *sesfil = '\0';
  4732.         setseslog(0);
  4733.         return(zclose(ZSFILE));
  4734. #endif /* NOLOCAL */
  4735.  
  4736. #ifdef TLOG
  4737.       case LOGT: {
  4738. #ifdef IKSD
  4739.           extern int iklogopen, xferlog;
  4740. #endif /* IKSD */
  4741.           if (tralog <= 0
  4742. #ifdef IKSD
  4743.               && !iklogopen
  4744. #endif /* IKSD */
  4745.               ) {
  4746.               if (msgflg)
  4747.                 printf("?Transaction log wasn't open\n");
  4748.               return(0);
  4749.           }
  4750. #ifdef IKSD
  4751.           if (iklogopen && !inserver) {
  4752.               close(xferlog);
  4753.               iklogopen = 0;
  4754.           }
  4755. #endif /* IKSD */
  4756.           if (tralog) {
  4757.               tlog(F100,"Transaction Log Closed","",0L);
  4758.               zclose(ZTFILE);
  4759.           }
  4760.           *trafil = '\0';
  4761.           tralog = 0;
  4762.           return(1);
  4763.       }
  4764. #endif /* TLOG */
  4765.  
  4766. #ifdef CKLOGDIAL
  4767.       case LOGM:
  4768.         if (dialog <= 0) {
  4769.             if (msgflg) printf("?Connection log wasn't open\n");
  4770.             return(0);
  4771.         }
  4772.         *diafil = '\0';
  4773.         dialog = 0;
  4774.         return(zclose(ZDIFIL));
  4775. #endif /* CKLOGDIAL */
  4776.  
  4777. #ifndef NOSPL
  4778.       case LOGW:                        /* WRITE file */
  4779.       case LOGR:                        /* READ file */
  4780.         y = (x == LOGR) ? ZRFILE : ZWFILE;
  4781.         if (chkfn(y) < 1)               /* If no file to close */
  4782.           return(1);                    /* succeed silently. */
  4783.         return(zclose(y));              /* Otherwise, close the file. */
  4784. #endif /* NOSPL */
  4785.  
  4786.       default:
  4787.         printf("\n?Unexpected log designator - %d\n", x);
  4788.         return(0);
  4789.     }
  4790. }
  4791.  
  4792. static int slc = 0;                     /* Screen line count */
  4793.  
  4794. char *
  4795. showstring(s) char * s; {
  4796.     return(s ? s : "(null)");
  4797. }
  4798.  
  4799. char *
  4800. showoff(x) int x; {
  4801.     return(x ? "on" : "off");
  4802. }
  4803.  
  4804. char *
  4805. showooa(x) int x; {
  4806.     switch (x) {
  4807.       case SET_OFF:  return("off");
  4808.       case SET_ON:   return("on");
  4809.       case SET_AUTO: return("automatic");
  4810.       default:       return("(unknown)");
  4811.     }
  4812. }
  4813.  
  4814. #ifdef GEMDOS
  4815. isxdigit(c) int c; {
  4816.     return(isdigit(c) ||
  4817.            (c >= 'a' && c <= 'f') ||
  4818.            (c >= 'A' && c <= 'F'));
  4819. }
  4820. #endif /* GEMDOS */
  4821.  
  4822. #ifndef NOSETKEY
  4823. #ifdef OS2
  4824. static struct keytab shokeytab[] = {    /* SHOW KEY modes */
  4825.     "all",    1, 0,
  4826.     "one",    0, 0
  4827. };
  4828. static int nshokey = (sizeof(shokeytab) / sizeof(struct keytab));
  4829.  
  4830. #define SHKEYDEF TT_MAX+5
  4831. struct keytab shokeymtab[] = {
  4832.     "aaa",       TT_AAA,     CM_INV,    /* AnnArbor */
  4833.     "adm3a",     TT_ADM3A,   0,         /* LSI ADM-3A */
  4834.     "aixterm",   TT_AIXTERM, 0,         /* IBM AIXterm */
  4835.     "annarbor",  TT_AAA,     0,         /* AnnArbor */
  4836.     "ansi-bbs",  TT_ANSI,    0,         /* ANSI.SYS (BBS) */
  4837.     "at386",     TT_AT386,   0,         /* Unixware ANSI */
  4838.     "avatar/0+", TT_ANSI,    0,         /* AVATAR/0+ */
  4839.     "ba80",      TT_BA80,    0,         /* Nixdorf BA80 */
  4840.     "be",        TT_BEOS,    CM_INV|CM_ABR,
  4841.     "beos-ansi", TT_BEOS,    CM_INV,    /* BeOS ANSI */
  4842.     "beterm",    TT_BEOS,    0,         /* BeOS Console */
  4843.     "d200",      TT_DG200,   CM_INV|CM_ABR, /* Data General DASHER 200 */
  4844.     "d210",      TT_DG210,   CM_INV|CM_ABR, /* Data General DASHER 210 */
  4845.     "d217",      TT_DG217,   CM_INV|CM_ABR, /* Data General DASHER 217 */
  4846.     "default",   SHKEYDEF,   0,
  4847.     "dg200",     TT_DG200,   0,         /* Data General DASHER 200 */
  4848.     "dg210",     TT_DG210,   0,         /* Data General DASHER 210 */
  4849.     "dg217",     TT_DG217,   0,         /* Data General DASHER 217 */
  4850.     "emacs",     TT_KBM_EMACS,   0,     /* Emacs mode */
  4851.     "h19",       TT_H19,     CM_INV,    /* Heath-19 */
  4852.     "heath19",   TT_H19,     0,         /* Heath-19 */
  4853.     "hebrew",    TT_KBM_HEBREW, 0,      /* Hebrew mode */
  4854.     "hft",       TT_HFT,     0,         /* IBM HFT */
  4855.     "hp2621a",   TT_HP2621,  0,         /* HP 2621A */
  4856.     "hpterm",    TT_HPTERM,  0,         /* HP TERM */
  4857.     "hz1500",    TT_HZL1500, 0,         /* Hazeltine 1500 */
  4858.     "ibm3151",   TT_IBM31,   0,         /* IBM 3101-xx,3161 */
  4859.     "linux",     TT_LINUX,   0,         /* Linux */
  4860.     "qansi",     TT_QANSI,   0,         /* QNX ANSI */
  4861.     "qnx",       TT_QNX,     0,         /* QNX */
  4862.     "russian",   TT_KBM_RUSSIAN, 0,     /* Russian mode */
  4863.     "scoansi",   TT_SCOANSI, 0,         /* SCO ANSI */
  4864.     "sni-97801", TT_97801,   0,         /* Sinix 97801 */
  4865.     "sun",       TT_SUN,     0,         /* Sun Console */
  4866. #ifdef OS2PM
  4867. #ifdef COMMENT
  4868.     "tek4014", TT_TEK40, 0,
  4869. #endif /* COMMENT */
  4870. #endif /* OS2PM */
  4871.     "tty",     TT_NONE,  0,
  4872.     "tvi910+", TT_TVI910, 0,
  4873.     "tvi925",  TT_TVI925, 0,
  4874.     "tvi950",  TT_TVI950, 0,
  4875.     "vc404",   TT_VC4404, 0,
  4876.     "vc4404",  TT_VC4404, CM_INV,
  4877.     "vip7809", TT_VIP7809, 0,
  4878.     "vt100",   TT_VT100, 0,
  4879.     "vt102",   TT_VT102, 0,
  4880.     "vt220",   TT_VT220, 0,
  4881.     "vt220pc", TT_VT220PC, 0,
  4882.     "vt320",   TT_VT320, 0,
  4883.     "vt320pc", TT_VT320PC, 0,
  4884.     "vt52",    TT_VT52,  0,
  4885.     "wp",      TT_KBM_WP, 0,
  4886.     "wy160",   TT_WY160,  0,
  4887.     "wy30",    TT_WY30,  0,
  4888.     "wy370",   TT_WY370, 0,
  4889.     "wy50",    TT_WY50,  0,
  4890.     "wy60",    TT_WY60,  0,
  4891.     "wyse30",  TT_WY30,  CM_INV,
  4892.     "wyse370", TT_WY370, CM_INV,
  4893.     "wyse50",  TT_WY50,  CM_INV,
  4894.     "wyse60",  TT_WY60,  CM_INV
  4895. };
  4896. int nshokeym = (sizeof(shokeymtab) / sizeof(struct keytab));
  4897. #endif /* OS2 */
  4898.  
  4899. VOID
  4900. #ifdef OS2
  4901. shokeycode(c,m) int c, m;
  4902. #else
  4903. shokeycode(c) int c;
  4904. #endif
  4905. /* shokeycode */ {
  4906.     KEY ch;
  4907.     CHAR *s;
  4908. #ifdef OS2
  4909.     int i;
  4910.     con_event km;
  4911. #else /* OS2 */
  4912.     int km;
  4913. #endif /* OS2 */
  4914.  
  4915. #ifdef OS2
  4916.     extern int mskkeys;
  4917.     char * mstr = "";
  4918.  
  4919.     if (c >= KMSIZE) {
  4920.         bleep(BP_FAIL);
  4921.         return;
  4922.     }
  4923. #else /* OS2 */
  4924.     printf(" Key code \\%d => ", c);
  4925. #endif /* OS2 */
  4926.  
  4927. #ifndef OS2
  4928.     km = mapkey(c);
  4929.  
  4930. #ifndef NOKVERBS
  4931.     if (IS_KVERB(km)) {                 /* \Kverb? */
  4932.         int i, kv;
  4933.         kv = km & ~(F_KVERB);
  4934.         printf("Verb: ");
  4935.         for (i = 0; i < nkverbs; i++)
  4936.           if (kverbs[i].kwval == kv) {
  4937.               printf("\\K%s",kverbs[i].kwd);
  4938.               break;
  4939.           }
  4940.         printf("\n");
  4941.     } else
  4942. #endif /* NOKVERBS */
  4943.       if (IS_CSI(km)) {
  4944.           int xkm = km & 0xFF;
  4945.           if (xkm <= 32 || xkm >= 127)
  4946.             printf("String: \\{27}[\\{%d}\n",xkm);
  4947.           else
  4948.             printf("String: \\{27}[%c\n",xkm);
  4949.       } else if (IS_ESC(km)) {
  4950.           int xkm = km & 0xFF;
  4951.           if (xkm <= 32 || xkm >= 127)
  4952.             printf("String: \\{27}\\{%d}\n",xkm);
  4953.           else
  4954.             printf("String: \\{27}%c\n",xkm);
  4955.       } else if (macrotab[c]) {         /* See if there's a macro */
  4956.           printf("String: ");           /* If so, display its definition */
  4957.           s = macrotab[c];
  4958.           shostrdef(s);
  4959.           printf("\n");
  4960. #ifndef NOKVERBS
  4961.     } else if (km >= 0x100) {           /* This means "undefined" */
  4962.         printf("Undefined\n");
  4963. #endif /* NOKVERBS */
  4964.     } else {                            /* No macro, show single character */
  4965.         printf("Character: ");
  4966.         ch = km;
  4967.         if (ch < 32 || ch == 127
  4968. #ifdef OS2
  4969.             || ch > 255
  4970. #endif /* OS2 */
  4971. #ifndef NEXT
  4972. #ifndef AUX
  4973. #ifndef XENIX
  4974. #ifndef OS2
  4975.             || (ch > 127 && ch < 160)
  4976. #endif /* OS2 */
  4977. #endif /* XENIX */
  4978. #endif /* AUX */
  4979. #endif /* NEXT */
  4980.             )
  4981. /*
  4982.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  4983.   %u is supposed to be totally portable.
  4984. */
  4985.           printf("\\%u",(unsigned int) ch);
  4986.         else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  4987.         if (ch == (KEY) c)
  4988.           printf(" (self, no translation)\n");
  4989.         else
  4990.           printf("\n");
  4991.     }
  4992. #else /* OS2 */
  4993.     if (m < 0) {
  4994.         km = mapkey(c);
  4995.         mstr = "default";
  4996.     } else {
  4997.         km = maptermkey(c,m);
  4998.         for (i = 0; i < nshokeym; i++) {
  4999.             if (m == shokeymtab[i].kwval) {
  5000.                 mstr = shokeymtab[i].kwd;
  5001.                 break;
  5002.             }
  5003.         }
  5004.     }
  5005.     s = keyname(c);
  5006.     debug(F111,"shokeycode mstr",mstr,m);
  5007.     debug(F111,"shokeycode keyname",s,c);
  5008.     printf(" %sKey code \\%d %s (%s) => ",
  5009.             mskkeys ? "mskermit " : "",
  5010.             mskkeys ? cktomsk(c) : c,
  5011.             s == NULL ? "" : s, mstr);
  5012.  
  5013.     switch (km.type) {
  5014. #ifndef NOKVERBS
  5015.       case kverb: {
  5016.           int i, kv;
  5017.           kv = km.kverb.id & ~(F_KVERB);
  5018.           printf("Verb: ");
  5019.           for (i = 0; i < nkverbs; i++) {
  5020.               if (kverbs[i].kwval == kv) {
  5021.                   printf("\\K%s",kverbs[i].kwd);
  5022.                   break;
  5023.               }
  5024.           }
  5025.           printf("\n");
  5026.           break;
  5027.       }
  5028. #endif /* NOKVERBS */
  5029.       case csi: {
  5030.           int xkm = km.csi.key & 0xFF;
  5031.           if (xkm <= 32 || xkm >= 127)
  5032.             printf("String: \\{27}[\\{%d}\n",xkm);
  5033.           else
  5034.             printf("String: \\{27}[%c\n",xkm);
  5035.           break;
  5036.       }
  5037.       case esc: {
  5038.           int xkm = km.esc.key & 0xFF;
  5039.           if (xkm <= 32 || xkm >= 127)
  5040.             printf("String: \\{%d}\\{%d}\n",ISDG200(tt_type)?30:27,xkm);
  5041.           else
  5042.             printf("String: \\{%d}%c\n",ISDG200(tt_type)?30:27,xkm);
  5043.           break;
  5044.       }
  5045.       case macro: {
  5046.           printf("String: ");           /* Macro, display its definition */
  5047.           shostrdef(km.macro.string);
  5048.           printf("\n");
  5049.           break;
  5050.       }
  5051.       case literal: {
  5052.           printf("Literal string: ");   /* Literal, display its definition */
  5053.           shostrdef(km.literal.string);
  5054.           printf("\n");
  5055.           break;
  5056.       }
  5057.       case error: {
  5058.           if (c >= 0x100) {
  5059.               printf("Undefined\n");
  5060.           } else {
  5061.               printf("Character: ");
  5062.               ch = c;
  5063.               if (ch < 32 || ch == 127 || ch > 255
  5064. #ifndef NEXT
  5065. #ifndef AUX
  5066. #ifndef XENIX
  5067. #ifndef OS2
  5068.                    || (ch > 127 && ch < 160)
  5069. #endif /* OS2 */
  5070. #endif /* XENIX */
  5071. #endif /* AUX */
  5072. #endif /* NEXT */
  5073.                    )
  5074. /*
  5075.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  5076.   %u is supposed to be totally portable.
  5077. */
  5078.                   printf("\\%u",(unsigned int) ch);
  5079.               else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  5080.               printf(" (self, no translation)\n");
  5081.           }
  5082.           break;
  5083.       }
  5084.       case key: {
  5085.           printf("Character: ");
  5086.           ch = km.key.scancode;
  5087.           if (ch < 32 || ch == 127 || ch > 255
  5088. #ifndef NEXT
  5089. #ifndef AUX
  5090. #ifndef XENIX
  5091. #ifndef OS2
  5092.               || (ch > 127 && ch < 160)
  5093. #else
  5094.                || (ch > 127)
  5095. #endif /* OS2 */
  5096. #endif /* XENIX */
  5097. #endif /* AUX */
  5098. #endif /* NEXT */
  5099.               )
  5100. /*
  5101.   These used to be %d, but gcc 1.93 & later complain about type mismatches.
  5102.   %u is supposed to be totally portable.
  5103. */
  5104.             printf("\\%u",(unsigned int) ch);
  5105.           else printf("%c \\%u",(CHAR) (ch & 0xff),(unsigned int) ch);
  5106.           if (ch == (KEY) c)
  5107.             printf(" (self, no translation)\n");
  5108.           else
  5109.             printf("\n");
  5110.           break;
  5111.       }
  5112.     }
  5113. #endif /* OS2 */
  5114. }
  5115. #endif /* NOSETKEY */
  5116.  
  5117. VOID
  5118. shostrdef(s) CHAR * s; {
  5119.     CHAR ch;
  5120.     if (!s) s = (CHAR *)"";
  5121.     while ((ch = *s++)) {
  5122.         if (ch < 32 || ch == 127 || ch == 255
  5123. /*
  5124.   Systems whose native character sets have graphic characters in C1...
  5125. */
  5126. #ifndef NEXT                            /* NeXT */
  5127. #ifndef AUX                             /* Macintosh */
  5128. #ifndef XENIX                           /* IBM PC */
  5129. #ifdef OS2
  5130. /*
  5131.   It doesn't matter whether the local host can display 8-bit characters;
  5132.   they are not portable among character-sets and fonts.  Who knows what
  5133.   would be displayed...
  5134. */
  5135.             || (ch > 127)
  5136. #else /* OS2 */
  5137.             || (ch > 127 && ch < 160)
  5138. #endif /* OS2 */
  5139. #endif /* XENIX */
  5140. #endif /* AUX */
  5141. #endif /* NEXT */
  5142.             )
  5143.           printf("\\{%d}",ch);          /* Display control characters */
  5144.         else putchar((char) ch);        /* in backslash notation */
  5145.     }
  5146. }
  5147.  
  5148. #define xxdiff(v,sys) strncmp(v,sys,strlen(sys))
  5149.  
  5150. #ifndef NOSHOW
  5151. VOID
  5152. shover() {
  5153. #ifdef OS2
  5154.     extern char ckxsystem[];
  5155. #endif /* OS2 */
  5156.     extern char *ck_patch, * cklibv;
  5157.     printf("\nVersions:\n %s\n",versio);
  5158.     printf(" Numeric: %ld\n",vernum);
  5159. #ifdef OS2
  5160.     printf(" Operating System: %s\n", ckxsystem);
  5161. #else /* OS2 */
  5162.     printf(" Built for: %s\n", ckxsys);
  5163. #ifdef CK_UTSNAME
  5164.     if (unm_nam[0])
  5165.       printf(" Running on: %s %s %s %s\n", unm_nam,unm_ver,unm_rel,unm_mch);
  5166. #endif /* CK_UTSNAME */
  5167.     printf(" Patches: %s\n", *ck_patch ? ck_patch : "(none)");
  5168. #endif /* OS2 */
  5169.     if (xxdiff(ckxv,ckxsys))
  5170.       printf(" %s for%s\n",ckxv,ckxsys);
  5171.     else
  5172.       printf(" %s\n",ckxv);
  5173.     if (xxdiff(ckzv,ckzsys))
  5174.       printf(" %s for%s\n",ckzv,ckzsys);
  5175.     else
  5176.       printf(" %s\n",ckzv);
  5177.     printf(" %s\n",cklibv);
  5178.     printf(" %s\n",protv);
  5179.     printf(" %s\n",fnsv);
  5180.     printf(" %s\n %s\n",cmdv,userv);
  5181. #ifndef NOCSETS
  5182.     printf(" %s\n",xlav);
  5183. #endif /* NOCSETS */
  5184. #ifndef MAC
  5185. #ifndef NOLOCAL
  5186.     printf(" %s\n",connv);
  5187. #ifdef OS2
  5188.     printf(" %s\n",ckyv);
  5189. #endif /* OS2 */
  5190. #endif /* NOLOCAL */
  5191. #endif /* MAC */
  5192. #ifndef NODIAL
  5193.     printf(" %s\n",dialv);
  5194. #endif /* NODIAL */
  5195. #ifndef NOSCRIPT
  5196.     printf(" %s\n",loginv);
  5197. #endif /* NOSCRIPT */
  5198. #ifdef NETCONN
  5199.     printf(" %s\n",cknetv);
  5200. #ifdef OS2
  5201.     printf(" %s\n",ckonetv);
  5202. #ifdef CK_NETBIOS
  5203.     printf(" %s\n",ckonbiv);
  5204. #endif /* CK_NETBIOS */
  5205. #endif /* OS2 */
  5206. #endif /* NETCONN */
  5207. #ifdef TNCODE
  5208.     printf(" %s\n",cktelv);
  5209. #endif /* TNCODE */
  5210. #ifdef OS2
  5211. #ifdef OS2MOUSE
  5212.     printf(" %s\n",ckomouv);
  5213. #endif /* OS2MOUSE */
  5214. #endif /* OS2 */
  5215. #ifdef NEWFTP
  5216.     printf(" %s\n",ckftpv);
  5217. #endif /* NEWFTP */
  5218. #ifdef CK_AUTHENTICATION
  5219.     printf(" %s\n",ckathv);
  5220. #endif /* CK_AUTHENTICATION */
  5221. #ifdef CK_ENCRYPTION
  5222. #ifdef CRYPT_DLL
  5223.     printf(" %s\n",ck_crypt_dll_version());
  5224. #else /* CRYPT_DLL */
  5225.     printf(" %s\n",ckcrpv);
  5226. #endif /* CRYPT_DLL */
  5227. #endif /* CK_ENCRYPTION */
  5228. #ifdef CK_SSL
  5229.     printf(" %s\n",cksslv);
  5230. #endif /* CK_SSL */
  5231.     printf("\n");
  5232. }
  5233.  
  5234. #ifdef CK_LABELED
  5235. VOID
  5236. sholbl() {
  5237. #ifdef VMS
  5238.     printf("VMS Labeled File Features:\n");
  5239.     printf(" acl %s (ACL info %s)\n",
  5240.            showoff(lf_opts & LBL_ACL),
  5241.            lf_opts & LBL_ACL ? "preserved" : "discarded");
  5242.     printf(" backup-date %s (backup date/time %s)\n",
  5243.            showoff(lf_opts & LBL_BCK),
  5244.            lf_opts & LBL_BCK ? "preserved" : "discarded");
  5245.     printf(" name %s (original filename %s)\n",
  5246.            showoff(lf_opts & LBL_NAM),
  5247.            lf_opts & LBL_NAM ? "preserved" : "discarded");
  5248.     printf(" owner %s (original file owner id %s)\n",
  5249.            showoff(lf_opts & LBL_OWN),
  5250.            lf_opts & LBL_OWN ? "preserved" : "discarded");
  5251.     printf(" path %s (original file's disk:[directory] %s)\n",
  5252.            showoff(lf_opts & LBL_PTH),
  5253.            lf_opts & LBL_PTH ? "preserved" : "discarded");
  5254. #else
  5255. #ifdef OS2
  5256.     printf("OS/2 Labeled File features (attributes):\n");
  5257.     printf(" archive:   %s\n", showoff(lf_opts & LBL_ARC));
  5258.     printf(" extended:  %s\n", showoff(lf_opts & LBL_EXT));
  5259.     printf(" hidden:    %s\n", showoff(lf_opts & LBL_HID));
  5260.     printf(" read-only: %s\n", showoff(lf_opts & LBL_RO ));
  5261.     printf(" system:    %s\n", showoff(lf_opts & LBL_SYS));
  5262. #endif /* OS2 */
  5263. #endif /* VMS */
  5264. }
  5265. #endif /* CK_LABELED */
  5266.  
  5267. VOID
  5268. shotcs(csl,csr) int csl, csr; {         /* Show terminal character set */
  5269. #ifndef NOCSETS
  5270. #ifdef OS2
  5271. #ifndef NOTERM
  5272.     extern struct _vtG G[4], *GL, *GR;
  5273.     extern int decnrcm, sni_chcode;
  5274.     extern int tt_utf8, dec_nrc, dec_kbd, dec_lang;
  5275.     extern prncs;
  5276.  
  5277.     printf(" Terminal character-sets:\n");
  5278.     if (IS97801(tt_type_mode)) {
  5279.         if (cmask == 0377)
  5280.           printf("     Mode: 8-bit Mode\n");
  5281.         else
  5282.           printf("     Mode: 7-bit Mode\n");
  5283.         printf("     CH.CODE is %s\n",sni_chcode?"On":"Off");
  5284.     } else if (ISVT100(tt_type_mode)) {
  5285.         if (decnrcm)
  5286.           printf("     Mode: 7-bit National Mode\n");
  5287.         else
  5288.           printf("     Mode: 8-bit Multinational Mode\n");
  5289.     }
  5290.     if ( isunicode() )
  5291.         printf("    Local: Unicode display / %s input\n",
  5292.                 csl == TX_TRANSP ? "transparent" :
  5293.                 csl == TX_UNDEF ? "undefined" : txrinfo[csl]->keywd);
  5294.     else
  5295.         printf("    Local: %s\n",
  5296.                 csl == TX_TRANSP ? "transparent" :
  5297.                 csl == TX_UNDEF ? "undefined" : txrinfo[csl]->keywd);
  5298.  
  5299.     if ( tt_utf8 ) {
  5300.         printf("   Remote: UTF-8\n");
  5301.     } else {
  5302.         printf("   Remote: %sG0: %s (%s)\n",
  5303.            GL == &G[0] ? "GL->" : GR == &G[0] ? "GR->" : "    ",
  5304.            txrinfo[G[0].designation]->keywd,
  5305.            G[0].designation == TX_TRANSP ? "" :
  5306.            G[0].size == cs94 ? "94 chars" :
  5307.            G[0].size == cs96 ? "96 chars" : "multi-byte");
  5308.         printf("           %sG1: %s (%s)\n",
  5309.            GL == &G[1] ? "GL->" : GR == &G[1] ? "GR->" : "    ",
  5310.            txrinfo[G[1].designation]->keywd,
  5311.            G[1].designation == TX_TRANSP ? "" :
  5312.            G[1].size == cs94 ? "94 chars" :
  5313.            G[1].size == cs96 ? "96 chars" : "multi-byte");
  5314.         printf("           %sG2: %s (%s)\n",
  5315.            GL == &G[2] ? "GL->" : GR == &G[2] ? "GR->" : "    ",
  5316.            txrinfo[G[2].designation]->keywd,
  5317.            G[2].designation == TX_TRANSP ? "" :
  5318.            G[2].size == cs94 ? "94 chars" :
  5319.            G[2].size == cs96 ? "96 chars" : "multi-byte");
  5320.         printf("           %sG3: %s (%s)\n",
  5321.            GL == &G[3] ? "GL->" : GR == &G[3] ? "GR->" : "    ",
  5322.            txrinfo[G[3].designation]->keywd,
  5323.            G[3].designation == TX_TRANSP ? "" :
  5324.            G[3].size == cs94 ? "94 chars" :
  5325.            G[3].size == cs96 ? "96 chars" : "multi-byte");
  5326.     }
  5327.     printf("\n");
  5328.     printf(" Keyboard character-sets:\n");
  5329.     printf("   Multinational: %s\n",txrinfo[dec_kbd]->keywd);
  5330.     printf("        National: %s\n",txrinfo[dec_nrc]->keywd);
  5331.     printf("\n");
  5332.     printf(" Printer character-set: %s\n",txrinfo[prncs]->keywd);
  5333. #endif /* NOTERM */
  5334. #else /* OS2 */
  5335. #ifndef MAC
  5336.     char *s;
  5337.  
  5338.     debug(F101,"TERM LOCAL CSET","",csl);
  5339.     debug(F101,"TERM REMOTE CSET","",csr);
  5340.     printf(" Terminal character-set: ");
  5341.     if (tcs_transp) {                   /* No translation */
  5342.         printf("transparent\n");
  5343.     } else {                            /* Translation */
  5344.         printf("%s (remote) %s (local)\n",
  5345.                fcsinfo[csr].keyword,fcsinfo[csl].keyword);
  5346.         if (csr != csl) {
  5347.             switch(gettcs(csr,csl)) {
  5348.               case TC_USASCII:  s = "ascii";        break;
  5349.               case TC_1LATIN:   s = "latin1-iso";   break;
  5350.               case TC_2LATIN:   s = "latin2-iso";   break;
  5351.               case TC_CYRILL:   s = "cyrillic-iso"; break;
  5352.               case TC_JEUC:     s = "japanese-euc"; break;
  5353.               case TC_HEBREW:   s = "hebrew-iso";   break;
  5354.               case TC_GREEK:    s = "greek-iso";    break;
  5355.               case TC_9LATIN:   s = "latin9-iso";   break;
  5356.               default:          s = "transparent";  break;
  5357.             }
  5358.             if (strcmp(s,fcsinfo[csl].keyword) &&
  5359.                 strcmp(s,fcsinfo[csr].keyword))
  5360.               printf("                         (via %s)\n",s);
  5361.         }
  5362.     }
  5363. #endif /* MAC */
  5364. #endif /* OS2 */
  5365. #endif /* NOCSETS */
  5366. }
  5367.  
  5368. #ifndef NOLOCAL
  5369. #ifdef OS2
  5370. extern char htab[];
  5371. VOID
  5372. shotabs() {
  5373.     int i;
  5374.  
  5375.     printf("Tab Stops:\n\n");
  5376.     for (i = 1; i <= 70; i++)
  5377.       printf("%c",htab[i]=='T'?'T':'-');
  5378.     printf("\n1.......10........20........30........40........50........60\
  5379. ........70\n\n");
  5380.     for (; i <= 140; i++)
  5381.       printf("%c",htab[i]=='T'?'T':'-');
  5382.     printf("\n........80........90.......100.......110.......120.......130\
  5383. .......140\n\n");
  5384.     for (; i <= 210; i++)
  5385.       printf("%c",htab[i]=='T'?'T':'-');
  5386.     printf("\n.......150.......160.......170.......180.......190.......200\
  5387. .......210\n\n");
  5388.     for (; i <= 255; i++)
  5389.       printf("%c",htab[i]=='T'?'T':'-');
  5390.     printf("\n.......220.......230.......240.......250..255\n");
  5391. }
  5392. #endif /* OS2 */
  5393. #endif /* NOLOCAL */
  5394.  
  5395. #ifdef OS2MOUSE
  5396. VOID
  5397. shomou() {
  5398.     int button, event, id, i;
  5399.     char * name = "";
  5400.  
  5401.     printf("Mouse settings:\n");
  5402.     printf("   Button Count:   %d\n",mousebuttoncount());
  5403.     printf("   Active:         %s\n\n",showoff(tt_mouse));
  5404.  
  5405.     for (button = 0; button < MMBUTTONMAX; button++)
  5406.       for (event = 0; event < MMEVENTSIZE; event++)
  5407.         if (mousemap[button][event].type != error)
  5408.           switch (mousemap[button][event].type) {
  5409.             case key:
  5410.               printf("   %s = Character: %c \\%d\n",
  5411.                      mousename(button,event),
  5412.                      mousemap[button][event].key.scancode,
  5413.                      mousemap[button][event].key.scancode );
  5414.               break;
  5415.             case kverb:
  5416.               id = mousemap[button][event].kverb.id & ~(F_KVERB);
  5417.               if (id != K_IGNORE) {
  5418.                   for (i = 0; i< nkverbs; i++)
  5419.                     if (id == kverbs[i].kwval) {
  5420.                         name = kverbs[i].kwd;
  5421.                         break;
  5422.                     }
  5423.                   printf("   %s = Kverb: \\K%s\n",
  5424.                          mousename(button,event),
  5425.                          name
  5426.                          );
  5427.               }
  5428.               break;
  5429.             case macro:
  5430.               printf("   %s = Macro: ",
  5431.                      mousename(button,event) );
  5432.               shostrdef(mousemap[button][event].macro.string);
  5433.               printf("\n");
  5434.               break;
  5435.           }
  5436. }
  5437. #endif /* OS2MOUSE */
  5438.  
  5439. #ifndef NOLOCAL
  5440. VOID
  5441. shotrm() {
  5442.     char *s;
  5443.     extern char * getiact();
  5444.     extern int tt_print, adl_err;
  5445. #ifndef NOTRIGGER
  5446.     extern char * tt_trigger[];
  5447. #endif /* NOTRIGGER */
  5448. #ifdef CKTIDLE
  5449.     extern char * tt_idlesnd_str;
  5450.     extern int tt_idlesnd_tmo;
  5451.     extern int tt_idlelimit, tt_idleact;
  5452. #endif /* CKTIDLE */
  5453. #ifdef OS2
  5454.     extern int wy_autopage, autoscroll, sgrcolors, colorreset, user_erasemode,
  5455.       decscnm, decscnm_usr, tt_diff_upd, tt_senddata,
  5456.       wy_blockend, marginbell, marginbellcol, tt_modechg, dgunix;
  5457.     int lines = 0;
  5458.  
  5459. #ifdef PCFONTS
  5460.     int i;
  5461.     char *font;
  5462.  
  5463.     if (IsOS2FullScreen()) {            /* Determine the font name */
  5464.         if (!os2LoadPCFonts()) {
  5465.             for (i = 0; i < ntermfont; i++) {
  5466.                 if (tt_font == term_font[i].kwval) {
  5467.                     font = term_font[i].kwd;
  5468.                     break;
  5469.                 }
  5470.             }
  5471.         } else {
  5472.             font = "(DLL not available)";
  5473.         }
  5474.     } else {
  5475.         font =     "(full screen only)";
  5476.     }
  5477. #endif /* PCFONTS */
  5478. #ifdef KUI
  5479.     char font[64] = "(unknown)";
  5480.     if ( ntermfont > 0 ) {
  5481.         int i;
  5482.         for (i = 0; i < ntermfont; i++) {
  5483.             if (tt_font == term_font[i].kwval) {
  5484.                 ckstrncpy(font,term_font[i].kwd,59);
  5485.                 ckstrncat(font," ",64);
  5486.                 ckstrncat(font,ckitoa(tt_font_size/2),64);
  5487.                 if ( tt_font_size % 2 )
  5488.                     ckstrncat(font,".5",64);
  5489.                 break;
  5490.             }
  5491.         }
  5492.     }
  5493. #endif /* KUI */
  5494.  
  5495.     printf("Terminal parameters:\n");
  5496.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5497.     printf(" %19s: %1d%-12s  %13s: %1d%-14s\n",
  5498.            "Bytesize: Command",
  5499.            (cmdmsk == 0377) ? 8 : 7,
  5500.            " bits","Terminal",
  5501.            (cmask == 0377) ? 8 : 7," bits");
  5502.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5503.     printf(" %19s: %-13s","Type",
  5504.            (tt_type >= 0 && tt_type <= max_tt) ?
  5505.            tt_info[tt_type].x_name :
  5506.            "unknown" );
  5507.     if (tt_type >= 0 && tt_type <= max_tt)
  5508.       if (strlen(tt_info[tt_type].x_id))
  5509.         printf("  %13s: <ESC>%s","ID",tt_info[tt_type].x_id);
  5510.     printf("\n");
  5511.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5512.     printf(" %19s: %-13s  %13s: %-15s\n","Echo",
  5513.            duplex ? "local" : "remote","Locking-shift",showoff(sosi));
  5514.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5515.     printf(" %19s: %-13s  %13s: %-15s\n","Newline-mode",
  5516.            showoff(tnlm),"Cr-display",tt_crd ? "crlf" : "normal");
  5517.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5518.     printf(" %19s: %-13s  %13s: %-15s\n","Cursor",
  5519.            (tt_cursor == 2) ? "full" :
  5520.            (tt_cursor == 1) ? "half" : "underline",
  5521. #ifdef CK_AUTODL
  5522.            "autodownload",autodl ?
  5523.            (adl_err ? "on, error stop" : "on, error continue") : "off"
  5524. #else /* CK_AUTODL */
  5525.            "", ""
  5526. #endif /* CK_AUTODL */
  5527.            );
  5528.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5529.     printf(" %19s: %-13s  %13s: %-15s\n","Arrow-keys",
  5530.            tt_arrow ? "application" : "cursor",
  5531.            "Keypad-mode", tt_keypad ? "application" : "numeric"
  5532.            );
  5533.  
  5534.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5535.  
  5536.     /* Just to make sure we are using current info */
  5537.     updanswerbk();
  5538.  
  5539.     /*
  5540.        This line doesn't end with '\n' because the answerback string
  5541.        is terminated with a newline
  5542.     */
  5543.     printf(" %19s: %-13s  %13s: %-15s","Answerback",
  5544.            showoff(tt_answer),"response",answerback);
  5545.     switch (tt_bell) {
  5546.       case XYB_NONE:
  5547.         s = "none";
  5548.         break;
  5549.       case XYB_VIS:
  5550.         s= "visible";
  5551.         break;
  5552.       case XYB_AUD | XYB_BEEP:
  5553.         s="beep";
  5554.         break;
  5555.       case XYB_AUD | XYB_SYS:
  5556.         s="system sounds";
  5557.         break;
  5558.       default:
  5559.         s="(unknown)";
  5560.     }
  5561.     printf(" %19s: %-13s  %13s: %-15s\n","Bell",s,
  5562.            "Wrap",showoff(tt_wrap));
  5563.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5564.     printf(" %19s: %-13s  %13s: %-15s\n","Autopage",showoff(wy_autopage),
  5565.            "Autoscroll",showoff(autoscroll));
  5566.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5567.     printf(" %19s: %-13s  %13s: %-15s\n","SGR Colors",showoff(sgrcolors),
  5568.            "ESC[0m color",colorreset?"default-color":"current-color");
  5569.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5570.     printf(" %19s: %-13s  %13s: %-15s\n",
  5571.             "Erase color",user_erasemode?"default-color":"current-color",
  5572.            "Screen mode",decscnm?"reverse":"normal");
  5573.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5574.  
  5575.     printf(" %19s: %-13d  %13s: %-15d\n","Transmit-timeout",tt_ctstmo,
  5576.            "Output-pacing",tt_pacing);
  5577.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5578.  
  5579.     printf(" %19s: %-13d  %13s: %s\n","Idle-timeout",tt_idlelimit,
  5580.            "Idle-action", getiact());
  5581.  
  5582.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5583.     printf(" %19s: %-13s  %13s: %-15s\n","Send data",
  5584.           showoff(tt_senddata),"End of Block", wy_blockend?"crlf/etx":"us/cr");
  5585.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5586. #ifndef NOTRIGGER
  5587.     printf(" %19s: %-13s  %13s: %d seconds\n","Auto-exit trigger",
  5588.            tt_trigger[0],"Output pacing",tt_pacing );
  5589.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5590. #endif /* NOTRIGGER */
  5591.     printf(" %19s: %-13s  %13s: %-15d\n","Margin bell",
  5592.            showoff(marginbell),"at column", marginbellcol);
  5593.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5594.     switch (tt_modechg) {
  5595.       case TVC_DIS: s = "disabled"; break;
  5596.       case TVC_ENA: s = "enabled";  break;
  5597.       case TVC_W95: s = "win95-restricted"; break;
  5598.       default: s = "(unknown)";
  5599.     }
  5600.     printf(" %19s: %-13s  %13s: %-15s\n","DG Unix mode",
  5601.            showoff(dgunix),"Video change", s);
  5602.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5603.  
  5604. #ifdef CK_APC
  5605.     if (apcstatus == APC_ON) s = "on";
  5606.     else if (apcstatus == APC_OFF) s = "off";
  5607.     else if (apcstatus == APC_ON|APC_UNCH) s = "unchecked";
  5608.     else if (apcstatus == APC_ON|APC_NOINP) s = "no-input";
  5609.     else if (apcstatus == APC_ON|APC_UNCH|APC_NOINP) s = "unchecked-no-input";
  5610.     printf(" %19s: %-13s  %13s: %-15s\n",
  5611.            "APC", s,
  5612. #ifdef PCFONTS
  5613.            "Font (VGA)",font
  5614. #else /* PCFONTS */
  5615. #ifdef KUI
  5616.            "Font",font
  5617. #else
  5618.            "Font","(not supported)"
  5619. #endif /* KUI */
  5620. #endif /* PCFONTS */
  5621.  
  5622.            );
  5623. #endif /* CK_APC */
  5624.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5625.  
  5626. #ifdef CK_TTGWSIZ                       /* Console terminal screen size */
  5627.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  5628.       ttgwsiz();                        /* Try to get latest size */
  5629. #endif /* CK_TTGWSIZ */
  5630.     printf(" %19s: %-13d  %13s: %-15d\n","Height",tt_rows[VTERM],
  5631.            "Width",tt_cols[VTERM]);
  5632.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5633.     printf(" %19s: %-13s  %13s: %d lines\n","Roll-mode",
  5634.           tt_roll[VTERM]?"insert":"overwrite","Scrollback", tt_scrsize[VTERM]);
  5635.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5636.  
  5637.     if (updmode == tt_updmode)
  5638.       if (updmode == TTU_FAST)
  5639.         s = "fast (fast)";
  5640.       else
  5641.         s = "smooth (smooth)";
  5642.     else
  5643.       if (updmode == TTU_FAST)
  5644.         s = "fast (smooth)";
  5645.       else
  5646.         s = "smooth (fast)";
  5647.  
  5648.     printf(" %19s: %-13s  %13s: %d ms\n","Screen-update: mode",s,
  5649.            "interval",tt_update);
  5650.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5651.     printf(" %19s: %-13s  %13s: %-15s\n",
  5652.            "Screen-optimization",showoff(tt_diff_upd),
  5653.            "Status line",showoff(tt_status[VTERM]));
  5654.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5655.     printf(" %19s: %-13s  %13s: %-15s\n","Debug",
  5656.            showoff(debses),"Session log", seslog? sesfil : "(none)" );
  5657.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5658.  
  5659.     /* Display colors (should become SHOW COLORS) */
  5660.     {
  5661.         USHORT row, col;
  5662.         char * colors[16] = {
  5663.             "black","blue","green","cyan","red","magenta","brown","lgray",
  5664.             "dgray","lblue","lgreen","lcyan","lred","lmagent","yellow","white"
  5665.         };
  5666.         printf("\n");
  5667.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5668.  
  5669.         printf(" Color:");
  5670. #ifndef ONETERMUPD
  5671.         GetCurPos(&row, &col);
  5672.         WrtCharStrAtt("border",    6, row, 9, &colorborder );
  5673.         WrtCharStrAtt("debug",     5, row, 17, &colordebug );
  5674.         WrtCharStrAtt("helptext",  8, row, 25, &colorhelp );
  5675.         WrtCharStrAtt("reverse",   7, row, 34, &colorreverse );
  5676.         WrtCharStrAtt("select",    6, row, 42, &colorselect );
  5677.         WrtCharStrAtt("status",    6, row, 50, &colorstatus );
  5678.         WrtCharStrAtt("terminal",  8, row, 58, &colornormal );
  5679.         WrtCharStrAtt("underline", 9, row, 67, &colorunderline );
  5680. #endif /* ONETERMUPD */
  5681.         row = VscrnGetCurPos(VCMD)->y+1;
  5682.         VscrnWrtCharStrAtt(VCMD, "border",    6, row, 9, &colorborder );
  5683.         VscrnWrtCharStrAtt(VCMD, "debug",     5, row, 17, &colordebug );
  5684.         VscrnWrtCharStrAtt(VCMD, "helptext",  8, row, 25, &colorhelp );
  5685.         VscrnWrtCharStrAtt(VCMD, "reverse",   7, row, 34, &colorreverse );
  5686.         VscrnWrtCharStrAtt(VCMD, "select",    6, row, 42, &colorselect );
  5687.         VscrnWrtCharStrAtt(VCMD, "status",    6, row, 50, &colorstatus );
  5688.         VscrnWrtCharStrAtt(VCMD, "terminal",  8, row, 58, &colornormal );
  5689.         VscrnWrtCharStrAtt(VCMD, "underline",  9, row, 67, &colorunderline );
  5690.         printf("\n");
  5691.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5692.  
  5693.         /* Foreground color names */
  5694.         printf("%6s: %-8s%-8s%-9s%-8s%-8s%-8s%-9s%-9s\n","fore",
  5695.                 "",
  5696.                 colors[colordebug&0x0F],
  5697.                 colors[colorhelp&0x0F],
  5698.                 colors[colorreverse&0x0F],
  5699.                 colors[colorselect&0x0F],
  5700.                 colors[colorstatus&0x0F],
  5701.                 colors[colornormal&0x0F],
  5702.                 colors[colorunderline&0x0F]);
  5703.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5704.  
  5705.         /* Background color names */
  5706.         printf("%6s: %-8s%-8s%-9s%-8s%-8s%-8s%-9s%-9s\n","back",
  5707.                 colors[colorborder],
  5708.                 colors[colordebug>>4],
  5709.                 colors[colorhelp>>4],
  5710.                 colors[colorreverse>>4],
  5711.                 colors[colorselect>>4],
  5712.                 colors[colorstatus>>4],
  5713.                 colors[colornormal>>4],
  5714.                 colors[colorunderline>>4] );
  5715.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5716.         printf("\n");
  5717.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5718.         printf(" Color:");
  5719. #ifndef ONETERMUPD
  5720.         GetCurPos(&row, &col);
  5721.         WrtCharStrAtt("graphic",   7, row, 9, &colorgraphic );
  5722.         WrtCharStrAtt("command",   7, row, 17, &colorcmd );
  5723.         WrtCharStrAtt("italic",    6, row, 26, &coloritalic );
  5724. #endif /* ONETERMUPD */
  5725.         row = VscrnGetCurPos(VCMD)->y+1;
  5726.         VscrnWrtCharStrAtt(VCMD, "graphic",   7, row, 9,  &colorgraphic );
  5727.         VscrnWrtCharStrAtt(VCMD, "command",   7, row, 17, &colorcmd );
  5728.         VscrnWrtCharStrAtt(VCMD, "italic",    6, row, 26, &coloritalic );
  5729.         printf("\n");
  5730.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5731.  
  5732.         /* Foreground color names */
  5733.         printf("%6s: %-8s%-8s%-8s\n","fore",
  5734.                 colors[colorgraphic&0x0F],
  5735.                 colors[colorcmd&0x0F],
  5736.                 colors[coloritalic&0x0F]);
  5737.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5738.  
  5739.         /* Background color names */
  5740.         printf("%6s: %-8s%-8s%-8s\n","back",
  5741.                 colors[colorgraphic>>4],
  5742.                 colors[colorcmd>>4],
  5743.                 colors[coloritalic>>4]);
  5744.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5745.     }
  5746.     printf("\n");
  5747.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5748.     {
  5749.         extern int trueblink, truereverse, trueunderline, trueitalic;
  5750.         printf(
  5751.     " Attribute:  blink: %-3s  reverse: %-3s  underline: %-3s italic: %-3s\n",
  5752.                 trueblink?"on":"off", truereverse?"on":"off",
  5753.                 trueunderline?"on":"off", trueitalic?"on":"off");
  5754.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5755.     }
  5756.     {
  5757.         extern vtattrib WPattrib;
  5758.         printf(" ASCII Protected chars: %s%s%s%s%s%s%s\n",
  5759.                 WPattrib.blinking?"blink ":"",
  5760.                 WPattrib.italic?"italic ":"",
  5761.                 WPattrib.reversed?"reverse ":"",
  5762.                 WPattrib.underlined?"underline ":"",
  5763.                 WPattrib.bold?"bold ":"",
  5764.                 WPattrib.dim?"dim ":"",
  5765.                 WPattrib.invisible?"invisible ":"");
  5766.         if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5767.     }
  5768.  
  5769.     printf("\n");
  5770.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5771.     (VOID) shoesc(escape);
  5772.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5773.     printf(" See SHOW CHARACTER-SETS for character-set info\n");
  5774.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  5775.  
  5776. #else /* OS2 */   /* Beginning of new non-OS2 version */
  5777.  
  5778.     printf("\n");
  5779.     printf("Terminal parameters:\n");
  5780.     printf(" %19s: %1d%-12s  %13s: %1d%-14s\n",
  5781.            "Bytesize: Command",
  5782.            (cmdmsk == 0377) ? 8 : 7,
  5783.            " bits","Terminal",
  5784.            (cmask == 0377) ? 8 : 7," bits");
  5785.     s = getenv("TERM");
  5786. #ifdef XPRINT
  5787.     printf(" %19s: %-13s  %13s: %-15s\n",
  5788.            "Type",
  5789.            s ? s : "(unknown)",
  5790.            "Print",
  5791.            showoff(tt_print)
  5792.            );
  5793. #else
  5794.     printf(" %19s: %-13s\n","Type", s ? s : "(unknown)");
  5795. #endif /* XPRINT */
  5796.     printf(" %19s: %-13s  %13s: %-15s\n","Echo",
  5797.            duplex ? "local" : "remote","Locking-shift",showoff(sosi));
  5798.     printf(" %19s: %-13s  %13s: %-15s\n","Newline-mode",
  5799.            showoff(tnlm),"Cr-display",tt_crd ? "crlf" : "normal");
  5800.  
  5801. #ifdef CK_APC
  5802.     if (apcstatus == APC_ON) s = "on";
  5803.     else if (apcstatus == APC_OFF) s = "off";
  5804.     else if (apcstatus == APC_ON|APC_UNCH) s = "unchecked";
  5805.     else if (apcstatus == APC_ON|APC_NOINP) s = "no-input";
  5806.     else if (apcstatus == APC_ON|APC_UNCH|APC_NOINP) s = "unchecked-no-input";
  5807.     printf(" %19s: %-13s  %13s: %-15s\n",
  5808.            "APC", s,
  5809. #ifdef CK_AUTODL
  5810.            "Autodownload", autodl ?
  5811.            (adl_err ? "on, error stop" : "on, error continue") : "off"
  5812. #else
  5813.            "",""
  5814. #endif /* CK_AUTODL */
  5815.            );
  5816. #endif /* CK_APC */
  5817.  
  5818. #ifdef CK_TTGWSIZ                       /* Console terminal screen size */
  5819.     ttgwsiz();                          /* Try to get latest size */
  5820.     printf(" %19s: %-13d  %13s: %-15d\n","Height",tt_rows, "Width", tt_cols);
  5821. #endif /* CK_TTGWSIZ */
  5822.  
  5823.     printf(" %19s: %-13s  %13s: %-15s\n","Debug",
  5824.            showoff(debses),"Session log", seslog? sesfil : "(none)" );
  5825.  
  5826. #ifdef CKTIDLE
  5827.     printf(" %19s: %-13d  %13s: %s\n","Idle-timeout",tt_idlelimit,
  5828.            "Idle-action", getiact());
  5829. #endif /* CKTIDLE */
  5830.  
  5831. #ifndef NOTRIGGER
  5832.     printf(" %19s: %-13s\n","Trigger",
  5833.            tt_trigger[0] ? tt_trigger[0] : "(none)");
  5834. #endif /* NOTRIGGER */
  5835. #ifdef UNIX
  5836. #ifndef NOJC
  5837.     printf(" %19s: %-13s\n\n","Suspend", showoff(suspend));
  5838. #endif /* NOJC */
  5839. #endif /* UNIX */
  5840.  
  5841.     printf("\n");
  5842.     (VOID) shoesc(escape);
  5843. #ifndef NOCSETS
  5844.     shotcs(tcsl,tcsr);          /* Show terminal character sets */
  5845. #endif /* NOCSETS */
  5846.  
  5847. #endif /* OS2 */
  5848. }
  5849.  
  5850. VOID
  5851. shmdmlin() {                            /* Briefly show modem & line */
  5852. #ifndef NODIAL
  5853. #ifndef MINIDIAL
  5854. #ifdef OLDTBCODE
  5855.     extern int tbmodel;
  5856.     _PROTOTYP( char * gtbmodel, (void) );
  5857. #endif /* OLDTBCODE */
  5858. #endif /* MINIDIAL */
  5859. #endif /* NODIAL */
  5860.     if (local)
  5861. #ifdef OS2
  5862.       printf(" Port: %s, Modem type: ",ttname);
  5863. #else
  5864.       printf(" Line: %s, Modem type: ",ttname);
  5865. #endif /* OS2 */
  5866.     else
  5867.       printf(
  5868. #ifdef OS2
  5869. " Communication device not yet selected with SET PORT\n Modem type: "
  5870. #else
  5871. " Communication device not yet selected with SET LINE\n Modem type: "
  5872. #endif /* OS2 */
  5873.              );
  5874. #ifndef NODIAL
  5875.     printf("%s",gmdmtyp());
  5876. #ifndef MINIDIAL
  5877. #ifdef OLDTBCODE
  5878.     if (tbmodel) printf(" (%s)",gtbmodel()); /* Telebit model info */
  5879. #endif /* OLDTBCODE */
  5880. #endif /* MINIDIAL */
  5881. #else
  5882.     printf("(disabled)");
  5883. #endif /* NODIAL */
  5884. }
  5885.  
  5886. #ifdef CK_TAPI
  5887. void
  5888. shotapi(int option) {
  5889.     int rc=0,k ;
  5890.     char *s=NULL;
  5891.     LPDEVCFG        lpDevCfg = NULL;
  5892.     LPCOMMCONFIG    lpCommConfig = NULL;
  5893.     LPMODEMSETTINGS lpModemSettings = NULL;
  5894.     DCB *           lpDCB = NULL;
  5895.     extern struct keytab * tapiloctab;  /* Microsoft TAPI Locations */
  5896.     extern int ntapiloc;
  5897.     extern struct keytab * tapilinetab; /* Microsoft TAPI Line Devices */
  5898.     extern int ntapiline;
  5899.     extern int tttapi;                  /* TAPI in use */
  5900.     extern int tapipass;                /* TAPI Passthrough mode */
  5901.     extern int tapiconv;                /* TAPI Conversion mode */
  5902.     extern int tapilights;
  5903.     extern int tapipreterm;
  5904.     extern int tapipostterm;
  5905.     extern int tapimanual;
  5906.     extern int tapiinactivity;
  5907.     extern int tapibong;
  5908.     extern int tapiusecfg;
  5909.     extern char tapiloc[];
  5910.     extern int tapilocid;
  5911.     extern int TAPIAvail;
  5912.  
  5913.     if (!TAPIAvail) {
  5914.         printf("TAPI Support not enabled\r\n");
  5915.         return;
  5916.     }
  5917.     switch (option) {
  5918.       case 0:
  5919.         printf("TAPI Settings:\n");
  5920.         printf("  Line:                      %s\n",
  5921.                tttapi ? ttname : "(none in use)");
  5922.  
  5923.         cktapiBuildLocationTable(&tapiloctab, &ntapiloc);
  5924.         if (tapilocid == -1)
  5925.           tapilocid = cktapiGetCurrentLocationID();
  5926.  
  5927.         /* Find the current tapiloc entry */
  5928.         /* and use it as the default. */
  5929.         for (k = 0; k < ntapiloc; k++) {
  5930.             if (tapiloctab[k].kwval == tapilocid)
  5931.               break;
  5932.         }
  5933.         if (k >= 0 && k < ntapiloc)
  5934.           s = tapiloctab[k].kwd;
  5935.         else
  5936.           s = "(unknown)";
  5937.         printf("  Location:                  %s\n",s);
  5938.         printf("  Modem-dialing:             %s\n",tapipass?"off":"on");
  5939.         printf("  Phone-number-conversions:  %s\n",
  5940.                 tapiconv==CK_ON?"on":tapiconv==CK_AUTO?"auto":"off");
  5941.         printf("  Modem-lights:              %s %s\n",tapilights?"on ":"off",
  5942.                 tapipass?"(n/a)":"");
  5943.         printf("  Predial-terminal:          %s %s\n",tapipreterm?"on ":"off",
  5944.                 tapipass?"(n/a)":"");
  5945.         printf("  Postdial-terminal:         %s %s\n",tapipostterm?"on ":"off",
  5946.                 tapipass?"(n/a)":"");
  5947.         printf("  Manual-dial:               %s %s\n",tapimanual?"on ":"off",
  5948.                 tapipass?"(n/a)":"");
  5949.         printf("  Inactivity-timeout:        %d seconds %s\n",tapiinactivity,
  5950.                 tapipass?"(n/a)":"");
  5951.         printf("  Wait-for-bong:             %d seconds %s\n",tapibong,
  5952.                 tapipass?"(n/a)":"");
  5953.         printf("  Use-windows-configuration: %s %s\n",
  5954.                 tapiusecfg?"on ":"off", tapipass?"(n/a)":"");
  5955.         printf("\n");
  5956.  
  5957. #ifdef BETATEST
  5958.         if (tapipass) {
  5959. printf("K-95 uses the TAPI Line in an exclusive mode.  Other applications\n");
  5960. printf("may open the device but may not place calls nor answer calls.\n");
  5961. printf("Dialing is performed using the K-95 dialing procedures.  SET MODEM\n");
  5962. printf("TYPE TAPI after the SET TAPI LINE command to activate the modem\n");
  5963. printf("definition associated with the active TAPI LINE device.\n\n");
  5964.  
  5965.         } else {
  5966.  
  5967. printf("K-95 uses the TAPI Line in a cooperative mode.  Other applications\n");
  5968. printf("may open the device, place and answer calls.  Dialing is performed\n");
  5969. printf("by TAPI.  K-95 SET MODEM commands are not used.\n\n");
  5970.         }
  5971.  
  5972.         if (tapiconv == CK_ON ||
  5973.             tapiconv == CK_AUTO && !tapipass) {
  5974. printf(
  5975. "Phone numbers are converted from canonical to dialable form by TAPI\n");
  5976. printf("using the dialing rules specified in the TAPI Dialing Properties\n");
  5977. printf("dialog.\n\n");
  5978.  
  5979.         } else {
  5980.  
  5981. printf(
  5982. "Phone numbers are converted from canonical to dialable form by K-95\n");
  5983. printf(
  5984. "using the dialing rules specified with the SET DIAL commands.  TAPI\n");
  5985. printf(
  5986. "Dialing Properties are imported automaticly upon startup and whenever\n");
  5987. printf("the TAPI Dialing Properties are altered or when the TAPI Location\n");
  5988. printf("is changed.\n\n");
  5989.         }
  5990. #endif /* BETATEST */
  5991.  
  5992.         if (tapipass) {
  5993.             printf("Type SHOW MODEM to see MODEM configuration.\n");
  5994.             if (tapiconv == CK_ON)
  5995.               printf("Type SHOW DIAL to see DIAL-related items.\n");
  5996.         } else {
  5997.             if (tapiconv == CK_ON || tapiconv == CK_AUTO)
  5998.               printf("Type SHOW DIAL to see DIAL-related items.\n");
  5999.         }
  6000.         break;
  6001.       case 1:
  6002.         cktapiDisplayTapiLocationInfo();
  6003.         break;
  6004.       case 2:
  6005.         rc = cktapiGetModemSettings(&lpDevCfg,&lpModemSettings,
  6006.                                      &lpCommConfig,&lpDCB);
  6007.         if (rc) {
  6008.             cktapiDisplayModemSettings(lpDevCfg,lpModemSettings,
  6009.                                          lpCommConfig,lpDCB);
  6010.         } else {
  6011.             printf("?Unable to retrieve Modem Settings\n");
  6012.         }
  6013.         break;
  6014.       case 3: {
  6015.           HANDLE hModem = GetModemHandleFromLine((HLINE)0);
  6016.           if (hModem)
  6017.             DisplayCommProperties(hModem);
  6018.           else
  6019.             printf("?Unable to retrieve a valid Modem Handle\n");
  6020.           CloseHandle(hModem);
  6021.           break;
  6022.       }
  6023.     }
  6024.     printf("\n");
  6025. }
  6026. #endif /* CK_TAPI */
  6027. #endif /* NOLOCAL */
  6028.  
  6029. #ifdef PATTERNS
  6030. static VOID
  6031. shopat() {
  6032.     extern char * binpatterns[], * txtpatterns[];
  6033.     extern int patterns, filepeek;
  6034.     char **p, *s;
  6035.     int i, j, k, n, flag, width;
  6036. #ifdef CK_TTGWSIZ
  6037.     ttgwsiz();                          /* Try to get latest size */
  6038. #ifdef OS2
  6039.     width = tt_cols[VCMD];
  6040. #else /* OS2 */
  6041.     width = tt_cols;
  6042. #endif /* OS2 */
  6043.     if (width < 1)
  6044. #endif /* CK_TTGWSIZ */
  6045.       width = 80;
  6046.     printf("\n");
  6047.     printf(" Set file type:            %s\n",gfmode(binary,1));
  6048.     printf(" Set file patterns:        %s", showooa(patterns));
  6049. #ifdef CK_LABELED
  6050.     if (binary == XYFT_L)
  6051.       printf(" (but SET FILE TYPE LABELED overrides)\n");
  6052.     else
  6053. #endif /* CK_LABELED */
  6054. #ifdef VMS
  6055.     if (binary == XYFT_I)
  6056.       printf(" (but SET FILE TYPE IMAGE overrides)\n");
  6057.     else
  6058. #endif /* VMS */
  6059.     if (filepeek)
  6060.       printf(" (but SET FILE SCAN ON overrides)\n");
  6061.     else
  6062.       printf("\n");
  6063.     printf(" Maximum patterns allowed: %d\n", FTPATTERNS);
  6064.     for (k = 0; k < 2; k++) {           /* For each kind of patter */
  6065.         printf("\n");
  6066.         if (k == 0) {                   /* binary... */
  6067.             printf(" File binary-patterns: ");
  6068.             p = binpatterns;
  6069.         } else {                        /* text... */
  6070.             printf(" File text-patterns:   ");
  6071.             p = txtpatterns;
  6072.         }
  6073.         if (!p[0]) {
  6074.             printf("(none)\n");
  6075.         } else {
  6076.             printf("\n ");
  6077.             n = 2;
  6078.             for (i = 0; i < FTPATTERNS; i++) { /* For each pattern */
  6079.                 if (!p[i])              /* Done */
  6080.                   break;
  6081.                 s = p[i];               /* Look for embedded space */
  6082.                 for (j = 0, flag = 1; *s; s++, j++) /* and also get length */
  6083.                   if (*s == SP)
  6084.                     flag = 3;
  6085.                 n += j + flag;          /* Length of this line */
  6086.                 if (n >= width - 1) {
  6087.                     printf("\n ");
  6088.                     n = j+2;
  6089.                 }
  6090.                 printf(flag == 3 ? " {%s}" : " %s", p[i]);
  6091.             }
  6092.             if (n > 2)
  6093.               printf("\n");
  6094.         }
  6095.     }
  6096.     printf("\n");
  6097. }
  6098. #endif /* PATTERNS */
  6099.  
  6100. #ifndef NOSPL
  6101. static VOID
  6102. shooutput() {
  6103.     printf(" Output pacing:          %d (milliseconds)\n",pacing);
  6104.     printf(" Output special-escapes: %s\n", showoff(outesc));
  6105. }
  6106.  
  6107. static VOID
  6108. shoinput() {
  6109. #ifdef CK_AUTODL
  6110.     printf(" Input autodownload:     %s\n", showoff(inautodl));
  6111. #endif /* CK_AUTODL */
  6112.     printf(" Input cancellation:     %s\n", showoff(inintr));
  6113.     printf(" Input case:             %s\n", inpcas[cmdlvl] ?
  6114.            "observe" : "ignore");
  6115.     printf(" Input buffer-length:    %d\n", inbufsize);
  6116.     printf(" Input echo:             %s\n", showoff(inecho));
  6117.     printf(" Input silence:          %d (seconds)\n", insilence);
  6118. #ifdef OS2
  6119.     printf(" Input terminal:         %s\n", showoff(interm));
  6120. #endif /* OS2 */
  6121.     printf(" Input timeout:          %s\n", intime[cmdlvl] ?
  6122.            "quit" : "proceed");
  6123.     if (instatus < 0)
  6124.       printf(" Last INPUT:             -1 (INPUT command not yet given)\n");
  6125.     else
  6126.       printf(" Last INPUT:             %d (%s)\n", instatus,i_text[instatus]);
  6127. }
  6128. #endif /* NOSPL */
  6129.  
  6130. #ifndef NOSPL
  6131. int
  6132. showarray() {
  6133. #ifdef COMMENT
  6134.     char * p, * q, ** ap;
  6135.     int i;
  6136. #endif /* COMMENT */
  6137.     char *s; int x = 0, y;
  6138.     int range[2];
  6139.  
  6140.     if ((y = cmfld("Array name","",&s,NULL)) < 0)
  6141.       if (y != -3)
  6142.         return(y);
  6143.     ckstrncpy(line,s,LINBUFSIZ);
  6144.     s = line;
  6145.     if ((y = cmcfm()) < 0)
  6146.       return(y);
  6147.     if (*s) {
  6148.         char ** ap;
  6149.         if ((x = arraybounds(s,&(range[0]),&(range[1]))) < 0) {
  6150.             printf("?Bad array: %s\n",s);
  6151.             return(-9);
  6152.         }
  6153.         ap = a_ptr[x];
  6154.         if (!ap) {
  6155.             printf("Array not declared: %s\n", s);
  6156.             return(success = 1);
  6157.         } else {
  6158.             int i, n, max;
  6159.             max = (range[1] > 0) ?
  6160.               range[1] :
  6161.                 ((range[0] > 0) ? range[0] : a_dim[x]);
  6162.             if (range[0] < 0)
  6163.               range[0] = 0;
  6164.             if (max > a_dim[x])
  6165.               max = a_dim[x];
  6166.             n = 1;
  6167.             printf("\\&%c[]: Dimension = %d",arrayitoa(x),a_dim[x]);
  6168.             if (a_link[x] > -1)
  6169.               printf(" (Link to \\&%c[])",arrayitoa(a_link[x]));
  6170.             printf("\n");
  6171.             for (i = range[0]; i <= max; i++) {
  6172.                 if (ap[i]) {
  6173.                     printf("%3d. %s\n",i,ap[i]);
  6174.                     if (xaskmore) {
  6175.                         if (cmd_cols > 0) {
  6176.                             x = strlen(ap[i]) + 5;
  6177.                             y = (x % cmd_cols) ? 1 : 0;
  6178.                             n += (x / cmd_cols) + y;
  6179.                         } else {
  6180.                             n++;
  6181.                         }
  6182.                         if (n > (cmd_rows - 3)) {
  6183.                             if (!askmore())
  6184.                               break;
  6185.                             else
  6186.                               n = 0;
  6187.                         }
  6188.                     }
  6189.                 }
  6190.             }
  6191.         }
  6192.         return(1);
  6193.     }
  6194.  
  6195.     /* All arrays - just show name and dimension */
  6196.  
  6197.     for (y = 0; y < (int) 'z' - ARRAYBASE + 1; y++) {
  6198.         if (a_ptr[y]) {
  6199.             if (x == 0) printf("Declared arrays:\n");
  6200.             x = 1;
  6201.             printf(" \\&%c[%d]",
  6202.                    (y == 1) ? 64 : y + ARRAYBASE, a_dim[y]);
  6203.             if (a_link[y] > -1)
  6204.               printf(" => \\&%c[]",arrayitoa(a_link[y]));
  6205.             printf("\n");
  6206.         }
  6207.         if (!x) printf(" No arrays declared\n");
  6208.     }
  6209.     return(1);
  6210. }
  6211. #endif /* NOSPL */
  6212.  
  6213. int
  6214. doshow(x) int x; {
  6215.     int y, z, i; long zz;
  6216.     extern int optlines;
  6217.     char *s;
  6218. #ifdef OS2
  6219.     extern int os2gks;
  6220.     extern int tt_kb_mode;
  6221. #endif /* OS2 */
  6222.     extern int srvcdmsg;
  6223.     extern char * cdmsgstr, * ckcdpath;
  6224.  
  6225. #ifndef NOSETKEY
  6226.     if (x == SHKEY) {                   /* SHOW KEY */
  6227.         int c;
  6228. #ifdef OS2
  6229.         if ((x = cmkey(shokeytab,nshokey,"How many keys should be shown?",
  6230.                         "one",xxstring)) < 0) return(x);
  6231.         switch (tt_kb_mode) {
  6232.           case KBM_EM:
  6233.             s = "emacs";
  6234.             break;
  6235.           case KBM_HE:
  6236.             s = "hebrew";
  6237.             break;
  6238.           case KBM_RU:
  6239.             s = "russian";
  6240.             break;
  6241.           case KBM_EN:
  6242.           default:
  6243.             s = "default";
  6244.             break;
  6245.         }
  6246.         if ((z = cmkey(shokeymtab,nshokeym,"Which definition should be shown?",
  6247.                         s,xxstring)) < 0) return(z);
  6248.         if (z == SHKEYDEF)
  6249.           z = -1;
  6250. #endif /* OS2 */
  6251.         if ((y = cmcfm()) < 0) return(y);
  6252. #ifdef IKSD
  6253.         if (inserver) {
  6254.             printf("Sorry, command disabled.\r\n");
  6255.             return(success = 0);
  6256.         }
  6257. #endif /* IKSD */
  6258.  
  6259. #ifdef MAC
  6260.         printf("Not implemented\n");
  6261.         return(0);
  6262. #else /* Not MAC */
  6263. #ifdef OS2
  6264.         if (x) {
  6265.             con_event evt;
  6266.             for (c = 0; c < KMSIZE; c++) {
  6267.                 evt = (z < 0) ? mapkey(c) : maptermkey(c,z);
  6268.                 if (evt.type != error) {
  6269.                     shokeycode(c,z);
  6270.                 }
  6271.             }
  6272.         } else {
  6273. #endif /* OS2 */
  6274.             printf(" Press key: ");
  6275. #ifdef UNIX
  6276. #ifdef NOSETBUF
  6277.             fflush(stdout);
  6278. #endif /* NOSETBUF */
  6279. #endif /* UNIX */
  6280.             conbin((char)escape);       /* Put terminal in binary mode */
  6281. #ifdef OS2
  6282.             os2gks = 0;                 /* Raw scancode processing */
  6283. #endif /* OS2 */
  6284.             c = congks(0);              /* Get character or scan code */
  6285. #ifdef OS2
  6286.             os2gks = 1;                 /* Cooked scancode processing */
  6287. #endif /* OS2 */
  6288.             concb((char)escape);        /* Restore terminal to cbreak mode */
  6289.             if (c < 0) {                /* Check for error */
  6290.                 printf("?Error reading key\n");
  6291.                 return(0);
  6292.             }
  6293. #ifndef OS2
  6294. /*
  6295.   Do NOT mask when it can be a raw scan code, perhaps > 255
  6296. */
  6297.             c &= cmdmsk;                /* Apply command mask */
  6298. #endif /* OS2 */
  6299.             printf("\n");
  6300. #ifdef OS2
  6301.             shokeycode(c,z);
  6302. #else /* OS2 */
  6303.             shokeycode(c);
  6304. #endif /* OS2 */
  6305. #ifdef OS2
  6306.         }
  6307. #endif /* OS2 */
  6308.         return(1);
  6309. #endif /* MAC */
  6310.     }
  6311. #ifndef NOKVERBS
  6312.     if (x == SHKVB) {                   /* SHOW KVERBS */
  6313.         if ((y = cmcfm()) < 0) return(y);
  6314. #ifdef IKSD
  6315.         if (inserver) {
  6316.             printf("Sorry, command disabled.\r\n");
  6317.             return(success = 0);
  6318.         }
  6319. #endif /* IKSD */
  6320.         printf("\nThe following %d keyboard verbs are available:\n\n",nkverbs);
  6321.         kwdhelp(kverbs,nkverbs,"","\\K","",3,0);
  6322.         printf("\n");
  6323.         return(1);
  6324.     }
  6325. #ifdef OS2
  6326.     if (x == SHUDK) {                   /* SHOW UDKs */
  6327.         extern void showudk(void);
  6328.         if ((y = cmcfm()) < 0) return(y);
  6329. #ifdef IKSD
  6330.         if (inserver) {
  6331.             printf("Sorry, command disabled.\r\n");
  6332.             return(success = 0);
  6333.         }
  6334. #endif /* IKSD */
  6335.         showudk();
  6336.         return(1);
  6337.     }
  6338. #endif /* OS2 */
  6339. #endif /* NOKVERBS */
  6340. #endif /* NOSETKEY */
  6341.  
  6342. #ifndef NOSPL
  6343.     if (x == SHMAC) {                   /* SHOW MACRO */
  6344.         struct FDB kw, fl, cm;
  6345.         int i, k, n = 0, left, flag, confirmed = 0;
  6346.         char * p, *q[64];
  6347.         for (i = 0; i < nmac; i++) {    /* copy the macro table */
  6348.             mackey[i].kwd = mactab[i].kwd; /* into a regular keyword table */
  6349.             mackey[i].kwval = i;        /* with value = pointer to macro tbl */
  6350.             mackey[i].flgs = mactab[i].flgs;
  6351.         }
  6352.         p = line;
  6353.         left = LINBUFSIZ;
  6354.         while (!confirmed && n < 64) {
  6355.             cmfdbi(&kw,                 /* First FDB - macro table */
  6356.                    _CMKEY,              /* fcode */
  6357.                    "Macro name",        /* hlpmsg */
  6358.                    "",                  /* default */
  6359.                    "",                  /* addtl string data */
  6360.                    nmac,                /* addtl numeric data 1: tbl size */
  6361.                    0,                   /* addtl numeric data 2: 4 = cmswi */
  6362.                    xxstring,            /* Processing function */
  6363.                    mackey,              /* Keyword table */
  6364.                    &fl                  /* Pointer to next FDB */
  6365.                    );
  6366.             cmfdbi(&fl,                 /* 2nd FDB - something not in mactab */
  6367.                    _CMFLD,              /* fcode */
  6368.                    "",                  /* hlpmsg */
  6369.                    "",                  /* default */
  6370.                    "",                  /* addtl string data */
  6371.                    0,                   /* addtl numeric data 1 */
  6372.                    0,                   /* addtl numeric data 2 */
  6373.                    xxstring,
  6374.                    NULL,
  6375.                    &cm
  6376.                    );
  6377.             cmfdbi(&cm,                 /* 3rd FDB - Confirmation */
  6378.                    _CMCFM,              /* fcode */
  6379.                    "",                  /* hlpmsg */
  6380.                    "",                  /* default */
  6381.                    "",                  /* addtl string data */
  6382.                    0,                   /* addtl numeric data 1 */
  6383.                    0,                   /* addtl numeric data 2 */
  6384.                    NULL,
  6385.                    NULL,
  6386.                    NULL
  6387.                    );
  6388.             x = cmfdb(&kw);             /* Parse something */
  6389.             if (x < 0)
  6390.               return(x);
  6391.             s = atmbuf;                 /* What the user typed */
  6392.             switch (cmresult.fcode) {
  6393.               case _CMKEY:              /* If it was a keyword */
  6394.                 y = mlook(mactab,atmbuf,nmac); /* get full name */
  6395.                 if (y > -1)
  6396.                   s = mactab[y].kwd;    /* (fall thru on purpose...) */
  6397.               case _CMFLD:
  6398.                 k = ckstrncpy(p,s,left) + 1; /* Copy result to list */
  6399.                 left -= k;
  6400.                 if (left <= 0) {
  6401.                     *p = NUL;
  6402.                     break;
  6403.                 }
  6404.                 q[n++] = p;             /* Point to this item */
  6405.                 p += k;                 /* Move buffer pointer past it */
  6406.                 break;
  6407.               case _CMCFM:              /* End of command */
  6408.                 confirmed++;
  6409.               default:
  6410.                 break;
  6411.             }
  6412.         }
  6413.         if (n == 0) {
  6414.             printf("Macros:\n");
  6415.             slc = 1;
  6416.             for (y = 0; y < nmac; y++)
  6417.               if (shomac(mactab[y].kwd,mactab[y].mval) < 0) break;
  6418.             return(1);
  6419.         }
  6420.         slc = 0;
  6421.         for (i = 0; i < n; i++) {
  6422.             flag = 0;
  6423.             s = q[i];
  6424.             if (!s) s = "";
  6425.             if (!*s) continue;
  6426.             if (iswild(s)) {            /* Pattern match */
  6427.                 for (k = 0, x = 0; x < nmac; x++) {
  6428.                     if (ckmatch(s,mactab[x].kwd,0,1)) {
  6429.                         shomac(mactab[x].kwd,mactab[x].mval);
  6430.                         k++;
  6431.                     }
  6432.                 }
  6433.                 if (!k)
  6434.                   x = -1;
  6435.                 else
  6436.                   continue;
  6437.             } else {                    /* Exact match */
  6438.                 x = mxlook(mactab,s,nmac);
  6439.                 flag = 1;
  6440.             }
  6441.             if (flag && x == -1)
  6442.               x = mlook(mactab,s,nmac);
  6443.             switch (x) {
  6444.               case -3:                  /* Nothing to look up */
  6445.               case -1:                  /* Not found */
  6446.                 printf("%s - (not defined)\n",s);
  6447.                 break;
  6448.               case -2:                  /* Ambiguous, matches more than one */
  6449.                 printf("%s - ambiguous\n",s);
  6450.                 break;
  6451.               default:                  /* Matches one exactly */
  6452.                 shomac(mactab[x].kwd,mactab[x].mval);
  6453.                 break;
  6454.             }
  6455.         }
  6456.         return(1);
  6457.     }
  6458. #endif /* NOSPL */
  6459.  
  6460. /*
  6461.   Other SHOW commands only have two fields.  Get command confirmation here,
  6462.   then handle with big switch() statement.
  6463. */
  6464. #ifndef NOSPL
  6465.     if (x != SHBUI && x != SHARR)
  6466. #endif /* NOSPL */
  6467.       if ((y = cmcfm()) < 0)
  6468.         return(y);
  6469.  
  6470. #ifdef COMMENT
  6471.     /* This restriction is too general. */
  6472. #ifdef IKSD
  6473.     if (inserver &&
  6474. #ifdef CK_LOGIN
  6475.         isguest
  6476. #else
  6477.         0
  6478. #endif /* CK_LOGIN */
  6479.         ) {
  6480.         printf("Sorry, command disabled.\r\n");
  6481.         return(success = 0);
  6482.     }
  6483. #endif /* IKSD */
  6484. #endif /* COMMENT */
  6485.  
  6486.     switch (x) {
  6487.  
  6488. #ifdef ANYX25
  6489. #ifndef IBMX25
  6490.       case SHPAD:
  6491.         shopad(0);
  6492.         break;
  6493. #endif /* IBMX25 */
  6494. #endif /* ANYX25 */
  6495.  
  6496.       case SHNET:
  6497. #ifdef NOLOCAL
  6498.         printf(" No network support in this version of C-Kermit.\n");
  6499. #else
  6500. #ifndef NETCONN
  6501.         printf(" No network support in this version of C-Kermit.\n");
  6502. #else
  6503.         shonet();
  6504. #endif /* NETCONN */
  6505. #endif /* NOLOCAL */
  6506.         break;
  6507.  
  6508.       case SHPAR:
  6509.         shopar();
  6510.         break;
  6511.  
  6512. #ifndef NOXFER
  6513.       case SHATT:
  6514.         shoatt();
  6515.         break;
  6516. #endif /* NOXFER */
  6517.  
  6518. #ifndef NOSPL
  6519.       case SHCOU:
  6520.         printf(" %d\n",count[cmdlvl]);
  6521.         break;
  6522. #endif /* NOSPL */
  6523.  
  6524. #ifndef NOSERVER
  6525.       case SHSER:                       /* Show Server */
  6526.         i = 0;
  6527. #ifndef NOFRILLS
  6528.         printf("Function:          Status:\n");
  6529.         i++;
  6530.         printf(" GET                %s\n",nm[en_get]);
  6531.         i++;
  6532.         printf(" SEND               %s\n",nm[en_sen]);
  6533.         i++;
  6534.         printf(" MAIL               %s\n",nm[inserver ? 0 : en_mai]);
  6535.         i++;
  6536.         printf(" PRINT              %s\n",nm[inserver ? 0 : en_pri]);
  6537.         i++;
  6538. #ifndef NOSPL
  6539.         printf(" REMOTE ASSIGN      %s\n",nm[en_asg]);
  6540.         i++;
  6541. #endif /* NOSPL */
  6542.         printf(" REMOTE CD/CWD      %s\n",nm[en_cwd]);
  6543.         i++;
  6544. #ifdef ZCOPY
  6545.         printf(" REMOTE COPY        %s\n",nm[en_cpy]);
  6546.         i++;
  6547. #endif /* ZCOPY */
  6548.         printf(" REMOTE DELETE      %s\n",nm[en_del]);
  6549.         printf(" REMOTE DIRECTORY   %s\n",nm[en_dir]);
  6550.         printf(" REMOTE HOST        %s\n",nm[inserver ? 0 : en_hos]);
  6551.         i += 3;
  6552. #ifndef NOSPL
  6553.         printf(" REMOTE QUERY       %s\n",nm[en_que]);
  6554.         i++;
  6555. #endif /* NOSPL */
  6556.         printf(" REMOTE MKDIR       %s\n",nm[en_mkd]);
  6557.         printf(" REMOTE RMDIR       %s\n",nm[en_rmd]);
  6558.         printf(" REMOTE RENAME      %s\n",nm[en_ren]);
  6559.         printf(" REMOTE SET         %s\n",nm[en_set]);
  6560.         printf(" REMOTE SPACE       %s\n",nm[en_spa]);
  6561.         printf(" REMOTE TYPE        %s\n",nm[en_typ]);
  6562.         printf(" REMOTE WHO         %s\n",nm[inserver ? 0 : en_who]);
  6563.         printf(" BYE                %s\n",nm[en_bye]);
  6564.         printf(" FINISH             %s\n",nm[en_fin]);
  6565.         printf(" EXIT               %s\n",nm[en_xit]);
  6566.         printf(" ENABLE             %s\n",nm[en_ena]);
  6567.         i += 11;
  6568. #endif /* NOFRILLS */
  6569.         if (i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6570.         printf("Server timeout:      %d\n",srvtim);
  6571.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6572.         printf("Server idle-timeout: %d\n",srvidl);
  6573.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6574.         printf("Server keepalive     %s\n", showoff(srvping));
  6575.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6576.         printf("Server cd-message    %s\n", showoff(srvcdmsg));
  6577.         if (srvcdmsg && cdmsgstr)
  6578.           printf("Server cd-message    %s\n", cdmsgstr);
  6579.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6580.         printf("Server display:      %s\n", showoff(srvdis));
  6581.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6582.         printf("Server login:        ");
  6583.         if (!x_user) {
  6584.             printf("(none)\n");
  6585.         } else {
  6586.             printf("\"%s\", \"%s\", \"%s\"\n",
  6587.                    x_user,
  6588.                    x_passwd ? x_passwd : "",
  6589.                    x_acct ? x_acct : ""
  6590.                    );
  6591.         }
  6592.         if (++i > cmd_rows - 3) { if (!askmore()) return(1); else i = 0; }
  6593.         printf("Server get-path: ");
  6594.         if (ngetpath == 0) {
  6595.             printf("    (none)\n");
  6596.         } else {
  6597.             printf("\n");
  6598.             i += 3;
  6599.             for (x = 0; x < ngetpath; x++) {
  6600.                 if (getpath[x]) printf(" %d. %s\n", x, getpath[x]);
  6601.                 if (++i > (cmd_rows - 3)) { /* More than a screenful... */
  6602.                     if (!askmore())
  6603.                       break;
  6604.                     else
  6605.                       i = 0;
  6606.                 }
  6607.             }
  6608.         }
  6609.         break;
  6610. #endif /* NOSERVER */
  6611.  
  6612.       case SHSTA:                       /* Status of last command */
  6613.         printf(" %s\n", success ? "SUCCESS" : "FAILURE");
  6614.         return(0);                      /* Don't change it */
  6615.  
  6616.       case SHSTK: {                     /* Stack for MAC debugging */
  6617. #ifdef MAC
  6618.           long sp;
  6619.           sp = -1;
  6620.           loadA0 ((char *)&sp);         /* set destination address */
  6621.           SPtoaA0();                    /* move SP to destination */
  6622.           printf("Stack at 0x%x\n", sp);
  6623.           show_queue();                 /* more debugging */
  6624.           break;
  6625. #else
  6626.           shostack();
  6627. #endif /* MAC */
  6628.           break;
  6629.       }
  6630.  
  6631.  
  6632. #ifndef NOLOCAL
  6633. #ifdef OS2
  6634.       case SHTAB:                       /* SHOW TABS */
  6635. #ifdef IKSD
  6636.         if (inserver) {
  6637.             printf("Sorry, command disabled.\r\n");
  6638.             return(success = 0);
  6639.         }
  6640. #endif /* IKSD */
  6641.         shotabs();
  6642.         break;
  6643. #endif /* OS2 */
  6644.  
  6645.       case SHTER:                       /* SHOW TERMINAL */
  6646. #ifdef IKSD
  6647.         if (inserver) {
  6648.             printf("Sorry, command disabled.\r\n");
  6649.             return(success = 0);
  6650.         }
  6651. #endif /* IKSD */
  6652.         shotrm();
  6653.         break;
  6654.  
  6655. #ifdef OS2
  6656.       case SHVSCRN:                     /* SHOW Virtual Screen - for debug */
  6657.         shovscrn();
  6658.         break;
  6659. #endif /* OS2 */
  6660. #endif /* NOLOCAL */
  6661.  
  6662. #ifdef OS2MOUSE
  6663.       case SHMOU:                       /* SHOW MOUSE */
  6664. #ifdef IKSD
  6665.         if (inserver) {
  6666.             printf("Sorry, command disabled.\r\n");
  6667.             return(success = 0);
  6668.         }
  6669. #endif /* IKSD */
  6670.         shomou();
  6671.         break;
  6672. #endif /* OS2MOUSE */
  6673.  
  6674. #ifndef NOFRILLS
  6675.       case SHVER:
  6676.         shover();
  6677.         break;
  6678. #endif /* NOFRILLS */
  6679.  
  6680. #ifndef NOSPL
  6681.       case SHBUI:                       /* Built-in variables */
  6682.         if ((y = cmtxt("Variable name or pattern","",&s,xxstring)) < 0)
  6683.           return(y);
  6684.         ckstrncpy(line,s,LINBUFSIZ);
  6685.         /* if (line[0]) ckstrncat(line,"*",LINBUFSIZ); */
  6686.  
  6687.       case SHFUN:                       /* or built-in functions */
  6688. #ifdef CK_TTGWSIZ
  6689. #ifdef OS2
  6690.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6691.           ttgwsiz();
  6692. #else /* OS2 */
  6693.         if (ttgwsiz() > 0) {            /* Get current screen size */
  6694.             if (tt_rows > 0 && tt_cols > 0) {
  6695.                 cmd_rows = tt_rows;
  6696.                 cmd_cols = tt_cols;
  6697.             }
  6698.         }
  6699. #endif /* OS2 */
  6700. #endif /* CK_TTGWSIZ */
  6701.  
  6702.         if (x == SHFUN) {               /* Functions */
  6703.             printf("\nThe following functions are available:\n\n");
  6704.             kwdhelp(fnctab,nfuncs,"","\\F","()",3,0);
  6705.             printf("\n");
  6706. #ifndef NOHELP
  6707.             printf(
  6708. "HELP FUNCTION <name> gives the calling conventions of the given function.\n\n"
  6709.                    );
  6710. #endif /* NOHELP */
  6711.             break;
  6712.         } else {                        /* Variables */
  6713.         int j, flag = 0, havearg = 0;
  6714.         struct stringarray * q = NULL;
  6715.         char ** pp;
  6716.         if (line[0]) {        /* Have something to search for */
  6717.         havearg = 1;        /* Maybe a list of things */
  6718.         q = cksplit(1,0,line,NULL,"_-^$*?[]{}",0,0,0);
  6719.         if (!q) break;
  6720.         pp = q->a_head;
  6721.         }
  6722.         i = 0;
  6723.         for (y = 0; y < nvars; y++) {
  6724.         if ((vartab[y].flgs & CM_INV))
  6725.           continue;
  6726.         if (havearg) {        /* If I have something to match */
  6727.             char * s2;
  6728.             for (flag = 0, j = 1; j <= q->a_size && !flag; j++) {
  6729.             s2 = pp[j] ? pp[j] : "";
  6730. #ifdef COMMENT
  6731. /* This is not needed because it's what the 4 arg does in ckmatch() */
  6732.             len = strlen(s2);
  6733.             if (len > 0) {
  6734.                 if (s2[len-1] != '$') {/* To allow anchors */
  6735.                 ckmakmsg(line,LINBUFSIZ,pp[j],"*",NULL,NULL);
  6736.                 s2 = line;
  6737.                 }
  6738.             }
  6739. #endif /* COMMENT */
  6740.             if (ckmatch(s2,vartab[y].kwd,0,4) > 0) {
  6741.                 flag = 1;    /* Matches */
  6742.                 break;
  6743.             }
  6744.             }
  6745.             if (!flag)        /* Doesn't match */
  6746.               continue;
  6747.         }
  6748.         s = nvlook(vartab[y].kwd);
  6749.         printf(" \\v(%s) = ",vartab[y].kwd);
  6750.         if (vartab[y].kwval == VN_NEWL) { /* \v(newline) */
  6751.             while (*s)        /* Show control chars symbolically */
  6752.               printf("\\{%d}",*s++);
  6753.             printf("\n");
  6754.         } else if (vartab[y].kwval == VN_IBUF  || /* \v(input) */
  6755.                vartab[y].kwval == VN_QUE   || /* \v(query) */
  6756. #ifdef OS2
  6757.                vartab[y].kwval == VN_SELCT || /* \v(select) */
  6758. #endif /* OS2 */
  6759.                (vartab[y].kwval >= VN_M_AAA && /* modem ones */
  6760.                 vartab[y].kwval <= VN_M_ZZZ)
  6761.                ) {
  6762.             int r = 12;        /* This one can wrap around */
  6763.             char buf[10];
  6764.             while (*s) {
  6765.             if (isprint(*s)) {
  6766.                 buf[0] = *s;
  6767.                 buf[1] = NUL;
  6768.                 r++;
  6769.             } else {
  6770.                 sprintf(buf,"\\{%d}",*s); /* SAFE */
  6771.                 r += (int) strlen(buf);
  6772.             }
  6773.             if (r >= cmd_cols - 1) {
  6774.                 printf("\n");
  6775.                 r = 0;
  6776.                 i++;
  6777.             }
  6778.             printf("%s",buf);
  6779.             s++;
  6780.             }
  6781.             printf("\n");
  6782.         } else
  6783.           printf("%s\n",s);
  6784.         if (++i > (cmd_rows - 3)) { /* More than a screenful... */
  6785.             if ((y >= nvars - 1) || !askmore())
  6786.               break;
  6787.             else
  6788.               i = 0;
  6789.         }
  6790.         }
  6791.         }
  6792.         break;
  6793.  
  6794.       case SHVAR:                       /* Global variables */
  6795.         x = 0;                          /* Variable count */
  6796.         slc = 1;                        /* Screen line count for "more?" */
  6797.         for (y = 33; y < GVARS; y++)
  6798.           if (g_var[y]) {
  6799.               if (x++ == 0) printf("Global variables:\n");
  6800.               sprintf(line," \\%%%c",y); /* SAFE */
  6801.               if (shomac(line,g_var[y]) < 0) break;
  6802.           }
  6803.         if (!x) printf(" No variables defined\n");
  6804.         break;
  6805.  
  6806.       case SHARG: {                     /* Args */
  6807.           char * s1, * s2;
  6808.           if (maclvl > -1) {
  6809.               printf("Macro arguments at level %d (\\v(argc) = %d):\n",
  6810.                      maclvl,
  6811.                      macargc[maclvl]
  6812.                      );
  6813.               for (y = 0; y < macargc[maclvl]; y++) {
  6814.                   s1 = m_arg[maclvl][y];
  6815.                   if (!s1) s1 = "(NULL)";
  6816.                   s2 = m_xarg[maclvl][y];
  6817.                   if (!s2) s2 = "(NULL)";
  6818.                   if (y < 10)
  6819.                     printf(" \\%%%d = %s\n",y,s1);
  6820.                   else
  6821.                     printf(" \\&_[%d] = %s\n",y,s2);
  6822.               }
  6823.           } else {
  6824.               printf("Top-level arguments (\\v(argc) = %d):\n", topargc);
  6825.               for (y = 0; y < topargc; y++) {
  6826.                   s1 = g_var[y + '0'];
  6827.                   if (!s1) s1 = "(NULL)";
  6828.                   s2 = toparg[y];
  6829.                   if (!s2) s2 = "(NULL)";
  6830.                   if (y < 10 && g_var[y])
  6831.                     printf(" \\%%%d = %s\n",y,s1);
  6832.                   if (toparg[y])
  6833.                     printf(" \\&_[%d] = %s\n",y,s2);
  6834.               }
  6835.           }
  6836.         }
  6837.         break;
  6838.  
  6839.       case SHARR:                       /* Arrays */
  6840.         return(showarray());
  6841. #endif /* NOSPL */
  6842.  
  6843. #ifndef NOXFER
  6844.       case SHPRO:                       /* Protocol parameters */
  6845.         shoparp();
  6846.         printf("\n");
  6847.         break;
  6848. #endif /* NOXFER */
  6849.  
  6850. #ifndef NOLOCAL
  6851.       case SHCOM:                       /* Communication parameters */
  6852.         printf("\n");
  6853.         shoparc();
  6854. #ifdef OS2
  6855.         {
  6856.             int i;
  6857.             char *s = "(unknown)";
  6858.             for (i = 0; i < nprty; i++)
  6859.               if (prtytab[i].kwval == priority) {
  6860.                   s = prtytab[i].kwd;
  6861.                   break;
  6862.               }
  6863.             printf(" Priority: %s\n", s );
  6864.         }
  6865. #endif /* OS2 */
  6866.  
  6867.         printf("\n");
  6868. #ifdef NETCONN
  6869.         if (!network
  6870. #ifdef IKSD
  6871.              && !inserver
  6872. #endif /* IKSD */
  6873.              ) {
  6874. #endif /* NETCONN */
  6875.             shomdm();
  6876.             printf("\n");
  6877. #ifdef NETCONN
  6878.         }
  6879. #endif /* NETCONN */
  6880.  
  6881. #ifndef NODIAL
  6882. #ifdef IKSD
  6883.         if ( !inserver )
  6884. #endif /* IKSD */
  6885.         {
  6886.             printf("Type SHOW DIAL to see DIAL-related items.\n");
  6887.             printf("Type SHOW MODEM to see modem-related items.\n");
  6888. #ifdef CK_TAPI
  6889.             printf("Type SHOW TAPI to see TAPI-related items.\n");
  6890. #endif /* CK_TAPI */
  6891.             printf("\n");
  6892.         }
  6893. #endif /* NODIAL */
  6894.         break;
  6895. #endif /* NOLOCAL */
  6896.  
  6897.       case SHFIL:                       /* File parameters */
  6898.         shofil();
  6899.         /* printf("\n"); */             /* (out o' space) */
  6900.         break;
  6901.  
  6902. #ifndef NOCSETS
  6903.       case SHLNG:                       /* Languages */
  6904.         shoparl();
  6905.         break;
  6906. #endif /* NOCSETS */
  6907.  
  6908. #ifndef NOSPL
  6909.       case SHSCR:                       /* Scripts */
  6910.         printf(" Command quoting:        %s\n", showoff(cmdgquo()));
  6911.         printf(" Take  echo:             %s\n", showoff(techo));
  6912.         printf(" Take  error:            %s\n", showoff(takerr[cmdlvl]));
  6913.         printf(" Macro echo:             %s\n", showoff(mecho));
  6914.         printf(" Macro error:            %s\n", showoff(merror[cmdlvl]));
  6915.         printf(" Quiet:                  %s\n", showoff(quiet));
  6916.         printf(" Function diagnostics:   %s\n", showoff(fndiags));
  6917.         printf(" Function error:         %s\n", showoff(fnerror));
  6918. #ifdef CKLEARN
  6919.         {
  6920.             extern char * learnfile;
  6921.             extern int learning;
  6922.             if (learnfile) {
  6923.                 printf(" LEARN file:             %s (%s)\n",
  6924.                        learnfile,
  6925.                        learning ? "ON" : "OFF"
  6926.                        );
  6927.             } else
  6928.               printf(" LEARN file:             (none)\n");
  6929.         }
  6930. #endif /* CKLEARN */
  6931.         shoinput();
  6932.         shooutput();
  6933. #ifndef NOSCRIPT
  6934.         printf(" Script echo:            %s\n", showoff(secho));
  6935. #endif /* NOSCRIPT */
  6936.         printf(" Command buffer length:  %d\n", CMDBL);
  6937.         printf(" Atom buffer length:     %d\n", ATMBL);
  6938.         break;
  6939. #endif /* NOSPL */
  6940.  
  6941. #ifndef NOXMIT
  6942.       case SHXMI:
  6943.         printf("\n");
  6944.         printf(" File type:                       %s\n",
  6945.                binary ? "binary" : "text");
  6946. #ifndef NOCSETS
  6947.         printf(" File character-set:              %s\n",
  6948.                fcsinfo[fcharset].keyword);
  6949.         printf(" Terminal character-set (remote): %s\n",
  6950.                fcsinfo[tcsr].keyword);
  6951.         printf(" Terminal character-set (local):  %s\n",
  6952.                fcsinfo[tcsl].keyword);
  6953. #endif /* NOCSETS */
  6954.         printf(" Terminal bytesize:               %d\n",
  6955.                (cmask == 0xff) ? 8 : 7);
  6956.         printf(" Terminal echo:                   %s\n",
  6957.                duplex ? "local" : "remote");
  6958.         printf(" Transmit EOF:                    ");
  6959.         if (*xmitbuf == NUL) {
  6960.             printf("(none)\n");
  6961.         } else {
  6962.             char *p;
  6963.             p = xmitbuf;
  6964.             while (*p) {
  6965.                 if (*p < SP)
  6966.                   printf("^%c",ctl(*p));
  6967.                 else
  6968.                   printf("%c",*p);
  6969.                 p++;
  6970.             }
  6971.             printf("\n");
  6972.         }
  6973.         if (xmitf)
  6974.           printf(" Transmit Fill:                   %d\n", xmitf);
  6975.         else
  6976.           printf(" Transmit Fill:                   (none)\n");
  6977.         printf(" Transmit Linefeed:               %s\n",showoff(xmitl));
  6978.         if (xmitp)
  6979.           printf(" Transmit Prompt:                 %d (%s)\n",
  6980.                  xmitp,
  6981.                  chartostr(xmitp)
  6982.                  );
  6983.         else
  6984.           printf(" Transmit Prompt:                 (none)\n");
  6985.         printf(" Transmit Echo:                   %s\n", showoff(xmitx));
  6986.         printf(" Transmit Locking-Shift:          %s\n", showoff(xmits));
  6987.         printf(" Transmit Pause:                  %d (millisecond%s)\n",
  6988.                xmitw,
  6989.                (xmitw == 1) ? "" : "s"
  6990.                );
  6991.         printf(" Transmit Timeout:                %d (second%s)\n",
  6992.                xmitt,
  6993.                (xmitt == 1) ? "" : "s"
  6994.                );
  6995.         printf("\n");
  6996.         break;
  6997. #endif /* NOXMIT */
  6998.  
  6999. #ifndef NODIAL
  7000.       case SHMOD:                       /* SHOW MODEM */
  7001. #ifdef IKSD
  7002.         if (inserver) {
  7003.             printf("Sorry, command disabled.\r\n");
  7004.             return(success = 0);
  7005.         }
  7006. #endif /* IKSD */
  7007.         shomodem();                     /* Show SET MODEM items */
  7008.         break;
  7009. #endif /* NODIAL */
  7010.  
  7011. #ifndef MAC
  7012.       case SHDFLT:
  7013.         printf("%s\n",zgtdir());
  7014.         break;
  7015. #endif /* MAC */
  7016.  
  7017. #ifndef NOLOCAL
  7018.       case SHESC:
  7019. #ifdef IKSD
  7020.         if (inserver) {
  7021.             printf("Sorry, command disabled.\r\n");
  7022.             return(success = 0);
  7023.         }
  7024. #endif /* IKSD */
  7025.         return(shoesc(escape));
  7026.  
  7027. #ifndef NODIAL
  7028.       case SHDIA:                       /* SHOW DIAL */
  7029. #ifdef IKSD
  7030.         if (inserver) {
  7031.             printf("Sorry, command disabled.\r\n");
  7032.             return(success = 0);
  7033.         }
  7034. #endif /* IKSD */
  7035.         shmdmlin();
  7036.         printf(", speed: ");
  7037.         if ((zz = ttgspd()) < 0) {
  7038.             printf("unknown");
  7039.         } else {
  7040.             if (zz == 8880) printf("75/1200"); else printf("%ld",zz);
  7041.         }
  7042.         if (carrier == CAR_OFF) s = "off";
  7043.         else if (carrier == CAR_ON) s = "on";
  7044.         else if (carrier == CAR_AUT) s = "auto";
  7045.         else s = "unknown";
  7046.         printf(", carrier: %s", s);
  7047.         if (carrier == CAR_ON) {
  7048.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  7049.             else printf(", timeout: none");
  7050.         }
  7051.         printf("\n");
  7052.         doshodial();
  7053.         if (local
  7054. #ifdef NETCONN
  7055.             && !network
  7056. #endif /* NETCONN */
  7057.             ) {
  7058.             printf("Type SHOW MODEM to see modem settings.\n");
  7059. #ifdef CK_TAPI
  7060.             printf("Type SHOW TAPI to see TAPI-related items\n");
  7061. #endif /* CK_TAPI */
  7062.             printf("Type SHOW COMMUNICATIONS to see modem signals.\n");
  7063.         }
  7064.         break;
  7065. #endif /* NODIAL */
  7066. #endif /* NOLOCAL */
  7067.  
  7068. #ifndef NOXFER
  7069. #ifdef CK_LABELED
  7070.       case SHLBL:                       /* Labeled file info */
  7071.         sholbl();
  7072.         break;
  7073. #endif /* CK_LABELED */
  7074. #endif /* NOXFER */
  7075.  
  7076.       case SHCSE:                       /* Character sets */
  7077. #ifdef NOCSETS
  7078.         printf(
  7079. " Character set translation is not supported in this version of C-Kermit\n");
  7080. #else
  7081.         shocharset();
  7082. #ifndef NOXFER
  7083.         printf("\n Unknown-Char-Set: %s\n",
  7084.                unkcs ? "Keep" : "Discard");
  7085. #endif /* NOXFER */
  7086. #ifdef OS2
  7087.         printf("\n");
  7088. #endif /* OS2 */
  7089.         shotcs(tcsl,tcsr);
  7090.         printf("\n");
  7091. #ifdef OS2
  7092.         /* PC Code Page information */
  7093.         {
  7094.             char cpbuf[128];
  7095.             int cplist[16], cps;
  7096.             int activecp;
  7097.             cps = os2getcplist(cplist, sizeof(cplist));
  7098.  
  7099.             sprintf(cpbuf,              /* SAFE */
  7100.                     "%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d",
  7101.                      cps > 1 ? cplist[1] : 0,
  7102.                      cps > 2 ? cplist[2] : 0, cps > 3 ? cplist[3] : 0,
  7103.                      cps > 4 ? cplist[4] : 0, cps > 5 ? cplist[5] : 0,
  7104.                      cps > 6 ? cplist[6] : 0, cps > 7 ? cplist[7] : 0,
  7105.                      cps > 8 ? cplist[8] : 0, cps > 9 ? cplist[9] : 0,
  7106.                      cps > 10 ? cplist[10] : 0, cps > 11 ? cplist[11] : 0,
  7107.                      cps > 12 ? cplist[12] : 0
  7108.                      );
  7109.             printf(" Code Pages:\n");
  7110.             activecp = os2getcp();
  7111.             if ( activecp ) {
  7112.               printf("     Active: %d\n",activecp);
  7113.               if (!isWin95())
  7114.                 printf("  Available: %s\n",cpbuf);
  7115.             } else
  7116.               printf("     Active: n/a\n");
  7117.             printf("\n");
  7118.         }
  7119. #endif /* OS2 */
  7120. #endif /* NOCSETS */
  7121.         break;
  7122.  
  7123.       case SHFEA:                       /* Features */
  7124.         shofea();
  7125.         break;
  7126.  
  7127. #ifdef CK_SPEED
  7128.       case SHCTL:                       /* Control-Prefix table */
  7129.         shoctl();
  7130.         break;
  7131. #endif /* CK_SPEED */
  7132.  
  7133.       case SHEXI: {
  7134.           extern int exithangup;
  7135.           printf("\n Exit warning %s\n", xitwarn ?
  7136.                  (xitwarn == 1 ? "on" : "always") : "off");
  7137.           printf(" Exit on-disconnect: %s\n", showoff(exitonclose));
  7138.           printf(" Exit hangup: %s\n", showoff(exithangup));
  7139.           printf(" Current exit status: %d\n\n", xitsta);
  7140.           break;
  7141.       }
  7142.       case SHPRT: {
  7143. #ifdef PRINTSWI
  7144.           extern int printtimo, printertype, noprinter;
  7145.           extern char * printterm, * printsep;
  7146. #ifdef BPRINT
  7147.           extern int printbidi;
  7148. #endif /* BPRINT */
  7149. #endif /* PRINTSWI */
  7150.  
  7151. #ifdef IKSD
  7152.         if (inserver &&
  7153. #ifdef CK_LOGIN
  7154.             isguest
  7155. #else /* CK_LOGIN */
  7156.             0
  7157. #endif /* CK_LOGIN */
  7158.              ) {
  7159.             printf("Sorry, command disabled.\r\n");
  7160.             return(success = 0);
  7161.         }
  7162. #endif /* IKSD */
  7163. #ifdef PRINTSWI
  7164.           if (noprinter) {
  7165.               printf("Printer: (none)\n\n");
  7166.               break;
  7167.           }
  7168. #endif /* PRINTSWI */
  7169.  
  7170.           printf("Printer: %s%s\n",
  7171.  
  7172.                  printpipe ? "| " : "",
  7173.                  printername ? printername :
  7174. #ifdef OS2
  7175.                  "PRN"
  7176. #else
  7177.                  "(default)"
  7178. #endif /* OS2 */
  7179.                  );
  7180. #ifdef PRINTSWI
  7181. #ifdef BPRINT
  7182.           if (printbidi) {
  7183.               printf(" /BIDIRECTIONAL\n");
  7184.               if (pportspeed > 0)
  7185.                 printf(" /SPEED:%ld\n",pportspeed);
  7186.               printf(" /PARITY:%s\n",parnam((char)pportparity));
  7187.               printf(" /FLOW:%s\n",
  7188.                      pportflow == FLO_NONE ? "NONE" :
  7189.                      (pportflow == FLO_RTSC ? "RTS/CTS" : "XON/XOFF")
  7190.                      );
  7191.           } else
  7192.             printf(" /OUTPUT-ONLY\n");
  7193. #endif /* BPRINT */
  7194.           switch (printertype) {
  7195.             case PRT_NON: printf(" /NONE\n"); break;
  7196.             case PRT_FIL: printf(" /FILE\n"); break;
  7197.             case PRT_PIP: printf(" /PIPE\n"); break;
  7198.             case PRT_DOS: printf(" /DOS-DEVICE\n"); break;
  7199.             case PRT_WIN: printf(" /WINDOWS-QUEUE\n"); break;
  7200.           }
  7201.           printf(" /TIMEOUT:%d\n",printtimo);
  7202.           if (printterm) {
  7203.               printf(" /END-OF-JOB-STRING:");
  7204.               shostrdef(printterm);
  7205.               printf("\n");
  7206.           } else
  7207.             printf(" /END-OF-JOB-STRING:(none)\n");
  7208.           printf(" /JOB-HEADER-FILE:%s\n",printsep ? printsep : "(none)");
  7209. #endif /* PRINTSWI */
  7210.           printf("\n");
  7211.           break;
  7212.       }
  7213.  
  7214.       case SHCMD: {
  7215. #ifdef DOUBLEQUOTING
  7216.           extern int dblquo;
  7217. #endif /* DOUBLEQUOTING */
  7218. #ifdef CK_AUTODL
  7219.           printf(" Command autodownload: %s\n",showoff(cmdadl));
  7220. #else
  7221.           printf(" Command autodownload: (not available)\n");
  7222. #endif /* CK_AUTODL */
  7223.           printf(" Command bytesize: %d bits\n", (cmdmsk == 0377) ? 8 : 7);
  7224. #ifdef CK_RECALL
  7225.           printf(" Command recall-buffer-size: %d\n",cm_recall);
  7226. #else
  7227.           printf(" Command recall-buffer not available in this version\n");
  7228. #endif /* CK_RECALL */
  7229. #ifdef CK_RECALL
  7230.           printf(" Command retry: %s\n",showoff(cm_retry));
  7231. #else
  7232.           printf(" Command retry not available in this version\n");
  7233. #endif /* CK_RECALL */
  7234.           printf(" Command interruption: %s\n", showoff(cmdint));
  7235.           printf(" Command quoting: %s\n", showoff(cmdgquo()));
  7236. #ifdef DOUBLEQUOTING
  7237.           printf(" Command doublequoting: %s\n", showoff(dblquo));
  7238. #endif /* DOUBLEQUOTING */
  7239.           printf(" Command more-prompting: %s\n", showoff(xaskmore));
  7240.           printf(" Command height: %d\n", cmd_rows);
  7241.           printf(" Command width:  %d\n", cmd_cols);
  7242. #ifndef IKSDONLY
  7243. #ifdef OS2
  7244.           printf(" Command statusline: %s\n",showoff(tt_status[VCMD]));
  7245. #endif /* OS2 */
  7246. #endif /* IKSDONLY */
  7247. #ifdef LOCUS
  7248.           printf(" Locus:          %s",
  7249.                  autolocus ? (autolocus == 2 ? "ask" : "auto") :
  7250.          (locus ? "local" : "remote"));
  7251.           if (autolocus)
  7252.             printf(" (%s)", locus ? "local" : "remote");
  7253.           printf("\n");
  7254. #endif /* LOCUS */
  7255.           printf(" Hints:          %s\n", showoff(hints));
  7256.           printf(" Quiet:          %s\n", showoff(quiet));
  7257.           printf(" Maximum command length: %d\n", CMDBL);
  7258. #ifndef NOSPL
  7259.           {
  7260.               char * s;
  7261.               int k;
  7262.               printf(" Maximum number of macros: %d\n", MAC_MAX);
  7263.               printf(" Macros defined: %d\n", nmac);
  7264.               printf(" Maximum macro depth: %d\n", MACLEVEL);
  7265.               printf(" Maximum TAKE depth: %d\n", MAXTAKE);
  7266.               s = "(not defined)";
  7267.               k = mlook(mactab,"on_unknown_command",nmac);
  7268.               if (k > -1) if (mactab[k].mval) s = mactab[k].mval;
  7269.               printf(" ON_UNKNOWN_COMMAND: %s\n",s);
  7270.           }
  7271. #endif /* NOSPL */
  7272. #ifdef UNIX
  7273. #ifndef NOJC
  7274.           printf(" Suspend: %s\n", showoff(suspend));
  7275. #endif /* NOJC */
  7276. #endif /* UNIX */
  7277.           printf(" Access to external commands and programs%s allowed\n",
  7278. #ifndef NOPUSH
  7279.                  !nopush ? "" :
  7280. #endif /* NOPUSH */
  7281.                   " not");
  7282.           break;
  7283.       }
  7284.  
  7285. #ifndef NOSPL
  7286.       case SHALRM:
  7287.         if (ck_alarm)
  7288.           printf("Alarm at %s %s\n",alrm_date,alrm_time);
  7289.         else
  7290.           printf("(no alarm set)\n");
  7291.         break;
  7292. #endif /* NOSPL */
  7293.  
  7294. #ifndef NOMSEND
  7295.       case SHSFL: {
  7296.           extern struct filelist * filehead;
  7297.           if (!filehead) {
  7298.               printf("send-list is empty\n");
  7299.           } else {
  7300.               struct filelist * flp;
  7301.               char * s;
  7302.               flp = filehead;
  7303.               while (flp) {
  7304.                   s = flp->fl_alias;
  7305.                   if (!s) s = "(none)";
  7306.                   printf("%s, mode: %s, alias: %s\n",
  7307.                          flp->fl_name,
  7308.                          gfmode(flp->fl_mode,0),
  7309.                          s
  7310.                          );
  7311.                   flp = flp->fl_next;
  7312.               }
  7313.           }
  7314.       }
  7315.       break;
  7316. #endif /* NOMSEND */
  7317.  
  7318. #ifdef CKXXCHAR
  7319.       case SHDBL:
  7320.         shodbl();
  7321.         break;
  7322. #endif /* CKXXCHAR */
  7323.  
  7324. #ifndef NOPUSH
  7325. #ifndef NOFRILLS
  7326.       case SHEDIT:
  7327.         if (!editor[0]) {
  7328.             s = getenv("EDITOR");
  7329.             if (s) ckstrncpy(editor,s,CKMAXPATH);
  7330.         }
  7331.         printf("\n editor:  %s\n", editor[0] ? editor : "(none)");
  7332.         if (editor[0]) {
  7333.             printf(" options: %s\n", editopts[0] ? editopts : "(none)");
  7334.             printf(" file:    %s\n", editfile[0] ? editfile : "(none)");
  7335.         }
  7336.         printf("\n");
  7337.         break;
  7338.  
  7339. #ifdef BROWSER
  7340.       case SHBROWSE:
  7341.         if (!browser[0]) {
  7342.             s = getenv("BROWSER");
  7343.             if (s) ckstrncpy(browser,s,CKMAXPATH);
  7344.         }
  7345.         printf("\n browser: %s\n", browser[0] ? browser : "(none)");
  7346.         if (browser[0]) {
  7347.             printf(" options: %s\n", browsopts[0] ? browsopts : "(none)");
  7348.             printf(" url:     %s\n", browsurl[0] ? browsurl : "(none)");
  7349.         }
  7350.         printf("\n");
  7351.         break;
  7352. #endif /* BROWSER */
  7353. #endif /*  NOFRILLS */
  7354. #endif /* NOPUSH */
  7355.  
  7356. #ifndef NOLOCAL
  7357. #ifdef CK_TAPI
  7358.       case SHTAPI:                      /* TAPI options */
  7359. #ifdef IKSD
  7360.         if (inserver) {
  7361.             printf("Sorry, command disabled.\r\n");
  7362.             return(success = 0);
  7363.         }
  7364. #endif /* IKSD */
  7365.         shotapi(0);
  7366.         break;
  7367.       case SHTAPI_L:                    /* TAPI Locations */
  7368. #ifdef IKSD
  7369.         if (inserver) {
  7370.             printf("Sorry, command disabled.\r\n");
  7371.             return(success = 0);
  7372.         }
  7373. #endif /* IKSD */
  7374.         shotapi(1);
  7375.         break;
  7376.       case SHTAPI_M:                    /* TAPI Modem */
  7377. #ifdef IKSD
  7378.         if (inserver) {
  7379.             printf("Sorry, command disabled.\r\n");
  7380.             return(success = 0);
  7381.         }
  7382. #endif /* IKSD */
  7383.         shotapi(2);
  7384.         break;
  7385.       case SHTAPI_C:                    /* TAPI Comm */
  7386. #ifdef IKSD
  7387.         if (inserver) {
  7388.             printf("Sorry, command disabled.\r\n");
  7389.             return(success = 0);
  7390.         }
  7391. #endif /* IKSD */
  7392.         shotapi(3);
  7393.         break;
  7394. #endif /* CK_TAPI */
  7395.  
  7396.       case SHTCP:                       /* SHOTCP */
  7397.         printf("\n");
  7398.         shotcp(0);
  7399.         printf("\n");
  7400.         break;
  7401.  
  7402. #ifdef TNCODE
  7403.       case SHTEL:                       /* TELNET */
  7404.         printf("\n");
  7405.         shotel(0);
  7406.         printf("\n");
  7407.         break;
  7408.  
  7409.       case SHTOPT:                      /* TELNET OPTIONS */
  7410.         printf("\n");
  7411.         shotopt(0);
  7412.         printf("\n");
  7413.         break;
  7414. #endif /* TNCODE */
  7415.  
  7416. #ifdef CK_TRIGGER
  7417.       case SHTRIG: {
  7418.           extern char * tt_trigger[], * triggerval;
  7419.           int i;
  7420.           if (!tt_trigger[0]) {
  7421.               printf(" Triggers: (none)\n");
  7422.           } else {
  7423.               printf(" Triggers:\n");
  7424.               for (i = 0; i < TRIGGERS; i++) {
  7425.                   if (!tt_trigger[i])
  7426.                     break;
  7427.                   printf("  \"%s\"\n",tt_trigger[i]);
  7428.               }
  7429.               printf(" Most recent trigger encountered: ");
  7430.               if (triggerval)
  7431.                 printf("\"%s\"\n",triggerval);
  7432.               else
  7433.                 printf("(none)\n");
  7434.           }
  7435.           break;
  7436.       }
  7437. #endif /* CK_TRIGGER */
  7438. #endif /* NOLOCAL */
  7439.  
  7440. #ifndef NOSPL
  7441.       case SHINP:
  7442.         shoinput();
  7443.         break;
  7444. #endif /* NOSPL */
  7445.  
  7446.       case SHLOG: {
  7447. #ifndef MAC
  7448. #ifdef IKSD
  7449.           if (inserver &&
  7450. #ifdef CK_LOGIN
  7451.               isguest
  7452. #else /* CK_LOGIN */
  7453.               0
  7454. #endif /* CK_LOGIN */
  7455.              ) {
  7456.             printf("Sorry, command disabled.\r\n");
  7457.             return(success = 0);
  7458.         }
  7459. #endif /* IKSD */
  7460. #ifdef DEBUG
  7461.           printf("\n Debug log:       %s\n", deblog ? debfil : "(none)");
  7462. #endif /* DEBUG */
  7463. #ifndef NOXFER
  7464.           printf(" Packet log:      %s\n",   pktlog ? pktfil : "(none)");
  7465. #endif /* NOXFER */
  7466. #ifndef NOLOCAL
  7467.           printf(" Session log:     %s\n",   seslog ? sesfil : "(none)");
  7468. #endif /* NOLOCAL */
  7469. #ifdef TLOG
  7470.           printf(" Transaction log: %s (%s)\n",
  7471.                  (tralog ? (*trafil ? trafil : "(none)") : "(none)"),
  7472.                  (tlogfmt ? ((tlogfmt == 2) ? "ftp" : "verbose") : "brief")
  7473.                  );
  7474. #endif /* TLOG */
  7475. #ifdef CKLOGDIAL
  7476.             printf(" Connection log:  %s\n", dialog ? diafil : "(none)");
  7477. #endif /* CKLOGDIAL */
  7478.           printf("\n");
  7479. #endif /* MAC */
  7480.           break;
  7481.       }
  7482.  
  7483. #ifndef NOSPL
  7484.       case SHOUTP:                      /* OUTPUT */
  7485.         shooutput();
  7486.         break;
  7487. #endif /* NOSPL */
  7488.  
  7489. #ifdef PATTERNS
  7490.       case SHOPAT:                      /* PATTERNS */
  7491.         shopat();
  7492.         break;
  7493. #endif /* PATTERNS */
  7494.  
  7495. #ifdef STREAMING
  7496.       case SHOSTR: {                    /* STREAMING */
  7497.           extern int streamrq, clearrq, cleared;
  7498.           extern long tfcps;
  7499.           debug(F101,"SHOW RELIABLE reliable","",reliable);
  7500.           printf("\n Reliable:     %s\n",showooa(reliable));
  7501.           printf(" Clearchannel: %s\n",showooa(clearrq));
  7502.           printf(" Streaming:    %s\n\n",showooa(streamrq));
  7503.           if ((!local && (streamrq == SET_ON)) ||
  7504.               (streamrq == SET_AUTO && reliable))
  7505.             printf(" Streaming will be done if requested.\n");
  7506.           else if ((streamrq == SET_OFF) ||
  7507.                    ((streamrq == SET_AUTO) && !reliable))
  7508.             printf(" Streaming will not be requested and will not be done.\n");
  7509.           else if ((streamrq == SET_ON) ||
  7510.                    ((streamrq == SET_AUTO) && reliable))
  7511.             printf(
  7512. " Streaming will be requested and will be done if the other Kermit agrees.\n");
  7513.           printf(" Last transfer: %sstreaming%s, %ld cps.\n",
  7514.                  streamed > 0 ? "" : "no ",
  7515.                  cleared ? ", clearchannel" : "",
  7516.                  tfcps
  7517.                  );
  7518.           printf("\n");
  7519.           break;
  7520.       }
  7521. #endif /* STREAMING */
  7522.  
  7523.       case SHOIKS:
  7524.         return(sho_iks());
  7525.         break;
  7526.  
  7527. #ifdef CK_AUTHENTICATION
  7528.       case SHOAUTH:
  7529.         return(sho_auth(0));
  7530. #endif /* CK_AUTHENTICATION */
  7531.  
  7532. #ifndef NOFTP
  7533.       case SHOFTP: {
  7534. #ifdef IKSD
  7535.         if (inserver) {
  7536.             printf("Sorry, command disabled.\r\n");
  7537.             return(success = 0);
  7538.         }
  7539. #endif /* IKSD */
  7540. #ifdef SYSFTP
  7541.         {
  7542.             extern char ftpapp[], ftpopts[];
  7543.             printf(" ftp-client:  %s\n", ftpapp[0] ? ftpapp : "(none)");
  7544.             if (ftpapp[0])
  7545.               printf(" ftp options: %s\n", ftpopts[0] ? ftpopts : "(none)");
  7546.         }
  7547. #else
  7548. #ifdef NEWFTP
  7549.         shoftp(0);
  7550. #else
  7551.         printf("(No FTP client included in this version of Kermit.)\n");
  7552. #endif /* NEWFTP */
  7553. #endif /* SYSFTP */
  7554.         break;
  7555.       }
  7556. #endif /* NOFTP */
  7557.  
  7558. #ifndef NOCMDL
  7559.       case SHXOPT: {
  7560. #ifdef IKSDB
  7561.           extern int dbenabled;
  7562.           extern char * dbfile, * dbdir;
  7563. #endif /* IKSDB */
  7564. #ifdef CKWTMP
  7565.           extern int ckxwtmp;
  7566.           extern char * wtmpfile;
  7567. #endif /* CKWTMP */
  7568. #ifdef CK_LOGIN
  7569.           extern int ckxanon, xferlog, logintimo;
  7570.           extern char * xferfile;
  7571. #ifdef UNIX
  7572.           extern int ckxpriv;
  7573. #endif /* UNIX */
  7574. #ifdef CK_PERMS
  7575.           extern int ckxperms;
  7576. #endif /* CK_PERMS */
  7577. #endif /* CK_LOGIN */
  7578.           extern char * bannerfile, * helpfile;
  7579.  
  7580. #ifdef IKSD
  7581.           if (inserver &&
  7582. #ifdef CK_LOGIN
  7583.               isguest
  7584. #else /* CK_LOGIN */
  7585.               0
  7586. #endif /* CK_LOGIN */
  7587.               ) {
  7588.               printf("Sorry, command disabled.\r\n");
  7589.               return(success = 0);
  7590.           }
  7591. #endif /* IKSD */
  7592.           printf("\n");
  7593.           if (!cmdint)
  7594.             printf(" --nointerrupts\n");
  7595.           printf(" --bannerfile=%s\n",bannerfile ? bannerfile : "(null)");
  7596.           printf(" --cdfile:%s\n",cdmsgstr ? cdmsgstr : "(null)");
  7597.           printf(" --cdmessage:%d\n",srvcdmsg);
  7598.           printf(" --helpfile:%d\n",helpfile);
  7599.           if (inserver) {
  7600.               printf("\n");
  7601.               break;
  7602.           }
  7603. #ifdef CKSYSLOG
  7604. #ifdef SYSLOGLEVEL
  7605.           printf(" --syslog:%d (forced)\n",ckxsyslog);
  7606. #else
  7607.           printf(" --syslog:%d\n",ckxsyslog);
  7608. #endif /* SYSLOGLEVEL */
  7609. #endif /* CKSYSLOG */
  7610. #ifdef CKWTMP
  7611.           printf(" --wtmplog:%d\n",ckxwtmp);
  7612.           printf(" --wtmpfile=%s\n",wtmpfile ? wtmpfile : "(null)");
  7613. #endif /* CKWTMP */
  7614. #ifdef IKSD
  7615. #ifdef CK_LOGIN
  7616.           printf(" --anonymous:%d\n",ckxanon);
  7617. #ifdef UNIX
  7618.           printf(" --privid:%d\n",ckxpriv);
  7619. #endif /* UNIX */
  7620. #ifdef CK_PERMS
  7621.           printf(" --permission:%04o\n",ckxperms);
  7622. #endif /* CK_PERMS */
  7623.           printf(" --initfile:%s\n",anonfile ? anonfile : "(null)");
  7624.           printf(" --userfile:%s\n",userfile ? userfile : "(null)");
  7625.           printf(" --root:%s\n",anonroot ? anonroot : "(null)");
  7626.           printf(" --xferlog=%d\n",xferlog);
  7627.           printf(" --xferfile=%s\n",xferfile ? xferfile : "(null)");
  7628.           printf(" --timeout=%d\n",logintimo);
  7629. #endif /* CK_LOGIN */
  7630. #ifdef IKSDB
  7631.           printf(" --database=%d\n",dbenabled);
  7632.           printf(" --dbfile=%s\n",dbfile ? dbfile : "(null)");
  7633.           if (dbdir)
  7634.             printf("   (db directory=[%s])\n",dbdir);
  7635. #endif /* IKSDB */
  7636. #ifdef IKSDCONF
  7637.           printf(" IKSD conf=%s\n",iksdconf);
  7638. #endif /* IKSDCONF */
  7639. #endif /* IKSD */
  7640.           printf("\n");
  7641.           break;
  7642.       }
  7643. #endif /* NOCMDL */
  7644.  
  7645.       case SHCD: {
  7646.       extern char * myhome;
  7647.       s = getenv("CDPATH");
  7648.       if (!s) s = "(none)";
  7649.       printf("\n current directory:  %s\n", zgtdir());
  7650.       printf(" previous directory: %s\n", prevdir ? prevdir : "(none)");
  7651.       printf(" cd home:            %s\n", homepath());
  7652.       printf(" cd path:            %s\n", ckcdpath ? ckcdpath : s);
  7653.       printf(" cd message:         %s\n", showoff(srvcdmsg & 2));
  7654.       printf(" server cd-message:  %s\n", showoff(srvcdmsg & 1));
  7655.       printf(" cd message file:    %s\n\n",cdmsgstr ? cdmsgstr : "(none)");
  7656.       break;
  7657.       }
  7658. #ifndef NOCSETS
  7659.       case SHASSOC:
  7660.         (VOID) showassoc();
  7661.         break;
  7662. #endif /* NOCSETS */
  7663.  
  7664. #ifdef CKLOGDIAL
  7665.       case SHCONNX:
  7666. #ifdef NEWFTP
  7667.         if (ftpisconnected()) {
  7668.             extern char cxlogbuf[];
  7669.             dologshow(W_FTP | 1);
  7670.             if (cxlogbuf[0])
  7671.               dologshow(1);
  7672.         } else {
  7673. #endif /* NEWFTP */
  7674.             dologshow(1);
  7675. #ifdef NEWFTP
  7676.         }
  7677. #endif /* NEWFTP */
  7678.         break;
  7679. #endif /* CKLOGDIAL */
  7680.  
  7681.       case SHOPTS:
  7682.         optlines = 0;
  7683. #ifndef NOFRILLS
  7684.         (VOID) showdelopts();
  7685. #endif /* NOFRILLS */
  7686. #ifdef DOMYDIR
  7687.         (VOID) showdiropts();
  7688. #endif /* DOMYDIR */
  7689. #ifdef CKPURGE
  7690.         (VOID) showpurgopts();
  7691. #endif /* CKPURGE */
  7692.         (VOID) showtypopts();
  7693.         break;
  7694.  
  7695. #ifndef NOLOCAL
  7696.       case SHOFLO:
  7697.         (VOID) shoflow();
  7698.         break;
  7699. #endif /* NOLOCAL */
  7700.  
  7701. #ifndef NOXFER
  7702.       case SHOXFER:
  7703.         (VOID) shoxfer();
  7704.         break;
  7705. #endif /* NOXFER */
  7706.  
  7707. #ifdef CK_RECALL
  7708.       case SHHISTORY:
  7709.         (VOID) cmhistory();
  7710.         break;
  7711. #endif /* CK_RECALL */
  7712.  
  7713. #ifndef NOSEXP
  7714. #ifndef NOSPL
  7715.       case SHSEXP:
  7716.         (VOID) shosexp();
  7717.         break;
  7718. #endif /* NOSPL */
  7719. #endif /* NOSEXP */
  7720.  
  7721. #ifdef ANYSSH
  7722.       case SHOSSH:
  7723.         (VOID) shossh();
  7724.         break;
  7725. #endif /* ANYSSH */
  7726.  
  7727. #ifdef KUI
  7728.       case SHOGUI:
  7729.         (VOID) shogui();
  7730.         break;
  7731. #endif /* KUI */
  7732.  
  7733.       default:
  7734.         printf("\nNothing to show...\n");
  7735.         return(-2);
  7736.     }
  7737.     return(success = 1);
  7738. }
  7739.  
  7740. #ifndef NOXFER
  7741. int
  7742. shoatt() {
  7743.     printf("Attributes: %s\n", showoff(atcapr));
  7744.     if (!atcapr) return(0);
  7745.     printf(" Blocksize: %s\n", showoff(atblki));
  7746.     printf(" Date: %s\n", showoff(atdati));
  7747.     printf(" Disposition: %s\n", showoff(atdisi));
  7748.     printf(" Encoding (Character Set): %s\n", showoff(atenci));
  7749.     printf(" Length: %s\n", showoff(atleni));
  7750.     printf(" Type (text/binary): %s\n", showoff(attypi));
  7751.     printf(" System ID: %s\n", showoff(atsidi));
  7752.     printf(" System Info: %s\n", showoff(atsysi));
  7753. #ifdef CK_PERMS
  7754.     printf(" Permissions In:  %s\n", showoff(atlpri));
  7755.     printf(" Permissions Out: %s\n", showoff(atlpro));
  7756. #endif /* CK_PERMS */
  7757. #ifdef STRATUS
  7758.     printf(" Format: %s\n", showoff(atfrmi));
  7759.     printf(" Creator: %s\n", showoff(atcrei));
  7760.     printf(" Account: %s\n", showoff(atacti));
  7761. #endif /* STRATUS */
  7762.     return(0);
  7763. }
  7764. #endif /* NOXFER */
  7765.  
  7766. #ifndef NOSPL
  7767. int                                     /* SHOW MACROS */
  7768. shomac(s1, s2) char *s1, *s2; {
  7769.     int x, n, pp;
  7770.     pp = 0;                             /* Parenthesis counter */
  7771.  
  7772.     debug(F110,"shomac s1",s1,0);
  7773.     debug(F110,"shomac s2",s2,0);
  7774.  
  7775. #ifdef IKSD
  7776.     if ( inserver &&
  7777. #ifdef IKSDCONF
  7778.         iksdcf
  7779. #else /* IKSDCONF */
  7780.         1
  7781. #endif /* IKSDCONF */
  7782.         ) {
  7783.         if (!ckstrcmp("on_exit",s1,-1,0) ||
  7784.             !ckstrcmp("on_logout",s1,-1,0))
  7785.           return(0);
  7786.     }
  7787. #endif /* IKSD */
  7788.  
  7789.     if (!s1)
  7790.       return(0);
  7791.     else
  7792.       printf("%s = ",s1);               /* Print blank line and macro name */
  7793.     n = (int)strlen(s1) + 4;            /* Width of current line */
  7794.     if (!s2) s2 = "(not defined)";
  7795.  
  7796.     while ((x = *s2++)) {               /* Loop thru definition */
  7797.         if (x == '(') pp++;             /* Treat commas within parens */
  7798.         if (x == ')') pp--;             /* as ordinary text */
  7799.         if (pp < 0) pp = 0;             /* Outside parens, */
  7800.         if (x == ',' && pp == 0) {      /* comma becomes comma-dash-NL. */
  7801.             putchar(',');
  7802.             putchar('-');
  7803.             x = '\n';
  7804.         }
  7805.         if (inserver && (x == '\n'))    /* Send CR before LF */
  7806.           putchar(CR);
  7807.         putchar((CHAR)x);               /* Output the character */
  7808.         if (x == '\n') {                /* If it was a newline */
  7809. #ifdef UNIX
  7810. #ifdef NOSETBUF
  7811.             fflush(stdout);
  7812. #endif /* NOSETBUF */
  7813. #endif /* UNIX */
  7814.             putchar(' ');               /* Indent the next line 1 space */
  7815.             while(*s2 == ' ') s2++;     /* skip past leading blanks */
  7816.             n = 2;                      /* restart the character counter */
  7817.             slc++;                      /* and increment the line counter. */
  7818.         } else if (++n > (cmd_cols - 1)) { /* If line is too wide */
  7819.             putchar('-');               /* output a dash */
  7820.             if (inserver)
  7821.               putchar(CR);              /* and a carriage return */
  7822.             putchar(NL);                /* and a newline */
  7823. #ifdef UNIX
  7824. #ifdef NOSETBUF
  7825.             fflush(stdout);
  7826. #endif /* NOSETBUF */
  7827. #endif /* UNIX */
  7828.             n = 1;                      /* and restart the char counter */
  7829.             slc++;                      /* and increment the line counter */
  7830.         }
  7831.         if (n < 3 && slc > (cmd_rows - 3)) { /* If new line and screen full */
  7832.             if (!askmore()) return(-1); /* ask if they want more. */
  7833.             n = 1;                      /* They do, start a new line */
  7834.             slc = 0;                    /* and restart line counter */
  7835.         }
  7836.     }
  7837.     if (inserver)
  7838.       putchar(CR);
  7839.     putchar(NL);                        /* End of definition */
  7840.     if (++slc > (cmd_rows - 3)) {
  7841.         if (!askmore()) return(-1);
  7842.         slc = 0;
  7843.     }
  7844.     return(0);
  7845. }
  7846. #endif /* NOSPL */
  7847. #endif /* NOSHOW */
  7848.  
  7849. int x_ifnum = 0;                        /* Flag for IF NUMERIC active */
  7850.  
  7851. #ifndef NOSPL
  7852. /* Evaluate an arithmetic expression. */
  7853. /* Code adapted from ev, by Howie Kaye of Columbia U & others. */
  7854.  
  7855. static int xerror = 0;
  7856. int divbyzero = 0;
  7857. static char *cp;
  7858. static long tokval;
  7859. static char curtok;
  7860. static long expval;
  7861.  
  7862. #define LONGBITS (8*sizeof (long))
  7863. #define NUMBER 'N'
  7864. #define N_EOT 'E'
  7865.  
  7866. /*
  7867.  Replacement for strchr() and index(), neither of which seem to be universal.
  7868. */
  7869.  
  7870. static char *
  7871. #ifdef CK_ANSIC
  7872. windex(char * s, char c)
  7873. #else
  7874. windex(s,c) char *s, c;
  7875. #endif /* CK_ANSIC */
  7876. /* windex */ {
  7877.     while (*s != NUL && *s != c) s++;
  7878.     if (*s == c) return(s); else return(NULL);
  7879. }
  7880.  
  7881.  
  7882. /*
  7883.  g e t t o k
  7884.  
  7885.  Returns the next token.  If token is a NUMBER, sets tokval appropriately.
  7886. */
  7887. static char
  7888. gettok() {
  7889.     char tbuf[80] /* ,*tp */ ;          /* Buffer to accumulate number */
  7890.  
  7891.     while (isspace(*cp))                /* Skip past leading spaces */
  7892.       cp++;
  7893.  
  7894.     debug(F110,"GETTOK",cp,0);
  7895.  
  7896.     switch (*cp) {
  7897.       case '$':                         /* ??? */
  7898.       case '+':                         /* Add */
  7899.       case '-':                         /* Subtract or Negate */
  7900.       case '@':                         /* Greatest Common Divisor */
  7901.       case '*':                         /* Multiply */
  7902.       case '/':                         /* Divide */
  7903.       case '%':                         /* Modulus */
  7904.       case '<':                         /* Left shift */
  7905.       case '>':                         /* Right shift */
  7906.       case '&':                         /* And */
  7907.       case '|':                         /* Or */
  7908.       case '#':                         /* Exclusive Or */
  7909.       case '~':                         /* Not */
  7910.       case '^':                         /* Exponent */
  7911.       case '!':                         /* Factorial */
  7912.       case '(':                         /* Parens for grouping */
  7913.       case ')': return(*cp++);          /* operator, just return it */
  7914.       case '\n':
  7915.       case '\0': return(N_EOT);         /* End of line, return that */
  7916.     }
  7917. #ifdef COMMENT
  7918. /* This is the original code, which allows only integer numbers. */
  7919.  
  7920.     if (isxdigit(*cp)) {                /* Digit, must be a number */
  7921.         int radix = 10;                 /* Default radix */
  7922.         for (tp = tbuf; isxdigit(*cp); cp++)
  7923.           *tp++ = (char) (isupper(*cp) ? tolower(*cp) : *cp);
  7924.         *tp = '\0';                     /* End number */
  7925.         switch(isupper(*cp) ? tolower(*cp) : *cp) { /* Examine break char */
  7926.           case 'h':
  7927.           case 'x': radix = 16; cp++; break; /* if radix signifier... */
  7928.           case 'o':
  7929.           case 'q': radix = 8; cp++; break;
  7930.           case 't': radix = 2; cp++; break;
  7931.         }
  7932.         for (tp = tbuf, tokval = 0; *tp != '\0'; tp++)  {
  7933.             int dig;
  7934.             dig = *tp - '0';            /* Convert number */
  7935.             if (dig > 10) dig -= 'a'-'0'-10;
  7936.             if (dig >= radix) {
  7937.                 if (cmdlvl == 0 && !x_ifnum && !xerror)
  7938.                   printf("?Invalid digit '%c' in number\n",*tp);
  7939.                 xerror = 1;
  7940.                 return(NUMBER);
  7941.             }
  7942.             tokval = radix*tokval + dig;
  7943.         }
  7944.         return(NUMBER);
  7945.     }
  7946.     if (cmdlvl == 0 && !x_ifnum && !xerror)
  7947.       printf("Invalid character '%c' in input\n",*cp);
  7948.     xerror = 1;
  7949.     cp++;
  7950.     return(gettok());
  7951. #else
  7952. /* This code allows non-numbers to be treated as macro names */
  7953.     {
  7954.         int i, x;
  7955.         char * s, * cp1;
  7956.         cp1 = cp;
  7957.         tp = tbuf;
  7958.         for (i = 0; i < 80; i++) {
  7959.             /* Look ahead to next break character */
  7960.             /* pretty much anything that is not in the switch() above. */
  7961.             if (isalpha(*cp) || isdigit(*cp) ||
  7962.                 *cp == '_' || *cp == ':' || *cp == '.' ||
  7963.                 *cp == '[' || *cp == ']' ||
  7964.                 *cp == '{' || *cp == '}'
  7965.                 )
  7966.               tbuf[i] = *cp++;
  7967.             else
  7968.               break;
  7969.         }
  7970.         if (i >= 80) {
  7971.             printf("Too long - \"%s\"\n", cp1);
  7972.             xerror = 1;
  7973.             cp++;
  7974.             return(gettok());
  7975.         }
  7976.         if (xerror) return(NUMBER);
  7977.  
  7978.         tbuf[i] = NUL;
  7979.         s = tbuf;
  7980.         if (!isdigit(tbuf[0])) {
  7981.             char * s2 = NULL;
  7982.             x = mxlook(mactab,tbuf,nmac);
  7983.             debug(F111,"gettok mxlook",tbuf,x);
  7984.             if (x < 0) {
  7985.                 if (cmdlvl == 0 && !x_ifnum && !xerror)
  7986.                   printf("Bad number - \"%s\"\n",tbuf);
  7987.                 xerror = 1;
  7988.                 cp++;
  7989.                 return(gettok());
  7990.             }
  7991.             s2 = mactab[x].mval;
  7992.             if (!s2) s2 = "";
  7993.             if (*s2) s = s2;
  7994.         }
  7995. #ifdef CKFLOAT
  7996.         x = isfloat(s,0);
  7997. #else
  7998.         x = chknum(s);
  7999. #endif /* CKFLOAT */
  8000.         if (x > 0) {
  8001.             tokval = atoi(s);
  8002.         } else {
  8003.             if (cmdlvl == 0 && !x_ifnum && !xerror)
  8004.               printf("Bad number - \"%s\"\n",tbuf);
  8005.             xerror = 1;
  8006.             cp++;
  8007.             return(gettok());
  8008.         }
  8009.         return(NUMBER);
  8010.     }
  8011. #endif /* COMMENT */
  8012. }
  8013.  
  8014. static long
  8015. #ifdef CK_ANSIC
  8016. expon(long x, long y)
  8017. #else
  8018. expon(x,y) long x,y;
  8019. #endif /* CK_ANSIC */
  8020. /* expon */ {
  8021.     long result = 1;
  8022.     int sign = 1;
  8023.     if (y < 0) return(0);
  8024.     if (x < 0) {
  8025.         x = -x;
  8026.         if (y & 1) sign = -1;
  8027.     }
  8028.     while (y != 0) {
  8029.         if (y & 1) result *= x;
  8030.         y >>= 1;
  8031.         if (y != 0) x *= x;
  8032.   }
  8033.   return(result * sign);
  8034. }
  8035.  
  8036. /*
  8037.  * factor ::= simple | simple ^ factor
  8038.  *
  8039.  */
  8040. static VOID
  8041. factor() {
  8042.     long oldval;
  8043.     simple();
  8044.     if (curtok == '^') {
  8045.         oldval = expval;
  8046.         curtok = gettok();
  8047.         factor();
  8048.         expval = expon(oldval,expval);
  8049.     }
  8050. }
  8051.  
  8052. /*
  8053.  * termp ::= NULL | {*,/,%,&} factor termp
  8054.  *
  8055.  */
  8056. static VOID
  8057. termp() {
  8058.     while (curtok == '*' || curtok == '/' || curtok == '%' || curtok == '&') {
  8059.         long oldval;
  8060.         char op;
  8061.         op = curtok;
  8062.         curtok = gettok();              /* skip past operator */
  8063.         oldval = expval;
  8064.         factor();
  8065.         switch(op) {
  8066.           case '*': expval = oldval * expval; break;
  8067.           case '/':
  8068.           case '%':
  8069.             if (expval == 0) {
  8070.                 if (!x_ifnum)
  8071.                   printf("?Divide by zero\n");
  8072.                 xerror = 1;
  8073.                 divbyzero = 1;
  8074.                 expval = -1;
  8075.             } else
  8076.               expval = (op == '/') ? (oldval / expval) : (oldval % expval);
  8077.             break;
  8078.           case '&':
  8079.             expval = oldval & expval; break;
  8080.         }
  8081.     }
  8082. }
  8083.  
  8084. static long
  8085. #ifdef CK_ANSIC
  8086. fact(long x)
  8087. #else
  8088. fact(x) long x;
  8089. #endif /* CK_ANSIC */
  8090. /* fact */ {                            /* factorial */
  8091.     long result = 1;
  8092.     while (x > 1)
  8093.       result *= x--;
  8094.     return(result);
  8095. }
  8096.  
  8097. /*
  8098.  * term ::= factor termp
  8099.  *
  8100.  */
  8101. static VOID
  8102. term() {
  8103.     factor();
  8104.     termp();
  8105. }
  8106.  
  8107. static long
  8108. #ifdef CK_ANSIC
  8109. gcd(long x, long y)
  8110. #else
  8111. gcd(x,y) long x,y;
  8112. #endif /* CK_ANSIC */
  8113. /* gcd */ {                             /* Greatest Common Divisor */
  8114.     int nshift = 0;
  8115.     if (x < 0) x = -x;
  8116.     if (y < 0) y = -y;                  /* validate arguments */
  8117.     if (x == 0 || y == 0) return(x + y);    /* this is bogus */
  8118.  
  8119.     while (!((x & 1) | (y & 1))) {      /* get rid of powers of 2 */
  8120.         nshift++;
  8121.         x >>= 1;
  8122.         y >>= 1;
  8123.     }
  8124.     while (x != 1 && y != 1 && x != 0 && y != 0) {
  8125.         while (!(x & 1)) x >>= 1;       /* eliminate unnecessary */
  8126.         while (!(y & 1)) y >>= 1;       /* powers of 2 */
  8127.         if (x < y) {                    /* force x to be larger */
  8128.             long t;
  8129.             t = x;
  8130.             x = y;
  8131.             y = t;
  8132.         }
  8133.         x -= y;
  8134.     }
  8135.     if (x == 0 || y == 0) return((x + y) << nshift); /* gcd is non-zero one */
  8136.     else return((long) 1 << nshift);    /* else gcd is 1 */
  8137. }
  8138.  
  8139. /*
  8140.  * exprp ::= NULL | {+,-,|,...} term exprp
  8141.  *
  8142.  */
  8143. static VOID
  8144. exprp() {
  8145.     while (windex("+-|<>#@",curtok) != NULL) {
  8146.         long oldval;
  8147.         char op;
  8148.         op = curtok;
  8149.         curtok = gettok();              /* skip past operator */
  8150.         oldval = expval;
  8151.         term();
  8152.         switch(op) {
  8153.           case '+' : expval = oldval + expval; break;
  8154.           case '-' : expval = oldval - expval; break;
  8155.           case '|' : expval = oldval | expval; break;
  8156.           case '#' : expval = oldval ^ expval; break;
  8157.           case '@' : expval = gcd(oldval,expval); break;
  8158.           case '<' : expval = oldval << expval; break;
  8159.           case '>' : expval = oldval >> expval; break;
  8160.         }
  8161.     }
  8162. }
  8163.  
  8164. /*
  8165.  * expr ::= term exprp
  8166.  *
  8167.  */
  8168. static VOID
  8169. expr() {
  8170.     term();
  8171.     exprp();
  8172. }
  8173.  
  8174. static long
  8175. xparse() {
  8176.     curtok = gettok();
  8177.     expr();
  8178. #ifdef COMMENT
  8179.     if (curtok == '$') {
  8180.         curtok = gettok();
  8181.         if (curtok != NUMBER) {
  8182.             if (cmdlvl == 0 && !x_ifnum)
  8183.               printf("?Illegal radix\n");
  8184.             xerror = 1;
  8185.             return(0);
  8186.         }
  8187.         curtok = gettok();
  8188.     }
  8189. #endif /* COMMENT */
  8190.     if (curtok != N_EOT) {
  8191.         if (cmdlvl == 0 && !x_ifnum && !xerror)
  8192.           printf("?Extra characters after expression\n");
  8193.         xerror = 1;
  8194.     }
  8195.     return(expval);
  8196. }
  8197.  
  8198. char *                                  /* Silent front end for evala() */
  8199. evalx(s) char *s; {
  8200.     char * p;
  8201.     int t;
  8202.     t = x_ifnum;
  8203.     x_ifnum = 1;
  8204.     p = evala(s);
  8205.     x_ifnum = t;
  8206.     return(p);
  8207. }
  8208.  
  8209. char *
  8210. evala(s) char *s; {
  8211.     long v;                             /* Numeric value */
  8212.     if (!s) return("");
  8213.     xerror = 0;                         /* Start out with no error */
  8214.     divbyzero = 0;
  8215.     cp = s;                             /* Make the argument global */
  8216.     v = xparse();                       /* Parse the string */
  8217.     return(xerror ? "" : ckltoa(v));    /* Return empty string on error */
  8218. }
  8219.  
  8220. /*
  8221.  * simplest ::= NUMBER | ( expr )
  8222.  *
  8223.  */
  8224. static VOID
  8225. simplest() {
  8226.     char * p;
  8227.     p = cp;
  8228.     if (curtok == NUMBER)
  8229.       expval = tokval;
  8230.     else if (curtok == '(') {
  8231.         curtok = gettok();              /* skip over paren */
  8232.         expr();
  8233.         if (curtok != ')') {
  8234.             if (cmdlvl == 0 && !x_ifnum && !xerror)
  8235.               printf("?Missing right parenthesis\n");
  8236.             xerror = 1;
  8237.         }
  8238.         debug(F110,"GETTOK SIMPLEST ()",p,0);
  8239.  
  8240.     } else {
  8241.         if (cmdlvl == 0 && !x_ifnum && !xerror)
  8242.           printf("?Operator unexpected\n");
  8243.         xerror = 1;
  8244.     }
  8245.     curtok = gettok();
  8246. }
  8247.  
  8248. /*
  8249.  * simpler ::= simplest | simplest !
  8250.  *
  8251.  */
  8252. static VOID
  8253. simpler() {
  8254.     simplest();
  8255.     if (curtok == '!') {
  8256.         curtok = gettok();
  8257.         expval = fact(expval);
  8258.     }
  8259. }
  8260.  
  8261. /*
  8262.  * simple ::= {-,~,!} simpler | simpler
  8263.  *
  8264.  */
  8265.  
  8266. static VOID
  8267. simple() {
  8268.     if (curtok == '-' || curtok == '~' || curtok == '!' || curtok == '+') {
  8269.         int op = curtok;
  8270.         curtok = gettok();              /* skip over - sign */
  8271.         simpler();                      /* parse the factor again */
  8272.         if (op != '+')
  8273.           expval = (op == '-') ? -expval : ((op == '!') ? !expval : ~expval);
  8274.     } else simpler();
  8275. }
  8276.  
  8277. /*  D C L A R R A Y  --  Declare an array  */
  8278. /*
  8279.   Call with:
  8280.    char a = single character designator for the array, e.g. "a".
  8281.    int  n = size of array.
  8282.   Returns:
  8283.    0 or greater on success, having created the requested array with
  8284.      with n+1 elements, 0..n.  If an array of the same name existed
  8285.      previously, it is destroyed.  The new array has all its elements
  8286.      initialized to NULL pointers.
  8287.   -1 on failure (because 'a' out of range or malloc failure).
  8288. */
  8289. int
  8290. #ifdef CK_ANSIC
  8291. dclarray(char a, int n)
  8292. #else
  8293. dclarray(a,n) char a; int n;
  8294. #endif /* CK_ANSIC */
  8295. /* dclarray */ {
  8296.     char c, **p; int i, n2, rc;
  8297.  
  8298.     if (a > 63 && a < 91) a += 32;      /* Convert letters to lowercase */
  8299.     if (a < ARRAYBASE || a > 122)       /* Verify name */
  8300.       return(-1);
  8301.     c = a;
  8302.     a -= ARRAYBASE;                     /* Convert name to number */
  8303.     rc = a;
  8304.     if ((p = a_ptr[a]) != NULL) {       /* Delete old array of same name */
  8305.         if (a_link[a] > -1) {           /* Is it a link? */
  8306.             if (n == 0) {               /* If we're just deleting it */
  8307.                 a_ptr[a] = (char **) NULL; /* clear all the info. */
  8308.                 a_dim[a] = 0;
  8309.                 a_link[a] = -1;
  8310.                 return(0);
  8311.             }                           /* Not deleting */
  8312.             a = a_link[a];              /* Switch to linked-to array */
  8313.         }
  8314.         n2 = a_dim[a];                  /* Real array */
  8315.         for (i = 0; i <= n2; i++) {     /* First delete its elements */
  8316.             if (p[i]) {
  8317.                 free(p[i]);
  8318.                 p[i] = NULL;
  8319.             }
  8320.         }
  8321.         free((char *)a_ptr[a]);         /* Then the element list */
  8322.         if (n == 0) {                   /* If undeclaring this array... */
  8323.             for (i = 0; i < 122 - ARRAYBASE; i++) { /* Any linked arrays? */
  8324.                 if (i != a && a_link[i] == a) {     /* Find them */
  8325.                     a_ptr[i] = (char **) NULL;      /* and remove them */
  8326.                     a_dim[i] = 0;
  8327.                     a_link[i] = -1;
  8328.                 }
  8329.             }
  8330.         }
  8331.         a_ptr[a] = (char **) NULL;      /* Remove pointer to element list */
  8332.         a_dim[a] = 0;                   /* Set dimension at zero. */
  8333.         a_link[a] = -1;                 /* Unset link word */
  8334.         if (n == 0)
  8335.           return(0);                    /* If dimension 0, just deallocate. */
  8336.     }
  8337.     p = (char **) malloc((n+1) * sizeof(char **)); /* Allocate for new array */
  8338.     if (p == NULL) return(-1);          /* Check */
  8339.     a_ptr[a] = p;                       /* Save pointer to member list */
  8340.     a_dim[a] = n;                       /* Save dimension */
  8341.     for (i = 0; i <= n; i++)            /* Initialize members to null */
  8342.       p[i] = NULL;
  8343.     for (i = 0; i < (int) 'z' - ARRAYBASE; i++) { /* Any linked arrays? */
  8344.         if (i != a && a_link[i] == a) { /* Find and update them */
  8345.             a_ptr[i] = p;
  8346.             a_dim[i] = n;
  8347.         }
  8348.     }
  8349.     return(rc);
  8350. }
  8351.  
  8352. /*  X A R R A Y  -- Convert array name to array index  */
  8353.  
  8354. int
  8355. xarray(s) char * s; {
  8356.     char buf[8];
  8357.     int x;
  8358.     char c;
  8359.  
  8360.     if (!s) s = "";
  8361.     debug(F110,"xarray",s,0);
  8362.     if (!*s)
  8363.       return(-1);
  8364.     x = strlen(s);
  8365.  
  8366.     buf[0] = NUL;
  8367.     buf[1] = NUL;
  8368.     buf[2] = s[0];
  8369.     buf[3] = (x > 0) ? s[1] : NUL;
  8370.     buf[4] = (x > 1) ? s[2] : NUL;
  8371.     buf[5] = (x > 2) ? s[3] : NUL;
  8372.     buf[6] = NUL;
  8373.     s = buf+2;
  8374.     if (*s == '&') {
  8375.         buf[1] = CMDQ;
  8376.         s--;
  8377.     } else if (*s != CMDQ) {
  8378.         buf[0] = CMDQ;
  8379.         buf[1] = '&';
  8380.         s = buf;
  8381.     }
  8382.     c = *(s+2);
  8383.     if (isupper(c))
  8384.       c = tolower(c);
  8385.     if (c == '@')
  8386.       c = 96;
  8387.     x = (int)c - ARRAYBASE;
  8388.     if (*(s+3) == '[')
  8389.       *(s+3) = NUL;
  8390.     return((x < 0 || x > 'z' - ARRAYBASE || *(s+3)) ? -1 : x);
  8391. }
  8392.  
  8393. /*  A R R A Y B O U N D S  --  Parse array segment notation \&a[n:m]  */
  8394.  
  8395. /*
  8396.   Call with s = array reference, plus two pointers to ints.
  8397.   Returns -1 on error, or array index, with the two ints set as follows:
  8398.    \&a[]     -1, -1
  8399.    \&a[3]     3, -1
  8400.    \&a[3:17]  3, 17
  8401.   The array need not be declared -- this routine is just for parsing.
  8402. */
  8403. int
  8404. arraybounds(s,lo,hi) char * s; int * lo, * hi; {
  8405.     int i, x, y, range[2];
  8406.     char buf[256], * p, * q;
  8407.     char * tmp = NULL;
  8408.  
  8409.     *lo = -1;                           /* Default bounds */
  8410.     *hi = -1;
  8411.  
  8412.     if (!s) s = "";                     /* Defense de null args */
  8413.     if (!*s)
  8414.       return(-1);
  8415.  
  8416.     x = xarray(s);                      /* Check basic structure */
  8417.     debug(F111,"arraybounds xarray",s,x);
  8418.  
  8419.     if (x < 0)                          /* Not OK, fail. */
  8420.       return(-1);
  8421.     range[0] = -1;                      /* It's OK -- get contents */
  8422.     range[1] = -1;                      /* of subscript brackets */
  8423.     makestr(&tmp,s);                    /* Make a pokeable copy */
  8424.     s = tmp;
  8425.     p = s;
  8426.     for (p = s, q = NULL; *p; p++) {    /* First find the brackets */
  8427.         if (*p == '[') {
  8428.             q = p+1;
  8429.         } else if (*p == ']')
  8430.           break;
  8431.     }
  8432.     if (q && *p == ']') {               /* If we have brackets... */
  8433.         int quitnow = 0;
  8434.         for (i = 0; i < 2 && !quitnow; i++) { /* Loop thru their contents */
  8435.             for (p = q; *p; p++) {
  8436.                 if ((i == 0 && *p == ':') || *p == ']') {
  8437.                     if (*p == ']')
  8438.                       quitnow = 1;
  8439.                     *p = NUL;
  8440.                     if (*q) {           /* We have something */
  8441.                         y = 255;        /* Expand variables, etc. */
  8442.                         s = buf;
  8443.                         zzstring(q,&s,&y);
  8444.                         s = evalx(buf); /* Evaluate it arithmetically */
  8445.                         if (s) if (*s)
  8446.                           ckstrncpy(buf,s,256);
  8447.                         if (!chknum(buf)) { /* Did we get a number? */
  8448.                             makestr(&tmp,NULL); /* No, fail. */
  8449.                             return(-1);
  8450.                         }
  8451.                         q = (i == 0) ? p+1 : NULL; /* Point to next if any */
  8452.                         range[i] = atoi(buf); /* Set this one */
  8453.                     }
  8454.                     break;
  8455.                 }
  8456.             }
  8457.         }
  8458.     }
  8459.     makestr(&tmp,NULL);                 /* Free temporary poked string */
  8460.     *lo = range[0];                     /* Return what we got */
  8461.     *hi = range[1];
  8462.     debug(F101,"arraybounds lo","",*lo);
  8463.     debug(F101,"arraybounds hi","",*hi);
  8464.     return(x);
  8465. }
  8466.  
  8467. /*  A R R A Y N A M  --  Parse an array name  */
  8468.  
  8469. /*
  8470.   Call with pointer to string that starts with the array reference.
  8471.   String may begin with either \& or just &.
  8472.   On success,
  8473.     Returns letter ID (always lowercase) in argument c,
  8474.       which can also be accent grave (` = 96; '@' is converted to grave);
  8475.     Dimension or subscript in argument n;
  8476.     IMPORTANT: These arguments must be provided by the caller as addresses
  8477.     of ints (not chars), for example:
  8478.       char *s; int x, y;
  8479.       arraynam(s,&x,&y);
  8480.   On failure, returns a negative number, with args n and c set to zero.
  8481. */
  8482. int
  8483. arraynam(ss,c,n) char *ss; int *c; int *n; {
  8484.     int i, y, pp, len;
  8485.     char x;
  8486.     char *s, *p, *sx, *vnp;
  8487.     /* On stack to allow for recursive calls... */
  8488.     char vnbuf[ARRAYREFLEN+1];          /* Entire array reference */
  8489.     char ssbuf[ARRAYREFLEN+1];          /* Subscript in "plain text" */
  8490.     char sxbuf[16];                     /* Evaluated subscript */
  8491.  
  8492.     *c = *n = 0;                        /* Initialize return values */
  8493.     len = strlen(ss);
  8494.     for (pp = 0,i = 0; i < len; i++) {          /* Check length */
  8495.         if (ss[i] == '[') {
  8496.             pp++;
  8497.         } else if (ss[i] == ']') {
  8498.             if (--pp == 0)
  8499.               break;
  8500.         }
  8501.     }
  8502.     if (i > ARRAYREFLEN) {
  8503.         printf("?Array reference too long - %s\n",ss);
  8504.         return(-9);
  8505.     }
  8506.     ckstrncpy(vnbuf,ss,ARRAYREFLEN);
  8507.     vnp = vnbuf;
  8508.     if (vnbuf[0] == CMDQ && vnbuf[1] == '&') vnp++;
  8509.     if (*vnp != '&') {
  8510.         printf("?Not an array - %s\n",vnbuf);
  8511.         return(-9);
  8512.     }
  8513.     x = *(vnp + 1);                     /* Fold case of array name */
  8514.  
  8515.     /* We don't use isupper & tolower here on purpose because these */
  8516.     /* would produce undesired effects with accented letters. */
  8517.     if (x > 63 && x < 91) x  = *(vnp + 1) = (char) (x + 32);
  8518.     if ((x < ARRAYBASE) || (x > 122) || (*(vnp+2) != '[')) {
  8519.         if (msgflg) {
  8520.             printf("?Invalid format for array name - %s\n",vnbuf);
  8521.             return(-9);
  8522.         } else
  8523.           return(-2);
  8524.     }
  8525.     *c = x;                             /* Return the array name */
  8526.     s = vnp+3;                          /* Get dimension */
  8527.     p = ssbuf;
  8528.     pp = 1;                             /* Bracket counter */
  8529.     for (i = 0; i < ARRAYREFLEN && *s != NUL; i++) { /* Copy up to ] */
  8530.         if (*s == '[') pp++;
  8531.         if (*s == ']' && --pp == 0) break;
  8532.         *p++ = *s++;
  8533.     }
  8534.     if (*s != ']') {
  8535.         printf("?No closing bracket on array dimension - %s\n",vnbuf);
  8536.         return(-9);
  8537.     }
  8538.     p--;                                /* Trim whitespace from end */
  8539.     while (*p == SP || *p == HT)
  8540.       p--;
  8541.     p++;
  8542.     *p = NUL;                           /* Terminate subscript with null */
  8543.     p = ssbuf;                          /* Point to beginning of subscript */
  8544.     while (*p == SP || *p == HT)        /* Trim whitespace from beginning */
  8545.       p++;
  8546.     sx = sxbuf;                         /* Where to put expanded subscript */
  8547.     y = 16;
  8548.     zzstring(p,&sx,&y);                 /* Convert variables, etc. */
  8549.     sx = sxbuf;
  8550.     while (*sx == SP) sx++;
  8551.     debug(F110,"arraynam sx","",sx);
  8552.     if (!*sx) {                         /* Empty brackets... */
  8553.         *n = -17;                       /* (Secret code :-) */
  8554.         return(-2);
  8555.     }
  8556.     p = evala(sx);                      /* Run it thru \fneval()... */
  8557.     if (p) if (*p) ckstrncpy(sxbuf,p,16); /* We know it has to be a number. */
  8558.  
  8559.     if (!chknum(sxbuf)) {               /* Make sure it's all digits */
  8560.         if (msgflg) {
  8561.             printf("?Array dimension or subscript missing or not numeric\n");
  8562.             return(-9);
  8563.         } else
  8564.           return(-2);
  8565.     }
  8566.     if ((y = atoi(sxbuf)) < 0) {
  8567.         if (cmflgs == 0) printf("\n");
  8568.         if (msgflg) {
  8569.             printf("?Array dimension or subscript not positive or zero\n");
  8570.             return(-9);
  8571.         } else
  8572.           return(-2);
  8573.     }
  8574.     *n = y;                             /* Return the subscript or dimension */
  8575.     return(0);
  8576. }
  8577.  
  8578. int
  8579. chkarray(a,i) int a, i; {               /* Check if array is declared */
  8580.     int x;                              /* and if subscript is in range */
  8581.     if (a == 64) a = 96;                /* Convert atsign to grave accent */
  8582.     x = a - ARRAYBASE;                  /* Values must be in range 95-122 */
  8583. #ifdef COMMENT
  8584.     if (x == 0 && maclvl < 0)           /* Macro arg vector but no macro */
  8585.       return(0);
  8586. #endif /* COMMENT */
  8587.     if (x < 0 || x > 'z' - ARRAYBASE)   /* Not in range */
  8588.       return(-2);
  8589.     if (a_ptr[x] == NULL) return(-1);   /* Not declared */
  8590.     if (i > a_dim[x]) return(-2);       /* Declared but out of range. */
  8591.     return(a_dim[x]);                   /* All ok, return dimension */
  8592. }
  8593.  
  8594. #ifdef COMMENT                          /* This isn't used. */
  8595. char *
  8596. arrayval(a,i) int a, i; {               /* Return value of \&a[i] */
  8597.     int x; char **p;                    /* (possibly NULL) */
  8598.     if (a == 64) a = 96;                /* Convert atsign to grave accent */
  8599.     x = a - ARRAYBASE;                  /* Values must be in range 95-122 */
  8600.     if (x < 0 || x > 27) return(NULL);  /* Not in range */
  8601.     if ((x > 0) && (p = a_ptr[x]) == NULL) /* Array not declared */
  8602.       return(NULL);
  8603.     if (i > a_dim[x])                   /* Subscript out of range. */
  8604.       return(NULL);
  8605.     return(p[i]);                       /* All ok, return pointer to value. */
  8606. }
  8607. #endif /* COMMENT */
  8608.  
  8609. /*
  8610.   pusharray() is called when an array name is included in a LOCAL statement.
  8611.   It moves the pointers from the global definition to the stack, and removes
  8612.   the global definition.  Later, if the same array is declared in the local
  8613.   context, it occupies the global definition in the normal way.  But when
  8614.   popclvl() is called, it replaces the global definition with the one saved
  8615.   here.  The "secret code" is used to indicate to popclv() that it should
  8616.   remove the global array when popping through this level -- otherwise if a
  8617.   local array were declared that had no counterpart at any higher level, it
  8618.   would never be deleted.  This allows Algol-like inheritance to work both
  8619.   on the way down and on the way back up.
  8620. */
  8621. int
  8622. pusharray(x,z) int x, z; {
  8623.     int y;
  8624.     debug(F000,"pusharray x","",x);
  8625.     debug(F101,"pusharray z","",z);
  8626.     y = chkarray(x,z);
  8627.     debug(F101,"pusharray y","",y);
  8628.     x -= ARRAYBASE;                     /* Convert name letter to index. */
  8629.     if (x < 0 || x > 27)
  8630.       return(-1);
  8631.     if (y < 0) {
  8632.         aa_ptr[cmdlvl][x] = (char **) NULL;
  8633.         aa_dim[cmdlvl][x] = -23;        /* Secret code (see popclvl()) */
  8634.     } else {
  8635.         aa_ptr[cmdlvl][x] = a_ptr[x];
  8636.         aa_dim[cmdlvl][x] = y;
  8637.     }
  8638.     a_ptr[x] = (char **) NULL;
  8639.     a_dim[x] = 0;
  8640.     return(0);
  8641. }
  8642.  
  8643. /*  P A R S E V A R  --  Parse a variable name or array reference.  */
  8644. /*
  8645.  Call with:
  8646.    s  = pointer to candidate variable name or array reference.
  8647.    *c = address of integer in which to return variable ID.
  8648.    *i = address of integer in which to return array subscript.
  8649.  Returns:
  8650.    -2:  syntax error in variable name or array reference.
  8651.     1:  successful parse of a simple variable, with ID in c.
  8652.     2:  successful parse of an array reference, w/ID in c and subscript in i.
  8653. */
  8654. int
  8655. parsevar(s,c,i) char *s; int *c, *i; {
  8656.     char *p;
  8657.     int x,y,z;
  8658.  
  8659.     p = s;
  8660.     if (*s == CMDQ) s++;                /* Point after backslash */
  8661.  
  8662.     if (*s != '%' && *s != '&') {       /* Make sure it's % or & */
  8663.         printf("?Not a variable name - %s\n",p);
  8664.         return(-9);
  8665.     }
  8666.     if ((int)strlen(s) < 2) {
  8667.         printf("?Incomplete variable name - %s\n",p);
  8668.         return(-9);
  8669.     }
  8670.     if (*s == '%' && *(s+2) != '\0') {
  8671.         printf("?Only one character after '%%' in variable name, please\n");
  8672.         return(-9);
  8673.     }
  8674.     if (*s == '&' && *(s+2) != '[') {
  8675.         printf("?Array subscript expected - %s\n",p);
  8676.         return(-9);
  8677.     }
  8678.     if (*s == '%') {                    /* Simple variable. */
  8679.         y = *(s+1);                     /* Get variable ID letter/char */
  8680.         if (isupper(y)) y -= ('a'-'A'); /* Convert upper to lower case */
  8681.         *c = y;                         /* Set the return values. */
  8682.         *i = -1;                        /* No array subscript. */
  8683.         return(1);                      /* Return 1 = simple variable */
  8684.     }
  8685.     if (*s == '&') {                    /* Array reference. */
  8686.         y = arraynam(s,&x,&z);          /* Go parse it. */
  8687.         debug(F101,"parsevar arraynam","",y);
  8688.         if ((y) < 0) {
  8689.             if (y == -2)
  8690.               return(pusharray(x,z));
  8691.             if (y != -9)
  8692.               printf("?Invalid array reference - %s\n",p);
  8693.             return(-9);
  8694.         }
  8695.         if (chkarray(x,z) < 0) {        /* Check if declared, etc. */
  8696.             printf("?Array not declared or subscript out of range\n");
  8697.             return(-9);
  8698.         }
  8699.         *c = x;                         /* Return array letter */
  8700.         *i = z;                         /* and subscript. */
  8701.         return(2);
  8702.     }
  8703.     return(-2);                         /* None of the above. */
  8704. }
  8705.  
  8706.  
  8707. #define VALN 32
  8708.  
  8709. /* Get the numeric value of a variable */
  8710. /*
  8711.   Call with pointer to variable name, pointer to int for return value.
  8712.   Returns:
  8713.     0 on success with second arg containing the value.
  8714.    -1 on failure (bad variable syntax, variable not defined or not numeric).
  8715. */
  8716. int
  8717. varval(s,v) char *s; int *v; {
  8718.     char valbuf[VALN+1];                /* s is pointer to variable name */
  8719.     char name[256];
  8720.     char *p;
  8721.     int y;
  8722.  
  8723.     if (*s != CMDQ) {                   /* Handle macro names too */
  8724.         ckmakmsg(name,256,"\\m(",s,")",NULL);
  8725.         s = name;
  8726.     }
  8727.     p = valbuf;                         /* Expand variable into valbuf. */
  8728.     y = VALN;
  8729.     if (zzstring(s,&p,&y) < 0) return(-1);
  8730.     p = valbuf;                         /* Make sure value is numeric  */
  8731.     if (!*p) {                          /* Be nice -- let an undefined */
  8732.         valbuf[0] = '0';                /* variable be treated as 0.   */
  8733.         valbuf[1] = NUL;
  8734.     }
  8735.     if (chknum(p)) {                    /* Convert numeric string to int */
  8736.         *v = atoi(p);                   /* OK */
  8737.     } else {                            /* Not OK */
  8738.         p = evala(p);                   /* Maybe it's an expression */
  8739.         if (!chknum(p))                 /* Did it evaluate? */
  8740.           return(-1);                   /* No, failure. */
  8741.         else                            /* Yes, */
  8742.           *v = atoi(p);                 /* success */
  8743.     }
  8744.     return(0);
  8745. }
  8746.  
  8747. /* Increment or decrement a variable */
  8748. /* Returns -1 on failure, 0 on success */
  8749.  
  8750. int
  8751. incvar(s,x,z) char *s; int x; int z; {  /* Increment a numeric variable */
  8752.     int n;                              /* s is pointer to variable name */
  8753.                                         /* x is amount to increment by */
  8754.                                         /* z != 0 means add */
  8755.                                         /* z = 0 means subtract */
  8756.     if (varval(s,&n) < 0)               /* Convert numeric string to int */
  8757.       return(-1);
  8758.     if (z)                              /* Increment it by the given amount */
  8759.       n += x;
  8760.     else                                /* or decrement as requested. */
  8761.       n -= x;
  8762.     addmac(s,ckitoa(n));                /* Replace old variable */
  8763.     return(0);
  8764. }
  8765.  
  8766. /* D O D O  --  Do a macro */
  8767.  
  8768. /*
  8769.   Call with x = macro table index, s = pointer to arguments.
  8770.   Returns 0 on failure, 1 on success.
  8771. */
  8772.  
  8773. int
  8774. dodo(x,s,flags) int x; char *s; int flags; {
  8775.     int y;
  8776.     extern int tra_asg, tra_cmd; int tra_tmp;
  8777. #ifndef NOLOCAL
  8778. #ifdef OS2
  8779.     extern int term_io;
  8780.     int term_io_sav = term_io;
  8781. #endif /* OS2 */
  8782. #endif /* NOLOCAL */
  8783.  
  8784.     if (x < 0)                          /* It can happen! */
  8785.       return(-1);
  8786.  
  8787.     tra_tmp = tra_asg;
  8788.  
  8789.     if (++maclvl >= MACLEVEL) {         /* Make sure we have storage */
  8790.         debug(F101,"dodo maclvl too deep","",maclvl);
  8791.         --maclvl;
  8792.         printf("Macros nested too deeply\n");
  8793.         return(0);
  8794.     }
  8795.     macp[maclvl] = mactab[x].mval;      /* Point to the macro body */
  8796.     macx[maclvl] = mactab[x].mval;      /* Remember where the beginning is */
  8797.  
  8798. #ifdef COMMENT
  8799.     makestr(&(m_line[maclvl]),s);       /* Entire arg string for "\%*" */
  8800. #endif /* COMMENT */
  8801.  
  8802.     cmdlvl++;                           /* Entering a new command level */
  8803.     if (cmdlvl >= CMDSTKL) {            /* Too many macros + TAKE files? */
  8804.         debug(F101,"dodo cmdlvl too deep","",cmdlvl);
  8805.         cmdlvl--;
  8806.         printf("?TAKE files and DO commands nested too deeply\n");
  8807.         return(0);
  8808.     }
  8809. #ifdef DEBUG
  8810.     if (deblog) {
  8811.         debug(F111,"CMD +M",mactab[x].kwd,cmdlvl);
  8812.         debug(F010,"CMD ->",s,0);
  8813.     }
  8814. #endif /* DEBUG */
  8815.  
  8816. #ifdef VMS
  8817.     conres();                           /* So Ctrl-C, etc, will work. */
  8818. #endif /* VMS */
  8819. #ifndef NOLOCAL
  8820. #ifdef OS2
  8821.     term_io = 0;                        /* Disable terminal emulator I/O */
  8822. #endif /* OS2 */
  8823. #endif /* NOLOCAL */
  8824.     ifcmd[cmdlvl] = 0;
  8825.     iftest[cmdlvl] = 0;
  8826.     count[cmdlvl] = count[cmdlvl-1];    /* Inherit COUNT from previous level */
  8827.     intime[cmdlvl] = intime[cmdlvl-1];  /* Inherit previous INPUT TIMEOUT */
  8828.     inpcas[cmdlvl] = inpcas[cmdlvl-1];  /*   and INPUT CASE */
  8829.     takerr[cmdlvl] = takerr[cmdlvl-1];  /*   and TAKE ERROR */
  8830.     merror[cmdlvl] = merror[cmdlvl-1];  /*   and MACRO ERROR */
  8831.     xquiet[cmdlvl] = quiet;
  8832.     xcmdsrc = CMD_MD;
  8833.     cmdstk[cmdlvl].src = CMD_MD;        /* Say we're in a macro */
  8834.     cmdstk[cmdlvl].lvl = maclvl;        /* and remember the macro level */
  8835.     cmdstk[cmdlvl].ccflgs = flags & ~CF_IMAC; /* Set flags */
  8836.  
  8837.     /* Initialize return value except in FOR, WHILE, IF, and SWITCH macros */
  8838.  
  8839.     if (!(flags & CF_IMAC) && mrval[maclvl]) {
  8840.         free(mrval[maclvl]);
  8841.         mrval[maclvl] = NULL;
  8842.     }
  8843.  
  8844.     /* Clear old %0..%9 arguments */
  8845.  
  8846.     addmac("%0",mactab[x].kwd);         /* Define %0 = name of macro */
  8847.     makestr(&(m_xarg[maclvl][0]),mactab[x].kwd);
  8848.     varnam[0] = '%';
  8849.     varnam[2] = '\0';
  8850.     tra_asg = 0;
  8851.     for (y = 1; y < 10; y++) {          /* Clear args %1..%9 */
  8852.         if (m_arg[maclvl][y]) {         /* Don't call delmac() unless */
  8853.             varnam[1] = (char) (y + '0'); /* we have to... */
  8854.             delmac(varnam,0);
  8855.         }
  8856.     }
  8857.     tra_asg = tra_tmp;
  8858.  
  8859. /* Assign the new args one word per arg, allowing braces to group words */
  8860.  
  8861.     xwords(s,MAXARGLIST,NULL,0);
  8862.  
  8863. #ifndef NOLOCAL
  8864. #ifdef OS2
  8865.     term_io = term_io_sav;
  8866. #endif /* OS2 */
  8867. #endif /* NOLOCAL */
  8868.     if (tra_cmd)
  8869.       printf("[%d] +M: \"%s\"\n",cmdlvl,mactab[x].kwd);
  8870.     return(1);
  8871. }
  8872.  
  8873. /* Insert "literal" quote around each comma-separated command to prevent */
  8874. /* its premature expansion.  Only do this if object command is surrounded */
  8875. /* by braces. */
  8876.  
  8877. static char* flit = "\\flit(";
  8878.  
  8879. int
  8880. litcmd(src,dest,n) char **src, **dest; int n; {
  8881.     int bc = 0, pp = 0;
  8882.     char c, *s, *lp, *ss;
  8883.  
  8884.     s = *src;
  8885.     lp = *dest;
  8886.  
  8887.     debug(F010,"litcmd",s,0);
  8888.  
  8889.     while (*s == SP) s++;               /* Strip extra leading spaces */
  8890.  
  8891.     if (*s == '{') {                    /* Starts with brace */
  8892.         pp = 0;                         /* Paren counter */
  8893.         bc = 1;                         /* Count leading brace */
  8894.         *lp++ = *s++;                   /* Copy it */
  8895.         if (--n < 1) return(-1);        /* Check space */
  8896.         while (*s == SP) s++;           /* Strip interior leading spaces */
  8897.         ss = flit;                      /* Point to "\flit(" */
  8898.         while ((*lp++ = *ss++))         /* Copy it */
  8899.           if (--n < 1)                  /* and check space */
  8900.             return(-1);
  8901.         lp--;                           /* Back up over null */
  8902.  
  8903.         while (*s) {                    /* Go thru rest of text */
  8904.             c = *s;
  8905.             if (c == '{') bc++;         /* Count brackets */
  8906.             if (c == '(') pp++;         /* and parens */
  8907.             if (c == ')') {             /* Right parenthesis. */
  8908.                 pp--;                   /* Count it. */
  8909.                 if (pp < 0) {           /* An unbalanced right paren... */
  8910. #ifdef COMMENT
  8911. /*
  8912.   The problem here is that "\{" appears to be a quoted brace and therefore
  8913.   isn't counted; then the "}" matches an earlier opening brace, causing
  8914.   (e.g.) truncation of macros by getncm().
  8915. */
  8916.                     if (n < 5)          /* Out of space in dest buffer? */
  8917.                       return(-1);       /* If so, give up. */
  8918.                     *lp++ = CMDQ;       /* Must be quoted to prevent */
  8919.                     *lp++ = '}';        /* premature termination of */
  8920.                     *lp++ = '4';        /* \flit(...) */
  8921.                     *lp++ = '1';
  8922.                     *lp++ = '}';
  8923.                     n -= 5;
  8924. #else
  8925. /* Here we rely on the fact the \nnn never takes more than 3 digits */
  8926.                     if (n < 4)          /* Out of space in dest buffer? */
  8927.                       return(-1);       /* If so, give up. */
  8928.                     *lp++ = CMDQ;       /* Must be quoted to prevent */
  8929.                     *lp++ = '0';        /* premature termination of */
  8930.                     *lp++ = '4';        /* \flit(...) */
  8931.                     *lp++ = '1';
  8932.                     n -= 4;
  8933. #endif /* COMMENT */
  8934.                     pp++;               /* Uncount it. */
  8935.                     s++;
  8936.                     continue;
  8937.                 }
  8938.             }
  8939.             if (c == '}') {             /* Closing brace. */
  8940.                 if (--bc == 0) {        /* Final one? */
  8941.                     *lp++ = ')';        /* Add closing paren for "\flit()" */
  8942.                     if (--n < 1) return(-1);
  8943.                     *lp++ = c;
  8944.                     if (--n < 1) return(-1);
  8945.                     s++;
  8946.                     break;
  8947.                 }
  8948.             }
  8949.             *lp++ = c;                  /* General case */
  8950.             if (--n < 1) return(-1);
  8951.             s++;
  8952.         }
  8953.         *lp = NUL;
  8954.     } else {                            /* No brackets around, */
  8955.         while ((*lp++ = *s++))          /* just copy. */
  8956.           if (--n < 1)
  8957.             return(-1);
  8958.         lp--;
  8959.     }
  8960.     *src = s;                           /* Return updated source */
  8961.     *dest = lp;                         /* and destination pointers */
  8962.     if (bc)                             /* Fail if braces unbalanced */
  8963.       return(-1);
  8964.     else                                /* Otherwise succeed. */
  8965.       return(0);
  8966. }
  8967. #endif /* NOSPL */
  8968.  
  8969. /* Functions moved here from ckuusr.c to even out the module sizes... */
  8970.  
  8971. /*
  8972.   Breaks up string s -- IN PLACE! -- into a list of up to max words.
  8973.   Pointers to each word go into the array list[].
  8974.   max is the maximum number of words (pointers).
  8975.   If list is NULL, then they are added to the macro table.
  8976.   flag = 0 means the last field is to be one word, like all the other fields,
  8977.          so anything after it is discarded.
  8978.   flag = 1 means the last field extends to the end of the string, even if
  8979.          there are lots of words left, so the last field contains the
  8980.          remainder of the string.
  8981. */
  8982. VOID
  8983. xwords(s,max,list,flag) char *s; int max; char *list[]; int flag; {
  8984.     char *p;
  8985.     int b, i, k, q, y, z;
  8986. #ifndef NOSPL
  8987.     int macro;
  8988.     macro = (list == NULL);
  8989.     debug(F010,"xwords",s,0);
  8990. #endif /* NOSPL */
  8991.  
  8992. #ifdef XWORDSDEBUG
  8993.     printf("XWORDS string=%s\n",s);
  8994.     printf("XWORDS max=%d\n",max);
  8995. #endif /* XWORDSDEBUG */
  8996.     p = s;                              /* Pointer to beginning of string */
  8997.     q = 0;                              /* Flag for doublequote removal */
  8998.     b = 0;                              /* Flag for outer brace removal */
  8999.     k = 0;                              /* Flag for in-word */
  9000.     y = 0;                              /* Brace nesting level */
  9001.     z = 0;                              /* "Word" counter, 0 thru max */
  9002.  
  9003.     if (list)
  9004.       for (i = 0; i <= max; i++)        /* Initialize pointers */
  9005.         list[i] = NULL;
  9006.  
  9007.     if (flag) max--;
  9008.  
  9009.     while (1) {                         /* Go thru word list */
  9010.         if (!s || (*s == '\0')) {       /* No more characters? */
  9011.             if (k != 0) {               /* Was I in a word? */
  9012.                 if (z == max) break;    /* Yes, only go up to max. */
  9013.                 z++;                    /* Count this word. */
  9014. #ifdef XWORDSDEBUG
  9015.                 printf("1 z++ = %d\n", z);
  9016. #endif /* XWORDSDEBUG */
  9017. #ifndef NOSPL
  9018.                 if (macro) {            /* Doing macro args */
  9019.                     if (z < 10) {
  9020.                         varnam[1] = (char) (z + '0'); /* Assign last arg */
  9021.                         addmac(varnam,p);
  9022.                     }
  9023.                     if (z <= max) {
  9024. #ifdef COMMENT
  9025.                         if (maclvl < 0)
  9026.                           addmac(varnam,p);
  9027.                         else
  9028. #endif /* COMMENT */
  9029.                           makestr(&(m_xarg[maclvl][z]),p);
  9030.                     }
  9031.                 } else {                /* Not doing macro args */
  9032. #endif /* NOSPL */
  9033.                     list[z] = p;        /* Assign pointer. */
  9034. #ifdef XWORDSDEBUG
  9035.                     printf("[1]LIST[%d]=\"%s\"\n",z,list[z]);
  9036. #endif /* XWORDSDEBUG */
  9037. #ifndef NOSPL
  9038.                 }
  9039. #endif /* NOSPL */
  9040.                 break;                  /* And get out. */
  9041.             } else break;               /* Was not in a word */
  9042.         }
  9043.         if (k == 0 && (*s == SP || *s == HT)) { /* Eat leading blanks */
  9044.             s++;
  9045.             continue;
  9046.         } else if (q == 0 && *s == '{') { /* An opening brace */
  9047.             if (k == 0 && y == 0) {     /* If leading brace */
  9048.                 p = s+1;                /* point past it */
  9049.                 b = 1;                  /* and flag that we did this */
  9050.             }
  9051.             k = 1;                      /* Flag that we're in a word */
  9052.             y++;                        /* Count the brace. */
  9053.         } else if (q == 0 && *s == '}') { /* A closing brace. */
  9054.             y--;                        /* Count it. */
  9055.             if (y <= 0 && b != 0) {     /* If it matches the leading brace */
  9056.                 char c;
  9057.                 c = *(s+1);
  9058.                 if (!c || c == SP || c == HT) { /* at EOL or followed by SP */
  9059.                     *s = SP;            /* change it to a space */
  9060.                     b = 0;              /* and we're not in braces any more */
  9061.                 }
  9062.             }
  9063. #ifdef DOUBLEQUOTING
  9064.         /* Opening doublequote */
  9065.         } else if (k == 0 && b == 0 && *s == '"' && dblquo) {
  9066.             y++;
  9067.             p = s+1;                    /* point past it */
  9068.             q = 1;                      /* and flag that we did this */
  9069.             k = 1;                      /* Flag that we're in a word */
  9070.         /* Closing double quote */
  9071.         } else if (q > 0 && k > 0 && b == 0 && *s == '"' && dblquo) {
  9072.             char c;
  9073.             c = *(s+1);
  9074.             if (!c || c == SP || c == HT) { /* at EOL or followed by SP */
  9075.                 y--;
  9076.                 *s = SP;                /* change it to a space */
  9077.                 q = 0;                  /* and we're not in quotes any more */
  9078.             }
  9079. #endif /* DOUBLEQUOTING */
  9080.  
  9081.         } else if (*s != SP && *s != HT) { /* Nonspace means we're in a word */
  9082.             if (k == 0) {               /* If we weren't in a word before, */
  9083.                 p = s;                  /* Mark the beginning */
  9084.                 if (flag && z == max) { /* Want last word to be remainder? */
  9085.                     z++;
  9086. #ifdef XWORDSDEBUG
  9087.                     printf("1 z++ = %d\n", z);
  9088. #endif /* XWORDSDEBUG */
  9089.                     list[z] = p;        /* Yes, point to it */
  9090. #ifdef XWORDSDEBUG
  9091.                     printf("[4]LIST[%d]=\"%s\"\n",z,list[z]);
  9092. #endif /* XWORDSDEBUG */
  9093.                     break;              /* and quit */
  9094.                 }
  9095.                 k = 1;                  /* Set in-word flag */
  9096.             }
  9097.         }
  9098.         /* If we're not inside a braced quantity, and we are in a word, and */
  9099.         /* we have hit whitespace, then we have a word. */
  9100.         if ((y < 1) && (k != 0) && (*s == SP || *s == HT) && !b) {
  9101.             if (!flag || z < max)       /* if we don't want to keep rest */
  9102.               *s = '\0';                /* terminate the arg with null */
  9103.             k = 0;                      /* say we're not in a word any more */
  9104.             y = 0;                      /* start braces off clean again */
  9105.             if (z == max) break;        /* Only go up to max. */
  9106.             z++;                        /* count this arg */
  9107. #ifdef XWORDSDEBUG
  9108.             printf("1 z++ = %d\n", z);
  9109. #endif /* XWORDSDEBUG */
  9110.  
  9111. #ifndef NOSPL
  9112.             if (macro) {
  9113.                 if (z < 10) {
  9114.                     varnam[1] = (char) (z + '0'); /* compute its name */
  9115.                     addmac(varnam,p);   /* add it to the macro table */
  9116.                 }
  9117.                 if (z <= max) {
  9118. #ifdef COMMENT
  9119.                     if (maclvl < 0)
  9120.                       addmac(varnam,p);
  9121.                     else
  9122. #endif /* COMMENT */
  9123.                       makestr(&(m_xarg[maclvl][z]),p);
  9124.                 }
  9125.             } else {
  9126. #endif /* NOSPL */
  9127.                 list[z] = p;
  9128. #ifdef XWORDSDEBUG
  9129.                 printf("[2]LIST[%d]=\"%s\"\n",z,list[z]);
  9130. #endif /* XWORDSDEBUG */
  9131. #ifndef NOSPL
  9132.             }
  9133. #endif /* NOSPL */
  9134.             p = s+1;
  9135.         }
  9136.         s++;                            /* Point past this character */
  9137.     }
  9138.     if ((z == 0) && (y > 1)) {          /* Extra closing brace(s) at end */
  9139.         z++;
  9140. #ifndef NOSPL
  9141.         if (macro) {
  9142.             if (z < 10) {
  9143.                 varnam[1] = z + '0';    /* compute its name */
  9144.                 addmac(varnam,p);       /* Add rest of line to last arg */
  9145.             }
  9146.             if (z <= max) {
  9147. #ifdef COMMENT
  9148.                 if (maclvl < 0)
  9149.                   addmac(varnam,p);
  9150.                 else
  9151. #endif /* COMMENT */
  9152.                   makestr(&(m_xarg[maclvl][z]),p);
  9153.             }
  9154.         } else {
  9155. #endif /* NOSPL */
  9156.             list[z] = p;
  9157. #ifdef XWORDSDEBUG
  9158.             printf("[3]LIST[%d]=\"%s\"\n",z,list[z]);
  9159. #endif /* XWORDSDEBUG */
  9160. #ifndef NOSPL
  9161.         }
  9162. #endif /* NOSPL */
  9163.     }
  9164. #ifndef NOSPL
  9165.     if (macro) {                        /* Macro */
  9166.         if (maclvl < 0) {
  9167.             a_dim[0] = z;               /* Array dimension is one less */
  9168.             topargc = z + 1;            /* than \v(argc) */
  9169.         debug(F111,"a_dim[0]","D",a_dim[0]);
  9170.         } else {
  9171.             macargc[maclvl] = z + 1;    /* Set \v(argc) variable */
  9172.             n_xarg[maclvl] = z + 1;     /* This is the actual number */
  9173.             a_ptr[0] = m_xarg[maclvl];  /* Point \&_[] at the args */
  9174.             a_dim[0] = z;               /* And give it this dimension */
  9175.         debug(F111,"a_dim[0]","E",a_dim[0]);
  9176.         }
  9177.     }
  9178. #endif /* NOSPL */
  9179.     return;
  9180. }
  9181.  
  9182. #ifndef NOSPL
  9183.  
  9184. /*  D O S H I F T  --  Do the SHIFT Command; shift macro args left by n */
  9185.  
  9186. /*  Note: at some point let's consolidate m_arg[][] and m_xarg[][]. */
  9187.  
  9188. int
  9189. doshift(n) int n; {                     /* n = shift count */
  9190.     int i, top, level;
  9191.     char /* *s, *m, */ buf[6];          /* Buffer to build scalar names */
  9192.     char * sx = tmpbuf;
  9193.     int nx = TMPBUFSIZ;
  9194.  
  9195.     debug(F101,"SHIFT count","",n);
  9196.     debug(F101,"SHIFT topargc","",topargc);
  9197.  
  9198.     if (n < 1)                          /* Stay in range */
  9199.       return(n == 0 ? 1 : 0);
  9200.  
  9201.     level = maclvl;
  9202.     top = (level < 0) ? topargc : macargc[level];
  9203.  
  9204.     if (n >= top)
  9205.       n = top - 1;
  9206.  
  9207. #ifdef DEBUG
  9208.     if (deblog) {
  9209.         debug(F101,"SHIFT count 2","",n);
  9210.         debug(F101,"SHIFT level","",level);
  9211.         if (level > -1)
  9212.           debug(F101,"SHIFT macargc[level]","",macargc[level]);
  9213.     }
  9214. #endif /* DEBUG */
  9215.  
  9216.     buf[0] = '\\';                      /* Initialize name template */
  9217.     buf[1] = '%';
  9218.     buf[2] = NUL;
  9219.     buf[3] = NUL;
  9220.  
  9221.     for (i = 1; i <= n; i++) {          /* Free shifted-over args */
  9222.         if (level < 0) {
  9223.             makestr(&(toparg[i]),NULL);
  9224.         } else {
  9225.             makestr(&(m_xarg[level][i]),NULL);
  9226.         }
  9227.         if (i < 10) {                   /* Is this necessary? */
  9228.             buf[2] = (char)(i+'0');
  9229.             delmac(buf,0);
  9230.         }
  9231.     }
  9232.     for (i = 1; i <= top-n; i++) {      /* Shift remaining args */
  9233.         if (level < 0) {
  9234. #ifdef COMMENT
  9235.             toparg[i] = toparg[i+n];    /* Full vector */
  9236. #else
  9237.             makestr(&(toparg[i]),toparg[i+n]); /* Full vector */
  9238. #endif /* COMMENT */
  9239.             if (i < 10)                 /* Scalars... */
  9240.               makestr(&(g_var[i+'0']),toparg[i+n]);
  9241.         } else {
  9242. #ifdef COMMENT
  9243.             m_xarg[level][i] = m_xarg[level][i+n];
  9244. #else
  9245.             makestr(&(m_xarg[level][i]),m_xarg[level][i+n]);
  9246. #endif /* COMMENT */
  9247.             if (i < 10) {
  9248.                 buf[2] = (char)(i+'0');
  9249.                 debug(F010,"SHIFT buf",buf,0);
  9250.                 addmac(buf,m_xarg[level][i+n]);
  9251.             }
  9252.         }
  9253.     }
  9254.     for (i = top-n; i <= top; i++) {    /* Clear n args from the end */
  9255.         if (level < 0) {
  9256. #ifdef COMMENT
  9257.             toparg[i] = NULL;
  9258. #else
  9259.             makestr(&(toparg[i]),NULL);
  9260. #endif /* COMMENt */
  9261.             if (i < 10)
  9262.               makestr(&(g_var[i+'0']),NULL);
  9263.         } else {
  9264. #ifdef COMMENT
  9265.             m_xarg[level][i] = NULL;
  9266. #else
  9267.             makestr(&(m_xarg[level][i]),NULL);
  9268. #endif /* COMMENt */
  9269.             if (i < 10) {
  9270.                 buf[2] = (char)(i+'0');
  9271.                 delmac(buf,0);
  9272.             }
  9273.         }
  9274.     }
  9275.     if (level > -1) {                   /* Macro args */
  9276.         macargc[level] -= n;            /* Adjust count */
  9277.         n_xarg[maclvl] = macargc[level]; /* Here too */
  9278.         a_dim[0] = macargc[level] - 1;  /* Adjust array dimension */
  9279.     debug(F111,"a_dim[0]","F",a_dim[0]);
  9280.         zzstring("\\fjoin(&_[],{ },1)",&sx,&nx); /* Handle \%* */
  9281. #ifdef COMMENT
  9282.         makestr(&(m_line[level]),tmpbuf);
  9283. #endif /* COMMENT */
  9284.     } else {                            /* Ditto for top level */
  9285.         topargc -= n;
  9286.         a_dim[0] = topargc - 1;
  9287.     debug(F111,"a_dim[0]","G",a_dim[0]);
  9288.         zzstring("\\fjoin(&_[],{ },1)",&sx,&nx);
  9289. #ifdef COMMENT
  9290.         makestr(&topline,tmpbuf);
  9291. #endif /* COMMENT */
  9292.     }
  9293.     return(1);
  9294. }
  9295. #endif /* NOSPL */
  9296.  
  9297. int
  9298. docd(cx) int cx; {                      /* Do the CD command */
  9299.     int x;
  9300.     extern int server, srvcdmsg, cdactive;
  9301.     extern char * cdmsgfile[], * ckcdpath;
  9302.     char *s, *p;
  9303. #ifdef MAC
  9304.     char temp[34];
  9305. #endif /* MAC */
  9306. #ifdef IKSDCONF
  9307. extern int iksdcf;
  9308. #endif /* IKSDCONF */
  9309.  
  9310. #ifndef NOFRILLS
  9311.     if (cx == XXBACK) {
  9312.         if ((x = cmcfm()) < 0)
  9313.         cwdf = 1;
  9314.         if (prevdir) {
  9315.             s = zgtdir();
  9316.             if (!zchdir(prevdir)) {
  9317.                 cwdf = 0;
  9318.                 perror(s);
  9319.             } else {
  9320.                 makestr(&prevdir,s);
  9321.             }
  9322.         }
  9323.         return(cwdf);
  9324.     }
  9325. #endif /* NOFRILLS */
  9326.  
  9327.     if (cx == XXCDUP) {
  9328. #ifdef VMS
  9329.         s = "[-]";
  9330. #else
  9331. #ifdef datageneral
  9332.         s = "^";
  9333. #else
  9334.         s = "..";
  9335. #endif /* datageneral */
  9336. #endif /* VMS */
  9337.         ckstrncpy(line,s,LINBUFSIZ);
  9338.         goto gocd;
  9339.     }
  9340. #ifndef NOSPL
  9341.     if (cx == XXKCD) {            /* Symbolic (Kermit) CD */
  9342.     char * p;
  9343.     int n, k;
  9344.     x = cmkey(kcdtab,nkcdtab,"Symbolic directory name","home",xxstring);
  9345.     if (x < 0)
  9346.       return(x);
  9347.     x = lookup(kcdtab,atmbuf,nkcdtab,&k); /* Get complete keyword */
  9348.     if (x < 0) {
  9349.         printf("?Lookup error\n");    /* shouldn't happen */
  9350.         return(-9);
  9351.     }
  9352.         if ((x = cmcfm()) < 0)
  9353.       return(x);
  9354.     if (k == VN_HOME) {        /* HOME: allow SET HOME to override */
  9355.         ckstrncpy(line,homepath(),LINBUFSIZ);
  9356.     } else {            /* Other symbolic name */
  9357.         /* Convert to variable syntax */
  9358.         ckmakmsg(tmpbuf,TMPBUFSIZ,"\\v(",kcdtab[k].kwd,")",NULL);
  9359.         p = line;            /* Expand the variable */
  9360.         n = LINBUFSIZ;
  9361.         zzstring(tmpbuf,&p,&n);
  9362.         if (!line[0]) {        /* Fail if variable not defined */
  9363.         printf("?%s - not defined\n",tmpbuf);
  9364.         return(success = 0);
  9365.         }
  9366.     }
  9367.     s = line;            /* All OK, go try to CD... */
  9368.     goto gocd;
  9369.     }
  9370. #endif /* NOSPL */
  9371.  
  9372.     cdactive = 1;
  9373. #ifdef GEMDOS
  9374.     if ((x = cmdir("Name of local directory, or carriage return",
  9375.                    homepath(),
  9376.                    &s,
  9377.                    NULL
  9378.                    )
  9379.          ) < 0 )
  9380.       return(x);
  9381. #else
  9382. #ifdef OS2
  9383.     if ((x = cmdirp("Name of PC disk and/or directory,\n\
  9384.        or press the Enter key for the default",
  9385.                     homepath(),
  9386.                     &s,
  9387.                     ckcdpath ? ckcdpath : getenv("CDPATH"),
  9388.                     xxstring
  9389.                     )
  9390.          ) < 0 )
  9391.       return(x);
  9392. #else
  9393. #ifdef MAC
  9394.     x = ckstrncpy(temp,homepath(),32);
  9395.     if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  9396.     if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  9397.  or press the Return key for the desktop on the boot disk",
  9398.                    temp,&s, xxstring)) < 0 )
  9399.       return(x);
  9400. #else
  9401.     if ((x = cmdirp("Carriage return for home directory,\n\
  9402. or name of directory on this computer",
  9403. #ifdef VMS
  9404.                     "SYS$LOGIN",        /* With no colon */
  9405. #else
  9406.                     homepath(),        /* In VMS this is "SYS$LOGIN:" */
  9407. #endif /* VMS */
  9408.                     &s,
  9409.                     ckcdpath ? ckcdpath : getenv("CDPATH"),
  9410.                     xxstring
  9411.                     )) < 0)
  9412.       return(x);
  9413. #endif /* MAC */
  9414. #endif /* OS2 */
  9415. #endif /* GEMDOS */
  9416.     ckstrncpy(line,s,LINBUFSIZ);        /* Make a safe copy */
  9417.     s = line;
  9418. #ifdef VMS
  9419.     if (ckmatch("*.DIR;1$",s,0,0))
  9420.       if (cvtdir(s,tmpbuf,TMPBUFSIZ) > 0)
  9421.         s = tmpbuf;
  9422. #endif /* VMS */
  9423.     debug(F110,"docd",s,0);
  9424. #ifndef MAC
  9425.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  9426.       return(x);
  9427. #endif /* MAC */
  9428.  
  9429.   gocd:
  9430.  
  9431. #ifdef datageneral
  9432.     x = strlen(line);                   /* homdir ends in colon, */
  9433.     if (x > 1 && line[x-1] == ':')      /* and "dir" doesn't like that... */
  9434.       line[x-1] = NUL;
  9435. #endif /* datageneral */
  9436.  
  9437. #ifdef MAC
  9438.     cwdf = 1;
  9439.     if (!zchdir(s)) {
  9440.         cwdf = 0;
  9441.         if (*s != ':') {                /* If it failed, */
  9442.             char *p;                    /* supply leading colon */
  9443.             int len = (int)strlen(s) + 2;
  9444.             p = malloc(len);            /* and try again... */
  9445.             if (p) {
  9446.                 strcpy(p,":");          /* safe */
  9447.                 strcat(p,s);            /* safe */
  9448.                 if (zchdir(p))
  9449.                   cwdf = 1;
  9450.                 free(p);
  9451.                 p = NULL;
  9452.             }
  9453.         }
  9454.     }
  9455.     if (!cwdf)
  9456.       perror(s);
  9457. #else
  9458.     p = zgtdir();
  9459.     if (!zchdir(s)) {
  9460.         cwdf = 0;
  9461. #ifdef CKROOT
  9462.         if (ckrooterr)
  9463.           printf("?Off limits: \"%s\"\n",s);
  9464.         else
  9465. #endif /* CKROOT */
  9466.           perror(s);
  9467.     } else cwdf = 1;
  9468. #endif /* MAC */
  9469.  
  9470.     x = 0;
  9471.     if (cwdf) {
  9472.         makestr(&prevdir,p);
  9473.         if (srvcdmsg
  9474. #ifdef IKSDCONF
  9475.             && !(inserver && !iksdcf)
  9476. #endif /* IKSDCONF */
  9477.             ) {
  9478.             int i;
  9479.             for (i = 0; i < 8; i++) {
  9480.                 if (zchki(cdmsgfile[i]) > -1) {
  9481.                     x = 1;
  9482.                     dotype(cdmsgfile[i],xaskmore,0,0,NULL,0,NULL,0,0,NULL,0);
  9483.                     break;
  9484.                 }
  9485.             }
  9486.         }
  9487.     }
  9488. /* xdocd: */
  9489.     if (!x && srvcdmsg && !server
  9490. #ifdef IKSDCONF
  9491.         && !(inserver && !iksdcf)
  9492. #endif /* IKSDCONF */
  9493.         && !quiet && !xcmdsrc)
  9494.       printf("%s\n", zgtdir());
  9495.  
  9496.     return(cwdf);
  9497. }
  9498.  
  9499. static int on_ctrlc = 0;
  9500.  
  9501. VOID
  9502. fixcmd() {                      /* Fix command parser after interruption */
  9503. #ifndef NOSPL
  9504. #ifndef NOONCTRLC
  9505.     if (nmac) {                         /* Any macros defined? */
  9506.         int k;                          /* Yes */
  9507.         char * s = "on_ctrlc";          /* Name of Ctrl-C handling macro */
  9508.         k = mlook(mactab,s,nmac);       /* Look it up. */
  9509.         if (k >= 0) {                   /* If found, */
  9510.             if (on_ctrlc++ == 0) {      /* if not already executing, */
  9511.                 if (dodo(k,"",0) > -1)  /* set it up, */
  9512.                   parser(1);            /* execute it, */
  9513.             }
  9514.             delmac(s,1);                /* and undefine it. */
  9515.         }
  9516.     }
  9517.     on_ctrlc = 0;
  9518. #endif /* NOONCTRLC */
  9519. #endif /* NOSPL */
  9520.     dostop();                   /* Back to top level (also calls conint()). */
  9521.     bgchk();                    /* Check background status */
  9522.     if (*psave) {               /* If old prompt saved, */
  9523.         cmsetp(psave);          /* restore it. */
  9524.         *psave = NUL;
  9525.     }
  9526.     success = 0;                /* Tell parser last command failed */
  9527. }
  9528.  
  9529. #ifndef NOSHOW                          /* SHOW FEATURES */
  9530. /*
  9531.   Note, presently optlist[] index overflow is not checked.
  9532.   There is plenty of room (less than 360 entries for 1000 slots).
  9533.   When space starts to get tight, check for noptlist >= NOPTLIST
  9534.   every time noptlist is incremented.
  9535. */
  9536. #define NOPTLIST 1024
  9537. static int noptlist = 0;
  9538. static char * optlist[NOPTLIST+1];
  9539. static int hpos = 0;
  9540.  
  9541. int
  9542. prtopt(lines,s) int * lines; char *s; { /* Print an option */
  9543.     int y, i;                           /* Does word wrap. */
  9544.     if (!s) s = "";
  9545.     i = *lines;
  9546.     if (!*s) {                          /* Empty argument */
  9547.         if (hpos > 0) {                 /* means to end this line. */
  9548.             printf("\n");               /* Not needed if already at */
  9549.             if (++i > (cmd_rows - 3)) { /* beginning of new line. */
  9550.                 if (!askmore())
  9551.                   return(0);
  9552.                 else
  9553.                   i = 0;
  9554.             }
  9555.         }
  9556.         printf("\n");                   /* And then make a blank line */
  9557.         if (++i > (cmd_rows - 3)) {
  9558.             if (!askmore())
  9559.               return(0);
  9560.             else
  9561.               i = 0;
  9562.         }
  9563.         hpos = 0;
  9564.         *lines = i;
  9565.         return(1);
  9566.     }
  9567.     y = (int)strlen(s) + 1;
  9568.     hpos += y;
  9569.     debug(F101,"prtopt hpos","",hpos);
  9570.     debug(F101,"prtopt cmd_cols","",cmd_cols);
  9571.  
  9572.     if (
  9573. #ifdef OS2
  9574.         hpos > ((cmd_cols > 40) ? (cmd_cols - 1) : 79)
  9575. #else /* OS2 */
  9576.         hpos > ((tt_cols > 40) ? (tt_cols - 1) : 79)
  9577. #endif /* OS2 */
  9578.         ) {
  9579.         printf("\n");
  9580.         if (++i > (cmd_rows - 3)) {
  9581.             if (!askmore())
  9582.               return(0);
  9583.             else
  9584.               i = 0;
  9585.         }
  9586.         printf(" %s",s);
  9587.         hpos = y;
  9588.     } else
  9589.       printf(" %s",s);
  9590.     *lines = i;
  9591.     return(1);
  9592. }
  9593.  
  9594. static VOID
  9595. initoptlist() {
  9596.     int i;
  9597.     if (noptlist > 0)
  9598.       return;
  9599.     for (i = 0; i < NOPTLIST; i++)
  9600.       optlist[i] = NULL;
  9601.  
  9602. #ifdef MAC
  9603. #ifdef MPW
  9604.     makestr(&(optlist[noptlist++]),"MPW");
  9605. #endif /* MPW */
  9606. #endif /* MAC */
  9607.  
  9608. #ifdef MAC
  9609. #ifdef THINK_C
  9610.     makestr(&(optlist[noptlist++]),"THINK_C");
  9611. #endif /* THINK_C */
  9612. #endif /* MAC */
  9613.  
  9614. #ifdef __386__
  9615.     makestr(&(optlist[noptlist++]),"__386__");
  9616. #endif /* __386__ */
  9617.  
  9618. /* Memory models... */
  9619.  
  9620. #ifdef __FLAT__
  9621.     makestr(&(optlist[noptlist++]),"__FLAT__");
  9622. #endif /* __FLAT__ */
  9623. #ifdef __SMALL__
  9624.     makestr(&(optlist[noptlist++]),"__SMALL__");
  9625. #endif /* __SMALL__ */
  9626. #ifdef __MEDIUM__
  9627.     makestr(&(optlist[noptlist++]),"__MEDIUM__");
  9628. #endif /* __MEDIUM__ */
  9629. #ifdef __COMPACT__
  9630.     makestr(&(optlist[noptlist++]),"__COMPACT__");
  9631. #endif /* __COMPACT__ */
  9632. #ifdef __LARGE__
  9633.     makestr(&(optlist[noptlist++]),"__LARGE__");
  9634. #endif /* __LARGE__ */
  9635.  
  9636. #ifdef DEBUG
  9637. #ifdef IFDEBUG
  9638.     makestr(&(optlist[noptlist++]),"IFDEBUG");
  9639. #else
  9640.     makestr(&(optlist[noptlist++]),"DEBUG");
  9641. #endif /* IFDEBUG */
  9642. #endif /* DEBUG */
  9643. #ifdef TLOG
  9644.     makestr(&(optlist[noptlist++]),"TLOG");
  9645. #endif /* TLOG */
  9646. #ifdef BIGBUFOK
  9647.     makestr(&(optlist[noptlist++]),"BIGBUFOK");
  9648. #endif /* BIGBUFOK */
  9649. #ifdef INPBUFSIZ
  9650.     sprintf(line,"INPBUFSIZ=%d",INPBUFSIZ); /* SAFE */
  9651.     makestr(&(optlist[noptlist++]),line);
  9652. #endif /* INPBUFSIZE */
  9653. #ifdef INBUFSIZE
  9654.     sprintf(line,"INBUFSIZE=%d",INBUFSIZE); /* SAFE */
  9655.     makestr(&(optlist[noptlist++]),line);
  9656. #endif /* INBUFSIZE */
  9657. #ifdef OBUFSIZE
  9658.     sprintf(line,"OBUFSIZE=%d",OBUFSIZE); /* SAFE */
  9659.     makestr(&(optlist[noptlist++]),line);
  9660. #endif /* OBUFSIZE */
  9661. #ifdef FD_SETSIZE
  9662.     sprintf(line,"FD_SETSIZE=%d",FD_SETSIZE); /* SAFE */
  9663.     makestr(&(optlist[noptlist++]),line);
  9664. #endif /* FD_SETSIZE */
  9665. #ifdef XFRCAN
  9666.     makestr(&(optlist[noptlist++]),"XFRCAN");
  9667. #endif /* XFRCAN */
  9668. #ifdef XPRINT
  9669.     makestr(&(optlist[noptlist++]),"XPRINT");
  9670. #endif /* XPRINT */
  9671. #ifdef PIPESEND
  9672.     makestr(&(optlist[noptlist++]),"PIPESEND");
  9673. #endif /* PIPESEND */
  9674. #ifdef CK_SPEED
  9675.     makestr(&(optlist[noptlist++]),"CK_SPEED");
  9676. #endif /* CK_SPEED */
  9677. #ifdef CK_FAST
  9678.     makestr(&(optlist[noptlist++]),"CK_FAST");
  9679. #endif /* CK_FAST */
  9680. #ifdef CK_APC
  9681.     makestr(&(optlist[noptlist++]),"CK_APC");
  9682. #endif /* CK_APC */
  9683. #ifdef CK_AUTODL
  9684.     makestr(&(optlist[noptlist++]),"CK_AUTODL");
  9685. #endif /* CK_AUTODL */
  9686. #ifdef CK_MKDIR
  9687.     makestr(&(optlist[noptlist++]),"CK_MKDIR");
  9688. #endif /* CK_MKDIR */
  9689. #ifdef NOMKDIR
  9690.     makestr(&(optlist[noptlist++]),"NOMKDIR");
  9691. #endif /* NOMKDIR */
  9692. #ifdef CK_LABELED
  9693.     makestr(&(optlist[noptlist++]),"CK_LABELED");
  9694. #endif /* CK_LABELED */
  9695. #ifdef NODIAL
  9696.     makestr(&(optlist[noptlist++]),"NODIAL");
  9697. #endif /* NODIAL */
  9698. #ifdef MINIDIAL
  9699.     makestr(&(optlist[noptlist++]),"MINIDIAL");
  9700. #endif /* MINIDIAL */
  9701. #ifdef WHATAMI
  9702.     makestr(&(optlist[noptlist++]),"WHATAMI");
  9703. #endif /* WHATAMI */
  9704. #ifdef DYNAMIC
  9705.     makestr(&(optlist[noptlist++]),"DYNAMIC");
  9706. #endif /* IFDEBUG */
  9707. #ifndef NOSPL
  9708.     sprintf(line,"CMDDEP=%d",CMDDEP);   /* SAFE */
  9709.     makestr(&(optlist[noptlist++]),line);
  9710. #endif /* NOSPL */
  9711.  
  9712. #ifdef MAXPATHLEN
  9713.     sprintf(line,"MAXPATHLEN=%d",MAXPATHLEN); /* SAFE */
  9714.     makestr(&(optlist[noptlist++]),line);
  9715. #endif /* MAXPATHLEN */
  9716.  
  9717. #ifdef DEVNAMLEN
  9718.     sprintf(line,"DEVNAMLEN=%d",DEVNAMLEN); /* SAFE */
  9719.     makestr(&(optlist[noptlist++]),line);
  9720. #endif /* DEVNAMLEN */
  9721.  
  9722. #ifdef NO_PARAM_H
  9723.     makestr(&(optlist[noptlist++]),"NO_PARAM_H");
  9724. #endif /* NO_PARAM_H */
  9725.  
  9726. #ifdef INCL_PARAM_H
  9727.     makestr(&(optlist[noptlist++]),"INCL_PARAM_H");
  9728. #endif /* INCL_PARAM_H */
  9729.  
  9730.     sprintf(line,"CKMAXPATH=%d",CKMAXPATH); /* SAFE */
  9731.     makestr(&(optlist[noptlist++]),line);
  9732.  
  9733.     sprintf(line,"CKMAXOPEN=%d",CKMAXOPEN); /* SAFE */
  9734.     makestr(&(optlist[noptlist++]),line);
  9735.  
  9736.     sprintf(line,"Z_MAXCHAN=%d",Z_MAXCHAN); /* SAFE */
  9737.     makestr(&(optlist[noptlist++]),line);
  9738.  
  9739. #ifdef OPEN_MAX
  9740.     sprintf(line,"OPEN_MAX=%d",OPEN_MAX); /* SAFE */
  9741.     makestr(&(optlist[noptlist++]),line);
  9742. #endif /* OPEN_MAX */
  9743.  
  9744. #ifdef _POSIX_OPEN_MAX
  9745.     sprintf(line,"_POSIX_OPEN_MAX=%d",_POSIX_OPEN_MAX); /* SAFE */
  9746.     makestr(&(optlist[noptlist++]),line);
  9747. #endif /* _POSIX_OPEN_MAX */
  9748.  
  9749. #ifdef CKCHANNELIO
  9750.     {
  9751.         extern int z_maxchan;
  9752. #ifdef UNIX
  9753.         extern int ckmaxfiles;
  9754.         sprintf(line,"ckmaxfiles=%d",ckmaxfiles); /* SAFE */
  9755.         makestr(&(optlist[noptlist++]),line);
  9756. #endif /* UNIX */
  9757.         sprintf(line,"z_maxchan=%d",z_maxchan); /* SAFE */
  9758.         makestr(&(optlist[noptlist++]),line);
  9759.     }
  9760. #endif /* CKCHANNELIO */
  9761.  
  9762. #ifdef FOPEN_MAX
  9763.     sprintf(line,"FOPEN_MAX=%d",FOPEN_MAX); /* SAFE */
  9764.     makestr(&(optlist[noptlist++]),line);
  9765. #endif /* FOPEN_MAX */
  9766.  
  9767. #ifdef MAXGETPATH
  9768.     sprintf(line,"MAXGETPATH=%d",MAXGETPATH); /* SAFE */
  9769.     makestr(&(optlist[noptlist++]),line);
  9770. #endif /* MAXGETPATH */
  9771.  
  9772. #ifdef CMDBL
  9773.     sprintf(line,"CMDBL=%d",CMDBL);     /* SAFE */
  9774.     makestr(&(optlist[noptlist++]),line);
  9775. #endif /* CMDBL */
  9776.  
  9777. #ifdef VNAML
  9778.     sprintf(line,"VNAML=%d",VNAML);     /* SAFE */
  9779.     makestr(&(optlist[noptlist++]),line);
  9780. #endif /* VNAML */
  9781.  
  9782. #ifdef ARRAYREFLEN
  9783.     sprintf(line,"ARRAYREFLEN=%d",ARRAYREFLEN); /* SAFE */
  9784.     makestr(&(optlist[noptlist++]),line);
  9785. #endif /* ARRAYREFLEN */
  9786.  
  9787. #ifdef UIDBUFLEN
  9788.     sprintf(line,"UIDBUFLEN=%d",UIDBUFLEN); /* SAFE */
  9789.     makestr(&(optlist[noptlist++]),line);
  9790. #endif /* UIDBUFLEN */
  9791.  
  9792. #ifdef FORDEPTH
  9793.     sprintf(line,"FORDEPTH=%d",FORDEPTH); /* SAFE */
  9794.     makestr(&(optlist[noptlist++]),line);
  9795. #endif /* FORDEPTH */
  9796.  
  9797. #ifdef MAXTAKE
  9798.     sprintf(line,"MAXTAKE=%d",MAXTAKE); /* SAFE */
  9799.     makestr(&(optlist[noptlist++]),line);
  9800. #endif /* MAXTAKE */
  9801.  
  9802. #ifdef MACLEVEL
  9803.     sprintf(line,"MACLEVEL=%d",MACLEVEL); /* SAFE */
  9804.     makestr(&(optlist[noptlist++]),line);
  9805. #endif /* MACLEVEL */
  9806.  
  9807. #ifdef MAC_MAX
  9808.     sprintf(line,"MAC_MAX=%d",MAC_MAX); /* SAFE */
  9809.     makestr(&(optlist[noptlist++]),line);
  9810. #endif /* MAC_MAX */
  9811.  
  9812. #ifdef MINPUTMAX
  9813.     sprintf(line,"MINPUTMAX=%d",MINPUTMAX); /* SAFE */
  9814.     makestr(&(optlist[noptlist++]),line);
  9815. #endif /* MINPUTMAX */
  9816.  
  9817. #ifdef MAXWLD
  9818.     sprintf(line,"MAXWLD=%d",MAXWLD); /* SAFE */
  9819.     makestr(&(optlist[noptlist++]),line);
  9820. #else
  9821. #ifdef OS2
  9822.     makestr(&(optlist[noptlist++]),"MAXWLD=unlimited");
  9823. #endif /* OS2 */
  9824. #endif /* MAXWLD */
  9825.  
  9826. #ifdef MSENDMAX
  9827.     sprintf(line,"MSENDMAX=%d",MSENDMAX); /* SAFE */
  9828.     makestr(&(optlist[noptlist++]),line);
  9829. #endif /* MSENDMAX */
  9830.  
  9831. #ifdef MAXDDIR
  9832.     sprintf(line,"MAXDDIR=%d",MAXDDIR); /* SAFE */
  9833.     makestr(&(optlist[noptlist++]),line);
  9834. #endif /* MAXDDIR */
  9835.  
  9836. #ifdef MAXDNUMS
  9837.     sprintf(line,"MAXDNUMS=%d",MAXDNUMS); /* SAFE */
  9838.     makestr(&(optlist[noptlist++]),line);
  9839. #endif /* MAXDNUMS */
  9840.  
  9841. #ifdef UNIX
  9842.     makestr(&(optlist[noptlist++]),"UNIX");
  9843. #endif /* UNIX */
  9844. #ifdef VMS
  9845.     makestr(&(optlist[noptlist++]),"VMS");
  9846. #ifdef __VMS_VER
  9847.     sprintf(line,"__VMS_VER=%d",__VMS_VER); /* SAFE */
  9848.     makestr(&(optlist[noptlist++]),line);
  9849. #endif /* __VMS_VER */
  9850. #ifdef VMSV70
  9851.     makestr(&(optlist[noptlist++]),"VMSV70");
  9852. #endif /* VMSV70 */
  9853. #endif /* VMS */
  9854. #ifdef OLD_VMS
  9855.     makestr(&(optlist[noptlist++]),"OLD_VMS");
  9856. #endif /* OLD_VMS */
  9857. #ifdef vms
  9858.     makestr(&(optlist[noptlist++]),"vms");
  9859. #endif /* vms */
  9860. #ifdef VMSV60
  9861.     makestr(&(optlist[noptlist++]),"VMSV60");
  9862. #endif /* VMSV60 */
  9863. #ifdef VMSV70
  9864.     makestr(&(optlist[noptlist++]),"VMSV70");
  9865. #endif /* VMSV70 */
  9866. #ifdef VMSSHARE
  9867.     makestr(&(optlist[noptlist++]),"VMSSHARE");
  9868. #endif /* VMSSHARE */
  9869. #ifdef NOVMSSHARE
  9870.     makestr(&(optlist[noptlist++]),"NOVMSSHARE");
  9871. #endif /* NOVMSSHARE */
  9872. #ifdef datageneral
  9873.     makestr(&(optlist[noptlist++]),"datageneral");
  9874. #endif /* datageneral */
  9875. #ifdef apollo
  9876.     makestr(&(optlist[noptlist++]),"apollo");
  9877. #endif /* apollo */
  9878. #ifdef aegis
  9879.     makestr(&(optlist[noptlist++]),"aegis");
  9880. #endif /* aegis */
  9881. #ifdef A986
  9882.     makestr(&(optlist[noptlist++]),"A986");
  9883. #endif /* A986 */
  9884. #ifdef AMIGA
  9885.     makestr(&(optlist[noptlist++]),"AMIGA");
  9886. #endif /* AMIGA */
  9887. #ifdef CONVEX9
  9888.     makestr(&(optlist[noptlist++]),"CONVEX9");
  9889. #endif /* CONVEX9 */
  9890. #ifdef CONVEX10
  9891.     makestr(&(optlist[noptlist++]),"CONVEX10");
  9892. #endif /* CONVEX9 */
  9893. #ifdef MAC
  9894.     makestr(&(optlist[noptlist++]),"MAC");
  9895. #endif /* MAC */
  9896. #ifdef AUX
  9897.     makestr(&(optlist[noptlist++]),"AUX");
  9898. #endif /* AUX */
  9899. #ifdef OS2
  9900.     makestr(&(optlist[noptlist++]),"OS2");
  9901. #ifdef NT
  9902.     makestr(&(optlist[noptlist++]),"NT");
  9903. #endif /* NT */
  9904. #endif /* OS2 */
  9905. #ifdef OSK
  9906.     makestr(&(optlist[noptlist++]),"OS9");
  9907. #endif /* OSK */
  9908. #ifdef MSDOS
  9909.     makestr(&(optlist[noptlist++]),"MSDOS");
  9910. #endif /* MSDOS */
  9911. #ifdef DIRENT
  9912.     makestr(&(optlist[noptlist++]),"DIRENT");
  9913. #endif /* DIRENT */
  9914. #ifdef SDIRENT
  9915.     makestr(&(optlist[noptlist++]),"SDIRENT");
  9916. #endif /* SDIRENT */
  9917. #ifdef NDIR
  9918.     makestr(&(optlist[noptlist++]),"NDIR");
  9919. #endif /* NDIR */
  9920. #ifdef XNDIR
  9921.     makestr(&(optlist[noptlist++]),"XNDIR");
  9922. #endif /* XNDIR */
  9923. #ifdef SAVEDUID
  9924.     makestr(&(optlist[noptlist++]),"SAVEDUID");
  9925. #endif /* SAVEDUID */
  9926. #ifdef RENAME
  9927.     makestr(&(optlist[noptlist++]),"RENAME");
  9928. #endif /* RENAME */
  9929. #ifdef CK_TMPDIR
  9930.     makestr(&(optlist[noptlist++]),"CK_TMPDIR");
  9931. #endif /* CK_TMPDIR */
  9932. #ifdef NOCCTRAP
  9933.     makestr(&(optlist[noptlist++]),"NOCCTRAP");
  9934. #endif /* NOCCTRAP */
  9935. #ifdef NOCOTFMC
  9936.     makestr(&(optlist[noptlist++]),"NOCOTFMC");
  9937. #endif /* NOCOTFMC */
  9938. #ifdef NOFRILLS
  9939.     makestr(&(optlist[noptlist++]),"NOFRILLS");
  9940. #endif /* NOFRILLS */
  9941. #ifdef PARSENSE
  9942.     makestr(&(optlist[noptlist++]),"PARSENSE");
  9943. #endif /* PARSENSE */
  9944. #ifdef TIMEH
  9945.     makestr(&(optlist[noptlist++]),"TIMEH");
  9946. #endif /* TIMEH */
  9947. #ifdef NOTIMEH
  9948.     makestr(&(optlist[noptlist++]),"TIMEH");
  9949. #endif /* NOTIMEH */
  9950.  
  9951. #ifdef SYSTIMEH
  9952.     makestr(&(optlist[noptlist++]),"SYSTIMEH");
  9953. #endif /* SYSTIMEH */
  9954. #ifdef NOSYSTIMEH
  9955.     makestr(&(optlist[noptlist++]),"SYSTIMEH");
  9956. #endif /* NOSYSTIMEH */
  9957.  
  9958. #ifdef SYSTIMEBH
  9959.     makestr(&(optlist[noptlist++]),"SYSTIMEBH");
  9960. #endif /* SYSTIMEBH */
  9961. #ifdef NOSYSTIMEBH
  9962.     makestr(&(optlist[noptlist++]),"SYSTIMEBH");
  9963. #endif /* NOSYSTIMEBH */
  9964. #ifdef UTIMEH
  9965.     makestr(&(optlist[noptlist++]),"UTIMEH");
  9966. #endif /* UTIMEH */
  9967. #ifdef SYSUTIMEH
  9968.     makestr(&(optlist[noptlist++]),"SYSUTIMEH");
  9969. #endif /* SYSUTIMEH */
  9970.  
  9971. #ifdef CK_NEED_SIG
  9972.     makestr(&(optlist[noptlist++]),"CK_NEED_SIG");
  9973. #endif /* CK_NEED_SIG */
  9974. #ifdef CK_TTYFD
  9975.     makestr(&(optlist[noptlist++]),"CK_TTYFD");
  9976. #endif /* CK_TTYFD */
  9977. #ifdef NETCONN
  9978.     makestr(&(optlist[noptlist++]),"NETCONN");
  9979. #endif /* NETCONN */
  9980. #ifdef TCPSOCKET
  9981.     makestr(&(optlist[noptlist++]),"TCPSOCKET");
  9982. #ifdef NOTCPOPTS
  9983.     makestr(&(optlist[noptlist++]),"NOTCPOPTS");
  9984. #endif /* NOTCPOPTS */
  9985. #ifdef CK_DNS_SRV
  9986.     makestr(&(optlist[noptlist++]),"CK_DNS_SRV");
  9987. #endif /* CK_DNS_SRV */
  9988. #ifdef NO_DNS_SRV
  9989.     makestr(&(optlist[noptlist++]),"NO_DNS_SRV");
  9990. #endif /* NO_DNS_SRV */
  9991. #ifdef CKGHNLHOST
  9992.     makestr(&(optlist[noptlist++]),"CKGHNLHOST");
  9993. #endif /* CKGHNLHOST */
  9994. #ifdef NOLISTEN
  9995.     makestr(&(optlist[noptlist++]),"NOLISTEN");
  9996. #endif /* NOLISTEN */
  9997. #ifdef SOL_SOCKET
  9998.     makestr(&(optlist[noptlist++]),"SOL_SOCKET");
  9999. #endif /* SOL_SOCKET */
  10000. #ifdef SO_OOBINLINE
  10001.     makestr(&(optlist[noptlist++]),"SO_OOBINLINE");
  10002. #endif /* SO_OOBINLNE */
  10003. #ifdef SO_DONTROUTE
  10004.     makestr(&(optlist[noptlist++]),"SO_DONTROUTE");
  10005. #endif /* SO_DONTROUTE */
  10006. #ifdef SO_KEEPALIVE
  10007.     makestr(&(optlist[noptlist++]),"SO_KEEPALIVE");
  10008. #endif /* SO_KEEPALIVE */
  10009. #ifdef SO_LINGER
  10010.     makestr(&(optlist[noptlist++]),"SO_LINGER");
  10011. #endif /* SO_LINGER */
  10012. #ifdef TCP_NODELAY
  10013.     makestr(&(optlist[noptlist++]),"TCP_NODELAY");
  10014. #endif /* TCP_NODELAY */
  10015. #ifdef SO_SNDBUF
  10016.     makestr(&(optlist[noptlist++]),"SO_SNDBUF");
  10017. #endif /* SO_SNDBUF */
  10018. #ifdef SO_RCVBUF
  10019.     makestr(&(optlist[noptlist++]),"SO_RCVBUF");
  10020. #endif /* SO_RCVBUF */
  10021. #ifdef h_addr
  10022.     makestr(&(optlist[noptlist++]),"h_addr");
  10023. #endif /* h_addr */
  10024. #ifdef HADDRLIST
  10025.     makestr(&(optlist[noptlist++]),"HADDRLIST");
  10026. #endif /* HADDRLIST */
  10027. #ifdef CK_SOCKS
  10028.     makestr(&(optlist[noptlist++]),"CK_SOCKS");
  10029. #ifdef CK_SOCKS5
  10030.     makestr(&(optlist[noptlist++]),"CK_SOCKS5");
  10031. #endif /* CK_SOCKS5 */
  10032. #ifdef CK_SOCKS_NS
  10033.     makestr(&(optlist[noptlist++]),"CK_SOCKS_NS");
  10034. #endif /* CK_SOCKS_NS */
  10035. #endif /* CK_SOCKS */
  10036. #ifdef RLOGCODE
  10037.     makestr(&(optlist[noptlist++]),"RLOGCODE");
  10038. #endif /* RLOGCODE */
  10039. #ifdef NETCMD
  10040.     makestr(&(optlist[noptlist++]),"NETCMD");
  10041. #endif /* NETCMD */
  10042. #ifdef NONETCMD
  10043.     makestr(&(optlist[noptlist++]),"NONETCMD");
  10044. #endif /* NONETCMD */
  10045. #ifdef NETPTY
  10046.     makestr(&(optlist[noptlist++]),"NETPTY");
  10047. #endif /* NETPTY */
  10048. #ifdef CK_ENVIRONMENT
  10049.     makestr(&(optlist[noptlist++]),"CK_ENVIRONMENT");
  10050. #endif /* CK_ENVIRONMENT */
  10051. #endif /* TCPSOCKET */
  10052. #ifdef TNCODE
  10053.     makestr(&(optlist[noptlist++]),"TNCODE");
  10054. #endif /* TNCODE */
  10055. #ifdef CK_FORWARD_X
  10056.     makestr(&(optlist[noptlist++]),"CK_FORWARD_X");
  10057. #endif /* CK_FORWARD_X */
  10058. #ifdef TN_COMPORT
  10059.     makestr(&(optlist[noptlist++]),"TN_COMPORT");
  10060. #endif /* TN_COMPORT */
  10061. #ifdef MULTINET
  10062.     makestr(&(optlist[noptlist++]),"MULTINET");
  10063. #endif /* MULTINET */
  10064. #ifdef DEC_TCPIP
  10065.     makestr(&(optlist[noptlist++]),"DEC_TCPIP");
  10066. #endif /* DEC_TCPIP */
  10067. #ifdef TCPWARE
  10068.     makestr(&(optlist[noptlist++]),"TCPWARE");
  10069. #endif /* TCPWARE */
  10070. #ifdef UCX50
  10071.     makestr(&(optlist[noptlist++]),"UCX50");
  10072. #endif /* UCX50 */
  10073. #ifdef TTLEBUF
  10074.     makestr(&(optlist[noptlist++]),"TTLEBUF");
  10075. #endif /* TTLEBUF */
  10076. #ifdef NETLEBUF
  10077.     makestr(&(optlist[noptlist++]),"NETLEBUF");
  10078. #endif /* NETLEBUF */
  10079. #ifdef IKS_OPTION
  10080.     makestr(&(optlist[noptlist++]),"IKS_OPTION");
  10081. #endif /* IKS_OPTION */
  10082. #ifdef IKSDB
  10083.     makestr(&(optlist[noptlist++]),"IKSDB");
  10084. #endif /* IKSDB */
  10085. #ifdef IKSDCONF
  10086.     makestr(&(optlist[noptlist++]),"IKSDCONF");
  10087. #endif /* IKSDCONF */
  10088. #ifdef CK_LOGIN
  10089.     makestr(&(optlist[noptlist++]),"CK_LOGIN");
  10090. #endif /* CK_LOGIN */
  10091. #ifdef CK_PAM
  10092.     makestr(&(optlist[noptlist++]),"CK_PAM");
  10093. #endif /* CK_PAM */
  10094. #ifdef CK_SHADOW
  10095.     makestr(&(optlist[noptlist++]),"CK_SHADOW");
  10096. #endif /* CK_SHADOW */
  10097. #ifdef CONGSPD
  10098.     makestr(&(optlist[noptlist++]),"CONGSPD");
  10099. #endif /* CONGSPD */
  10100. #ifdef SUNX25
  10101.     makestr(&(optlist[noptlist++]),"SUNX25");
  10102. #endif /* SUNX25 */
  10103. #ifdef IBMX25
  10104.     makestr(&(optlist[noptlist++]),"IBMX25");
  10105. #endif /* IBMX25 */
  10106. #ifdef HPX25
  10107.     makestr(&(optlist[noptlist++]),"HPX25");
  10108. #endif /* HPX25 */
  10109. #ifdef DECNET
  10110.     makestr(&(optlist[noptlist++]),"DECNET");
  10111. #endif /* DECNET */
  10112. #ifdef SUPERLAT
  10113.     makestr(&(optlist[noptlist++]),"SUPERLAT");
  10114. #endif /* SUPERLAT */
  10115. #ifdef NPIPE
  10116.     makestr(&(optlist[noptlist++]),"NPIPE");
  10117. #endif /* NPIPE */
  10118. #ifdef CK_NETBIOS
  10119.     makestr(&(optlist[noptlist++]),"CK_NETBIOS");
  10120. #endif /* CK_NETBIOS */
  10121. #ifdef ATT7300
  10122.     makestr(&(optlist[noptlist++]),"ATT7300");
  10123. #endif /* ATT7300 */
  10124. #ifdef ATT6300
  10125.     makestr(&(optlist[noptlist++]),"ATT6300");
  10126. #endif /* ATT6300 */
  10127. #ifdef HDBUUCP
  10128.     makestr(&(optlist[noptlist++]),"HDBUUCP");
  10129. #endif /* HDBUUCP */
  10130. #ifdef USETTYLOCK
  10131.     makestr(&(optlist[noptlist++]),"USETTYLOCK");
  10132. #endif /* USETTYLOCK */
  10133. #ifdef NOUUCP
  10134.     makestr(&(optlist[noptlist++]),"NOUUCP");
  10135. #endif /* NOUUCP */
  10136. #ifdef LONGFN
  10137.     makestr(&(optlist[noptlist++]),"LONGFN");
  10138. #endif /* LONGFN */
  10139. #ifdef RDCHK
  10140.     makestr(&(optlist[noptlist++]),"RDCHK");
  10141. #endif /* RDCHK */
  10142. #ifdef SELECT
  10143.     makestr(&(optlist[noptlist++]),"SELECT");
  10144. #endif /* SELECT */
  10145. #ifdef USLEEP
  10146.     makestr(&(optlist[noptlist++]),"USLEEP");
  10147. #endif /* USLEEP */
  10148. #ifdef NAP
  10149.     makestr(&(optlist[noptlist++]),"NAP");
  10150. #endif /* NAP */
  10151. #ifdef NAPHACK
  10152.     makestr(&(optlist[noptlist++]),"NAPHACK");
  10153. #endif /* NAPHACK */
  10154. #ifdef CK_POLL
  10155.     makestr(&(optlist[noptlist++]),"CK_POLL");
  10156. #endif /* CK_POLL */
  10157. #ifdef NOIEXTEN
  10158.     makestr(&(optlist[noptlist++]),"NOIEXTEN");
  10159. #endif /* NOIEXTEN */
  10160. #ifdef EXCELAN
  10161.     makestr(&(optlist[noptlist++]),"EXCELAN");
  10162. #endif /* EXCELAN */
  10163. #ifdef INTERLAN
  10164.     makestr(&(optlist[noptlist++]),"INTERLAN");
  10165. #endif /* INTERLAN */
  10166. #ifdef NOFILEH
  10167.     makestr(&(optlist[noptlist++]),"NOFILEH");
  10168. #endif /* NOFILEH */
  10169. #ifdef NOSYSIOCTLH
  10170.     makestr(&(optlist[noptlist++]),"NOSYSIOCTLH");
  10171. #endif /* NOSYSIOCTLH */
  10172. #ifdef DCLPOPEN
  10173.     makestr(&(optlist[noptlist++]),"DCLPOPEN");
  10174. #endif /* DCLPOPEN */
  10175. #ifdef NOSETBUF
  10176.     makestr(&(optlist[noptlist++]),"NOSETBUF");
  10177. #endif /* NOSETBUF */
  10178. #ifdef NOXFER
  10179.     makestr(&(optlist[noptlist++]),"NOXFER");
  10180. #endif /* NOXFER */
  10181. #ifdef NOCURSES
  10182.     makestr(&(optlist[noptlist++]),"NOCURSES");
  10183. #endif /* NOCURSES */
  10184. #ifdef NOSERVER
  10185.     makestr(&(optlist[noptlist++]),"NOSERVER");
  10186. #endif /* NOSERVER */
  10187. #ifdef NOPATTERNS
  10188.     makestr(&(optlist[noptlist++]),"NOPATTERNS");
  10189. #else
  10190. #ifdef PATTERNS
  10191.     makestr(&(optlist[noptlist++]),"PATTERNS");
  10192. #endif /* PATTERNS */
  10193. #endif /* NOPATTERNS */
  10194. #ifdef NOCKEXEC
  10195.     makestr(&(optlist[noptlist++]),"NOCKEXEC");
  10196. #else
  10197. #ifdef CKEXEC
  10198.     makestr(&(optlist[noptlist++]),"CKEXEC");
  10199. #endif /* CKEXEC */
  10200. #endif /* NOCKEXEC */
  10201. #ifdef NOAUTODL
  10202.     makestr(&(optlist[noptlist++]),"NOAUTODL");
  10203. #endif /* NOAUTODL */
  10204. #ifdef NOMSEND
  10205.     makestr(&(optlist[noptlist++]),"NOMSEND");
  10206. #endif /* NOMSEND */
  10207. #ifdef NOFDZERO
  10208.     makestr(&(optlist[noptlist++]),"NOFDZERO");
  10209. #endif /* NOFDZERO */
  10210. #ifdef NOPOPEN
  10211.     makestr(&(optlist[noptlist++]),"NOPOPEN");
  10212. #endif /* NOPOPEN */
  10213. #ifdef NOPARTIAL
  10214.     makestr(&(optlist[noptlist++]),"NOPARTIAL");
  10215. #endif /* NOPARTIAL */
  10216. #ifdef NOKVERBS
  10217.     makestr(&(optlist[noptlist++]),"NOKVERBS");
  10218. #endif /* NOKVERBS */
  10219. #ifdef NOSETREU
  10220.     makestr(&(optlist[noptlist++]),"NOSETREU");
  10221. #endif /* NOSETREU */
  10222. #ifdef LCKDIR
  10223.     makestr(&(optlist[noptlist++]),"LCKDIR");
  10224. #endif /* LCKDIR */
  10225. #ifdef ACUCNTRL
  10226.     makestr(&(optlist[noptlist++]),"ACUCNTRL");
  10227. #endif /* ACUCNTRL */
  10228. #ifdef BSD4
  10229.     makestr(&(optlist[noptlist++]),"BSD4");
  10230. #endif /* BSD4 */
  10231. #ifdef BSD44
  10232.     makestr(&(optlist[noptlist++]),"BSD44");
  10233. #endif /* BSD44 */
  10234. #ifdef BSD41
  10235.     makestr(&(optlist[noptlist++]),"BSD41");
  10236. #endif /* BSD41 */
  10237. #ifdef BSD43
  10238.     makestr(&(optlist[noptlist++]),"BSD43");
  10239. #endif /* BSD43 */
  10240. #ifdef BSD29
  10241.     makestr(&(optlist[noptlist++]),"BSD29");
  10242. #endif /* BSD29 */
  10243. #ifdef BSDI
  10244.     makestr(&(optlist[noptlist++]),"BSDI");
  10245. #endif /* BSDI */
  10246. #ifdef __bsdi__
  10247.     makestr(&(optlist[noptlist++]),"__bsdi__");
  10248. #endif /* __bsdi__ */
  10249. #ifdef __NetBSD__
  10250.     makestr(&(optlist[noptlist++]),"__NetBSD__");
  10251. #endif /* __NetBSD__ */
  10252. #ifdef __OpenBSD__
  10253.     makestr(&(optlist[noptlist++]),"__OpenBSD__");
  10254. #endif /* __OpenBSD__ */
  10255. #ifdef __FreeBSD__
  10256.     makestr(&(optlist[noptlist++]),"__FreeBSD__");
  10257. #endif /* __FreeBSD__ */
  10258. #ifdef __linux__
  10259.     makestr(&(optlist[noptlist++]),"__linux__");
  10260. #endif /* __linux__ */
  10261. #ifdef LINUX_HI_SPD
  10262.     makestr(&(optlist[noptlist++]),"LINUX_HI_SPD");
  10263. #endif /* LINUX_HI_SPD */
  10264. #ifdef LYNXOS
  10265.     makestr(&(optlist[noptlist++]),"LYNXOS");
  10266. #endif /* LYNXOS */
  10267. #ifdef V7
  10268.     makestr(&(optlist[noptlist++]),"V7");
  10269. #endif /* V7 */
  10270. #ifdef AIX370
  10271.     makestr(&(optlist[noptlist++]),"AIX370");
  10272. #endif /* AIX370 */
  10273. #ifdef RTAIX
  10274.     makestr(&(optlist[noptlist++]),"RTAIX");
  10275. #endif /* RTAIX */
  10276. #ifdef HPUX
  10277.     makestr(&(optlist[noptlist++]),"HPUX");
  10278. #endif /* HPUX */
  10279. #ifdef HPUXPRE65
  10280.     makestr(&(optlist[noptlist++]),"HPUXPRE65");
  10281. #endif /* HPUXPRE65 */
  10282. #ifdef DGUX
  10283.     makestr(&(optlist[noptlist++]),"DGUX");
  10284. #endif /* DGUX */
  10285. #ifdef DGUX430
  10286.     makestr(&(optlist[noptlist++]),"DGUX430");
  10287. #endif /* DGUX430 */
  10288. #ifdef DGUX540
  10289.     makestr(&(optlist[noptlist++]),"DGUX540");
  10290. #endif /* DGUX540 */
  10291. #ifdef DGUX543
  10292.     makestr(&(optlist[noptlist++]),"DGUX543");
  10293. #endif /* DGUX543 */
  10294. #ifdef DGUX54410
  10295.     makestr(&(optlist[noptlist++]),"DGUX54410");
  10296. #endif /* DGUX54410 */
  10297. #ifdef DGUX54411
  10298.     makestr(&(optlist[noptlist++]),"DGUX54411");
  10299. #endif /* DGUX54411 */
  10300. #ifdef sony_news
  10301.     makestr(&(optlist[noptlist++]),"sony_news");
  10302. #endif /* sony_news */
  10303. #ifdef CIE
  10304.     makestr(&(optlist[noptlist++]),"CIE");
  10305. #endif /* CIE */
  10306. #ifdef XENIX
  10307.     makestr(&(optlist[noptlist++]),"XENIX");
  10308. #endif /* XENIX */
  10309. #ifdef SCO_XENIX
  10310.     makestr(&(optlist[noptlist++]),"SCO_XENIX");
  10311. #endif /* SCO_XENIX */
  10312. #ifdef ISIII
  10313.     makestr(&(optlist[noptlist++]),"ISIII");
  10314. #endif /* ISIII */
  10315. #ifdef I386IX
  10316.     makestr(&(optlist[noptlist++]),"I386IX");
  10317. #endif /* I386IX */
  10318. #ifdef RTU
  10319.     makestr(&(optlist[noptlist++]),"RTU");
  10320. #endif /* RTU */
  10321. #ifdef PROVX1
  10322.     makestr(&(optlist[noptlist++]),"PROVX1");
  10323. #endif /* PROVX1 */
  10324. #ifdef PYRAMID
  10325.     makestr(&(optlist[noptlist++]),"PYRAMID");
  10326. #endif /* PYRAMID */
  10327. #ifdef TOWER1
  10328.     makestr(&(optlist[noptlist++]),"TOWER1");
  10329. #endif /* TOWER1 */
  10330. #ifdef UTEK
  10331.     makestr(&(optlist[noptlist++]),"UTEK");
  10332. #endif /* UTEK */
  10333. #ifdef ZILOG
  10334.     makestr(&(optlist[noptlist++]),"ZILOG");
  10335. #endif /* ZILOG */
  10336. #ifdef TRS16
  10337.     makestr(&(optlist[noptlist++]),"TRS16");
  10338. #endif /* TRS16 */
  10339. #ifdef MINIX
  10340.     makestr(&(optlist[noptlist++]),"MINIX");
  10341. #endif /* MINIX */
  10342. #ifdef C70
  10343.     makestr(&(optlist[noptlist++]),"C70");
  10344. #endif /* C70 */
  10345. #ifdef AIXPS2
  10346.     makestr(&(optlist[noptlist++]),"AIXPS2");
  10347. #endif /* AIXPS2 */
  10348. #ifdef AIXRS
  10349.     makestr(&(optlist[noptlist++]),"AIXRS");
  10350. #endif /* AIXRS */
  10351. #ifdef UTSV
  10352.     makestr(&(optlist[noptlist++]),"UTSV");
  10353. #endif /* UTSV */
  10354. #ifdef ATTSV
  10355.     makestr(&(optlist[noptlist++]),"ATTSV");
  10356. #endif /* ATTSV */
  10357. #ifdef SVR3
  10358.     makestr(&(optlist[noptlist++]),"SVR3");
  10359. #endif /* SVR3 */
  10360. #ifdef SVR4
  10361.     makestr(&(optlist[noptlist++]),"SVR4");
  10362. #endif /* SVR4 */
  10363. #ifdef DELL_SVR4
  10364.     makestr(&(optlist[noptlist++]),"DELL_SVR4");
  10365. #endif /* DELL_SVR4 */
  10366. #ifdef ICL_SVR4
  10367.     makestr(&(optlist[noptlist++]),"ICL_SVR4");
  10368. #endif /* ICL_SVR4 */
  10369. #ifdef OSF
  10370.     makestr(&(optlist[noptlist++]),"OSF");
  10371. #endif /* OSF */
  10372. #ifdef OSF1
  10373.     makestr(&(optlist[noptlist++]),"OSF1");
  10374. #endif /* OSF1 */
  10375. #ifdef __OSF
  10376.     makestr(&(optlist[noptlist++]),"__OSF");
  10377. #endif /* __OSF */
  10378. #ifdef __OSF__
  10379.     makestr(&(optlist[noptlist++]),"__OSF__");
  10380. #endif /* __OSF__ */
  10381. #ifdef __osf__
  10382.     makestr(&(optlist[noptlist++]),"__osf__");
  10383. #endif /* __osf__ */
  10384. #ifdef __OSF1
  10385.     makestr(&(optlist[noptlist++]),"__OSF1");
  10386. #endif /* __OSF1 */
  10387. #ifdef __OSF1__
  10388.     makestr(&(optlist[noptlist++]),"__OSF1__");
  10389. #endif /* __OSF1__ */
  10390. #ifdef PTX
  10391.     makestr(&(optlist[noptlist++]),"PTX");
  10392. #endif /* PTX */
  10393. #ifdef POSIX
  10394.     makestr(&(optlist[noptlist++]),"POSIX");
  10395. #endif /* POSIX */
  10396. #ifdef BSD44ORPOSIX
  10397.     makestr(&(optlist[noptlist++]),"BSD44ORPOSIX");
  10398. #endif /* BSD44ORPOSIX */
  10399. #ifdef SVORPOSIX
  10400.     makestr(&(optlist[noptlist++]),"SVORPOSIX");
  10401. #endif /* SVORPOSIX */
  10402. #ifdef SVR4ORPOSIX
  10403.     makestr(&(optlist[noptlist++]),"SVR4ORPOSIX");
  10404. #endif /* SVR4ORPOSIX */
  10405. #ifdef OS2ORVMS
  10406.     makestr(&(optlist[noptlist++]),"OS2ORVMS");
  10407. #endif /* OS2ORVMS */
  10408. #ifdef OS2ORUNIX
  10409.     makestr(&(optlist[noptlist++]),"OS2ORUNIX");
  10410. #endif /* OS2ORUNIX */
  10411. #ifdef VMSORUNIX
  10412.     makestr(&(optlist[noptlist++]),"VMSORUNIX");
  10413. #endif /* VMSORUNIX */
  10414. #ifdef _POSIX_SOURCE
  10415.     makestr(&(optlist[noptlist++]),"_POSIX_SOURCE");
  10416. #endif /* _POSIX_SOURCE */
  10417. #ifdef _XOPEN_SOURCE
  10418.     makestr(&(optlist[noptlist++]),"_XOPEN_SOURCE");
  10419. #endif
  10420. #ifdef _ALL_SOURCE
  10421.     makestr(&(optlist[noptlist++]),"_ALL_SOURCE");
  10422. #endif
  10423. #ifdef _SVID3
  10424.     makestr(&(optlist[noptlist++]),"_SVID3");
  10425. #endif /* _SVID3 */
  10426. #ifdef Plan9
  10427.     makestr(&(optlist[noptlist++]),"Plan9");
  10428. #endif /* Plan9 */
  10429. #ifdef SOLARIS
  10430.     makestr(&(optlist[noptlist++]),"SOLARIS");
  10431. #ifdef SOLARIS24
  10432.     makestr(&(optlist[noptlist++]),"SOLARIS24");
  10433. #endif /* SOLARIS24 */
  10434. #ifdef SOLARIS25
  10435.     makestr(&(optlist[noptlist++]),"SOLARIS25");
  10436. #endif /* SOLARIS25 */
  10437. #ifdef SOLARIS26
  10438.     makestr(&(optlist[noptlist++]),"SOLARIS26");
  10439. #endif /* SOLARIS26 */
  10440. #ifdef SOLARIS7
  10441.     makestr(&(optlist[noptlist++]),"SOLARIS7");
  10442. #endif /* SOLARIS7 */
  10443. #ifdef SOLARIS8
  10444.     makestr(&(optlist[noptlist++]),"SOLARIS8");
  10445. #endif /* SOLARIS8 */
  10446. #endif /* SOLARIS */
  10447.  
  10448. #ifdef SUNOS4
  10449.     makestr(&(optlist[noptlist++]),"SUNOS4");
  10450. #endif /* SUNOS4 */
  10451. #ifdef SUN4S5
  10452.     makestr(&(optlist[noptlist++]),"SUN4S5");
  10453. #endif /* SUN4S5 */
  10454. #ifdef IRIX
  10455.     makestr(&(optlist[noptlist++]),"IRIX");
  10456. #endif /* IRIX */
  10457. #ifdef ENCORE
  10458.     makestr(&(optlist[noptlist++]),"ENCORE");
  10459. #endif /* ENCORE */
  10460. #ifdef ultrix
  10461.     makestr(&(optlist[noptlist++]),"ultrix");
  10462. #endif
  10463. #ifdef sxaE50
  10464.     makestr(&(optlist[noptlist++]),"sxaE50");
  10465. #endif
  10466. #ifdef mips
  10467.     makestr(&(optlist[noptlist++]),"mips");
  10468. #endif
  10469. #ifdef MIPS
  10470.     makestr(&(optlist[noptlist++]),"MIPS");
  10471. #endif
  10472. #ifdef vax
  10473.     makestr(&(optlist[noptlist++]),"vax");
  10474. #endif
  10475. #ifdef VAX
  10476.     makestr(&(optlist[noptlist++]),"VAX");
  10477. #endif
  10478. #ifdef alpha
  10479.     makestr(&(optlist[noptlist++]),"alpha");
  10480. #endif
  10481. #ifdef ALPHA
  10482.     makestr(&(optlist[noptlist++]),"ALPHA");
  10483. #endif
  10484. #ifdef __ALPHA
  10485.     makestr(&(optlist[noptlist++]),"__ALPHA");
  10486. #endif
  10487. #ifdef __alpha
  10488.     makestr(&(optlist[noptlist++]),"__alpha");
  10489. #endif
  10490. #ifdef __AXP
  10491.     makestr(&(optlist[noptlist++]),"__AXP");
  10492. #endif
  10493. #ifdef AXP
  10494.     makestr(&(optlist[noptlist++]),"AXP");
  10495. #endif
  10496. #ifdef axp
  10497.     makestr(&(optlist[noptlist++]),"axp");
  10498. #endif
  10499. #ifdef __ALPHA__
  10500.     makestr(&(optlist[noptlist++]),"__ALPHA__");
  10501. #endif
  10502. #ifdef __alpha__
  10503.     makestr(&(optlist[noptlist++]),"__alpha__");
  10504. #endif
  10505. #ifdef sun
  10506.     makestr(&(optlist[noptlist++]),"sun");
  10507. #endif
  10508. #ifdef sun3
  10509.     makestr(&(optlist[noptlist++]),"sun3");
  10510. #endif
  10511. #ifdef sun386
  10512.     makestr(&(optlist[noptlist++]),"sun386");
  10513. #endif
  10514. #ifdef _SUN
  10515.     makestr(&(optlist[noptlist++]),"_SUN");
  10516. #endif
  10517. #ifdef sun4
  10518.     makestr(&(optlist[noptlist++]),"sun4");
  10519. #endif
  10520. #ifdef sparc
  10521.     makestr(&(optlist[noptlist++]),"sparc");
  10522. #endif
  10523. #ifdef _CRAY
  10524.     makestr(&(optlist[noptlist++]),"_CRAY");
  10525. #endif /* _CRAY */
  10526. #ifdef NEXT33
  10527.     makestr(&(optlist[noptlist++]),"NEXT33");
  10528. #endif
  10529. #ifdef NEXT
  10530.     makestr(&(optlist[noptlist++]),"NEXT");
  10531. #endif
  10532. #ifdef NeXT
  10533.     makestr(&(optlist[noptlist++]),"NeXT");
  10534. #endif
  10535. #ifdef MACH
  10536.     makestr(&(optlist[noptlist++]),"MACH");
  10537. #endif
  10538. #ifdef sgi
  10539.     makestr(&(optlist[noptlist++]),"sgi");
  10540. #endif
  10541. #ifdef M_SYS5
  10542.     makestr(&(optlist[noptlist++]),"M_SYS5");
  10543. #endif
  10544. #ifdef __SYSTEM_FIVE
  10545.     makestr(&(optlist[noptlist++]),"__SYSTEM_FIVE");
  10546. #endif
  10547. #ifdef sysV
  10548.     makestr(&(optlist[noptlist++]),"sysV");
  10549. #endif
  10550. #ifdef M_XENIX                          /* SCO Xenix V and UNIX/386 */
  10551.     makestr(&(optlist[noptlist++]),"M_XENIX");
  10552. #endif
  10553. #ifdef M_UNIX                           /* SCO UNIX */
  10554.     makestr(&(optlist[noptlist++]),"M_UNIX");
  10555. #endif
  10556. #ifdef _M_UNIX                          /* SCO UNIX 3.2v4 = ODT 2.0 */
  10557.     makestr(&(optlist[noptlist++]),"_M_UNIX");
  10558. #endif
  10559. #ifdef CK_SCOV5
  10560.     makestr(&(optlist[noptlist++]),"CK_SCOV5");
  10561. #endif
  10562. #ifdef SCO_OSR504
  10563.     makestr(&(optlist[noptlist++]),"SCO_OSR504");
  10564. #endif
  10565. #ifdef M_IA64
  10566.     makestr(&(optlist[noptlist++]),"M_IA64");
  10567. #endif
  10568. #ifdef _M_IA64
  10569.     makestr(&(optlist[noptlist++]),"_M_IA64");
  10570. #endif
  10571. #ifdef ia64
  10572.     makestr(&(optlist[noptlist++]),"ia64");
  10573. #endif
  10574. #ifdef _ia64
  10575.     makestr(&(optlist[noptlist++]),"_ia64");
  10576. #endif
  10577. #ifdef _ia64_
  10578.     makestr(&(optlist[noptlist++]),"_ia64_");
  10579. #endif
  10580. #ifdef M_I686
  10581.     makestr(&(optlist[noptlist++]),"M_I686");
  10582. #endif
  10583. #ifdef _M_I686
  10584.     makestr(&(optlist[noptlist++]),"_M_I686");
  10585. #endif
  10586. #ifdef i686
  10587.     makestr(&(optlist[noptlist++]),"i686");
  10588. #endif
  10589. #ifdef M_I586
  10590.     makestr(&(optlist[noptlist++]),"M_I586");
  10591. #endif
  10592. #ifdef _M_I586
  10593.     makestr(&(optlist[noptlist++]),"_M_I586");
  10594. #endif
  10595. #ifdef i586
  10596.     makestr(&(optlist[noptlist++]),"i586");
  10597. #endif
  10598. #ifdef M_I486
  10599.     makestr(&(optlist[noptlist++]),"M_I486");
  10600. #endif
  10601. #ifdef _M_I486
  10602.     makestr(&(optlist[noptlist++]),"_M_I486");
  10603. #endif
  10604. #ifdef i486
  10605.     makestr(&(optlist[noptlist++]),"i486");
  10606. #endif
  10607. #ifdef M_I386
  10608.     makestr(&(optlist[noptlist++]),"M_I386");
  10609. #endif
  10610. #ifdef _M_I386
  10611.     makestr(&(optlist[noptlist++]),"_M_I386");
  10612. #endif
  10613. #ifdef i386
  10614.     makestr(&(optlist[noptlist++]),"i386");
  10615. #endif
  10616. #ifdef i286
  10617.     makestr(&(optlist[noptlist++]),"i286");
  10618. #endif
  10619. #ifdef M_I286
  10620.     makestr(&(optlist[noptlist++]),"M_I286");
  10621. #endif
  10622. #ifdef mc68000
  10623.     makestr(&(optlist[noptlist++]),"mc68000");
  10624. #endif
  10625. #ifdef mc68010
  10626.     makestr(&(optlist[noptlist++]),"mc68010");
  10627. #endif
  10628. #ifdef mc68020
  10629.     makestr(&(optlist[noptlist++]),"mc68020");
  10630. #endif
  10631. #ifdef mc68030
  10632.     makestr(&(optlist[noptlist++]),"mc68030");
  10633. #endif
  10634. #ifdef mc68040
  10635.     makestr(&(optlist[noptlist++]),"mc68040");
  10636. #endif
  10637. #ifdef M_68000
  10638.     makestr(&(optlist[noptlist++]),"M_68000");
  10639. #endif
  10640. #ifdef M_68010
  10641.     makestr(&(optlist[noptlist++]),"M_68010");
  10642. #endif
  10643. #ifdef M_68020
  10644.     makestr(&(optlist[noptlist++]),"M_68020");
  10645. #endif
  10646. #ifdef M_68030
  10647.     makestr(&(optlist[noptlist++]),"M_68030");
  10648. #endif
  10649. #ifdef M_68040
  10650.     makestr(&(optlist[noptlist++]),"M_68040");
  10651. #endif
  10652. #ifdef m68k
  10653.     makestr(&(optlist[noptlist++]),"m68k");
  10654. #endif
  10655. #ifdef m88k
  10656.     makestr(&(optlist[noptlist++]),"m88k");
  10657. #endif
  10658. #ifdef pdp11
  10659.     makestr(&(optlist[noptlist++]),"pdp11");
  10660. #endif
  10661. #ifdef iAPX
  10662.     makestr(&(optlist[noptlist++]),"iAPX");
  10663. #endif
  10664. #ifdef hpux
  10665.     makestr(&(optlist[noptlist++]),"hpux");
  10666. #endif
  10667. #ifdef __hpux
  10668.     makestr(&(optlist[noptlist++]),"__hpux");
  10669. #endif
  10670. #ifdef __hp9000s800
  10671.     makestr(&(optlist[noptlist++]),"__hp9000s800");
  10672. #endif
  10673. #ifdef __hp9000s700
  10674.     makestr(&(optlist[noptlist++]),"__hp9000s700");
  10675. #endif
  10676. #ifdef __hp9000s500
  10677.     makestr(&(optlist[noptlist++]),"__hp9000s500");
  10678. #endif
  10679. #ifdef __hp9000s300
  10680.     makestr(&(optlist[noptlist++]),"__hp9000s300");
  10681. #endif
  10682. #ifdef __hp9000s200
  10683.     makestr(&(optlist[noptlist++]),"__hp9000s200");
  10684. #endif
  10685. #ifdef AIX
  10686.     makestr(&(optlist[noptlist++]),"AIX");
  10687. #endif
  10688. #ifdef _AIXFS
  10689.     makestr(&(optlist[noptlist++]),"_AIXFS");
  10690. #endif
  10691. #ifdef u370
  10692.     makestr(&(optlist[noptlist++]),"u370");
  10693. #endif
  10694. #ifdef u3b
  10695.     makestr(&(optlist[noptlist++]),"u3b");
  10696. #endif
  10697. #ifdef u3b2
  10698.     makestr(&(optlist[noptlist++]),"u3b2");
  10699. #endif
  10700. #ifdef multimax
  10701.     makestr(&(optlist[noptlist++]),"multimax");
  10702. #endif
  10703. #ifdef balance
  10704.     makestr(&(optlist[noptlist++]),"balance");
  10705. #endif
  10706. #ifdef ibmrt
  10707.     makestr(&(optlist[noptlist++]),"ibmrt");
  10708. #endif
  10709. #ifdef _IBMRT
  10710.     makestr(&(optlist[noptlist++]),"_IBMRT");
  10711. #endif
  10712. #ifdef ibmrs6000
  10713.     makestr(&(optlist[noptlist++]),"ibmrs6000");
  10714. #endif
  10715. #ifdef _AIX
  10716.     makestr(&(optlist[noptlist++]),"_AIX");
  10717. #endif /* _AIX */
  10718. #ifdef _IBMR2
  10719.     makestr(&(optlist[noptlist++]),"_IBMR2");
  10720. #endif
  10721. #ifdef UNIXWARE
  10722.     makestr(&(optlist[noptlist++]),"UNIXWARE");
  10723. #endif
  10724. #ifdef QNX
  10725.     makestr(&(optlist[noptlist++]),"QNX");
  10726. #ifdef __QNX__
  10727.     makestr(&(optlist[noptlist++]),"__QNX__");
  10728. #ifdef __16BIT__
  10729.     makestr(&(optlist[noptlist++]),"__16BIT__");
  10730. #endif
  10731. #ifdef CK_QNX16
  10732.     makestr(&(optlist[noptlist++]),"CK_QNX16");
  10733. #endif
  10734. #ifdef __32BIT__
  10735.     makestr(&(optlist[noptlist++]),"__32BIT__");
  10736. #endif
  10737. #ifdef CK_QNX32
  10738.     makestr(&(optlist[noptlist++]),"CK_QNX32");
  10739. #endif
  10740. #endif /* __QNX__ */
  10741. #endif /* QNX */
  10742.  
  10743. #ifdef QNX6
  10744.     makestr(&(optlist[noptlist++]),"QNX6");
  10745. #endif /* QNX6 */
  10746.  
  10747. #ifdef NEUTRINO
  10748.     makestr(&(optlist[noptlist++]),"NEUTRINO");
  10749. #endif /* NEUTRINO */
  10750.  
  10751. #ifdef __STRICT_BSD__
  10752.     makestr(&(optlist[noptlist++]),"__STRICT_BSD__");
  10753. #endif
  10754. #ifdef __STRICT_ANSI__
  10755.     makestr(&(optlist[noptlist++]),"__STRICT_ANSI__");
  10756. #endif
  10757. #ifdef _ANSI_C_SOURCE
  10758.     makestr(&(optlist[noptlist++]),"_ANSI_C_SOURCE");
  10759. #endif
  10760. #ifdef __STDC__
  10761.     makestr(&(optlist[noptlist++]),"__STDC__");
  10762. #endif
  10763. #ifdef __DECC
  10764.     makestr(&(optlist[noptlist++]),"__DECC");
  10765. #ifdef __DECC_VER
  10766.     sprintf(line,"__DECC_VER=%d",__DECC_VER); /* SAFE */
  10767.     makestr(&(optlist[noptlist++]),line);
  10768. #endif /* __DECC_VER */
  10769. #endif /* __DECC */
  10770. #ifdef __CRTL_VER
  10771.     sprintf(line,"__CRTL_VER=%d",__CRTL_VER); /* SAFE */
  10772.     makestr(&(optlist[noptlist++]),line);
  10773. #endif /* __CRTL_VER */
  10774. #ifdef __GNUC__                         /* gcc in ansi mode */
  10775.     makestr(&(optlist[noptlist++]),"__GNUC__");
  10776. #endif
  10777. #ifdef GNUC                             /* gcc in traditional mode */
  10778.     makestr(&(optlist[noptlist++]),"GNUC");
  10779. #endif
  10780. #ifdef __EGCS__                         /* egcs in ansi mode */
  10781.     makestr(&(optlist[noptlist++]),"__EGCS__");
  10782. #endif
  10783. #ifdef __egcs__                         /* egcs in ansi mode */
  10784.     makestr(&(optlist[noptlist++]),"__egcs__");
  10785. #endif
  10786. #ifdef __WATCOMC__
  10787.     makestr(&(optlist[noptlist++]),"__WATCOMC__");
  10788. #endif
  10789. #ifdef CK_ANSIC
  10790.     makestr(&(optlist[noptlist++]),"CK_ANSIC");
  10791. #endif
  10792. #ifdef CK_ANSILIBS
  10793.     makestr(&(optlist[noptlist++]),"CK_ANSILIBS");
  10794. #endif
  10795. #ifdef CKCONINTB4CB
  10796.     makestr(&(optlist[noptlist++]),"CKCONINTB4CB");
  10797. #endif /* CKCONINTB4CB */
  10798. #ifdef NOTERMCAP
  10799.     makestr(&(optlist[noptlist++]),"NOTERMCAP");
  10800. #endif /* NOTERMCAP */
  10801. #ifdef __GLIBC__
  10802.     makestr(&(optlist[noptlist++]),"__GLIBC__");
  10803. #endif
  10804. #ifdef _SC_JOB_CONTROL
  10805.     makestr(&(optlist[noptlist++]),"_SC_JOB_CONTROL");
  10806. #endif
  10807. #ifdef _POSIX_JOB_CONTROL
  10808.     makestr(&(optlist[noptlist++]),"_POSIX_JOB_CONTROL");
  10809. #endif
  10810. #ifdef SIG_I
  10811.     makestr(&(optlist[noptlist++]),"SIG_I");
  10812. #endif /* SIG_I */
  10813. #ifdef SIG_V
  10814.     makestr(&(optlist[noptlist++]),"SIG_V");
  10815. #endif /* SIG_V */
  10816. #ifdef CK_POSIX_SIG
  10817.     makestr(&(optlist[noptlist++]),"CK_POSIX_SIG");
  10818. #endif
  10819. #ifdef SVR3JC
  10820.     makestr(&(optlist[noptlist++]),"SVR3JC");
  10821. #endif
  10822. #ifdef _386BSD
  10823.     makestr(&(optlist[noptlist++]),"_386BSD");
  10824. #endif
  10825. #ifdef _BSD
  10826.     makestr(&(optlist[noptlist++]),"_BSD");
  10827. #endif
  10828. #ifdef USE_MEMCPY
  10829.     makestr(&(optlist[noptlist++]),"USE_MEMCPY");
  10830. #endif /* USE_MEMCPY */
  10831. #ifdef USE_LSTAT
  10832.     makestr(&(optlist[noptlist++]),"USE_LSTAT");
  10833. #endif /* USE_LSTAT */
  10834. #ifdef TERMIOX
  10835.     makestr(&(optlist[noptlist++]),"TERMIOX");
  10836. #endif /* TERMIOX */
  10837. #ifdef STERMIOX
  10838.     makestr(&(optlist[noptlist++]),"STERMIOX");
  10839. #endif /* STERMIOX */
  10840. #ifdef CK_CURSES
  10841.     makestr(&(optlist[noptlist++]),"CK_CURSES");
  10842. #endif /* CK_CURSES */
  10843. #ifdef CK_NEWTERM
  10844.     makestr(&(optlist[noptlist++]),"CK_NEWTERM");
  10845. #endif /* CK_NEWTERM */
  10846. #ifdef CK_WREFRESH
  10847.     makestr(&(optlist[noptlist++]),"CK_WREFRESH");
  10848. #endif /* CK_WREFRESH */
  10849. #ifdef CK_PCT_BAR
  10850.     makestr(&(optlist[noptlist++]),"CK_PCT_BAR");
  10851. #endif /* CK_PCT_BAR */
  10852. #ifdef CK_DTRCD
  10853.     makestr(&(optlist[noptlist++]),"CK_DTRCD");
  10854. #endif /* CK_DTRCD */
  10855. #ifdef CK_DTRCTS
  10856.     makestr(&(optlist[noptlist++]),"CK_DTRCTS");
  10857. #endif /* CK_DTRCTS */
  10858. #ifdef CK_RTSCTS
  10859.     makestr(&(optlist[noptlist++]),"CK_RTSCTS");
  10860. #endif /* CK_RTSCTS */
  10861. #ifdef POSIX_CRTSCTS
  10862.     makestr(&(optlist[noptlist++]),"POSIX_CRTSCTS");
  10863. #endif /* POSIX_CRTSCTS */
  10864. #ifdef FIXCRTSCTS
  10865.     makestr(&(optlist[noptlist++]),"FIXCRTSCTS");
  10866. #endif /* FIXCRTSCTS */
  10867. #ifdef HWPARITY
  10868.     makestr(&(optlist[noptlist++]),"HWPARITY");
  10869. #endif /* HWPARITY */
  10870. #ifdef CK_SYSINI
  10871. #ifdef CK_INI_A
  10872.     makestr(&(optlist[noptlist++]),"CK_INI_A");
  10873.     ckmakmsg(line,LINBUFSIZ,"CK_SYSINI=\"",CK_SYSINI,"\"",NULL);
  10874.     makestr(&(optlist[noptlist++]),line);
  10875. #else
  10876. #ifdef CK_INI_B
  10877.     makestr(&(optlist[noptlist++]),"CK_INI_B");
  10878.     ckmakmsg(line,LINBUFSIZ,"CK_SYSINI=\"",CK_SYSINI,"\"",NULL);
  10879.     makestr(&(optlist[noptlist++]),line);
  10880. #else
  10881.     makestr(&(optlist[noptlist++]),"CK_SYSINI");
  10882. #endif /* CK_INI_B */
  10883. #endif /* CK_INI_A */
  10884. #endif /* CK_DSYSINI */
  10885. #ifdef CK_DSYSINI
  10886.     makestr(&(optlist[noptlist++]),"CK_DSYSINI");
  10887. #endif /* CK_DSYSINI */
  10888. #ifdef CK_TTGWSIZ
  10889.     makestr(&(optlist[noptlist++]),"CK_TTGWSIZ");
  10890. #endif /* CK_TTGWSIZ */
  10891. #ifdef CK_NAWS
  10892.     makestr(&(optlist[noptlist++]),"CK_NAWS");
  10893. #endif /* CK_NAWS */
  10894. #ifdef MDMHUP
  10895.     makestr(&(optlist[noptlist++]),"MDMHUP");
  10896. #endif /* MDMHUP */
  10897. #ifdef HUP_CLOSE_POSIX
  10898.     makestr(&(optlist[noptlist++]),"HUP_CLOSE_POSIX");
  10899. #endif /* HUP_CLOSE_POSIX */
  10900. #ifdef NO_HUP_CLOSE_POSIX
  10901.     makestr(&(optlist[noptlist++]),"NO_HUP_CLOSE_POSIX");
  10902. #endif /* NO_HUP_CLOSE_POSIX */
  10903. #ifdef DCMDBUF
  10904.     makestr(&(optlist[noptlist++]),"DCMDBUF");
  10905. #endif /* DCMDBUF */
  10906. #ifdef CK_RECALL
  10907.     makestr(&(optlist[noptlist++]),"CK_RECALL");
  10908. #endif /* CK_RECALL */
  10909. #ifdef BROWSER
  10910.     makestr(&(optlist[noptlist++]),"BROWSER");
  10911. #endif /* BROWSER */
  10912. #ifdef CLSOPN
  10913.     makestr(&(optlist[noptlist++]),"CLSOPN");
  10914. #endif /* CLSOPN */
  10915. #ifdef STRATUS
  10916.     makestr(&(optlist[noptlist++]),"STRATUS");
  10917. #endif /* STRATUS */
  10918. #ifdef __VOS__
  10919.     makestr(&(optlist[noptlist++]),"__VOS__");
  10920. #endif /* __VOS__ */
  10921. #ifdef STRATUSX25
  10922.     makestr(&(optlist[noptlist++]),"STRATUSX25");
  10923. #endif /* STRATUSX25 */
  10924. #ifdef OS2MOUSE
  10925.     makestr(&(optlist[noptlist++]),"OS2MOUSE");
  10926. #endif /* OS2MOUSE */
  10927. #ifdef CK_REXX
  10928.     makestr(&(optlist[noptlist++]),"CK_REXX");
  10929. #endif /* CK_REXX */
  10930. #ifdef CK_TIMERS
  10931.     makestr(&(optlist[noptlist++]),"CK_TIMERS");
  10932. #endif /* CK_TIMERS */
  10933. #ifdef TTSPDLIST
  10934.     makestr(&(optlist[noptlist++]),"TTSPDLIST");
  10935. #endif /* TTSPDLIST */
  10936. #ifdef CK_PERMS
  10937.     makestr(&(optlist[noptlist++]),"CK_PERMS");
  10938. #endif /* CK_PERMS */
  10939. #ifdef CKTUNING
  10940.     makestr(&(optlist[noptlist++]),"CKTUNING");
  10941. #endif /* CKTUNING */
  10942. #ifdef NEWFTP
  10943.     makestr(&(optlist[noptlist++]),"NEWFTP");
  10944. #endif /* NEWFTP */
  10945. #ifdef SYSFTP
  10946.     makestr(&(optlist[noptlist++]),"SYSFTP");
  10947. #endif /* SYSFTP */
  10948. #ifdef NOFTP
  10949.     makestr(&(optlist[noptlist++]),"NOFTP");
  10950. #endif /* NOFTP */
  10951. #ifdef CKHTTP
  10952.     makestr(&(optlist[noptlist++]),"CKHTTP");
  10953. #endif /* CKHTTP */
  10954. #ifdef NOHTTP
  10955.     makestr(&(optlist[noptlist++]),"NOHTTP");
  10956. #endif /* NOHTTP */
  10957. #ifdef CKROOT
  10958.     makestr(&(optlist[noptlist++]),"CKROOT");
  10959. #endif /* CKROOT */
  10960. #ifdef CKREALPATH
  10961.     makestr(&(optlist[noptlist++]),"CKREALPATH");
  10962. #endif /* CKREALPATH */
  10963. #ifdef STREAMING
  10964.     makestr(&(optlist[noptlist++]),"STREAMING");
  10965. #endif /* STREAMING */
  10966. #ifdef UNPREFIXZERO
  10967.     makestr(&(optlist[noptlist++]),"UNPREFIXZERO");
  10968. #endif /* UNPREFIXZERO */
  10969. #ifdef CKREGEX
  10970.     makestr(&(optlist[noptlist++]),"CKREGEX");
  10971. #endif /* CKREGEX */
  10972. #ifdef ZXREWIND
  10973.     makestr(&(optlist[noptlist++]),"ZXREWIND");
  10974. #endif /* ZXREWIND */
  10975. #ifdef CKSYSLOG
  10976.     makestr(&(optlist[noptlist++]),"CKSYSLOG");
  10977. #endif /* CKSYSLOG */
  10978. #ifdef SYSLOGLEVEL
  10979.     sprintf(line,"SYSLOGLEVEL=%d",SYSLOGLEVEL); /* SAFE */
  10980.     makestr(&(optlist[noptlist++]),line);
  10981. #endif /* SYSLOGLEVEL */
  10982. #ifdef NOSEXP
  10983.     makestr(&(optlist[noptlist++]),"NOSEXP");
  10984. #endif /* NOSEXP */
  10985. #ifdef CKLEARN
  10986.     makestr(&(optlist[noptlist++]),"CKLEARN");
  10987. #else
  10988. #ifdef NOLOEARN
  10989.     makestr(&(optlist[noptlist++]),"NOLOEARN");
  10990. #endif /* NOLOEARN */
  10991. #endif /* CKLEARN */
  10992. #ifdef NOFLOAT
  10993.     makestr(&(optlist[noptlist++]),"NOFLOAT");
  10994. #else
  10995. #ifdef FNFLOAT
  10996.     makestr(&(optlist[noptlist++]),"FNFLOAT");
  10997. #endif /* FNFLOAT */
  10998. #ifdef CKFLOAT
  10999. #ifdef GFTIMER
  11000.     makestr(&(optlist[noptlist++]),"GFTIMER");
  11001. #endif /* GFTIMER */
  11002. #ifdef CKFLOAT_S
  11003.     ckmakmsg(line,LINBUFSIZ,"CKFLOAT=",CKFLOAT_S,NULL,NULL);
  11004.     makestr(&(optlist[noptlist++]),line);
  11005. #else
  11006.     makestr(&(optlist[noptlist++]),"CKFLOAT");
  11007. #endif /* CKFLOAT_S */
  11008. #endif /* CKFLOAT */
  11009. #endif /* NOFLOAT */
  11010.  
  11011. #ifdef SSH
  11012.     makestr(&(optlist[noptlist++]),"SSH");
  11013. #endif /* SSH */
  11014. #ifdef NETDLL
  11015.     makestr(&(optlist[noptlist++]),"NETDLL");
  11016. #endif /* NETDLL */
  11017. #ifdef NETFILE
  11018.     makestr(&(optlist[noptlist++]),"NETFILE");
  11019. #endif /* NETFILE */
  11020. #ifdef CK_TAPI
  11021.     makestr(&(optlist[noptlist++]),"CK_TAPI");
  11022. #endif /* CK_TAPI */
  11023. #ifdef CK_SSL
  11024.     makestr(&(optlist[noptlist++]),"CK_SSL");
  11025. #endif /* CK_SSL */
  11026.  
  11027.     debug(F101,"initoptlist noptlist","",noptlist);
  11028.     sh_sort(optlist,NULL,noptlist,0,0,0);
  11029. }
  11030.  
  11031. int
  11032. shofea() {
  11033.     int i;
  11034.     int flag = 0;
  11035.     int lines = 1;
  11036. #ifdef FNFLOAT
  11037.     extern int fp_digits, fp_rounding;
  11038. #endif /* FNFLOAT */
  11039.     extern int byteorder;
  11040.     printf("%s\n",versio);
  11041.     if (inserver)
  11042.       return(1);
  11043.     debug(F101,"shofea NOPTLIST","",NOPTLIST);
  11044.     initoptlist();
  11045.     debug(F101,"shofea noptlist","",noptlist);
  11046. #ifdef OS2
  11047. #ifdef NT
  11048. #ifdef _M_ALPHA
  11049.     printf("Microsoft Windows Operating Systems for Alpha CPUs.\n");
  11050. #else /* _M_ALPHA */
  11051. #ifdef _M_PPC
  11052.     printf("Microsoft Windows Operating Systems for PowerPC CPUs.\n");
  11053. #else /* _M_PPC */
  11054. #ifdef _M_MRX000
  11055.     printf("Microsoft Windows Operating Systems for MIPS CPUs.\n");
  11056. #else /* _M_MRX000 */
  11057. #ifdef _M_IX86
  11058.     printf("Microsoft Windows Operating Systems for 32-bit Intel CPUs.\n");
  11059. #else /* _M_IX86 */
  11060.     UNKNOWN WINDOWS PLATFORM
  11061. #endif /* _M_IX86 */
  11062. #endif /* _M_MRX000 */
  11063. #endif /* _M_PPC */
  11064. #endif /* _M_ALPHA */
  11065. #else /* NT */
  11066. #ifdef M_I286
  11067.     printf("IBM OS/2 16-bit.\n");
  11068. #else
  11069.     printf("IBM OS/2 32-bit.\n");
  11070. #endif /* M_I286 */
  11071. #endif /* NT */
  11072.     lines++;
  11073. #endif /* OS2 */
  11074.     printf("\n");
  11075.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11076.     printf("Major optional features included:\n");
  11077.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11078.  
  11079. #ifdef NETCONN
  11080.     printf(" Network support (type SHOW NET for further info)\n");
  11081.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11082. #ifdef IKS_OPTION
  11083.     printf(" Telnet Kermit Option\n");
  11084.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11085. #endif /* IKS_OPTION */
  11086. #ifdef CK_AUTHENTICATION
  11087.     printf(" Telnet Authentication Option\n");
  11088.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11089. #ifdef CK_KERBEROS
  11090. #ifdef KRB4
  11091. #ifdef KRB5
  11092.     printf(" Kerberos(TM) IV and Kerberos V authentication\n");
  11093.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11094. #else /* KRB5 */
  11095.     printf(" Kerberos(TM) IV authentication\n");
  11096.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11097. #endif /* KRB5 */
  11098. #else /* KRB4 */
  11099. #ifdef KRB5
  11100.     printf(" Kerberos(TM) V authentication\n");
  11101.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11102. #endif /* KRB5 */
  11103. #endif /* KRB4 */
  11104. #endif /* CK_KERBEROS */
  11105. #ifdef CK_SRP
  11106.     printf(" SRP(TM) (Secure Remote Password) authentication\n");
  11107.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11108. #endif /* CK_SRP */
  11109. #ifdef CK_SSL
  11110.     printf(" Secure Sockets Layer (SSL)\n");
  11111.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11112.     printf(" Transport Layer Security (TLS)\n");
  11113.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11114. #endif /* CK_SSL */
  11115. #ifdef SSHBUILTIN
  11116.     printf(" Secure Shell (SSH) [internal]\n");
  11117.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11118. #endif /* SSHBUILTIN */
  11119. #ifdef SSHCMD
  11120.     printf(" Secure Shell (SSH) [external]\n");
  11121.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11122. #endif /* SSHCMD */
  11123. #ifdef CK_ENCRYPTION
  11124.     printf(" Telnet Encryption Option\n");
  11125.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11126. #ifdef CK_DES
  11127.     printf(" DES Encryption\n");
  11128.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11129. #endif /* CK_DES */
  11130. #ifdef CK_CAST
  11131.     printf(" CAST Encryption\n");
  11132.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11133. #endif /* CK_CAST */
  11134. #endif /* CK_ENCRYPTION */
  11135. #endif /* CK_AUTHENTICATION */
  11136. #ifdef CK_FORWARD_X
  11137.     printf(" X Windows forwarding\n");
  11138.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11139. #endif /* CK_FORWARD_X */
  11140. #ifdef TN_COMPORT
  11141.     printf(" Telnet Remote Com Port Control Option\n");
  11142.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11143. #endif /* TN_COMPORT */
  11144. #ifdef CK_SOCKS
  11145. #ifdef CK_SOCKS5
  11146.     printf(" SOCKS 5\n");
  11147.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11148. #else /* CK_SOCKS5 */
  11149.     printf(" SOCKS 4\n");
  11150.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11151. #endif /* CK_SOCKS5 */
  11152. #endif /* CK_SOCKS */
  11153. #ifdef NEWFTP
  11154.     printf(" Built-in FTP client\n");
  11155.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11156. #endif /* NEWFTP */
  11157. #ifdef CKHTTP
  11158.     printf(" Built-in HTTP client\n");
  11159.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11160. #endif /* CKHTTP */
  11161. #endif /* NETCONN */
  11162.  
  11163. #ifdef CK_RTSCTS
  11164.     printf(" Hardware flow control\n");
  11165.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11166. #endif /* CK_RTSCTS */
  11167.  
  11168. #ifdef CK_XYZ
  11169. #ifdef XYZ_INTERNAL
  11170.     printf(" Built-in XYZMODEM protocols\n");
  11171. #else
  11172.     printf(" External XYZMODEM protocol support\n");
  11173. #endif /* XYZ_INTERNAL */
  11174.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11175. #endif /* CK_XYZ */
  11176.  
  11177. #ifndef NOCSETS
  11178.     printf(" Latin-1 (West European) character-set translation\n");
  11179.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11180. #ifdef LATIN2
  11181.     printf(" Latin-2 (East European) character-set translation\n");
  11182.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11183. #endif /* LATIN2 */
  11184. #ifdef CYRILLIC
  11185.     printf(" Cyrillic (Russian, Ukrainian, etc) character-set translation\n");
  11186.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11187. #endif /* CYRILLIC */
  11188. #ifdef GREEK
  11189.     printf(" Greek character-set translation\n");
  11190.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11191. #endif /* GREEK */
  11192. #ifdef HEBREW
  11193.     printf(" Hebrew character-set translation\n");
  11194.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11195. #endif /* HEBREW */
  11196. #ifdef KANJI
  11197.     printf(" Japanese character-set translation\n");
  11198.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11199. #endif /* KANJI */
  11200. #ifdef UNICODE
  11201.     printf(" Unicode character-set translation\n");
  11202.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11203. #endif /* UNICODE */
  11204. #ifdef CKOUNI
  11205.     if (isunicode())
  11206.       printf(" Unicode support for ISO-2022 Terminal Emulation\n");
  11207.     else
  11208.       printf(" Unicode translation for Terminal Character-Sets\n");
  11209.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11210. #endif /* CKOUNI */
  11211. #endif /* NOCSETS */
  11212.  
  11213. #ifdef NETPTY
  11214.     printf(" Pseudoterminal control\n");
  11215.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11216. #endif /* NETPTY */
  11217.  
  11218. #ifdef CK_REDIR
  11219.     printf(" REDIRECT command\n");
  11220.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11221. #endif /* CK_REDIR */
  11222.  
  11223. #ifdef CK_RESEND
  11224.     printf(" RESEND command\n");
  11225.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11226. #endif /* CK_RESEND */
  11227.  
  11228. #ifndef NOXFER
  11229. #ifdef CK_CURSES
  11230.     printf(" Fullscreen file transfer display\n");
  11231.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11232. #endif /* CK_CURSES */
  11233. #endif /* NOXFER */
  11234.  
  11235. #ifdef CK_SPEED
  11236.     printf(" Control-character unprefixing\n");
  11237.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11238. #endif /* CK_SPEED */
  11239.  
  11240. #ifdef STREAMING
  11241.     printf(" Streaming\n");
  11242.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11243. #endif /* STREAMING */
  11244.  
  11245. #ifdef CK_AUTODL
  11246.     printf(" Autodownload\n");
  11247.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11248. #endif /* CK_AUTODL */
  11249.  
  11250. #ifdef OS2MOUSE
  11251.     printf(" Mouse support\n");
  11252.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11253. #endif /* OS2MOUSE */
  11254.  
  11255. #ifdef CK_REXX
  11256.     printf(" REXX script language interface\n");
  11257.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11258. #endif /* CK_REXX */
  11259.  
  11260. #ifdef IKSD
  11261. #ifdef CK_LOGIN
  11262.     printf(" Internet Kermit Service with user login support\n");
  11263. #else /* CK_LOGIN */
  11264.     printf(" Internet Kermit Service without user login support\n");
  11265. #endif /* CK_LOGIN */
  11266.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11267. #endif /* IKSD */
  11268.  
  11269.     printf("\n");
  11270.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11271.     printf("Major optional features not included:\n");
  11272.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11273.  
  11274. #ifdef NOXFER
  11275.     printf(" No file-transfer protocols\n");
  11276.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11277.     flag = 1;
  11278. #else
  11279. #ifndef CK_CURSES
  11280. #ifndef MAC
  11281.     printf(" No fullscreen file transfer display\n");
  11282.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11283.     flag = 1;
  11284. #endif /* MAC */
  11285. #endif /* CK_CURSES */
  11286.  
  11287. #ifdef NOSERVER
  11288.     printf(" No server mode\n");
  11289.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11290.     flag = 1;
  11291. #endif /* NOSERVER */
  11292.  
  11293. #ifndef CK_SPEED
  11294.     printf(" No control-character unprefixing\n");
  11295.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11296.     flag = 1;
  11297. #endif /* CK_SPEED */
  11298.  
  11299. #ifndef STREAMING
  11300.     printf(" No streaming\n");
  11301.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11302.     flag = 1;
  11303. #endif /* STREAMING */
  11304.  
  11305. #ifndef CK_AUTODL
  11306.     printf(" No autodownload\n");
  11307.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11308.     flag = 1;
  11309. #endif /* CK_AUTODL */
  11310.  
  11311. #ifndef CK_XYZ
  11312.     printf(" No built-in XYZMODEM protocols\n");
  11313.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11314.     flag = 1;
  11315. #endif /* CK_XYZ */
  11316.  
  11317. #ifdef NOTLOG
  11318.     printf(" No transaction log\n");
  11319.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11320.     flag = 1;
  11321. #endif /* NOTLOG */
  11322. #endif /* NOXFER */
  11323.  
  11324. #ifdef NODEBUG
  11325.     printf(" No debugging\n");
  11326.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11327.     flag = 1;
  11328. #endif /* NODEBUG */
  11329.  
  11330. #ifdef NOHELP
  11331.     printf(" No built-in help\n");
  11332.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11333.     flag = 1;
  11334. #endif /* NOHELP */
  11335.  
  11336. #ifdef NOLOCAL
  11337.     printf(" No making connections\n");
  11338.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11339.     flag = 1;
  11340. #else
  11341. #ifndef NETCONN
  11342.     printf(" No network support\n");
  11343.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11344.     flag = 1;
  11345. #else /* NETCONN */
  11346. #ifndef IKS_OPTION
  11347.     printf(" No Telnet Kermit Option\n");
  11348.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11349.     flag = 1;
  11350. #endif /* IKS_OPTION */
  11351. #endif /* NETCONN */
  11352.  
  11353. #ifdef NOSSH
  11354.     printf(" No Secure Shell (SSH)\n");
  11355.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11356. #endif /* NOSSH */
  11357. #ifndef CK_AUTHENTICATION
  11358.     printf(" No Kerberos(TM) authentication\n");
  11359.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11360.     printf(" No SRP(TM) (Secure Remote Password) protocol\n");
  11361.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11362.     printf(" No Secure Sockets Layer (SSL) protocol\n");
  11363.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11364.     printf(" No Transport Layer Security (TLS) protocol\n");
  11365.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11366.     printf(" No encryption\n");
  11367.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11368.     flag = 1;
  11369. #else /* CK_AUTHENTICATION */
  11370. #ifndef CK_KERBEROS
  11371.     printf(" No Kerberos(TM) authentication\n");
  11372.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11373.     flag = 1;
  11374. #else /* CK_KERBEROS */
  11375. #ifndef KRB4
  11376.     printf(" No Kerberos(TM) IV authentication\n");
  11377.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11378.     flag = 1;
  11379. #endif /* KRB4 */
  11380. #ifndef KRB5
  11381.     printf(" No Kerberos(TM) V authentication\n");
  11382.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11383.     flag = 1;
  11384. #endif /* KRB5 */
  11385. #endif /* CK_KERBEROS */
  11386. #ifndef CK_SRP
  11387.     printf(" No SRP(TM) (Secure Remote Password) authentication\n");
  11388.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11389.     flag = 1;
  11390. #endif /* CK_SRP */
  11391. #ifndef CK_SSL
  11392.     printf(" No Secure Sockets Layer (SSL) protocol\n");
  11393.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11394.     printf(" No Transport Layer Security (TLS) protocol\n");
  11395.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11396.     flag = 1;
  11397. #endif /* CK_SSL */
  11398. #ifndef CK_ENCRYPTION
  11399.     printf(" No encryption\n");
  11400.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11401.     flag = 1;
  11402. #else /* CK_ENCRYPTION */
  11403. #ifndef OS2
  11404. #ifndef CK_DES
  11405.     printf(" No DES encryption\n");
  11406.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11407.     flag = 1;
  11408. #endif /* CK_DES */
  11409. #ifndef CK_CAST
  11410.     printf(" No CAST encryption\n");
  11411.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11412.     flag = 1;
  11413. #endif /* CK_CAST */
  11414. #endif /* OS2 */
  11415. #endif /* CK_ENCRYPTION */
  11416. #endif /* CK_AUTHENTICATION */
  11417. #ifndef CK_FORWARD_X
  11418.     printf(" No X Windows forwarding\n");
  11419.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11420. #endif /* CK_FORWARD_X */
  11421. #ifndef TN_COMPORT
  11422.     printf(" No Telnet Remote Com Port Control Option\n");
  11423.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11424. #endif /* TN_COMPORT */
  11425. #ifndef CK_SOCKS
  11426.     printf(" No SOCKS\n");
  11427.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11428. #endif /* CK_SOCKS */
  11429. #ifndef NEWFTP
  11430.     printf(" No built-in FTP client\n");
  11431.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11432. #endif /* NEWFTP */
  11433. #ifdef NOHTTP
  11434.     printf(" No built-in HTTP client\n");
  11435.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11436. #endif /* NOHTTP */
  11437.  
  11438. #ifdef NODIAL
  11439.     printf(" No DIAL command\n");
  11440.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11441.     flag = 1;
  11442. #else
  11443. #ifdef MINIDIAL
  11444.     printf(" Support for most modem types excluded\n");
  11445.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11446.     flag = 1;
  11447. #endif /* MINIDIAL */
  11448. #endif /* NODIAL */
  11449. #endif /* NOLOCAL */
  11450.  
  11451. #ifndef CK_RTSCTS
  11452. #ifndef MAC
  11453.     printf(" No hardware flow control\n");
  11454.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11455.     flag = 1;
  11456. #endif /* MAC */
  11457. #endif /* CK_RTSCTS */
  11458.  
  11459. #ifdef NOXMIT
  11460.     printf(" No TRANSMIT command\n");
  11461.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11462.     flag = 1;
  11463. #endif /* NOXMIT */
  11464.  
  11465. #ifdef NOSCRIPT
  11466.     printf(" No SCRIPT command\n");
  11467.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11468.     flag = 1;
  11469. #endif /* NOSCRIPT */
  11470.  
  11471. #ifdef NOSPL
  11472.     printf(" No script programming features\n");
  11473.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11474.     flag = 1;
  11475. #endif /* NOSPL */
  11476.  
  11477. #ifdef NOCSETS
  11478.     printf(" No character-set translation\n");
  11479.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11480.     flag = 1;
  11481. #else
  11482.  
  11483. #ifndef LATIN2
  11484.     printf(" No Latin-2 character-set translation\n");
  11485.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11486.     flag = 1;
  11487. #endif /* LATIN2 */
  11488.  
  11489. #ifdef NOGREEK
  11490.     printf(" No Greek character-set translation\n");
  11491.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11492.     flag = 1;
  11493. #endif /* NOGREEK */
  11494.  
  11495. #ifdef NOHEBREW
  11496.     printf(" No Hebrew character-set translation\n");
  11497.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11498.     flag = 1;
  11499. #endif /* NOHEBREW */
  11500.  
  11501. #ifdef NOUNICODE
  11502.     printf(" No Unicode character-set translation\n");
  11503.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11504.     flag = 1;
  11505. #endif /* NOUNICODE */
  11506.  
  11507. #ifdef NOCYRIL
  11508.     printf(" No Cyrillic character-set translation\n");
  11509.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11510.     flag = 1;
  11511. #endif /* NOCYRIL */
  11512.  
  11513. #ifndef KANJI
  11514.     printf(" No Kanji character-set translation\n");
  11515.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11516.     flag = 1;
  11517. #endif /* KANJI */
  11518. #endif /* NOCSETS */
  11519.  
  11520. #ifdef NOCMDL
  11521.     printf(" No command-line arguments\n");
  11522.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11523.     flag = 1;
  11524. #endif /* NOCMDL */
  11525.  
  11526. #ifdef NOPUSH
  11527.     printf(" No escape to system\n");
  11528.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11529.     flag = 1;
  11530. #endif /* NOPUSH */
  11531.  
  11532. #ifdef NOJC
  11533. #ifdef UNIX
  11534.     printf(" No UNIX job control\n");
  11535.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11536.     flag = 1;
  11537. #endif /* UNIX */
  11538. #endif /* NOJC */
  11539.  
  11540. #ifdef NOSETKEY
  11541.     printf(" No SET KEY command\n");
  11542.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11543.     flag = 1;
  11544. #endif /* NOSETKEY */
  11545.  
  11546. #ifndef CK_REDIR
  11547.     printf(" No REDIRECT or PIPE command\n");
  11548.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11549.     flag = 1;
  11550. #endif /* CK_REDIR */
  11551.  
  11552. #ifdef UNIX
  11553. #ifndef NETPTY
  11554.     printf(" No pseudoterminal control\n");
  11555.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11556.     flag = 1;
  11557. #endif /* NETPTY */
  11558. #endif /* UNIX */
  11559.  
  11560. #ifndef CK_RESEND
  11561.     printf(" No RESEND command\n");
  11562.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11563.     flag = 1;
  11564. #endif /* CK_RESEND */
  11565.  
  11566. #ifdef OS2
  11567. #ifdef __32BIT__
  11568. #ifndef OS2MOUSE
  11569.     printf(" No Mouse support\n");
  11570.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11571.     flag = 1;
  11572. #endif /* __32BIT__ */
  11573. #endif /* OS2 */
  11574. #endif /* OS2MOUSE */
  11575.  
  11576. #ifdef OS2
  11577. #ifndef NT
  11578. #ifndef CK_REXX
  11579.     printf(" No REXX script language interface\n");
  11580.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11581.     flag = 1;
  11582. #endif /* CK_REXX */
  11583. #endif /* NT */
  11584. #endif /* OS2 */
  11585.  
  11586. #ifndef IKSD
  11587.     printf(" No Internet Kermit Service\n");
  11588.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11589.     flag = 1;
  11590. #endif /* IKSD */
  11591.  
  11592.     if (flag == 0) {
  11593.         printf(" None\n");
  11594.         if (++lines > cmd_rows - 3)
  11595.           { if (!askmore()) return(1); else lines = 0; }
  11596.     }
  11597.     printf("\n");
  11598.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11599.  
  11600. #ifdef CK_UTSNAME
  11601.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11602.     printf("Host info:\n");
  11603.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11604.     printf(" Machine:    %s\n",unm_mch[0] ? unm_mch : "(unknown)");
  11605.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11606.     printf(" Model:      %s\n",unm_mod[0] ? unm_mod : "(unknown)");
  11607.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11608.     printf(" OS:         %s\n",unm_nam[0] ? unm_nam : "(unknown)");
  11609.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11610.     printf(" OS Release: %s\n",unm_rel[0] ? unm_rel : "(unknown)");
  11611.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11612.     printf(" OS Version: %s\n",unm_ver[0] ? unm_ver : "(unknown)");
  11613.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11614.     printf("\n");
  11615.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11616. #endif /* CK_UTSNAME */
  11617.  
  11618. /*
  11619.   Print compile-time (-D) options, as well as C preprocessor
  11620.   predefined symbols that might affect us...
  11621. */
  11622. #ifdef KTARGET
  11623.     {
  11624.         char * s;                       /* Makefile target */
  11625.         s = KTARGET;
  11626.         if (!s) s = "";
  11627.         if (!*s) s = "(unknown)";
  11628.         printf("\n");
  11629.         if (++lines > cmd_rows - 3) {
  11630.             if (!askmore()) return(1); else lines = 0;
  11631.         }
  11632.         printf("Target: %s\n", s);
  11633.         if (++lines > cmd_rows - 3) {
  11634.             if (!askmore()) return(1); else lines = 0;
  11635.         }
  11636.     }
  11637. #endif /* KTARGET */
  11638.  
  11639. #ifdef __VERSION__
  11640. #ifdef __GNUC__
  11641.     printf("GCC version: %s\n", __VERSION__);
  11642. #else
  11643.     printf("Compiler version: %s\n", __VERSION__);
  11644. #endif /* __GNUC__ */
  11645.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11646. #endif /* __VERSION__ */
  11647.  
  11648. #ifdef __DATE__                         /* GNU and other ANSI */
  11649. #ifdef __TIME__
  11650.     printf("Compiled %s %s, options:\n", __DATE__, __TIME__);
  11651. #else
  11652.     printf("Compiled %s, options:\n", __DATE__);
  11653. #endif /* __TIME__ */
  11654. #else /* !__DATE__ */
  11655.     printf("Compiler options:\n");
  11656. #endif /* __DATE__ */
  11657.     if (++lines > cmd_rows - 3) { if (!askmore()) return(1); else lines = 0; }
  11658.  
  11659.     for (i = 0; i < noptlist; i++)      /* Print sorted option list */
  11660.       if (!prtopt(&lines,optlist[i]))
  11661.         return(0);
  11662.  
  11663.     if (!prtopt(&lines,"")) return(0);  /* Start a new section */
  11664.  
  11665. /* Sizes of data types */
  11666.  
  11667.     ckmakmsg(line,
  11668.              LINBUFSIZ,
  11669.              "byte order: ",
  11670.              byteorder ? "little" : "big",
  11671.              " endian",
  11672.              NULL
  11673.              );
  11674.     if (!prtopt(&lines,line)) return(0);
  11675.     if (!prtopt(&lines,"")) return(0);  /* Start a new section */
  11676.     sprintf(line,"sizeofs: int=%ld",sizeof(int)); /* SAFE */
  11677.     if (!prtopt(&lines,line)) return(0);
  11678.     sprintf(line,"long=%ld",sizeof(long)); /* SAFE */
  11679.     if (!prtopt(&lines,line)) return(0);
  11680.     sprintf(line,"short=%ld",sizeof(short)); /* SAFE */
  11681.     if (!prtopt(&lines,line)) return(0);
  11682.     sprintf(line,"char=%ld",sizeof(char)); /* SAFE */
  11683.     if (!prtopt(&lines,line)) return(0);
  11684.     sprintf(line,"char*=%ld",sizeof(char *)); /* SAFE */
  11685.     if (!prtopt(&lines,line)) return(0);
  11686. #ifdef LONG_MAX
  11687.     sprintf(line,"LONG_MAX=%d",LONG_MAX); /* SAFE */
  11688. #endif /* LONG_MAX */
  11689. #ifdef CKFLOAT
  11690.     sprintf(line,"float=%ld",sizeof(float)); /* SAFE */
  11691.     if (!prtopt(&lines,line)) return(0);
  11692.     sprintf(line,"double=%ld",sizeof(double)); /* SAFE */
  11693.     if (!prtopt(&lines,line)) return(0);
  11694. #ifdef FNFLOAT
  11695.     if (!prtopt(&lines,"")) return(0);  /* Start a new section */
  11696.     if (!prtopt(&lines,"floating-point:")) return(0);
  11697.     sprintf(line,"precision=%d",fp_digits); /* SAFE */
  11698.     if (!prtopt(&lines,line)) return(0);
  11699.     sprintf(line,"rounding=%d",fp_rounding); /* SAFE */
  11700.     if (!prtopt(&lines,line)) return(0);
  11701. #endif /* FNFLOAT */
  11702. #endif /* CKFLOAT */
  11703.  
  11704.     prtopt(&lines,"");
  11705.     return(0);
  11706. }
  11707. #endif /* NOSHOW */
  11708. #endif /* NOICP */
  11709.