home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / misc / 3940 < prev    next >
Encoding:
Text File  |  1992-09-13  |  57.1 KB  |  2,149 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  4. Subject:  v32i048:  ecu - ECU Asynchronous Communications v3.20, Part13/40
  5. Message-ID: <1992Sep13.153452.5353@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 61397c70bb6cc28ee0912cfb15916d90
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v32i036=ecu.141245@sparky.IMD.Sterling.COM>
  11. Date: Sun, 13 Sep 1992 15:34:52 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2134
  14.  
  15. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  16. Posting-number: Volume 32, Issue 48
  17. Archive-name: ecu/part13
  18. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  19. Supersedes: ecu: Volume 21, Issue 53-89
  20.  
  21. ---- Cut Here and feed the following to sh ----
  22. #!/bin/sh
  23. # this is ecu320.13 (part 13 of ecu320)
  24. # do not concatenate these parts, unpack them in order with /bin/sh
  25. # file ecutcap.c continued
  26. #
  27. if test ! -r _shar_seq_.tmp; then
  28.     echo 'Please unpack part 1 first!'
  29.     exit 1
  30. fi
  31. (read Scheck
  32.  if test "$Scheck" != 13; then
  33.     echo Please unpack part "$Scheck" next!
  34.     exit 1
  35.  else
  36.     exit 0
  37.  fi
  38. ) < _shar_seq_.tmp || exit 1
  39. if test ! -f _shar_wnt_.tmp; then
  40.     echo 'x - still skipping ecutcap.c'
  41. else
  42. echo 'x - continuing file ecutcap.c'
  43. sed 's/^X//' << 'SHAR_EOF' >> 'ecutcap.c' &&
  44. Xvoid
  45. Xtcap_bold_off()
  46. X{
  47. X    if(*tc_bold_off)
  48. X        tputs(tc_bold_off,1,tcap_putc);
  49. X    else if(*tc_standend) /* && (tc_standout_width == 0)) */
  50. X        tputs(tc_standend,1,tcap_putc);
  51. X    rcvrdisp_actual2();
  52. X}    /* end of tcap_bold_off */
  53. X
  54. X/*+-------------------------------------------------------------------------
  55. X    tcap_underscore_on()
  56. X--------------------------------------------------------------------------*/
  57. Xvoid
  58. Xtcap_underscore_on()
  59. X{
  60. X    if(*tc_underscore_on)
  61. X        tputs(tc_underscore_on,1,tcap_putc);
  62. X    else if(*tc_standout) /*  && (tc_standout_width == 0)) */
  63. X        tputs(tc_standout,1,tcap_putc);
  64. X    rcvrdisp_actual2();
  65. X}    /* end of tcap_underscore_on */
  66. X
  67. X/*+-------------------------------------------------------------------------
  68. X    tcap_underscore_off()
  69. X--------------------------------------------------------------------------*/
  70. Xvoid
  71. Xtcap_underscore_off()
  72. X{
  73. X    if(*tc_underscore_off)
  74. X        tputs(tc_underscore_off,1,tcap_putc);
  75. X    else if(*tc_standend) /* && (tc_standout_width == 0)) */
  76. X        tputs(tc_standend,1,tcap_putc);
  77. X    rcvrdisp_actual2();
  78. X}    /* end of tcap_underscore_off */
  79. X
  80. X/*+-------------------------------------------------------------------------
  81. X    tcap_blink_on()
  82. X--------------------------------------------------------------------------*/
  83. Xvoid
  84. Xtcap_blink_on()
  85. X{
  86. X    if(*tc_blink_on)
  87. X        tputs(tc_blink_on,1,tcap_putc);
  88. X    else if(*tc_standout) /*  && (tc_standout_width == 0)) */
  89. X        tputs(tc_standout,1,tcap_putc);
  90. X    rcvrdisp_actual2();
  91. X}    /* end of tcap_blink_on */
  92. X
  93. X/*+-------------------------------------------------------------------------
  94. X    tcap_blink_off()
  95. X--------------------------------------------------------------------------*/
  96. Xvoid
  97. Xtcap_blink_off()
  98. X{
  99. X    if(*tc_blink_off)
  100. X        tputs(tc_blink_off,1,tcap_putc);
  101. X    else if(*tc_standend) /* && (tc_standout_width == 0)) */
  102. X        tputs(tc_standend,1,tcap_putc);
  103. X    rcvrdisp_actual2();
  104. X}    /* end of tcap_blink_off */
  105. X
  106. X/*+-------------------------------------------------------------------------
  107. X    tcap_clear_area_char(count,clrch)
  108. X--------------------------------------------------------------------------*/
  109. Xvoid
  110. Xtcap_clear_area_char(count,clrch)
  111. Xregister count;
  112. Xregister clrch;
  113. X{
  114. X    register itmp = count;
  115. X
  116. X    while(itmp--)
  117. X        tcap_putc(clrch);
  118. X    itmp = count;
  119. X    while(itmp--)
  120. X        tputs(tc_curleft);
  121. X    rcvrdisp_actual2();
  122. X
  123. X}    /* end of tcap_clear_area_char */
  124. X
  125. X/* end of ecutcap.c */
  126. X/* vi: set tabstop=4 shiftwidth=4: */
  127. SHAR_EOF
  128. echo 'File ecutcap.c is complete' &&
  129. chmod 0644 ecutcap.c ||
  130. echo 'restore of ecutcap.c failed'
  131. Wc_c="`wc -c < 'ecutcap.c'`"
  132. test 14572 -eq "$Wc_c" ||
  133.     echo 'ecutcap.c: original size 14572, current size' "$Wc_c"
  134. rm -f _shar_wnt_.tmp
  135. fi
  136. # ============= ecutime.c ==============
  137. if test -f 'ecutime.c' -a X"$1" != X"-c"; then
  138.     echo 'x - skipping ecutime.c (File already exists)'
  139.     rm -f _shar_wnt_.tmp
  140. else
  141. > _shar_wnt_.tmp
  142. echo 'x - extracting ecutime.c (Text)'
  143. sed 's/^X//' << 'SHAR_EOF' > 'ecutime.c' &&
  144. X/*+-------------------------------------------------------------------------
  145. X    ecutime.c -- ecu time-related functions
  146. X    wht@n4hgf.Mt-Park.GA.US
  147. X
  148. X  Defined functions:
  149. X    epoch_secs_to_str(epoch_secs,type,buf)
  150. X    get_day(zflag)
  151. X    get_elapsed_time(elapsed_seconds)
  152. X    get_month(zflag)
  153. X    get_tod(type,buf)
  154. X
  155. X--------------------------------------------------------------------------*/
  156. X/*+:EDITS:*/
  157. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  158. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  159. X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
  160. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  161. X
  162. X#include "ecu_types.h"
  163. X#include <time.h>
  164. X#include <sys/timeb.h>
  165. X
  166. Xstruct tm *gmtime();
  167. Xstruct tm *localtime();
  168. X
  169. X/*+-------------------------------------------------------------------------
  170. X    get_month(zflag) - month 1-12 - zflag true for UTC (Z)), else local time
  171. X--------------------------------------------------------------------------*/
  172. Xint
  173. Xget_month(zflag)
  174. Xint zflag;
  175. X{
  176. X    long epoch_secs = time((long *)0);
  177. X    struct tm *tod = (zflag) ? gmtime(&epoch_secs) : localtime(&epoch_secs);
  178. X    return(tod->tm_mon + 1);
  179. X
  180. X}    /* end of get_month */
  181. X
  182. X/*+-------------------------------------------------------------------------
  183. X    get_day(zflag) - day 0-6 - zflag true for UTC (Z)), else local time
  184. X--------------------------------------------------------------------------*/
  185. Xint
  186. Xget_day(zflag)
  187. Xint zflag;
  188. X{
  189. X    long epoch_secs = time((long *)0);
  190. X    struct tm *tod = (zflag) ? gmtime(&epoch_secs) : localtime(&epoch_secs);
  191. X    return(tod->tm_wday);
  192. X
  193. X}    /* end of get_day */
  194. X
  195. X/*+-----------------------------------------------------------------------
  196. X    char *epoch_secs_to_str(epoch_secs,type,buf)
  197. X
  198. X  time of day types:
  199. X    0        hh:mm
  200. X    1        hh:mm:ss
  201. X    2        mm-dd-yyyy hh:mm
  202. X    3        mm-dd-yyyy hh:mm:ss
  203. X    4        mm-dd-yyyy hh:mm:ss (UTC hh:mm)
  204. X    5        mm-dd-yyyy
  205. X    6        hh:mmZ
  206. X    7        hh:mm:ssZ
  207. X    8        mm-dd-yyyy (UTC date)
  208. X
  209. X    returns 'buf' address
  210. X
  211. X------------------------------------------------------------------------*/
  212. Xchar *
  213. Xepoch_secs_to_str(epoch_secs,type,buf)
  214. Xlong epoch_secs;
  215. Xint type;
  216. Xchar *buf;
  217. X{
  218. X    struct tm *tod;
  219. X
  220. X    if(type < 6)
  221. X        tod = localtime(&epoch_secs);
  222. X    else
  223. X        tod = gmtime(&epoch_secs);
  224. X
  225. X    switch(type)
  226. X    {
  227. X        default:
  228. X        case 6:
  229. X        case 0:
  230. X            sprintf(buf,"%02d:%02d",tod->tm_hour,tod->tm_min);
  231. X            if(type == 6)
  232. X                strcat(buf,"Z");
  233. X            break;
  234. X
  235. X        case 7:
  236. X        case 1:
  237. X            sprintf(buf,"%02d:%02d:%02d",tod->tm_hour,tod->tm_min,tod->tm_sec);
  238. X            if(type == 7)
  239. X                strcat(buf,"Z");
  240. X            break;
  241. X
  242. X        case 2:
  243. X            sprintf(buf,"%02d-%02d-%04d %02d:%02d",
  244. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
  245. X                tod->tm_hour,tod->tm_min);
  246. X            break;
  247. X
  248. X        case 3:
  249. X            sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
  250. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
  251. X                tod->tm_hour,tod->tm_min,tod->tm_sec);
  252. X            break;
  253. X
  254. X        case 4:
  255. X            sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
  256. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
  257. X                tod->tm_hour,tod->tm_min,tod->tm_sec);
  258. X            tod = gmtime(&epoch_secs);
  259. X            sprintf(&buf[strlen(buf) ]," (UTC %02d:%02d)",
  260. X                tod->tm_hour,tod->tm_min);
  261. X            break;
  262. X
  263. X        case 8:
  264. X        case 5:
  265. X            sprintf(buf,"%02d-%02d-%04d",
  266. X                tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900);
  267. X            break;
  268. X
  269. X    }
  270. X
  271. X    return(buf);
  272. X}    /* end of epoch_secs_to_str */
  273. X
  274. X/*+-----------------------------------------------------------------------
  275. X    char *get_tod(type,buf)
  276. X
  277. X  time of day types:
  278. X    0        hh:mm
  279. X    1        hh:mm:ss
  280. X    2        mm-dd-yyyy hh:mm
  281. X    3        mm-dd-yyyy hh:mm:ss
  282. X    4        mm-dd-yyyy hh:mm:ss (UTC hh:mm)
  283. X    5        mm-dd-yyyy
  284. X    6        hh:mmZ
  285. X    7        hh:mm:ssZ
  286. X    8        mm-dd-yyyy (UTC date)
  287. X
  288. X    returns 'buf' address
  289. X
  290. X------------------------------------------------------------------------*/
  291. Xchar *
  292. Xget_tod(type,buf)
  293. Xint type;
  294. Xchar *buf;
  295. X{
  296. X    return(epoch_secs_to_str(time((long *)0),type,buf));
  297. X}    /* end of get_tod */
  298. X
  299. X/*+-----------------------------------------------------------------------
  300. X    char *get_elapsed_time(elapsed_seconds)
  301. X    "hh:mm:ss" returned
  302. X  static string address is returned
  303. X------------------------------------------------------------------------*/
  304. Xchar *
  305. Xget_elapsed_time(elapsed_seconds)
  306. Xlong elapsed_seconds;
  307. X{
  308. X    static char elapsed_time_str[40];
  309. X    long hh,mm,ss;
  310. X
  311. X    hh = elapsed_seconds / 3600;
  312. X    elapsed_seconds -= hh * 3600;
  313. X    mm = elapsed_seconds / 60L;
  314. X    elapsed_seconds -= mm * 60L;
  315. X    ss = elapsed_seconds;
  316. X
  317. X    sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  318. X    return(elapsed_time_str);
  319. X}    /* end of get_elapsed_time */
  320. X
  321. X/* end of ecutime.c */
  322. X/* vi: set tabstop=4 shiftwidth=4: */
  323. SHAR_EOF
  324. chmod 0644 ecutime.c ||
  325. echo 'restore of ecutime.c failed'
  326. Wc_c="`wc -c < 'ecutime.c'`"
  327. test 4411 -eq "$Wc_c" ||
  328.     echo 'ecutime.c: original size 4411, current size' "$Wc_c"
  329. rm -f _shar_wnt_.tmp
  330. fi
  331. # ============= ecutty.c ==============
  332. if test -f 'ecutty.c' -a X"$1" != X"-c"; then
  333.     echo 'x - skipping ecutty.c (File already exists)'
  334.     rm -f _shar_wnt_.tmp
  335. else
  336. > _shar_wnt_.tmp
  337. echo 'x - extracting ecutty.c (Text)'
  338. sed 's/^X//' << 'SHAR_EOF' > 'ecutty.c' &&
  339. X#ifndef USE_COLOR
  340. X#   ifdef M_SYSV            /* SCO family */
  341. X#       define USE_COLOR
  342. X#   endif
  343. X#   ifdef ISC                /* not yet */
  344. X#   endif
  345. X#   ifdef sun                /* not yet */
  346. X#   endif
  347. X#   ifdef ISCSVR4            /* last I heard from lothar, this worked */
  348. X#       define USE_COLOR
  349. X#   endif
  350. X#   ifdef ESIXSVR4            /* I heard this does not work */
  351. X#   endif
  352. X#endif /* USE_COLOR */
  353. X
  354. X/*+-------------------------------------------------------------------------
  355. X    ecutty.c - local tty (console) functions
  356. X    wht@n4hgf.Mt-Park.GA.US
  357. X
  358. X  Defined functions:
  359. X    B_to_timeout_msec(c_cflag,st_rdev)
  360. X    _setcolor(clrs)
  361. X    color_name_to_num(cname)
  362. X    get_initial_colors()
  363. X    get_ttymode()
  364. X    get_ttyname()
  365. X    kbd_test()
  366. X    read_colors_file()
  367. X    restore_initial_colors()
  368. X    ring_bell()
  369. X    setcolor(new_colors)
  370. X    setcolor_internal(ntokens,tokens)
  371. X    termio_to_kbd_chars()
  372. X    ttyflush(flush_type)
  373. X    ttygetc(xkey_ok)
  374. X    ttygets(str,maxsize,flags,delim,pstrpos)
  375. X    ttygets(str,maxsize,flags,delim,pstrpos)
  376. X    ttygets_esd(tesd,flags,append_flag)
  377. X    ttyinit(param)
  378. X    ttymode(arg)
  379. X    ttyrdchk()
  380. X
  381. X    In SCO versions, ECU keeps the the state of the normal and
  382. X    reverse video foreground and background colors in a 32-bit value:
  383. X
  384. X     00000000001111111111222222222233
  385. X     01234567890123456789012345678901
  386. X     0000|--|0000|--|0000|--|0000|--|
  387. X          fg      bk      fg      bk
  388. X           reverse      normal
  389. X
  390. X    The color values are per the SCO extended color definitons:
  391. X
  392. X    black    0     gray         8
  393. X    blue     1     lt_blue      9
  394. X    green    2     lt_green    10
  395. X    cyan     3     lt_cyan     11
  396. X    red      4     lt_red      12
  397. X    magenta  5     lt_magenta  13
  398. X    brown    6     yellow      14
  399. X    white    7     hi_white    15
  400. X
  401. X    With Lothar's ISC SVR4, the format is
  402. X
  403. X     00000000001111111111222222222233
  404. X     01234567890123456789012345678901
  405. X     00000000000000000011????0100????
  406. X       0   0   0   0   3   f   4  o b
  407. X    where f is the foreground color
  408. X    and   b is the background color
  409. X
  410. X    (I dont have one, so I'm guessing these colors are chosen from
  411. X    the ISO colors):
  412. X
  413. X     BLACK       0
  414. X     RED         1
  415. X     GREEN       2
  416. X     YELLOW      3
  417. X     BLUE        4
  418. X     MAGENTA     5
  419. X     CYAN        6
  420. X     WHITE       7
  421. X
  422. X--------------------------------------------------------------------------*/
  423. X/*+:EDITS:*/
  424. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  425. X/*:08-30-1992-07:42-wht@n4hgf-implement USE_COLOR+turn off ESIX color for now */
  426. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  427. X/*:08-16-1992-03:43-wht@n4hgf-add -F funckeytype */
  428. X/*:06-20-1992-21:13-wht@n4hgf-eculibdir was overwritten if no home dir colors */
  429. X/*:06-16-1992-11:20-wht@n4hgf-ECUFUNCKEY */
  430. X/*:05-05-1992-17:42-wht@n4hgf-repair underscore always on on sun */
  431. X/*:04-24-1992-16:55-wht@n4hgf-dont flunk on >43 lines but use only 43 */
  432. X/*:04-20-1992-20:31-wht@n4hgf-ttymode now no-op until ttyinit called */
  433. X/*:04-20-1992-19:42-wht@n4hgf-kbdtest code in ttygetc messed up-str too short */
  434. X/*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 */
  435. X/*:04-19-1992-02:00-wht@n4hgf-if TERM=ansi with WINDOWID, assume scoterm */
  436. X/*:08-31-1991-13:29-wht@n4hgf2-look for colors in ECULIBDIR too */
  437. X/*:08-30-1991-04:12-wht@n4hgf2-restore colors wrong to do now if not SCO */
  438. X/*:08-30-1991-02:49-aega84!lh-use at_ansi.h/kd.h/CONS_GET under ISC SVR4 */
  439. X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  440. X/*:08-17-1991-18:29-wht@n4hgf-add kbdtest command */
  441. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  442. X/*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
  443. X/*:07-10-1991-16:19-wht@n4hgf-improve multi-char func key read timeout */
  444. X/*:03-20-1991-03:07-root@n4hgf-pts driver returns -1 on rdchk success! */
  445. X/*:03-19-1991-21:24-root@n4hgf-METROLINK_X11R4_PTS mods */
  446. X/*:01-29-1991-14:03-wht@n4hgf-more time for ESC vs fkey discrimination */
  447. X/*:01-29-1991-13:44-wht@n4hgf-load colors_normal w/ioctl GIO_ATTR if M_UNIX */
  448. X/*:12-01-1990-14:33-wht@n4hgf-more non-ansi - fkey mapping with nonansi.c */
  449. X/*:11-28-1990-15:56-wht@n4hgf-add non-ansi terminal support */
  450. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  451. X
  452. X#include "ecu.h"
  453. X#include "esd.h"
  454. X#include "ecufkey.h"
  455. X#include "ecukey.h"
  456. X#include "ecuxkey.h"
  457. X#include "ecuerror.h"
  458. X#include "termecu.h"
  459. X
  460. X/*
  461. X * This is how we determine whether we are on a color terminal or not.
  462. X * We handle SCO XENIX, SCO UNIX, ISC 2.2 and ISC SVR4.
  463. X * If you have trouble with this add some kind of thing instead of MYSYS
  464. X * and mail me the full details.  Search for MYSYS throughout here.
  465. X */
  466. X#if defined(M_SYSV)
  467. X#   include <sys/machdep.h>
  468. X/*
  469. X * Thanks for the G2, er GIO_ATTR, to staceyc@sco.COM (Stacey Campbell)
  470. X * GIO_ATTR was not defined in header files as of this writing
  471. X */
  472. X#if !defined(GIO_ATTR)
  473. X#define GIO_ATTR  ('a' << 8) | 0    /* Ioctl call for current attribute */
  474. X#endif
  475. X#else
  476. X#if defined(ISC) || defined(ISCSVR4) || defined(ESIXSVR4) /*&&!defined(MYSYS)*/
  477. X#  include <sys/at_ansi.h>
  478. X#  include <sys/kd.h>
  479. X#endif /* ISC || ISCSVR4 || ESIXSVR4 */
  480. X#endif /* M_SYSV */
  481. X
  482. X#define DEFINE_TTY_DATA
  483. X#include "ecutty.h"
  484. X
  485. Xextern uint tcap_LINES;
  486. Xextern uint tcap_COLS;
  487. Xextern int LINES;
  488. Xextern int COLS;
  489. Xextern char screen_dump_file_name[];
  490. Xextern char *dash_f_funckeytype;
  491. X
  492. Xchar *kde_text();
  493. X
  494. Xuint LINESxCOLS;
  495. Xint current_ttymode = 0;
  496. Xint ttymode_termecu_on_sigint = 0;
  497. X#if defined(METROLINK_X11R4_PTS)
  498. Xint tty_is_pts;
  499. X#endif
  500. Xint tty_is_pty;
  501. Xint tty_is_multiscreen;
  502. Xint tty_not_char_special;
  503. Xint use_colors = 0;        /* set by ttyinit, but default no */
  504. Xchar *ttype;            /* getenv("TERM") */
  505. X
  506. Xstatic int kbd_test_active = 0;
  507. Xstatic int ttyinit_has_been_called = 0;
  508. Xstatic int got_original_colors = 0;
  509. X
  510. Xstruct termio tty_termio_at_entry;
  511. Xstruct termio tty_termio_current;
  512. Xstruct stat tty_stat;
  513. Xstruct stat dn;
  514. Xstruct stat tty01;
  515. Xstruct stat ttyp0;
  516. X#if defined(METROLINK_X11R4_PTS)
  517. Xstruct stat pts000;
  518. X#endif /* METROLINK_X11R4_PTS */
  519. Xstruct stat console;
  520. X
  521. Xuchar kbdeof;            /* current input EOF */
  522. Xuchar kbdeol2;            /* current secondary input EOL */
  523. Xuchar kbdeol;            /* current input EOL */
  524. Xuchar kbderase;            /* current input ERASE */
  525. Xuchar kbdintr;            /* current input INTR */
  526. Xuchar kbdkill;            /* current input KILL */
  527. Xuchar kbdquit;            /* current input QUIT */
  528. Xint echo_erase_char;    /* save users ECHOE bit */
  529. Xint echo_kill_char;        /* save users ECHOK bit */
  530. Xchar kbd_is_7bit;        /* keyboard has parity */
  531. Xlong tty_escape_timeout = 40L;        /* timeout on waiting for char after ESC */
  532. X
  533. Xuchar *dole_out_tgc_accum = (uchar *)0;
  534. Xint dole_out_tgc_accum_count = 0;
  535. X
  536. X/*
  537. X * color definitions per format described at top of source
  538. X * we handle SCO XENIX and UNIX and ISC SVR4 but not "MYSYS"
  539. X * (search for MYSYS near top of source for clue what MYSYS means)
  540. X *
  541. X * As of this writing, I don't know about colors on ISC 2.2.
  542. X * but they might be the same as for SVR4.
  543. X *
  544. X */
  545. X#ifdef M_SYSV /* SCO */
  546. Xulong colors_current = 0x04070A00L;
  547. Xulong colors_normal = 0x04070A00L;    /* default lt_green/black red/white */
  548. Xulong colors_initial = 0x04070A00L;    /* default initial colors */
  549. Xulong colors_success = 0x07000A00L;    /* lt_green/black red/white */
  550. Xulong colors_alert = 0x0E000E00L;    /* yellow */
  551. Xulong colors_error = 0x04000400L;    /* red */
  552. Xulong colors_notify = 0x08000800L;    /* gray */
  553. X#define COLORS_DEFINED
  554. X#endif /* M_SYSV */
  555. X
  556. X#if defined(ISCSVR4)
  557. Xulong colors_current = 0x00003740L;
  558. Xulong colors_normal = 0x00003740L;    /* */
  559. Xulong colors_initial = 0x00003740L;    /* */
  560. Xulong colors_success = 0x00003740L;    /* */
  561. Xulong colors_alert = 0x00003740L;    /* */
  562. Xulong colors_error = 0x00003140L;    /* */
  563. Xulong colors_notify = 0x00003340L;    /* */
  564. X#define COLORS_DEFINED
  565. X#endif /* ISCSVR4 */
  566. X
  567. X#if defined(ESIXSVR4)
  568. Xulong colors_current = 0x00003740L;
  569. Xulong colors_normal = 0x00003740L;    /* not correct - THESE NEED FIXING */
  570. Xulong colors_initial = 0x00003740L;    /* not correct - THESE NEED FIXING */
  571. Xulong colors_success = 0x00003740L;    /* not correct - THESE NEED FIXING */
  572. Xulong colors_alert = 0x00003740LL;    /* not correct - THESE NEED FIXING */
  573. Xulong colors_error = 0x00003140L;    /* not correct - THESE NEED FIXING */
  574. Xulong colors_notify = 0x00003340L;    /* not correct - THESE NEED FIXING */
  575. X#define COLORS_DEFINED
  576. X
  577. Xstatic struct color_remapping {
  578. X  char *name;
  579. X  char ecu_val;
  580. X  char svr4_val;
  581. X} color_remapping[] =  {
  582. X    { "black",        0,        0x00 },
  583. X    { "blue",        1,        0x04 },
  584. X    { "brown",        6,        0x03 },
  585. X    { "cyan",        3,        0x06 },
  586. X    { "gray",        8,        0x10 },
  587. X    { "green",        2,        0x02 },
  588. X    { "hi_white",    15,        0x17 },
  589. X    { "lt_blue",    9,        0x14 },
  590. X    { "lt_cyan",    11,        0x16 },
  591. X    { "lt_green",    10,        0x12 },
  592. X    { "lt_magenta",    13,        0x15 },
  593. X    { "lt_red",        12,        0x11 },
  594. X    { "magenta",    5,        0x05 },
  595. X    { "red",        4,        0x01 },
  596. X    { "white",        7,        0x07 },
  597. X    { "yellow",        14,        0x13 },
  598. X    0, 0, 0,
  599. X};
  600. X#endif /* ESIXSVR4 */
  601. X
  602. X#if !defined(COLORS_DEFINED)
  603. Xulong colors_current = 1; /* dummy */
  604. Xulong colors_normal = 2; /* dummy */
  605. Xulong colors_initial = 3; /* dummy */
  606. Xulong colors_success = 4; /* dummy */
  607. Xulong colors_alert = 5; /* dummy */
  608. Xulong colors_error = 6; /* dummy */
  609. Xulong colors_notify = 7; /* dummy */
  610. X#define COLORS_DEFINED
  611. X#endif /* !COLORS_DEFINED */
  612. X
  613. X
  614. X/*+-------------------------------------------------------------------------
  615. X    B_to_timeout_msec(c_cflag,st_rdev) - CBAUD code to ESC timeout msec
  616. X--------------------------------------------------------------------------*/
  617. X/*ARGSUSED*/
  618. Xulong
  619. XB_to_timeout_msec(c_cflag,st_rdev)
  620. Xushort c_cflag;
  621. Xushort st_rdev;
  622. X{
  623. X    long ms = 300L;
  624. X
  625. X    /* make pts sweat, but don't make as many mistakes */
  626. X#if defined(METROLINK_X11R4_PTS)
  627. X    if(tty_is_pts)
  628. X        return(ms);
  629. X#endif /* METROLINK_X11R4_PTS */
  630. X
  631. X    /* make network/xterm/pty sweat, but don't make as many mistakes */
  632. X    if(tty_is_pty)
  633. X        return(ms);
  634. X
  635. X    /* if multiscreen, 3 ticks is pu-lenty */
  636. X    if(tty_is_multiscreen)
  637. X        return((long)(1000/hz * 3));
  638. X
  639. X    /* baud rate fiddling */
  640. X    switch(c_cflag & CBAUD)
  641. X    {
  642. X        /*       char times * time/char */
  643. X        case B110:    ms = 10 * 100;
  644. X        case B300:    ms = 10 * 33;
  645. X        case B600:    ms = 10 * 16;
  646. X        case B1200:    ms = 10 * 8;
  647. X        case B2400:    ms = 10 * 4;
  648. X        default:        /* many character times for packetized ... */
  649. X            ms = 400L;    /* ... modems used for console */
  650. X    }
  651. X    return(ms);
  652. X
  653. X}    /* end of B_to_timeout_msec */
  654. X
  655. X/*+-------------------------------------------------------------------------
  656. X    color_name_to_num(cname)
  657. X--------------------------------------------------------------------------*/
  658. Xint
  659. Xcolor_name_to_num(cname)
  660. Xchar *cname;
  661. X{
  662. X    register COLOR *color = colors;
  663. X    register itmp;
  664. X
  665. X    while(color->name)
  666. X    {
  667. X        if((itmp = strcmp(color->name,cname)) > 0)
  668. X            return(-1);
  669. X        if(!itmp)
  670. X            return(color->num);
  671. X        color++;
  672. X    }
  673. X    return(-1);
  674. X
  675. X}    /* end of color_name_to_num */
  676. X
  677. X/*+-------------------------------------------------------------------------
  678. X    _setcolor(clrs)
  679. X--------------------------------------------------------------------------*/
  680. Xvoid
  681. X_setcolor(clrs)
  682. Xulong clrs;
  683. X{
  684. X#if defined(SVR4)
  685. X#if defined(ESIXSVR4)
  686. X    struct color_remapping *cr;
  687. X    char fgcolor;
  688. X    char bgcolor;
  689. X#else
  690. X    char fg[4], bg[4];
  691. X#endif
  692. X#endif
  693. X
  694. X    if(!use_colors || tty_not_char_special)
  695. X        return;
  696. X
  697. X#if defined(SVR4)
  698. X#if defined(ESIXSVR4)
  699. X    /* set foreground color */
  700. X    fgcolor = (clrs >> 8) & 0xff;
  701. X    for (cr=color_remapping; cr->name; ++cr) {
  702. X      if (fgcolor == cr->ecu_val) {
  703. X        fgcolor = cr->svr4_val;
  704. X        break;
  705. X      }
  706. X    }
  707. X    if (!cr->name) {
  708. X      fgcolor = 0x07; /* white */
  709. X    }
  710. X    if (fgcolor & 0x10) {
  711. X      fgcolor &= ~0x10;
  712. X      ff(se, "\033[1;3%d;m", fgcolor);
  713. X    } else {
  714. X      ff(se, "\033[0;3%d;m", fgcolor);
  715. X    }
  716. X
  717. X    /* set background color */
  718. X    bgcolor = clrs & 0xff;
  719. X    for (cr=color_remapping; cr->name; ++cr) {
  720. X      if (bgcolor == cr->ecu_val) {
  721. X        bgcolor = cr->svr4_val;
  722. X        break;
  723. X      }
  724. X    }
  725. X    if (!cr->name) {
  726. X      bgcolor = 0x00; /* black */
  727. X    }
  728. X    if (bgcolor & 0x10) {
  729. X      bgcolor &= ~0x10;
  730. X      ff(se, "\033[5;3%d;m", bgcolor);
  731. X    } else {
  732. X      ff(se, "\033[0;3%d;m", bgcolor);
  733. X    }
  734. X#else    /* ISC SVR4 */
  735. X    /* normal */
  736. X    sprintf(fg,"%d", (clrs >> 8) & 0xFF);
  737. X    sprintf(bg,"%d", clrs & 0xFF);
  738. X    ff(se,"\033[%sm", fg);
  739. X    ff(se,"\033[%sm", bg);
  740. X#endif    /* ESIXSVR4 */
  741. X#else    /* not any SVR4 */
  742. X#ifdef M_SYSV /* SCO */
  743. X    /* normal */
  744. X    ff(se,"\033[=%ldF\033[=%ldG",(clrs >> 8) & 0xFF,clrs & 0xFF);
  745. X
  746. X    /* reverse */
  747. X    ff(se,"\033[=%ldH\033[=%ldI",(clrs >> 24) & 0xFF,(clrs >> 16) & 0xFF);
  748. X#endif /* M_SYSV */
  749. X#endif /* SVR4 */
  750. X    colors_current = clrs;
  751. X}    /* end of _setcolor */
  752. X
  753. X/*+-------------------------------------------------------------------------
  754. X    setcolor(new_colors)
  755. X
  756. Xrequires termcap init to have been done
  757. X--------------------------------------------------------------------------*/
  758. Xvoid
  759. Xsetcolor(new_colors)
  760. Xulong new_colors;
  761. X{
  762. X    if(tty_not_char_special)
  763. X        return;
  764. X
  765. X    if(!use_colors)
  766. X    {
  767. X        if(new_colors == colors_notify)
  768. X            tcap_underscore_on();
  769. X        else if(new_colors == colors_alert)
  770. X            tcap_bold_on();
  771. X        else if(new_colors == colors_error)
  772. X            tcap_stand_out();
  773. X        else
  774. X        {
  775. X            tcap_underscore_on();
  776. X            tcap_bold_on();
  777. X            tcap_stand_end();
  778. X        }
  779. X        return;
  780. X    }
  781. X    _setcolor(new_colors);
  782. X    tcap_stand_end();
  783. X}    /* end of setcolor */
  784. X
  785. X/*+-------------------------------------------------------------------------
  786. X    setcolor_internal(ntokens,tokens)
  787. X
  788. Xreturns 0 on success, else token number in error + 1
  789. X--------------------------------------------------------------------------*/
  790. Xint
  791. Xsetcolor_internal(ntokens,tokens)
  792. Xint ntokens;
  793. Xchar **tokens;
  794. X{
  795. X    ulong fgnd;
  796. X    ulong bgnd;
  797. X
  798. X    if(tty_not_char_special || !use_colors)
  799. X        return(0);
  800. X
  801. X    if(ntokens == 2)
  802. X        tokens[2] = "black";
  803. X
  804. X    if((fgnd = (ulong)color_name_to_num(tokens[1])) > 15)
  805. X        return(2);
  806. X    if((bgnd = (ulong)color_name_to_num(tokens[2])) > 15) 
  807. X        return(3);
  808. X
  809. X    if(!strcmp(tokens[0],"normal"))
  810. X    {
  811. X        colors_normal &= 0xFFFF0000L;
  812. X        colors_normal |= (fgnd << 8) | bgnd;
  813. X        setcolor(colors_normal);
  814. X    }
  815. X    else if(!strcmp(tokens[0],"reverse"))
  816. X    {
  817. X        colors_normal &= 0x0000FFFFL;
  818. X        colors_normal |= (fgnd << 24) | (bgnd << 16);
  819. X        setcolor(colors_normal);
  820. X    }
  821. X    else if(!strcmp(tokens[0],"notify"))
  822. X        colors_notify = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  823. X    else if(!strcmp(tokens[0],"success"))
  824. X        colors_success = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  825. X    else if(!strcmp(tokens[0],"alert"))
  826. X        colors_alert = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  827. X    else if(!strcmp(tokens[0],"error"))
  828. X        colors_error = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  829. X    else
  830. X        return(1);
  831. X
  832. X    return(0);
  833. X
  834. X}    /* end of setcolor_internal */
  835. X
  836. X/*+-------------------------------------------------------------------------
  837. X    restore_initial_colors() - make screen safe
  838. X
  839. XOn SCO, restore color choices at execution time if we successfully
  840. Xgot them from the driver; in other situations, use tcap to reset.
  841. X--------------------------------------------------------------------------*/
  842. Xvoid
  843. Xrestore_initial_colors()
  844. X{
  845. X#if defined(M_SYSV) || defined(SVR4)
  846. X    if(use_colors && got_original_colors)
  847. X        setcolor(colors_initial);
  848. X    else
  849. X#endif
  850. X    {
  851. X        tcap_blink_off();
  852. X        tcap_bold_off();
  853. X        tcap_underscore_off();
  854. X    }
  855. X}    /* end of restore_initial_colors */
  856. X
  857. X/*+-------------------------------------------------------------------------
  858. X    get_initial_colors() - read colors at time of execution from driver
  859. X
  860. X     00000000001111111111222222222233
  861. X     01234567890123456789012345678901
  862. X     0000|--|0000|--|0000|--|0000|--|
  863. X          fg      bk      fg      bk
  864. X           reverse      normal
  865. X
  866. X--------------------------------------------------------------------------*/
  867. X#if defined(M_SYSV)
  868. Xvoid
  869. Xget_initial_colors()
  870. X{
  871. X    uint cur_attr;
  872. X    ulong fgnd;
  873. X    ulong bgnd;
  874. X
  875. X    colors_initial = colors_normal;     /* scoterm can use color but ... */
  876. X    if(ioctl(TTYIN, GIO_ATTR, 0) == -1) /* ... GIO_ATTR won't work */
  877. X        return;
  878. X    colors_normal = 0L;
  879. X
  880. X/*
  881. X * first, reverse, so we can end up with normal colors selected
  882. X */
  883. X    write(1,"\033[7m",4);        /* select reverse */
  884. X    cur_attr = (uint)ioctl(TTYIN, GIO_ATTR, 0);
  885. X    fgnd = (ulong)cur_attr & 0x0F;
  886. X    bgnd = (ulong) (cur_attr >> 4) & 0x0F;
  887. X    colors_normal |= (fgnd << 24) | (bgnd << 16);
  888. X
  889. X/*
  890. X * now, normal
  891. X */
  892. X    write(1,"\033[m",3);        /* select normal */
  893. X    cur_attr = (uint)ioctl(TTYIN, GIO_ATTR, 0);
  894. X    fgnd = (ulong)cur_attr & 0x0F;
  895. X    bgnd = (ulong) (cur_attr >> 4) & 0x0F;
  896. X    colors_normal |= (fgnd << 8) | bgnd;
  897. X
  898. X    colors_initial = colors_normal;        /* save for restore_initial_colors */
  899. X    got_original_colors = 1;
  900. X
  901. X}    /* end of get_initial_colors */
  902. X#endif
  903. X
  904. X/*+-------------------------------------------------------------------------
  905. X    read_colors_file() - read color definition if present
  906. X--------------------------------------------------------------------------*/
  907. Xvoid
  908. Xread_colors_file()
  909. X{
  910. X    FILE *fp;
  911. X    char s128[128];
  912. X#define MAX_COLOR_TOKENS 6
  913. X    char *tokens[MAX_COLOR_TOKENS];
  914. X    int ntokens;
  915. X    char *cptr;
  916. X    int itmp;
  917. X
  918. X    if(tty_not_char_special)
  919. X        return;
  920. X
  921. X#if defined(M_SYSV)
  922. X    get_initial_colors();
  923. X#endif
  924. X
  925. X    get_home_dir(s128);
  926. X    strcat(s128,"/.ecu/colors");
  927. X    if(access(s128,4))
  928. X        return;
  929. X
  930. X    if(!(fp = fopen(s128,"r")))
  931. X    {
  932. X        strcpy(s128,eculibdir);
  933. X        strcat(s128,"/colors");
  934. X        if(!(fp = fopen(s128,"r")))
  935. X            return;
  936. X    }
  937. X
  938. X    while(fgets(s128,sizeof(s128),fp))
  939. X    {
  940. X        if(s128[0] == '#')            /* comment? */
  941. X            continue;
  942. X        if(itmp = strlen(s128))        /* itmp = len; if > 0 ... */
  943. X        {
  944. X            itmp--;
  945. X            s128[itmp] = 0;            /* ... strip trailing NL */
  946. X        }
  947. X        cptr = s128;                /* first call to str_token, -> buff */
  948. X        while((*cptr == 0x20) || (*cptr == TAB))
  949. X            cptr++;                /* strip leading spaces */
  950. X        if(*cptr == 0)                /* if line all blank, skip it */
  951. X            continue;
  952. X
  953. X        build_str_array(s128,tokens,MAX_COLOR_TOKENS,&ntokens);
  954. X        if(ntokens < 2)
  955. X            continue;
  956. X
  957. X        setcolor_internal(ntokens,tokens);
  958. X
  959. X    }            /* while records left to ready */
  960. X
  961. X#if defined(M_SYSV)
  962. X    if(ioctl(TTYIN, GIO_ATTR, 0) == -1)
  963. X        colors_initial = colors_normal; /* hack for scoterm */
  964. X#endif
  965. X
  966. X    fclose(fp);
  967. X}    /* end of read_colors_file */
  968. X
  969. X/*+-------------------------------------------------------------------------
  970. X    ring_bell()
  971. X--------------------------------------------------------------------------*/
  972. Xvoid
  973. Xring_bell()
  974. X{
  975. X    char b = BEL;
  976. X
  977. X    if(tty_not_char_special)
  978. X        return;
  979. X    write(TTYOUT,&b,1);
  980. X
  981. X}    /* end of ring_bell */
  982. X
  983. X/*+-------------------------------------------------------------------------
  984. X    termio_to_kbd_chars()
  985. X--------------------------------------------------------------------------*/
  986. Xvoid
  987. Xtermio_to_kbd_chars()
  988. X{
  989. X    kbdintr =  (tty_termio_at_entry.c_cc[VINTR])
  990. X        ? (tty_termio_at_entry.c_cc[VINTR]  & 0x7F) : '\377';
  991. X    kbdquit =  (tty_termio_at_entry.c_cc[VQUIT])
  992. X        ? (tty_termio_at_entry.c_cc[VQUIT]  & 0x7F) : '\377';
  993. X    kbderase = (tty_termio_at_entry.c_cc[VERASE])
  994. X        ? (tty_termio_at_entry.c_cc[VERASE] & 0x7F) : '\377';
  995. X    kbdkill =  (tty_termio_at_entry.c_cc[VKILL])
  996. X        ? (tty_termio_at_entry.c_cc[VKILL]  & 0x7F) : '\377';
  997. X    kbdeof =   (tty_termio_at_entry.c_cc[VEOF])
  998. X        ? (tty_termio_at_entry.c_cc[VEOF]   & 0x7F) : '\04';
  999. X    kbdeol2 =  (tty_termio_at_entry.c_cc[VEOL])
  1000. X        ? (tty_termio_at_entry.c_cc[VEOL]   & 0x7F) : '\377';
  1001. X    kbdeol =   (tty_termio_at_entry.c_iflag & ICRNL)
  1002. X        ? '\r' : '\n';
  1003. X
  1004. X    kbd_is_7bit = ((tty_termio_at_entry.c_cflag & PARENB) != 0);
  1005. X    echo_erase_char = tty_termio_at_entry.c_lflag & ECHOE;
  1006. X    echo_kill_char = tty_termio_at_entry.c_lflag & ECHOK;
  1007. X
  1008. X}    /* end of termio_to_kbd_chars */
  1009. X
  1010. X/*+-------------------------------------------------------------------------
  1011. X    ttyinit(param)
  1012. X--------------------------------------------------------------------------*/
  1013. Xvoid
  1014. Xttyinit(param)
  1015. Xuchar param;
  1016. X{
  1017. X    int fddevtty;
  1018. X    int itmp;
  1019. X    char *ftype;
  1020. X#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)
  1021. X    int monitor_type;
  1022. X    int cons_get_err;
  1023. X#endif
  1024. X
  1025. X    ttype = getenv("TERM");    /* must do this first */
  1026. X
  1027. X    /*
  1028. X     * get control tty control chars in case stdin not tty
  1029. X     */
  1030. X    if((fddevtty = open("/dev/tty",O_RDONLY,0)) >= 0)
  1031. X    {
  1032. X        ioctl(fddevtty,TCGETA,(char *)&tty_termio_at_entry);
  1033. X        close(fddevtty);
  1034. X        termio_to_kbd_chars();
  1035. X    }
  1036. X
  1037. X    sigint = 0;            /* see xmtr signal handlers */
  1038. X
  1039. X    memset((char *)&tty_stat,0xFF,sizeof(struct stat));
  1040. X    memset((char *)&ttyp0,0xFF,sizeof(struct stat));
  1041. X    memset((char *)&console,0xFF,sizeof(struct stat));
  1042. X    stat("/dev/console",&console);
  1043. X    stat("/dev/null",&dn);
  1044. X    stat("/dev/tty01",&tty01);
  1045. X    stat("/dev/ttyp0",&ttyp0);
  1046. X
  1047. X    /*
  1048. X     * if stdin not open or is /dev/null or is non-character-device
  1049. X     */
  1050. X
  1051. X    itmp = fstat(TTYIN,&tty_stat);
  1052. X    if(itmp || ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
  1053. X        ((dn.st_ino == tty_stat.st_ino) && (dn.st_rdev == tty_stat.st_rdev)))
  1054. X    {
  1055. X        tcap_LINES = LINES = 25;    /* fake necessary termcap/curses vars */
  1056. X        tcap_COLS = COLS = 80;
  1057. X        LINESxCOLS = tcap_LINES * tcap_COLS;
  1058. X        shm->scr_lines = tcap_LINES;
  1059. X        shm->scr_cols = tcap_COLS;
  1060. X        shm->scr_size = LINESxCOLS;
  1061. X
  1062. X        tty_not_char_special = 1;
  1063. X        tty_is_multiscreen = 0;
  1064. X        return;
  1065. X    }
  1066. X
  1067. X    /*
  1068. X     * if pty
  1069. X     */
  1070. X    if((tty_stat.st_rdev & 0xFF00) == (ttyp0.st_rdev & 0xFF00))
  1071. X        tty_is_pty = 1;
  1072. X
  1073. X    /*
  1074. X     * if pts
  1075. X     */
  1076. X#if defined(METROLINK_X11R4_PTS)
  1077. X    memset((char *)&pts000,0xFF,sizeof(struct stat));
  1078. X    stat("/dev/pts000",&pts000);
  1079. X    if((tty_stat.st_rdev & 0xFF00) == (pts000.st_rdev & 0xFF00))
  1080. X        tty_is_pts = 1;
  1081. X#endif /* METROLINK_X11R4_PTS */
  1082. X
  1083. X    /*
  1084. X     * use color if we are on a display that supports it and we know how :-|
  1085. X     */
  1086. X    use_colors = 0;
  1087. X
  1088. X#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)
  1089. X    if( ((cons_get_err = ioctl(TTYIN,CONS_GET,&monitor_type)) >= 0) &&
  1090. X        (use_colors = (monitor_type != MONO)))
  1091. X    {
  1092. X        read_colors_file();
  1093. X        setcolor(colors_normal);
  1094. X    }
  1095. X
  1096. X#endif /* CONS_GET && MONO && USE_COLOR */
  1097. X
  1098. X#if defined(M_SYSV) /* for multiscreen and scoterm */
  1099. X
  1100. X    /*
  1101. X     * remember whether or not we are on a multiscreen
  1102. X     */
  1103. X    tty_is_multiscreen = !(cons_get_err < 0);
  1104. X
  1105. X    /*
  1106. X     * a fuzzy heuristic for scoterm:
  1107. X     * 1. presence of WINDOWID and
  1108. X     * 2. first four characters of $TERM == "ansi"
  1109. X     */
  1110. X    if(getenv("WINDOWID") && ttype && !strncmp(ttype,"ansi",4))
  1111. X    {
  1112. X        use_colors = 1;
  1113. X        read_colors_file();
  1114. X        setcolor(colors_normal);
  1115. X    }
  1116. X#endif /* M_SYSV multiscreen and scoterm */
  1117. X
  1118. X    /*
  1119. X     * save initial tty state
  1120. X     */
  1121. X    ioctl(TTYIN,TCGETA,(char *)&tty_termio_at_entry);
  1122. X    tty_escape_timeout =
  1123. X        B_to_timeout_msec(tty_termio_at_entry.c_cflag,tty_stat.st_rdev);
  1124. X
  1125. X    termio_to_kbd_chars();
  1126. X
  1127. X    tty_termio_current = tty_termio_at_entry;
  1128. X    current_ttymode = 0;
  1129. X
  1130. X    get_home_dir(screen_dump_file_name);
  1131. X    strcat(screen_dump_file_name,"/.ecu/screen.dump");
  1132. X
  1133. X    ftype = 0;
  1134. X    if(dash_f_funckeytype)
  1135. X        ftype =    dash_f_funckeytype;
  1136. X    else
  1137. X        ftype = getenv("ECUFUNCKEY");
  1138. X    if(ttype || ftype)
  1139. X        funckeymap_read((ftype) ? ftype : ttype);
  1140. X
  1141. X    /* initialize termcap */
  1142. X    tcap_init();            /* read termcap strings */
  1143. X
  1144. X    /* yetch - magic number gretching for lines and columns */
  1145. X    if(tcap_LINES < 20)
  1146. X    {
  1147. X        ff(se,"\7screen height must be >= 20 lines (found %dx%d).\r\n",
  1148. X            tcap_COLS,tcap_LINES);
  1149. X        termecu(TERMECU_GEOMETRY);
  1150. X    }
  1151. X    if(tcap_LINES > SCREEN_LINES_MAX)
  1152. X    {
  1153. X        ff(se,"\7screen height limited to %d lines (found %dx%d).\r\n",
  1154. X            SCREEN_LINES_MAX,tcap_COLS,tcap_LINES);
  1155. X        termecu(TERMECU_GEOMETRY);
  1156. X    }
  1157. X    if(tcap_COLS != SCREEN_COLS_MAX)
  1158. X    {
  1159. X        ff(se,"\7terminal width must be %d columns (found %dx%d).\r\n",
  1160. X            SCREEN_COLS_MAX,tcap_COLS,tcap_LINES);
  1161. X        termecu(TERMECU_GEOMETRY);
  1162. X    }
  1163. X    LINESxCOLS = tcap_LINES * tcap_COLS;
  1164. X    shm->scr_lines = tcap_LINES;
  1165. X    shm->scr_cols = tcap_COLS;
  1166. X    shm->scr_size = LINESxCOLS;
  1167. X    ttyinit_has_been_called = 1;
  1168. X
  1169. X}    /* end of ttyinit */
  1170. X
  1171. X/*+-----------------------------------------------------------------------
  1172. X    ttymode(arg) -- control user console (kbd/screen)
  1173. X
  1174. X  Where arg ==
  1175. X    0 restore attributes saved at start of execution
  1176. X    1 raw mode (send xon/xoff, but do not respond to it, no ISIG/SIGINT)
  1177. X    2 raw mode (same as 1 but allow keyboard interrupts)
  1178. X    3 same as 2 but terminate program on SIGINT
  1179. X    4 terminate ecu on sigint
  1180. X
  1181. X------------------------------------------------------------------------*/
  1182. Xvoid
  1183. Xttymode(arg)
  1184. Xint arg;
  1185. X{
  1186. X
  1187. X    /*
  1188. X     * ignore if no keyboard involved
  1189. X     */
  1190. X    if(tty_not_char_special)
  1191. X        return;
  1192. X
  1193. X    /*
  1194. X     * usage()->termecu()->ttymode() is possible before ttyinit()
  1195. X     */
  1196. X    if(!ttyinit_has_been_called)
  1197. X        return;
  1198. X
  1199. X    switch(arg)
  1200. X    {
  1201. X    case 0:
  1202. X        ioctl(TTYIN,TCSETAW,(char *)&tty_termio_at_entry);
  1203. X        tty_termio_current = tty_termio_at_entry;
  1204. X        current_ttymode = 0;
  1205. X        break;
  1206. X
  1207. X    case 4:
  1208. X        ttymode_termecu_on_sigint = 1;
  1209. X        /* fall thru */
  1210. X    case 1:
  1211. X    case 2:
  1212. X    case 3:
  1213. X        tty_termio_current = tty_termio_at_entry;
  1214. X
  1215. X        tty_termio_current.c_cflag &= ~(PARENB | PARODD);
  1216. X        tty_termio_current.c_cflag |= CS8;
  1217. X
  1218. X        /* don't want to honor tty xon/xoff, but pass to other end */
  1219. X        tty_termio_current.c_iflag &=
  1220. X            ~(INLCR | ICRNL | IGNCR | IUCLC | ISTRIP);
  1221. X        tty_termio_current.c_iflag |= IXON | IXOFF;    /* both ends xon/xoff */
  1222. X
  1223. X        tty_termio_current.c_oflag |= OPOST;
  1224. X        tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
  1225. X
  1226. X        tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
  1227. X        if(arg > 1)
  1228. X            tty_termio_current.c_lflag |= ISIG;
  1229. X
  1230. X        tty_termio_current.c_cc[VMIN] = 1;
  1231. X        tty_termio_current.c_cc[VTIME] = 0;
  1232. X
  1233. X        ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
  1234. X        current_ttymode = arg;
  1235. X        break;
  1236. X
  1237. X    default:
  1238. X        ff(se,"\r\nttymode: invalid argument %d\r\n",arg);
  1239. X        break;
  1240. X    }
  1241. X}    /* end of ttymode */
  1242. X
  1243. X/*+-------------------------------------------------------------------------
  1244. X    int    get_ttymode()
  1245. X--------------------------------------------------------------------------*/
  1246. Xint
  1247. Xget_ttymode()
  1248. X{
  1249. X    return(current_ttymode);
  1250. X}    /* end of get_ttymode */
  1251. X
  1252. X/*+-----------------------------------------------------------------------
  1253. X    ttyflush(flush_type) -- flush tty driver input &/or output buffers
  1254. X
  1255. X0 == input buffer
  1256. X1 == output buffer
  1257. X2 == both buffers
  1258. X------------------------------------------------------------------------*/
  1259. Xvoid
  1260. Xttyflush(flush_type)
  1261. Xint flush_type;
  1262. X{
  1263. X    if(tty_not_char_special)
  1264. X        return;
  1265. X
  1266. X    ioctl(TTYIN,TCXONC,(char *)0); /* stop tty output */
  1267. X
  1268. X#if !defined(M_I286)
  1269. X    ioctl(TTYIN,TCFLSH,(char *)flush_type);
  1270. X#else
  1271. X    /* avoid 286 compiler warning of cast int to far ptr */
  1272. X    switch(flush_type)
  1273. X    {
  1274. X        case 0:
  1275. X            ioctl(TTYIN,TCFLSH,(char *)0); break;
  1276. X        case 1:
  1277. X            ioctl(TTYIN,TCFLSH,(char *)1); break;
  1278. X        case 2:
  1279. X            ioctl(TTYIN,TCFLSH,(char *)2); break;
  1280. X    }
  1281. X#endif
  1282. X
  1283. X    ioctl(TTYIN,TCXONC,(char *)1);    /* restart tty output */
  1284. X
  1285. X    if(flush_type != 1)
  1286. X    {
  1287. X        dole_out_tgc_accum = (uchar *)0;
  1288. X        dole_out_tgc_accum_count = 0;
  1289. X    }
  1290. X
  1291. X}    /* end of ttyflush */
  1292. X
  1293. X/*+-------------------------------------------------------------------------
  1294. X    ttyrdchk() - see if key pressed and not read
  1295. X--------------------------------------------------------------------------*/
  1296. Xint
  1297. Xttyrdchk()
  1298. X{
  1299. X    return(rdchk(TTYIN) || dole_out_tgc_accum_count);
  1300. X}    /* end of ttyrdchk */
  1301. X
  1302. X/*+-------------------------------------------------------------------------
  1303. X    ttygetc(xkey_ok) -- get a key from the keyboard
  1304. Xif UNIX or XENIX, map extended keys to sign-bit-set special value
  1305. Xif xkey_ok is 0, disallow extended keys
  1306. X--------------------------------------------------------------------------*/
  1307. Xuint
  1308. Xttygetc(xkey_ok)
  1309. Xint xkey_ok;
  1310. X{
  1311. X    uchar ctmp;
  1312. X    extern int errno;
  1313. X    register uint itmp = 0;
  1314. X    long timeout_remaining;
  1315. X    static uchar tgc_accum[16];
  1316. X    uchar funckeymap();
  1317. X
  1318. X    if(tty_not_char_special)    /* this really is unexplored territory */
  1319. X    {
  1320. X        ctmp = 255;
  1321. X        read(TTYIN,(char *)&ctmp,1);
  1322. X        return((uint)ctmp);
  1323. X    }
  1324. X
  1325. X    if(dole_out_tgc_accum_count)
  1326. X    {
  1327. X        ctmp = *dole_out_tgc_accum++;
  1328. X        dole_out_tgc_accum_count--;
  1329. X        if(kbd_is_7bit)
  1330. X            ctmp &= 0x7F;
  1331. X        return((uint)ctmp);
  1332. X    }
  1333. X
  1334. XGET_KEY:
  1335. X    errno = 0;
  1336. X    if(read(TTYIN,(char *)&ctmp,1) < 0)
  1337. X    {
  1338. X        if(errno == EINTR)
  1339. X            goto GET_KEY;
  1340. X        perror_errmsg("keyboard");
  1341. X        termecu(TERMECU_TTYIN_READ_ERROR);
  1342. X    }
  1343. X
  1344. X    if(    ((ctmp >= 0x01) && (ctmp <= 0x1F) ||
  1345. X         (ctmp >= 0x81) && (ctmp <= 0x9F)) &&
  1346. X        (ctmp != kbderase) && (ctmp != kbdkill) &&
  1347. X        (ctmp != kbdeol) && (ctmp != kbdeol2) &&
  1348. X        (ctmp != kbdintr) && (ctmp != kbdeof) )
  1349. X    {
  1350. X        tgc_accum[0] = ctmp;
  1351. X        tgc_accum[itmp = 1] = 0;
  1352. X        timeout_remaining = tty_escape_timeout;
  1353. X#if defined(NAP_DEBUG)
  1354. X        ff(se,"timeout_remaining = %ld hzmsec=%ld\r\n",
  1355. X            timeout_remaining,hzmsec);
  1356. X#endif
  1357. X        while(((ctmp = funckeymap(tgc_accum,itmp)) >= XF_no_way) &&
  1358. X            (timeout_remaining > 0))
  1359. X        {
  1360. X            timeout_remaining -= Nap(hzmsec);
  1361. X#if defined(NAP_DEBUG)
  1362. X            ff(se,"timeout_remaining = %ld\r\n",timeout_remaining);
  1363. X#endif
  1364. X            if(!rdchk(TTYIN))
  1365. X                continue;
  1366. X            read(TTYIN,(char *)&ctmp,1);
  1367. X            if(itmp == (sizeof(tgc_accum) - 1))    /* do not allow overflow */
  1368. X            {
  1369. X                ctmp = XF_no_way;
  1370. X                break;
  1371. X            }
  1372. X            timeout_remaining = tty_escape_timeout;
  1373. X            tgc_accum[itmp++] = ctmp;
  1374. X        }
  1375. X        tgc_accum[itmp] = 0;
  1376. X        if((ctmp == XF_not_yet) && (itmp == 1))
  1377. X        {
  1378. X            if(kbd_is_7bit)
  1379. X                tgc_accum[0] &= 0x7F;
  1380. X            return((uint)tgc_accum[0]);
  1381. X        }
  1382. X        else if(ctmp < XF_no_way)    /* if we got a map */
  1383. X        {
  1384. X            if(kbd_test_active)
  1385. X            {
  1386. X                char title[128];
  1387. X                sprintf(title,"--> func key '%s' (%d key codes received)",
  1388. X                    kde_text(ctmp),itmp);
  1389. X                hex_dump(tgc_accum,-itmp,title,1);
  1390. X            }
  1391. X            if(!xkey_ok)
  1392. X            {
  1393. X                ring_bell();
  1394. X                goto GET_KEY;
  1395. X            }
  1396. X            switch(ctmp)
  1397. X            {
  1398. X                case IKDE_CU5:
  1399. X                    screen_dump(screen_dump_file_name);
  1400. X                    goto GET_KEY;
  1401. X                default:
  1402. X                    return((uint)ikde_to_xf(ctmp));
  1403. X            }
  1404. X            /*NOTREACHED*/
  1405. X        }
  1406. X        /* not func key -- must be typamatic control key */
  1407. X        if(kbd_test_active)
  1408. X        {
  1409. X            char title[128];
  1410. X            if(itmp > 1)
  1411. X            {
  1412. X                sprintf(title,
  1413. X                    "--> no func key recognized (%d key codes received)",itmp);
  1414. X                hex_dump(tgc_accum,-itmp,title,1);
  1415. X            }
  1416. X        }
  1417. X        dole_out_tgc_accum_count = itmp - 1;
  1418. X        dole_out_tgc_accum = tgc_accum + 1;
  1419. X        if(kbd_is_7bit)
  1420. X            tgc_accum[0] &= 0x7F;
  1421. X        return((uint)tgc_accum[0]);
  1422. X    }
  1423. X
  1424. X    /*
  1425. X     * simple key, not special
  1426. X     */
  1427. X    if(kbd_is_7bit)
  1428. X        ctmp &= 0x7F;
  1429. X    return((uint)ctmp);
  1430. X}    /* end if ttygetc */
  1431. X
  1432. X/*+-----------------------------------------------------------------------
  1433. X    ttygets(str,maxsize,flags,delim,pstrpos)
  1434. X
  1435. Xflags & TG_CRLF   - echo cr/lf terminator
  1436. Xflags & TG_XDELIM - extended delimiter set
  1437. X                    (Home, End, PgUp, PgDn, CurUp, CurDn)
  1438. Xflags & TG_EDIT   - redisplay/edit current string
  1439. Xflags & TG_IPOS   - if edit, use initial string pos
  1440. X------------------------------------------------------------------------*/
  1441. Xvoid
  1442. Xttygets(str,maxsize,flags,delim,pstrpos)
  1443. Xregister char *str;
  1444. Xint maxsize;
  1445. Xint flags;
  1446. Xuchar *delim;
  1447. Xint *pstrpos;
  1448. X{
  1449. X    register inch;
  1450. X    char ch;
  1451. X    register strcount = 0;
  1452. X    register strpos = 0;
  1453. X    int insert_mode = 0;
  1454. X    char *bs_str = "\010 \010";
  1455. X    extern int rcvrdisp_actual2_xmtr_buffer;
  1456. X
  1457. X    rcvrdisp_actual2_xmtr_buffer = 1; /* let tcap_ rtns buffer */
  1458. X
  1459. X    --maxsize;        /* decrement for safety */
  1460. X
  1461. X    if(flags & TG_EDIT)
  1462. X    {
  1463. X        strpos = strcount = strlen(str);
  1464. X        write(TTYOUT,str,strcount);
  1465. X        if(pstrpos && (*pstrpos > 0) && (*pstrpos <= strcount))
  1466. X            strpos = *pstrpos;
  1467. X        tcap_curleft(strcount - strpos);
  1468. X    }
  1469. X
  1470. X    while(1)
  1471. X    {
  1472. X        rcvrdisp_actual2_xmtr_buffer = 0; /* disallow tcap_ rtns buffer */
  1473. X        rcvrdisp_actual2_xmtr_buffer = 1; /* let tcap_ rtns buffer */
  1474. X        inch = ttygetc(1);
  1475. X        *delim = (uchar)inch;    /* last char will always be the delimiter */
  1476. X        if((inch == kbdintr) || (inch == ESC))
  1477. X        {
  1478. X            tcap_curright(strcount - strpos);
  1479. X            while(strcount)
  1480. X            {
  1481. X                write(TTYOUT,bs_str,strlen(bs_str));
  1482. X                strcount--;
  1483. X            }
  1484. X            str[strcount] = 0;
  1485. X            *delim = ESC;
  1486. X            goto RETURN;
  1487. X        }
  1488. X        else if(inch == kbdkill)
  1489. X        {
  1490. X            tcap_curright(strcount - strpos);
  1491. X            while(strcount)
  1492. X            {
  1493. X                write(TTYOUT,bs_str,strlen(bs_str));
  1494. X                strcount--;
  1495. X            }
  1496. X            strpos = 0;
  1497. X            *str = 0;
  1498. X            continue;
  1499. X        }
  1500. X        else if(inch == kbderase)
  1501. X        {
  1502. X            if(strcount)
  1503. X            {
  1504. X                if(strcount == strpos)
  1505. X                {
  1506. X                    write(TTYOUT,bs_str,strlen(bs_str));
  1507. X                    strcount--,strpos--;
  1508. X                }
  1509. X                else
  1510. X                {
  1511. X                    if(!strpos)
  1512. X                        continue;
  1513. X                    mem_cpy(str + strpos - 1,str + strpos,strcount - strpos);
  1514. X                    write(TTYOUT,"\010",1);
  1515. X                    str[--strcount] = 0;
  1516. X                    strpos--;
  1517. X                    write(TTYOUT,str + strpos,strlen(str + strpos));
  1518. X                    write(TTYOUT," ",1);
  1519. X                    tcap_curleft(strcount - strpos + 1);
  1520. X                }
  1521. X            }
  1522. X            str[strcount] = 0;
  1523. X            continue;
  1524. X        }
  1525. X        else if(inch == XFins)
  1526. X        {
  1527. X            insert_mode = !insert_mode;
  1528. X            continue;
  1529. X        }
  1530. X        else if(inch == XFcurlf)
  1531. X        {
  1532. X            if(strpos)
  1533. X            {
  1534. X                strpos--;
  1535. X                tcap_curleft(1);
  1536. X            }
  1537. X            continue;
  1538. X        }
  1539. X        else if(inch == XFcurrt)
  1540. X        {
  1541. X            if(strpos < strcount)
  1542. X            {
  1543. X                strpos++;
  1544. X                tcap_curright(1);
  1545. X            }
  1546. X            continue;
  1547. X        }
  1548. X
  1549. X        if(flags & TG_XDELIM)    /* extended delimiter */
  1550. X        {
  1551. X            switch(inch)
  1552. X            {
  1553. X                case XFhome:
  1554. X                case XFend:
  1555. X                case XFpgup:
  1556. X                case XFpgdn:
  1557. X                case XFcurup:
  1558. X                case XFcurdn:
  1559. X#ifdef notdef
  1560. X                    tcap_curright(strcount - strpos);
  1561. X                    while(strcount)
  1562. X                    {
  1563. X                        write(TTYOUT,bs_str,strlen(bs_str));
  1564. X                        strcount--;
  1565. X                    }
  1566. X#endif
  1567. X                    str[strcount] = 0;
  1568. X                    goto RETURN;
  1569. X            }
  1570. X        }
  1571. X
  1572. X        switch(inch)
  1573. X        {
  1574. X            case CRET:
  1575. X                *delim = NL;
  1576. X            case NL:
  1577. X                str[strcount] = 0;
  1578. X                tcap_curright(strcount - strpos);
  1579. X                if((flags & TG_CRLF))
  1580. X                    ff(se,"\r\n");
  1581. X                goto RETURN;
  1582. X
  1583. X            case CTL_L:
  1584. X            case CTL_R:
  1585. X                tcap_curright(strcount - strpos);
  1586. X                ff(se,"%s (insert mode %s)\r\n",make_char_graphic(inch,0),
  1587. X                    (insert_mode) ? "ON" : "OFF");
  1588. X                tcap_eeol();
  1589. X                write(TTYOUT,str,strcount);
  1590. X                tcap_curleft(strcount - strpos);
  1591. X                break;
  1592. X
  1593. X            default:
  1594. X                if((inch < SPACE) || (inch >= 0x7F))
  1595. X                {
  1596. X                    ring_bell();
  1597. X                    break;
  1598. X                }
  1599. X                if(strpos == strcount)
  1600. X                {
  1601. X                    if(strcount == maxsize)
  1602. X                    {
  1603. X                        ring_bell();
  1604. X                        continue;
  1605. X                    }
  1606. X                    str[strcount++] = inch;
  1607. X                    strpos++;
  1608. X                    ch = (char)inch;
  1609. X                    write(TTYOUT,&ch,1);
  1610. X                }
  1611. X                else
  1612. X                {
  1613. X                    if(insert_mode)
  1614. X                    {
  1615. X                        if(strcount == maxsize)
  1616. X                        {
  1617. X                            ring_bell();
  1618. X                            continue;
  1619. X                        }
  1620. X                        mem_cpy(str+strpos+1,str+strpos,strcount-strpos);
  1621. X                        str[strpos] = inch;
  1622. X                        strcount++;
  1623. X                        str[strcount] = 0;
  1624. X                        write(TTYOUT,str + strpos,strcount - strpos);
  1625. X                        strpos++;
  1626. X                        tcap_curleft(strcount - strpos);
  1627. X                    }
  1628. X                    else
  1629. X                    {
  1630. X                        str[strpos++] = inch;
  1631. X                        ch = (char)inch;
  1632. X                        write(TTYOUT,&ch,1);
  1633. X                    }
  1634. X                }
  1635. X                str[strcount] = 0;
  1636. X                continue;
  1637. X        }
  1638. X    }
  1639. X
  1640. XRETURN:
  1641. X    rcvrdisp_actual2_xmtr_buffer = 0; /* disallow tcap_ rtns buffer */
  1642. X    if(pstrpos)
  1643. X        *pstrpos = strpos;
  1644. X
  1645. X}    /* end of ttygets() */
  1646. X
  1647. X/*+-------------------------------------------------------------------------
  1648. X    ttygets_esd(tesd,flags,append_flag)
  1649. X--------------------------------------------------------------------------*/
  1650. Xttygets_esd(tesd,flags,append_flag)
  1651. XESD *tesd;
  1652. Xint flags;
  1653. Xint append_flag;
  1654. X{
  1655. X    char *pb = tesd->pb;
  1656. X    int maxcb = tesd->maxcb;
  1657. X    uchar delim;
  1658. X
  1659. X    if(append_flag)
  1660. X    {
  1661. X        pb += tesd->cb;
  1662. X        maxcb -= tesd->cb;
  1663. X    }
  1664. X    else
  1665. X    {
  1666. X        pb = tesd->pb;
  1667. X        maxcb = tesd->maxcb;
  1668. X        tesd->cb = 0;
  1669. X    }
  1670. X
  1671. X    ttygets(pb,maxcb,flags,&delim,(int *)0);
  1672. X
  1673. X    if(delim == ESC)
  1674. X    {
  1675. X        if(!append_flag)
  1676. X            esdzero(tesd);
  1677. X        return(eProcAttn_ESCAPE);
  1678. X    }
  1679. X
  1680. X    tesd->cb = strlen(tesd->pb);
  1681. X    plogs(pb);
  1682. X    if(flags & 1)
  1683. X        plogc(NL);
  1684. X    return(0);
  1685. X
  1686. X}    /* end of ttygets_esd */
  1687. X
  1688. X/*+-------------------------------------------------------------------------
  1689. X    kbd_test() - test keyboard handler
  1690. X--------------------------------------------------------------------------*/
  1691. Xvoid
  1692. Xkbd_test()
  1693. X{
  1694. X    uint ctmp = 0;
  1695. X
  1696. X    pputs("Press keys to test (ESCape to exit)\n");
  1697. X    kbd_test_active = 1;
  1698. X    while(ctmp != ESC)
  1699. X    {
  1700. X        ctmp = ttygetc(1);
  1701. X        
  1702. X        if((ctmp < 0x80) && dole_out_tgc_accum_count)
  1703. X        {
  1704. X            pprintf("    got %d key sequence %s ",
  1705. X                dole_out_tgc_accum_count + 1,hex_to_ascii_name(ctmp));
  1706. X            while(dole_out_tgc_accum_count)
  1707. X            {
  1708. X                pprintf("%s ",hex_to_ascii_name(*dole_out_tgc_accum++));
  1709. X                dole_out_tgc_accum_count--;
  1710. X            }
  1711. X            pputs("\n");
  1712. X            ctmp = 0;
  1713. X            continue;
  1714. X        }
  1715. X        pputs("    got ");
  1716. X        if(ctmp >= 0x80)
  1717. X            pprintf("fkey '%s'\n",xf_text(ctmp));
  1718. X        else
  1719. X            pprintf("key  '%s'\n",hex_to_ascii_name(ctmp));
  1720. X    }
  1721. X    kbd_test_active = 0;
  1722. X    ttyflush(0);
  1723. X    pputs("keyboard test complete\n\n");
  1724. X    dole_out_tgc_accum = (uchar *)0;
  1725. X    dole_out_tgc_accum_count = 0;
  1726. X    
  1727. X}    /* end of kbd_test */
  1728. X
  1729. X/*+-------------------------------------------------------------------------
  1730. X    char *get_ttyname() - return pointer to static string
  1731. X
  1732. XThis routine is largely a crock and is likely to explode at any rev or twist
  1733. X--------------------------------------------------------------------------*/
  1734. Xchar *
  1735. Xget_ttyname()
  1736. X{
  1737. X#ifndef OLD_WAY
  1738. X    char *ttyname();
  1739. X    return(ttyname(TTYIN));
  1740. X#else
  1741. X    static char ttname[64];
  1742. X    register unsigned int rdev;
  1743. X    register char *cptr;
  1744. X
  1745. X    if(tty_not_char_special)
  1746. X        return("stdin");
  1747. X    else if(!tty_is_multiscreen)
  1748. X        return("non-multiscreen");
  1749. X
  1750. X    rdev = (unsigned)tty_stat.st_rdev;
  1751. X    if(rdev == 0x0301)
  1752. X        strcpy(ttname,"/dev/console");
  1753. X#if defined(M_UNIX)
  1754. X    else if(rdev == 0x0000)
  1755. X        strcpy(ttname,"/dev/syscon");
  1756. X#endif
  1757. X    else
  1758. X    {
  1759. X        strcpy(ttname,"/dev/tty");
  1760. X        cptr = ttname + 8;
  1761. X
  1762. X        if(rdev < 0x000C)
  1763. X        {
  1764. X            *cptr++ = '0' + ((rdev + 1) / 10);
  1765. X            *cptr++ = '0' + ((rdev + 1) % 10);
  1766. X        }
  1767. X        else if(!(rdev & ~0x58F))
  1768. X        {
  1769. X            *cptr++ = (rdev & 0x0008) ? '2' : '1';
  1770. X            *cptr++ = ((rdev & 0x0080) ? 'A' : 'a') + (rdev & 0x0007);
  1771. X        }
  1772. X        else
  1773. X        {
  1774. X            *cptr++ = '?';
  1775. X            *cptr++ = '?';
  1776. X        }
  1777. X        *cptr = 0;
  1778. X    }
  1779. X
  1780. X    return(ttname);
  1781. X#endif
  1782. X}    /* end of get_ttyname */
  1783. X
  1784. X/* end of ecutty.c */
  1785. X/* vi: set tabstop=4 shiftwidth=4: */
  1786. SHAR_EOF
  1787. chmod 0644 ecutty.c ||
  1788. echo 'restore of ecutty.c failed'
  1789. Wc_c="`wc -c < 'ecutty.c'`"
  1790. test 36216 -eq "$Wc_c" ||
  1791.     echo 'ecutty.c: original size 36216, current size' "$Wc_c"
  1792. rm -f _shar_wnt_.tmp
  1793. fi
  1794. # ============= ecutty.h ==============
  1795. if test -f 'ecutty.h' -a X"$1" != X"-c"; then
  1796.     echo 'x - skipping ecutty.h (File already exists)'
  1797.     rm -f _shar_wnt_.tmp
  1798. else
  1799. > _shar_wnt_.tmp
  1800. echo 'x - extracting ecutty.h (Text)'
  1801. sed 's/^X//' << 'SHAR_EOF' > 'ecutty.h' &&
  1802. X/*+-------------------------------------------------------------------------
  1803. X    ecutty.h
  1804. X    wht@n4hgf.Mt-Park.GA.US
  1805. X--------------------------------------------------------------------------*/
  1806. X/*+:EDITS:*/
  1807. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1808. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1809. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  1810. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1811. X/*:07-14-1991-18:19-wht@n4hgf-new ttygets functions */
  1812. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1813. X
  1814. X#ifndef _ecutty_h
  1815. X#define _ecutty_h
  1816. X
  1817. Xtypedef struct color_type
  1818. X{
  1819. X    char *name;
  1820. X    int num;
  1821. X} COLOR;
  1822. X
  1823. X#ifdef DEFINE_TTY_DATA
  1824. XCOLOR colors[] =
  1825. X{
  1826. X    { "black",        0 },
  1827. X    { "blue",        1 },
  1828. X    { "brown",        6 },
  1829. X    { "cyan",        3 },
  1830. X    { "gray",        8 },
  1831. X    { "green",        2 },
  1832. X    { "hi_white",    15 },
  1833. X    { "lt_blue",    9 },
  1834. X    { "lt_cyan",    11 },
  1835. X    { "lt_green",    10 },
  1836. X    { "lt_magenta",    13 },
  1837. X    { "lt_red",        12 },
  1838. X    { "magenta",    5 },
  1839. X    { "red",        4 },
  1840. X    { "white",        7 },
  1841. X    { "yellow",        14 },
  1842. X    {(char *)0,-1}
  1843. X};
  1844. X#else
  1845. Xextern COLOR colors[];
  1846. X#endif
  1847. X
  1848. X/* color words are ulong:
  1849. X   MSB:  reverse video foreground
  1850. X         reverse video background
  1851. X         normal  video foreground
  1852. X   LSB:  normal  video background
  1853. X*/
  1854. X
  1855. X/*
  1856. X * ttygets flag bits
  1857. X */
  1858. X#define TG_CRLF        1    /* echo cr/lf terminator */
  1859. X#define TG_XDELIM    2    /* extended delimiter set */
  1860. X#define TG_EDIT        4    /* redisplay/edit current string */
  1861. X
  1862. X#endif /* _ecutty_h */
  1863. X
  1864. X/* vi: set tabstop=4 shiftwidth=4: */
  1865. X/* end of ecutty.h */
  1866. SHAR_EOF
  1867. chmod 0644 ecutty.h ||
  1868. echo 'restore of ecutty.h failed'
  1869. Wc_c="`wc -c < 'ecutty.h'`"
  1870. test 1477 -eq "$Wc_c" ||
  1871.     echo 'ecutty.h: original size 1477, current size' "$Wc_c"
  1872. rm -f _shar_wnt_.tmp
  1873. fi
  1874. # ============= ecuuclc.c ==============
  1875. if test -f 'ecuuclc.c' -a X"$1" != X"-c"; then
  1876.     echo 'x - skipping ecuuclc.c (File already exists)'
  1877.     rm -f _shar_wnt_.tmp
  1878. else
  1879. > _shar_wnt_.tmp
  1880. echo 'x - extracting ecuuclc.c (Text)'
  1881. sed 's/^X//' << 'SHAR_EOF' > 'ecuuclc.c' &&
  1882. X/*+-----------------------------------------------------------------------
  1883. X    ecuuclc.c - uuper/lower-case string functions
  1884. X    wht@n4hgf.Mt-Park.GA.US
  1885. X
  1886. X  Defined functions:
  1887. X    minunique(str1,str2,minquan)
  1888. X    ulcmpb(str1,str2)
  1889. X    ulindex(str1,str2)
  1890. X    ulrindex(str1,str2)
  1891. X
  1892. X------------------------------------------------------------------------*/
  1893. X/*+:EDITS:*/
  1894. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  1895. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  1896. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  1897. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1898. X
  1899. Xchar to_upper();
  1900. Xchar to_lower();
  1901. X/*+----------------------------------------------------------------------------
  1902. X    ulcmpb(str1,str) -- Upper/Lower [case insensitive] Compare Bytes
  1903. X
  1904. X Returns -1 if strings are equal, else failing character position
  1905. X If the second strings terminates with a null and both strings have matched
  1906. X character for character until that point, then -1 is returned.
  1907. X NOTE:  this is not a test for complete equality of two strings, but allows
  1908. X discovery of a string as a substring in a larger containing string.
  1909. X-----------------------------------------------------------------------------*/
  1910. Xint
  1911. Xulcmpb(str1,str2)
  1912. Xregister unsigned char *str1;
  1913. Xregister unsigned char *str2;
  1914. X{
  1915. Xregister istr;
  1916. X
  1917. X    for( istr=0 ; ;  ++istr )
  1918. X    {
  1919. X        if(str2[istr] == '\0')          /* if second string exhausts, match! */
  1920. X            return(-1);
  1921. X        if((str1[istr] == '\0' ) ||
  1922. X            ( to_upper(str1[istr]) != to_upper(str2[istr]) ))
  1923. X            return(istr);
  1924. X    }
  1925. X    /*NOTREACHED*/
  1926. X} /* end of ulcmpb */
  1927. X
  1928. X/*+-------------------------------------------------------------------------
  1929. X    ulindex:  Upper/Lower [case insensitive] Index function
  1930. X
  1931. X  Returns position of 'str2' in 'str1' if found
  1932. X  If 'str2' is null, then 0 is returned (null matches anything)
  1933. X  Returns -1 if not found
  1934. X
  1935. X  uses 'ulcmpb'
  1936. X--------------------------------------------------------------------------*/
  1937. Xint
  1938. Xulindex(str1,str2)
  1939. Xregister char *str1;    /* the (target) string to search */
  1940. Xregister char *str2;    /* the (comparand) string to search for */
  1941. X{
  1942. Xregister istr1 = 0;        /* moving index into str1 */
  1943. Xregister char *mstr = str1;    /* moving string pointer */
  1944. X
  1945. X    if(str2[0] == '\0')             /* null string matches anything */
  1946. X        return(0);
  1947. X    if(strlen(str2) > strlen(str1))
  1948. X        return(-1);
  1949. X    while(1)
  1950. X    {
  1951. X        if(*mstr == '\0')           /* if we exhaust target string, flunk */
  1952. X            return(-1);
  1953. X        /* Can we find either case of first comparand char in target? */
  1954. X        if( to_upper(*mstr) == to_upper(str2[0]) )
  1955. X        {
  1956. X            /* we have a first char match... does rest of string match? */
  1957. X            if(ulcmpb(mstr,str2) == -1)         /* if the rest matches, ... */
  1958. X                break;
  1959. X        }
  1960. X        /* we did not match this time... increment istr1, mstr and try again */
  1961. X        ++istr1;
  1962. X        ++mstr;
  1963. X    }
  1964. X    return(istr1);                  /* return match position */
  1965. X}    /* end of ulindex */
  1966. X
  1967. X/*+-------------------------------------------------------------------------
  1968. X    ulrindex:  Upper/Lower [case insensitive] Right Index function
  1969. X
  1970. X  Returns position of 'str2' in 'str1' if found
  1971. X  Returns -1 if not found
  1972. X  If 'str2' is null, then -1 is returned
  1973. X
  1974. X  uses 'ulcmpb'
  1975. X--------------------------------------------------------------------------*/
  1976. Xint
  1977. Xulrindex(str1,str2)
  1978. Xregister char *str1;    /* the (target) string to search */
  1979. Xregister char *str2;    /* the (comparand) string to search for */
  1980. X{
  1981. Xregister char *mstr;
  1982. Xregister istr1;
  1983. X
  1984. X    if(!str2[0])             /* null string matches anything */
  1985. X        return(-1);
  1986. X    if(strlen(str2) > strlen(str1))
  1987. X        return(-1);
  1988. X
  1989. X    mstr = str1 + strlen(str1) - strlen(str2);    /* moving string pointer */
  1990. X    istr1 = mstr - str1;        /* moving index into str1 */
  1991. X
  1992. X    while(mstr >= str1)
  1993. X    {
  1994. X        /* Can we find either case of first comparand char in target? */
  1995. X        if( to_upper(*mstr) == to_upper(str2[0]) )
  1996. X        {
  1997. X            /* we have a first char match... does rest of string match? */
  1998. X            if(ulcmpb(mstr,str2) == -1)         /* if the rest matches, ... */
  1999. X                return(istr1);                  /* ... return match position */
  2000. X        }
  2001. X        /* we did not match this time... increment istr1, mstr and try again */
  2002. X        --istr1;
  2003. X        --mstr;
  2004. X    }
  2005. X    return(-1);
  2006. X}    /* end of ulrindex */
  2007. X
  2008. X/*+----------------------------------------------------------------
  2009. X    minunique(str1,str2,minquan)
  2010. X
  2011. X  Returns 1 if at least 'minquan' chars of str2 match
  2012. X  str1 and there are no chars after the minimum unique
  2013. X  chars which do not match str1.  Returns 0 on failure.
  2014. X-----------------------------------------------------------------*/
  2015. Xint
  2016. Xminunique(str1,str2,minquan)
  2017. Xregister char *str1;
  2018. Xregister char *str2;
  2019. Xregister minquan;
  2020. X{
  2021. Xregister index;
  2022. X
  2023. X    if(strlen(str2) < minquan)
  2024. X        return(0);
  2025. X
  2026. X    index = ulcmpb(str1,str2);
  2027. X    if(index < 0)
  2028. X        return(1);
  2029. X
  2030. X    if(index < minquan)
  2031. X        return(0);
  2032. X    if(index < strlen(str2))
  2033. X        return(0);
  2034. X    
  2035. X    return(1);
  2036. X    
  2037. X}   /* end of minunique */
  2038. X/* vi: set tabstop=4 shiftwidth=4: */
  2039. SHAR_EOF
  2040. chmod 0644 ecuuclc.c ||
  2041. echo 'restore of ecuuclc.c failed'
  2042. Wc_c="`wc -c < 'ecuuclc.c'`"
  2043. test 5082 -eq "$Wc_c" ||
  2044.     echo 'ecuuclc.c: original size 5082, current size' "$Wc_c"
  2045. rm -f _shar_wnt_.tmp
  2046. fi
  2047. # ============= ecuungetty.h ==============
  2048. if test -f 'ecuungetty.h' -a X"$1" != X"-c"; then
  2049.     echo 'x - skipping ecuungetty.h (File already exists)'
  2050.     rm -f _shar_wnt_.tmp
  2051. else
  2052. > _shar_wnt_.tmp
  2053. echo 'x - extracting ecuungetty.h (Text)'
  2054. sed 's/^X//' << 'SHAR_EOF' > 'ecuungetty.h' &&
  2055. X/*+-------------------------------------------------------------------------
  2056. X    ecuungetty.h
  2057. X    wht@n4hgf.Mt-Park.GA.US
  2058. X--------------------------------------------------------------------------*/
  2059. X/*+:EDITS:*/
  2060. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  2061. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  2062. X/*:04-27-1992-18:49-wht@n4hgf-ecuungetty grows up to chown ttys */
  2063. X/*:03-27-1992-16:21-wht@n4hgf-re-include protection for all .h files */
  2064. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  2065. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2066. X
  2067. X#ifndef _ecuungetty_h
  2068. X#define _ecuungetty_h
  2069. X
  2070. X/* ungetty definitions */
  2071. X#define    UG_NOTENAB        0    /* on no-switch exec, line not enabled */
  2072. X#define    UG_RESTART        1    /* on -t exec, restart needed */
  2073. X#define    UG_FAIL            2    /* on no switch exec, line in use */
  2074. X
  2075. X/* extended ecuungetty codes */
  2076. X#define UGE_T_LOGIN        200 /* -t found utmp status US_LOGIN */
  2077. X#define UGE_T_LOGGEDIN    201 /* -t found utmp status US_LOGGGEDIN */
  2078. X#define UGE_T_NOTFOUND    202 /* not found */
  2079. X#define UGE_BADARGC        230    /* usage: bad arg count */
  2080. X#define UGE_BADSWITCH    231    /* usage: bad switch */
  2081. X#define UGE_BADARGV        232    /* usage: bad argument */
  2082. X#define UGE_NOTROOT        233    /* ecuungetty found it had no root privileges */
  2083. X#define UGE_NOUUCP        234 /* cannot find uucp passwd entry */
  2084. X#define UGE_LOGIC        235 /* logic error */
  2085. X#define UGE_CALLER        236    /* caller is not ecu or root */
  2086. X#define UGE_BOMB        254 /* ungetty core dumped or killed */
  2087. X#define UGE_DNE            255 /* ungetty did not execute */
  2088. X
  2089. X/* vi: set tabstop=4 shiftwidth=4: */
  2090. X/* end of ecuungetty.h */
  2091. X
  2092. X#endif /* _ecuungetty_h */
  2093. SHAR_EOF
  2094. chmod 0644 ecuungetty.h ||
  2095. echo 'restore of ecuungetty.h failed'
  2096. Wc_c="`wc -c < 'ecuungetty.h'`"
  2097. test 1603 -eq "$Wc_c" ||
  2098.     echo 'ecuungetty.h: original size 1603, current size' "$Wc_c"
  2099. rm -f _shar_wnt_.tmp
  2100. fi
  2101. # ============= ecuusage.c ==============
  2102. if test -f 'ecuusage.c' -a X"$1" != X"-c"; then
  2103.     echo 'x - skipping ecuusage.c (File already exists)'
  2104.     rm -f _shar_wnt_.tmp
  2105. else
  2106. > _shar_wnt_.tmp
  2107. echo 'x - extracting ecuusage.c (Text)'
  2108. sed 's/^X//' << 'SHAR_EOF' > 'ecuusage.c' &&
  2109. X/*+-----------------------------------------------------------------------
  2110. X    ecuusage.c - user admonishment
  2111. X    wht@n4hgf.Mt-Park.GA.US
  2112. X
  2113. X  Defined functions:
  2114. X    general_usage(uptr)
  2115. X    log_cmd_usage()
  2116. X    usage()
  2117. X
  2118. X------------------------------------------------------------------------*/
  2119. X/*+:EDITS:*/
  2120. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  2121. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  2122. X/*:04-24-1992-21:07-wht@n4hgf-put defaults back into cmd line usage */
  2123. X/*:04-24-1992-06:30-wht@n4hgf-rll usage fixes */
  2124. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  2125. X/*:04-27-1991-01:52-wht@n4hgf-overhaul revision numbers */
  2126. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  2127. X
  2128. X#include <stdio.h>
  2129. X#include "termecu.h"
  2130. X#define pf printf
  2131. X
  2132. X#if defined(BUILDING_PROTOTYPES) || defined(lint)
  2133. X#define DEFAULT_TTY "/dev/tty1"
  2134. X#define DEFAULT_BAUD_RATE 2400
  2135. X#define DEFAULT_PARITY 'n'
  2136. X#endif
  2137. X
  2138. Xextern char *makedate;            /* temporary make date */
  2139. Xextern char *revstr;            /* ecunumrev.c */
  2140. SHAR_EOF
  2141. true || echo 'restore of ecuusage.c failed'
  2142. fi
  2143. echo 'End of ecu320 part 13'
  2144. echo 'File ecuusage.c is continued in part 14'
  2145. echo 14 > _shar_seq_.tmp
  2146. exit 0
  2147.  
  2148. exit 0 # Just in case...
  2149.