home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume42 / ecu / part12 < prev    next >
Encoding:
Internet Message Format  |  1994-05-23  |  64.5 KB

  1. From: wht@n4hgf.atl.ga.us (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v42i110:  ecu - ECU Asynchronous Communications v3.30, Part12/37
  4. Date: 23 May 1994 14:23:00 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <2rqvqk$dmu@sparky.sterling.com>
  9. X-Md4-Signature: c8929ae97d660e500fe8137b1e855e84
  10.  
  11. Submitted-by: wht@n4hgf.atl.ga.us (Warren Tucker)
  12. Posting-number: Volume 42, Issue 110
  13. Archive-name: ecu/part12
  14. Environment: SCO,SCOXENIX,MOTOROLA,HP-UX,LINUX,NetBSD,SUNOS,SYSVR4,SOLARIS2
  15. Supersedes: ecu: Volume 32, Issue 36-75
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  ecu330/ecutty.c ecu330/sea/scurses.c
  22. # Wrapped by kent@sparky on Mon May 23 13:40:51 1994
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 12 (of 37)."'
  26. if test -f 'ecu330/ecutty.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'ecu330/ecutty.c'\"
  28. else
  29.   echo shar: Extracting \"'ecu330/ecutty.c'\" \(38143 characters\)
  30.   sed "s/^X//" >'ecu330/ecutty.c' <<'END_OF_FILE'
  31. X#ifndef USE_COLOR
  32. X#ifdef M_SYSV                 /* SCO family */
  33. X#define USE_COLOR
  34. X#endif
  35. X#ifdef MOTSVR3                 /* not yet */
  36. X#endif
  37. X#ifdef ISC                     /* not yet */
  38. X#endif
  39. X#ifdef sun                     /* not yet */
  40. X#endif
  41. X#ifdef ISCSVR4                 /* last I heard from lothar, this worked */
  42. X#define USE_COLOR
  43. X#endif
  44. X#ifdef ESIXSVR4                 /* I heard this does not work */
  45. X#endif
  46. X#ifdef LINUX
  47. X#define USE_COLOR
  48. X#endif
  49. X#endif /* USE_COLOR */
  50. X
  51. X/*+-------------------------------------------------------------------------
  52. X    ecutty.c - local tty (console) functions
  53. X    wht@n4hgf.atl.ga.us
  54. X
  55. X  Defined functions:
  56. X    B_to_timeout_msec(termio_tty,st_rdev)
  57. X    _setcolor(clrs)
  58. X    color_name_to_num(cname)
  59. X    get_initial_colors()
  60. X    get_ttymode()
  61. X    get_ttyname()
  62. X    kbd_test()
  63. X    read_colors_file()
  64. X    restore_initial_colors()
  65. X    ring_bell()
  66. X    setcolor(new_colors)
  67. X    setcolor_internal(ntokens,tokens)
  68. X    termio_to_kbd_chars()
  69. X    ttyflush(flush_type)
  70. X    ttygetc(xkey_ok)
  71. X    ttygets(str,maxsize,flags,delim,pstrpos)
  72. X    ttygets_esd(tesd,flags,append_flag)
  73. X    ttyinit(param)
  74. X    ttymode(arg)
  75. X    ttyrdchk()
  76. X
  77. X    In SCO versions, ECU keeps the the state of the normal and
  78. X    reverse video foreground and background colors in a 32-bit value:
  79. X
  80. X     00000000001111111111222222222233
  81. X     01234567890123456789012345678901
  82. X     0000|--|0000|--|0000|--|0000|--|
  83. X          fg      bk      fg      bk
  84. X           reverse      normal
  85. X
  86. X    The color values are per the SCO extended color definitons:
  87. X
  88. X    black    0     gray         8
  89. X    blue     1     lt_blue      9
  90. X    green    2     lt_green    10
  91. X    cyan     3     lt_cyan     11
  92. X    red      4     lt_red      12
  93. X    magenta  5     lt_magenta  13
  94. X    brown    6     yellow      14
  95. X    white    7     hi_white    15
  96. X
  97. X    With Lothar's ISC SVR4, the format is
  98. X
  99. X     00000000001111111111222222222233
  100. X     01234567890123456789012345678901
  101. X     00000000000000000011????0100????
  102. X       0   0   0   0   3   f   4  o b
  103. X    where f is the foreground color
  104. X    and   b is the background color
  105. X
  106. X    (I dont have one, so I'm guessing these colors are chosen from
  107. X    the ISO colors):
  108. X
  109. X     BLACK       0
  110. X     RED         1
  111. X     GREEN       2
  112. X     YELLOW      3
  113. X     BLUE        4
  114. X     MAGENTA     5
  115. X     CYAN        6
  116. X     WHITE       7
  117. X
  118. X--------------------------------------------------------------------------*/
  119. X/*+:EDITS:*/
  120. X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  121. X/*:03-13-1994-19:22-wht@fep-added WHT rterm detection */
  122. X/*:01-16-1994-15:46-wht@n4hgf-use ecumachdep.h */
  123. X/*:12-12-1993-13:32-wht@n4hgf-support MOTSVR3 */
  124. X/*:12-02-1993-14:05-Robert_Broughton@mindlink.bc.c-further LINUX patches */
  125. X/*:08-03-1993-12:43-wht@n4hgf-use build_arg_array in read_color_file */
  126. X/*:08-03-1993-12:43-wht@n4hgf-global colors file was never read */
  127. X/*:08-03-1993-12:41-wht@n4hgf-comment trigger can now be in col > 1 */
  128. X/*:07-17-1993-12:36-wht@n4hgf-no more rcvrdisp_actual2_xmtr_buffer junk */
  129. X/*:01-30-1993-13:29-wht@n4hgf-get rid of warning about unused variable */
  130. X/*:12-20-1992-12:37-wht@n4hgf-WHT experiment with attributes */
  131. X/*:10-18-1992-14:26-wht@n4hgf-add console xon/xoff control */
  132. X/*:10-08-1992-01:12-wht@n4hgf-no more obsolete Metro Link PTS */
  133. X/*:10-08-1992-01:06-wht@n4hgf-SVR4 color work + !use_color normal fix */
  134. X/*:09-15-1992-18:52-wht@n4hgf-left some debug code in patch01 dammit */
  135. X/*:09-13-1992-12:52-wht@n4hgf-add tty_is_scoterm */
  136. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  137. X/*:08-30-1992-07:42-wht@n4hgf-implement USE_COLOR+turn off ESIX color for now */
  138. X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  139. X/*:08-16-1992-03:43-wht@n4hgf-add -F funckeytype */
  140. X/*:06-20-1992-21:13-wht@n4hgf-eculibdir was overwritten if no home dir colors */
  141. X/*:06-16-1992-11:20-wht@n4hgf-ECUFUNCKEY */
  142. X/*:05-05-1992-17:42-wht@n4hgf-repair underscore always on on sun */
  143. X/*:04-24-1992-16:55-wht@n4hgf-dont flunk on >43 lines but use only 43 */
  144. X/*:04-20-1992-20:31-wht@n4hgf-ttymode now no-op until ttyinit called */
  145. X/*:04-20-1992-19:42-wht@n4hgf-kbdtest code in ttygetc messed up-str too short */
  146. X/*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 */
  147. X/*:04-19-1992-02:00-wht@n4hgf-if TERM=ansi with WINDOWID, assume scoterm */
  148. X/*:08-31-1991-13:29-wht@n4hgf2-look for colors in ECULIBDIR too */
  149. X/*:08-30-1991-04:12-wht@n4hgf2-restore colors wrong to do now if not SCO */
  150. X/*:08-30-1991-02:49-aega84!lh-use at_ansi.h/kd.h/CONS_GET under ISC SVR4 */
  151. X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
  152. X/*:08-17-1991-18:29-wht@n4hgf-add kbdtest command */
  153. X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  154. X/*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
  155. X/*:07-10-1991-16:19-wht@n4hgf-improve multi-char func key read timeout */
  156. X/*:03-20-1991-03:07-root@n4hgf-pts driver returns -1 on rdchk success! */
  157. X/*:03-19-1991-21:24-root@n4hgf-METROLINK_X11R4_PTS mods */
  158. X/*:01-29-1991-14:03-wht@n4hgf-more time for ESC vs fkey discrimination */
  159. X/*:01-29-1991-13:44-wht@n4hgf-load colors_normal w/ioctl GIO_ATTR if M_UNIX */
  160. X/*:12-01-1990-14:33-wht@n4hgf-more non-ansi - fkey mapping with nonansi.c */
  161. X/*:11-28-1990-15:56-wht@n4hgf-add non-ansi terminal support */
  162. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  163. X
  164. X#include "ecu.h"
  165. X#include "esd.h"
  166. X#include "ecufkey.h"
  167. X#include "ecukey.h"
  168. X#include "ecuxkey.h"
  169. X#include "ecuerror.h"
  170. X#include "termecu.h"
  171. X
  172. X#include "ecumachdep.h"
  173. X
  174. X#define DEFINE_TTY_DATA
  175. X#include "ecutty.h"
  176. X
  177. Xextern uint tcap_LINES;
  178. Xextern uint tcap_COLS;
  179. Xextern int LINES;
  180. Xextern int COLS;
  181. Xextern char screen_dump_file_name[];
  182. Xextern char *dash_f_funckeytype;
  183. X
  184. Xchar *kde_text();
  185. X
  186. Xuint LINESxCOLS;
  187. Xint current_ttymode = 0;
  188. Xint ttymode_termecu_on_sigint = 0;
  189. Xint tty_is_pty;
  190. Xint tty_is_multiscreen;
  191. Xint tty_is_scoterm;
  192. Xint tty_not_char_special;
  193. Xint tty_use_kbd_sw_flow_control = 1;
  194. Xint use_colors = 0;             /* set by ttyinit, but default no */
  195. Xchar *ttype;                 /* getenv("TERM") */
  196. X
  197. Xstatic int kbd_test_active = 0;
  198. Xstatic int ttyinit_has_been_called = 0;
  199. X
  200. X#if defined(M_SYSV) || defined(SVR4)
  201. Xstatic int got_original_colors = 0;
  202. X
  203. X#endif
  204. X
  205. Xstruct termio tty_termio_at_entry;
  206. Xstruct termio tty_termio_current;
  207. Xstruct stat tty_stat;
  208. Xstruct stat dn;
  209. Xstruct stat tty01;
  210. Xstruct stat ttyp0;
  211. Xstruct stat console;
  212. X
  213. Xuchar kbdeof;                 /* current input EOF */
  214. Xuchar kbdeol2;                 /* current secondary input EOL */
  215. Xuchar kbdeol;                 /* current input EOL */
  216. Xuchar kbderase;                 /* current input ERASE */
  217. Xuchar kbdintr;                 /* current input INTR */
  218. Xuchar kbdkill;                 /* current input KILL */
  219. Xuchar kbdquit;                 /* current input QUIT */
  220. Xint echo_erase_char;         /* save users ECHOE bit */
  221. Xint echo_kill_char;             /* save users ECHOK bit */
  222. Xchar kbd_is_7bit;             /* keyboard has parity */
  223. Xlong tty_escape_timeout = 40L;    /* timeout on waiting for char after ESC */
  224. X
  225. Xuchar *dole_out_tgc_accum = (uchar *) 0;
  226. Xint dole_out_tgc_accum_count = 0;
  227. X
  228. X/*
  229. X * color definitions per format described at top of source
  230. X * we handle SCO XENIX and UNIX and ISC SVR4 but not "MYSYS"
  231. X * (search for MYSYS near top of source for clue what MYSYS means)
  232. X *
  233. X * As of this writing, I don't know about colors on ISC 2.2.
  234. X * but they might be the same as for SVR4.
  235. X *
  236. X */
  237. X#ifdef M_SYSV                 /* SCO */
  238. Xulong colors_initial = 0x04070A00L;    /* default initial colors */
  239. Xulong colors_current = 0x04070A00L;    /* colors set during execution */
  240. Xulong colors_normal = 0x04070A00L;    /* default lt_green/black red/white */
  241. Xulong colors_success = 0x07000A00L;    /* lt_green/black red/white */
  242. Xulong colors_alert = 0x0E000E00L;    /* yellow */
  243. Xulong colors_error = 0x04000400L;    /* red */
  244. Xulong colors_notify = 0x08000800L;    /* gray */
  245. X#define COLORS_DEFINED
  246. X#endif /* M_SYSV */
  247. X
  248. X#if defined(ISCSVR4) || defined(LINUX) || defined(ESIXSVR4)
  249. Xulong colors_initial = 0x00002528L;
  250. Xulong colors_current = 0x00002528L;
  251. Xulong colors_normal = 0x00002528L;    /* white */
  252. Xulong colors_success = 0x00002028L;    /* green */
  253. Xulong colors_alert = 0x00002128L;    /* yellow */
  254. Xulong colors_error = 0x00001F28L;    /* red  */
  255. Xulong colors_notify = 0x00002428L;    /* cyan */
  256. X#define COLORS_DEFINED
  257. X#endif /* ISCSVR4 */
  258. X
  259. X#if 0
  260. Xulong colors_initial = 0x00003740L;
  261. Xulong colors_current = 0x00003740L;
  262. Xulong colors_normal = 0x00003740L;    /* ? */
  263. Xulong colors_success = 0x00003240L;    /* ? */
  264. Xulong colors_alert = 0x00003340L;    /* ? */
  265. Xulong colors_error = 0x00003140L;    /* ? */
  266. Xulong colors_notify = 0x00003640L;    /* ? */
  267. X#define COLORS_DEFINED
  268. X#endif
  269. X
  270. X#if defined(ESIXSVR4) || defined(LINUX)
  271. Xstatic struct color_remapping
  272. X{
  273. X    char *name;
  274. X    char ecu_val;
  275. X    char svr4_val;
  276. X}
  277. Xcolor_remapping[] =
  278. X{
  279. X    {
  280. X        "black", 0, 0x00
  281. X    }
  282. X    ,
  283. X    {
  284. X        "blue", 1, 0x04
  285. X    }
  286. X    ,
  287. X    {
  288. X        "brown", 6, 0x03
  289. X    }
  290. X    ,
  291. X    {
  292. X        "cyan", 3, 0x06
  293. X    }
  294. X    ,
  295. X    {
  296. X        "gray", 8, 0x10
  297. X    }
  298. X    ,
  299. X    {
  300. X        "green", 2, 0x02
  301. X    }
  302. X    ,
  303. X    {
  304. X        "hi_white", 15, 0x17
  305. X    }
  306. X    ,
  307. X    {
  308. X        "lt_blue", 9, 0x14
  309. X    }
  310. X    ,
  311. X    {
  312. X        "lt_cyan", 11, 0x16
  313. X    }
  314. X    ,
  315. X    {
  316. X        "lt_green", 10, 0x12
  317. X    }
  318. X    ,
  319. X    {
  320. X        "lt_magenta", 13, 0x15
  321. X    }
  322. X    ,
  323. X    {
  324. X        "lt_red", 12, 0x11
  325. X    }
  326. X    ,
  327. X    {
  328. X        "magenta", 5, 0x05
  329. X    }
  330. X    ,
  331. X    {
  332. X        "red", 4, 0x01
  333. X    }
  334. X    ,
  335. X    {
  336. X        "white", 7, 0x07
  337. X    }
  338. X    ,
  339. X    {
  340. X        "yellow", 14, 0x13
  341. X    }
  342. X    ,
  343. X    0, 0, 0,
  344. X};
  345. X#endif /* ESIXSVR4 */
  346. X
  347. X#if !defined(COLORS_DEFINED)
  348. Xulong colors_current = 1;     /* dummy */
  349. Xulong colors_normal = 2;     /* dummy */
  350. Xulong colors_initial = 3;     /* dummy */
  351. Xulong colors_success = 4;     /* dummy */
  352. Xulong colors_alert = 5;         /* dummy */
  353. Xulong colors_error = 6;         /* dummy */
  354. Xulong colors_notify = 7;     /* dummy */
  355. X#define COLORS_DEFINED
  356. X#endif /* !COLORS_DEFINED */
  357. X
  358. X/*+-------------------------------------------------------------------------
  359. X    B_to_timeout_msec(c_cflag,st_rdev) - CBAUD code to ESC timeout msec
  360. X--------------------------------------------------------------------------*/
  361. X/*ARGSUSED*/
  362. Xulong
  363. XB_to_timeout_msec(termio_tty, st_rdev)
  364. Xstruct termio *termio_tty;
  365. Xushort st_rdev;
  366. X{
  367. X    long ms = 300L;
  368. X
  369. X    /* make network/xterm/pty sweat, but don't make as many mistakes */
  370. X    if (tty_is_pty)
  371. X        return (ms);
  372. X
  373. X    /* if multiscreen, 3 ticks is pu-lenty */
  374. X    if (tty_is_multiscreen)
  375. X        return ((long)(1000 / hz * 3));
  376. X
  377. X    /* baud rate fiddling */
  378. X    switch (ecugetspeed(termio_tty))
  379. X    {
  380. X            /* char times * time/char */
  381. X        case B110:
  382. X            ms = 10 * 100;
  383. X        case B300:
  384. X            ms = 10 * 33;
  385. X        case B600:
  386. X            ms = 10 * 16;
  387. X        case B1200:
  388. X            ms = 10 * 8;
  389. X        case B2400:
  390. X            ms = 10 * 4;
  391. X        default:             /* many character times for packetized ... */
  392. X            ms = 400L;         /* ... modems used for console */
  393. X    }
  394. X    return (ms);
  395. X
  396. X}                             /* end of B_to_timeout_msec */
  397. X
  398. X/*+-------------------------------------------------------------------------
  399. X    color_name_to_num(cname)
  400. X--------------------------------------------------------------------------*/
  401. Xint
  402. Xcolor_name_to_num(cname)
  403. Xchar *cname;
  404. X{
  405. X    register COLOR *color = colors;
  406. X    register itmp;
  407. X
  408. X    while (color->name)
  409. X    {
  410. X        if ((itmp = strcmp(color->name, cname)) > 0)
  411. X            return (-1);
  412. X        if (!itmp)
  413. X            return (color->num);
  414. X        color++;
  415. X    }
  416. X    return (-1);
  417. X
  418. X}                             /* end of color_name_to_num */
  419. X
  420. X/*+-------------------------------------------------------------------------
  421. X    _setcolor(clrs)
  422. X--------------------------------------------------------------------------*/
  423. Xvoid
  424. X_setcolor(clrs)
  425. Xulong clrs;
  426. X{
  427. X#if defined(ESIXSVR4) || defined(LINUX)
  428. X    struct color_remapping *cr;
  429. X
  430. X#endif
  431. X#if defined(SVR4) || defined(LINUX)
  432. X    char fgcolor;
  433. X    char bgcolor;
  434. X
  435. X#endif /* SVR4 || LINUX */
  436. X
  437. X    if (!use_colors || tty_not_char_special)
  438. X        return;
  439. X
  440. X#if defined(SVR4) || defined(LINUX)
  441. X#if defined(ESIXSVR4) || defined(LINUX)
  442. X    /* set foreground color */
  443. X    fgcolor = (clrs >> 8) & 0xff;
  444. X    for (cr = color_remapping; cr->name; ++cr)
  445. X    {
  446. X        if (fgcolor == cr->ecu_val)
  447. X        {
  448. X            fgcolor = cr->svr4_val;
  449. X            break;
  450. X        }
  451. X    }
  452. X    if (!cr->name)
  453. X    {
  454. X        fgcolor = 0x07;         /* white */
  455. X    }
  456. X    if (fgcolor & 0x10)
  457. X    {
  458. X        fgcolor &= ~0x10;
  459. X        ff(se, "\033[1;3%d;m", fgcolor);
  460. X    }
  461. X    else
  462. X    {
  463. X        ff(se, "\033[0;3%d;m", fgcolor);
  464. X    }
  465. X
  466. X    /* set background color */
  467. X    bgcolor = clrs & 0xff;
  468. X    for (cr = color_remapping; cr->name; ++cr)
  469. X    {
  470. X        if (bgcolor == cr->ecu_val)
  471. X        {
  472. X            bgcolor = cr->svr4_val;
  473. X            break;
  474. X        }
  475. X    }
  476. X    if (!cr->name)
  477. X    {
  478. X        bgcolor = 0x00;         /* black */
  479. X    }
  480. X    if (bgcolor & 0x10)
  481. X    {
  482. X        bgcolor &= ~0x10;
  483. X        ff(se, "\033[5;3%d;m", bgcolor);
  484. X    }
  485. X    else
  486. X    {
  487. X        ff(se, "\033[0;3%d;m", bgcolor);
  488. X    }
  489. X#else /* ISC SVR4 */
  490. X    /* normal */
  491. X    fgcolor = (clrs >> 8) & 0xff;
  492. X    bgcolor = clrs & 0xff;
  493. X    ff(se, "\033[%d;%dm", fgcolor, bgcolor);
  494. X#endif /* ESIXSVR4 */
  495. X#else /* not any SVR4 */
  496. X#ifdef M_SYSV                 /* SCO */
  497. X    /* normal */
  498. X    ff(se, "\033[=%ldF\033[=%ldG", (clrs >> 8) & 0xFF, clrs & 0xFF);
  499. X
  500. X    /* reverse */
  501. X    ff(se, "\033[=%ldH\033[=%ldI", (clrs >> 24) & 0xFF, (clrs >> 16) & 0xFF);
  502. X#endif /* M_SYSV */
  503. X#endif /* SVR4 */
  504. X    colors_current = clrs;
  505. X}                             /* end of _setcolor */
  506. X
  507. X/*+-------------------------------------------------------------------------
  508. X    setcolor(new_colors)
  509. X
  510. Xrequires termcap init to have been done
  511. X--------------------------------------------------------------------------*/
  512. Xvoid
  513. Xsetcolor(new_colors)
  514. Xulong new_colors;
  515. X{
  516. X    if (tty_not_char_special)
  517. X        return;
  518. X
  519. X    if (!use_colors)
  520. X    {
  521. X        if (new_colors == colors_notify)
  522. X            tcap_underscore_on();
  523. X        else if (new_colors == colors_alert)
  524. X            tcap_bold_on();
  525. X        else if (new_colors == colors_error)
  526. X            tcap_stand_out();
  527. X#ifdef WHT
  528. X        else if (new_colors == colors_success)
  529. X        {
  530. X            tcap_underscore_on();
  531. X            tcap_bold_on();
  532. X        }
  533. X#endif
  534. X        else
  535. X        {
  536. X            tcap_underscore_off();
  537. X            tcap_bold_off();
  538. X            tcap_stand_end();
  539. X        }
  540. X        return;
  541. X    }
  542. X    _setcolor(new_colors);
  543. X#ifndef LINUX
  544. X    tcap_stand_end();
  545. X#endif
  546. X}                             /* end of setcolor */
  547. X
  548. X/*+-------------------------------------------------------------------------
  549. X    setcolor_internal(ntokens,tokens)
  550. X
  551. Xreturns 0 on success, else token number in error + 1
  552. X--------------------------------------------------------------------------*/
  553. Xint
  554. Xsetcolor_internal(ntokens, tokens)
  555. Xint ntokens;
  556. Xchar **tokens;
  557. X{
  558. X    ulong fgnd;
  559. X    ulong bgnd;
  560. X
  561. X    if (tty_not_char_special || !use_colors)
  562. X        return (0);
  563. X
  564. X    if (ntokens < 2)
  565. X        return (1);
  566. X    else if (ntokens == 2)
  567. X        tokens[2] = "black";
  568. X
  569. X    if ((fgnd = (ulong) color_name_to_num(tokens[1])) > 15)
  570. X        return (2);
  571. X    if ((bgnd = (ulong) color_name_to_num(tokens[2])) > 15)
  572. X        return (3);
  573. X
  574. X    if (!strcmp(tokens[0], "normal"))
  575. X    {
  576. X        colors_normal &= 0xFFFF0000L;
  577. X        colors_normal |= (fgnd << 8) | bgnd;
  578. X        setcolor(colors_normal);
  579. X    }
  580. X    else if (!strcmp(tokens[0], "reverse"))
  581. X    {
  582. X        colors_normal &= 0x0000FFFFL;
  583. X        colors_normal |= (fgnd << 24) | (bgnd << 16);
  584. X        setcolor(colors_normal);
  585. X    }
  586. X    else if (!strcmp(tokens[0], "notify"))
  587. X        colors_notify = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  588. X    else if (!strcmp(tokens[0], "success"))
  589. X        colors_success = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  590. X    else if (!strcmp(tokens[0], "alert"))
  591. X        colors_alert = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  592. X    else if (!strcmp(tokens[0], "error"))
  593. X        colors_error = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
  594. X    else
  595. X        return (1);
  596. X
  597. X    return (0);
  598. X
  599. X}                             /* end of setcolor_internal */
  600. X
  601. X/*+-------------------------------------------------------------------------
  602. X    restore_initial_colors() - make screen safe
  603. X
  604. XOn SCO, restore color choices at execution time if we successfully
  605. Xgot them from the driver; in other situations, use tcap to reset.
  606. X--------------------------------------------------------------------------*/
  607. Xvoid
  608. Xrestore_initial_colors()
  609. X{
  610. X#if defined(M_SYSV) || defined(SVR4)
  611. X    if (use_colors && got_original_colors)
  612. X        setcolor(colors_initial);
  613. X    else
  614. X#endif
  615. X    {
  616. X        tcap_blink_off();
  617. X        tcap_bold_off();
  618. X        tcap_underscore_off();
  619. X    }
  620. X}                             /* end of restore_initial_colors */
  621. X
  622. X/*+-------------------------------------------------------------------------
  623. X    get_initial_colors() - read colors at time of execution from driver
  624. X
  625. X     00000000001111111111222222222233
  626. X     01234567890123456789012345678901
  627. X     0000|--|0000|--|0000|--|0000|--|
  628. X          fg      bk      fg      bk
  629. X           reverse      normal
  630. X
  631. X--------------------------------------------------------------------------*/
  632. X#if defined(M_SYSV)
  633. Xvoid
  634. Xget_initial_colors()
  635. X{
  636. X    uint cur_attr;
  637. X    ulong fgnd;
  638. X    ulong bgnd;
  639. X
  640. X    colors_initial = colors_normal;    /* scoterm can use color but ... */
  641. X    if (ioctl(TTYIN, GIO_ATTR, 0) == -1)    /* ... GIO_ATTR won't work */
  642. X        return;
  643. X    colors_normal = 0L;
  644. X
  645. X/*
  646. X * first, reverse, so we can end up with normal colors selected
  647. X */
  648. X    write(1, "\033[7m", 4);     /* select reverse */
  649. X    cur_attr = (uint) ioctl(TTYIN, GIO_ATTR, 0);
  650. X    fgnd = (ulong) cur_attr & 0x0F;
  651. X    bgnd = (ulong) (cur_attr >> 4) & 0x0F;
  652. X    colors_normal |= (fgnd << 24) | (bgnd << 16);
  653. X
  654. X/*
  655. X * now, normal
  656. X */
  657. X    write(1, "\033[m", 3);     /* select normal */
  658. X    cur_attr = (uint) ioctl(TTYIN, GIO_ATTR, 0);
  659. X    fgnd = (ulong) cur_attr & 0x0F;
  660. X    bgnd = (ulong) (cur_attr >> 4) & 0x0F;
  661. X    colors_normal |= (fgnd << 8) | bgnd;
  662. X
  663. X    colors_initial = colors_normal;    /* save for restore_initial_colors */
  664. X    got_original_colors = 1;
  665. X
  666. X}                             /* end of get_initial_colors */
  667. X#endif
  668. X
  669. X/*+-------------------------------------------------------------------------
  670. X    read_colors_file() - read color definition if present
  671. X--------------------------------------------------------------------------*/
  672. Xvoid
  673. Xread_colors_file()
  674. X{
  675. X    FILE *fp;
  676. X    char s128[128];
  677. X
  678. X#define MAX_COLOR_TOKENS 6
  679. X    char *tokens[MAX_COLOR_TOKENS];
  680. X    int ntokens;
  681. X    char *cptr;
  682. X    int itmp;
  683. X
  684. X    if (tty_not_char_special)
  685. X        return;
  686. X
  687. X#if defined(M_SYSV)
  688. X    get_initial_colors();
  689. X#endif
  690. X
  691. X    get_home_dir(s128);
  692. X    strcat(s128, "/.ecu/colors");
  693. X
  694. X    if (!(fp = fopen(s128, "r")))
  695. X    {
  696. X        strcpy(s128, eculibdir);
  697. X        strcat(s128, "/colors");
  698. X        if (!(fp = fopen(s128, "r")))
  699. X            return;
  700. X    }
  701. X
  702. X    while (fgets(s128, sizeof(s128), fp))
  703. X    {
  704. X        if (itmp = strlen(s128))    /* itmp = len; if > 0 ... */
  705. X        {
  706. X            itmp--;
  707. X            s128[itmp] = 0;     /* ... strip trailing NL */
  708. X        }
  709. X        if (cptr = strchr(s128, '#'))    /* comment? */
  710. X            *cptr = 0;
  711. X        cptr = s128;         /* first call to str_token, -> buff */
  712. X        while ((*cptr == 0x20) || (*cptr == TAB))
  713. X            cptr++;             /* strip leading spaces */
  714. X        if (*cptr == 0)         /* if line all blank, skip it */
  715. X            continue;
  716. X
  717. X        build_arg_array(s128, tokens, MAX_COLOR_TOKENS, &ntokens);
  718. X        if (ntokens < 2)
  719. X            continue;
  720. X
  721. X        setcolor_internal(ntokens, tokens);
  722. X
  723. X    }                         /* while records left to ready */
  724. X
  725. X#if defined(M_SYSV)
  726. X    if (ioctl(TTYIN, GIO_ATTR, 0) == -1)
  727. X        colors_initial = colors_normal;    /* hack for scoterm */
  728. X#endif
  729. X
  730. X    fclose(fp);
  731. X}                             /* end of read_colors_file */
  732. X
  733. X/*+-------------------------------------------------------------------------
  734. X    ring_bell()
  735. X--------------------------------------------------------------------------*/
  736. Xvoid
  737. Xring_bell()
  738. X{
  739. X    char b = BEL;
  740. X
  741. X    if (tty_not_char_special)
  742. X        return;
  743. X    write(TTYOUT, &b, 1);
  744. X
  745. X}                             /* end of ring_bell */
  746. X
  747. X/*+-------------------------------------------------------------------------
  748. X    termio_to_kbd_chars()
  749. X--------------------------------------------------------------------------*/
  750. Xvoid
  751. Xtermio_to_kbd_chars()
  752. X{
  753. X    kbdintr = (tty_termio_at_entry.c_cc[VINTR])
  754. X    ? (tty_termio_at_entry.c_cc[VINTR] & 0x7F) : '\377';
  755. X    kbdquit = (tty_termio_at_entry.c_cc[VQUIT])
  756. X        ? (tty_termio_at_entry.c_cc[VQUIT] & 0x7F) : '\377';
  757. X    kbderase = (tty_termio_at_entry.c_cc[VERASE])
  758. X        ? (tty_termio_at_entry.c_cc[VERASE] & 0x7F) : '\377';
  759. X    kbdkill = (tty_termio_at_entry.c_cc[VKILL])
  760. X        ? (tty_termio_at_entry.c_cc[VKILL] & 0x7F) : '\377';
  761. X    kbdeof = (tty_termio_at_entry.c_cc[VEOF])
  762. X        ? (tty_termio_at_entry.c_cc[VEOF] & 0x7F) : '\04';
  763. X    kbdeol2 = (tty_termio_at_entry.c_cc[VEOL])
  764. X        ? (tty_termio_at_entry.c_cc[VEOL] & 0x7F) : '\377';
  765. X    kbdeol = (tty_termio_at_entry.c_iflag & ICRNL)
  766. X        ? '\r' : '\n';
  767. X
  768. X    kbd_is_7bit = ((tty_termio_at_entry.c_cflag & PARENB) != 0);
  769. X    echo_erase_char = tty_termio_at_entry.c_lflag & ECHOE;
  770. X    echo_kill_char = tty_termio_at_entry.c_lflag & ECHOK;
  771. X
  772. X}                             /* end of termio_to_kbd_chars */
  773. X
  774. X/*+-------------------------------------------------------------------------
  775. X    ttyinit(param)
  776. X--------------------------------------------------------------------------*/
  777. Xvoid
  778. Xttyinit(param)
  779. Xuchar param;
  780. X{
  781. X    int fddevtty;
  782. X    int itmp;
  783. X    char *ftype;
  784. X
  785. X#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)
  786. X    int monitor_type;
  787. X    int cons_get_err;
  788. X
  789. X#endif
  790. X
  791. X    ttype = getenv("TERM");     /* must do this first */
  792. X
  793. X    /*
  794. X     * get control tty control chars in case stdin not tty
  795. X     */
  796. X    if ((fddevtty = open("/dev/tty", O_RDONLY, 0)) >= 0)
  797. X    {
  798. X        ecugetattr(fddevtty, &tty_termio_at_entry);
  799. X        close(fddevtty);
  800. X        termio_to_kbd_chars();
  801. X    }
  802. X
  803. X    sigint = 0;                 /* see xmtr signal handlers */
  804. X
  805. X    memset((char *)&tty_stat, 0xFF, sizeof(struct stat));
  806. X    memset((char *)&ttyp0, 0xFF, sizeof(struct stat));
  807. X    memset((char *)&console, 0xFF, sizeof(struct stat));
  808. X
  809. X    stat("/dev/console", &console);
  810. X    stat("/dev/null", &dn);
  811. X    stat("/dev/tty01", &tty01);
  812. X    stat("/dev/ttyp0", &ttyp0);
  813. X
  814. X    /*
  815. X     * if stdin not open or is /dev/null or is non-character-device
  816. X     */
  817. X
  818. X    itmp = fstat(TTYIN, &tty_stat);
  819. X    if (itmp || ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
  820. X        ((dn.st_ino == tty_stat.st_ino) && (dn.st_rdev == tty_stat.st_rdev)))
  821. X    {
  822. X        tcap_LINES = LINES = 25;    /* fake necessary termcap/curses vars */
  823. X        tcap_COLS = COLS = 80;
  824. X        LINESxCOLS = tcap_LINES * tcap_COLS;
  825. X        shm->scr_lines = tcap_LINES;
  826. X        shm->scr_cols = tcap_COLS;
  827. X        shm->scr_size = LINESxCOLS;
  828. X
  829. X        tty_not_char_special = 1;
  830. X        tty_is_multiscreen = 0;
  831. X        return;
  832. X    }
  833. X
  834. X    /*
  835. X     * if pty
  836. X     */
  837. X    if ((tty_stat.st_rdev & 0xFF00) == (ttyp0.st_rdev & 0xFF00))
  838. X        tty_is_pty = 1;
  839. X
  840. X    /*
  841. X     * use color if we are on a display that supports it and we know how
  842. X     * :-|
  843. X     */
  844. X    use_colors = 0;
  845. X
  846. X#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)
  847. X    if (((cons_get_err = ioctl(TTYIN, CONS_GET, &monitor_type)) >= 0) &&
  848. X        (use_colors = (monitor_type != MONO)))
  849. X    {
  850. X        read_colors_file();
  851. X        setcolor(colors_normal);
  852. X    }
  853. X
  854. X#endif /* CONS_GET && MONO && USE_COLOR */
  855. X
  856. X    /*
  857. X     * remember whether or not we are on a multiscreen
  858. X     */
  859. X#ifdef LINUX
  860. X    tty_is_multiscreen = 1;
  861. X    use_colors = 1;
  862. X    tty_not_char_special = 0;
  863. X    read_colors_file();
  864. X    setcolor(colors_normal);
  865. X#endif
  866. X#if defined(M_SYSV)             /* for multiscreen and scoterm */
  867. X    tty_is_multiscreen = !(cons_get_err < 0);
  868. X
  869. X    /*
  870. X     * a fuzzy heuristic for scoterm: 1. presence of WINDOWID and 2. first
  871. X     * four characters of $TERM == "ansi"
  872. X     */
  873. X    if (getenv("WINDOWID") && ttype && !strncmp(ttype, "ansi", 4))
  874. X    {
  875. X        use_colors = 1;
  876. X        tty_is_scoterm = 1;
  877. X        read_colors_file();
  878. X        setcolor(colors_normal);
  879. X    }
  880. X#endif /* M_SYSV multiscreen and scoterm */
  881. X
  882. X    /*
  883. X     * save initial tty state
  884. X     */
  885. X    ecugetattr(TTYIN, &tty_termio_at_entry);
  886. X    tty_escape_timeout =
  887. X        B_to_timeout_msec(&tty_termio_at_entry, tty_stat.st_rdev);
  888. X
  889. X    termio_to_kbd_chars();
  890. X
  891. X    tty_termio_current = tty_termio_at_entry;
  892. X    current_ttymode = 0;
  893. X
  894. X    get_home_dir(screen_dump_file_name);
  895. X    strcat(screen_dump_file_name, "/.ecu/screen.dump");
  896. X
  897. X    ftype = 0;
  898. X    if (dash_f_funckeytype)
  899. X        ftype = dash_f_funckeytype;
  900. X    else
  901. X        ftype = getenv("ECUFUNCKEY");
  902. X#ifdef WHT
  903. X    if (!ftype && !strcmp(ttype, "vt100"))
  904. X        ftype = "rterm";
  905. X#endif
  906. X    if (ttype || ftype)
  907. X        funckeymap_read((ftype) ? ftype : ttype);
  908. X
  909. X    /* initialize termcap */
  910. X    tcap_init();             /* read termcap strings */
  911. X
  912. X    /* yetch - magic number gretching for lines and columns */
  913. X    if (tcap_LINES < 20)
  914. X    {
  915. X        ff(se, "\7screen height must be >= 20 lines (found %dx%d).\r\n",
  916. X            tcap_COLS, tcap_LINES);
  917. X        termecu(TERMECU_GEOMETRY);
  918. X    }
  919. X    if (tcap_LINES > SCREEN_LINES_MAX)
  920. X    {
  921. X        ff(se, "\7screen height limited to %d lines (found %dx%d).\r\n",
  922. X            SCREEN_LINES_MAX, tcap_COLS, tcap_LINES);
  923. X        termecu(TERMECU_GEOMETRY);
  924. X    }
  925. X    if (tcap_COLS != SCREEN_COLS_MAX)
  926. X    {
  927. X        ff(se, "\7terminal width must be %d columns (found %dx%d).\r\n",
  928. X            SCREEN_COLS_MAX, tcap_COLS, tcap_LINES);
  929. X        termecu(TERMECU_GEOMETRY);
  930. X    }
  931. X    LINESxCOLS = tcap_LINES * tcap_COLS;
  932. X    shm->scr_lines = tcap_LINES;
  933. X    shm->scr_cols = tcap_COLS;
  934. X    shm->scr_size = LINESxCOLS;
  935. X    ttyinit_has_been_called = 1;
  936. X
  937. X}                             /* end of ttyinit */
  938. X
  939. X/*+-----------------------------------------------------------------------
  940. X    ttymode(arg) -- control user console (kbd/screen)
  941. X
  942. X  Where arg ==
  943. X    0 restore attributes saved at start of execution
  944. X    1 raw mode (send xon/xoff, but do not respond to it, no ISIG/SIGINT)
  945. X    2 raw mode (same as 1 but allow keyboard interrupts)
  946. X    3 same as 2 but terminate program on SIGINT
  947. X    4 terminate ecu on sigint
  948. X
  949. X------------------------------------------------------------------------*/
  950. Xvoid
  951. Xttymode(arg)
  952. Xint arg;
  953. X{
  954. X
  955. X    /*
  956. X     * ignore if no keyboard involved
  957. X     */
  958. X    if (tty_not_char_special)
  959. X        return;
  960. X
  961. X    /*
  962. X     * usage()->termecu()->ttymode() is possible before ttyinit()
  963. X     */
  964. X    if (!ttyinit_has_been_called)
  965. X        return;
  966. X
  967. X    switch (arg)
  968. X    {
  969. X        case 0:
  970. X            ecusetattr(TTYIN, TCSETAW, &tty_termio_at_entry);
  971. X            tty_termio_current = tty_termio_at_entry;
  972. X            current_ttymode = 0;
  973. X            ttymode_termecu_on_sigint = 0;
  974. X            break;
  975. X
  976. X        case 1:
  977. X        case 2:
  978. X        case 3:
  979. X        case 4:
  980. X            tty_termio_current = tty_termio_at_entry;
  981. X
  982. X            tty_termio_current.c_cflag &= ~(PARENB | PARODD);
  983. X            tty_termio_current.c_cflag |= CS8;
  984. X
  985. X            /* don't want to honor tty xon/xoff, but pass to other end */
  986. X#if defined(CFG_TermiosLineio)
  987. X            tty_termio_current.c_iflag &= ~(INLCR | ICRNL | IGNCR | ISTRIP);
  988. X            tty_termio_current.c_oflag &= ~(ONLCR);
  989. X#else
  990. X            tty_termio_current.c_iflag &= ~(INLCR | ICRNL | IGNCR | IUCLC | ISTRIP);
  991. X            tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
  992. X#endif
  993. X            tty_termio_current.c_oflag |= OPOST;
  994. X
  995. X            if (tty_use_kbd_sw_flow_control)
  996. X                tty_termio_current.c_iflag |= IXON | IXOFF;
  997. X            else
  998. X                tty_termio_current.c_iflag &= ~(IXON | IXOFF);
  999. X
  1000. X            tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
  1001. X            if (arg > 1)
  1002. X                tty_termio_current.c_lflag |= ISIG;
  1003. X
  1004. X            tty_termio_current.c_cc[VMIN] = 1;
  1005. X            tty_termio_current.c_cc[VTIME] = 0;
  1006. X
  1007. X            ecusetattr(TTYIN, TCSETAW, &tty_termio_current);
  1008. X            current_ttymode = arg;
  1009. X            ttymode_termecu_on_sigint = (arg == 4);
  1010. X            break;
  1011. X
  1012. X        default:
  1013. X            ff(se, "\r\nttymode: invalid argument %d\r\n", arg);
  1014. X            break;
  1015. X    }
  1016. X
  1017. X}                             /* end of ttymode */
  1018. X
  1019. X/*+-------------------------------------------------------------------------
  1020. X    int    get_ttymode()
  1021. X--------------------------------------------------------------------------*/
  1022. Xint
  1023. Xget_ttymode()
  1024. X{
  1025. X    return (current_ttymode);
  1026. X}                             /* end of get_ttymode */
  1027. X
  1028. X/*+-----------------------------------------------------------------------
  1029. X    ttyflush(flush_type) -- flush tty driver input &/or output buffers
  1030. X
  1031. X0 == input buffer
  1032. X1 == output buffer
  1033. X2 == both buffers
  1034. X------------------------------------------------------------------------*/
  1035. Xvoid
  1036. Xttyflush(flush_type)
  1037. Xint flush_type;
  1038. X{
  1039. X    if (tty_not_char_special)
  1040. X        return;
  1041. X
  1042. X    ecuflow(TTYIN, TCOOFF);
  1043. X
  1044. X#if !defined(M_I286)
  1045. X    ecuflush(TTYIN, flush_type);
  1046. X#else
  1047. X    /* avoid 286 compiler warning of cast int to far ptr */
  1048. X    switch (flush_type)
  1049. X    {
  1050. X        case 0:
  1051. X            ioctl(TTYIN, TCFLSH, (char *)0);
  1052. X            break;
  1053. X        case 1:
  1054. X            ioctl(TTYIN, TCFLSH, (char *)1);
  1055. X            break;
  1056. X        case 2:
  1057. X            ioctl(TTYIN, TCFLSH, (char *)2);
  1058. X            break;
  1059. X    }
  1060. X#endif
  1061. X
  1062. X    ecuflow(TTYIN, TCOON);
  1063. X
  1064. X    if (flush_type != 1)
  1065. X    {
  1066. X        dole_out_tgc_accum = (uchar *) 0;
  1067. X        dole_out_tgc_accum_count = 0;
  1068. X    }
  1069. X
  1070. X}                             /* end of ttyflush */
  1071. X
  1072. X/*+-------------------------------------------------------------------------
  1073. X    ttyrdchk() - see if key pressed and not read
  1074. X--------------------------------------------------------------------------*/
  1075. Xint
  1076. Xttyrdchk()
  1077. X{
  1078. X    return (rdchk(TTYIN) || dole_out_tgc_accum_count);
  1079. X}                             /* end of ttyrdchk */
  1080. X
  1081. X/*+-------------------------------------------------------------------------
  1082. X    ttygetc(xkey_ok) -- get a key from the keyboard
  1083. Xif UNIX or XENIX, map extended keys to sign-bit-set special value
  1084. Xif xkey_ok is 0, disallow extended keys
  1085. X--------------------------------------------------------------------------*/
  1086. Xuint
  1087. Xttygetc(xkey_ok)
  1088. Xint xkey_ok;
  1089. X{
  1090. X    uchar ctmp;
  1091. X    extern int errno;
  1092. X    register uint itmp = 0;
  1093. X    long timeout_remaining;
  1094. X    static uchar tgc_accum[16];
  1095. X    uchar funckeymap();
  1096. X
  1097. X    if (tty_not_char_special)/* this really is unexplored territory */
  1098. X    {
  1099. X        ctmp = 255;
  1100. X        read(TTYIN, (char *)&ctmp, 1);
  1101. X        return ((uint) ctmp);
  1102. X    }
  1103. X
  1104. X    if (dole_out_tgc_accum_count)
  1105. X    {
  1106. X        ctmp = *dole_out_tgc_accum++;
  1107. X        dole_out_tgc_accum_count--;
  1108. X        if (kbd_is_7bit)
  1109. X            ctmp &= 0x7F;
  1110. X        return ((uint) ctmp);
  1111. X    }
  1112. X
  1113. X  GET_KEY:
  1114. X    errno = 0;
  1115. X    if (read(TTYIN, (char *)&ctmp, 1) < 0)
  1116. X    {
  1117. X        if (errno == EINTR)
  1118. X            goto GET_KEY;
  1119. X        perror_errmsg("keyboard");
  1120. X        termecu(TERMECU_TTYIN_READ_ERROR);
  1121. X    }
  1122. X
  1123. X    if (((ctmp >= 0x01) && (ctmp <= 0x1F) ||
  1124. X            (ctmp >= 0x81) && (ctmp <= 0x9F)) &&
  1125. X        (ctmp != kbderase) && (ctmp != kbdkill) &&
  1126. X        (ctmp != kbdeol) && (ctmp != kbdeol2) &&
  1127. X        (ctmp != kbdintr) && (ctmp != kbdeof))
  1128. X    {
  1129. X        tgc_accum[0] = ctmp;
  1130. X        tgc_accum[itmp = 1] = 0;
  1131. X        timeout_remaining = tty_escape_timeout;
  1132. X#if defined(NAP_DEBUG)
  1133. X        ff(se, "timeout_remaining = %ld hzmsec=%ld\r\n",
  1134. X            timeout_remaining, hzmsec);
  1135. X#endif
  1136. X        while (((ctmp = funckeymap(tgc_accum, itmp)) >= XF_no_way) &&
  1137. X            (timeout_remaining > 0))
  1138. X        {
  1139. X            timeout_remaining -= Nap(hzmsec);
  1140. X#if defined(NAP_DEBUG)
  1141. X            ff(se, "timeout_remaining = %ld\r\n", timeout_remaining);
  1142. X#endif
  1143. X            if (!rdchk(TTYIN))
  1144. X                continue;
  1145. X            read(TTYIN, (char *)&ctmp, 1);
  1146. X            if (itmp == (sizeof(tgc_accum) - 1))    /* do not allow overflow */
  1147. X            {
  1148. X                ctmp = XF_no_way;
  1149. X                break;
  1150. X            }
  1151. X            timeout_remaining = tty_escape_timeout;
  1152. X            tgc_accum[itmp++] = ctmp;
  1153. X        }
  1154. X        tgc_accum[itmp] = 0;
  1155. X        if ((ctmp == XF_not_yet) && (itmp == 1))
  1156. X        {
  1157. X            if (kbd_is_7bit)
  1158. X                tgc_accum[0] &= 0x7F;
  1159. X            return ((uint) tgc_accum[0]);
  1160. X        }
  1161. X        else if (ctmp < XF_no_way)    /* if we got a map */
  1162. X        {
  1163. X            if (kbd_test_active)
  1164. X            {
  1165. X                char title[128];
  1166. X
  1167. X                sprintf(title, "--> func key '%s' (%d key codes received)",
  1168. X                    kde_text(ctmp), itmp);
  1169. X                hex_dump(tgc_accum, -itmp, title, 1);
  1170. X            }
  1171. X            if (!xkey_ok)
  1172. X            {
  1173. X                ring_bell();
  1174. X                goto GET_KEY;
  1175. X            }
  1176. X            switch (ctmp)
  1177. X            {
  1178. X                case IKDE_CU5:
  1179. X                    screen_dump(screen_dump_file_name);
  1180. X                    goto GET_KEY;
  1181. X                default:
  1182. X                    return ((uint) ikde_to_xf(ctmp));
  1183. X            }
  1184. X            /* NOTREACHED */
  1185. X        }
  1186. X        /* not func key -- must be typamatic control key */
  1187. X        if (kbd_test_active)
  1188. X        {
  1189. X            char title[128];
  1190. X
  1191. X            if (itmp > 1)
  1192. X            {
  1193. X                sprintf(title,
  1194. X                    "--> no func key recognized (%d key codes received)",
  1195. X                    itmp);
  1196. X                hex_dump(tgc_accum, -itmp, title, 1);
  1197. X            }
  1198. X        }
  1199. X        dole_out_tgc_accum_count = itmp - 1;
  1200. X        dole_out_tgc_accum = tgc_accum + 1;
  1201. X        if (kbd_is_7bit)
  1202. X            tgc_accum[0] &= 0x7F;
  1203. X        return ((uint) tgc_accum[0]);
  1204. X    }
  1205. X
  1206. X    /*
  1207. X     * simple key, not special
  1208. X     */
  1209. X    ctmp &= 0x7F;
  1210. X
  1211. X#if 0                         /* not necessary I think, but leave marker
  1212. X                              * for further if wrong --wht */
  1213. X#ifdef LINUX
  1214. X    /* make backspace key really backspace */
  1215. X    if (ctmp == kbderase)
  1216. X        ctmp = 0x08;
  1217. X#endif /* LINUX */
  1218. X#endif
  1219. X
  1220. X    return ((uint) ctmp);
  1221. X
  1222. X}                             /* end if ttygetc */
  1223. X
  1224. X/*+-----------------------------------------------------------------------
  1225. X    ttygets(str,maxsize,flags,delim,pstrpos)
  1226. X
  1227. Xflags & TG_CRLF   - echo cr/lf terminator
  1228. Xflags & TG_XDELIM - extended delimiter set
  1229. X                    (Home, End, PgUp, PgDn, CurUp, CurDn)
  1230. Xflags & TG_EDIT   - redisplay/edit current string
  1231. Xflags & TG_IPOS   - if edit, use initial string pos
  1232. X------------------------------------------------------------------------*/
  1233. Xvoid
  1234. Xttygets(str, maxsize, flags, delim, pstrpos)
  1235. Xregister char *str;
  1236. Xint maxsize;
  1237. Xint flags;
  1238. Xuchar *delim;
  1239. Xint *pstrpos;
  1240. X{
  1241. X    register inch;
  1242. X    char ch;
  1243. X    int strcount = 0;
  1244. X    int strpos = 0;
  1245. X    int insert_mode = 0;
  1246. X    char *bs_str = "\010 \010";
  1247. X
  1248. X    --maxsize;                 /* decrement for safety */
  1249. X
  1250. X    if (flags & TG_EDIT)
  1251. X    {
  1252. X        strpos = strcount = strlen(str);
  1253. X        write(TTYOUT, str, strcount);
  1254. X        if (pstrpos && (*pstrpos > 0) && (*pstrpos <= strcount))
  1255. X            strpos = *pstrpos;
  1256. X        tcap_curleft(strcount - strpos);
  1257. X    }
  1258. X
  1259. X    while (1)
  1260. X    {
  1261. X        inch = ttygetc(1);
  1262. X        *delim = (uchar) inch;    /* last char will always be the delimiter */
  1263. X        if ((inch == kbdintr) || (inch == ESC))
  1264. X        {
  1265. X            tcap_curright(strcount - strpos);
  1266. X            while (strcount)
  1267. X            {
  1268. X                write(TTYOUT, bs_str, strlen(bs_str));
  1269. X                strcount--;
  1270. X            }
  1271. X            str[strcount] = 0;
  1272. X            *delim = ESC;
  1273. X            goto FUNC_RETURN;
  1274. X        }
  1275. X        else if (inch == kbdkill)
  1276. X        {
  1277. X            tcap_curright(strcount - strpos);
  1278. X            while (strcount)
  1279. X            {
  1280. X                write(TTYOUT, bs_str, strlen(bs_str));
  1281. X                strcount--;
  1282. X            }
  1283. X            strpos = 0;
  1284. X            *str = 0;
  1285. X            continue;
  1286. X        }
  1287. X        else if (inch == kbderase)
  1288. X        {
  1289. X            if (strcount)
  1290. X            {
  1291. X                if (strcount == strpos)
  1292. X                {
  1293. X                    write(TTYOUT, bs_str, strlen(bs_str));
  1294. X                    strcount--, strpos--;
  1295. X                }
  1296. X                else
  1297. X                {
  1298. X                    if (!strpos)
  1299. X                        continue;
  1300. X                    mem_cpy(str + strpos - 1, str + strpos, strcount - strpos);
  1301. X                    write(TTYOUT, "\010", 1);
  1302. X                    str[--strcount] = 0;
  1303. X                    strpos--;
  1304. X                    write(TTYOUT, str + strpos, strlen(str + strpos));
  1305. X                    write(TTYOUT, " ", 1);
  1306. X                    tcap_curleft(strcount - strpos + 1);
  1307. X                }
  1308. X            }
  1309. X            str[strcount] = 0;
  1310. X            continue;
  1311. X        }
  1312. X        else if (inch == XFins)
  1313. X        {
  1314. X            insert_mode = !insert_mode;
  1315. X            continue;
  1316. X        }
  1317. X        else if (inch == XFcurlf)
  1318. X        {
  1319. X            if (strpos)
  1320. X            {
  1321. X                strpos--;
  1322. X                tcap_curleft(1);
  1323. X            }
  1324. X            continue;
  1325. X        }
  1326. X        else if (inch == XFcurrt)
  1327. X        {
  1328. X            if (strpos < strcount)
  1329. X            {
  1330. X                strpos++;
  1331. X                tcap_curright(1);
  1332. X            }
  1333. X            continue;
  1334. X        }
  1335. X
  1336. X        if (flags & TG_XDELIM)    /* extended delimiter */
  1337. X        {
  1338. X            switch (inch)
  1339. X            {
  1340. X                case XFhome:
  1341. X                case XFend:
  1342. X                case XFpgup:
  1343. X                case XFpgdn:
  1344. X                case XFcurup:
  1345. X                case XFcurdn:
  1346. X#ifdef notdef
  1347. X                    tcap_curright(strcount - strpos);
  1348. X                    while (strcount)
  1349. X                    {
  1350. X                        write(TTYOUT, bs_str, strlen(bs_str));
  1351. X                        strcount--;
  1352. X                    }
  1353. X#endif
  1354. X                    str[strcount] = 0;
  1355. X                    goto FUNC_RETURN;
  1356. X            }
  1357. X        }
  1358. X
  1359. X        switch (inch)
  1360. X        {
  1361. X            case CRET:
  1362. X                *delim = NL;
  1363. X            case NL:
  1364. X                str[strcount] = 0;
  1365. X                tcap_curright(strcount - strpos);
  1366. X                if ((flags & TG_CRLF))
  1367. X                    ff(se, "\r\n");
  1368. X                goto FUNC_RETURN;
  1369. X
  1370. X            case CTL_L:
  1371. X            case CTL_R:
  1372. X                tcap_curright(strcount - strpos);
  1373. X                ff(se, "%s (insert mode %s)\r\n", make_char_graphic(inch, 0),
  1374. X                    (insert_mode) ? "ON" : "OFF");
  1375. X                tcap_eeol();
  1376. X                write(TTYOUT, str, strcount);
  1377. X                tcap_curleft(strcount - strpos);
  1378. X                break;
  1379. X
  1380. X            default:
  1381. X                if ((inch < SPACE) || (inch >= 0x7F))
  1382. X                {
  1383. X                    ring_bell();
  1384. X                    break;
  1385. X                }
  1386. X                if (strpos == strcount)
  1387. X                {
  1388. X                    if (strcount == maxsize)
  1389. X                    {
  1390. X                        ring_bell();
  1391. X                        continue;
  1392. X                    }
  1393. X                    str[strcount++] = inch;
  1394. X                    strpos++;
  1395. X                    ch = (char)inch;
  1396. X                    write(TTYOUT, &ch, 1);
  1397. X                }
  1398. X                else
  1399. X                {
  1400. X                    if (insert_mode)
  1401. X                    {
  1402. X                        if (strcount == maxsize)
  1403. X                        {
  1404. X                            ring_bell();
  1405. X                            continue;
  1406. X                        }
  1407. X                        mem_cpy(str + strpos + 1, str + strpos, strcount - strpos);
  1408. X                        str[strpos] = inch;
  1409. X                        strcount++;
  1410. X                        str[strcount] = 0;
  1411. X                        write(TTYOUT, str + strpos, strcount - strpos);
  1412. X                        strpos++;
  1413. X                        tcap_curleft(strcount - strpos);
  1414. X                    }
  1415. X                    else
  1416. X                    {
  1417. X                        str[strpos++] = inch;
  1418. X                        ch = (char)inch;
  1419. X                        write(TTYOUT, &ch, 1);
  1420. X                    }
  1421. X                }
  1422. X                str[strcount] = 0;
  1423. X        }
  1424. X    }
  1425. X
  1426. X  FUNC_RETURN:
  1427. X    if (pstrpos)
  1428. X        *pstrpos = strpos;
  1429. X
  1430. X}                             /* end of ttygets() */
  1431. X
  1432. X/*+-------------------------------------------------------------------------
  1433. X    ttygets_esd(tesd,flags,append_flag)
  1434. X--------------------------------------------------------------------------*/
  1435. Xttygets_esd(tesd, flags, append_flag)
  1436. XESD *tesd;
  1437. Xint flags;
  1438. Xint append_flag;
  1439. X{
  1440. X    char *pb = tesd->pb;
  1441. X    int maxcb = tesd->maxcb;
  1442. X    uchar delim;
  1443. X
  1444. X    if (append_flag)
  1445. X    {
  1446. X        pb += tesd->cb;
  1447. X        maxcb -= tesd->cb;
  1448. X    }
  1449. X    else
  1450. X    {
  1451. X        pb = tesd->pb;
  1452. X        maxcb = tesd->maxcb;
  1453. X        tesd->cb = 0;
  1454. X    }
  1455. X
  1456. X    ttygets(pb, maxcb, flags, &delim, (int *)0);
  1457. X
  1458. X    if (delim == ESC)
  1459. X    {
  1460. X        if (!append_flag)
  1461. X            esdzero(tesd);
  1462. X        return (eProcAttn_ESCAPE);
  1463. X    }
  1464. X
  1465. X    tesd->cb = strlen(tesd->pb);
  1466. X    plogs(pb);
  1467. X    if (flags & 1)
  1468. X        plogc(NL);
  1469. X    return (0);
  1470. X
  1471. X}                             /* end of ttygets_esd */
  1472. X
  1473. X/*+-------------------------------------------------------------------------
  1474. X    kbd_test() - test keyboard handler
  1475. X--------------------------------------------------------------------------*/
  1476. Xvoid
  1477. Xkbd_test()
  1478. X{
  1479. X    uint ctmp = 0;
  1480. X
  1481. X    pputs("Press keys to test (ESCape to exit)\n");
  1482. X    kbd_test_active = 1;
  1483. X    while (ctmp != ESC)
  1484. X    {
  1485. X        ctmp = ttygetc(1);
  1486. X
  1487. X        if ((ctmp < 0x80) && dole_out_tgc_accum_count)
  1488. X        {
  1489. X            pprintf("    got %d key sequence %s ",
  1490. X                dole_out_tgc_accum_count + 1, hex_to_ascii_name(ctmp));
  1491. X            while (dole_out_tgc_accum_count)
  1492. X            {
  1493. X                pprintf("%s ", hex_to_ascii_name(*dole_out_tgc_accum++));
  1494. X                dole_out_tgc_accum_count--;
  1495. X            }
  1496. X            pputs("\n");
  1497. X            ctmp = 0;
  1498. X            continue;
  1499. X        }
  1500. X        pputs("    got ");
  1501. X        if (ctmp >= 0x80)
  1502. X            pprintf("fkey '%s'\n", xf_text(ctmp));
  1503. X        else
  1504. X            pprintf("key  '%s'\n", hex_to_ascii_name(ctmp));
  1505. X    }
  1506. X    kbd_test_active = 0;
  1507. X    ttyflush(0);
  1508. X    pputs("keyboard test complete\n\n");
  1509. X    dole_out_tgc_accum = (uchar *) 0;
  1510. X    dole_out_tgc_accum_count = 0;
  1511. X
  1512. X}                             /* end of kbd_test */
  1513. X
  1514. X/*+-------------------------------------------------------------------------
  1515. X    char *get_ttyname() - return pointer to static string
  1516. X
  1517. XThis routine is largely a crock and is likely to explode at any rev or twist
  1518. X--------------------------------------------------------------------------*/
  1519. Xchar *
  1520. Xget_ttyname()
  1521. X{
  1522. X#ifndef OLD_WAY
  1523. X    char *ttyname();
  1524. X
  1525. X    return (ttyname(TTYIN));
  1526. X#else
  1527. X    static char ttname[64];
  1528. X    register unsigned int rdev;
  1529. X    register char *cptr;
  1530. X
  1531. X    if (tty_not_char_special)
  1532. X        return ("stdin");
  1533. X    else if (!tty_is_multiscreen)
  1534. X        return ("non-multiscreen");
  1535. X
  1536. X    rdev = (unsigned)tty_stat.st_rdev;
  1537. X    if (rdev == 0x0301)
  1538. X        strcpy(ttname, "/dev/console");
  1539. X#if defined(M_UNIX)
  1540. X    else if (rdev == 0x0000)
  1541. X        strcpy(ttname, "/dev/syscon");
  1542. X#endif
  1543. X    else
  1544. X    {
  1545. X        strcpy(ttname, "/dev/tty");
  1546. X        cptr = ttname + 8;
  1547. X
  1548. X        if (rdev < 0x000C)
  1549. X        {
  1550. X            *cptr++ = '0' + ((rdev + 1) / 10);
  1551. X            *cptr++ = '0' + ((rdev + 1) % 10);
  1552. X        }
  1553. X        else if (!(rdev & ~0x58F))
  1554. X        {
  1555. X            *cptr++ = (rdev & 0x0008) ? '2' : '1';
  1556. X            *cptr++ = ((rdev & 0x0080) ? 'A' : 'a') + (rdev & 0x0007);
  1557. X        }
  1558. X        else
  1559. X        {
  1560. X            *cptr++ = '?';
  1561. X            *cptr++ = '?';
  1562. X        }
  1563. X        *cptr = 0;
  1564. X    }
  1565. X
  1566. X    return (ttname);
  1567. X#endif
  1568. X}                             /* end of get_ttyname */
  1569. X
  1570. X/*+-------------------------------------------------------------------------
  1571. X    set_console_xon_xoff_by_arg(arg)
  1572. X--------------------------------------------------------------------------*/
  1573. Xint
  1574. Xset_console_xon_xoff_by_arg(arg)
  1575. Xchar *arg;
  1576. X{
  1577. X    int new_xon_xoff = 0;
  1578. X
  1579. X    if (ulcmpb(arg, "on") < 0)
  1580. X    {
  1581. X        new_xon_xoff = IXON | IXOFF;
  1582. X        tty_use_kbd_sw_flow_control = 1;
  1583. X    }
  1584. X    else if (ulcmpb(arg, "off") < 0)
  1585. X    {
  1586. X        new_xon_xoff = 0;
  1587. X        tty_use_kbd_sw_flow_control = 0;
  1588. X    }
  1589. X    else
  1590. X        return (-1);
  1591. X
  1592. X    tty_termio_current.c_iflag &= ~(IXON | IXOFF);
  1593. X    tty_termio_current.c_iflag |= new_xon_xoff;
  1594. X    ecusetattr(TTYIN, TCSETA, &tty_termio_current);
  1595. X    return (0);
  1596. X
  1597. X}                             /* end of set_console_xon_xoff_by_arg */
  1598. X
  1599. X/*+-------------------------------------------------------------------------
  1600. X    console_xon_status()
  1601. X--------------------------------------------------------------------------*/
  1602. Xchar *
  1603. Xconsole_xon_status()
  1604. X{
  1605. X    if (tty_use_kbd_sw_flow_control)
  1606. X        return ("HONOR ^S/^Q locally");
  1607. X    else
  1608. X        return ("PASS ^S/^Q to remote");
  1609. X}                             /* end of console_xon_status */
  1610. X
  1611. X/* end of ecutty.c */
  1612. X/* vi: set tabstop=4 shiftwidth=4: */
  1613. END_OF_FILE
  1614.   if test 38143 -ne `wc -c <'ecu330/ecutty.c'`; then
  1615.     echo shar: \"'ecu330/ecutty.c'\" unpacked with wrong size!
  1616.   fi
  1617.   # end of 'ecu330/ecutty.c'
  1618. fi
  1619. if test -f 'ecu330/sea/scurses.c' -a "${1}" != "-c" ; then 
  1620.   echo shar: Will not clobber existing file \"'ecu330/sea/scurses.c'\"
  1621. else
  1622.   echo shar: Extracting \"'ecu330/sea/scurses.c'\" \(23014 characters\)
  1623.   sed "s/^X//" >'ecu330/sea/scurses.c' <<'END_OF_FILE'
  1624. X
  1625. X/*+-------------------------------------------------------------------------
  1626. X    scurses.c -- ecu file transfer program curses interface
  1627. X
  1628. X  000000000011111111112222222222333333333344444444445555555550
  1629. X  012345678901234567890123456789012345678901234567890123456789
  1630. X00.----------------------------------------------------------.
  1631. X01|  SEAlink_6____  _39____________________________________  |
  1632. X02|  File ### of ###: _38__________________________________  |
  1633. X03|  File position:  _8______ length: _8______               |
  1634. X04|  _55____________________________________________________ | transaction
  1635. X05|  _55____________________________________________________ | last rx/tx hdr
  1636. X06|  Comm I/O: rx _8______  tx _8______ bytes                |
  1637. X07|  Baud rate: _5___ BINARY blklen: _____ comm mode: CBREAK |
  1638. X08|  Time started: session: HH:MM:SS  this file: HH:MM:SS    |
  1639. X09|                elpased: HH:MM:SS       time: HH:MM:SS    |
  1640. X10|  Error counts: this file:  _4__  total: _6____           |
  1641. X11|  _55____________________________________________________ |  err str
  1642. X12|  _55____________________________________________________ |  comment str
  1643. X13|  _55____________________________________________________ |  remote info
  1644. X14`----------------------------------------------------------'
  1645. X
  1646. X  Defined functions:
  1647. X    clear_area(w,row,col,len)
  1648. X    clear_area_char(w,row,col,len,fillchar)
  1649. X    get_elapsed_time(elapsed_secs)
  1650. X    hhmmss(tod)
  1651. X    report_error_count()
  1652. X    report_file_byte_io(count)
  1653. X    report_file_close()
  1654. X    report_file_open_length(length)
  1655. X    report_file_open_tod()
  1656. X    report_file_rcv_started(filename,length,last_mod_time)
  1657. X    report_file_send_open(filename,filestat)
  1658. X    report_init(title)
  1659. X    report_last_rxhdr(rptstr,error_flag)
  1660. X    report_last_txhdr(rptstr,error_flag)
  1661. X    report_line(baud_rate,mode)
  1662. X    report_protocol_crc_type(str)
  1663. X    report_rx_ind(status)
  1664. X    report_rx_tx_count()
  1665. X    report_rxpos(pos)
  1666. X    report_str(rptstr,error_flag)
  1667. X    report_top_line(topstr)
  1668. X    report_transaction(str)
  1669. X    report_tx_ind(status)
  1670. X    report_txpos(pos)
  1671. X    report_uninit()
  1672. X    vanilla_ruling()
  1673. X
  1674. X------------------------------------------------------------------------*/
  1675. X/*+:EDITS:*/
  1676. X/*:05-04-1994-04:40-wht@n4hgf-ECU release 3.30 */
  1677. X/*:01-16-1994-15:46-wht@n4hgf-use ecumachdep.h */
  1678. X/*:12-02-1993-14:05-Robert_Broughton@mindlink.bc.c-LINUX patches */
  1679. X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
  1680. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  1681. X/*:04-24-1992-21:15-wht@n4hgf-sort out vannilla vs. at ruling */
  1682. X/*:02-09-1992-16:08-root@n4hgf-ruling characters only on  SCO (tcap curses) */
  1683. X/*:08-28-1991-14:08-wht@n4hgf2-SVR4 cleanup by aega84!lh */
  1684. X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
  1685. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  1686. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1687. X
  1688. X#include "../ecucurses.h"
  1689. X#include "../ecu_types.h"
  1690. X#include "../ecu_stat.h"
  1691. X#include "../ecu_time.h"
  1692. X#include <ctype.h>
  1693. X#include <signal.h>
  1694. X
  1695. X#include "../ecumachdep.h"
  1696. X#include "../pc_scr.h"
  1697. X
  1698. Xlong time();
  1699. Xextern char *tzname[];
  1700. Xstruct tm *localtime();
  1701. X
  1702. X#define WIN_LINES    15
  1703. X#define WIN_COLS    60
  1704. X#define WIN_TOPY    2
  1705. X#define WIN_LEFTX    8
  1706. X
  1707. Xextern char curr_dir[];
  1708. Xextern char s128[];
  1709. Xextern int Filcnt;
  1710. Xextern int Restricted;
  1711. Xextern int sending_flag;     /* send == 1, receive == 0 */
  1712. Xextern int npaths;
  1713. Xextern long rxpos;
  1714. Xextern int log_packets;
  1715. X
  1716. XWINDOW *win;
  1717. Xint (*original_sigint_handler) ();
  1718. Xint (*original_sigquit_handler) ();
  1719. Xint (*original_sigterm_handler) ();
  1720. Xint curses_installed = 0;     /* curses not yet active */
  1721. Xint this_file_errors = 0;
  1722. Xint total_errors = 0;
  1723. Xlong current_seconds;
  1724. Xlong start_seconds;
  1725. Xlong elapsed_seconds;
  1726. Xunsigned long total_data_chars_xfered = 0L;
  1727. X
  1728. X#ifdef LINUX
  1729. Xtypedef chtype Chtype;
  1730. X
  1731. X#else
  1732. Xtypedef unsigned char Chtype;
  1733. X
  1734. X#endif
  1735. X
  1736. XChtype sTL = at_TL;
  1737. XChtype sTR = at_TR;
  1738. XChtype sBL = at_BL;
  1739. XChtype sBR = at_BR;
  1740. XChtype sLT = at_LT;
  1741. XChtype sRT = at_RT;
  1742. XChtype sVR = at_VR;
  1743. XChtype sHR = at_HR;
  1744. X
  1745. Xchar *win_template[] =
  1746. X{
  1747. X/*00000000001111111111222222222233333333334444444444555555555 */
  1748. X/*01234567890123456789012345678901234567890123456789012345678 */
  1749. X/*.----------------------------------------------------------. */
  1750. X    "  SEAlink                                                 ",    /* 1 */
  1751. X    "  File ### of ###: _____________________________________  ",    /* 2 */
  1752. X    "  File position:  ________ length: ________               ",    /* 3 */
  1753. X    "                                                          ",    /* 4 */
  1754. X    "  tx: ______________________  rx: ______________________  ",    /* 5 */
  1755. X    "  Comm I/O: rx ________  tx ________ bytes                ",    /* 6 */
  1756. X    "  Baud rate: _____ BINARY blklen: 128   comm mode: ______ ",    /* 7 */
  1757. X    "  Time started: session: --:--:--  this file: --:--:--    ",    /* 8 */
  1758. X    "                elapsed: --:--:--    current: --:--:--    ",    /* 9 */
  1759. X    "  Error counts: this file:  ____  total: ______           ",    /* 10 */
  1760. X    "                                                          ",    /* 11 */
  1761. X    "                                                          ",    /* 12 */
  1762. X    "                                                          ",    /* 13 */
  1763. X/*`----------------------------------------------------------' */
  1764. X    (char *)0
  1765. X};
  1766. X
  1767. X/*+-------------------------------------------------------------------------
  1768. X    vanilla_ruling() - use ordinary ruling characters
  1769. X--------------------------------------------------------------------------*/
  1770. Xvoid
  1771. Xvanilla_ruling()
  1772. X{
  1773. X    sTL = vanilla_TL;
  1774. X    sTR = vanilla_TR;
  1775. X    sBL = vanilla_BL;
  1776. X    sBR = vanilla_BR;
  1777. X    sLT = vanilla_LT;
  1778. X    sRT = vanilla_RT;
  1779. X    sVR = vanilla_VR;
  1780. X    sHR = vanilla_HR;
  1781. X
  1782. X}                             /* end of vanilla_ruling */
  1783. X
  1784. X/*+-----------------------------------------------------------------------
  1785. X    char *get_elapsed_time(elapsed_secs)
  1786. X    hh:mm:ss returned
  1787. X  static string address is returned
  1788. X------------------------------------------------------------------------*/
  1789. Xchar *
  1790. Xget_elapsed_time(elapsed_secs)
  1791. Xlong elapsed_secs;
  1792. X{
  1793. X    static char elapsed_time_str[10];
  1794. X    long hh, mm, ss;
  1795. X
  1796. X    hh = elapsed_secs / 3600;
  1797. X    elapsed_secs -= hh * 3600;
  1798. X    mm = elapsed_secs / 60L;
  1799. X    elapsed_secs -= mm * 60L;
  1800. X    ss = elapsed_secs;
  1801. X
  1802. X    sprintf(elapsed_time_str, "%02ld:%02ld:%02ld", hh, mm, ss);
  1803. X    return (elapsed_time_str);
  1804. X}                             /* end of get_elapsed_time */
  1805. X
  1806. X/*+-----------------------------------------------------------------------
  1807. X    char *hhmmss(tod) - get time of day in form "hh:mm:ss"
  1808. X
  1809. X  static string address is returned
  1810. X  if tod != (char *)0, time is returned there too
  1811. X------------------------------------------------------------------------*/
  1812. Xchar *
  1813. Xhhmmss(tod)
  1814. Xchar *tod;
  1815. X{
  1816. X    long cur_time = 0;
  1817. X    struct tm *lt;             /* local time */
  1818. X    static char tod_str[32];
  1819. X
  1820. X    cur_time = time((long *)0);
  1821. X    lt = localtime(&cur_time);
  1822. X
  1823. X    sprintf(tod_str, "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
  1824. X
  1825. X    if (tod != (char *)0)
  1826. X        strcpy(tod, tod_str);
  1827. X
  1828. X    return (tod_str);
  1829. X
  1830. X}                             /* end of hhmmss */
  1831. X
  1832. X/*+-------------------------------------------------------------------------
  1833. X    clear_area(w,row,col,len)
  1834. X--------------------------------------------------------------------------*/
  1835. Xclear_area(w, row, col, len)
  1836. XWINDOW *w;
  1837. Xint row;
  1838. Xint col;
  1839. Xint len;
  1840. X{
  1841. X    wmove(w, row, col);
  1842. X    while (len-- > 0)
  1843. X        waddch(w, ' ');
  1844. X    wmove(w, row, col);
  1845. X
  1846. X}                             /* end of clear_area */
  1847. X
  1848. X/*+-------------------------------------------------------------------------
  1849. X    clear_area_char(w,row,col,len,fillchar)
  1850. X--------------------------------------------------------------------------*/
  1851. Xclear_area_char(w, row, col, len, fillchar)
  1852. XWINDOW *w;
  1853. Xint row;
  1854. Xint col;
  1855. Xint len;
  1856. Xchar fillchar;
  1857. X{
  1858. X    wmove(w, row, col);
  1859. X    while (len-- > 0)
  1860. X        waddch(w, fillchar);
  1861. X    wmove(w, row, col);
  1862. X
  1863. X}                             /* end of clear_area_char */
  1864. X
  1865. X/*+-------------------------------------------------------------------------
  1866. X    report_top_line(topstr)
  1867. X   top line: row 1 col 18 length 39
  1868. X--------------------------------------------------------------------------*/
  1869. Xvoid
  1870. Xreport_top_line(topstr)
  1871. Xchar *topstr;
  1872. X{
  1873. X    char s42[42];
  1874. X
  1875. X    clear_area(win, 1, 18, 39);
  1876. X    if (strlen(topstr) < 39)
  1877. X        waddstr(win, topstr);
  1878. X    else
  1879. X    {
  1880. X        strncpy(s42, topstr, 39);
  1881. X        s42[39] = 0;
  1882. X        waddstr(win, s42);
  1883. X    }
  1884. X}                             /* end of report_top_line */
  1885. X
  1886. X/*+-------------------------------------------------------------------------
  1887. X    report_protocol_crc_type(str)
  1888. X
  1889. X  protocol crc type:  row 1 col 10 length 6
  1890. X--------------------------------------------------------------------------*/
  1891. Xreport_protocol_crc_type(str)
  1892. Xregister char *str;
  1893. X{
  1894. X    char s8[8];
  1895. X
  1896. X    if (strlen(str) > 6)
  1897. X    {
  1898. X        strncpy(s8, str, 6);
  1899. X        s8[6] = 0;
  1900. X        str = s8;
  1901. X    }
  1902. X    clear_area(win, 1, 10, 6);
  1903. X    waddstr(win, str);
  1904. X    wrefresh(win);
  1905. X    if (log_packets)
  1906. X    {
  1907. X        write(log_packets, "chk:  ", 6);
  1908. X        write(log_packets, str, strlen(str));
  1909. X        write(log_packets, "\n", 1);
  1910. X    }
  1911. X
  1912. X}                             /* end of report_protocol_crc_type */
  1913. X
  1914. X/*+-------------------------------------------------------------------------
  1915. X    report_error_count()
  1916. X    DOES NOT PERFORM A REFRESH CYCLE
  1917. X  this file: row 10 col 29 len 4
  1918. X  total:     row 10 col 42 len 6
  1919. X--------------------------------------------------------------------------*/
  1920. Xvoid
  1921. Xreport_error_count()
  1922. X{
  1923. X    char tmp[16];
  1924. X
  1925. X    clear_area(win, 10, 29, 4);
  1926. X    sprintf(tmp, "%4d", this_file_errors);
  1927. X    waddstr(win, tmp);
  1928. X
  1929. X    clear_area(win, 10, 42, 6);
  1930. X    sprintf(tmp, "%6d", total_errors);
  1931. X    waddstr(win, tmp);
  1932. X    wrefresh(win);
  1933. X
  1934. X}                             /* end of report_error_count */
  1935. X
  1936. X/*+-------------------------------------------------------------------------
  1937. X    report_uninit()
  1938. X--------------------------------------------------------------------------*/
  1939. Xvoid
  1940. Xreport_uninit()
  1941. X{
  1942. X    float total = (float)total_data_chars_xfered;
  1943. X
  1944. X    if (curses_installed)
  1945. X    {
  1946. X        if ((total_data_chars_xfered != 0L) && (elapsed_seconds != 0L))
  1947. X        {
  1948. X            sprintf(s128, "Data xfer rate ~= %6.0f chars/sec",
  1949. X                total / (float)elapsed_seconds);
  1950. X            if (log_packets)
  1951. X            {
  1952. X                write(log_packets, "info: ", 6);
  1953. X                write(log_packets, s128, strlen(s128));
  1954. X                write(log_packets, "\n", 1);
  1955. X            }
  1956. X            report_top_line(s128);
  1957. X        }
  1958. X        report_file_byte_io(0L);
  1959. X        report_rx_tx_count();
  1960. X        wmove(win, WIN_LINES - 1, WIN_COLS - 1);
  1961. X        wrefresh(win);
  1962. X        endwin();
  1963. X        fprintf(stderr, "\r\n\r\n\r\n");
  1964. X        fflush(stderr);
  1965. X        curses_installed = 0;
  1966. X    }
  1967. X
  1968. X}                             /* end of report_uninit */
  1969. X
  1970. X/*+-------------------------------------------------------------------------
  1971. X    report_init(title)
  1972. X--------------------------------------------------------------------------*/
  1973. Xvoid
  1974. Xreport_init(title)
  1975. Xchar *title;
  1976. X{
  1977. X    register int itmp;
  1978. X
  1979. X#if defined(CONS_GET)
  1980. X    int monitor_type;
  1981. X
  1982. X#endif
  1983. X
  1984. X    if (curses_installed)
  1985. X        return;
  1986. X
  1987. X#if defined(M_SYSV)
  1988. X    if (ioctl(0, CONS_GET, &monitor_type) < 0)    /* not multiscreen */
  1989. X#ifdef M_SYSV                 /* SCO non AT console */
  1990. X        vanilla_ruling();
  1991. X#endif
  1992. X#else
  1993. X    vanilla_ruling();
  1994. X#endif
  1995. X#ifdef LINUX
  1996. X    sTL = ACS_ULCORNER;
  1997. X    sTR = ACS_URCORNER;
  1998. X    sBL = ACS_LLCORNER;
  1999. X    sBR = ACS_LRCORNER;
  2000. X    sLT = ACS_LTEE;
  2001. X    sRT = ACS_RTEE;
  2002. X    sVR = ACS_VLINE;
  2003. X    sHR = ACS_HLINE;
  2004. X#endif
  2005. X
  2006. X    initscr();
  2007. X    crmode();
  2008. X    noecho();
  2009. X    nonl();
  2010. X    clear();
  2011. X    curses_installed = 1;
  2012. X    win = newwin(WIN_LINES, WIN_COLS, WIN_TOPY, WIN_LEFTX);
  2013. X    box(win, sVR, sHR);
  2014. X#if !defined(SVR4) && !defined(LINUX)
  2015. X    wmove(win, 0, 0);
  2016. X    waddch(win, sTL);
  2017. X    wmove(win, win->_maxy - 1, 0);
  2018. X    waddch(win, sBL);
  2019. X    wmove(win, win->_maxy - 1, win->_maxx - 1);
  2020. X    waddch(win, sBR);
  2021. X    wmove(win, 0, win->_maxx - 1);
  2022. X    waddch(win, sTR);
  2023. X#endif
  2024. X    wmove(win, 0, 2);
  2025. X    wstandout(win);
  2026. X    waddch(win, '[');
  2027. X    waddch(win, ' ');
  2028. X    waddstr(win, title);
  2029. X    waddch(win, ' ');
  2030. X    waddch(win, ']');
  2031. X    wstandend(win);
  2032. X#ifdef SVR4
  2033. X    whline(win, (unsigned long)(sHR & 0x00ff), 2);
  2034. X    wmove(win, 0, 8 + strlen(title));
  2035. X#else
  2036. X#ifdef LINUX
  2037. X    whline(win, sHR, 2);
  2038. X    wmove(win, 0, 8 + strlen(title));
  2039. X#else
  2040. X    waddch(win, sHR);
  2041. X    waddch(win, sHR);
  2042. X#endif
  2043. X#endif
  2044. X    waddstr(win, " dir: ");
  2045. X    waddstr(win, curr_dir);
  2046. X    waddch(win, ' ');
  2047. X
  2048. X    itmp = 0;
  2049. X    while (1)
  2050. X    {
  2051. X        if (win_template[itmp] == (char *)0)
  2052. X            break;
  2053. X        wmove(win, itmp + 1, 1);
  2054. X        waddstr(win, win_template[itmp++]);
  2055. X    }
  2056. X    if (sending_flag)
  2057. X    {
  2058. X        clear_area(win, 2, 15, 3);
  2059. X        sprintf(s128, "%3d", npaths);
  2060. X        waddstr(win, s128);
  2061. X    }
  2062. X    else
  2063. X        /* ecurz */
  2064. X    {
  2065. X        clear_area(win, 2, 11, 8);    /* clear "of ###" */
  2066. X        waddstr(win, ":");
  2067. X    }
  2068. X
  2069. X    clear_area(win, 1, 11, 47);
  2070. X    report_error_count();
  2071. X    clear_area(win, 8, 26, 8);    /* starting time */
  2072. X    waddstr(win, hhmmss((char *)0));
  2073. X    start_seconds = time((long *)0);
  2074. X    current_seconds = start_seconds;
  2075. X
  2076. X    wrefresh(win);
  2077. X
  2078. X}                             /* end of report_init */
  2079. X
  2080. X/*+-------------------------------------------------------------------------
  2081. X    report_rx_ind(status)
  2082. X--------------------------------------------------------------------------*/
  2083. Xvoid
  2084. Xreport_rx_ind(status)
  2085. Xint status;
  2086. X{
  2087. X    wmove(win, 1, 54);
  2088. X    waddch(win, (status) ? 'R' : ' ');
  2089. X    wmove(win, 1, 54);
  2090. X    wrefresh(win);
  2091. X}                             /* end of report_rx_ind */
  2092. X
  2093. X/*+-------------------------------------------------------------------------
  2094. X    report_tx_ind(status)
  2095. X--------------------------------------------------------------------------*/
  2096. Xvoid
  2097. Xreport_tx_ind(status)
  2098. Xint status;
  2099. X{
  2100. X    wmove(win, 1, 56);
  2101. X    waddch(win, (status) ? 'T' : ' ');
  2102. X    wmove(win, 1, 56);
  2103. X    wrefresh(win);
  2104. X}                             /* end of report_tx_ind */
  2105. X
  2106. X/*+-------------------------------------------------------------------------
  2107. X    report_rx_tx_count()
  2108. X
  2109. X  rx char count: row 6 col 16 length 8 unsigned long
  2110. X  tx char count: row 6 col 29 length 8 unsigned long
  2111. X  now time of day: row 1 col 50 length 8 hh:mm:ss
  2112. X  This procedure may be counted upon to perform wrefresh(win)
  2113. X
  2114. Xelapsed time row 9 col 26 length 8
  2115. Xcurrent tod row 9 col 47 length 8
  2116. X--------------------------------------------------------------------------*/
  2117. Xreport_rx_tx_count()
  2118. X{
  2119. X    extern unsigned long rx_char_count;
  2120. X    extern unsigned long tx_char_count;
  2121. X
  2122. X    register char *cptr;
  2123. X
  2124. X    sprintf(s128, "%8ld", rx_char_count);
  2125. X    wmove(win, 6, 16);
  2126. X    waddstr(win, s128);
  2127. X    sprintf(s128, "%8ld", tx_char_count);
  2128. X    wmove(win, 6, 29);
  2129. X    waddstr(win, s128);
  2130. X
  2131. X    /* now time of day */
  2132. X    clear_area(win, 9, 47, 8);
  2133. X    cptr = hhmmss((char *)0);
  2134. X    waddstr(win, cptr);
  2135. X    current_seconds = time((long *)0);
  2136. X    elapsed_seconds = current_seconds - start_seconds;
  2137. X    cptr = get_elapsed_time(elapsed_seconds);
  2138. X    clear_area(win, 9, 26, 8);
  2139. X    waddstr(win, cptr);
  2140. X    wrefresh(win);             /* calling procs expect this to occur always */
  2141. X
  2142. X}                             /* end of report_rx_tx_count */
  2143. X
  2144. X/*+-------------------------------------------------------------------------
  2145. X    report_line(baud_rate,mode)
  2146. X--------------------------------------------------------------------------*/
  2147. Xvoid
  2148. Xreport_line(baud_rate, mode)
  2149. Xunsigned baud_rate;
  2150. Xchar *mode;
  2151. X{
  2152. X    char s16[16];
  2153. X
  2154. X    wmove(win, 7, 14);
  2155. X    sprintf(s16, "%5u", baud_rate);
  2156. X    waddstr(win, s16);
  2157. X    clear_area(win, 7, 52, 6);
  2158. X    waddstr(win, mode);
  2159. X    wrefresh(win);
  2160. X}                             /* end of report_line */
  2161. X
  2162. X/*+-------------------------------------------------------------------------
  2163. X    report_rxpos(pos) row 3 col 19 len 8
  2164. X--------------------------------------------------------------------------*/
  2165. Xvoid
  2166. Xreport_rxpos(pos)
  2167. Xlong pos;
  2168. X{
  2169. X    char tmp[16];
  2170. X    char refr;
  2171. X
  2172. X    if (rdchk(0))
  2173. X    {
  2174. X        read(0, &refr, 1);
  2175. X        if (refr == 0x0C || refr == 0x012)    /* ^L or ^R */
  2176. X        {
  2177. X            write(2, "\033[2J", 4);
  2178. X            Nap((long)60);
  2179. X            touchwin(stdscr);
  2180. X            wrefresh(stdscr);
  2181. X            touchwin(win);
  2182. X            wrefresh(win);
  2183. X        }
  2184. X    }
  2185. X
  2186. X    if ((pos > 99999999L) || (pos < 0L))
  2187. X        return;
  2188. X
  2189. X    sprintf(tmp, "%8lu", pos);
  2190. X    wmove(win, 3, 19);
  2191. X    waddstr(win, tmp);
  2192. X    wrefresh(win);
  2193. X    report_rx_tx_count();     /* which will do a refresh */
  2194. X}                             /* end of report_rxpos */
  2195. X
  2196. X/*+-------------------------------------------------------------------------
  2197. X    report_txpos(pos)
  2198. X--------------------------------------------------------------------------*/
  2199. Xvoid
  2200. Xreport_txpos(pos)
  2201. Xlong pos;
  2202. X{
  2203. X    report_rxpos(pos);
  2204. X}                             /* end of report_txpos */
  2205. X
  2206. X/*+-------------------------------------------------------------------------
  2207. X    report_last_txhdr(rptstr,error_flag)
  2208. X    5,7,22
  2209. X--------------------------------------------------------------------------*/
  2210. Xvoid
  2211. Xreport_last_txhdr(rptstr, error_flag)
  2212. Xregister char *rptstr;
  2213. Xint error_flag;
  2214. X{
  2215. X    char s24[24];
  2216. X
  2217. X    if (log_packets)
  2218. X    {
  2219. X        write(log_packets, "tx:   ", 6);
  2220. X        write(log_packets, rptstr, strlen(rptstr));
  2221. X        write(log_packets, "\n", 1);
  2222. X    }
  2223. X
  2224. X    if (strlen(rptstr) > 22)
  2225. X    {
  2226. X        strncpy(s24, rptstr, 22);
  2227. X        s24[23] = 0;
  2228. X        rptstr = s24;
  2229. X    }
  2230. X    clear_area(win, 5, 7, 22);
  2231. X    waddstr(win, rptstr);
  2232. X    wrefresh(win);
  2233. X
  2234. X    if (error_flag)
  2235. X    {
  2236. X        ++this_file_errors;
  2237. X        ++total_errors;
  2238. X        report_error_count();
  2239. X    }
  2240. X}                             /* end of report_last_txhdr */
  2241. X
  2242. X/*+-------------------------------------------------------------------------
  2243. X    report_last_rxhdr(rptstr,error_flag)
  2244. X    5,35,22
  2245. X--------------------------------------------------------------------------*/
  2246. Xvoid
  2247. Xreport_last_rxhdr(rptstr, error_flag)
  2248. Xregister char *rptstr;
  2249. Xint error_flag;
  2250. X{
  2251. X    char s24[24];
  2252. X    extern int log_packets;
  2253. X
  2254. X    if (log_packets)
  2255. X    {
  2256. X        write(log_packets, "rx: ", 4);
  2257. X        write(log_packets, (error_flag) ? "E " : "  ", 2);
  2258. X        write(log_packets, rptstr, strlen(rptstr));
  2259. X        write(log_packets, "\n", 1);
  2260. X    }
  2261. X
  2262. X    if (strlen(rptstr) > 22)
  2263. X    {
  2264. X        strncpy(s24, rptstr, 22);
  2265. X        s24[23] = 0;
  2266. X        rptstr = s24;
  2267. X    }
  2268. X    clear_area(win, 5, 35, 22);
  2269. X    waddstr(win, rptstr);
  2270. X    wrefresh(win);
  2271. X
  2272. X    if (error_flag)
  2273. X    {
  2274. X        ++this_file_errors;
  2275. X        ++total_errors;
  2276. X        report_error_count();
  2277. X    }
  2278. X
  2279. X}                             /* end of report_last_rxhdr */
  2280. X
  2281. X/*+-------------------------------------------------------------------------
  2282. X    report_str(rptstr,error_flag) row 11/12 col 3 len 55
  2283. X
  2284. X  error_flag == 0 for status/progress message
  2285. X             == 1 for bump error count, unless rptstr is null
  2286. X                  in which case, merely clear error string area
  2287. X             == 2 write string on bottom line (not an error)
  2288. X             == 3 write string on transaction line (not an error)
  2289. X             == -1 use error line but do not bump error count
  2290. X--------------------------------------------------------------------------*/
  2291. Xvoid
  2292. Xreport_str(rptstr, error_flag)
  2293. Xregister char *rptstr;
  2294. Xint error_flag;
  2295. X{
  2296. X    char s60[60];
  2297. X    extern int log_packets;
  2298. X
  2299. X    if (strlen(rptstr) > 55)
  2300. X    {
  2301. X        strncpy(s60, rptstr, 55);
  2302. X        s60[56] = 0;
  2303. X        rptstr = s60;
  2304. X    }
  2305. X
  2306. X    switch (error_flag)
  2307. X    {
  2308. X        case 0:
  2309. X            clear_area(win, 12, 3, 55);
  2310. X            break;
  2311. X        case 1:
  2312. X            ++this_file_errors;
  2313. X            ++total_errors;
  2314. X            report_error_count();
  2315. X        case -1:
  2316. X            clear_area(win, 11, 3, 55);
  2317. X            break;
  2318. X        case 2:
  2319. X            clear_area(win, 13, 3, 55);
  2320. X            break;
  2321. X        case 3:
  2322. X            clear_area(win, 4, 3, 55);
  2323. X            break;
  2324. X    }
  2325. X
  2326. X    waddstr(win, rptstr);
  2327. X    wrefresh(win);
  2328. X
  2329. X    if (log_packets)
  2330. X    {
  2331. X        write(log_packets, "info: ", 6);
  2332. X        sprintf(s60, "%2d ", error_flag);
  2333. X        write(log_packets, s60, 3);
  2334. X        write(log_packets, rptstr, strlen(rptstr));
  2335. X        write(log_packets, "\n", 1);
  2336. X    }
  2337. X
  2338. X}                             /* end of report_str */
  2339. X
  2340. X/*+-------------------------------------------------------------------------
  2341. X    report_transaction()
  2342. X--------------------------------------------------------------------------*/
  2343. Xvoid
  2344. Xreport_transaction(str)
  2345. Xchar *str;
  2346. X{
  2347. X    report_str(str, 3);
  2348. X}                             /* end of report_transaction */
  2349. X
  2350. X/*+-------------------------------------------------------------------------
  2351. X    report_file_open_tod() -- time of start of this file
  2352. X
  2353. X  this file open time: row 8 col 47 length 8
  2354. X--------------------------------------------------------------------------*/
  2355. Xvoid
  2356. Xreport_file_open_tod()
  2357. X{
  2358. X    clear_area(win, 8, 47, 8);
  2359. X    waddstr(win, hhmmss((char *)0));
  2360. X    wrefresh(win);
  2361. X}                             /* end of report_file_open_tod */
  2362. X
  2363. X/*+-------------------------------------------------------------------------
  2364. X    report_file_open_length(long_length)
  2365. X  length:   row 3 col 36 len  8
  2366. X--------------------------------------------------------------------------*/
  2367. Xreport_file_open_length(length)
  2368. Xlong length;
  2369. X{
  2370. X    clear_area(win, 3, 36, 8);
  2371. X    if (length <= 0)
  2372. X        waddstr(win, "unknown");
  2373. X    else
  2374. X    {
  2375. X        sprintf(s128, "%8lu", length);
  2376. X        waddstr(win, s128);
  2377. X    }
  2378. X    wrefresh(win);
  2379. X}                             /* end of report_file_open_length */
  2380. X
  2381. X/*+-------------------------------------------------------------------------
  2382. X    report_file_send_open(filename,filestat)
  2383. X
  2384. X  filename: row 2 col 20 len 38
  2385. X  number:   row 2 col 8 len 3
  2386. X  length:   row 3 col 36 len  8
  2387. X  mode:     row 3 col 46 len 10
  2388. X  time of start of this file: row 4 col 47 length 8 hh:mm:ss
  2389. X--------------------------------------------------------------------------*/
  2390. Xvoid
  2391. Xreport_file_send_open(filename, filestat)
  2392. Xchar *filename;
  2393. Xstruct stat *filestat;
  2394. X{
  2395. X    char s50[50];
  2396. X    register char *cptr = filename;
  2397. X
  2398. X    if (log_packets)
  2399. X    {
  2400. X        write(log_packets, "file: ", 6);
  2401. X        write(log_packets, filename, strlen(filename));
  2402. X        write(log_packets, "\n", 1);
  2403. X    }
  2404. X
  2405. X    /* number */
  2406. X    clear_area(win, 2, 8, 3);
  2407. X    sprintf(s50, "%3d", Filcnt);
  2408. X    waddstr(win, s50);
  2409. X
  2410. X    /* filename */
  2411. X    if (strlen(filename) > 38)
  2412. X    {
  2413. X        strncpy(s50, filename, 38);
  2414. X        s50[39] = 0;
  2415. X        cptr = s50;
  2416. X    }
  2417. X    clear_area(win, 2, 20, 38);
  2418. X    waddstr(win, cptr);
  2419. X
  2420. X#if defined(LOG_XFER)
  2421. X    sprintf(s128, "sending %s", filename);
  2422. X    ecu_log_event(getppid(), s128);
  2423. X#endif
  2424. X
  2425. X    /* length */
  2426. X    report_file_open_length(filestat->st_size);
  2427. X
  2428. X    /* time of start of this file */
  2429. X    report_file_open_tod();
  2430. X
  2431. X    this_file_errors = 0;
  2432. X    report_error_count();
  2433. X}                             /* end of report_file_send_open */
  2434. X
  2435. X/*+-------------------------------------------------------------------------
  2436. X    report_file_rcv_started(filename,length,last_mod_time)
  2437. X
  2438. X  filename: row 2 col 7 len 50
  2439. X  length:   row 3 col 36 len  8 if not xmodem
  2440. X  time of start of this file: row 4 col 47 length 8 hh:mm:ss
  2441. X--------------------------------------------------------------------------*/
  2442. Xreport_file_rcv_started(filename, length, last_mod_time)
  2443. Xchar *filename;
  2444. Xlong length;                 /* if < 0, "UNKNOWN" */
  2445. Xlong last_mod_time;             /* not currently displayed */
  2446. X{
  2447. X    register char *cptr;
  2448. X    char s50[50];
  2449. X
  2450. X    if (log_packets)
  2451. X    {
  2452. X        write(log_packets, "file: ", 6);
  2453. X        write(log_packets, filename, strlen(filename));
  2454. X        write(log_packets, "\n", 1);
  2455. X    }
  2456. X
  2457. X    /* filename */
  2458. X    if (strlen(filename) > 38)
  2459. X    {
  2460. X        strncpy(s50, filename, 38);
  2461. X        s50[39] = 0;
  2462. X        cptr = s50;
  2463. X    }
  2464. X    else
  2465. X        cptr = filename;
  2466. X
  2467. X#if defined(LOG_XFER)
  2468. X    sprintf(s128, "receiving %s", filename);
  2469. X    ecu_log_event(getppid(), s128);
  2470. X#endif
  2471. X
  2472. X    clear_area(win, 2, 20, 38);
  2473. X    waddstr(win, cptr);
  2474. X
  2475. X    /* file number */
  2476. X    clear_area(win, 2, 8, 3);
  2477. X    sprintf(s50, "%3d", Filcnt);    /* rz uses as file number 1-n */
  2478. X    waddstr(win, s50);
  2479. X
  2480. X/* if remote sender provides a file count, display it */
  2481. X    if (npaths)
  2482. X    {
  2483. X        clear_area(win, 2, 12, 7);    /* clear "of ###" */
  2484. X        sprintf(s50, "of %3d:", npaths);
  2485. X        waddstr(win, s50);
  2486. X    }
  2487. X
  2488. X    /* length */
  2489. X    report_file_open_length(length);
  2490. X
  2491. X    /* time of start of this file */
  2492. X    report_file_open_tod();
  2493. X
  2494. X    this_file_errors = 0;
  2495. X    report_error_count();
  2496. X}                             /* end of report_file_rcv_started */
  2497. X
  2498. X/*+-------------------------------------------------------------------------
  2499. X    report_file_close()
  2500. X--------------------------------------------------------------------------*/
  2501. Xvoid
  2502. Xreport_file_close()
  2503. X{
  2504. X    report_str("End of file", 0);
  2505. X    wrefresh(win);
  2506. X
  2507. X}                             /* end of report_file_close */
  2508. X
  2509. X/*+-------------------------------------------------------------------------
  2510. X    report_file_byte_io(count)
  2511. X--------------------------------------------------------------------------*/
  2512. Xreport_file_byte_io(count)
  2513. Xlong count;
  2514. X{
  2515. X
  2516. X    total_data_chars_xfered += (long)count;
  2517. X    if (total_data_chars_xfered)
  2518. X    {
  2519. X        sprintf(s128, "Total file bytes transferred: %lu",
  2520. X            total_data_chars_xfered);
  2521. X        report_str(s128, -1);
  2522. X    }
  2523. X
  2524. X}                             /* end of report_file_byte_io */
  2525. X
  2526. X/* end of scurses.c */
  2527. X/* vi: set tabstop=4 shiftwidth=4: */
  2528. END_OF_FILE
  2529.   if test 23014 -ne `wc -c <'ecu330/sea/scurses.c'`; then
  2530.     echo shar: \"'ecu330/sea/scurses.c'\" unpacked with wrong size!
  2531.   fi
  2532.   # end of 'ecu330/sea/scurses.c'
  2533. fi
  2534. echo shar: End of archive 12 \(of 37\).
  2535. cp /dev/null ark12isdone
  2536. MISSING=""
  2537. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ; do
  2538.     if test ! -f ark${I}isdone ; then
  2539.     MISSING="${MISSING} ${I}"
  2540.     fi
  2541. done
  2542. if test "${MISSING}" = "" ; then
  2543.     echo You have unpacked all 37 archives.
  2544.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2545. else
  2546.     echo You still must unpack the following archives:
  2547.     echo "        " ${MISSING}
  2548. fi
  2549. exit 0
  2550. exit 0 # Just in case...
  2551.