home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckocon.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  124KB  |  3,865 lines

  1. #ifdef NT
  2. char *connv = "Win32 CONNECT command 8.0.232, 20 Oct 2003";
  3. #else /* NT */
  4. char *connv = "OS/2 CONNECT command 8.0.232, 20 Oct 2003";
  5. #endif /* NT */
  6.  
  7. /* C K O C O N  --  Kermit CONNECT command for OS/2 and Windows */
  8.  
  9. /*
  10.   Authors: Frank da Cruz <fdc@columbia.edu>,
  11.              Kermit Project, Columbia University, New York City.
  12.            Jeffrey E Altman <jaltman@secure-endpoints.com>
  13.              Secure Endpoints Inc., New York City
  14.  
  15.   Copyright (C) 1985, 2004,
  16.     Trustees of Columbia University in the City of New York.
  17.     All rights reserved.
  18.  
  19.  
  20.   Originally adapted to OS/2 by Chris Adie of Edinburgh University, Scotland
  21.   (C.Adie@edinburgh.ac.uk), 1988, from the UNIX Kermit CONNECT module by Frank
  22.   da Cruz, Columbia University.  VT102 terminal emulation originally by Chris
  23.   Adie, 1988 ("If the code looks a bit funny sometimes, it's because it was
  24.   machine translated to C.")  (From what??)
  25.  
  26.   Adapted to c-Kermit 5A by Kai Uwe Rommel (rommel@informatik.tu-muenchen.de),
  27.   1992-93 (present address: rommel@ars.muc.de).
  28.  
  29.   Many changes by Frank da Cruz (fdc@columbia.edu): numerous bug fixes (tabs,
  30.   cursor/attributes save/restore, scrolling, keypad modes, etc), new SET
  31.   TERMINAL commands, TCP/IP TELNET support, printer support, character-set
  32.   support, APC escape sequence handling, print/dump screen, complete rewrite
  33.   of character attribute handling & screen reversal and rollback, addition of
  34.   VT220 and ANSI emulations, keyboard verbs, Compose key, Hebrew features,
  35.   Cyrillic features, context-sensitive popup screens, cosmetic improvements,
  36.   commentary, etc: 1992-present.  (Hopefully much of the funny-looking code
  37.   looks less funny now.)
  38.  
  39.   Massive improvements by Jeffrey Altman <jaltman@secure-endpoints.com>:
  40.   changes to keyboard handling, mouse support, ...: 1993 to present.
  41.   (191) new connect mode screen handling, scrollback, ...
  42.   (192) Win32 support, many new emulations, new keyboard scan codes, ... */
  43.  
  44. /*
  45.  * =============================#includes=====================================
  46.  */
  47.  
  48. #include "ckcdeb.h"             /* Typedefs, debug formats, etc */
  49. #include "ckcker.h"             /* Kermit definitions */
  50. #include "ckcasc.h"             /* ASCII character symbols */
  51. #include "ckcxla.h"             /* Character set translation */
  52. #include "ckcnet.h"             /* Network support */
  53. #include "ckuusr.h"             /* For terminal type definitions, etc. */
  54.  
  55. #include <ctype.h>              /* Character types */
  56. #include <io.h>                 /* File io function declarations */
  57. #include <process.h>            /* Process-control function declarations */
  58. #include <stdlib.h>             /* Standard library declarations */
  59. #include <sys/types.h>
  60. #include <sys/stat.h>
  61. #include <stdio.h>
  62. #include <string.h>
  63. #include <assert.h>
  64. #include <signal.h>
  65.  
  66. #ifdef NT
  67. #include <windows.h>
  68. #include <tapi.h>
  69. #include "ckntap.h"
  70. #include "cknwin.h"
  71. #ifdef KUI
  72. #include "kui/ikui.h"
  73. #endif /* KUI */
  74. #else /* NT */
  75. #ifdef OS2MOUSE
  76. #define INCL_MOU
  77. #endif /* OS2MOUSE */
  78.  
  79. #define INCL_WIN
  80. #define INCL_VIO
  81. #define INCL_ERRORS
  82. #define INCL_DOSPROCESS
  83. #define INCL_DOSSEMAPHORES
  84. #define INCL_DOSDEVIOCTL
  85. #define INCL_WINCLIPBOARD
  86. #define INCL_DOSDATETIME
  87. #include <os2.h>
  88. #undef COMMENT                /* COMMENT is defined in os2.h */
  89. #endif /* NT */
  90.  
  91. #include "ckowin.h"
  92. #include "ckcuni.h"
  93. #include "ckocon.h"             /* definitions common to console routines */
  94. #include "ckokey.h"
  95.  
  96. #ifdef CK_NETBIOS
  97. #include "ckonbi.h"
  98. extern UCHAR NetBiosRemote[] ;
  99. #endif /* CK_NETBIOS */
  100.  
  101.  
  102. /*
  103.  *
  104.  * =============================externals=====================================
  105.  */
  106. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR);  /* Character set xlate */
  107. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);  /* functions. */
  108. extern int language;            /* Current language. */
  109. extern struct langinfo langs[]; /* Language info. */
  110. extern struct csinfo fcsinfo[]; /* File character set info */
  111. extern int tcsr, tcsl;          /* Terminal character sets, remote & local. */
  112. extern int tcs_transp;
  113. extern struct _vtG G[4];         /* G0->G3 character sets */
  114.  
  115. extern int tnlm, tn_nlm;        /* Terminal newline mode, ditto for TELNET */
  116. extern int me_binary, u_binary; /* Telnet binary modes */
  117. extern int tt_crd;              /* Carriage-return display mode */
  118. extern int tt_lfd;              /* Line-feed display mode */
  119. extern int tt_bell;             /* How to handle incoming Ctrl-G characters */
  120. extern long     speed, vernum;
  121. extern int      local, escape, duplex, parity, flow, seslog, ttyfd,
  122.                 cmdmsk, cmask, sosi, xitsta, debses, mdmtyp, carrier, what;
  123. extern int      cflg, cnflg, stayflg, tt_escape;
  124. extern int      network, nettype, ttnproto;
  125. extern int     tt_status[VNUM] ;
  126. extern int     quiet, tn_exit, exitonclose;
  127. extern int     SysInited;
  128. #ifndef NOSPL
  129. extern struct mtab *mactab;             /* Main macro table */
  130. extern int nmac;                        /* Number of macros */
  131. #endif /* NOSPL */
  132.  
  133. extern KEY      *keymap;
  134. extern MACRO    *macrotab;
  135. extern char     ttname[];
  136. extern char *versio, *ckxsys;
  137.  
  138. #ifdef COMMENT
  139. extern HAB hab ;
  140. #endif /* COMMENT */
  141.  
  142. extern enum markmodes markmodeflag[VNUM] ;
  143.  
  144. /*
  145.  * =============================variables==============================
  146.  */
  147.  
  148. /*
  149.   These are RGB bits for the fore- and background colors in the PC's video
  150.   adapter, 3 bits for each color.  These default values can be changed by the
  151.   SET TERMINAL COLOR command (in ckuus7.c) or by CSI3x;4xm escape sequences
  152.   from the host.
  153. */
  154. extern unsigned char     colorhelp;
  155. extern unsigned char     colorcmd;
  156.  
  157. int     scrninitialized[VNUM] = {0,0,0} ;
  158. bool    scrollflag[VNUM]  = {0,0,0}, flipscrnflag[VNUM] = {0,0,0};
  159. extern bool scrollstatus[] ;
  160. bool    viewonly = FALSE ;              /* View only terminal mode */
  161. int     updmode         = TTU_FAST ;    /* Fast/Smooth scrolling */
  162. int     priority        = XYP_REG ;
  163.  
  164. int tn_bold = 0;                        /* TELNET negotiation bold */
  165. int esc_exit = 0;                       /* Escape back = exit */
  166. char * esc_msg;
  167.  
  168. long waittime;                          /* Timeout on CTS during CONNECT */
  169. #define INTERVAL 100L
  170.  
  171. char termessage[MAXTERMCOL];
  172. #ifdef CK_APC
  173. extern int apcactive;                   /* Application Program Command (APC) */
  174. #endif /* CK_APC */
  175. #ifdef IKSD
  176. extern int inserver;
  177. #endif /* IKSD */
  178. #ifdef KUI
  179. int gui_dialog = 1;
  180. #else
  181. int gui_dialog = 0;
  182. #endif /* KUI */
  183.  
  184. char * keydefptr = NULL;
  185. int keymac = 0;
  186. int keymacx = -1 ;
  187. int pmask = 0377 ;
  188. extern videobuffer vscrn[];
  189.  
  190. ascreen                                 /* For saving screens: */
  191.   vt100screen,                          /* terminal screen */
  192.   commandscreen ;                       /* OS/2 screen */
  193.  
  194. extern unsigned char                    /* Video attribute bytes */
  195.   attribute,                            /* Current video attribute byte */
  196.   savedattribute,                       /* Saved video attribute byte */
  197.   defaultattribute;                     /* Default video attribute byte */
  198.  
  199. int wherex[VNUM]={1,1,1};               /* Screen column, 1-based */
  200. int wherey[VNUM]={1,1,1};               /* Screen row, 1-based */
  201.  
  202. int ConnectMode ;
  203. int quitnow, hangnow, outshift, tcs, langsv;
  204.  
  205. #ifdef NT
  206. char answerback[81] = "K-95\r";         /* Default answerback */
  207. #else /* NT */
  208. char answerback[81] = "K-95 for OS/2\r";/* Default answerback */
  209. #endif /* NT */
  210. char useranswerbk[60] = "" ;            /* User answerback extension */
  211. int  safeanswerbk = TRUE ;              /* Require Kermit Product Prefix */
  212. char usertext[(MAXTERMCOL) + 1];        /* Status line and its parts */
  213. char statusline[MAXTERMCOL + 1];
  214. char exittext[(20) + 1];
  215. #define HLPTXTLEN 41
  216. char helptext[HLPTXTLEN];
  217. char filetext[(20) + 1];
  218. #define HSTNAMLEN 41
  219. char hostname[HSTNAMLEN];
  220.  
  221. #ifdef NT
  222. CK_CURSORINFO crsr_command={88,0,8,1};
  223. #else
  224. CK_CURSORINFO crsr_command={-88,0,8,1};
  225. #endif /* NT */
  226.  
  227. extern bool     cursoron[VNUM]  = {TRUE,TRUE,TRUE};       /* For speed, turn off when busy */
  228. extern bool     cursorena[VNUM] = {TRUE,TRUE,TRUE};       /* Cursor enabled / disabled */
  229.  
  230. extern bool     printon;                /* Printer is on */
  231. extern bool     xprint;                 /* Controller print in progress */
  232. extern bool     aprint;                 /* Auto print in progress */
  233. extern bool     uprint;                 /* User/transparent print in progress */
  234. extern bool     keylock;
  235. extern bool     deccolm;                /* 80/132-column mode */
  236. extern bool     decscnm;                /* Normal/reverse screen mode */
  237. extern struct _vtG G[4];                /* Graphic Set definitions */
  238.  
  239. /*
  240.   Terminal parameters that can also be set externally by SET commands.
  241.   Formerly they were declared and initialized here, and had different
  242.   names, as shown in the comments.  Now they are declared and
  243.   initialized in ckuus7.c.  - fdc
  244. */
  245. bool tt_hebrew = 0;                     /* Keyboard is in Hebrew mode */
  246.  
  247. /* SET TERMINAL values ... */
  248.  
  249. extern struct tt_info_rec tt_info[] ;   /* Indexed by terminal type */
  250. extern int max_tt;                      /* Highest terminal type */
  251.  
  252. extern int tt_arrow;                    /* Arrow-key mode */
  253. extern int tt_keypad;                   /* Keypad mode */
  254. extern int tt_wrap;                     /* Autowrap */
  255. extern int tt_type;                     /* Terminal type */
  256. extern int tt_type_mode;                /* Terminal type */
  257. extern int tt_cursor;                   /* Cursor type */
  258. extern int tt_answer;                   /* Answerback enabled/disabled */
  259. extern int tt_scrsize[];                /* Scrollback buffer size */
  260. extern int tt_roll[];                   /* Scrollback style */
  261. extern int tt_rows[];                   /* Screen rows */
  262. extern int tt_cols[];                   /* Screen columns */
  263. extern int tt_cols_usr;
  264. extern int tt_szchng[VNUM];
  265. extern int cmd_rows;                    /* Screen rows */
  266. extern int cmd_cols;                    /* Screen columns */
  267. extern int tt_ctstmo;                   /* CTS timeout */
  268. extern int tt_pacing;                   /* Output-pacing */
  269. extern int tt_updmode;                  /* Terminal Screen Update Mode */
  270. extern bool escapestatus[VNUM] ;        /* are we in ESCAPE mode? */
  271. /* extern int tt_idlesnd_tmo;           /* Idle Send Timeout, disabled */
  272. extern char * tt_idlesnd_str;           /* Idle Send String, none */
  273. extern int tt_idlelimit;                /* Auto-exit Connect when idle */
  274. extern int tt_idleact;
  275. extern int tt_timelimit;
  276. static time_t keypress_t=0;             /* Time of last keypress */
  277. static time_t idlesnd_t=0;              /* Time of last idle send */
  278. int escstate ;
  279. USHORT marginbot;                       /* Bottom of same, 1-based */
  280. int tt_async = 0;                       /* asynchronous connect mode? */
  281. int col_init = 0, row_init = 0;
  282. /*
  283.    For pushing back input characters,
  284.    e.g. converting 8-bit controls to 7-bit escape sequences.
  285. */
  286. int f_pushed = 0, c_pushed = 0, f_popped = 0;
  287.  
  288. unsigned char sgrcols[8] = {0, 4, 2, 6, 1, 5, 3, 7};
  289.  
  290. /* Function prototypes */
  291. #ifndef NOSETKEY
  292. /* Key names */
  293. char *keyname(unsigned long);           /* Names of keys, by scan code */
  294. extern vik_rec vik;
  295. #endif /* NOSETKEY */
  296.  
  297. /* Thread stuff... */
  298. #define THRDSTKSIZ      131072          /* Needed for Mouse Thread */
  299.  
  300. extern TID tidRdComWrtScr,
  301.     tidConKbdHandler,
  302.     tidTermScrnUpd;
  303.  
  304. extern BYTE vmode ;
  305.  
  306. int
  307.   oskipesc = 0,                         /* Esc seq recognizer for keys... */
  308.   os2_outesc = ES_NORMAL;
  309.  
  310. #ifndef NOLOCAL
  311. #ifndef NT
  312. #define CK_BORDER                       /* Allow border colors */
  313. #endif /* NT */
  314.  
  315. int cmd_border = -1;
  316.  
  317. void
  318. setborder() {
  319. #ifdef CK_BORDER
  320.     extern HVIO VioHandle ;
  321.     extern unsigned char borderattribute ;
  322.     VIOOVERSCAN vo;                     /* Set border (overscan) color */
  323.  
  324.     vo.cb = sizeof(vo);                 /* for terminal emulation window */
  325.     vo.type = 1;
  326.     vo.color = borderattribute ;
  327.     VioSetState((PVOID) &vo, VioHandle );
  328. #endif /* CK_BORDER */
  329. }
  330.  
  331. void
  332. saveborder() {                          /* Save command-screen border */
  333. #ifdef CK_BORDER
  334.     extern HVIO VioHandle ;
  335.     VIOOVERSCAN vo;
  336.     vo.cb = sizeof(vo);
  337.     vo.type = 1;
  338.     VioGetState((PVOID) &vo, VioHandle);
  339.     cmd_border = vo.color;
  340. #endif /* CK_BORDER */
  341. }
  342.  
  343. void
  344. restoreborder() {
  345. #ifdef CK_BORDER
  346.     extern HVIO VioHandle ;
  347.     VIOOVERSCAN vo;                     /* Restore command-screen border */
  348.     if (cmd_border < 0)                 /* None saved. */
  349.       return;
  350.     vo.cb = sizeof(vo);
  351.     vo.type = 1;
  352.     vo.color = cmd_border;
  353.     cmd_border = 0;
  354.     VioSetState((PVOID) &vo, VioHandle);
  355. #endif /* CK_BORDER */
  356. }
  357.  
  358. /* Save current status of screen */
  359. void
  360. SaveTermMode(int wherex, int wherey) {
  361.     debug(F101,"x_save wherex","",wherex);
  362.     debug(F101,"x_save wherey","",wherey);
  363. #ifndef KUI
  364.     if (GetMode( &vt100screen.mi ))
  365.         return;
  366. #endif /* KUI */
  367.     vt100screen.ox = wherex;
  368.     vt100screen.oy = wherey;
  369.     vt100screen.att = attribute;
  370.     vt100screen.scrncpy ;  /* not used for terminal mode */
  371. }
  372.  
  373. /* Restore a saved screen */
  374. void
  375. RestoreTermMode(void) {
  376.     extern int tt_modechg;
  377.     int omode = vmode ;
  378.  
  379. #ifndef KUI
  380.     if ( tt_modechg == TVC_ENA )
  381.         SetMode( &vt100screen.mi ) ;
  382.     else if ( tt_modechg == TVC_W95 ) {
  383.         CK_VIDEOMODEINFO wmi = vt100screen.mi ;
  384.         wmi.col = 80 ;
  385.         SetMode( &wmi ) ;
  386.     }
  387. #endif /* KUI */
  388.     vmode = VTERM ;
  389.     VscrnIsDirty(omode);
  390.     VscrnForceFullUpdate();
  391.     VscrnIsDirty(VTERM);
  392. }
  393.  
  394. /* Save current status of command screen */
  395. void
  396. SaveCmdMode(int wherex, int wherey) {
  397.     debug(F101,"x_save wherex","",wherex);
  398.     debug(F101,"x_save wherey","",wherey);
  399. #ifndef KUI
  400.     if (GetMode( &commandscreen.mi ))
  401.         return;
  402.     commandscreen.mi.row = (commandscreen.mi.row > MAXSCRNROW ?
  403.                              MAXSCRNROW : commandscreen.mi.row) ;
  404.     commandscreen.mi.col = (commandscreen.mi.col > MAXSCRNCOL ?
  405.                              MAXSCRNCOL : commandscreen.mi.col);
  406. #ifdef NT
  407.     commandscreen.mi.sbcol = commandscreen.mi.col;
  408.     commandscreen.mi.sbrow = commandscreen.mi.row;
  409. #endif /* NT */
  410. #endif /* KUI */
  411.     commandscreen.ox = wherex;
  412.     commandscreen.oy = wherey;
  413.     commandscreen.att = colorcmd;
  414. }
  415.  
  416. /* Restore a saved command screen */
  417. void
  418. RestoreCmdMode() {
  419.     extern int tt_modechg;
  420.     int omode = vmode ;
  421.  
  422. #ifndef KUI
  423.     if ( tt_modechg == TVC_ENA )
  424.         SetMode( &commandscreen.mi ) ;
  425.     else if ( tt_modechg == TVC_W95 ) {
  426.         CK_VIDEOMODEINFO wmi = commandscreen.mi ;
  427.         wmi.col = 80 ;
  428.         SetMode( &wmi ) ;
  429.     }
  430. #endif /* KUI */
  431. #ifdef COMMENT
  432.     colorcmd = commandscreen.att;
  433.     wherey[VTERM] = commandscreen.oy;
  434.     wherex[VTERM] = commandscreen.ox;
  435. #endif /* COMMENT */
  436.     debug(F101,"x_rest wherex","",commandscreen.ox);
  437.     debug(F101,"x_rest wherey","",commandscreen.oy);
  438.     SetCurPos( commandscreen.oy-1, commandscreen.ox-1 ) ;
  439.    /* lgotoxy no longer moves */
  440.    /* the physical cursor     */
  441.     vmode = VCMD ;
  442.     VscrnIsDirty(omode);
  443.     VscrnForceFullUpdate();
  444.     VscrnIsDirty(VCMD);
  445. }
  446. #endif /* NOLOCAL */
  447.  
  448. void                                    /* Push from CONNECT mode to OS/2 */
  449. os2push() {                             /* not just for CONNECT mode anymore */
  450. #ifndef NOPUSH
  451. #ifndef KUI
  452.     CK_VIDEOMODEINFO mi;
  453. #endif /* KUI */
  454.     int connectmode = IsConnectMode() ;
  455.     extern int nopush;
  456.     if ( nopush )
  457.     {
  458.         bleep( BP_WARN ) ;
  459.         return;
  460.     }
  461.  
  462. #ifndef KUI
  463.     if (GetMode(&mi))
  464.          return;
  465. #endif /* KUI */
  466.     if ( connectmode ) {
  467.         SaveTermMode(wherex[VTERM],wherey[VTERM]) ;
  468.         concooked();
  469. #ifdef NT
  470.         setint();
  471. #endif
  472.     }
  473.  
  474.     RequestScreenMutex(SEM_INDEFINITE_WAIT);
  475.     clearcmdscreen();
  476.  
  477.     if ( connectmode ) {
  478.         restorecursormode();
  479.         puts("Enter EXIT to return to Kermit-95 Connect Mode.");
  480.     }
  481.     else
  482.         puts("Enter EXIT to return to Kermit-95 Command Mode.");
  483.  
  484.     zshcmd("");
  485.  
  486.     if ( connectmode ) {
  487.         conraw();
  488.         connoi();
  489. #ifndef KUI
  490.         SetMode(&mi);
  491. #endif /* KUI */
  492.         setborder();                    /* Put back CONNECT screen border */
  493.         setcursormode();
  494.         RestoreTermMode();
  495.     }
  496.     ReleaseScreenMutex();
  497.  
  498.     if ( connectmode ) {
  499.         cursoron[VTERM] = FALSE ;      /* Force update just in case */
  500.         VscrnIsDirty(VTERM);
  501.     }
  502.     else
  503.         VscrnIsDirty(VCMD);
  504. #endif /* NOPUSH */
  505. }
  506.  
  507. /*---------------------------------------------------------------------------*/
  508. /* bleep                                                                     */
  509. /*---------------------------------------------------------------------------*/
  510. int beepfreq = DEF_BEEP_FREQ ;                  /* Beep Frequency */
  511. int beeptime = DEF_BEEP_TIME ;                  /* Beep Duration  */
  512.  
  513. void
  514. bleep(short int type) {
  515.     debug(F101,"bleep","",type);
  516. #ifdef IKSD
  517.     if ( inserver ) {
  518.         if ( ttyfd != -1 )
  519.             printf("%c",BEL);
  520.         return;
  521.     }
  522. #endif /* IKSD */
  523.  
  524. #ifndef IKSDONLY
  525.     switch(tt_bell) {                   /* Follows TERMINAL BELL setting. */
  526.     case XYB_AUD | XYB_BEEP:            /* AUDIBLE - BEEP */
  527.         switch (type) {
  528. #ifndef NT
  529.         case BP_NOTE:
  530.             DosBeep( WinQuerySysValue(HWND_DESKTOP,SV_NOTEFREQ),
  531.                      WinQuerySysValue(HWND_DESKTOP,SV_NOTEDURATION));
  532.             break;
  533.         case BP_WARN:
  534.             DosBeep( WinQuerySysValue(HWND_DESKTOP,SV_WARNINGFREQ),
  535.                      WinQuerySysValue(HWND_DESKTOP,SV_WARNINGDURATION));
  536.             break;
  537.         case BP_FAIL:
  538.             DosBeep( WinQuerySysValue(HWND_DESKTOP,SV_ERRORFREQ),
  539.                      WinQuerySysValue(HWND_DESKTOP,SV_ERRORDURATION));
  540.             break;
  541.         case BP_BEL:
  542.             DosBeep(beepfreq,beeptime);
  543.             break;
  544.         default:
  545.             DosBeep(DEF_BEEP_FREQ,DEF_BEEP_TIME);
  546. #else /* NT */
  547.         case BP_BEL:
  548.             Beep(beepfreq,beeptime);
  549.             break;
  550.         default:
  551.             Beep(DEF_BEEP_FREQ,DEF_BEEP_TIME ) ;
  552. #endif /* NT */
  553.         }
  554.         return;
  555.  
  556.       case XYB_AUD | XYB_SYS:       /* AUDIBLE - SYSTEM-SOUNDS */
  557.         switch (type) {
  558. #ifndef NT
  559.         case BP_NOTE:
  560.             WinAlarm(HWND_DESKTOP, WA_NOTE);
  561.             break;
  562.         case BP_WARN:
  563.             WinAlarm(HWND_DESKTOP, WA_WARNING);
  564.             break;
  565.         case BP_FAIL:
  566.         case BP_BEL:
  567.         default:
  568.             WinAlarm(HWND_DESKTOP, WA_ERROR);
  569.             break;
  570. #ifdef COMMENT
  571.         case BP_BEL:
  572.             DosBeep(beepfreq,beeptime);
  573.             break;
  574.         default:
  575.             DosBeep(DEF_BEEP_FREQ,DEF_BEEP_TIME);
  576. #endif /* COMMENT */
  577. #else /* NT */
  578.         case BP_NOTE:
  579.             MessageBeep( MB_ICONQUESTION );
  580.             break;
  581.         case BP_WARN:
  582.             MessageBeep( MB_ICONASTERISK );
  583.             break;
  584.         case BP_FAIL:
  585.         case BP_BEL:
  586.         default:
  587.             MessageBeep( MB_ICONEXCLAMATION );
  588.             break;
  589. #ifdef COMMENT
  590.         case BP_BEL:
  591.             Beep(beepfreq,beeptime);
  592.             break;
  593.         default:
  594.             MessageBeep(0xFFFFFFFF);            /* Standard Beep */
  595. #endif /* COMMENT */
  596. #endif /* NT */
  597.         }
  598.         return;
  599.  
  600.     case XYB_VIS:                               /* VISIBLE */
  601.         if ( IsConnectMode() ) {                /* in terminal mode */
  602.             if ( flipscrnflag[VTERM] )          /* Flash the screen */
  603.                 flipscrnflag[VTERM] = FALSE ;
  604.             else
  605.                 flipscrnflag[VTERM] = TRUE ;
  606.             VscrnForceFullUpdate();
  607.             VscrnIsDirty(VTERM);
  608.             msleep(250);                        /* for 250 msec */
  609.             if ( flipscrnflag[VTERM] )          /* Flash the screen */
  610.                 flipscrnflag[VTERM] = FALSE ;
  611.             else
  612.                 flipscrnflag[VTERM] = TRUE ;
  613.             VscrnForceFullUpdate();
  614.             VscrnIsDirty(VTERM);
  615.         }
  616.         else {                                  /* in command mode */
  617.             if ( flipscrnflag[VCMD] )           /* Flash the screen */
  618.                 flipscrnflag[VCMD] = FALSE ;
  619.             else
  620.                 flipscrnflag[VCMD] = TRUE ;
  621.             /* reversescreen(VTERM); */         /* Flash the screen */
  622.             VscrnForceFullUpdate();
  623.             VscrnIsDirty(VCMD);
  624.             msleep(250);                        /* for 250 msec */
  625.             if ( flipscrnflag[VCMD] )           /* Flash the screen */
  626.                 flipscrnflag[VCMD] = FALSE ;
  627.             else
  628.                 flipscrnflag[VCMD] = TRUE ;
  629.             /* reversescreen(VTERM); */         /* Flash the screen */
  630.             VscrnForceFullUpdate();
  631.             VscrnIsDirty(VCMD);
  632.         }
  633.         return;
  634.  
  635.       default:                          /* NONE or other */
  636.         return;
  637.     }
  638. #endif /* IKSDONLY */
  639. }
  640.  
  641. #ifndef NOLOCAL
  642. /*             */
  643. /* getcmdcolor */
  644. /*             */
  645. void
  646. getcmdcolor(void)
  647. {
  648. #ifndef KUI
  649.     viocell cell ;
  650.     USHORT  x,y ;
  651.     USHORT  length = 1;
  652.     GetCurPos( &x, &y ) ;
  653.     ReadCellStr( &cell, &length, x, y ) ;
  654.     colorcmd = cell.a ;
  655. #endif /* KUI */
  656. }
  657.  
  658. /*---------------------------------------------------------------------------*/
  659. /* clearcmdscreen                                                            */
  660. /*---------------------------------------------------------------------------*/
  661. void
  662. clearcmdscreen(void) {
  663.     viocell         cell ;
  664.  
  665.     ttgcwsz();
  666.     cell.c = ' ' ;
  667.     cell.a = colorcmd ;
  668.     WrtNCell(cell, cmd_cols * (cmd_rows+1), 0, 0);
  669.     SetCurPos( 0, 0 ) ;
  670. }
  671.  
  672. /*---------------------------------------------------------------------------*/
  673. /* clearscrollback                                                           */
  674. /*---------------------------------------------------------------------------*/
  675. void
  676. clearscrollback( BYTE vmode ) {
  677.     ULONG bufsize = VscrnGetBufferSize(vmode) ;
  678.  
  679.     VscrnSetBufferSize( vmode, 256 ) ;
  680.     VscrnSetBufferSize( vmode, bufsize ) ;
  681.     scrollstatus[vmode] = FALSE ;
  682.     scrollflag[vmode] = FALSE ;
  683.     cursoron[vmode] = FALSE ;
  684.     cleartermscreen(vmode) ;
  685. }
  686.  
  687. /*---------------------------------------------------------------------------*/
  688. /* cleartermscreen                                                               */
  689. /*---------------------------------------------------------------------------*/
  690. void
  691. cleartermscreen( BYTE vmode ) {
  692.     int             x,y ;
  693.     videoline *     line ;
  694.  
  695.     for ( y = 0 ; y < VscrnGetHeight(vmode) ; y++ ) {
  696.         line = VscrnGetLineFromTop(vmode,y) ;
  697.         line->width = VscrnGetWidth(vmode) ;
  698.         line->vt_line_attr = VT_LINE_ATTR_NORMAL ;
  699.         for ( x = 0 ; x < MAXTERMCOL ; x++ ) {
  700.             line->cells[x].c = ' ' ;
  701.             line->cells[x].a = vmode == VTERM ? attribute : colorcmd ;
  702.             line->vt_char_attrs[x] = VT_CHAR_ATTR_NORMAL ;
  703.             }
  704.         }
  705.     lgotoxy(vmode,1, 1);
  706.     if ( IsConnectMode() || vmode != VTERM )
  707.         VscrnIsDirty(vmode);
  708.     else {
  709.         vt100screen.ox = vt100screen.oy = 1 ;
  710.         }
  711. }
  712.  
  713. /* POPUPHELP  --  Give help message for connect.  */
  714. static int helpcol, helprow;
  715. static int helpwidth;
  716.  
  717. videopopup *
  718. helpstart(int w, int h, int gui) {               /* Start help window */
  719.     videopopup * pPopup = malloc(sizeof(videopopup)) ;
  720.  
  721.     if (pPopup == NULL)
  722.         return(NULL);
  723.  
  724. #ifdef KUI
  725.     if ( gui ) {
  726.         helpcol = 0;        
  727.         helprow = -1;
  728.         pPopup->width = w;
  729.         pPopup->height = h;
  730.         pPopup->gui = 1;
  731.     } else
  732. #endif /* KUI */
  733.     {
  734.         helpcol = helprow = 0 ;
  735.         pPopup->a = colorhelp ;
  736.         pPopup->width = w + 4 ;   /* 2 for border, plus 2 for padding */
  737.         pPopup->height = h + 2 ;  /* 2 for border */
  738.         pPopup->c[helprow][helpcol++] = 201; /* IBM upper left box corner double */
  739.         pPopup->gui = 0;
  740.         for ( helpcol ; helpcol < pPopup->width-1 ; helpcol++ )
  741.             pPopup->c[helprow][helpcol] = 205 ;
  742.                                              /* Center box bar horizontal double */
  743.         pPopup->c[helprow][helpcol] = 187;   /* Upper right box corner double */
  744.     }
  745.     return pPopup ;
  746. }
  747.  
  748. void
  749. helpline(videopopup *pPopup, char *s) {                 /* Add line to popup help */
  750.     int l;
  751.  
  752.     l = strlen(s);                      /* Length of this line */
  753.     helprow++;
  754.     helpcol=0;
  755.  
  756. #ifdef KUI
  757.     if ( pPopup->gui ) {
  758.         /* Add the string */
  759.         for ( helpcol ; helpcol < l && helpcol < pPopup->width; helpcol++ )
  760.             pPopup->c[helprow][helpcol] = s[helpcol] ;
  761.  
  762.         /* Pad with NUL */
  763.         for ( helpcol ; helpcol < pPopup->width ; helpcol++ )
  764.             pPopup->c[helprow][helpcol] = NUL;
  765.     } else
  766. #endif /* KUI */
  767.     {
  768.         pPopup->c[helprow][helpcol++] = 186;   /* IBM center bar vertical double */
  769.  
  770.         /* Add the string */
  771.         for ( helpcol ; helpcol <= l && helpcol < (pPopup->width-2); helpcol++ )
  772.             pPopup->c[helprow][helpcol] = s[helpcol-1] ;
  773.  
  774.         /* Pad with spaces */
  775.         for ( helpcol ; helpcol < pPopup->width-1 ; helpcol++ )
  776.             pPopup->c[helprow][helpcol] = SP;
  777.  
  778.         pPopup->c[helprow][helpcol++] = 186;   /* IBM center bar vertical double */
  779.     }
  780. }
  781.  
  782. void
  783. helpend(videopopup * pPopup) {          /* End of popup help box */
  784.     helprow++;
  785.     helpcol=0;
  786. #ifdef KUI
  787.     if ( !pPopup->gui )
  788. #endif /* KUI */
  789.     {
  790.         pPopup->c[helprow][helpcol++] = 200; /* IBM lower left box corner double */
  791.         for ( helpcol ; helpcol < pPopup->width-1 ; helpcol++ )
  792.             pPopup->c[helprow][helpcol] = 205; /* Center box bar horizontal double */
  793.  
  794.         pPopup->c[helprow][helpcol++] = 188; /* Lower right box corner double */
  795.     }
  796. }
  797.  
  798. int
  799. popuperror(int mode, char * msg ) {
  800.     videopopup * pPopup = NULL ;
  801.     int c=0;
  802.     con_event evt ;
  803.     extern int holdscreen;
  804.  
  805.     save_status_line();                 /* Save current status line */
  806.     strcpy(usertext, " ERROR: Press (almost) any key to continue.");
  807.     exittext[0] = helptext[0] = hostname[0] = NUL;
  808.  
  809.     pPopup = helpstart(strlen(msg), 1, gui_dialog);
  810.     helpline( pPopup, msg ) ;
  811.     helpend(pPopup);                    /* Write bottom of help panel */
  812.  
  813. #ifdef KUI
  814.     if ( pPopup->gui ) {
  815.         c = gui_videopopup_dialog(pPopup, 0);
  816.     } else 
  817. #endif /* KUI */
  818.     {
  819. #ifdef OS2ONLY
  820.         VscrnSetPopup( mode, pPopup ) ;
  821.         /* wait until user presses a key */
  822.         evt = congev(mode,0);
  823.         while ( evt.type != key && evt.type != kverb) {
  824.             if ( evt.type != error )
  825.                 bleep( BP_WARN ) ;
  826.             evt = congev(mode,0);
  827.         }
  828.         if ( evt.type == kverb )
  829.             c = F_KVERB | evt.kverb.id ;
  830.         else  {
  831.             c = 0 ;
  832.         }
  833.         VscrnResetPopup(mode) ;            /* This frees the Popup structure */
  834. #else /* OS2ONLY */
  835.         ;
  836. #endif /* OS2ONLY */
  837.     }
  838.     restore_status_line();
  839.     return (c);
  840. }
  841.  
  842. int
  843. popupdemo(int mode, int secsleft ) {
  844.     videopopup * pPopup = NULL ;
  845.     char buf[80];
  846.     extern unsigned char colorhelp ;
  847.     int color_sav;
  848.     color_sav = colorhelp;
  849.     colorhelp = 0xE9;
  850.  
  851.     sprintf(buf," Time remaining in this session: %2d:%02d",secsleft/60, secsleft%60);
  852.  
  853.     pPopup = helpstart(57, (ttyfd == -1 || ttyfd == -2) ? 5 : 7, gui_dialog);
  854.     helpline( pPopup, " This is a trial copy of Kermit 95 to be evaluated for" ) ;
  855.     helpline( pPopup, " for possible purchase.  It is fully functional and does" );
  856.     helpline( pPopup, " not expire, but sessions are limited to 15 minutes." );
  857.     helpline( pPopup, " To register, contact the distributor of this package or" );
  858.     helpline( pPopup, " visit http://www.columbia.edu/kermit/k95.html." );
  859.     if ( ttyfd != -1 && ttyfd != -2 ) {
  860.         helpline( pPopup, " " );
  861.         helpline( pPopup, buf );
  862.     }
  863.     helpend(pPopup);                    /* Write bottom of help panel */
  864.     bleep(BP_WARN);
  865. #ifdef KUI
  866.     if ( pPopup->gui )
  867.         gui_videopopup_dialog(pPopup, 6);
  868.     else
  869. #endif /* KUI */
  870.     {
  871.         VscrnSetPopup( mode, pPopup ) ;
  872.         sleep(6);
  873.         VscrnResetPopup(mode) ;            /* This frees the Popup structure */
  874.     }
  875.     colorhelp = color_sav;
  876.     return(0);
  877. }
  878.  
  879.  
  880.  
  881. int
  882. popup_readtext(int mode, char * preface, char * prmpt, char * buffer, int buflen, int timo ) {
  883.     videopopup * pPopup = NULL ;
  884.     con_event evt ;
  885.     char inputline[256];
  886.     char prompt[1024];
  887.     int input_width,popup_width,i,j,len=0;
  888.     CHAR x1, * p, * q;
  889.     int lines;
  890.     int resp_line;
  891.  
  892.     if ( prmpt ) {
  893.         ckstrncpy(prompt,prmpt,1024);
  894.     }
  895.     else
  896.         strcpy(prompt,"Enter text:");
  897.  
  898.     if ( !buffer || buflen <= 0 )
  899.         return(-1);
  900.  
  901.     i = 0;
  902.     lines=1;
  903.  
  904.     if ( preface ) {
  905.         lines += 2;
  906.         p = q = preface;
  907.         while ( *p ) {
  908.             if ( *p == LF ) {
  909.                 lines++;
  910.                 if ( p - q > i )
  911.                     i = p - q;
  912.                 q = p;
  913.             }
  914.             p++;
  915.         }
  916.         if ( q == preface )
  917.             i = p - q;
  918.     }
  919.  
  920.     p = q = prompt;
  921.     while ( *p ) {
  922.         if ( *p == LF ) {
  923.             lines++;
  924.             if ( p - q > i )
  925.                 i = p - q;
  926.             q = p;
  927.         }
  928.         p++;
  929.     }
  930.     if ( q == prompt )
  931.         i = p - q;
  932.     j = VscrnGetWidth(mode);
  933.  
  934.     popup_width = (i > j - 10 || buflen > j - 10) ? j - 10 :
  935.         (buflen > i) ? buflen : i;
  936.     input_width = (buflen <= popup_width ? buflen : popup_width)-1;
  937.  
  938.     save_status_line();                 /* Save current status line */
  939.     strcpy(usertext, " Enter text followed by Enter to continue");
  940.     exittext[0] = helptext[0] = hostname[0] = NUL;
  941.  
  942.     pPopup = helpstart(popup_width, lines+1, 0);
  943.  
  944.     if ( preface ) {
  945.     char * cp_preface = NULL;
  946.     makestr(&cp_preface, preface);
  947.         p = q = cp_preface;
  948.         while ( *p ) {
  949.             if ( *p == LF ) {
  950.                 *p = '\0';
  951.                 if ( *(p-1) == CR )
  952.                     *(p-1) = '\0';
  953.                 helpline( pPopup, q );
  954.                 q = p+1;
  955.             }
  956.             p++;
  957.         }
  958.         helpline( pPopup, q );
  959.         helpline( pPopup, "" );
  960.     free(cp_preface);
  961.     }
  962.  
  963.     p = q = prompt;
  964.     while ( *p ) {
  965.         if ( *p == LF ) {
  966.             *p = '\0';
  967.             if ( *(p-1) == CR )
  968.                 *(p-1) = '\0';
  969.             helpline( pPopup, q );
  970.             q = p+1;
  971.         }
  972.         p++;
  973.     }
  974.     helpline( pPopup, q );
  975.  
  976.     resp_line = helprow;
  977.     sprintf(inputline,"[%*s]",input_width," ");
  978.     helpline(pPopup,inputline);
  979.     helpend(pPopup);                    /* Write bottom of help panel */
  980.     VscrnSetPopup( mode, pPopup );
  981.  
  982.     buffer[0] = '\0';
  983.     len = 0;
  984.  
  985.     do {
  986.         VscrnIsDirty(vmode);  /* status line needs to be updated */
  987.  
  988.         evt = congev(vmode,timo > 0 ? timo : -1) ;
  989.         switch (evt.type) {
  990.         case key:
  991. #ifdef COMMENT
  992.             x1 = mapkey(evt.key.scancode); /* Get value from keymap */
  993. #else
  994.             x1 = evt.key.scancode ;
  995. #endif
  996.             break;
  997. #ifndef NOKVERBS
  998.         case kverb:
  999.             x1 = evt.kverb.id | F_KVERB;
  1000.             switch ( evt.kverb.id & ~F_KVERB ) {
  1001.             case K_KPENTER  :
  1002.             case K_WYENTER  :
  1003.             case K_WYRETURN :
  1004.             case K_TVIENTER :
  1005.             case K_TVIRETURN:
  1006.             case K_HPENTER  :
  1007.             case K_HPRETURN :
  1008.                 x1 = CR;
  1009.                 break;
  1010.             default:
  1011.                 bleep(BP_WARN);
  1012.                 continue;
  1013.             }
  1014.             break;
  1015. #endif /* NOKVERBS */
  1016.         case macro:
  1017.             if ( evt.macro.string )
  1018.                 free( evt.macro.string ) ;
  1019.             x1 = 0;
  1020.             break;
  1021.         case literal:
  1022.             if ( evt.literal.string )
  1023.                 free( evt.literal.string ) ;
  1024.             x1 = 0;
  1025.             break;
  1026.         case error:
  1027.             if ( timo ) {
  1028.                 len = -1;
  1029.                 goto popup_exit;
  1030.             }
  1031.         case esc:
  1032.         case csi:
  1033.         default:
  1034.             x1 = 0 ;
  1035.         }
  1036.  
  1037.         if ( x1 >= ' ' && x1 <= 126 || x1 >= 128 && x1 <= 255 )
  1038.         {
  1039.             if ( len >= buflen - 1 ) {
  1040.                 bleep(BP_WARN);
  1041.             }
  1042.             else {
  1043.                 buffer[len] = x1 ;
  1044.                 buffer[len+1] = '\0' ;
  1045.             }
  1046.         }
  1047.         else if ( x1 == 8 || x1 == 127 )
  1048.         {
  1049.             buffer[len-1] = '\0' ;
  1050.         }
  1051.         else if ( x1 == CR )
  1052.         {
  1053.             break;
  1054.         }
  1055.         else if ( x1 == 21 )
  1056.         {
  1057.             buffer[0] = '\0' ;
  1058.             len = 0 ;
  1059.         }
  1060.         else if ( x1 == ESC ) {
  1061.             buffer[0] = '\0' ;
  1062.             len = 0;
  1063.             break;
  1064.         }
  1065.         else
  1066.         {
  1067.             bleep(BP_FAIL);
  1068.         }
  1069.  
  1070.         len = strlen(buffer);
  1071.         helprow = resp_line;    /* we know the internal representation */
  1072.         sprintf(inputline,"[%-*s]",input_width,
  1073.                  (len > input_width) ? &buffer[len-input_width] : buffer);
  1074.         helpline(pPopup,inputline);
  1075.     } while ( TRUE );
  1076.  
  1077.   popup_exit:
  1078.     VscrnResetPopup(mode) ;            /* This frees the Popup structure */
  1079.     restore_status_line();
  1080.     return (len);
  1081. }
  1082.  
  1083.  
  1084. int
  1085. popup_readpass(int mode, char * preface, char * prmpt, char * buffer, int buflen, int timo ) {
  1086.     videopopup * pPopup = NULL ;
  1087.     con_event evt ;
  1088.     char inputline[256];
  1089.     char prompt[1024];
  1090.     int input_width,popup_width,i,j,len=0;
  1091.     CHAR x1, * p, * q;
  1092.     int lines;
  1093.     int resp_line;
  1094.  
  1095.     if ( prmpt ) {
  1096.         ckstrncpy(prompt,prmpt,1024);
  1097.     }
  1098.     else
  1099.         strcpy(prompt,"Enter password:");
  1100.  
  1101.     if ( !buffer || buflen <= 0 )
  1102.         return(-1);
  1103.  
  1104.     i = 0;
  1105.     lines=1;
  1106.  
  1107.     if ( preface ) {
  1108.         lines += 2;
  1109.         p = q = preface;
  1110.         while ( *p ) {
  1111.             if ( *p == LF ) {
  1112.                 lines++;
  1113.                 if ( p - q > i )
  1114.                     i = p - q;
  1115.                 q = p;
  1116.             }
  1117.             p++;
  1118.         }
  1119.         if ( q == preface )
  1120.             i = p - q;
  1121.     }
  1122.  
  1123.     p = q = prompt;
  1124.     while ( *p ) {
  1125.         if ( *p == LF ) {
  1126.             lines++;
  1127.             if ( p - q > i )
  1128.                 i = p - q;
  1129.             q = p;
  1130.         }
  1131.         p++;
  1132.     }
  1133.     if ( q == prompt )
  1134.         i = p - q;
  1135.     j = VscrnGetWidth(mode);
  1136.  
  1137.     popup_width = (i > j - 10 || buflen > j - 10) ? j - 10 :
  1138.         (buflen > i) ? buflen : i;
  1139.     input_width = (buflen <= popup_width ? buflen : popup_width)-1;
  1140.  
  1141.     save_status_line();                 /* Save current status line */
  1142.     strcpy(usertext, " Enter password followed by Enter to continue");
  1143.     exittext[0] = helptext[0] = hostname[0] = NUL;
  1144.  
  1145.     pPopup = helpstart(popup_width, lines+1, 0);
  1146.  
  1147.     if ( preface ) {
  1148.     char * cp_preface = NULL;
  1149.     makestr(&cp_preface, preface);
  1150.         p = q = cp_preface;
  1151.         while ( *p ) {
  1152.             if ( *p == LF ) {
  1153.                 *p = '\0';
  1154.                 if ( *(p-1) == CR )
  1155.                     *(p-1) = '\0';
  1156.                 helpline( pPopup, q );
  1157.                 q = p+1;
  1158.             }
  1159.             p++;
  1160.         }
  1161.         helpline( pPopup, q );
  1162.         helpline( pPopup, "" );
  1163.     free(cp_preface);
  1164.     }
  1165.  
  1166.     p = q = prompt;
  1167.     while ( *p ) {
  1168.         if ( *p == LF ) {
  1169.             *p = '\0';
  1170.             if ( *(p-1) == CR )
  1171.                 *(p-1) = '\0';
  1172.             helpline( pPopup, q );
  1173.             q = p+1;
  1174.         }
  1175.         p++;
  1176.     }
  1177.     helpline( pPopup, q );
  1178.  
  1179.     resp_line = helprow;
  1180.     sprintf(inputline,"[%*s]",input_width," ");
  1181.     helpline(pPopup,inputline);
  1182.     helpend(pPopup);                    /* Write bottom of help panel */
  1183.     VscrnSetPopup( mode, pPopup );
  1184.  
  1185.     buffer[0] = '\0';
  1186.     len = 0;
  1187.  
  1188.     do {
  1189.         VscrnIsDirty(vmode);  /* status line needs to be updated */
  1190.  
  1191.         evt = congev(vmode,timo > 0 ? timo : -1) ;
  1192.         switch (evt.type) {
  1193.         case key:
  1194. #ifdef COMMENT
  1195.             x1 = mapkey(evt.key.scancode); /* Get value from keymap */
  1196. #else
  1197.             x1 = evt.key.scancode ;
  1198. #endif
  1199.             break;
  1200. #ifndef NOKVERBS
  1201.         case kverb:
  1202.             x1 = evt.kverb.id | F_KVERB;
  1203.             switch ( evt.kverb.id & ~F_KVERB ) {
  1204.             case K_KPENTER  :
  1205.             case K_WYENTER  :
  1206.             case K_WYRETURN :
  1207.             case K_TVIENTER :
  1208.             case K_TVIRETURN:
  1209.             case K_HPENTER  :
  1210.             case K_HPRETURN :
  1211.                 x1 = CR;
  1212.                 break;
  1213.             default:
  1214.                 bleep(BP_WARN);
  1215.                 continue;
  1216.             }
  1217.             break;
  1218. #endif /* NOKVERBS */
  1219.         case macro:
  1220.             if ( evt.macro.string )
  1221.                 free( evt.macro.string ) ;
  1222.             x1 = 0;
  1223.             break;
  1224.         case literal:
  1225.             if ( evt.literal.string )
  1226.                 free( evt.literal.string ) ;
  1227.             x1 = 0;
  1228.             break;
  1229.         case error:
  1230.             if ( timo ) {
  1231.                 len = -1;
  1232.                 goto popup_exit;
  1233.             }
  1234.         case esc:
  1235.         case csi:
  1236.         default:
  1237.             x1 = 0 ;
  1238.         }
  1239.  
  1240.         if ( x1 >= ' ' && x1 <= 126 || x1 >= 128 && x1 <= 255 )
  1241.         {
  1242.             if ( len >= buflen - 1 ) {
  1243.                 bleep(BP_WARN);
  1244.             }
  1245.             else {
  1246.                 buffer[len] = x1 ;
  1247.                 buffer[len+1] = '\0' ;
  1248.             }
  1249.         }
  1250.         else if ( x1 == 8 || x1 == 127 )
  1251.         {
  1252.             buffer[len-1] = '\0' ;
  1253.         }
  1254.         else if ( x1 == CR )
  1255.         {
  1256.             break;
  1257.         }
  1258.         else if ( x1 == 21 )
  1259.         {
  1260.             buffer[0] = '\0' ;
  1261.             len = 0 ;
  1262.         }
  1263.         else if ( x1 == ESC ) {
  1264.             buffer[0] = '\0' ;
  1265.             len = 0;
  1266.             break;
  1267.         }
  1268.         else
  1269.         {
  1270.             bleep(BP_FAIL);
  1271.         }
  1272.  
  1273.         len = strlen(buffer);
  1274.         helprow = resp_line;    /* we know the internal representation */
  1275.         sprintf(inputline,"[%*s]",input_width," ");
  1276.         memset(&inputline[1],'*',len<input_width?len:input_width);
  1277.         helpline(pPopup,inputline);
  1278.     } while ( TRUE );
  1279.  
  1280.   popup_exit:
  1281.     VscrnResetPopup(mode) ;            /* This frees the Popup structure */
  1282.     restore_status_line();
  1283.     return (len);
  1284. }
  1285.  
  1286. char fkeylabel[16][32] = {"","","","","","","","",
  1287.                               "","","","","","","",""};
  1288. int
  1289. fkeypopup(int mode) {
  1290.     videopopup * pPopup = NULL ;
  1291.     int c,i;
  1292.     con_event evt ;
  1293.     char buffer[64];
  1294.  
  1295.     save_status_line();                 /* Save current status line */
  1296.     strcpy(usertext, " Function Key Labels: Press (almost) any key to continue.");
  1297.     exittext[0] = helptext[0] = hostname[0] = NUL;
  1298.  
  1299.     if ( ISWYSE(tt_type_mode) ) {
  1300.         pPopup = helpstart(32, 11, gui_dialog);
  1301.         helpline( pPopup, " Wyse Function Key Labels" ) ;
  1302.         helpline( pPopup, "" ) ;
  1303.         for ( i=0 ; i<8 ; i++ ) {
  1304.             sprintf(buffer,"  F%-2d:  \"%s\"",i+1,fkeylabel[i]);
  1305.             helpline( pPopup, buffer );
  1306.         }
  1307.         helpline( pPopup, "" ) ;
  1308.     }
  1309.     else if ( ISHP(tt_type_mode) ) {
  1310.         pPopup = helpstart(32, 19, gui_dialog );
  1311.         helpline( pPopup, " HP Function Key Labels" ) ;
  1312.         helpline( pPopup, "" ) ;
  1313.         for ( i=0 ; i<16 ; i++ ) {
  1314.             sprintf(buffer,"  F%-2d:  \"%s\"",i+1,fkeylabel[i]);
  1315.             helpline( pPopup, buffer );
  1316.         }
  1317.         helpline( pPopup, "" ) ;
  1318.     }
  1319.     else if ( ISBA80(tt_type_mode) ) {
  1320.         pPopup = helpstart(32, 12, gui_dialog );
  1321.         helpline( pPopup, " BA80 Function Key Labels" ) ;
  1322.         helpline( pPopup, "" ) ;
  1323.         for ( i=0 ; i<9 ; i++ ) {
  1324.             sprintf(buffer,"  F%-2d:  \"%s\"",i+1,fkeylabel[i]);
  1325.             helpline( pPopup, buffer );
  1326.         }
  1327.         helpline( pPopup, "" ) ;
  1328.     }
  1329.     else {
  1330.         pPopup = helpstart(32, 1, gui_dialog );
  1331.         helpline( pPopup, " No Function Key Labels" ) ;
  1332.     }
  1333.  
  1334.     helpend(pPopup);                    /* Write bottom of help panel */
  1335. #ifdef KUI
  1336.     if ( pPopup->gui )
  1337.         c = gui_videopopup_dialog(pPopup, 0);
  1338.     else
  1339. #endif /* KUI */
  1340.     {
  1341.         VscrnSetPopup( mode, pPopup ) ;
  1342.  
  1343.         /* wait until user presses a key */
  1344.         evt = congev(mode,0);
  1345.         while ( evt.type != key
  1346. #ifndef NOKVERBS
  1347.                 && evt.type != kverb
  1348. #endif /* NOKVERBS */
  1349.                 ) {
  1350.             if ( evt.type != error )
  1351.                 bleep( BP_WARN ) ;
  1352.             evt = congev(mode,0);
  1353.         }
  1354. #ifndef NOKVERBS
  1355.         if ( evt.type == kverb )
  1356.             c = F_KVERB | evt.kverb.id ;
  1357.         else
  1358. #endif /* NOKVERBS */
  1359.         {
  1360.             c = 0 ;
  1361.         }   
  1362.         VscrnResetPopup(mode) ;            /* This frees the Popup structure */
  1363.     }
  1364.  
  1365.     restore_status_line();
  1366.     return (c);
  1367. }
  1368.  
  1369. int
  1370. popuphelp(int mode, enum helpscreen x) {
  1371. #ifndef NOKVERBS
  1372.     videopopup * pPopup = NULL ;
  1373.     int c, n, z;
  1374.     char line[81];
  1375.     char kn[40];
  1376.     char *s;
  1377.     static int whichscreen = 0 ;
  1378.     con_event evt ;
  1379. #ifdef OS2MOUSE
  1380.     int button, event ;
  1381. #endif /* OS2MOUSE */
  1382.  
  1383.     char *hlpmsg[] = {
  1384.         "",
  1385.         " Command:   (SPACE to cancel)",
  1386.         "",
  1387. #ifdef NT
  1388.         "    C    to return to the K-95 prompt",
  1389. #else /* NT */
  1390.         "    C    to return to the Kermit prompt",
  1391. #endif /* NT */
  1392.         "    U    to hangUp and return to the prompt",
  1393. #ifdef NT
  1394.         "    Q    to hangup and Quit K-95",
  1395. #else /* NT */
  1396.         "    Q    to hangup and Quit Kermit",
  1397. #endif /* NT */
  1398.         "    !    to enter the system command processor",
  1399.         "    F    to print or File the current screen",
  1400.         "",
  1401.         "    0    (zero) to send a null",
  1402.         "   ^%c    to send the escape character",
  1403.         "    B    to send a BREAK signal",
  1404.         "    L    to send a Long BREAK",
  1405.         "",
  1406. #ifdef TNCODE
  1407.         "    I    to Interrupt process (TELNET)",
  1408.         "    A    to send \"Are you there?\" (TELNET)",
  1409.         "",
  1410. #endif /* TNCODE */
  1411.         "    \\    backslash escape (end with ENTER):",
  1412.         "         \\nnn   decimal code, like \\199",
  1413.         "         \\Onnn  octal code, like \\o307",
  1414.         "         \\Xhh   hexadecimal code, like \\xC7",
  1415.         "" };
  1416. #define HELPSIZE (sizeof(hlpmsg)/sizeof(char *))
  1417.  
  1418.     char *abouthlpmsg[] = {
  1419.         " By Jeffrey Eric Altman, IAM Consulting",
  1420.         "    Frank da Cruz, Columbia University",
  1421.         " Copyright (C) 1985, 2003",
  1422.         " Trustees of Columbia University in the City of New York.",
  1423.         "",
  1424.         "  Type INTRO   for a brief introduction to the Kermit Command screen.",
  1425.         "  Type VERSION for version and copyright information.",
  1426.         "  Type HELP    followed by a command name for help about a specific command.",
  1427.         "  Type NEWS    for news about new features.",
  1428.         "  Type BUG     to learn how to get technical support.",
  1429.         "  Press ?      (question mark) at the prompt, or anywhere within a command,",
  1430.         "               for a menu (context-sensitive help, menu on demand).",
  1431.         ""
  1432.     };
  1433. #define ABOUTHLPSIZE (sizeof(abouthlpmsg)/sizeof(char *))
  1434.  
  1435.     char *l2ckmsg[] = {
  1436.         " COMPOSE SEQUENCES FOR MULTINATIONAL CHARACTERS",
  1437.         "",
  1438.         " Press two keys to compose the desired character:",
  1439.         "",
  1440.         " First  Second  Result",
  1441.         "   '     Letter   Letter with acute accent",
  1442.         "   #     Letter   Letter with double acute accent",
  1443.         "   %%     Letter   Letter with breve accent",
  1444.         "   \"     Letter   Letter with diaeresis/trema/umlaut",
  1445.         "   &     Letter   Letter with caron/hacek",
  1446.         "   ^     Letter   Letter with circumflex",
  1447.         "   *     Letter   Letter with ring above",
  1448.         "   ,     Letter   Letter with cedilla",
  1449.         "   =     Letter   Letter with ogonek",
  1450.         "   .     Letter   Letter with dot above",
  1451.         "   L       /      L with stroke",
  1452.         "   s       s      German sharp s / Ess-Zet"
  1453.  
  1454. #ifdef KUI
  1455. ,       "   n       b      No-break space"
  1456. #endif /* KUI */
  1457.     };
  1458. #define L2COMPOSESIZE (sizeof(l2ckmsg)/sizeof(char *))
  1459.  
  1460.     char *cmposmsg[] = {
  1461.         " COMPOSE SEQUENCES FOR MULTINATIONAL CHARACTERS",
  1462.         "",
  1463.         " Press two keys to compose the desired character:",
  1464.         "",
  1465.         " First  Second  Result",
  1466.         "   '     Vowel   Vowel with acute accent",
  1467.         "   `     Vowel   Vowel with grave accent",
  1468.         "   \"     Vowel   Vowel with diaeresis/trema/umlaut",
  1469.         "   ^     Vowel   Vowel with circumflex",
  1470.         "   *       A     A ring",
  1471.         "   ,       C     C cedilla",
  1472.         "   ~     N,A,O   Letter with tilde",
  1473.         "   A       E     AE digraph",
  1474.         "   O       /     O with stroke",
  1475.         "   s       s     German sharp s",
  1476.         "   n       b     No-break space"
  1477.         "",
  1478.         " And others; see the documentation.",
  1479.     };
  1480. #define COMPOSESIZE (sizeof(cmposmsg)/sizeof(char *))
  1481.  
  1482.     char *ucs2msg[] = {
  1483.         "Enter exactly 4 hexadecimal digits",
  1484.         "corresponding to a Unicode character.",
  1485.         "Examples:",
  1486.         "",
  1487.         " 0041  Latin Capital Letter A",
  1488.         " 00de  Latin Capital Letter Thorn",
  1489.         " 03c8  Greek Small Letter Psi",
  1490.         " 0428  Cyrillic Capital Letter Sha",
  1491.         " 054c  Armenian Capital Letter Ra",
  1492.         " 05d0  Hebrew Letter Alef",
  1493.         " 20ac  Euro Symbol",
  1494.         " 30a2  Katakana Letter A",
  1495.         "",
  1496.         "Results depend on your font.  Works best",
  1497.         "with SET TERMINAL REMOTE-CHARACTER-SET UTF8.",
  1498.     };
  1499. #define UCS2SIZE (sizeof(ucs2msg)/sizeof(char *))
  1500.  
  1501.      char *srchhlpmsg[] = {
  1502.          " SCROLLBACK SEARCH",
  1503.          " ",
  1504.          " Use Delete and Ctrl-U for editing,",
  1505.          " Esc to cancel, Enter to start the search.",
  1506.          ""
  1507.      };
  1508. #define SEARCHHLPSIZE (sizeof(srchhlpmsg)/sizeof(char *))
  1509.  
  1510.     char * bkmrkhlpmsg[] = {
  1511.         " BOOKMARKS",
  1512.         " ",
  1513.         " Type a bookmark number, 0 through 9.",
  1514.         " Press the Space bar to cancel.",
  1515.         ""
  1516.     };
  1517. #define BKMRKHLPSIZE (sizeof(bkmrkhlpmsg)/sizeof(char *))
  1518.  
  1519.     vikinit() ;                         /* Update VIK Table */
  1520.     save_status_line();                 /* Save current status line */
  1521.  
  1522.     switch (x) {
  1523.     case hlp_search:
  1524.         pPopup = helpstart(52, SEARCHHLPSIZE, gui_dialog);
  1525.         for ( c=0; c<SEARCHHLPSIZE; c++ ) {
  1526.             s = srchhlpmsg[c] ;
  1527.             if ( strchr( s, '%') ) {
  1528.                 sprintf(line, s, ctl(escape));
  1529.                 helpline( pPopup, line ) ;
  1530.             } else
  1531.               helpline( pPopup, s ) ;
  1532.         }
  1533.         break;
  1534.  
  1535.     case hlp_bookmark:
  1536.         pPopup = helpstart(52, BKMRKHLPSIZE, gui_dialog);
  1537.         for ( c = 0; c < BKMRKHLPSIZE; c++ ) {
  1538.             s = bkmrkhlpmsg[c] ;
  1539.             if ( strchr( s, '%') ) {
  1540.                 sprintf(line, s, ctl(escape));
  1541.                 helpline( pPopup, line ) ;
  1542.             } else
  1543.               helpline( pPopup, s ) ;
  1544.         }
  1545.         break;
  1546.  
  1547.     case hlp_compose:                 /* Compose help popup */
  1548.         z = (tcsl == FC_CP852) ? L2COMPOSESIZE : COMPOSESIZE;
  1549.         pPopup = helpstart(52, z, gui_dialog);
  1550.         for (c = 0; c < z; c++) {
  1551.             s = (tcsl == TX_CP852) ? l2ckmsg[c] : cmposmsg[c];
  1552.             if (strchr(s, '%')) {
  1553.                 sprintf(line, s, ctl(escape));
  1554.                 helpline( pPopup, line);
  1555.             } else
  1556.               helpline( pPopup, s);
  1557.         }
  1558.         break;
  1559.  
  1560.     case hlp_ucs2:                   /* UCS2 help popup */
  1561.         pPopup = helpstart(52, UCS2SIZE, gui_dialog);
  1562.         for (c = 0; c < UCS2SIZE; c++) {
  1563.             s = ucs2msg[c];
  1564.             if (strchr(s, '%')) {
  1565.                 sprintf(line, s, ctl(escape));
  1566.                 helpline( pPopup, line);
  1567.             } else
  1568.               helpline( pPopup, s);
  1569.         }
  1570.         break;
  1571.  
  1572.     case hlp_escape:  /* escape help popup */
  1573.         pPopup = helpstart(47, HELPSIZE, gui_dialog);
  1574.         for (c = 0; c < HELPSIZE; c++) {
  1575.             s = hlpmsg[c];
  1576.             if (strchr(s, '%')) {
  1577.                 sprintf(line, s, ctl(escape));
  1578.                 helpline( pPopup, line);
  1579.             } else
  1580.               helpline( pPopup, s);
  1581.         }
  1582.         break;
  1583.  
  1584.     case hlp_rollback:
  1585.         strcpy(usertext, " Press (almost) any key to restore the screen");
  1586.         exittext[0] = helptext[0] = hostname[0] = NUL;
  1587.  
  1588.         s = " SCREEN SCROLL KEYS";      /* Box title */
  1589.         n = 22;                         /* How many lines for help box */
  1590.         if (vik.upscn   < 256) n--;     /* Deduct for verbs not assigned */
  1591.         if (vik.upone   < 256) n--;
  1592.         if (vik.dnscn   < 256) n--;
  1593.         if (vik.dnone   < 256) n--;
  1594.         if (vik.homscn  < 256) n--;
  1595.         if (vik.endscn  < 256) n--;
  1596.         if ( vik.lfone < 256 ) n--;
  1597.         if ( vik.lfpg < 256 ) n--;
  1598.         if ( vik.lfall < 256 ) n--;
  1599.         if ( vik.rtone < 256 ) n--;
  1600.         if ( vik.rtpg < 256 ) n--;
  1601.         if ( vik.rtall < 256 ) n--;
  1602.         if (vik.dump    < 256) n--;
  1603.         if (vik.exit    < 256) n--;
  1604.         if (vik.markstart < 256) n--;
  1605.         if (vik.help < 256) n--;
  1606.         pPopup = helpstart(66, n, gui_dialog);      /* Make popup window 66 x n */
  1607.         helpline( pPopup, s);           /* 1 */
  1608.         helpline( pPopup, "");          /* 2 */
  1609.  
  1610.         if (vik.upscn > 255 && keyname(vik.upscn)) {
  1611.             ckstrncpy(kn,keyname(vik.upscn),40);
  1612.             sprintf(line,"  %-34.33s%s",kn,"Scroll backward one screen");
  1613.             helpline( pPopup, line);    /* 3 */
  1614.         }
  1615.         if (vik.upone > 255 && keyname(vik.upone)) {
  1616.             ckstrncpy(kn,keyname(vik.upone),40);
  1617.             sprintf(line,"  %-34.33s%s",kn,"Scroll backward one line");
  1618.             helpline( pPopup, line);    /* 4 */
  1619.         }
  1620.         if (vik.dnscn > 255 && keyname(vik.dnscn)) {
  1621.             ckstrncpy(kn,keyname(vik.dnscn),40);
  1622.             sprintf(line,"  %-34.33s%s",kn,"Scroll forward one screen");
  1623.             helpline( pPopup, line);    /* 5 */
  1624.         }
  1625.         if (vik.dnone > 255 && keyname(vik.dnone)) {
  1626.             ckstrncpy(kn,keyname(vik.dnone),40);
  1627.             sprintf(line,"  %-34.33s%s",kn,"Scroll forward one line");
  1628.             helpline( pPopup, line);    /* 6 */
  1629.         }
  1630.         if (vik.homscn > 255 && keyname(vik.homscn)) {
  1631.             ckstrncpy(kn,keyname(vik.homscn),40);
  1632.             sprintf(line,"  %-34.33s%s",kn,"Scroll back to beginning");
  1633.             helpline( pPopup, line);            /* 7 */
  1634.         }
  1635.         if (vik.endscn > 255 && keyname(vik.endscn)) {
  1636.             ckstrncpy(kn,keyname(vik.endscn),40);
  1637.             sprintf(line,"  %-34.33s%s",kn,"Scroll forward to end");
  1638.             helpline( pPopup, line);    /* 8 */
  1639.         }
  1640.         if (vik.lfone > 255 && keyname(vik.lfone)) {
  1641.             ckstrncpy(kn,keyname(vik.lfone),40);
  1642.             sprintf(line,"  %-34.33s%s",kn,"Scroll left one column");
  1643.             helpline( pPopup, line);    /* 9 */
  1644.         }
  1645.         if (vik.lfpg > 255 && keyname(vik.lfpg)) {
  1646.             ckstrncpy(kn,keyname(vik.lfpg),40);
  1647.             sprintf(line,"  %-34.33s%s",kn,"Scroll left eight columns");
  1648.             helpline( pPopup, line);    /* 9 */
  1649.         }
  1650.         if (vik.lfall > 255 && keyname(vik.lfall)) {
  1651.             ckstrncpy(kn,keyname(vik.lfall),40);
  1652.             sprintf(line,"  %-34.33s%s",kn,"Scroll left to first column");
  1653.             helpline( pPopup, line);    /* 9 */
  1654.         }
  1655.         if (vik.rtone > 255 && keyname(vik.rtone)) {
  1656.             ckstrncpy(kn,keyname(vik.rtone),40);
  1657.             sprintf(line,"  %-34.33s%s",kn,"Scroll right one column");
  1658.             helpline( pPopup, line);    /* 9 */
  1659.         }
  1660.         if (vik.rtpg > 255 && keyname(vik.rtpg)) {
  1661.             ckstrncpy(kn,keyname(vik.rtpg),40);
  1662.             sprintf(line,"  %-34.33s%s",kn,"Scroll right eight columns");
  1663.             helpline( pPopup, line);    /* 9 */
  1664.         }
  1665.         if (vik.rtall > 255 && keyname(vik.rtall)) {
  1666.             ckstrncpy(kn,keyname(vik.rtall),40);
  1667.             sprintf(line,"  %-34.33s%s",kn,"Scroll right to last column");
  1668.             helpline( pPopup, line);    /* 9 */
  1669.         }
  1670.         if (vik.markstart > 255 && keyname(vik.markstart)) {
  1671.             ckstrncpy(kn,keyname(vik.markstart),40);
  1672.             sprintf(line,"  %-34.33s%s",kn,"Begin selection (mark mode)");
  1673.             helpline( pPopup, line);    /* 11 */
  1674.         }
  1675.         if (vik.dump > 255 && keyname(vik.dump)) {
  1676.             ckstrncpy(kn,keyname(vik.dump),40);
  1677.             sprintf(line,"  %-34.33s%s",kn,"Print the visible screen");
  1678.             helpline( pPopup, line);    /* 9 */
  1679.         }
  1680.         if (vik.exit > 255 && keyname(vik.exit)) {
  1681.             ckstrncpy(kn,keyname(vik.exit),40);
  1682.             sprintf(line,"  %-34.33s%s",kn,"Return to Command screen");
  1683.             helpline( pPopup, line);    /* 10 */
  1684.         }
  1685.         if (vik.help > 255 && keyname(vik.help)) {
  1686.             ckstrncpy(kn,keyname(vik.help),40);
  1687. #ifdef KUI
  1688.             if ( pPopup->gui )
  1689.                 sprintf(line,"  %-34.33s%s",kn,"Context Help");
  1690.             else
  1691. #endif /* KUI */
  1692.                 sprintf(line,"  %-34.33s%s",kn,"More help...");
  1693.             helpline( pPopup, line);    /* 18 */
  1694.         }
  1695.         helpline( pPopup, "");          /* 12 */
  1696.         helpline( pPopup, tt_roll ?
  1697.                  " ROLL-MODE is INSERT: New data appears at end of buffer." :
  1698.                  " ROLL-MODE is OVERWRITE: New data appears on current screen."
  1699.                  );                     /* 13 */
  1700.         sprintf(line, " Scrollback buffer size: %d lines.",
  1701.                 VscrnGetBufferSize(mode)
  1702.                 );
  1703.         helpline(pPopup, line); /* 14 */
  1704.         helpline(pPopup," Use SET TERMINAL SCROLLBACK to change it."); /* 13 */
  1705.         break;
  1706.  
  1707.     case hlp_normal:
  1708.         if ( mode == VTERM ) {
  1709.             strcpy(usertext, " Press (almost) any key to restore the screen");
  1710.             exittext[0] = helptext[0] = hostname[0] = NUL;
  1711.  
  1712.             n = 24;                         /* How many lines */
  1713.             s = " IMPORTANT KEYS";
  1714.             if (vik.flipscn < 256) n--;
  1715.             if (vik.debug   < 256) n--;
  1716.             if (vik.reset   < 256) n--;
  1717.             if (vik.prtctrl < 256) n--;
  1718.             if (vik.prtauto < 256) n--;
  1719.             if (vik.printff < 256) n--;
  1720.             if (vik.compose < 256) n--;
  1721.             if (vik.ucs2 < 256) n--;
  1722.             if (vik.fnkeys  < 256) n--;
  1723.             if (vik.help < 256) n--;
  1724.             if ( vik.exit < 256 && !tt_escape ) n-- ;
  1725.             if ( vik.hangup < 256 && !tt_escape ) n-- ;
  1726.             if ( vik.os2 < 256 && !tt_escape ) n--;
  1727.             if ( vik.xbreak < 256 && !tt_escape ) n--;
  1728.             if ( vik.lbreak < 256 && !tt_escape ) n--;
  1729.             if ( vik.dump < 256 && !tt_escape ) n--;
  1730.             if (vik.quit    < 256) n--;
  1731.             if (vik.status    < 256) n--;
  1732.             if (vik.paste < 256) n--;
  1733.             if ( !tt_escape ) n -= 3 ;
  1734.  
  1735.             if (network) n--;               /* long break not displayed */
  1736.  
  1737.             pPopup = helpstart(60, n, gui_dialog);      /* Make popup window 50 x n */
  1738.             helpline( pPopup, s);           /* 1 */
  1739.             helpline( pPopup, "");          /* 2 */
  1740.  
  1741.             if (vik.exit > 255 && keyname(vik.exit))
  1742.                 ckstrncpy(kn,keyname(vik.exit),40);
  1743.             else if ( tt_escape )
  1744.                 sprintf(kn, "Ctrl-%c?", ctl(escape));
  1745.             else
  1746.                 kn[0] = NUL ;
  1747.             if ( kn[0] ) {
  1748.                 sprintf(line,"  %-25.24s%s",kn,"Return to Command screen");
  1749.                 helpline( pPopup, line);        /* 3 */
  1750.             }
  1751.  
  1752.             if (vik.hangup > 255 && keyname(vik.hangup))
  1753.                 ckstrncpy(kn,keyname(vik.hangup),40);
  1754.             else if     ( tt_escape )
  1755.             sprintf(kn, "Ctrl-%cH", ctl(escape));
  1756.             else
  1757.                 kn[0] = NUL ;
  1758.             if ( kn[0] ) {
  1759.                 sprintf(line,"  %-25.24s%s",kn,"Hang up the connection");
  1760.                 helpline( pPopup, line);        /* 4 */
  1761.             }
  1762.  
  1763.             if (vik.quit > 255 && keyname(vik.quit)) {
  1764.                 ckstrncpy(kn,keyname(vik.quit),40);
  1765.                 sprintf(line,"  %-25.24s%s",kn,"Hangup and Quit");
  1766.                 helpline( pPopup, line);    /* 10 */
  1767.             }
  1768.             if (vik.os2 > 255 && keyname(vik.os2))
  1769.                 ckstrncpy(kn,keyname(vik.os2),40);
  1770.             else if ( tt_escape )
  1771.                 sprintf(kn, "Ctrl-%c!", ctl(escape));
  1772.             else
  1773.                 kn[0] = NUL ;
  1774.             if ( kn[0] ) {
  1775.                 sprintf(line,"  %-25.24s%s",kn,"Enter system command processor");
  1776.                 helpline( pPopup, line);        /* 5 */
  1777.             }
  1778.  
  1779.             if (vik.xbreak > 255 && keyname(vik.xbreak))
  1780.                 ckstrncpy(kn,keyname(vik.xbreak),40);
  1781.             else if ( tt_escape )
  1782.                 sprintf(kn, "Ctrl-%cB", ctl(escape));
  1783.             else
  1784.                 kn[0] = NUL ;
  1785.             if ( kn[0] ) {
  1786.                 sprintf(line,"  %-25.24s%s",kn,
  1787.                      (network && IS_TELNET()) ?
  1788.                      "Send TELNET BREAK" :
  1789.                      "Send a BREAK signal"
  1790.                      );
  1791.                 helpline( pPopup, line);        /* 6 */
  1792.             }
  1793.  
  1794.             if (!network) {
  1795.                 if ((vik.lbreak > 255) && (keyname(vik.lbreak)))
  1796.                     ckstrncpy(kn,keyname(vik.lbreak),40);
  1797.                 else if ( tt_escape )
  1798.                     sprintf(kn, "Ctrl-%cL", ctl(escape));
  1799.                 else
  1800.                     kn[0] = NUL ;
  1801.                 if ( kn[0] ) {
  1802.                 sprintf(line,"  %-25.24s%s",kn,"Send a Long BREAK signal");
  1803.                 helpline( pPopup, line);    /* 7 */
  1804.                 }
  1805.             }
  1806.             if (vik.dump > 255 && keyname(vik.dump))
  1807.                 ckstrncpy(kn,keyname(vik.dump),40);
  1808.             else if ( tt_escape )
  1809.                 sprintf(kn, "Ctrl-%cF", ctl(escape));
  1810.             else
  1811.                 kn[0] = NUL ;
  1812.             if ( kn[0] ) {
  1813.             sprintf(line,"  %-25.24s%s",kn,"Print the current screen");
  1814.             helpline( pPopup, line);        /* 8 */
  1815.             }
  1816.  
  1817.             if (vik.prtctrl > 255 && keyname(vik.prtctrl)) {
  1818.                 ckstrncpy(kn,keyname(vik.prtctrl),40);
  1819.                 sprintf(line,"  %-25.24s%s",
  1820.                          kn,
  1821.                          xprint ?
  1822.                          "Stop printing screen lines" :
  1823.                          "Copy screen lines to printer"
  1824.                          );
  1825.                 helpline( pPopup, line);    /* 9, maybe */
  1826.             }
  1827.             if (vik.prtauto > 255 && keyname(vik.prtauto)) {
  1828.                 ckstrncpy(kn,keyname(vik.prtauto),40);
  1829.                 sprintf(line,"  %-25.24s%s%s",kn,"Turn copy-to-printer ",
  1830.                          aprint ? "OFF" : "ON");
  1831.                 helpline( pPopup, line);    /* 9, maybe */
  1832.             }
  1833.             if (vik.printff > 255 && keyname(vik.printff)) {
  1834.                 ckstrncpy(kn,keyname(vik.printff),40);
  1835.                 sprintf(line,"  %-25.24s%s",kn,"Print formfeed / page eject");
  1836.                 helpline( pPopup, line);    /* 10, maybe */
  1837.             }
  1838.             if (vik.flipscn > 255 && keyname(vik.flipscn)) {
  1839.                 ckstrncpy(kn,keyname(vik.flipscn),40);
  1840.                 sprintf(line,"  %-25.24s%s%s",kn,
  1841.                          (decscnm ? "Normal" : "Reverse"),
  1842.                          " screen video");
  1843.                 helpline( pPopup, line);    /* 13, maybe */
  1844.             }
  1845.             if (vik.debug > 255 && keyname(vik.debug)) {
  1846.                 ckstrncpy(kn,keyname(vik.debug),40);
  1847.                 sprintf(line,"  %-25.24s%s%s",kn,"Turn terminal debugging ",
  1848.                          debses ? "OFF" : "ON");
  1849.                 helpline( pPopup, line);    /* 14, maybe */
  1850.             }
  1851.             if (vik.reset > 255 && keyname(vik.reset)) {
  1852.                 ckstrncpy(kn,keyname(vik.reset),40);
  1853.                 sprintf(line,"  %-25.24s%s",kn,"Reset the terminal emulator");
  1854.                 helpline( pPopup, line);    /* 15, maybe */
  1855.             }
  1856.             if (vik.compose > 255 && keyname(vik.compose)) {
  1857.                 ckstrncpy(kn,keyname(vik.compose),40);
  1858.                 sprintf(line,"  %-25.24s%s",kn,"Compose a special character");
  1859.                 helpline( pPopup, line);    /* 16, maybe */
  1860.             }
  1861.             if (vik.ucs2 > 255 && keyname(vik.ucs2)) {
  1862.                 ckstrncpy(kn,keyname(vik.ucs2),40);
  1863.                 sprintf(line,"  %-25.24s%s",kn,"Compose a Unicode character");
  1864.                 helpline( pPopup, line);    /* 17, maybe */
  1865.             }
  1866.             if (vik.status > 255 && keyname(vik.status)) {
  1867.                 ckstrncpy(kn,keyname(vik.status),40);
  1868.                 sprintf(line,"  %-25.24s%s",kn,"Toggle Status Line");
  1869.                 helpline( pPopup, line);    /* 18 */
  1870.             }
  1871.             if (vik.fnkeys > 255 && keyname(vik.fnkeys)) {
  1872.                 ckstrncpy(kn,keyname(vik.fnkeys),40);
  1873.                 sprintf(line,"  %-25.24s%s",kn,"Display Fn key labels");
  1874.                 helpline( pPopup, line);    /* 19 */
  1875.             }
  1876.             if (vik.paste > 255 && keyname(vik.paste)) {
  1877.                 ckstrncpy(kn,keyname(vik.paste),40);
  1878.                 sprintf(line,"  %-25.24s%s",kn,"Paste clipboard text");
  1879.                 helpline( pPopup, line);    /* 20 */
  1880.             }
  1881.             if (vik.help > 255 && keyname(vik.help)) {
  1882.                 ckstrncpy(kn,keyname(vik.help),40);
  1883. #ifdef KUI
  1884.                 if ( pPopup->gui )
  1885.                     sprintf(line,"  %-25.24s%s",kn,"Help");
  1886.                 else
  1887. #endif /* KUI */
  1888.                     sprintf(line,"  %-25.24s%s",kn,"More help...");
  1889.                 helpline( pPopup, line);    /* 21 */
  1890.             }
  1891.             if ( tt_escape ) {
  1892.             helpline( pPopup, "");          /* 22 */
  1893.             sprintf(line," or the CONNECT-mode escape character Ctrl-%c",
  1894.                      ctl(escape));
  1895.             helpline( pPopup, line);        /* 23 */
  1896.             helpline( pPopup, " followed by ? for additional commands."); /* 22 */
  1897.             }
  1898.         }
  1899.         else {
  1900.             pPopup = helpstart(76, ABOUTHLPSIZE+2, gui_dialog);
  1901.             sprintf(line," %s, for %s",versio,ckxsys);
  1902.             helpline( pPopup, line );
  1903.             for ( c = 0; c < ABOUTHLPSIZE; c++ ) {
  1904.                 s = abouthlpmsg[c] ;
  1905.                 if ( strchr( s, '%') ) {
  1906.                     sprintf(line, s, ctl(escape));
  1907.                     helpline( pPopup, line ) ;
  1908.                 } else
  1909.                     helpline( pPopup, s ) ;
  1910.             }
  1911.             if (vik.help > 255 && keyname(vik.help)) {
  1912.                 ckstrncpy(kn,keyname(vik.help),40);
  1913. #ifdef KUI
  1914.                 if ( pPopup->gui )
  1915.                     sprintf(line,"  Press <Cancel> to exit, or OK for more help");
  1916.                 else
  1917. #endif /* KUI */
  1918.                     sprintf(line,"  Press <SPACE> to exit, or %s for more help",kn);
  1919.             }
  1920.             else {
  1921. #ifdef KUI
  1922.                 if ( pPopup->gui )
  1923.                     sprintf(line,"  Press <Cancel> to exit");
  1924.                 else
  1925. #endif /* KUI */
  1926.                     sprintf(line,"  Press <SPACE> to exit");
  1927.             }
  1928.             helpline( pPopup, line);
  1929.  
  1930.         }
  1931.         break;
  1932.  
  1933.     case hlp_markmode:
  1934.         strcpy(usertext, " Press (almost) any key to restore the screen");
  1935.         exittext[0] = helptext[0] = hostname[0] = NUL;
  1936.  
  1937.         s = " MARK MODE KEYS"; /* Box title */
  1938.         if ( markmodeflag[mode] == inmarkmode ) /* how many lines ? */
  1939.           n = 13 ;
  1940.         else
  1941.           n = 16 ;
  1942.         if (vik.upscn   < 256) n--;     /* Deduct for verbs not assigned */
  1943.         if (vik.upone   < 256) n--;
  1944.         if (vik.dnscn   < 256) n--;
  1945.         if (vik.dnone   < 256) n--;
  1946.         if (vik.homscn  < 256) n--;
  1947.         if (vik.endscn  < 256) n--;
  1948.         if (vik.markstart < 256) n-- ;
  1949.         if (vik.markcancel < 256) n-- ;
  1950.         if ( markmodeflag[mode] == marking ) {
  1951.             if (vik.dump < 256) n--;
  1952.             if (vik.copyclip < 256) n-- ;
  1953.             if (vik.copyhost < 256) n-- ;
  1954.         }
  1955.         pPopup = helpstart(65, n, gui_dialog);      /* Make popup window 70 x n */
  1956.         helpline( pPopup, s);           /* 1 */
  1957.         helpline( pPopup, "");          /* 2 */
  1958.  
  1959.         if (vik.upscn > 255 && keyname(vik.upscn)) {
  1960.             ckstrncpy(kn,keyname(vik.upscn),40);
  1961.             sprintf(line,"  %-26.25s%s",kn,
  1962.                     "Extend selection backward one screen");
  1963.             helpline( pPopup, line);    /* 3 */
  1964.         }
  1965.         if (vik.upone > 255 && keyname(vik.upone)) {
  1966.             ckstrncpy(kn,keyname(vik.upone),40);
  1967.             sprintf(line,"  %-26.25s%s",kn,
  1968.                     "Extend selection backward one line");
  1969.             helpline( pPopup, line);    /* 4 */
  1970.         }
  1971.         if (vik.dnscn > 255 && keyname(vik.dnscn)) {
  1972.             ckstrncpy(kn,keyname(vik.dnscn),40);
  1973.             sprintf(line,"  %-26.25s%s",kn,
  1974.                     "Extend selection forward one screen");
  1975.             helpline( pPopup, line);    /* 5 */
  1976.         }
  1977.         if (vik.dnone > 255 && keyname(vik.dnone)) {
  1978.             ckstrncpy(kn,keyname(vik.dnone),40);
  1979.             sprintf(line,"  %-26.25s%s",kn,
  1980.                     "Extend selection forward one line");
  1981.             helpline( pPopup, line);    /* 6 */
  1982.         }
  1983.         if (vik.homscn > 255 && keyname(vik.homscn)) {
  1984.             ckstrncpy(kn,keyname(vik.homscn),40);
  1985.             sprintf(line,"  %-26.25s%s",kn,
  1986.                     "Extend selection to top of buffer");
  1987.             helpline( pPopup, line);    /* 7 */
  1988.         }
  1989.         if (vik.endscn > 255 && keyname(vik.endscn)) {
  1990.             ckstrncpy(kn,keyname(vik.endscn),40);
  1991.             sprintf(line,"  %-26.25s%s",kn,
  1992.                     "Extend selection to bottom of buffer");
  1993.             helpline( pPopup, line);    /* 8 */
  1994.         }
  1995.         if (vik.exit > 255 && keyname(vik.exit)) {
  1996.             ckstrncpy(kn,keyname(vik.exit),40);
  1997.             sprintf(line,"  %-26.25s%s",kn,"Return to Command screen");
  1998.             helpline( pPopup, line);    /* 9 */
  1999.         }
  2000.         if (vik.markstart > 255 && keyname(vik.markstart)) {
  2001.             ckstrncpy(kn,keyname(vik.markstart),40);
  2002.             sprintf(line,"  %-26.25s%s",kn, markmodeflag[mode] == inmarkmode ?
  2003.                     "Begin selection" :
  2004.                     "Anchor selection at current position"
  2005.                     );
  2006.             helpline( pPopup, line);    /* 10 */
  2007.         }
  2008.         if (vik.markcancel > 255 && keyname(vik.markcancel)) {
  2009.             ckstrncpy(kn,keyname(vik.markcancel),40);
  2010.             sprintf(line,"  %-26.25s%s",kn, "Cancel selection" );
  2011.             helpline( pPopup, line);    /* 11 */
  2012.         }
  2013.         if ( markmodeflag[mode] == marking ) {
  2014.             if (vik.copyclip > 255 && keyname(vik.copyclip)) {
  2015.                 ckstrncpy(kn,keyname(vik.copyclip),40);
  2016.                 sprintf(line,"  %-26.25s%s",kn,
  2017.                         "Copy selection to clipboard" );
  2018.                 helpline( pPopup, line); /* 12 */
  2019.             }
  2020.             if (vik.copyhost > 255 && keyname(vik.copyhost)) {
  2021.                 ckstrncpy(kn,keyname(vik.copyhost),40);
  2022.                 sprintf(line,"  %-26.25s%s",kn,
  2023.                         "Transmit selection" );
  2024.                 helpline( pPopup, line); /* 13 */
  2025.             }
  2026.             if (vik.dump > 255 && keyname(vik.dump)) {
  2027.                 ckstrncpy(kn,keyname(vik.dump),40);
  2028.                 sprintf(line,"  %-26.25s%s",kn,
  2029.                         "Copy selection to printer (or file)");
  2030.                 helpline( pPopup, line); /* 14 */
  2031.             }
  2032.         }
  2033.         helpline( pPopup, "");          /* 12/15 */
  2034.         helpline( pPopup,               /* 13/16 */
  2035.                   " You can also use the arrow keys to modify the selection.");
  2036.         break;
  2037.  
  2038. #ifdef OS2MOUSE
  2039.     case hlp_mouse:
  2040.         strcpy(usertext, " Press (almost) any key to restore the screen");
  2041.         exittext[0] = helptext[0] = hostname[0] = NUL;
  2042.  
  2043.         n = 21;                         /* How many lines */
  2044.         s = " MOUSE ACTIONS";
  2045.         if (!vik.mou_curpos)   n--;     /* Deduct for verbs not assigned */
  2046.         if (!vik.mou_copyhost) n--;
  2047.         if (!vik.mou_copyclip) n--;
  2048.         if (!vik.mou_paste)    n--;
  2049.         if (!vik.mou_dump)     n--;
  2050.         if (!vik.mou_mark)     n--;
  2051.         if (!vik.mou_url)      n--;
  2052.         if (vik.help < 256)    n--;
  2053.         if (!vik.backsrch)     n--;
  2054.         if (!vik.backnext)     n--;
  2055.         if (!vik.fwdsrch)      n--;
  2056.         if (!vik.fwdnext)      n--;
  2057.         if (!vik.setbook)      n--;
  2058.         if (!vik.gobook)       n--;
  2059.         if (!vik.xgoto)        n--;
  2060.  
  2061.         pPopup = helpstart(70, n, gui_dialog);      /* Make popup window 70 x n */
  2062.         helpline( pPopup, s);           /* 1 */
  2063.         helpline( pPopup, "");          /* 2 */
  2064.  
  2065.         if (vik.mou_curpos) {
  2066.             ckstrncpy(kn,mousename(vik.mou_curpos>>5,vik.mou_curpos&0x1F),40);
  2067.             sprintf(line,"  %-31.30s%s",kn,"Move cursor to new position");
  2068.             helpline( pPopup, line);    /* 3 */
  2069.         }
  2070.         if (vik.mou_copyhost) {
  2071.            ckstrncpy(kn,mousename(vik.mou_copyhost>>5,vik.mou_copyhost&0x1F),40);
  2072.             sprintf(line,"  %-31.30s%s",kn,"Select text and transmit it");
  2073.             helpline( pPopup, line);    /* 4 */
  2074.         }
  2075.         if (vik.mou_copyclip) {
  2076.            ckstrncpy(kn,mousename(vik.mou_copyclip>>5,vik.mou_copyclip&0x1F),40);
  2077.             sprintf(line,"  %-31.30s%s",kn,"Select and copy to Clipboard");
  2078.             helpline( pPopup, line);     /* 5 */
  2079.         }
  2080.         if (vik.mou_dump) {
  2081.             ckstrncpy(kn,mousename(vik.mou_dump>>5,vik.mou_dump&0x1F),40);
  2082.             sprintf(line,
  2083.                     "  %-31.30s%s",kn,"Select and copy to printer (or file)");
  2084.             helpline( pPopup, line);    /* 6 */
  2085.         }
  2086.         if (vik.mou_mark) {
  2087.             ckstrncpy(kn,mousename(vik.mou_mark>>5,vik.mou_mark&0x1F),40);
  2088.             sprintf(line,"  %-31.30s%s",kn,"Select but don't copy");
  2089.             helpline( pPopup, line);    /* 7 */
  2090.         }
  2091.         if (vik.mou_paste) {
  2092.             ckstrncpy(kn,mousename(vik.mou_paste>>5,vik.mou_paste&0x1F),40);
  2093.             sprintf(line,
  2094.                     "  %-31.30s%s",kn,"Transmit from clipboard");
  2095.             helpline( pPopup, line);    /* 8 */
  2096.         }
  2097.         if (vik.mou_url) {
  2098.             ckstrncpy(kn,mousename(vik.mou_url>>5,vik.mou_url&0x1F),40);
  2099.             sprintf(line,"  %-31.30s%s",kn,"Start browser with URL");
  2100.             helpline( pPopup, line);    /* 7 */
  2101.         }
  2102.         helpline( pPopup, "");          /* 9 */
  2103.         helpline( pPopup, " SEARCHING AND BOOKMARKS"); /* 10 */
  2104.         helpline( pPopup, "");          /* 11 */
  2105.         if (vik.backsrch > 255 && keyname(vik.backsrch)) {
  2106.             ckstrncpy(kn,keyname(vik.backsrch),40);
  2107.             sprintf(line,"  %-31.30s%s",kn,"Search backward");
  2108.             helpline( pPopup, line);    /* 12 */
  2109.         }
  2110.         if (vik.backnext > 255 && keyname(vik.backnext)) {
  2111.             ckstrncpy(kn,keyname(vik.backnext),40);
  2112.             sprintf(line,"  %-31.30s%s",kn,"Next occurrence backward");
  2113.             helpline( pPopup, line);    /* 13 */
  2114.         }
  2115.         if (vik.fwdsrch > 255 && keyname(vik.fwdsrch)) {
  2116.             ckstrncpy(kn,keyname(vik.fwdsrch),40);
  2117.             sprintf(line,"  %-31.30s%s",kn,"Search forward");
  2118.             helpline( pPopup, line);    /* 14 */
  2119.         }
  2120.         if (vik.fwdnext > 255 && keyname(vik.fwdnext)) {
  2121.             ckstrncpy(kn,keyname(vik.fwdnext),40);
  2122.             sprintf(line,"  %-31.30s%s",kn,"Next occurrence forward");
  2123.             helpline( pPopup, line);    /* 15 */
  2124.         }
  2125.         if (vik.setbook > 255 && keyname(vik.setbook)) {
  2126.             ckstrncpy(kn,keyname(vik.setbook),40);
  2127.             sprintf(line,"  %-31.30s%s",kn,"Set bookmark");
  2128.             helpline( pPopup, line);    /* 16 */
  2129.         }
  2130.         if (vik.gobook > 255 && keyname(vik.gobook)) {
  2131.             ckstrncpy(kn,keyname(vik.gobook),40);
  2132.             sprintf(line,"  %-31.30s%s",kn,"Go to bookmark");
  2133.             helpline( pPopup, line);    /* 17 */
  2134.         }
  2135.         if (vik.xgoto > 255 && keyname(vik.xgoto)) {
  2136.             ckstrncpy(kn,keyname(vik.xgoto),40);
  2137.             sprintf(line,"  %-31.30s%s",kn,"Go to line");
  2138.             helpline( pPopup, line);    /* 18 */
  2139.         }
  2140.         helpline( pPopup, "");          /* 19 */
  2141.         if (vik.help > 255 && keyname(vik.help)) {
  2142.             ckstrncpy(kn,keyname(vik.help),40);
  2143. #ifdef KUI
  2144.             if ( pPopup->gui )
  2145.                 sprintf(line," %-32.31s%s",kn,"Help");
  2146.             else
  2147. #endif /* KUI */
  2148.                 sprintf(line," %-32.31s%s",kn,"Back to first help screen...");
  2149.             helpline( pPopup, line);    /* 20 */
  2150.         }
  2151.         break;
  2152. #endif /* OS2MOUSE */
  2153.     } /* switch */
  2154.  
  2155.     helpend(pPopup);                    /* Write bottom of help panel */
  2156. #ifdef KUI
  2157.     if ( pPopup->gui )
  2158.         c = gui_videopopup_dialog(pPopup, 0);
  2159.     else
  2160. #endif /* KUI */
  2161.     {
  2162.     VscrnSetPopup( mode, pPopup ) ;
  2163.     /* wait until user presses a key */
  2164.     evt = congev(mode,-1);
  2165.     while ( evt.type != key
  2166. #ifndef NOKVERBS
  2167.             && evt.type != kverb
  2168. #endif /* NOKVERBS */
  2169.             ) {
  2170.         if ( evt.type != error )
  2171.             bleep( BP_WARN ) ;
  2172.         evt = congev(mode,-1);
  2173.     }
  2174. #ifndef NOKVERBS
  2175.     if ( evt.type == kverb )
  2176.         c = F_KVERB | evt.kverb.id ;
  2177.     else
  2178. #endif /* NOKVERBS */
  2179.     {
  2180.         c = 0 ;
  2181.     }
  2182.     VscrnResetPopup(mode) ;            /* This frees the Popup structure */
  2183.     }
  2184.  
  2185.     restore_status_line();
  2186.     return (c);
  2187. #else /* NOKVERBS */
  2188.     return(-1);
  2189. #endif /* NOKVERBS */
  2190. }
  2191. #endif /* NOLOCAL */
  2192.  
  2193.  
  2194. int                                     /* NOTE: not static, on purpose */
  2195. ttgwsiz() {                             /* Get Terminal Window Size */
  2196. #ifndef NOLOCAL
  2197. #ifndef KUI
  2198.    CK_VIDEOMODEINFO mi ;
  2199.  
  2200.    if (GetMode(&mi))
  2201.        return 1;
  2202.    debug(F101,"ttgwsiz mi.row","",mi.row);
  2203.    debug(F101,"ttgwsiz mi.col","",mi.col);
  2204.    debug(F101,"ttgwsiz tt_rows","",tt_rows[VTERM]);
  2205.    debug(F101,"ttgwsiz tt_cols","",tt_cols[VTERM]);
  2206.  
  2207.    if ( mi.row != tt_rows[VTERM] + (tt_status[VTERM]?1:0) || mi.col != tt_cols[VTERM] ) {
  2208.        tt_rows[VTERM] = (mi.row > MAXSCRNROW ? MAXSCRNROW : mi.row)- (tt_status[VTERM]?1:0) ;
  2209.        tt_cols[VTERM] = (mi.col > MAXSCRNCOL ? MAXSCRNCOL : mi.col);
  2210.        checkscreenmode();
  2211.    }
  2212. #endif /* KUI */
  2213. #endif /* NOLOCAL */
  2214.    return((tt_rows[VTERM] < 1 || tt_cols[VTERM] < 1) ? 0 : 1);
  2215. }
  2216.  
  2217. int                                     /* NOTE: not static, on purpose */
  2218. ttgcwsz() {                             /* Get Command Window Size */
  2219. #ifndef NOLOCAL
  2220. #ifndef KUI
  2221.     CK_VIDEOMODEINFO mi ;
  2222.     extern int tt_modechg;
  2223.  
  2224. #ifdef IKSD
  2225.     if ( inserver )
  2226.         return(0);
  2227. #endif /* IKSD */
  2228.  
  2229.     if (GetMode(&mi))
  2230.         return 1;
  2231.  
  2232.     debug(F101,"ttgcwsiz mi.row","",mi.row);
  2233.     debug(F101,"ttgcwsiz mi.col","",mi.col);
  2234.     debug(F101,"ttgcwsiz cmd_rows","",cmd_rows);
  2235.     debug(F101,"ttgcwsiz cmd_cols","",cmd_cols);
  2236.     if ( tt_modechg == TVC_W95 && ( mi.row > cmd_rows || mi.col > cmd_cols) ||
  2237.          tt_modechg == TVC_ENA && (mi.row != cmd_rows + (tt_status[VCMD]?1:0) ||
  2238.                                    mi.col != cmd_cols) ) {
  2239.         tt_rows[VCMD] = cmd_rows = (mi.row > MAXSCRNROW ? MAXSCRNROW : mi.row) - (tt_status[VCMD]?1:0);
  2240.         tt_cols[VCMD] = cmd_cols = (mi.col > MAXSCRNCOL ? MAXSCRNCOL : mi.col);
  2241.     }
  2242. #endif /* KUI */
  2243. #endif /* NOLOCAL */
  2244.    return((cmd_rows < 1 || cmd_cols < 1) ? 0 : 1);
  2245. }
  2246.  
  2247. #ifndef NOLOCAL
  2248. /* CHECKSCREENMODE  --  Make sure we are in a usable mode */
  2249. /* JEFFA ??? - I don't know what checkscreenmode() should do */
  2250.  
  2251. void
  2252. checkscreenmode() {
  2253. #ifndef KUI
  2254.     CK_VIDEOMODEINFO  m;
  2255. #endif /* KUI */
  2256.  
  2257.     debug(F100,"checkscreenmode","",0);
  2258. #ifndef KUI
  2259.     if (GetMode(&m))
  2260.         return;
  2261.  
  2262.     ttgcwsz();
  2263. #endif /* KUI */
  2264.  
  2265.     if ( VscrnGetBufferSize(VTERM) != tt_scrsize[VTERM] || VscrnGetWidth(VTERM) <= 0
  2266.         || VscrnGetHeight(VTERM) <= 0 || tt_cols[VTERM] <= 0 || tt_rows[VTERM] <= 0 ) {
  2267.         scrninitialized[VTERM] = 0;
  2268.  
  2269.         debug(F101,"tt_cols","",tt_cols[VTERM]);
  2270.         debug(F101,"tt_rows","",tt_rows[VTERM]);
  2271. #ifndef KUI
  2272.         debug(F101,"m.row","",m.row);
  2273.         debug(F101,"m.col","",m.col);
  2274.  
  2275.         if ( tt_cols[VTERM] <= 0 || tt_rows[VTERM] <= 0 ) {
  2276.             tt_cols[VTERM] = min(MAXTERMCOL, m.col);
  2277.             tt_rows[VTERM] = min(MAXTERMROW, m.row-1);
  2278.         }
  2279. #endif /* KUI */
  2280.  
  2281.         if ( VscrnGetWidth(VTERM) <= 0 ) {
  2282.             VscrnSetWidth( VTERM, tt_cols[VTERM] );
  2283.         }
  2284.  
  2285.         if ( VscrnGetHeight(VTERM) <= 0 ) {
  2286.             debug(F101,"tt_rows[VTERM]","",tt_rows[VTERM]);
  2287.             VscrnSetHeight( VTERM, tt_rows[VTERM]+(tt_status[VTERM]?1:0) );
  2288.         }
  2289.  
  2290.         marginbot = VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0);
  2291.     }
  2292.  
  2293. #ifndef KUI
  2294.     vt100screen.mi = m;
  2295.     vt100screen.mi.row = tt_rows[VTERM] + (tt_status[VTERM]?1:0) ;
  2296.     vt100screen.mi.col = tt_cols[VTERM] ;
  2297. #ifdef NT
  2298.     vt100screen.mi.sbrow = vt100screen.mi.row;
  2299.     vt100screen.mi.sbcol = vt100screen.mi.col;
  2300. #endif /* NT */
  2301. #endif /* KUI */
  2302.     vt100screen.att = defaultattribute ;
  2303. }
  2304.  
  2305. void
  2306. setcursormode() {
  2307. #ifdef NT
  2308.     CK_CURSORINFO vci={88,0,8,1};
  2309. #else
  2310.     CK_CURSORINFO vci={-88,0,8,1};
  2311.     extern HVIO VioHandle ;
  2312.     VIOINTENSITY vi;
  2313. #endif /* NT */
  2314.     int cell, bottom, top;
  2315.  
  2316.     if (!GetCurType(&vci))
  2317.         crsr_command = vci;
  2318.  
  2319. #ifdef NT
  2320.     switch (tt_cursor) {
  2321.         case 0:
  2322.             vci.yStart = 12 ;
  2323.             break;
  2324.         case 1:
  2325.             vci.yStart = 50 ;
  2326.             break;
  2327.         case 2:
  2328.             vci.yStart = 88 ;
  2329.             break;
  2330.         }
  2331.     SetCurType(&vci);
  2332. #else /* NT */
  2333.     vci.cEnd   = -100;
  2334.     switch (tt_cursor) {
  2335.         case 0:
  2336.             vci.yStart = -90 ;
  2337.             break;
  2338.         case 1:
  2339.             vci.yStart = -50 ;
  2340.             break;
  2341.         case 2:
  2342.             vci.yStart = -10 ;
  2343.             break;
  2344.         }
  2345.     SetCurType(&vci);
  2346. /*
  2347.   Note: For some reason, choosing vi.fs = 0 makes *everything* blink.
  2348.   Receipt of "turn-on-blink" escape sequences turn off blinking.  Thus,
  2349.   everything is backwards.  But when vi.fs = 1, the sense is not reversed.
  2350.   A puzzle.
  2351. */
  2352.     vi.cb = sizeof(vi);
  2353.     vi.type = 2;                        /* High-intensity vs blinking */
  2354.     vi.fs = 1;                          /* 0 = blinking, 1 = hi intensity */
  2355.     VioSetState((PVOID) &vi, VioHandle);
  2356. #endif /* NT */
  2357. }
  2358.  
  2359. void
  2360. restorecursormode() {
  2361.     debug(F100,"restorecursormode","",0);
  2362.     SetCurType(&crsr_command);
  2363. }
  2364.  
  2365. static void
  2366. doesc(int c) {
  2367.     int x;
  2368.     CHAR d, temp[8];
  2369.  
  2370.     while (1) {
  2371.         if (tt_escape && c == escape) { /* Send escape character */
  2372.             sendchar((char)c);
  2373.             return;
  2374.         } else if (isupper(c))  /* Or else look it up below. */
  2375.             c = tolower(c);
  2376.  
  2377.         switch (c) {
  2378.  
  2379.         case 'c':               /* Return to prompt */
  2380.         case '\03':
  2381.             SetConnectMode(0,CSX_ESCAPE);
  2382.             return;
  2383.  
  2384.         case 'u':               /* Hangup and return to command mode */
  2385.             hangnow = 1;
  2386.             SetConnectMode(0,CSX_USERDISC);
  2387.             strcpy(termessage, "Hangup.\n");
  2388.             return;
  2389.  
  2390.         case 'q':               /* Hangup and quit */
  2391.             SetConnectMode(0,CSX_USERDISC);
  2392.             hangnow = 1;
  2393.             quitnow = 1;
  2394.             strcpy(termessage, "Hangup and quit.\n");
  2395.             return;
  2396.  
  2397. #ifndef NOPUSH
  2398.         case '!': {             /* Push to OS/2 */
  2399.             os2push();
  2400.             return;
  2401.        }
  2402. #endif /* NOPUSH */
  2403.  
  2404.         case 'b':               /* Send a BREAK signal */
  2405.         case '\02':
  2406. #ifdef CKLEARN
  2407.             {
  2408.                 con_event evt;
  2409.                 evt.type = kverb;
  2410.                 evt.kverb.id = K_BREAK;
  2411.                 learnkeyb(evt, LEARN_KEYBOARD);
  2412.             }
  2413. #endif /* CKLEARN */
  2414.             ttsndb();
  2415.             return;
  2416.  
  2417.         case 'l':               /* Send a Long BREAK signal */
  2418.         case '\014':
  2419. #ifdef CKLEARN
  2420.             {
  2421.                 con_event evt;
  2422.                 evt.type = kverb;
  2423.                 evt.kverb.id = K_LBREAK;
  2424.                 learnkeyb(evt, LEARN_KEYBOARD);
  2425.             }
  2426. #endif /* CKLEARN */
  2427.             ttsndlb();
  2428.             return;
  2429.  
  2430.         case 'f': {              /* Print/dump screen */
  2431.             extern bool xprintff;
  2432.             x = xprintff;
  2433.             xprintff = 0;
  2434.             prtscreen(VTERM,1,VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0));
  2435.             xprintff = x;
  2436.             return;
  2437.         }
  2438.  
  2439.         case '0':               /* Send a NUL character */
  2440.             c = '\0';
  2441.             sendchar((char)c);
  2442.             return;
  2443.  
  2444. #ifdef NETCONN
  2445. #ifdef TCPSOCKET
  2446.         case 'i':                       /* Send TELNET Interrupt Process */
  2447. #ifdef CKLEARN
  2448.             {
  2449.                 con_event evt;
  2450.                 evt.type = kverb;
  2451.                 evt.kverb.id = K_TN_IP;
  2452.                 learnkeyb(evt, LEARN_KEYBOARD);
  2453.             }
  2454. #endif /* CKLEARN */
  2455.             do_tn_cmd((CHAR) TN_IP);
  2456.             return;
  2457.  
  2458.         case 'a':                       /* "Are You There?" */
  2459. #ifdef CKLEARN
  2460.             {
  2461.                 con_event evt;
  2462.                 evt.type = kverb;
  2463.                 evt.kverb.id = K_TN_AYT;
  2464.                 learnkeyb(evt, LEARN_KEYBOARD);
  2465.             }
  2466. #endif /* CKLEARN */
  2467.             do_tn_cmd((CHAR) TN_AYT);
  2468.             return;
  2469. #endif /* TCPSOCKET */
  2470. #endif /* NETCONN */
  2471.  
  2472.         case '\\':
  2473.             {
  2474.             char kbuf[32];
  2475.             char *kbp = kbuf, *text = usertext + 2;
  2476.  
  2477.                 *kbp++ = c;
  2478.  
  2479.             strcpy(helptext, " \\");
  2480.             strcpy(exittext,"Exit: ENTER");
  2481.             helptext[0] = 0;
  2482.             VscrnIsDirty(VTERM);  /* status line needs to be updated */
  2483.  
  2484.                 while (((c = (coninc(0) & cmdmsk)) != '\r') && (c != '\n')) {
  2485.                 if ( c == '\b' ) {
  2486.                     if ( kbp > kbuf + 1 ) {
  2487.                                 *--kbp = 0;
  2488.                         *--text = 0;
  2489.                         }
  2490.                     }
  2491.                 else if ( kbp - kbuf < sizeof(kbuf) - 2 ) {
  2492.                             *kbp++ = c;
  2493.                     *text++ = c;
  2494.                     *text = 0;
  2495.                     }
  2496.                 VscrnIsDirty(VTERM);  /* status line needs to be updated */
  2497.                 }
  2498.  
  2499.                 *kbp = 0; kbp = kbuf;
  2500.                 c = xxesc(&kbp);        /* Interpret it */
  2501.  
  2502.                 if (c >= 0) {
  2503.                     sendcharduplex((char)c,FALSE);
  2504.                     return;
  2505.                 } else {                /* Invalid backslash code. */
  2506.                     bleep(BP_WARN);
  2507.                     return;
  2508.                 }
  2509.             }
  2510.             return;
  2511.  
  2512.         case SP:                /* Space, ignore */
  2513.             return;
  2514.  
  2515.         default:                /* Other */
  2516.             bleep(BP_WARN);
  2517.             return;             /* Invalid esc arg, beep */
  2518.         }
  2519.     }
  2520. }
  2521.  
  2522. int
  2523. kbdlocked(void)
  2524. {
  2525.     extern int tt_rkeys[];
  2526.  
  2527.     if ( keylock )
  2528.         return 1;
  2529.  
  2530.     if (scrollflag[VTERM]) {
  2531.         switch ( tt_rkeys[VTERM] ) {
  2532.         case TTRK_IGN:
  2533.             return 1;
  2534.         case TTRK_RST:
  2535.             scrollflag[VTERM] = 0;
  2536.             scrollstatus[VTERM] = 0;
  2537.             ipadl25();
  2538.             os2settitle(NULL, 1);
  2539.             VscrnIsDirty(VTERM);
  2540.             return 0;
  2541.         case TTRK_SND:
  2542.             return 0;
  2543.         }
  2544.     }
  2545.     return 0;
  2546. }
  2547.  
  2548. /* C O N K B D H A N D L E R */
  2549.  
  2550. void
  2551. con2host(con_event evt)
  2552. {
  2553.     int c;
  2554.  
  2555.     switch ( evt.type ) {
  2556.     case key:
  2557.         c = evt.key.scancode ;
  2558.         if (tt_escape && c == escape) { /* Is it the escape character? */
  2559.             save_status_line();         /* Yes, save current status line.  */
  2560.             escapestatus[VTERM] = TRUE ;
  2561.             esc25(0);                   /* Make new one. */
  2562.             evt = congev(VTERM,0);
  2563.             while ( evt.type != key ) {
  2564.                 bleep( BP_WARN ) ;
  2565.                 evt = congev(VTERM,0);
  2566.             }
  2567.  
  2568.             c = evt.key.scancode ;
  2569.             if (c == '?' || c == 'h' || c == 'H') { /* They want help menu. */
  2570.                 esc25(1);               /* Show it */
  2571.                 c = popuphelp(VTERM,hlp_escape);    /* Then get real escape command */
  2572.             }
  2573.             if (c != escape) {
  2574.                 doesc(c);               /* And process it */
  2575.                 escapestatus[VTERM] = FALSE ;
  2576.                 restore_status_line();      /* Then restore status line */
  2577.                 if ( tt_idlelimit /* || tt_idlesnd_tmo */)
  2578.                     idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2579.                 break;
  2580.             }
  2581.             restore_status_line();
  2582.         }
  2583.  
  2584.         /* Ordinary character */
  2585. #ifdef CKLEARN
  2586.         if (c == CR)
  2587.             learnkeyb(evt, LEARN_NEUTRAL);
  2588.         else
  2589.             learnkeyb(evt, LEARN_KEYBOARD);
  2590. #endif /* CKLEARN */
  2591.         vt100key(c);                /* go process it. */
  2592.         if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2593.             idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2594.         break;
  2595.  
  2596. #ifndef NOKVERBS
  2597.     case kverb:
  2598. #ifdef CKLEARN
  2599.         switch ( evt.kverb.id | F_KVERB ) {
  2600.         case F_KVERB | K_KPENTER:
  2601.         case F_KVERB | K_WYENTER:
  2602.         case F_KVERB | K_WYRETURN:
  2603.         case F_KVERB | K_TVIENTER:
  2604.         case F_KVERB | K_TVIRETURN:
  2605.         case F_KVERB | K_HPENTER:
  2606.         case F_KVERB | K_HPRETURN:
  2607.             learnkeyb(evt, LEARN_NEUTRAL);
  2608.             break;
  2609.         default:
  2610.             learnkeyb(evt, LEARN_KEYBOARD);
  2611.             break;
  2612.         }
  2613. #endif /* CKLEARN */
  2614.         dokverb( VTERM, evt.kverb.id ) ;
  2615.         if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2616.             idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2617.         break;
  2618. #endif /* NOKVERBS */
  2619.     case macro:
  2620.         if ( !kbdlocked() ) {
  2621. #ifdef CKLEARN
  2622.             int len = strlen(evt.macro.string);
  2623.             if (evt.macro.string[len-1] == CR ||
  2624.                 evt.macro.string[len-2] == CR && evt.macro.string[len-1] == LF)
  2625.                 learnkeyb(evt,LEARN_NEUTRAL);
  2626.             else
  2627.                 learnkeyb(evt, LEARN_KEYBOARD);
  2628. #endif /* CKLEARN */
  2629.             sendkeydef( evt.macro.string, FALSE ) ;
  2630.             if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2631.                 idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2632.         }
  2633.         if ( evt.macro.string )
  2634.             free( evt.macro.string ) ;
  2635.         break;
  2636.  
  2637.     case literal:
  2638.         if ( !kbdlocked() ) {
  2639. #ifdef CKLEARN
  2640.             int len = strlen(evt.literal.string);
  2641.             if (evt.literal.string[len-1] == CR ||
  2642.                 evt.literal.string[len-2] == CR && evt.literal.string[len-1] == LF)
  2643.                 learnkeyb(evt,LEARN_NEUTRAL);
  2644.             else
  2645.                 learnkeyb(evt, LEARN_KEYBOARD);
  2646. #endif /* CKLEARN */
  2647.             sendkeydef( evt.literal.string, TRUE ) ;
  2648.             if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2649.                 idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2650.         }
  2651.         if ( evt.literal.string )
  2652.             free( evt.literal.string ) ;
  2653.         break;
  2654.  
  2655.     case esc:
  2656.         if ( !kbdlocked() ) {
  2657.             char buf[2] ;
  2658. #ifdef CKLEARN
  2659.             learnkeyb(evt, LEARN_KEYBOARD);
  2660. #endif /* CKLEARN */
  2661.             buf[0] = evt.esc.key & ~F_ESC ;
  2662.             buf[1] = '\0' ;
  2663.             sendescseq(buf) ;
  2664.             if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2665.                 idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2666.         }
  2667.         break;
  2668.  
  2669.     case csi:
  2670.         if ( !kbdlocked() ) {
  2671.             char buf[3] ;
  2672. #ifdef CKLEARN
  2673.             learnkeyb(evt, LEARN_KEYBOARD);
  2674. #endif /* CKLEARN */
  2675.             buf[0] = '[' ;
  2676.             buf[1] = evt.csi.key & ~F_CSI ;
  2677.             buf[2] = '\0' ;
  2678.             sendescseq(buf);
  2679.             if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2680.                 idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2681.         }
  2682.         break;
  2683. #ifdef OS2MOUSE
  2684.       case mouse:
  2685.         debug( F100, "con2host - a mouse event arrived, ignored","",0);
  2686.         if ( tt_idlelimit /*|| tt_idlesnd_tmo*/ )
  2687.             idlesnd_t = keypress_t = time(NULL);/* Remember the time */
  2688.         break;
  2689. #endif /* OS2MOUSE */
  2690.       case error:
  2691.         if ( ttyfd != -1 && ttyfd != -2 &&
  2692.              /* tt_idlesnd_tmo */ tt_idlelimit &&
  2693.              ((tt_idleact == IDLE_OUT && tt_idlesnd_str && tt_idlesnd_str[0]) ||
  2694.                tt_idleact == IDLE_TNOP || tt_idleact == IDLE_TAYT) &&
  2695.              IsConnectMode() &&
  2696.              (time(NULL) - idlesnd_t) > /* tt_idlesnd_tmo */ tt_idlelimit ) {
  2697.             switch (tt_idleact) {
  2698.             case IDLE_OUT:
  2699.                 debug( F111, "con2host - idle send string sent",
  2700.                        tt_idlesnd_str,/*tt_idlesnd_tmo*/ tt_idlelimit);
  2701.                 sendkeydef( tt_idlesnd_str, FALSE ) ;
  2702.                 break;
  2703.             case IDLE_TNOP:
  2704.                 debug(F100, "con2host - idle Telnet NOP","",0);
  2705.                 do_tn_cmd((CHAR) TN_NOP);
  2706.                 break;
  2707.             case IDLE_TAYT:
  2708.                 debug(F100, "con2host - idle Telnet AYT","",0);
  2709.                 do_tn_cmd((CHAR) TN_AYT);
  2710.                 break;
  2711.             }
  2712.             idlesnd_t = time(NULL);     /* Remember the time */
  2713.         }
  2714.         else
  2715.             debug( F100, "con2host - an error event arrived, ignored","",0);
  2716.         break;
  2717.     }
  2718.  
  2719. }
  2720.  
  2721. void
  2722. conkbdhandler(void *pArgList) {
  2723.     int c, cm, cx, tx, evtcnt;
  2724.     int prty = priority, boost = FALSE;
  2725.     con_event evt ;
  2726.     extern int Shutdown;
  2727. #ifdef OS2PM
  2728.     HAB oldhab = hab ;
  2729.  
  2730.     hab = WinInitialize(0);
  2731.     debug ( F101, "WinInitialize hab","",hab) ;
  2732. #endif /* OS2PM */
  2733.  
  2734.     PostConKbdHandlerThreadSem();
  2735. #ifdef NT
  2736.     setint();
  2737.     SetThreadPrty(priority,isWin95() ? 2 : 11);
  2738. #else
  2739.     SetThreadPrty(priority,4);
  2740. #endif
  2741.  
  2742.     while ( !Shutdown ) {         /* Read the keyboard and write to comms line */
  2743.  
  2744.         if (
  2745. #ifdef KUI
  2746. #ifndef K95G
  2747.              0 &&
  2748. #endif /* K95G */
  2749. #endif /* KUI */
  2750.              (!IsConnectMode() ||
  2751. #ifdef COMMENT
  2752.                what != W_CONNECT ||
  2753. #endif /* COMMENT */
  2754.              VscrnIsPopup(VTERM) ||
  2755.              ttyfd == -1
  2756. #ifdef CK_TAPI
  2757.              || ttyfd == -2
  2758. #endif /* CK_TAPI */
  2759.              )) {
  2760.             /* debug(F110,"conkbdhandler",
  2761.                "Waiting for CONNECT_MODE or HOLDSCREEN",0); */
  2762.             if (prty != -1 ) {
  2763.                 prty = -1;      /* lie */
  2764.                 SetThreadPrty(XYP_REG,0);
  2765.             }
  2766.             msleep(500);
  2767.             continue;
  2768.         }
  2769.  
  2770.         evtcnt = evtinbuf(VTERM);
  2771.         if ( evtcnt >= 5 && (!boost || prty != priority)) {
  2772. #ifdef NT
  2773.             SetThreadPrty(priority,isWin95() ? 6 : 13);
  2774. #else
  2775.             SetThreadPrty(priority,6);
  2776. #endif
  2777.             boost = TRUE;
  2778.             prty = priority;
  2779.         }
  2780.         else if ( evtcnt <= 0 && (boost || prty != priority)) {
  2781. #ifdef NT
  2782.             SetThreadPrty(priority,isWin95() ? 3 : 11);
  2783. #else
  2784.             SetThreadPrty(priority,4);
  2785. #endif
  2786.             boost = FALSE;
  2787.             prty = priority;
  2788.         }
  2789.  
  2790.         evt = congev( VTERM,                    /* Read the VTERM event queue */
  2791. #ifdef COMMENT
  2792.                       tt_idlesnd_tmo?tt_idlesnd_tmo:-1
  2793. #else
  2794.                       (tt_idlelimit &&
  2795.                         (tt_idleact == IDLE_OUT || tt_idleact == IDLE_TNOP ||
  2796.                          tt_idleact == IDLE_TAYT)) ? tt_idlelimit : -1
  2797. #endif /* COMMENT */
  2798.                       );
  2799.         con2host(evt);
  2800.     }  /* while (IsConnectMode()) */
  2801.  
  2802. #ifdef COMMENT
  2803.     WinTerminate(hab) ;
  2804.     hab = oldhab ;
  2805. #endif /* COMMENT */
  2806.     PostConKbdHandlerThreadDownSem();  /* signal thread termination */
  2807.     ckThreadEnd(pArgList) ;
  2808. }
  2809.  
  2810. /* Update the Answerback message
  2811.    with current terminal type
  2812.    and version number
  2813. */
  2814. void
  2815. updanswerbk( void )
  2816. {
  2817.     if ( safeanswerbk ) {
  2818.         sprintf(answerback,
  2819.                  useranswerbk[0] ? "%s %ld %s_%s\n" : "%s %ld %s\n",
  2820.              "K-95",
  2821.              vernum,
  2822.              tt_info[tt_type].x_name,
  2823.              useranswerbk
  2824.             );
  2825.     }
  2826.     else {
  2827.         ckstrncpy( answerback, useranswerbk, 80 ) ;
  2828.         ckstrncat( answerback, "\n", 80 ) ;
  2829.     }
  2830.  
  2831. }
  2832.  
  2833. /*  C O N E C T  --  Perform CONNECT command  */
  2834.  
  2835. static time_t start_t = 0;
  2836. static time_t now_t = 0;
  2837. static int viewonly_sav = 0;
  2838. static bool keylocksav = 0;
  2839. static int  holdscreensav;
  2840.  
  2841. extern int term_io;
  2842. extern int holdscreen;
  2843.  
  2844.  
  2845. void
  2846. isconnect()
  2847. {
  2848.     /* ResetThreadPrty();   already done */
  2849.     while (IsConnectMode()) {
  2850.         msleep( 500 ) ;
  2851.         if ( apcactive == APC_INACTIVE || !tt_async ) {
  2852.             if ( tt_timelimit || tt_idlelimit )
  2853.                 now_t = time(NULL);
  2854.             if (viewonly)
  2855.                 continue;
  2856.  
  2857.             if ( ttchk() < 0 )
  2858.                 SetConnectMode(0,CSX_HOSTDISC);
  2859.  
  2860. #ifdef BETATEST
  2861.             if (!term_io)
  2862.                 debug(F100,"term_io is false while Connect monitor thread running\r\n","",0);
  2863. #endif /* BETATEST */
  2864.  
  2865. #ifdef IKS_OPTION
  2866.             if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  2867.                 SetConnectMode(0,CSX_IKSD);
  2868. #endif /* IKS_OPTION */
  2869.  
  2870. #ifdef COMMENT
  2871. #ifdef KUI
  2872.             if (evtinbuf(VCMD))
  2873.                 SetConnectMode(0,CSX_ESCAPE);
  2874. #endif /* KUI */
  2875. #endif /* COMMENT */
  2876.  
  2877.             if (tt_timelimit && (now_t - start_t >= tt_timelimit))
  2878.                 SetConnectMode(0,CSX_TIME);
  2879.  
  2880.             if (tt_idlelimit && (now_t - keypress_t >= tt_idlelimit)) {
  2881.                 switch ( tt_idleact ) {
  2882.                 case IDLE_RET:
  2883.                     SetConnectMode(0,CSX_IDLE);
  2884.                     break;
  2885.                 case IDLE_EXIT:
  2886.                     quitnow = 1;
  2887.                     hangnow = 1;
  2888.                     strcpy(termessage, "Hangup and quit.\n");
  2889.                     SetConnectMode(0,CSX_USERDISC);
  2890.                     break;
  2891.                 case IDLE_HANG:
  2892.                     hangnow = 1;
  2893.                     strcpy(termessage, "Hangup.\n");
  2894.                     SetConnectMode(0,CSX_USERDISC);
  2895.                     break;
  2896.                 }
  2897.             }
  2898.         }
  2899.     }
  2900. }
  2901.  
  2902. int
  2903. unconect1() {
  2904.     int x;
  2905.  
  2906. #ifdef CKLEARN
  2907.     if (learning && learnfp)
  2908.       fputs("\n",learnfp);
  2909. #endif /* CKLEARN */
  2910.  
  2911.     if ( ttchk() < 0 ) {
  2912. #ifdef NETDLL
  2913.         if ( network && nettype == NET_DLL && ttyfd != -1 )
  2914.             ttclos(0);
  2915. #endif /* NETDLL */
  2916.         if ( ttyfd == -1
  2917. #ifdef CK_TAPI
  2918.              || ttyfd == -2
  2919. #endif /* CK_TAPI */
  2920.              )
  2921.             /* Discard unsent keystrokes if the connection has been lost */
  2922.             while( evtinbuf(VTERM) ) {
  2923.                 con_event evt;
  2924.                 getevent( VTERM, &evt );
  2925.             }
  2926.     }
  2927.  
  2928.     if ( !quiet && !viewonly && !termessage[0] ) {
  2929.         if ( (!network 
  2930. #ifdef TN_COMPORT
  2931.           || istncomport()
  2932. #endif /* TN_COMPORT */
  2933.           ) && carrier != CAR_OFF && (ttgmdm() & BM_DCD) == 0)
  2934.             strcpy( termessage, "Carrier required but not detected.\n");
  2935.         else if ( ttyfd == -1 )
  2936.             strcpy( termessage, "Connection closed.\n");
  2937.         else if ( tt_timelimit && (now_t - start_t >= tt_timelimit) )
  2938.             strcpy( termessage, "Timeout.\n");
  2939.         else if ( tt_idlelimit && (tt_idleact >= IDLE_RET && tt_idleact <= IDLE_HANG) &&
  2940.                   (now_t - keypress_t >= tt_idlelimit) )
  2941.             strcpy( termessage, "Idle timeout.\n");
  2942.     }
  2943.  
  2944.     if (termessage[0] != '\0')
  2945.         printf(termessage);
  2946.  
  2947. #ifdef IKS_OPTION
  2948.     if ( tt_async ) {                   /* From doconect() */
  2949.         if (TELOPT_U(TELOPT_KERMIT) &&
  2950.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2951.              !tcp_incoming && !quiet && ttchk() >= 0
  2952.              ) {
  2953.             printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2954.             printf(
  2955. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2956.             printf(" SEND and GET for file transfer.\r\n");
  2957.             printf(" REMOTE commands for file management.\r\n");
  2958.             printf(" FINISH to terminate Client/Server mode.\r\n");
  2959.             printf(" BYE to terminate and close connection.\r\n");
  2960.             printf(" REMOTE HELP for additional information.\r\n\r\n");
  2961.         }
  2962.     }
  2963. #endif /* IKS_OPTION */
  2964.  
  2965.     if ( network ) {
  2966.         if ( ttyfd == -1 )
  2967.           DialerSend( OPT_KERMIT_HANGUP, 0 ) ;
  2968.     } else {
  2969.         if ( (carrier != CAR_OFF) &&    /* Carrier dropped */
  2970.             ((ttgmdm() & BM_DCD) == 0) )
  2971.           DialerSend( OPT_KERMIT_HANGUP, 0 ) ;
  2972.     }
  2973.     debug( F100,"Exiting connect mode","",0) ;
  2974.     SetThreadPrty(priority,3);
  2975.  
  2976.     viewonly = viewonly_sav;            /* Restore viewonly state */
  2977.     keylock = keylocksav ;              /* Restore keylock state */
  2978.     holdscreen = holdscreensav;         /* Restore holdscreen state */
  2979.     language = langsv;                  /* Restore language */
  2980.     concooked();                        /* Restore console to "cooked" mode */
  2981. #ifdef NT
  2982.     connoi();
  2983. #endif
  2984.  
  2985. #ifndef NT
  2986. #ifndef KUI
  2987. #ifdef OS2MOUSEX
  2988.     if ( tt_mouse ) {
  2989.         os2_mouseoff() ;
  2990.     }
  2991. #endif /* OS2MOUSE */
  2992. #endif /* KUI */
  2993. #endif /* NT */
  2994.  
  2995.     SaveTermMode(wherex[VTERM],wherey[VTERM]);
  2996.  
  2997. #ifdef PCFONTS
  2998.     if (IsOS2FullScreen())
  2999.       os2ResetFont() ;
  3000. #endif /* PCFONTS */
  3001.     return(0);
  3002. }
  3003.  
  3004. int
  3005. unconect2() {
  3006.     int x;
  3007.  
  3008.     x = cursoron[VTERM];
  3009.     cursoron[VTERM] = TRUE;             /* Needed for lgotoxy()... */
  3010.     restoreborder();                    /* Put back command-screen border */
  3011.     RestoreCmdMode();                   /* Put back command screen */
  3012.     restorecursormode();                /* Put command-screen cursor back */
  3013.     cursoron[VTERM] = x;                /* Remember this for next time... */
  3014.     vmode = VCMD ;
  3015.     VscrnIsDirty(VTERM);                /* Force TermScrnUpd() to unblock */
  3016.     debug( F111,"unconect2()","hangnow",hangnow);
  3017.     if (hangnow) {
  3018.         DialerSend( OPT_KERMIT_HANGUP, 0 ) ;
  3019. #ifndef NODIAL
  3020.         if (mdmhup() < 1)
  3021. #endif /* NODIAL */
  3022.             tthang();
  3023.     }
  3024.     debug( F111,"unconect2()","quitnow",quitnow);
  3025.     if (quitnow) {
  3026.         if (isWin95())
  3027.             sleep(1);
  3028.         doexit(GOOD_EXIT,0);
  3029.     }
  3030.  
  3031.     debug(F111,"unconect2()","tt_async",tt_async);
  3032.     if ( tt_async ) {                   /* From doconect() */
  3033.         if ( ttchk() < 0 ) {
  3034.             debug(F110,"unconect2()","ttchk() < 0",0);
  3035. #ifdef NETCONN
  3036.             debug(F111,"unconect2()","network",network);
  3037.             debug(F111,"unconect2()","tn_exit",tn_exit);
  3038.             debug(F111,"unconect2()","exitonclose",exitonclose);
  3039.             if (network && tn_exit)
  3040.                 doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  3041. #endif /* NETCONN */
  3042.             /* Exit on disconnect if the port is not open or carrier detect */
  3043.             else if (exitonclose)
  3044.                 doexit(GOOD_EXIT,xitsta);
  3045.         }
  3046.         concb((char)escape);                /* Restore console for commands */
  3047.         setint();
  3048.     }
  3049.     what = W_COMMAND;                   /* Back in command mode. */
  3050.     return(1);
  3051. }
  3052.  
  3053. int
  3054. conect(int async) {
  3055.     USHORT          len, x, y;
  3056.     int             i, c, cm;   /* c is a character, but must be signed
  3057.                                  * integer to pass thru -1, which is the
  3058.                                  * modem disconnection signal, and is
  3059.                                  * different from the character 0377 */
  3060.     char errmsg[50], *erp, ac, bc;
  3061.     extern int cmdlvl,tlevel;
  3062. #ifdef OS2MOUSE
  3063.     int button, event ;
  3064.     extern int tt_mouse ;
  3065. #endif /* OS2MOUSE */
  3066. #ifdef NT
  3067.     DWORD ExitCode ;
  3068. #endif /* NT */
  3069. #ifdef CK_TAPI
  3070.     extern int tttapi;
  3071.     extern int tapipass;
  3072. #endif /* CK_TAPI */
  3073. #ifdef IKS_OPTION
  3074.     int do_iks = 0;
  3075. #ifdef CK_AUTODL
  3076.     extern int autodl;
  3077. #endif /* CK_AUTODL */
  3078.     extern int quiet, tcp_incoming;
  3079. #endif /* IKS_OPTION */
  3080. #ifdef ANYSSH
  3081.     extern int ssh_cas;
  3082.     extern char * ssh_cmd;
  3083. #endif /* ANYSSH */
  3084.  
  3085.     viewonly_sav = viewonly;
  3086.     keylocksav = keylock ;
  3087.     holdscreensav  = holdscreen;
  3088.     now_t = time(NULL);/* Set the timers */
  3089.  
  3090.     tt_async = async;
  3091.  
  3092.     debug(F111,"conect()","tt_timelimit",tt_timelimit);
  3093.     debug(F111,"conect()","tt_idlelimit",tt_idlelimit);
  3094.     debug(F111,"conect()","start_t",start_t);
  3095.     debug(F111,"conect()","now_t",now_t);
  3096.     debug(F111,"conect()","tt_async",tt_async);
  3097.  
  3098.     /* do not reset timers if we are returning from an APC command */
  3099. #ifdef CK_APC
  3100.     if ( apcactive == APC_INACTIVE )
  3101. #endif /* CK_APC */
  3102.         idlesnd_t = keypress_t = start_t = now_t;       /* reset timers */
  3103.  
  3104.     term_io = TRUE;             /* handle I/O in the terminal emulator */
  3105. #ifdef CK_APC
  3106.     apcactive = APC_INACTIVE ;  /* reset APC flag in case we are returning */
  3107. #endif /* CK_APC */
  3108.  
  3109. #ifdef KUI
  3110. #ifndef K95G
  3111.     if ( evtinbuf(VCMD) )       /* If the user is entering commands into  */
  3112.         return(1) ;             /* the command window, return immediately */
  3113. #endif /* K95G */
  3114. #endif /* KUI */
  3115.  
  3116.     /*
  3117.      * The problem.  If there is stuff in the Local Echo Buffer
  3118.      * when the connection is dropped, the user is never able to
  3119.      * see it.  So if they try to start CONNECT mode we feed the
  3120.      * data into the emulator and then fail.
  3121.      */
  3122.     if ((ttyfd == -1
  3123. #ifdef CK_TAPI
  3124.           || (!tttapi && ttyfd == -2)
  3125. #endif /* CK_TAPI */
  3126.           ) && (ttchk() > 0)) {
  3127.         int ch;
  3128.         debug(F110,"conect()","local echo buffer copied to terminal",0);
  3129.         while ((ch = ttinc(-50))>=0) {
  3130.             scriptwrtbuf(ch);
  3131.         }
  3132.     }
  3133.     else if ( !viewonly ) {    /* View only requires no connection checks */
  3134.         if (!network) {
  3135.             if (ttyfd == -1) {
  3136.                 printf("Sorry, you must first open a device or connection.\n");
  3137.                 return (0);
  3138.             }
  3139.  
  3140.             if (speed < 0) {
  3141.                 printf("Sorry, you must set speed first.\n");
  3142.                 return (0);
  3143.             }
  3144.         }
  3145. #ifdef SSHBUILTIN
  3146.         if ( network && nettype == NET_SSH && ssh_cas && ssh_cmd && 
  3147.              !(strcmp(ssh_cmd,"kermit") && strcmp(ssh_cmd,"sftp"))) {
  3148.             printf("?SSH Subsystem active: %s\n", ssh_cmd);
  3149.             return(0);
  3150.         }
  3151. #endif /* SSHBUILTIN */
  3152.         if (tt_escape && ((escape < 0) || (escape > 0177))) {
  3153.             printf("Escape character out of range: %d\n", escape);
  3154.             return (0);
  3155.         }
  3156. #ifdef IKS_OPTION
  3157.         do_iks = (ttyfd == -1) && ((local && network && IS_TELNET())
  3158.                                     || (!local && sstelnet));
  3159. #endif /* IKS_OPTION */
  3160.  
  3161.         if (ttopen(ttname, &local, network ? -nettype : mdmtyp, 0) < 0) {
  3162.             erp = errmsg;
  3163.             sprintf(erp, "Sorry, can't open %s", ttname);
  3164.             perror(errmsg);
  3165.             return (0);
  3166.         }
  3167.  
  3168. #ifdef IKS_OPTION
  3169.         if ( do_iks ) {
  3170.             if (TELOPT_U(TELOPT_KERMIT)) {
  3171.                 /* If the remote side is in a state of IKS START-SERVER    */
  3172.                 /* we request that the state be changed.  We will detect   */
  3173.                 /* a failure to adhere to the request when we call ttinc() */
  3174.                 if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  3175.                     if (!quiet) {
  3176.                         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  3177.                         printf(
  3178.  " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  3179.                         printf(" SEND and GET for file transfer.\r\n");
  3180.                         printf(" REMOTE commands for file management.\r\n");
  3181.                         printf(" FINISH to terminate Client/Server mode.\r\n");
  3182.                         printf(" BYE to terminate and close connection.\r\n");
  3183.                         printf(" REMOTE HELP for additional information.\r\n\r\n");
  3184.                     }
  3185.                     return(0);      /* Failure */
  3186.                 }
  3187.             }
  3188.  
  3189.             /* Let our peer know our state. */
  3190. #ifdef CK_AUTODL
  3191.             if (TELOPT_ME(TELOPT_KERMIT)) {
  3192.                 if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  3193.                     tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  3194.                 } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  3195.                     tn_siks(KERMIT_STOP);
  3196.                 }
  3197.             }
  3198. #else /* CK_AUTODL */
  3199.             if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  3200.                 tn_siks(KERMIT_STOP);
  3201.             }
  3202. #endif /* CK_AUTODL */
  3203.         }
  3204. #endif /* IKS_OPTION */
  3205.  
  3206.  
  3207.         /* Condition console terminal and communication line */
  3208.         if (ttvt(speed, flow) < 0) {
  3209. #ifdef CK_TAPI
  3210.             if ( tttapi && !tapipass )
  3211.                 printf("Sorry, you must DIAL a number first.\n");
  3212.             else
  3213. #endif /* CK_TAPI */
  3214.                 printf("Sorry, Can't condition communication line\n");
  3215.             return (0);
  3216.         }
  3217.  
  3218. #ifdef CK_TAPI
  3219.         if ( tttapi && !tapipass && ttyfd == -2 ) {
  3220.             printf("?Sorry, you must DIAL a number first\n");
  3221.             return (0);
  3222.         }
  3223. #endif /* CK_TAPI */
  3224.         if (!network && carrier != CAR_OFF && (ttgmdm() & BM_DCD) == 0) {
  3225. #ifndef NOHINTS
  3226.             extern int hints;
  3227. #endif /* NOHINTS */
  3228.             printf("?Carrier required but not detected on \"%s\".\n",ttname);
  3229.  
  3230. #ifndef NOHINTS
  3231.             if (!hints)
  3232.                 return(0);
  3233.  
  3234.             printf("***********************************\n");
  3235.             printf(
  3236.            "Hint: Use the DIAL command, or else SET CARRIER-WATCH OFF.\n");
  3237.             printf(
  3238.           "If you want to make a network connection, use SET HOST or TELNET.\n"
  3239.                    );
  3240.             printf("***********************************\n\n");
  3241. #endif /* NOHINTS */
  3242.             return (0);
  3243.         }
  3244.     } /* if (!viewonly) */
  3245.  
  3246.  
  3247.     now_t = time(NULL);/* Set the timers */
  3248.     tt_async = async;
  3249.  
  3250.     debug(F111,"conect()","tt_timelimit",tt_timelimit);
  3251.     debug(F111,"conect()","tt_idlelimit",tt_idlelimit);
  3252.     debug(F111,"conect()","start_t",start_t);
  3253.     debug(F111,"conect()","now_t",now_t);
  3254.     debug(F111,"conect()","tt_async",tt_async);
  3255.  
  3256.     /* do not reset timers if we are returning from an APC command */
  3257. #ifdef CK_APC
  3258.     if ( apcactive == APC_INACTIVE )
  3259. #endif /* CK_APC */
  3260.         idlesnd_t = keypress_t = start_t = now_t;       /* reset timers */
  3261.  
  3262.     term_io = TRUE;             /* handle I/O in the terminal emulator */
  3263. #ifdef CK_APC
  3264.     apcactive = APC_INACTIVE ;  /* reset APC flag in case we are returning */
  3265. #endif /* CK_APC */
  3266.  
  3267.     /* Will Kermit exit when user escapes back? */
  3268.     esc_exit = (cflg || cnflg) && !stayflg;
  3269.     esc_msg  = esc_exit ? "Exit:" :
  3270. #ifdef COMMENT
  3271. #ifndef NOSPL
  3272.                  cmdlvl == 0
  3273. #else
  3274.                  tlevel == -1
  3275. #endif /* NOSPL */
  3276.                      ? "Prompt:" : "Command:"
  3277. #else /* COMMENT */
  3278.                          "Command:"
  3279. #endif /* COMMENT */
  3280.                          ;
  3281.  
  3282.     keymac = 0;                         /* Initialize \Kmacro flag */
  3283.     keymacx = -1;                       /* and index */
  3284.  
  3285.     outshift = 0;                       /* Initial SO shift state. */
  3286.     langsv = language;                  /* No language rules during CONNECT! */
  3287.     language = L_USASCII;
  3288.     if (debses) {                       /* Session debugging? */
  3289.         escstate = ES_NORMAL;           /* No escape-sequence processing */
  3290.         tt_wrap = TRUE;                 /* Always wrap */
  3291.     }
  3292.     pmask = (parity ? 0177 : 0377) & cmask ;
  3293.  
  3294.     /* initialize DEC Graphic Set Translation functions if necessary */
  3295.     for ( i = 0 ; i < 4 ; i++ ) {
  3296.         if ( G[i].init ) {
  3297.             if ( tcs_transp ) {
  3298.                 G[i].rtoi = NULL;
  3299.                 G[i].itol = NULL;
  3300.                 G[i].ltoi = NULL;
  3301.                 G[i].itor = NULL;
  3302.             } else {
  3303.                 G[i].rtoi = xl_u[G[i].designation];
  3304.                 G[i].itol = xl_tx[tcsl] ;
  3305.                 G[i].ltoi = xl_u[tcsl] ;
  3306.                 G[i].itor = xl_tx[G[i].designation];
  3307.             }
  3308.             G[i].init = FALSE ;
  3309.         }
  3310.     }
  3311.     os2_outesc = ES_NORMAL;                     /* Initial state of recognizer */
  3312.  
  3313. #ifdef CK_BORDER
  3314.     saveborder();                       /* Save command-screen border */
  3315. #endif /* CK_BORDER */
  3316.  
  3317.     checkscreenmode();                  /* Initialize terminal emulator */
  3318.     setcursormode();
  3319.     GetCurPos(&y, &x);                  /* Command screen cursor position */
  3320.     SaveCmdMode(x+1,y+1);               /* Remember Command screen */
  3321.     RestoreTermMode();                  /* Put up previous terminal screen */
  3322. #ifndef KUI
  3323.     scrninit();
  3324. #ifndef NT
  3325. #ifdef OS2MOUSEX
  3326.     if ( tt_mouse ) {
  3327.         os2_mouseon() ;
  3328.         }
  3329. #endif /* OS2MOUSE */
  3330. #endif /* NT */
  3331. #endif /* KUI */
  3332.  
  3333. #ifdef PCFONTS
  3334.     if (IsOS2FullScreen())
  3335.       os2SetFont() ;
  3336. #endif /* PCFONTS */
  3337.  
  3338.     /* configure cursor */
  3339.     {
  3340.         int cursor_offset = (scrollstatus[VTERM] && tt_roll[VTERM]) ?
  3341.           (vscrn[VTERM].top + vscrn[VTERM].linecount
  3342.            - vscrn[VTERM].scrolltop)%vscrn[VTERM].linecount : 0 ;
  3343.         if ( !cursorena[VTERM] ||
  3344.             vscrn[VTERM].cursor.y + cursor_offset >= VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) ) {
  3345.             cursoron[VTERM] = TRUE ;
  3346.         } else {
  3347.             cursoron[VTERM] = FALSE ;
  3348.         }
  3349.     }
  3350.  
  3351.     conraw();                           /* Put console in raw mode */
  3352.     connoi();                           /* No interrupts from console */
  3353.     ipadl25();                          /* Put up status line */
  3354.     if ( scrollstatus[VTERM] )
  3355.       scrollstatusline() ;
  3356.     waittime = tt_ctstmo * 1000L;       /* CTS timeout */
  3357.  
  3358. #ifdef CKLEARN
  3359.     if (learning) {                     /* Learned script active... */
  3360.         learnbp = 0;                    /* INPUT buffer pointer */
  3361.         learnbc = 0;                    /* INPUT buffer count */
  3362.         learnst = 0;                    /* State (0 = neutral, none) */
  3363.         learnt1 = (ULONG) time(0);
  3364.     }
  3365. #endif /* CKLEARN */
  3366.  
  3367.     /* Create a thread to read the comms line and write to the screen */
  3368.  
  3369.     SetConnectMode(1,CSX_INTERNAL);     /* So thread 2 doesn't end at once */
  3370.     what = W_CONNECT;                   /* Keep track of what we're doing */
  3371.     quitnow = 0;
  3372.     hangnow = 0;
  3373.     termessage[0] = 0;
  3374.     if ( viewonly ) {
  3375.         keylock = TRUE ;
  3376.         holdscreen = TRUE;
  3377.     }
  3378.     VscrnIsDirty(VTERM);
  3379.     VscrnIsDirty(VCMD);
  3380.  
  3381.     if ( !async )
  3382.         isconnect();
  3383.     else
  3384.         _beginthread(isconnect,
  3385. #ifdef OS2ONLY
  3386.                       0,
  3387. #endif /* OS2ONLY */
  3388.                       65536, 0);
  3389.  
  3390.     if (tt_timelimit && (now_t - start_t >= tt_timelimit))
  3391.         return(0);
  3392.     if (tt_idlelimit && (tt_idleact == IDLE_RET) &&
  3393.          (now_t - keypress_t >= tt_idlelimit))
  3394.         return(0);
  3395.     return (1);                         /* Success */
  3396. }
  3397.  
  3398. void
  3399. SmoothScroll( void ) {
  3400.     updmode = TTU_SMOOTH ;
  3401. }
  3402.  
  3403. void
  3404. JumpScroll( void ) {
  3405.     updmode = TTU_FAST ;
  3406. }
  3407.  
  3408. void
  3409. SetConnectMode( BOOL mode, int ExitCode ) {
  3410.     con_event evt;
  3411.     extern int cx_status, cmdlvl;
  3412. #ifdef DCMDBUF
  3413.     extern struct cmdptr *cmdstk;
  3414. #else
  3415.     extern struct cmdptr cmdstk[];
  3416. #endif /* DCMDBUF */
  3417. #ifdef KUI
  3418.     char buf[30];
  3419. #endif /* KUI */
  3420.  
  3421.     if (RequestConnectModeMutex( 200 ) )
  3422.         return;
  3423.     if ( ConnectMode != mode ) {
  3424.         debug(F111,"SetConnectMode change","from",ConnectMode);
  3425.         debug(F111,"SetConnectMode change","to",mode);
  3426.         ConnectMode = mode ;
  3427.         evt.type = error;
  3428.  
  3429.         switch ( mode ) {
  3430.         case VTERM:
  3431.             putevent(VTERM,evt);
  3432.             PostTerminalModeSem();
  3433.             ResetCommandModeSem();
  3434.             cx_status = CSX_INTERNAL;
  3435. #ifdef KUI
  3436.             KuiSetTerminalStatusText(STATUS_CMD_TERM, "Terminal Screen");
  3437.             KuiSetTerminalConnectButton(1);
  3438.             KuiSetTerminalStatusText(STATUS_PROTO, (char *)protoString());
  3439.             ckmakmsg(buf,30,ckitoa(vscrn[mode].cursor.x+1),", ",
  3440.                       ckitoa(vscrn[mode].cursor.y+1),NULL);
  3441.             KuiSetTerminalStatusText(STATUS_CURPOS, buf);
  3442.             ckmakmsg(buf,30,ckitoa(vscrn[mode].width)," x ",
  3443.                       ckitoa(vscrn[mode].height-(tt_status[vmode]?1:0)),NULL);
  3444.             KuiSetTerminalStatusText(STATUS_HW, buf);
  3445. #endif /* KUI */
  3446.             break;
  3447.         case VCMD:
  3448.             /* putevent(VCMD,evt); */
  3449.             unconect1();
  3450.             if ( tt_async ) {
  3451. #ifndef NOKVERBS
  3452.                 if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  3453.                     /* Set up the macro and return */
  3454.                     /* Do not clear the keymac flag */
  3455.                     dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs);
  3456.                 }
  3457. #endif /* NOKVERBS */
  3458.                 resconn();
  3459.             }
  3460.             PostCommandModeSem();
  3461.             ResetTerminalModeSem();
  3462.             unconect2();
  3463.             cx_status = ExitCode;
  3464. #ifdef KUI
  3465.             KuiSetTerminalStatusText(STATUS_CMD_TERM, "Command Screen");
  3466.             KuiSetTerminalConnectButton(0);
  3467.             KuiSetTerminalStatusText(STATUS_PROTO, (char *)protoString());
  3468.             ckmakmsg(buf,30,ckitoa(vscrn[mode].cursor.x+1),", ",
  3469.                       ckitoa(vscrn[mode].cursor.y+1),NULL);
  3470.             KuiSetTerminalStatusText(STATUS_CURPOS, buf);
  3471.             ckmakmsg(buf,30,ckitoa(vscrn[mode].width)," x ",
  3472.                       ckitoa(vscrn[mode].height-(tt_status[vmode]?1:0)),NULL);
  3473.             KuiSetTerminalStatusText(STATUS_HW, buf);
  3474. #endif /* KUI */
  3475.             break;
  3476.         default:
  3477.             if (mode)
  3478.                 unconect1();
  3479.             if ( tt_async )
  3480.                 resconn();
  3481.             ResetTerminalModeSem();
  3482.             ResetCommandModeSem();
  3483.             if ( mode )
  3484.                 unconect2();
  3485.             cx_status = ExitCode;
  3486. #ifdef KUI
  3487.             KuiSetTerminalStatusText(0, "(unknown)");
  3488. #endif /* KUI */
  3489.         }
  3490.         msleep(50);           /* Give other threads a chance to catch up */
  3491.     }
  3492.     ReleaseConnectModeMutex() ;
  3493. }
  3494.  
  3495. int
  3496. StartConnectThreads( void )
  3497. {
  3498.     int i=0;
  3499.     extern int Shutdown;
  3500.  
  3501.     Shutdown = FALSE;
  3502.     tidRdComWrtScr = (TID) ckThreadBegin( &rdcomwrtscr,
  3503.                                           THRDSTKSIZ, 0, TRUE, 0 ) ;
  3504.     if ( tidRdComWrtScr == (TID) -1 ) {
  3505.         printf("Sorry, can't create thread\n");
  3506.         SetConnectMode(0,CSX_INTERNAL) ;
  3507.         fatal("Sorry, can't create thread.");
  3508.         return(0);
  3509.     }
  3510.     i = 0 ;
  3511.     while ( !WaitAndResetRdComWrtScrThreadSem( 1000 ) ) {
  3512.         debug(F100,"Waiting for RdComWrtScrThreadSem","",0) ;
  3513.         printf("Waiting for RdComWrtScrThreadSem\n") ;
  3514.         if ( ++i > 5 ) {
  3515.             printf("Sorry, giving up ...\n");
  3516.             SetConnectMode(0,CSX_INTERNAL) ;
  3517.             return(0);
  3518.         }
  3519.     }
  3520.  
  3521.     /* Use a separate thread for Keyboard handling */
  3522.     tidConKbdHandler = (TID) ckThreadBegin( &conkbdhandler,
  3523.                                             THRDSTKSIZ, 0, TRUE, 0 ) ;
  3524.     if ( tidConKbdHandler == (TID) -1) {
  3525.         printf("Sorry, can't create thread\n");
  3526.         SetConnectMode(0,CSX_INTERNAL) ;
  3527.         fatal("Sorry, can't create thread.");
  3528.         return(0);
  3529.     }
  3530.     i = 0 ;
  3531.     while ( !WaitAndResetConKbdHandlerThreadSem( 2500 ) ) {
  3532.         debug(F100,"Waiting for ConKbdHandlerThreadSem","",0) ;
  3533.         printf("Waiting for ConKbdHandlerThreadSem\n") ;
  3534.         if ( ++i > 5 ) {
  3535.            printf("Sorry, giving up...\n");
  3536.             SetConnectMode(0,CSX_INTERNAL) ;
  3537.             return(0);
  3538.        }
  3539.     }
  3540.     return(1);
  3541. }
  3542.  
  3543. int
  3544. StopConnectThreads( int wait4ever )
  3545. {
  3546.     int i=0;
  3547. #ifdef NT
  3548.     DWORD ExitCode ;
  3549. #endif /* NT */
  3550.     extern int Shutdown;
  3551.  
  3552.     if ( !tidConKbdHandler )
  3553.         return(0);
  3554.  
  3555.     debug(F111,"StopConnectThreads","wait4ever",wait4ever);
  3556.  
  3557.     Shutdown = TRUE;
  3558.     puterror(VTERM);
  3559.  
  3560.     while ( !tt_async &&
  3561.             !WaitAndResetConKbdHandlerThreadDownSem( 1000 ) ) {
  3562.         debug(F100,"Waiting for ConKbdHandlerThreadDownSem","",0) ;
  3563. #ifdef NT
  3564.         ExitCode = STILL_ACTIVE ;
  3565.         if ( GetExitCodeThread( tidConKbdHandler, &ExitCode ) )
  3566.             if ( ExitCode != STILL_ACTIVE ) {
  3567.               debug( F111,"ConKbdHandler not active","ExitCode",ExitCode);
  3568.               break;
  3569.             }
  3570. #endif /* NT */
  3571.         if (!wait4ever && ++i > 5 ) {
  3572.             printf("ConKbdHandlerThreadThread did not die\n");
  3573.             debug(F100,"ConKbdHandlerThread did not die.","",0);
  3574.             break;
  3575.         }
  3576.     }
  3577.     debug(F100,"ConKbdHandlerThread might be dead","",0);
  3578.  
  3579.     i = 0;
  3580.     if ( !viewonly ) {
  3581.         while ( !WaitAndResetRdComWrtScrThreadDownSem( 1000 ) ) {
  3582.             debug(F100,"Waiting for RdComWrtScrThread to die","",0);
  3583. #ifdef NT
  3584.             ExitCode = STILL_ACTIVE ;
  3585.             if ( GetExitCodeThread( tidRdComWrtScr, &ExitCode ) )
  3586.               if ( ExitCode != STILL_ACTIVE ) {
  3587.                   debug( F111,"RdComWrtScrThread not active",
  3588.                         "ExitCode",ExitCode);
  3589.                   break;
  3590.               }
  3591. #endif /* NT */
  3592.                 if (!wait4ever && ++i > 5 ) {
  3593.                     printf("RdComWrtScrThread did not die\n");
  3594.                     debug(F100,"RdComWrtScrThread did not die.","",0);
  3595.                     break;
  3596.                 }
  3597.         }
  3598.         debug(F100,"RdComWrtScrThread might be dead","",0);
  3599.     }
  3600.  
  3601.     i=0;
  3602. #ifndef NT
  3603.     DosWaitThread( &tidRdComWrtScr, DCWW_WAIT );
  3604. #endif /* NT */
  3605.     debug(F100,"Connect mode threads are dead","",0) ;
  3606.     puterror(VTERM);
  3607.     return(1);
  3608. }
  3609.  
  3610. /* The routines that follow provide an interface between the command parser
  3611.  * and the actual functionality used to implement the command when it is K95
  3612.  * specific.  This way KUI can call the routines without using the command
  3613.  * parser.  
  3614.  
  3615.  * This function accepts Window Height and Width.  The Window Height includes
  3616.  * the status line if there is one.  This is important to remember for the 
  3617.  * difference between the terminal and command windows which may have different
  3618.  * values for tt_status.
  3619.  */
  3620.  
  3621. #ifdef KUI
  3622. int
  3623. kui_setheightwidth(int x, int y)
  3624. {
  3625.     tt_szchng[VTERM] = (tt_status[VTERM]?2:1);
  3626.     tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  3627.     tt_cols[VTERM] = x;
  3628.     tt_cols_usr = x;
  3629.     VscrnSetWidth( VTERM, x);
  3630.     VscrnInit( VTERM );         /* Height set here */
  3631. #ifdef TNCODE
  3632.     if (TELOPT_ME(TELOPT_NAWS))
  3633.         tn_snaws();
  3634. #endif /* TNCODE */
  3635. #ifdef RLOGCODE
  3636.     if (TELOPT_ME(TELOPT_NAWS))
  3637.         rlog_naws();
  3638. #endif /* RLOGCODE */
  3639. #ifdef SSHBUILTIN
  3640.     ssh_snaws();
  3641. #endif /* SSHBUILTIN */
  3642.  
  3643.     tt_szchng[VCMD] = (tt_status[VCMD]?2:1);
  3644.     tt_rows[VCMD] = cmd_rows = y - (tt_status[VCMD]?1:0);
  3645.     tt_cols[VCMD] = x;
  3646.     VscrnSetWidth(VCMD, x);
  3647.     cmd_cols = x;
  3648.     VscrnInit(VCMD);
  3649.     SetCols(VCMD);
  3650.  
  3651.     return(1);
  3652. }
  3653. #endif /* KUI */
  3654.  
  3655. int
  3656. os2_settermwidth(int x)
  3657. {
  3658.     if (x % 2) {
  3659.         printf("\n?The width must be an even value\n.");
  3660.         return(0);
  3661.     }
  3662.  
  3663.     if ( IsOS2FullScreen() ) {
  3664.         if ( x != 40 && x != 80 && x != 132 ) {
  3665.             printf("\n?The width must be 40, 80,");
  3666. #ifdef NT
  3667.                   printf(" or 132 under Windows 95.\n.");
  3668. #else /* NT */
  3669.                   printf(" or 132 in a Full Screen session.\n.");
  3670. #endif /* NT */
  3671.             return(0);
  3672.         }
  3673.     } else {
  3674.         if ( !IsWARPed() && x != 80 ) {
  3675.             printf("\n?OS/2 version is pre-WARP: the width must equal ");
  3676.             printf("80 in a Windowed Session\n.");
  3677.             return(0);
  3678.         }
  3679.         if (x < 20 || x > MAXTERMCOL ) {
  3680.             printf("\n?The width must be between 20 and %d\n.",MAXTERMCOL);
  3681.             return(0);
  3682.         }
  3683.     }
  3684.  
  3685. #ifdef KUI
  3686.     return(kui_setheightwidth(x,tt_rows[VTERM]+(tt_status[VTERM]?1:0)));
  3687. #else /* KUI */
  3688.     if (x > 8192/(tt_rows[VTERM]+1)) {
  3689.         printf("\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  3690.                 tt_rows[VTERM]+1,x,x*(tt_rows[VTERM]+1));
  3691.         return(0);
  3692.     }
  3693.  
  3694.     tt_cols[VTERM] = x;
  3695.     tt_cols_usr = x;
  3696.     if (SysInited) {
  3697.         VscrnSetWidth( VTERM, x);
  3698. #ifdef TNCODE
  3699.         if (TELOPT_ME(TELOPT_NAWS))
  3700.             tn_snaws();
  3701. #endif /* TNCODE */
  3702. #ifdef RLOGCODE
  3703.         if (TELOPT_ME(TELOPT_NAWS))
  3704.             rlog_naws();
  3705. #endif /* RLOGCODE */
  3706. #ifdef SSHBUILTIN
  3707.         ssh_snaws();
  3708. #endif /* SSHBUILTIN */
  3709.     }
  3710. /*
  3711.    We do not set tt_szchng here because that would result in the screen buffer
  3712.    being reallocated and the screen cleared.  But that is not necessary when
  3713.    only the screen width is being changed since the buffer allocates the full
  3714.    width
  3715. */
  3716.     return(1);
  3717. #endif /* KUI */
  3718. }
  3719.  
  3720. int
  3721. os2_settermheight(int x)
  3722. {
  3723. #ifdef KUI
  3724.     return(kui_setheightwidth(tt_cols[VTERM],x+(tt_status[VTERM]?1:0)));
  3725. #else /* KUI */
  3726.     if (x > 8192/(tt_cols[VTERM])) {
  3727.         printf("\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  3728.                 x,tt_cols[VTERM],x*(tt_cols[VTERM]));
  3729.         return(0);
  3730.     }
  3731.  
  3732.     tt_szchng[VTERM] = (tt_status[VTERM]?2:1);
  3733.     tt_rows[VTERM] = x;
  3734.     if (SysInited) {
  3735.         VscrnInit( VTERM );             /* Height set here */
  3736. #ifdef TNCODE
  3737.         if (TELOPT_ME(TELOPT_NAWS))
  3738.             tn_snaws();
  3739. #endif /* TNCODE */
  3740. #ifdef RLOGCODE
  3741.         if (TELOPT_ME(TELOPT_NAWS))
  3742.             rlog_naws();
  3743. #endif /* RLOGCODE */
  3744. #ifdef SSHBUILTIN
  3745.         ssh_snaws();
  3746. #endif /* SSHBUILTIN */
  3747.     }
  3748.     return(1);
  3749. #endif /* KUI */
  3750. }
  3751.  
  3752. int
  3753. os2_setcmdheight(int x)
  3754. {
  3755.     extern int tt_modechg;
  3756.  
  3757.     if (IsOS2FullScreen()) {
  3758.         if ( tt_status[VCMD] ) {
  3759.             if (x != 24 && x != 42 && x != 49 && x != 59) {
  3760.                 printf("\n?The height must be 24, 42, 49");
  3761. #ifdef NT
  3762.                 printf(" or 59 under Windows 95.\n.");
  3763. #else /* NT */
  3764.                 printf(" or 59 in a Full Screen session.\n.");
  3765. #endif /* NT */
  3766.                 return(0);
  3767.             }
  3768.         } else {
  3769.             if (x != 25 && x != 43 && x != 50 && x != 60) {
  3770.                 printf("\n?The height must be 25, 43, 50");
  3771. #ifdef NT
  3772.                 printf(" or 60 under Windows 95.\n.");
  3773. #else /* NT */
  3774.                 printf(" or 60 in a Full Screen session.\n.");
  3775. #endif /* NT */
  3776.                 return(0);
  3777.             }
  3778.         }
  3779.     } else if (tt_modechg == TVC_W95) {
  3780.         if (tt_status[VCMD]) {
  3781.             if (x != 24 && x != 42 && x != 59) {
  3782.                 printf("\n?The height must be 24, 42, 49");
  3783. #ifdef NT       
  3784.                 printf(" under Windows 95.\n.");
  3785. #else /* NT */  
  3786.                 printf(" in a Full Screen session.\n.");
  3787. #endif /* NT */
  3788.                 return(0);
  3789.             }
  3790.         } else {
  3791.             if (x != 25 && x != 43 && x != 50) {
  3792.                 printf("\n?The height must be 25, 43, 50");
  3793. #ifdef NT       
  3794.                 printf(" under Windows 95.\n.");
  3795. #else /* NT */  
  3796.                 printf(" in a Full Screen session.\n.");
  3797. #endif /* NT */ 
  3798.                 return(0);
  3799.             }
  3800.         }
  3801.     } else {
  3802.         if (x < 8 || x > MAXTERMROW ) {
  3803.             printf("\n?The height must be between 8 and %d\n.",
  3804.                     MAXTERMROW);
  3805.             return(0);
  3806.         }
  3807.     }
  3808. #ifdef KUI
  3809.     return(kui_setheightwidth(tt_cols[VCMD],x+(tt_status[VCMD]?1:0)));
  3810. #else /* KUI */
  3811.     if (x > 8192/tt_cols[VCMD]) {
  3812.         printf("\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  3813.                 x,tt_cols[VCMD],x*tt_cols[VCMD]);
  3814.                 return(0);
  3815.     }
  3816.  
  3817.     tt_szchng[VCMD] = (tt_status[VCMD]?2:1);
  3818.     tt_rows[VCMD] = cmd_rows = x;
  3819.     VscrnInit(VCMD);
  3820.     SetCols(VCMD);
  3821.     return(1);
  3822. #endif /* KUI */
  3823. }
  3824.  
  3825. int
  3826. os2_setcmdwidth(int x)
  3827. {
  3828.     if (IsOS2FullScreen()) {
  3829.         if (x != 40 && x != 80 && x != 132) {
  3830.             printf("\n?The width must be 40, 80,");
  3831. #ifdef NT
  3832.             printf(" or 132 under Windows 95.\n.");
  3833. #else /* NT */
  3834.             printf(" or 132 in a Full Screen session.\n.");
  3835. #endif /* NT */
  3836.             return(0);
  3837.         }
  3838.     } else {
  3839.         if (!IsWARPed() && x != 80) {
  3840.             printf("\n?OS/2 version is pre-WARP: the width must");
  3841.             printf("equal 80 in a Windowed Session\n.");
  3842.             return(0);
  3843.         }
  3844.         if (x < 20 || x > MAXTERMCOL) {
  3845.             printf("\n?The width must be between 20 and %d\n.",MAXTERMCOL);
  3846.             return(0);
  3847.         }
  3848.     }
  3849. #ifdef KUI
  3850.     return(kui_setheightwidth(x,tt_rows[VCMD]+(tt_status[VCMD]?1:0)));
  3851. #else /* KUI */
  3852.     if (x > 8192/(tt_rows[VCMD]+1)) {
  3853.         printf("\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  3854.                 tt_rows[VCMD]+1,x,x*(tt_rows[VCMD]+1));
  3855.         return(0);
  3856.     }
  3857.     tt_cols[VCMD] = x;
  3858.     VscrnSetWidth(VCMD, x);
  3859.     cmd_cols = x;
  3860.     SetCols(VCMD);
  3861.     return(1);
  3862. #endif /* KUI */
  3863. }
  3864. #endif /* NOLOCAL */
  3865.