home *** CD-ROM | disk | FTP | other *** search
- From: wht@n4hgf.atl.ga.us (Warren Tucker)
- Newsgroups: comp.sources.misc
- Subject: v42i110: ecu - ECU Asynchronous Communications v3.30, Part12/37
- Date: 23 May 1994 14:23:00 -0500
- Organization: Sterling Software
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <2rqvqk$dmu@sparky.sterling.com>
- X-Md4-Signature: c8929ae97d660e500fe8137b1e855e84
-
- Submitted-by: wht@n4hgf.atl.ga.us (Warren Tucker)
- Posting-number: Volume 42, Issue 110
- Archive-name: ecu/part12
- Environment: SCO,SCOXENIX,MOTOROLA,HP-UX,LINUX,NetBSD,SUNOS,SYSVR4,SOLARIS2
- Supersedes: ecu: Volume 32, Issue 36-75
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: ecu330/ecutty.c ecu330/sea/scurses.c
- # Wrapped by kent@sparky on Mon May 23 13:40:51 1994
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 12 (of 37)."'
- if test -f 'ecu330/ecutty.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ecu330/ecutty.c'\"
- else
- echo shar: Extracting \"'ecu330/ecutty.c'\" \(38143 characters\)
- sed "s/^X//" >'ecu330/ecutty.c' <<'END_OF_FILE'
- X#ifndef USE_COLOR
- X#ifdef M_SYSV /* SCO family */
- X#define USE_COLOR
- X#endif
- X#ifdef MOTSVR3 /* not yet */
- X#endif
- X#ifdef ISC /* not yet */
- X#endif
- X#ifdef sun /* not yet */
- X#endif
- X#ifdef ISCSVR4 /* last I heard from lothar, this worked */
- X#define USE_COLOR
- X#endif
- X#ifdef ESIXSVR4 /* I heard this does not work */
- X#endif
- X#ifdef LINUX
- X#define USE_COLOR
- X#endif
- X#endif /* USE_COLOR */
- X
- X/*+-------------------------------------------------------------------------
- X ecutty.c - local tty (console) functions
- X wht@n4hgf.atl.ga.us
- X
- X Defined functions:
- X B_to_timeout_msec(termio_tty,st_rdev)
- X _setcolor(clrs)
- X color_name_to_num(cname)
- X get_initial_colors()
- X get_ttymode()
- X get_ttyname()
- X kbd_test()
- X read_colors_file()
- X restore_initial_colors()
- X ring_bell()
- X setcolor(new_colors)
- X setcolor_internal(ntokens,tokens)
- X termio_to_kbd_chars()
- X ttyflush(flush_type)
- X ttygetc(xkey_ok)
- X ttygets(str,maxsize,flags,delim,pstrpos)
- X ttygets_esd(tesd,flags,append_flag)
- X ttyinit(param)
- X ttymode(arg)
- X ttyrdchk()
- X
- X In SCO versions, ECU keeps the the state of the normal and
- X reverse video foreground and background colors in a 32-bit value:
- X
- X 00000000001111111111222222222233
- X 01234567890123456789012345678901
- X 0000|--|0000|--|0000|--|0000|--|
- X fg bk fg bk
- X reverse normal
- X
- X The color values are per the SCO extended color definitons:
- X
- X black 0 gray 8
- X blue 1 lt_blue 9
- X green 2 lt_green 10
- X cyan 3 lt_cyan 11
- X red 4 lt_red 12
- X magenta 5 lt_magenta 13
- X brown 6 yellow 14
- X white 7 hi_white 15
- X
- X With Lothar's ISC SVR4, the format is
- X
- X 00000000001111111111222222222233
- X 01234567890123456789012345678901
- X 00000000000000000011????0100????
- X 0 0 0 0 3 f 4 o b
- X where f is the foreground color
- X and b is the background color
- X
- X (I dont have one, so I'm guessing these colors are chosen from
- X the ISO colors):
- X
- X BLACK 0
- X RED 1
- X GREEN 2
- X YELLOW 3
- X BLUE 4
- X MAGENTA 5
- X CYAN 6
- X WHITE 7
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
- X/*:03-13-1994-19:22-wht@fep-added WHT rterm detection */
- X/*:01-16-1994-15:46-wht@n4hgf-use ecumachdep.h */
- X/*:12-12-1993-13:32-wht@n4hgf-support MOTSVR3 */
- X/*:12-02-1993-14:05-Robert_Broughton@mindlink.bc.c-further LINUX patches */
- X/*:08-03-1993-12:43-wht@n4hgf-use build_arg_array in read_color_file */
- X/*:08-03-1993-12:43-wht@n4hgf-global colors file was never read */
- X/*:08-03-1993-12:41-wht@n4hgf-comment trigger can now be in col > 1 */
- X/*:07-17-1993-12:36-wht@n4hgf-no more rcvrdisp_actual2_xmtr_buffer junk */
- X/*:01-30-1993-13:29-wht@n4hgf-get rid of warning about unused variable */
- X/*:12-20-1992-12:37-wht@n4hgf-WHT experiment with attributes */
- X/*:10-18-1992-14:26-wht@n4hgf-add console xon/xoff control */
- X/*:10-08-1992-01:12-wht@n4hgf-no more obsolete Metro Link PTS */
- X/*:10-08-1992-01:06-wht@n4hgf-SVR4 color work + !use_color normal fix */
- X/*:09-15-1992-18:52-wht@n4hgf-left some debug code in patch01 dammit */
- X/*:09-13-1992-12:52-wht@n4hgf-add tty_is_scoterm */
- X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
- X/*:08-30-1992-07:42-wht@n4hgf-implement USE_COLOR+turn off ESIX color for now */
- X/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
- X/*:08-16-1992-03:43-wht@n4hgf-add -F funckeytype */
- X/*:06-20-1992-21:13-wht@n4hgf-eculibdir was overwritten if no home dir colors */
- X/*:06-16-1992-11:20-wht@n4hgf-ECUFUNCKEY */
- X/*:05-05-1992-17:42-wht@n4hgf-repair underscore always on on sun */
- X/*:04-24-1992-16:55-wht@n4hgf-dont flunk on >43 lines but use only 43 */
- X/*:04-20-1992-20:31-wht@n4hgf-ttymode now no-op until ttyinit called */
- X/*:04-20-1992-19:42-wht@n4hgf-kbdtest code in ttygetc messed up-str too short */
- X/*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 */
- X/*:04-19-1992-02:00-wht@n4hgf-if TERM=ansi with WINDOWID, assume scoterm */
- X/*:08-31-1991-13:29-wht@n4hgf2-look for colors in ECULIBDIR too */
- X/*:08-30-1991-04:12-wht@n4hgf2-restore colors wrong to do now if not SCO */
- X/*:08-30-1991-02:49-aega84!lh-use at_ansi.h/kd.h/CONS_GET under ISC SVR4 */
- X/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
- X/*:08-17-1991-18:29-wht@n4hgf-add kbdtest command */
- X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
- X/*:07-14-1991-18:18-wht@n4hgf-new ttygets functions */
- X/*:07-10-1991-16:19-wht@n4hgf-improve multi-char func key read timeout */
- X/*:03-20-1991-03:07-root@n4hgf-pts driver returns -1 on rdchk success! */
- X/*:03-19-1991-21:24-root@n4hgf-METROLINK_X11R4_PTS mods */
- X/*:01-29-1991-14:03-wht@n4hgf-more time for ESC vs fkey discrimination */
- X/*:01-29-1991-13:44-wht@n4hgf-load colors_normal w/ioctl GIO_ATTR if M_UNIX */
- X/*:12-01-1990-14:33-wht@n4hgf-more non-ansi - fkey mapping with nonansi.c */
- X/*:11-28-1990-15:56-wht@n4hgf-add non-ansi terminal support */
- X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
- X
- X#include "ecu.h"
- X#include "esd.h"
- X#include "ecufkey.h"
- X#include "ecukey.h"
- X#include "ecuxkey.h"
- X#include "ecuerror.h"
- X#include "termecu.h"
- X
- X#include "ecumachdep.h"
- X
- X#define DEFINE_TTY_DATA
- X#include "ecutty.h"
- X
- Xextern uint tcap_LINES;
- Xextern uint tcap_COLS;
- Xextern int LINES;
- Xextern int COLS;
- Xextern char screen_dump_file_name[];
- Xextern char *dash_f_funckeytype;
- X
- Xchar *kde_text();
- X
- Xuint LINESxCOLS;
- Xint current_ttymode = 0;
- Xint ttymode_termecu_on_sigint = 0;
- Xint tty_is_pty;
- Xint tty_is_multiscreen;
- Xint tty_is_scoterm;
- Xint tty_not_char_special;
- Xint tty_use_kbd_sw_flow_control = 1;
- Xint use_colors = 0; /* set by ttyinit, but default no */
- Xchar *ttype; /* getenv("TERM") */
- X
- Xstatic int kbd_test_active = 0;
- Xstatic int ttyinit_has_been_called = 0;
- X
- X#if defined(M_SYSV) || defined(SVR4)
- Xstatic int got_original_colors = 0;
- X
- X#endif
- X
- Xstruct termio tty_termio_at_entry;
- Xstruct termio tty_termio_current;
- Xstruct stat tty_stat;
- Xstruct stat dn;
- Xstruct stat tty01;
- Xstruct stat ttyp0;
- Xstruct stat console;
- X
- Xuchar kbdeof; /* current input EOF */
- Xuchar kbdeol2; /* current secondary input EOL */
- Xuchar kbdeol; /* current input EOL */
- Xuchar kbderase; /* current input ERASE */
- Xuchar kbdintr; /* current input INTR */
- Xuchar kbdkill; /* current input KILL */
- Xuchar kbdquit; /* current input QUIT */
- Xint echo_erase_char; /* save users ECHOE bit */
- Xint echo_kill_char; /* save users ECHOK bit */
- Xchar kbd_is_7bit; /* keyboard has parity */
- Xlong tty_escape_timeout = 40L; /* timeout on waiting for char after ESC */
- X
- Xuchar *dole_out_tgc_accum = (uchar *) 0;
- Xint dole_out_tgc_accum_count = 0;
- X
- X/*
- X * color definitions per format described at top of source
- X * we handle SCO XENIX and UNIX and ISC SVR4 but not "MYSYS"
- X * (search for MYSYS near top of source for clue what MYSYS means)
- X *
- X * As of this writing, I don't know about colors on ISC 2.2.
- X * but they might be the same as for SVR4.
- X *
- X */
- X#ifdef M_SYSV /* SCO */
- Xulong colors_initial = 0x04070A00L; /* default initial colors */
- Xulong colors_current = 0x04070A00L; /* colors set during execution */
- Xulong colors_normal = 0x04070A00L; /* default lt_green/black red/white */
- Xulong colors_success = 0x07000A00L; /* lt_green/black red/white */
- Xulong colors_alert = 0x0E000E00L; /* yellow */
- Xulong colors_error = 0x04000400L; /* red */
- Xulong colors_notify = 0x08000800L; /* gray */
- X#define COLORS_DEFINED
- X#endif /* M_SYSV */
- X
- X#if defined(ISCSVR4) || defined(LINUX) || defined(ESIXSVR4)
- Xulong colors_initial = 0x00002528L;
- Xulong colors_current = 0x00002528L;
- Xulong colors_normal = 0x00002528L; /* white */
- Xulong colors_success = 0x00002028L; /* green */
- Xulong colors_alert = 0x00002128L; /* yellow */
- Xulong colors_error = 0x00001F28L; /* red */
- Xulong colors_notify = 0x00002428L; /* cyan */
- X#define COLORS_DEFINED
- X#endif /* ISCSVR4 */
- X
- X#if 0
- Xulong colors_initial = 0x00003740L;
- Xulong colors_current = 0x00003740L;
- Xulong colors_normal = 0x00003740L; /* ? */
- Xulong colors_success = 0x00003240L; /* ? */
- Xulong colors_alert = 0x00003340L; /* ? */
- Xulong colors_error = 0x00003140L; /* ? */
- Xulong colors_notify = 0x00003640L; /* ? */
- X#define COLORS_DEFINED
- X#endif
- X
- X#if defined(ESIXSVR4) || defined(LINUX)
- Xstatic struct color_remapping
- X{
- X char *name;
- X char ecu_val;
- X char svr4_val;
- X}
- Xcolor_remapping[] =
- X{
- X {
- X "black", 0, 0x00
- X }
- X ,
- X {
- X "blue", 1, 0x04
- X }
- X ,
- X {
- X "brown", 6, 0x03
- X }
- X ,
- X {
- X "cyan", 3, 0x06
- X }
- X ,
- X {
- X "gray", 8, 0x10
- X }
- X ,
- X {
- X "green", 2, 0x02
- X }
- X ,
- X {
- X "hi_white", 15, 0x17
- X }
- X ,
- X {
- X "lt_blue", 9, 0x14
- X }
- X ,
- X {
- X "lt_cyan", 11, 0x16
- X }
- X ,
- X {
- X "lt_green", 10, 0x12
- X }
- X ,
- X {
- X "lt_magenta", 13, 0x15
- X }
- X ,
- X {
- X "lt_red", 12, 0x11
- X }
- X ,
- X {
- X "magenta", 5, 0x05
- X }
- X ,
- X {
- X "red", 4, 0x01
- X }
- X ,
- X {
- X "white", 7, 0x07
- X }
- X ,
- X {
- X "yellow", 14, 0x13
- X }
- X ,
- X 0, 0, 0,
- X};
- X#endif /* ESIXSVR4 */
- X
- X#if !defined(COLORS_DEFINED)
- Xulong colors_current = 1; /* dummy */
- Xulong colors_normal = 2; /* dummy */
- Xulong colors_initial = 3; /* dummy */
- Xulong colors_success = 4; /* dummy */
- Xulong colors_alert = 5; /* dummy */
- Xulong colors_error = 6; /* dummy */
- Xulong colors_notify = 7; /* dummy */
- X#define COLORS_DEFINED
- X#endif /* !COLORS_DEFINED */
- X
- X/*+-------------------------------------------------------------------------
- X B_to_timeout_msec(c_cflag,st_rdev) - CBAUD code to ESC timeout msec
- X--------------------------------------------------------------------------*/
- X/*ARGSUSED*/
- Xulong
- XB_to_timeout_msec(termio_tty, st_rdev)
- Xstruct termio *termio_tty;
- Xushort st_rdev;
- X{
- X long ms = 300L;
- X
- X /* make network/xterm/pty sweat, but don't make as many mistakes */
- X if (tty_is_pty)
- X return (ms);
- X
- X /* if multiscreen, 3 ticks is pu-lenty */
- X if (tty_is_multiscreen)
- X return ((long)(1000 / hz * 3));
- X
- X /* baud rate fiddling */
- X switch (ecugetspeed(termio_tty))
- X {
- X /* char times * time/char */
- X case B110:
- X ms = 10 * 100;
- X case B300:
- X ms = 10 * 33;
- X case B600:
- X ms = 10 * 16;
- X case B1200:
- X ms = 10 * 8;
- X case B2400:
- X ms = 10 * 4;
- X default: /* many character times for packetized ... */
- X ms = 400L; /* ... modems used for console */
- X }
- X return (ms);
- X
- X} /* end of B_to_timeout_msec */
- X
- X/*+-------------------------------------------------------------------------
- X color_name_to_num(cname)
- X--------------------------------------------------------------------------*/
- Xint
- Xcolor_name_to_num(cname)
- Xchar *cname;
- X{
- X register COLOR *color = colors;
- X register itmp;
- X
- X while (color->name)
- X {
- X if ((itmp = strcmp(color->name, cname)) > 0)
- X return (-1);
- X if (!itmp)
- X return (color->num);
- X color++;
- X }
- X return (-1);
- X
- X} /* end of color_name_to_num */
- X
- X/*+-------------------------------------------------------------------------
- X _setcolor(clrs)
- X--------------------------------------------------------------------------*/
- Xvoid
- X_setcolor(clrs)
- Xulong clrs;
- X{
- X#if defined(ESIXSVR4) || defined(LINUX)
- X struct color_remapping *cr;
- X
- X#endif
- X#if defined(SVR4) || defined(LINUX)
- X char fgcolor;
- X char bgcolor;
- X
- X#endif /* SVR4 || LINUX */
- X
- X if (!use_colors || tty_not_char_special)
- X return;
- X
- X#if defined(SVR4) || defined(LINUX)
- X#if defined(ESIXSVR4) || defined(LINUX)
- X /* set foreground color */
- X fgcolor = (clrs >> 8) & 0xff;
- X for (cr = color_remapping; cr->name; ++cr)
- X {
- X if (fgcolor == cr->ecu_val)
- X {
- X fgcolor = cr->svr4_val;
- X break;
- X }
- X }
- X if (!cr->name)
- X {
- X fgcolor = 0x07; /* white */
- X }
- X if (fgcolor & 0x10)
- X {
- X fgcolor &= ~0x10;
- X ff(se, "\033[1;3%d;m", fgcolor);
- X }
- X else
- X {
- X ff(se, "\033[0;3%d;m", fgcolor);
- X }
- X
- X /* set background color */
- X bgcolor = clrs & 0xff;
- X for (cr = color_remapping; cr->name; ++cr)
- X {
- X if (bgcolor == cr->ecu_val)
- X {
- X bgcolor = cr->svr4_val;
- X break;
- X }
- X }
- X if (!cr->name)
- X {
- X bgcolor = 0x00; /* black */
- X }
- X if (bgcolor & 0x10)
- X {
- X bgcolor &= ~0x10;
- X ff(se, "\033[5;3%d;m", bgcolor);
- X }
- X else
- X {
- X ff(se, "\033[0;3%d;m", bgcolor);
- X }
- X#else /* ISC SVR4 */
- X /* normal */
- X fgcolor = (clrs >> 8) & 0xff;
- X bgcolor = clrs & 0xff;
- X ff(se, "\033[%d;%dm", fgcolor, bgcolor);
- X#endif /* ESIXSVR4 */
- X#else /* not any SVR4 */
- X#ifdef M_SYSV /* SCO */
- X /* normal */
- X ff(se, "\033[=%ldF\033[=%ldG", (clrs >> 8) & 0xFF, clrs & 0xFF);
- X
- X /* reverse */
- X ff(se, "\033[=%ldH\033[=%ldI", (clrs >> 24) & 0xFF, (clrs >> 16) & 0xFF);
- X#endif /* M_SYSV */
- X#endif /* SVR4 */
- X colors_current = clrs;
- X} /* end of _setcolor */
- X
- X/*+-------------------------------------------------------------------------
- X setcolor(new_colors)
- X
- Xrequires termcap init to have been done
- X--------------------------------------------------------------------------*/
- Xvoid
- Xsetcolor(new_colors)
- Xulong new_colors;
- X{
- X if (tty_not_char_special)
- X return;
- X
- X if (!use_colors)
- X {
- X if (new_colors == colors_notify)
- X tcap_underscore_on();
- X else if (new_colors == colors_alert)
- X tcap_bold_on();
- X else if (new_colors == colors_error)
- X tcap_stand_out();
- X#ifdef WHT
- X else if (new_colors == colors_success)
- X {
- X tcap_underscore_on();
- X tcap_bold_on();
- X }
- X#endif
- X else
- X {
- X tcap_underscore_off();
- X tcap_bold_off();
- X tcap_stand_end();
- X }
- X return;
- X }
- X _setcolor(new_colors);
- X#ifndef LINUX
- X tcap_stand_end();
- X#endif
- X} /* end of setcolor */
- X
- X/*+-------------------------------------------------------------------------
- X setcolor_internal(ntokens,tokens)
- X
- Xreturns 0 on success, else token number in error + 1
- X--------------------------------------------------------------------------*/
- Xint
- Xsetcolor_internal(ntokens, tokens)
- Xint ntokens;
- Xchar **tokens;
- X{
- X ulong fgnd;
- X ulong bgnd;
- X
- X if (tty_not_char_special || !use_colors)
- X return (0);
- X
- X if (ntokens < 2)
- X return (1);
- X else if (ntokens == 2)
- X tokens[2] = "black";
- X
- X if ((fgnd = (ulong) color_name_to_num(tokens[1])) > 15)
- X return (2);
- X if ((bgnd = (ulong) color_name_to_num(tokens[2])) > 15)
- X return (3);
- X
- X if (!strcmp(tokens[0], "normal"))
- X {
- X colors_normal &= 0xFFFF0000L;
- X colors_normal |= (fgnd << 8) | bgnd;
- X setcolor(colors_normal);
- X }
- X else if (!strcmp(tokens[0], "reverse"))
- X {
- X colors_normal &= 0x0000FFFFL;
- X colors_normal |= (fgnd << 24) | (bgnd << 16);
- X setcolor(colors_normal);
- X }
- X else if (!strcmp(tokens[0], "notify"))
- X colors_notify = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
- X else if (!strcmp(tokens[0], "success"))
- X colors_success = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
- X else if (!strcmp(tokens[0], "alert"))
- X colors_alert = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
- X else if (!strcmp(tokens[0], "error"))
- X colors_error = (fgnd << 24) | (bgnd << 16) | (fgnd << 8) | bgnd;
- X else
- X return (1);
- X
- X return (0);
- X
- X} /* end of setcolor_internal */
- X
- X/*+-------------------------------------------------------------------------
- X restore_initial_colors() - make screen safe
- X
- XOn SCO, restore color choices at execution time if we successfully
- Xgot them from the driver; in other situations, use tcap to reset.
- X--------------------------------------------------------------------------*/
- Xvoid
- Xrestore_initial_colors()
- X{
- X#if defined(M_SYSV) || defined(SVR4)
- X if (use_colors && got_original_colors)
- X setcolor(colors_initial);
- X else
- X#endif
- X {
- X tcap_blink_off();
- X tcap_bold_off();
- X tcap_underscore_off();
- X }
- X} /* end of restore_initial_colors */
- X
- X/*+-------------------------------------------------------------------------
- X get_initial_colors() - read colors at time of execution from driver
- X
- X 00000000001111111111222222222233
- X 01234567890123456789012345678901
- X 0000|--|0000|--|0000|--|0000|--|
- X fg bk fg bk
- X reverse normal
- X
- X--------------------------------------------------------------------------*/
- X#if defined(M_SYSV)
- Xvoid
- Xget_initial_colors()
- X{
- X uint cur_attr;
- X ulong fgnd;
- X ulong bgnd;
- X
- X colors_initial = colors_normal; /* scoterm can use color but ... */
- X if (ioctl(TTYIN, GIO_ATTR, 0) == -1) /* ... GIO_ATTR won't work */
- X return;
- X colors_normal = 0L;
- X
- X/*
- X * first, reverse, so we can end up with normal colors selected
- X */
- X write(1, "\033[7m", 4); /* select reverse */
- X cur_attr = (uint) ioctl(TTYIN, GIO_ATTR, 0);
- X fgnd = (ulong) cur_attr & 0x0F;
- X bgnd = (ulong) (cur_attr >> 4) & 0x0F;
- X colors_normal |= (fgnd << 24) | (bgnd << 16);
- X
- X/*
- X * now, normal
- X */
- X write(1, "\033[m", 3); /* select normal */
- X cur_attr = (uint) ioctl(TTYIN, GIO_ATTR, 0);
- X fgnd = (ulong) cur_attr & 0x0F;
- X bgnd = (ulong) (cur_attr >> 4) & 0x0F;
- X colors_normal |= (fgnd << 8) | bgnd;
- X
- X colors_initial = colors_normal; /* save for restore_initial_colors */
- X got_original_colors = 1;
- X
- X} /* end of get_initial_colors */
- X#endif
- X
- X/*+-------------------------------------------------------------------------
- X read_colors_file() - read color definition if present
- X--------------------------------------------------------------------------*/
- Xvoid
- Xread_colors_file()
- X{
- X FILE *fp;
- X char s128[128];
- X
- X#define MAX_COLOR_TOKENS 6
- X char *tokens[MAX_COLOR_TOKENS];
- X int ntokens;
- X char *cptr;
- X int itmp;
- X
- X if (tty_not_char_special)
- X return;
- X
- X#if defined(M_SYSV)
- X get_initial_colors();
- X#endif
- X
- X get_home_dir(s128);
- X strcat(s128, "/.ecu/colors");
- X
- X if (!(fp = fopen(s128, "r")))
- X {
- X strcpy(s128, eculibdir);
- X strcat(s128, "/colors");
- X if (!(fp = fopen(s128, "r")))
- X return;
- X }
- X
- X while (fgets(s128, sizeof(s128), fp))
- X {
- X if (itmp = strlen(s128)) /* itmp = len; if > 0 ... */
- X {
- X itmp--;
- X s128[itmp] = 0; /* ... strip trailing NL */
- X }
- X if (cptr = strchr(s128, '#')) /* comment? */
- X *cptr = 0;
- X cptr = s128; /* first call to str_token, -> buff */
- X while ((*cptr == 0x20) || (*cptr == TAB))
- X cptr++; /* strip leading spaces */
- X if (*cptr == 0) /* if line all blank, skip it */
- X continue;
- X
- X build_arg_array(s128, tokens, MAX_COLOR_TOKENS, &ntokens);
- X if (ntokens < 2)
- X continue;
- X
- X setcolor_internal(ntokens, tokens);
- X
- X } /* while records left to ready */
- X
- X#if defined(M_SYSV)
- X if (ioctl(TTYIN, GIO_ATTR, 0) == -1)
- X colors_initial = colors_normal; /* hack for scoterm */
- X#endif
- X
- X fclose(fp);
- X} /* end of read_colors_file */
- X
- X/*+-------------------------------------------------------------------------
- X ring_bell()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xring_bell()
- X{
- X char b = BEL;
- X
- X if (tty_not_char_special)
- X return;
- X write(TTYOUT, &b, 1);
- X
- X} /* end of ring_bell */
- X
- X/*+-------------------------------------------------------------------------
- X termio_to_kbd_chars()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xtermio_to_kbd_chars()
- X{
- X kbdintr = (tty_termio_at_entry.c_cc[VINTR])
- X ? (tty_termio_at_entry.c_cc[VINTR] & 0x7F) : '\377';
- X kbdquit = (tty_termio_at_entry.c_cc[VQUIT])
- X ? (tty_termio_at_entry.c_cc[VQUIT] & 0x7F) : '\377';
- X kbderase = (tty_termio_at_entry.c_cc[VERASE])
- X ? (tty_termio_at_entry.c_cc[VERASE] & 0x7F) : '\377';
- X kbdkill = (tty_termio_at_entry.c_cc[VKILL])
- X ? (tty_termio_at_entry.c_cc[VKILL] & 0x7F) : '\377';
- X kbdeof = (tty_termio_at_entry.c_cc[VEOF])
- X ? (tty_termio_at_entry.c_cc[VEOF] & 0x7F) : '\04';
- X kbdeol2 = (tty_termio_at_entry.c_cc[VEOL])
- X ? (tty_termio_at_entry.c_cc[VEOL] & 0x7F) : '\377';
- X kbdeol = (tty_termio_at_entry.c_iflag & ICRNL)
- X ? '\r' : '\n';
- X
- X kbd_is_7bit = ((tty_termio_at_entry.c_cflag & PARENB) != 0);
- X echo_erase_char = tty_termio_at_entry.c_lflag & ECHOE;
- X echo_kill_char = tty_termio_at_entry.c_lflag & ECHOK;
- X
- X} /* end of termio_to_kbd_chars */
- X
- X/*+-------------------------------------------------------------------------
- X ttyinit(param)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xttyinit(param)
- Xuchar param;
- X{
- X int fddevtty;
- X int itmp;
- X char *ftype;
- X
- X#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)
- X int monitor_type;
- X int cons_get_err;
- X
- X#endif
- X
- X ttype = getenv("TERM"); /* must do this first */
- X
- X /*
- X * get control tty control chars in case stdin not tty
- X */
- X if ((fddevtty = open("/dev/tty", O_RDONLY, 0)) >= 0)
- X {
- X ecugetattr(fddevtty, &tty_termio_at_entry);
- X close(fddevtty);
- X termio_to_kbd_chars();
- X }
- X
- X sigint = 0; /* see xmtr signal handlers */
- X
- X memset((char *)&tty_stat, 0xFF, sizeof(struct stat));
- X memset((char *)&ttyp0, 0xFF, sizeof(struct stat));
- X memset((char *)&console, 0xFF, sizeof(struct stat));
- X
- X stat("/dev/console", &console);
- X stat("/dev/null", &dn);
- X stat("/dev/tty01", &tty01);
- X stat("/dev/ttyp0", &ttyp0);
- X
- X /*
- X * if stdin not open or is /dev/null or is non-character-device
- X */
- X
- X itmp = fstat(TTYIN, &tty_stat);
- X if (itmp || ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
- X ((dn.st_ino == tty_stat.st_ino) && (dn.st_rdev == tty_stat.st_rdev)))
- X {
- X tcap_LINES = LINES = 25; /* fake necessary termcap/curses vars */
- X tcap_COLS = COLS = 80;
- X LINESxCOLS = tcap_LINES * tcap_COLS;
- X shm->scr_lines = tcap_LINES;
- X shm->scr_cols = tcap_COLS;
- X shm->scr_size = LINESxCOLS;
- X
- X tty_not_char_special = 1;
- X tty_is_multiscreen = 0;
- X return;
- X }
- X
- X /*
- X * if pty
- X */
- X if ((tty_stat.st_rdev & 0xFF00) == (ttyp0.st_rdev & 0xFF00))
- X tty_is_pty = 1;
- X
- X /*
- X * use color if we are on a display that supports it and we know how
- X * :-|
- X */
- X use_colors = 0;
- X
- X#if defined(CONS_GET) && defined(MONO) && defined(USE_COLOR)
- X if (((cons_get_err = ioctl(TTYIN, CONS_GET, &monitor_type)) >= 0) &&
- X (use_colors = (monitor_type != MONO)))
- X {
- X read_colors_file();
- X setcolor(colors_normal);
- X }
- X
- X#endif /* CONS_GET && MONO && USE_COLOR */
- X
- X /*
- X * remember whether or not we are on a multiscreen
- X */
- X#ifdef LINUX
- X tty_is_multiscreen = 1;
- X use_colors = 1;
- X tty_not_char_special = 0;
- X read_colors_file();
- X setcolor(colors_normal);
- X#endif
- X#if defined(M_SYSV) /* for multiscreen and scoterm */
- X tty_is_multiscreen = !(cons_get_err < 0);
- X
- X /*
- X * a fuzzy heuristic for scoterm: 1. presence of WINDOWID and 2. first
- X * four characters of $TERM == "ansi"
- X */
- X if (getenv("WINDOWID") && ttype && !strncmp(ttype, "ansi", 4))
- X {
- X use_colors = 1;
- X tty_is_scoterm = 1;
- X read_colors_file();
- X setcolor(colors_normal);
- X }
- X#endif /* M_SYSV multiscreen and scoterm */
- X
- X /*
- X * save initial tty state
- X */
- X ecugetattr(TTYIN, &tty_termio_at_entry);
- X tty_escape_timeout =
- X B_to_timeout_msec(&tty_termio_at_entry, tty_stat.st_rdev);
- X
- X termio_to_kbd_chars();
- X
- X tty_termio_current = tty_termio_at_entry;
- X current_ttymode = 0;
- X
- X get_home_dir(screen_dump_file_name);
- X strcat(screen_dump_file_name, "/.ecu/screen.dump");
- X
- X ftype = 0;
- X if (dash_f_funckeytype)
- X ftype = dash_f_funckeytype;
- X else
- X ftype = getenv("ECUFUNCKEY");
- X#ifdef WHT
- X if (!ftype && !strcmp(ttype, "vt100"))
- X ftype = "rterm";
- X#endif
- X if (ttype || ftype)
- X funckeymap_read((ftype) ? ftype : ttype);
- X
- X /* initialize termcap */
- X tcap_init(); /* read termcap strings */
- X
- X /* yetch - magic number gretching for lines and columns */
- X if (tcap_LINES < 20)
- X {
- X ff(se, "\7screen height must be >= 20 lines (found %dx%d).\r\n",
- X tcap_COLS, tcap_LINES);
- X termecu(TERMECU_GEOMETRY);
- X }
- X if (tcap_LINES > SCREEN_LINES_MAX)
- X {
- X ff(se, "\7screen height limited to %d lines (found %dx%d).\r\n",
- X SCREEN_LINES_MAX, tcap_COLS, tcap_LINES);
- X termecu(TERMECU_GEOMETRY);
- X }
- X if (tcap_COLS != SCREEN_COLS_MAX)
- X {
- X ff(se, "\7terminal width must be %d columns (found %dx%d).\r\n",
- X SCREEN_COLS_MAX, tcap_COLS, tcap_LINES);
- X termecu(TERMECU_GEOMETRY);
- X }
- X LINESxCOLS = tcap_LINES * tcap_COLS;
- X shm->scr_lines = tcap_LINES;
- X shm->scr_cols = tcap_COLS;
- X shm->scr_size = LINESxCOLS;
- X ttyinit_has_been_called = 1;
- X
- X} /* end of ttyinit */
- X
- X/*+-----------------------------------------------------------------------
- X ttymode(arg) -- control user console (kbd/screen)
- X
- X Where arg ==
- X 0 restore attributes saved at start of execution
- X 1 raw mode (send xon/xoff, but do not respond to it, no ISIG/SIGINT)
- X 2 raw mode (same as 1 but allow keyboard interrupts)
- X 3 same as 2 but terminate program on SIGINT
- X 4 terminate ecu on sigint
- X
- X------------------------------------------------------------------------*/
- Xvoid
- Xttymode(arg)
- Xint arg;
- X{
- X
- X /*
- X * ignore if no keyboard involved
- X */
- X if (tty_not_char_special)
- X return;
- X
- X /*
- X * usage()->termecu()->ttymode() is possible before ttyinit()
- X */
- X if (!ttyinit_has_been_called)
- X return;
- X
- X switch (arg)
- X {
- X case 0:
- X ecusetattr(TTYIN, TCSETAW, &tty_termio_at_entry);
- X tty_termio_current = tty_termio_at_entry;
- X current_ttymode = 0;
- X ttymode_termecu_on_sigint = 0;
- X break;
- X
- X case 1:
- X case 2:
- X case 3:
- X case 4:
- X tty_termio_current = tty_termio_at_entry;
- X
- X tty_termio_current.c_cflag &= ~(PARENB | PARODD);
- X tty_termio_current.c_cflag |= CS8;
- X
- X /* don't want to honor tty xon/xoff, but pass to other end */
- X#if defined(CFG_TermiosLineio)
- X tty_termio_current.c_iflag &= ~(INLCR | ICRNL | IGNCR | ISTRIP);
- X tty_termio_current.c_oflag &= ~(ONLCR);
- X#else
- X tty_termio_current.c_iflag &= ~(INLCR | ICRNL | IGNCR | IUCLC | ISTRIP);
- X tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
- X#endif
- X tty_termio_current.c_oflag |= OPOST;
- X
- X if (tty_use_kbd_sw_flow_control)
- X tty_termio_current.c_iflag |= IXON | IXOFF;
- X else
- X tty_termio_current.c_iflag &= ~(IXON | IXOFF);
- X
- X tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
- X if (arg > 1)
- X tty_termio_current.c_lflag |= ISIG;
- X
- X tty_termio_current.c_cc[VMIN] = 1;
- X tty_termio_current.c_cc[VTIME] = 0;
- X
- X ecusetattr(TTYIN, TCSETAW, &tty_termio_current);
- X current_ttymode = arg;
- X ttymode_termecu_on_sigint = (arg == 4);
- X break;
- X
- X default:
- X ff(se, "\r\nttymode: invalid argument %d\r\n", arg);
- X break;
- X }
- X
- X} /* end of ttymode */
- X
- X/*+-------------------------------------------------------------------------
- X int get_ttymode()
- X--------------------------------------------------------------------------*/
- Xint
- Xget_ttymode()
- X{
- X return (current_ttymode);
- X} /* end of get_ttymode */
- X
- X/*+-----------------------------------------------------------------------
- X ttyflush(flush_type) -- flush tty driver input &/or output buffers
- X
- X0 == input buffer
- X1 == output buffer
- X2 == both buffers
- X------------------------------------------------------------------------*/
- Xvoid
- Xttyflush(flush_type)
- Xint flush_type;
- X{
- X if (tty_not_char_special)
- X return;
- X
- X ecuflow(TTYIN, TCOOFF);
- X
- X#if !defined(M_I286)
- X ecuflush(TTYIN, flush_type);
- X#else
- X /* avoid 286 compiler warning of cast int to far ptr */
- X switch (flush_type)
- X {
- X case 0:
- X ioctl(TTYIN, TCFLSH, (char *)0);
- X break;
- X case 1:
- X ioctl(TTYIN, TCFLSH, (char *)1);
- X break;
- X case 2:
- X ioctl(TTYIN, TCFLSH, (char *)2);
- X break;
- X }
- X#endif
- X
- X ecuflow(TTYIN, TCOON);
- X
- X if (flush_type != 1)
- X {
- X dole_out_tgc_accum = (uchar *) 0;
- X dole_out_tgc_accum_count = 0;
- X }
- X
- X} /* end of ttyflush */
- X
- X/*+-------------------------------------------------------------------------
- X ttyrdchk() - see if key pressed and not read
- X--------------------------------------------------------------------------*/
- Xint
- Xttyrdchk()
- X{
- X return (rdchk(TTYIN) || dole_out_tgc_accum_count);
- X} /* end of ttyrdchk */
- X
- X/*+-------------------------------------------------------------------------
- X ttygetc(xkey_ok) -- get a key from the keyboard
- Xif UNIX or XENIX, map extended keys to sign-bit-set special value
- Xif xkey_ok is 0, disallow extended keys
- X--------------------------------------------------------------------------*/
- Xuint
- Xttygetc(xkey_ok)
- Xint xkey_ok;
- X{
- X uchar ctmp;
- X extern int errno;
- X register uint itmp = 0;
- X long timeout_remaining;
- X static uchar tgc_accum[16];
- X uchar funckeymap();
- X
- X if (tty_not_char_special)/* this really is unexplored territory */
- X {
- X ctmp = 255;
- X read(TTYIN, (char *)&ctmp, 1);
- X return ((uint) ctmp);
- X }
- X
- X if (dole_out_tgc_accum_count)
- X {
- X ctmp = *dole_out_tgc_accum++;
- X dole_out_tgc_accum_count--;
- X if (kbd_is_7bit)
- X ctmp &= 0x7F;
- X return ((uint) ctmp);
- X }
- X
- X GET_KEY:
- X errno = 0;
- X if (read(TTYIN, (char *)&ctmp, 1) < 0)
- X {
- X if (errno == EINTR)
- X goto GET_KEY;
- X perror_errmsg("keyboard");
- X termecu(TERMECU_TTYIN_READ_ERROR);
- X }
- X
- X if (((ctmp >= 0x01) && (ctmp <= 0x1F) ||
- X (ctmp >= 0x81) && (ctmp <= 0x9F)) &&
- X (ctmp != kbderase) && (ctmp != kbdkill) &&
- X (ctmp != kbdeol) && (ctmp != kbdeol2) &&
- X (ctmp != kbdintr) && (ctmp != kbdeof))
- X {
- X tgc_accum[0] = ctmp;
- X tgc_accum[itmp = 1] = 0;
- X timeout_remaining = tty_escape_timeout;
- X#if defined(NAP_DEBUG)
- X ff(se, "timeout_remaining = %ld hzmsec=%ld\r\n",
- X timeout_remaining, hzmsec);
- X#endif
- X while (((ctmp = funckeymap(tgc_accum, itmp)) >= XF_no_way) &&
- X (timeout_remaining > 0))
- X {
- X timeout_remaining -= Nap(hzmsec);
- X#if defined(NAP_DEBUG)
- X ff(se, "timeout_remaining = %ld\r\n", timeout_remaining);
- X#endif
- X if (!rdchk(TTYIN))
- X continue;
- X read(TTYIN, (char *)&ctmp, 1);
- X if (itmp == (sizeof(tgc_accum) - 1)) /* do not allow overflow */
- X {
- X ctmp = XF_no_way;
- X break;
- X }
- X timeout_remaining = tty_escape_timeout;
- X tgc_accum[itmp++] = ctmp;
- X }
- X tgc_accum[itmp] = 0;
- X if ((ctmp == XF_not_yet) && (itmp == 1))
- X {
- X if (kbd_is_7bit)
- X tgc_accum[0] &= 0x7F;
- X return ((uint) tgc_accum[0]);
- X }
- X else if (ctmp < XF_no_way) /* if we got a map */
- X {
- X if (kbd_test_active)
- X {
- X char title[128];
- X
- X sprintf(title, "--> func key '%s' (%d key codes received)",
- X kde_text(ctmp), itmp);
- X hex_dump(tgc_accum, -itmp, title, 1);
- X }
- X if (!xkey_ok)
- X {
- X ring_bell();
- X goto GET_KEY;
- X }
- X switch (ctmp)
- X {
- X case IKDE_CU5:
- X screen_dump(screen_dump_file_name);
- X goto GET_KEY;
- X default:
- X return ((uint) ikde_to_xf(ctmp));
- X }
- X /* NOTREACHED */
- X }
- X /* not func key -- must be typamatic control key */
- X if (kbd_test_active)
- X {
- X char title[128];
- X
- X if (itmp > 1)
- X {
- X sprintf(title,
- X "--> no func key recognized (%d key codes received)",
- X itmp);
- X hex_dump(tgc_accum, -itmp, title, 1);
- X }
- X }
- X dole_out_tgc_accum_count = itmp - 1;
- X dole_out_tgc_accum = tgc_accum + 1;
- X if (kbd_is_7bit)
- X tgc_accum[0] &= 0x7F;
- X return ((uint) tgc_accum[0]);
- X }
- X
- X /*
- X * simple key, not special
- X */
- X ctmp &= 0x7F;
- X
- X#if 0 /* not necessary I think, but leave marker
- X * for further if wrong --wht */
- X#ifdef LINUX
- X /* make backspace key really backspace */
- X if (ctmp == kbderase)
- X ctmp = 0x08;
- X#endif /* LINUX */
- X#endif
- X
- X return ((uint) ctmp);
- X
- X} /* end if ttygetc */
- X
- X/*+-----------------------------------------------------------------------
- X ttygets(str,maxsize,flags,delim,pstrpos)
- X
- Xflags & TG_CRLF - echo cr/lf terminator
- Xflags & TG_XDELIM - extended delimiter set
- X (Home, End, PgUp, PgDn, CurUp, CurDn)
- Xflags & TG_EDIT - redisplay/edit current string
- Xflags & TG_IPOS - if edit, use initial string pos
- X------------------------------------------------------------------------*/
- Xvoid
- Xttygets(str, maxsize, flags, delim, pstrpos)
- Xregister char *str;
- Xint maxsize;
- Xint flags;
- Xuchar *delim;
- Xint *pstrpos;
- X{
- X register inch;
- X char ch;
- X int strcount = 0;
- X int strpos = 0;
- X int insert_mode = 0;
- X char *bs_str = "\010 \010";
- X
- X --maxsize; /* decrement for safety */
- X
- X if (flags & TG_EDIT)
- X {
- X strpos = strcount = strlen(str);
- X write(TTYOUT, str, strcount);
- X if (pstrpos && (*pstrpos > 0) && (*pstrpos <= strcount))
- X strpos = *pstrpos;
- X tcap_curleft(strcount - strpos);
- X }
- X
- X while (1)
- X {
- X inch = ttygetc(1);
- X *delim = (uchar) inch; /* last char will always be the delimiter */
- X if ((inch == kbdintr) || (inch == ESC))
- X {
- X tcap_curright(strcount - strpos);
- X while (strcount)
- X {
- X write(TTYOUT, bs_str, strlen(bs_str));
- X strcount--;
- X }
- X str[strcount] = 0;
- X *delim = ESC;
- X goto FUNC_RETURN;
- X }
- X else if (inch == kbdkill)
- X {
- X tcap_curright(strcount - strpos);
- X while (strcount)
- X {
- X write(TTYOUT, bs_str, strlen(bs_str));
- X strcount--;
- X }
- X strpos = 0;
- X *str = 0;
- X continue;
- X }
- X else if (inch == kbderase)
- X {
- X if (strcount)
- X {
- X if (strcount == strpos)
- X {
- X write(TTYOUT, bs_str, strlen(bs_str));
- X strcount--, strpos--;
- X }
- X else
- X {
- X if (!strpos)
- X continue;
- X mem_cpy(str + strpos - 1, str + strpos, strcount - strpos);
- X write(TTYOUT, "\010", 1);
- X str[--strcount] = 0;
- X strpos--;
- X write(TTYOUT, str + strpos, strlen(str + strpos));
- X write(TTYOUT, " ", 1);
- X tcap_curleft(strcount - strpos + 1);
- X }
- X }
- X str[strcount] = 0;
- X continue;
- X }
- X else if (inch == XFins)
- X {
- X insert_mode = !insert_mode;
- X continue;
- X }
- X else if (inch == XFcurlf)
- X {
- X if (strpos)
- X {
- X strpos--;
- X tcap_curleft(1);
- X }
- X continue;
- X }
- X else if (inch == XFcurrt)
- X {
- X if (strpos < strcount)
- X {
- X strpos++;
- X tcap_curright(1);
- X }
- X continue;
- X }
- X
- X if (flags & TG_XDELIM) /* extended delimiter */
- X {
- X switch (inch)
- X {
- X case XFhome:
- X case XFend:
- X case XFpgup:
- X case XFpgdn:
- X case XFcurup:
- X case XFcurdn:
- X#ifdef notdef
- X tcap_curright(strcount - strpos);
- X while (strcount)
- X {
- X write(TTYOUT, bs_str, strlen(bs_str));
- X strcount--;
- X }
- X#endif
- X str[strcount] = 0;
- X goto FUNC_RETURN;
- X }
- X }
- X
- X switch (inch)
- X {
- X case CRET:
- X *delim = NL;
- X case NL:
- X str[strcount] = 0;
- X tcap_curright(strcount - strpos);
- X if ((flags & TG_CRLF))
- X ff(se, "\r\n");
- X goto FUNC_RETURN;
- X
- X case CTL_L:
- X case CTL_R:
- X tcap_curright(strcount - strpos);
- X ff(se, "%s (insert mode %s)\r\n", make_char_graphic(inch, 0),
- X (insert_mode) ? "ON" : "OFF");
- X tcap_eeol();
- X write(TTYOUT, str, strcount);
- X tcap_curleft(strcount - strpos);
- X break;
- X
- X default:
- X if ((inch < SPACE) || (inch >= 0x7F))
- X {
- X ring_bell();
- X break;
- X }
- X if (strpos == strcount)
- X {
- X if (strcount == maxsize)
- X {
- X ring_bell();
- X continue;
- X }
- X str[strcount++] = inch;
- X strpos++;
- X ch = (char)inch;
- X write(TTYOUT, &ch, 1);
- X }
- X else
- X {
- X if (insert_mode)
- X {
- X if (strcount == maxsize)
- X {
- X ring_bell();
- X continue;
- X }
- X mem_cpy(str + strpos + 1, str + strpos, strcount - strpos);
- X str[strpos] = inch;
- X strcount++;
- X str[strcount] = 0;
- X write(TTYOUT, str + strpos, strcount - strpos);
- X strpos++;
- X tcap_curleft(strcount - strpos);
- X }
- X else
- X {
- X str[strpos++] = inch;
- X ch = (char)inch;
- X write(TTYOUT, &ch, 1);
- X }
- X }
- X str[strcount] = 0;
- X }
- X }
- X
- X FUNC_RETURN:
- X if (pstrpos)
- X *pstrpos = strpos;
- X
- X} /* end of ttygets() */
- X
- X/*+-------------------------------------------------------------------------
- X ttygets_esd(tesd,flags,append_flag)
- X--------------------------------------------------------------------------*/
- Xttygets_esd(tesd, flags, append_flag)
- XESD *tesd;
- Xint flags;
- Xint append_flag;
- X{
- X char *pb = tesd->pb;
- X int maxcb = tesd->maxcb;
- X uchar delim;
- X
- X if (append_flag)
- X {
- X pb += tesd->cb;
- X maxcb -= tesd->cb;
- X }
- X else
- X {
- X pb = tesd->pb;
- X maxcb = tesd->maxcb;
- X tesd->cb = 0;
- X }
- X
- X ttygets(pb, maxcb, flags, &delim, (int *)0);
- X
- X if (delim == ESC)
- X {
- X if (!append_flag)
- X esdzero(tesd);
- X return (eProcAttn_ESCAPE);
- X }
- X
- X tesd->cb = strlen(tesd->pb);
- X plogs(pb);
- X if (flags & 1)
- X plogc(NL);
- X return (0);
- X
- X} /* end of ttygets_esd */
- X
- X/*+-------------------------------------------------------------------------
- X kbd_test() - test keyboard handler
- X--------------------------------------------------------------------------*/
- Xvoid
- Xkbd_test()
- X{
- X uint ctmp = 0;
- X
- X pputs("Press keys to test (ESCape to exit)\n");
- X kbd_test_active = 1;
- X while (ctmp != ESC)
- X {
- X ctmp = ttygetc(1);
- X
- X if ((ctmp < 0x80) && dole_out_tgc_accum_count)
- X {
- X pprintf(" got %d key sequence %s ",
- X dole_out_tgc_accum_count + 1, hex_to_ascii_name(ctmp));
- X while (dole_out_tgc_accum_count)
- X {
- X pprintf("%s ", hex_to_ascii_name(*dole_out_tgc_accum++));
- X dole_out_tgc_accum_count--;
- X }
- X pputs("\n");
- X ctmp = 0;
- X continue;
- X }
- X pputs(" got ");
- X if (ctmp >= 0x80)
- X pprintf("fkey '%s'\n", xf_text(ctmp));
- X else
- X pprintf("key '%s'\n", hex_to_ascii_name(ctmp));
- X }
- X kbd_test_active = 0;
- X ttyflush(0);
- X pputs("keyboard test complete\n\n");
- X dole_out_tgc_accum = (uchar *) 0;
- X dole_out_tgc_accum_count = 0;
- X
- X} /* end of kbd_test */
- X
- X/*+-------------------------------------------------------------------------
- X char *get_ttyname() - return pointer to static string
- X
- XThis routine is largely a crock and is likely to explode at any rev or twist
- X--------------------------------------------------------------------------*/
- Xchar *
- Xget_ttyname()
- X{
- X#ifndef OLD_WAY
- X char *ttyname();
- X
- X return (ttyname(TTYIN));
- X#else
- X static char ttname[64];
- X register unsigned int rdev;
- X register char *cptr;
- X
- X if (tty_not_char_special)
- X return ("stdin");
- X else if (!tty_is_multiscreen)
- X return ("non-multiscreen");
- X
- X rdev = (unsigned)tty_stat.st_rdev;
- X if (rdev == 0x0301)
- X strcpy(ttname, "/dev/console");
- X#if defined(M_UNIX)
- X else if (rdev == 0x0000)
- X strcpy(ttname, "/dev/syscon");
- X#endif
- X else
- X {
- X strcpy(ttname, "/dev/tty");
- X cptr = ttname + 8;
- X
- X if (rdev < 0x000C)
- X {
- X *cptr++ = '0' + ((rdev + 1) / 10);
- X *cptr++ = '0' + ((rdev + 1) % 10);
- X }
- X else if (!(rdev & ~0x58F))
- X {
- X *cptr++ = (rdev & 0x0008) ? '2' : '1';
- X *cptr++ = ((rdev & 0x0080) ? 'A' : 'a') + (rdev & 0x0007);
- X }
- X else
- X {
- X *cptr++ = '?';
- X *cptr++ = '?';
- X }
- X *cptr = 0;
- X }
- X
- X return (ttname);
- X#endif
- X} /* end of get_ttyname */
- X
- X/*+-------------------------------------------------------------------------
- X set_console_xon_xoff_by_arg(arg)
- X--------------------------------------------------------------------------*/
- Xint
- Xset_console_xon_xoff_by_arg(arg)
- Xchar *arg;
- X{
- X int new_xon_xoff = 0;
- X
- X if (ulcmpb(arg, "on") < 0)
- X {
- X new_xon_xoff = IXON | IXOFF;
- X tty_use_kbd_sw_flow_control = 1;
- X }
- X else if (ulcmpb(arg, "off") < 0)
- X {
- X new_xon_xoff = 0;
- X tty_use_kbd_sw_flow_control = 0;
- X }
- X else
- X return (-1);
- X
- X tty_termio_current.c_iflag &= ~(IXON | IXOFF);
- X tty_termio_current.c_iflag |= new_xon_xoff;
- X ecusetattr(TTYIN, TCSETA, &tty_termio_current);
- X return (0);
- X
- X} /* end of set_console_xon_xoff_by_arg */
- X
- X/*+-------------------------------------------------------------------------
- X console_xon_status()
- X--------------------------------------------------------------------------*/
- Xchar *
- Xconsole_xon_status()
- X{
- X if (tty_use_kbd_sw_flow_control)
- X return ("HONOR ^S/^Q locally");
- X else
- X return ("PASS ^S/^Q to remote");
- X} /* end of console_xon_status */
- X
- X/* end of ecutty.c */
- X/* vi: set tabstop=4 shiftwidth=4: */
- END_OF_FILE
- if test 38143 -ne `wc -c <'ecu330/ecutty.c'`; then
- echo shar: \"'ecu330/ecutty.c'\" unpacked with wrong size!
- fi
- # end of 'ecu330/ecutty.c'
- fi
- if test -f 'ecu330/sea/scurses.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ecu330/sea/scurses.c'\"
- else
- echo shar: Extracting \"'ecu330/sea/scurses.c'\" \(23014 characters\)
- sed "s/^X//" >'ecu330/sea/scurses.c' <<'END_OF_FILE'
- X
- X/*+-------------------------------------------------------------------------
- X scurses.c -- ecu file transfer program curses interface
- X
- X 000000000011111111112222222222333333333344444444445555555550
- X 012345678901234567890123456789012345678901234567890123456789
- X00.----------------------------------------------------------.
- X01| SEAlink_6____ _39____________________________________ |
- X02| File ### of ###: _38__________________________________ |
- X03| File position: _8______ length: _8______ |
- X04| _55____________________________________________________ | transaction
- X05| _55____________________________________________________ | last rx/tx hdr
- X06| Comm I/O: rx _8______ tx _8______ bytes |
- X07| Baud rate: _5___ BINARY blklen: _____ comm mode: CBREAK |
- X08| Time started: session: HH:MM:SS this file: HH:MM:SS |
- X09| elpased: HH:MM:SS time: HH:MM:SS |
- X10| Error counts: this file: _4__ total: _6____ |
- X11| _55____________________________________________________ | err str
- X12| _55____________________________________________________ | comment str
- X13| _55____________________________________________________ | remote info
- X14`----------------------------------------------------------'
- X
- X Defined functions:
- X clear_area(w,row,col,len)
- X clear_area_char(w,row,col,len,fillchar)
- X get_elapsed_time(elapsed_secs)
- X hhmmss(tod)
- X report_error_count()
- X report_file_byte_io(count)
- X report_file_close()
- X report_file_open_length(length)
- X report_file_open_tod()
- X report_file_rcv_started(filename,length,last_mod_time)
- X report_file_send_open(filename,filestat)
- X report_init(title)
- X report_last_rxhdr(rptstr,error_flag)
- X report_last_txhdr(rptstr,error_flag)
- X report_line(baud_rate,mode)
- X report_protocol_crc_type(str)
- X report_rx_ind(status)
- X report_rx_tx_count()
- X report_rxpos(pos)
- X report_str(rptstr,error_flag)
- X report_top_line(topstr)
- X report_transaction(str)
- X report_tx_ind(status)
- X report_txpos(pos)
- X report_uninit()
- X vanilla_ruling()
- X
- X------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:05-04-1994-04:40-wht@n4hgf-ECU release 3.30 */
- X/*:01-16-1994-15:46-wht@n4hgf-use ecumachdep.h */
- X/*:12-02-1993-14:05-Robert_Broughton@mindlink.bc.c-LINUX patches */
- X/*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 */
- X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
- X/*:04-24-1992-21:15-wht@n4hgf-sort out vannilla vs. at ruling */
- X/*:02-09-1992-16:08-root@n4hgf-ruling characters only on SCO (tcap curses) */
- X/*:08-28-1991-14:08-wht@n4hgf2-SVR4 cleanup by aega84!lh */
- X/*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 */
- X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
- X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
- X
- X#include "../ecucurses.h"
- X#include "../ecu_types.h"
- X#include "../ecu_stat.h"
- X#include "../ecu_time.h"
- X#include <ctype.h>
- X#include <signal.h>
- X
- X#include "../ecumachdep.h"
- X#include "../pc_scr.h"
- X
- Xlong time();
- Xextern char *tzname[];
- Xstruct tm *localtime();
- X
- X#define WIN_LINES 15
- X#define WIN_COLS 60
- X#define WIN_TOPY 2
- X#define WIN_LEFTX 8
- X
- Xextern char curr_dir[];
- Xextern char s128[];
- Xextern int Filcnt;
- Xextern int Restricted;
- Xextern int sending_flag; /* send == 1, receive == 0 */
- Xextern int npaths;
- Xextern long rxpos;
- Xextern int log_packets;
- X
- XWINDOW *win;
- Xint (*original_sigint_handler) ();
- Xint (*original_sigquit_handler) ();
- Xint (*original_sigterm_handler) ();
- Xint curses_installed = 0; /* curses not yet active */
- Xint this_file_errors = 0;
- Xint total_errors = 0;
- Xlong current_seconds;
- Xlong start_seconds;
- Xlong elapsed_seconds;
- Xunsigned long total_data_chars_xfered = 0L;
- X
- X#ifdef LINUX
- Xtypedef chtype Chtype;
- X
- X#else
- Xtypedef unsigned char Chtype;
- X
- X#endif
- X
- XChtype sTL = at_TL;
- XChtype sTR = at_TR;
- XChtype sBL = at_BL;
- XChtype sBR = at_BR;
- XChtype sLT = at_LT;
- XChtype sRT = at_RT;
- XChtype sVR = at_VR;
- XChtype sHR = at_HR;
- X
- Xchar *win_template[] =
- X{
- X/*00000000001111111111222222222233333333334444444444555555555 */
- X/*01234567890123456789012345678901234567890123456789012345678 */
- X/*.----------------------------------------------------------. */
- X " SEAlink ", /* 1 */
- X " File ### of ###: _____________________________________ ", /* 2 */
- X " File position: ________ length: ________ ", /* 3 */
- X " ", /* 4 */
- X " tx: ______________________ rx: ______________________ ", /* 5 */
- X " Comm I/O: rx ________ tx ________ bytes ", /* 6 */
- X " Baud rate: _____ BINARY blklen: 128 comm mode: ______ ", /* 7 */
- X " Time started: session: --:--:-- this file: --:--:-- ", /* 8 */
- X " elapsed: --:--:-- current: --:--:-- ", /* 9 */
- X " Error counts: this file: ____ total: ______ ", /* 10 */
- X " ", /* 11 */
- X " ", /* 12 */
- X " ", /* 13 */
- X/*`----------------------------------------------------------' */
- X (char *)0
- X};
- X
- X/*+-------------------------------------------------------------------------
- X vanilla_ruling() - use ordinary ruling characters
- X--------------------------------------------------------------------------*/
- Xvoid
- Xvanilla_ruling()
- X{
- X sTL = vanilla_TL;
- X sTR = vanilla_TR;
- X sBL = vanilla_BL;
- X sBR = vanilla_BR;
- X sLT = vanilla_LT;
- X sRT = vanilla_RT;
- X sVR = vanilla_VR;
- X sHR = vanilla_HR;
- X
- X} /* end of vanilla_ruling */
- X
- X/*+-----------------------------------------------------------------------
- X char *get_elapsed_time(elapsed_secs)
- X hh:mm:ss returned
- X static string address is returned
- X------------------------------------------------------------------------*/
- Xchar *
- Xget_elapsed_time(elapsed_secs)
- Xlong elapsed_secs;
- X{
- X static char elapsed_time_str[10];
- X long hh, mm, ss;
- X
- X hh = elapsed_secs / 3600;
- X elapsed_secs -= hh * 3600;
- X mm = elapsed_secs / 60L;
- X elapsed_secs -= mm * 60L;
- X ss = elapsed_secs;
- X
- X sprintf(elapsed_time_str, "%02ld:%02ld:%02ld", hh, mm, ss);
- X return (elapsed_time_str);
- X} /* end of get_elapsed_time */
- X
- X/*+-----------------------------------------------------------------------
- X char *hhmmss(tod) - get time of day in form "hh:mm:ss"
- X
- X static string address is returned
- X if tod != (char *)0, time is returned there too
- X------------------------------------------------------------------------*/
- Xchar *
- Xhhmmss(tod)
- Xchar *tod;
- X{
- X long cur_time = 0;
- X struct tm *lt; /* local time */
- X static char tod_str[32];
- X
- X cur_time = time((long *)0);
- X lt = localtime(&cur_time);
- X
- X sprintf(tod_str, "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
- X
- X if (tod != (char *)0)
- X strcpy(tod, tod_str);
- X
- X return (tod_str);
- X
- X} /* end of hhmmss */
- X
- X/*+-------------------------------------------------------------------------
- X clear_area(w,row,col,len)
- X--------------------------------------------------------------------------*/
- Xclear_area(w, row, col, len)
- XWINDOW *w;
- Xint row;
- Xint col;
- Xint len;
- X{
- X wmove(w, row, col);
- X while (len-- > 0)
- X waddch(w, ' ');
- X wmove(w, row, col);
- X
- X} /* end of clear_area */
- X
- X/*+-------------------------------------------------------------------------
- X clear_area_char(w,row,col,len,fillchar)
- X--------------------------------------------------------------------------*/
- Xclear_area_char(w, row, col, len, fillchar)
- XWINDOW *w;
- Xint row;
- Xint col;
- Xint len;
- Xchar fillchar;
- X{
- X wmove(w, row, col);
- X while (len-- > 0)
- X waddch(w, fillchar);
- X wmove(w, row, col);
- X
- X} /* end of clear_area_char */
- X
- X/*+-------------------------------------------------------------------------
- X report_top_line(topstr)
- X top line: row 1 col 18 length 39
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_top_line(topstr)
- Xchar *topstr;
- X{
- X char s42[42];
- X
- X clear_area(win, 1, 18, 39);
- X if (strlen(topstr) < 39)
- X waddstr(win, topstr);
- X else
- X {
- X strncpy(s42, topstr, 39);
- X s42[39] = 0;
- X waddstr(win, s42);
- X }
- X} /* end of report_top_line */
- X
- X/*+-------------------------------------------------------------------------
- X report_protocol_crc_type(str)
- X
- X protocol crc type: row 1 col 10 length 6
- X--------------------------------------------------------------------------*/
- Xreport_protocol_crc_type(str)
- Xregister char *str;
- X{
- X char s8[8];
- X
- X if (strlen(str) > 6)
- X {
- X strncpy(s8, str, 6);
- X s8[6] = 0;
- X str = s8;
- X }
- X clear_area(win, 1, 10, 6);
- X waddstr(win, str);
- X wrefresh(win);
- X if (log_packets)
- X {
- X write(log_packets, "chk: ", 6);
- X write(log_packets, str, strlen(str));
- X write(log_packets, "\n", 1);
- X }
- X
- X} /* end of report_protocol_crc_type */
- X
- X/*+-------------------------------------------------------------------------
- X report_error_count()
- X DOES NOT PERFORM A REFRESH CYCLE
- X this file: row 10 col 29 len 4
- X total: row 10 col 42 len 6
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_error_count()
- X{
- X char tmp[16];
- X
- X clear_area(win, 10, 29, 4);
- X sprintf(tmp, "%4d", this_file_errors);
- X waddstr(win, tmp);
- X
- X clear_area(win, 10, 42, 6);
- X sprintf(tmp, "%6d", total_errors);
- X waddstr(win, tmp);
- X wrefresh(win);
- X
- X} /* end of report_error_count */
- X
- X/*+-------------------------------------------------------------------------
- X report_uninit()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_uninit()
- X{
- X float total = (float)total_data_chars_xfered;
- X
- X if (curses_installed)
- X {
- X if ((total_data_chars_xfered != 0L) && (elapsed_seconds != 0L))
- X {
- X sprintf(s128, "Data xfer rate ~= %6.0f chars/sec",
- X total / (float)elapsed_seconds);
- X if (log_packets)
- X {
- X write(log_packets, "info: ", 6);
- X write(log_packets, s128, strlen(s128));
- X write(log_packets, "\n", 1);
- X }
- X report_top_line(s128);
- X }
- X report_file_byte_io(0L);
- X report_rx_tx_count();
- X wmove(win, WIN_LINES - 1, WIN_COLS - 1);
- X wrefresh(win);
- X endwin();
- X fprintf(stderr, "\r\n\r\n\r\n");
- X fflush(stderr);
- X curses_installed = 0;
- X }
- X
- X} /* end of report_uninit */
- X
- X/*+-------------------------------------------------------------------------
- X report_init(title)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_init(title)
- Xchar *title;
- X{
- X register int itmp;
- X
- X#if defined(CONS_GET)
- X int monitor_type;
- X
- X#endif
- X
- X if (curses_installed)
- X return;
- X
- X#if defined(M_SYSV)
- X if (ioctl(0, CONS_GET, &monitor_type) < 0) /* not multiscreen */
- X#ifdef M_SYSV /* SCO non AT console */
- X vanilla_ruling();
- X#endif
- X#else
- X vanilla_ruling();
- X#endif
- X#ifdef LINUX
- X sTL = ACS_ULCORNER;
- X sTR = ACS_URCORNER;
- X sBL = ACS_LLCORNER;
- X sBR = ACS_LRCORNER;
- X sLT = ACS_LTEE;
- X sRT = ACS_RTEE;
- X sVR = ACS_VLINE;
- X sHR = ACS_HLINE;
- X#endif
- X
- X initscr();
- X crmode();
- X noecho();
- X nonl();
- X clear();
- X curses_installed = 1;
- X win = newwin(WIN_LINES, WIN_COLS, WIN_TOPY, WIN_LEFTX);
- X box(win, sVR, sHR);
- X#if !defined(SVR4) && !defined(LINUX)
- X wmove(win, 0, 0);
- X waddch(win, sTL);
- X wmove(win, win->_maxy - 1, 0);
- X waddch(win, sBL);
- X wmove(win, win->_maxy - 1, win->_maxx - 1);
- X waddch(win, sBR);
- X wmove(win, 0, win->_maxx - 1);
- X waddch(win, sTR);
- X#endif
- X wmove(win, 0, 2);
- X wstandout(win);
- X waddch(win, '[');
- X waddch(win, ' ');
- X waddstr(win, title);
- X waddch(win, ' ');
- X waddch(win, ']');
- X wstandend(win);
- X#ifdef SVR4
- X whline(win, (unsigned long)(sHR & 0x00ff), 2);
- X wmove(win, 0, 8 + strlen(title));
- X#else
- X#ifdef LINUX
- X whline(win, sHR, 2);
- X wmove(win, 0, 8 + strlen(title));
- X#else
- X waddch(win, sHR);
- X waddch(win, sHR);
- X#endif
- X#endif
- X waddstr(win, " dir: ");
- X waddstr(win, curr_dir);
- X waddch(win, ' ');
- X
- X itmp = 0;
- X while (1)
- X {
- X if (win_template[itmp] == (char *)0)
- X break;
- X wmove(win, itmp + 1, 1);
- X waddstr(win, win_template[itmp++]);
- X }
- X if (sending_flag)
- X {
- X clear_area(win, 2, 15, 3);
- X sprintf(s128, "%3d", npaths);
- X waddstr(win, s128);
- X }
- X else
- X /* ecurz */
- X {
- X clear_area(win, 2, 11, 8); /* clear "of ###" */
- X waddstr(win, ":");
- X }
- X
- X clear_area(win, 1, 11, 47);
- X report_error_count();
- X clear_area(win, 8, 26, 8); /* starting time */
- X waddstr(win, hhmmss((char *)0));
- X start_seconds = time((long *)0);
- X current_seconds = start_seconds;
- X
- X wrefresh(win);
- X
- X} /* end of report_init */
- X
- X/*+-------------------------------------------------------------------------
- X report_rx_ind(status)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_rx_ind(status)
- Xint status;
- X{
- X wmove(win, 1, 54);
- X waddch(win, (status) ? 'R' : ' ');
- X wmove(win, 1, 54);
- X wrefresh(win);
- X} /* end of report_rx_ind */
- X
- X/*+-------------------------------------------------------------------------
- X report_tx_ind(status)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_tx_ind(status)
- Xint status;
- X{
- X wmove(win, 1, 56);
- X waddch(win, (status) ? 'T' : ' ');
- X wmove(win, 1, 56);
- X wrefresh(win);
- X} /* end of report_tx_ind */
- X
- X/*+-------------------------------------------------------------------------
- X report_rx_tx_count()
- X
- X rx char count: row 6 col 16 length 8 unsigned long
- X tx char count: row 6 col 29 length 8 unsigned long
- X now time of day: row 1 col 50 length 8 hh:mm:ss
- X This procedure may be counted upon to perform wrefresh(win)
- X
- Xelapsed time row 9 col 26 length 8
- Xcurrent tod row 9 col 47 length 8
- X--------------------------------------------------------------------------*/
- Xreport_rx_tx_count()
- X{
- X extern unsigned long rx_char_count;
- X extern unsigned long tx_char_count;
- X
- X register char *cptr;
- X
- X sprintf(s128, "%8ld", rx_char_count);
- X wmove(win, 6, 16);
- X waddstr(win, s128);
- X sprintf(s128, "%8ld", tx_char_count);
- X wmove(win, 6, 29);
- X waddstr(win, s128);
- X
- X /* now time of day */
- X clear_area(win, 9, 47, 8);
- X cptr = hhmmss((char *)0);
- X waddstr(win, cptr);
- X current_seconds = time((long *)0);
- X elapsed_seconds = current_seconds - start_seconds;
- X cptr = get_elapsed_time(elapsed_seconds);
- X clear_area(win, 9, 26, 8);
- X waddstr(win, cptr);
- X wrefresh(win); /* calling procs expect this to occur always */
- X
- X} /* end of report_rx_tx_count */
- X
- X/*+-------------------------------------------------------------------------
- X report_line(baud_rate,mode)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_line(baud_rate, mode)
- Xunsigned baud_rate;
- Xchar *mode;
- X{
- X char s16[16];
- X
- X wmove(win, 7, 14);
- X sprintf(s16, "%5u", baud_rate);
- X waddstr(win, s16);
- X clear_area(win, 7, 52, 6);
- X waddstr(win, mode);
- X wrefresh(win);
- X} /* end of report_line */
- X
- X/*+-------------------------------------------------------------------------
- X report_rxpos(pos) row 3 col 19 len 8
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_rxpos(pos)
- Xlong pos;
- X{
- X char tmp[16];
- X char refr;
- X
- X if (rdchk(0))
- X {
- X read(0, &refr, 1);
- X if (refr == 0x0C || refr == 0x012) /* ^L or ^R */
- X {
- X write(2, "\033[2J", 4);
- X Nap((long)60);
- X touchwin(stdscr);
- X wrefresh(stdscr);
- X touchwin(win);
- X wrefresh(win);
- X }
- X }
- X
- X if ((pos > 99999999L) || (pos < 0L))
- X return;
- X
- X sprintf(tmp, "%8lu", pos);
- X wmove(win, 3, 19);
- X waddstr(win, tmp);
- X wrefresh(win);
- X report_rx_tx_count(); /* which will do a refresh */
- X} /* end of report_rxpos */
- X
- X/*+-------------------------------------------------------------------------
- X report_txpos(pos)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_txpos(pos)
- Xlong pos;
- X{
- X report_rxpos(pos);
- X} /* end of report_txpos */
- X
- X/*+-------------------------------------------------------------------------
- X report_last_txhdr(rptstr,error_flag)
- X 5,7,22
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_last_txhdr(rptstr, error_flag)
- Xregister char *rptstr;
- Xint error_flag;
- X{
- X char s24[24];
- X
- X if (log_packets)
- X {
- X write(log_packets, "tx: ", 6);
- X write(log_packets, rptstr, strlen(rptstr));
- X write(log_packets, "\n", 1);
- X }
- X
- X if (strlen(rptstr) > 22)
- X {
- X strncpy(s24, rptstr, 22);
- X s24[23] = 0;
- X rptstr = s24;
- X }
- X clear_area(win, 5, 7, 22);
- X waddstr(win, rptstr);
- X wrefresh(win);
- X
- X if (error_flag)
- X {
- X ++this_file_errors;
- X ++total_errors;
- X report_error_count();
- X }
- X} /* end of report_last_txhdr */
- X
- X/*+-------------------------------------------------------------------------
- X report_last_rxhdr(rptstr,error_flag)
- X 5,35,22
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_last_rxhdr(rptstr, error_flag)
- Xregister char *rptstr;
- Xint error_flag;
- X{
- X char s24[24];
- X extern int log_packets;
- X
- X if (log_packets)
- X {
- X write(log_packets, "rx: ", 4);
- X write(log_packets, (error_flag) ? "E " : " ", 2);
- X write(log_packets, rptstr, strlen(rptstr));
- X write(log_packets, "\n", 1);
- X }
- X
- X if (strlen(rptstr) > 22)
- X {
- X strncpy(s24, rptstr, 22);
- X s24[23] = 0;
- X rptstr = s24;
- X }
- X clear_area(win, 5, 35, 22);
- X waddstr(win, rptstr);
- X wrefresh(win);
- X
- X if (error_flag)
- X {
- X ++this_file_errors;
- X ++total_errors;
- X report_error_count();
- X }
- X
- X} /* end of report_last_rxhdr */
- X
- X/*+-------------------------------------------------------------------------
- X report_str(rptstr,error_flag) row 11/12 col 3 len 55
- X
- X error_flag == 0 for status/progress message
- X == 1 for bump error count, unless rptstr is null
- X in which case, merely clear error string area
- X == 2 write string on bottom line (not an error)
- X == 3 write string on transaction line (not an error)
- X == -1 use error line but do not bump error count
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_str(rptstr, error_flag)
- Xregister char *rptstr;
- Xint error_flag;
- X{
- X char s60[60];
- X extern int log_packets;
- X
- X if (strlen(rptstr) > 55)
- X {
- X strncpy(s60, rptstr, 55);
- X s60[56] = 0;
- X rptstr = s60;
- X }
- X
- X switch (error_flag)
- X {
- X case 0:
- X clear_area(win, 12, 3, 55);
- X break;
- X case 1:
- X ++this_file_errors;
- X ++total_errors;
- X report_error_count();
- X case -1:
- X clear_area(win, 11, 3, 55);
- X break;
- X case 2:
- X clear_area(win, 13, 3, 55);
- X break;
- X case 3:
- X clear_area(win, 4, 3, 55);
- X break;
- X }
- X
- X waddstr(win, rptstr);
- X wrefresh(win);
- X
- X if (log_packets)
- X {
- X write(log_packets, "info: ", 6);
- X sprintf(s60, "%2d ", error_flag);
- X write(log_packets, s60, 3);
- X write(log_packets, rptstr, strlen(rptstr));
- X write(log_packets, "\n", 1);
- X }
- X
- X} /* end of report_str */
- X
- X/*+-------------------------------------------------------------------------
- X report_transaction()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_transaction(str)
- Xchar *str;
- X{
- X report_str(str, 3);
- X} /* end of report_transaction */
- X
- X/*+-------------------------------------------------------------------------
- X report_file_open_tod() -- time of start of this file
- X
- X this file open time: row 8 col 47 length 8
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_file_open_tod()
- X{
- X clear_area(win, 8, 47, 8);
- X waddstr(win, hhmmss((char *)0));
- X wrefresh(win);
- X} /* end of report_file_open_tod */
- X
- X/*+-------------------------------------------------------------------------
- X report_file_open_length(long_length)
- X length: row 3 col 36 len 8
- X--------------------------------------------------------------------------*/
- Xreport_file_open_length(length)
- Xlong length;
- X{
- X clear_area(win, 3, 36, 8);
- X if (length <= 0)
- X waddstr(win, "unknown");
- X else
- X {
- X sprintf(s128, "%8lu", length);
- X waddstr(win, s128);
- X }
- X wrefresh(win);
- X} /* end of report_file_open_length */
- X
- X/*+-------------------------------------------------------------------------
- X report_file_send_open(filename,filestat)
- X
- X filename: row 2 col 20 len 38
- X number: row 2 col 8 len 3
- X length: row 3 col 36 len 8
- X mode: row 3 col 46 len 10
- X time of start of this file: row 4 col 47 length 8 hh:mm:ss
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_file_send_open(filename, filestat)
- Xchar *filename;
- Xstruct stat *filestat;
- X{
- X char s50[50];
- X register char *cptr = filename;
- X
- X if (log_packets)
- X {
- X write(log_packets, "file: ", 6);
- X write(log_packets, filename, strlen(filename));
- X write(log_packets, "\n", 1);
- X }
- X
- X /* number */
- X clear_area(win, 2, 8, 3);
- X sprintf(s50, "%3d", Filcnt);
- X waddstr(win, s50);
- X
- X /* filename */
- X if (strlen(filename) > 38)
- X {
- X strncpy(s50, filename, 38);
- X s50[39] = 0;
- X cptr = s50;
- X }
- X clear_area(win, 2, 20, 38);
- X waddstr(win, cptr);
- X
- X#if defined(LOG_XFER)
- X sprintf(s128, "sending %s", filename);
- X ecu_log_event(getppid(), s128);
- X#endif
- X
- X /* length */
- X report_file_open_length(filestat->st_size);
- X
- X /* time of start of this file */
- X report_file_open_tod();
- X
- X this_file_errors = 0;
- X report_error_count();
- X} /* end of report_file_send_open */
- X
- X/*+-------------------------------------------------------------------------
- X report_file_rcv_started(filename,length,last_mod_time)
- X
- X filename: row 2 col 7 len 50
- X length: row 3 col 36 len 8 if not xmodem
- X time of start of this file: row 4 col 47 length 8 hh:mm:ss
- X--------------------------------------------------------------------------*/
- Xreport_file_rcv_started(filename, length, last_mod_time)
- Xchar *filename;
- Xlong length; /* if < 0, "UNKNOWN" */
- Xlong last_mod_time; /* not currently displayed */
- X{
- X register char *cptr;
- X char s50[50];
- X
- X if (log_packets)
- X {
- X write(log_packets, "file: ", 6);
- X write(log_packets, filename, strlen(filename));
- X write(log_packets, "\n", 1);
- X }
- X
- X /* filename */
- X if (strlen(filename) > 38)
- X {
- X strncpy(s50, filename, 38);
- X s50[39] = 0;
- X cptr = s50;
- X }
- X else
- X cptr = filename;
- X
- X#if defined(LOG_XFER)
- X sprintf(s128, "receiving %s", filename);
- X ecu_log_event(getppid(), s128);
- X#endif
- X
- X clear_area(win, 2, 20, 38);
- X waddstr(win, cptr);
- X
- X /* file number */
- X clear_area(win, 2, 8, 3);
- X sprintf(s50, "%3d", Filcnt); /* rz uses as file number 1-n */
- X waddstr(win, s50);
- X
- X/* if remote sender provides a file count, display it */
- X if (npaths)
- X {
- X clear_area(win, 2, 12, 7); /* clear "of ###" */
- X sprintf(s50, "of %3d:", npaths);
- X waddstr(win, s50);
- X }
- X
- X /* length */
- X report_file_open_length(length);
- X
- X /* time of start of this file */
- X report_file_open_tod();
- X
- X this_file_errors = 0;
- X report_error_count();
- X} /* end of report_file_rcv_started */
- X
- X/*+-------------------------------------------------------------------------
- X report_file_close()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xreport_file_close()
- X{
- X report_str("End of file", 0);
- X wrefresh(win);
- X
- X} /* end of report_file_close */
- X
- X/*+-------------------------------------------------------------------------
- X report_file_byte_io(count)
- X--------------------------------------------------------------------------*/
- Xreport_file_byte_io(count)
- Xlong count;
- X{
- X
- X total_data_chars_xfered += (long)count;
- X if (total_data_chars_xfered)
- X {
- X sprintf(s128, "Total file bytes transferred: %lu",
- X total_data_chars_xfered);
- X report_str(s128, -1);
- X }
- X
- X} /* end of report_file_byte_io */
- X
- X/* end of scurses.c */
- X/* vi: set tabstop=4 shiftwidth=4: */
- END_OF_FILE
- if test 23014 -ne `wc -c <'ecu330/sea/scurses.c'`; then
- echo shar: \"'ecu330/sea/scurses.c'\" unpacked with wrong size!
- fi
- # end of 'ecu330/sea/scurses.c'
- fi
- echo shar: End of archive 12 \(of 37\).
- cp /dev/null ark12isdone
- MISSING=""
- 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
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 37 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-