home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / ecu / part10 < prev    next >
Text File  |  1991-08-05  |  55KB  |  2,040 lines

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