home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / ecu / part13 < prev    next >
Encoding:
Text File  |  1992-09-13  |  56.9 KB  |  2,143 lines

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