home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume21
/
ecu
/
part10
< prev
next >
Wrap
Text File
|
1991-08-05
|
55KB
|
2,040 lines
Newsgroups: comp.sources.misc
From: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Subject: v21i062: ecu - ECU async comm package rev 3.10, Part10/37
Message-ID: <1991Aug4.015008.8705@sparky.IMD.Sterling.COM>
X-Md4-Signature: f89423b1839aca8b51d7d2af4927958b
Date: Sun, 4 Aug 1991 01:50:08 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Posting-number: Volume 21, Issue 62
Archive-name: ecu/part10
Environment: SCO, XENIX, ISC
Supersedes: ecu3: Volume 16, Issue 25-59
---- Cut Here and feed the following to sh ----
#!/bin/sh
# this is ecu310.10 (part 10 of ecu310)
# do not concatenate these parts, unpack them in order with /bin/sh
# file ecutcap.c continued
#
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 10; then
echo Please unpack part "$Scheck" next!
exit 1
else
exit 0
fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
echo 'x - still skipping ecutcap.c'
else
echo 'x - continuing file ecutcap.c'
sed 's/^X//' << 'SHAR_EOF' >> 'ecutcap.c' &&
X tputs(tc_standout,1,tcap_putc_stderr);
X} /* end of tcap_blink_on */
X
X/*+-------------------------------------------------------------------------
X tcap_blink_off()
X--------------------------------------------------------------------------*/
Xvoid
Xtcap_blink_off()
X{
X if(*tc_blink_off)
X tputs(tc_blink_off,1,tcap_putc_stderr);
X else if(*tc_standend) /* && (tc_standout_width == 0)) */
X tputs(tc_standend,1,tcap_putc_stderr);
X} /* end of tcap_blink_off */
X
X/*+-------------------------------------------------------------------------
X tcap_clear_area_char(count,clrch)
X--------------------------------------------------------------------------*/
Xvoid
Xtcap_clear_area_char(count,clrch)
Xregister count;
Xregister clrch;
X{
Xregister itmp = count;
X while(itmp--)
X fputc(clrch,se);
X itmp = count;
X while(itmp--)
X fputs(tc_curleft,se);
X
X} /* end of tcap_clear_area_char */
X
X/*+-------------------------------------------------------------------------
X numchars = tcap_gets(buf,bufsize,&delim,wait_for_key)
X
XThis procedure reads a string and returns the number
Xof characters read. -1 is returned if an abort is signaled by the
Xkeyboard user.
X--------------------------------------------------------------------------*/
Xint
Xtcap_gets(buf,bufsize,delim,wait_for_key)
Xchar *buf;
Xregister bufsize; /* includes room for null..field is 1 less */
Xregister uchar *delim;
Xint wait_for_key;
X{
Xregister count;
Xregister itmp;
Xregister char *cptr = buf;
X
X if(!wait_for_key)
X tcap_clear_area_char(bufsize-1,'_');
X
X count = 0; /* no characters in string */
X *cptr = 0; /* start with null string */
X
X while(1)
X {
X *delim = ttygetc(1);
X if((*delim < 0x20) || (*delim >= 0x7F))
X {
X switch(*delim)
X {
X case CRET:
X *delim = NL;
X case NL:
X return(count);
X
X case BS:
X if(count)
X {
X count--;
X *--cptr = 0;
X fputc(0x08,se);
X fputc('_',se);
X fputs(tc_curleft,se);
X }
X continue;
X
X case ESC:
X case CTL_U:
X itmp = count;
X while(itmp--)
X {
X *--cptr = 0;
X fputc(0x08,se);
X }
X itmp = count;
X while(itmp--)
X fputc('_',se);
X itmp = count;
X while(itmp--)
X fputs(tc_curleft,se);
X cptr = buf;
X count = 0;
X if(*delim == ESC)
X return(-1);
X continue;
X
X default:
X return(-1);
X } /* end of switch(*delim) */
X /*NOTREACHED*/
X } /* end of if read delimiter */
X
X if(count == bufsize-1)
X continue;
X if(wait_for_key)
X {
X tcap_clear_area_char(bufsize-1,'_');
X wait_for_key = 0;
X }
X fputc(*delim,se);
X *cptr++ = *delim;
X *cptr = 0;
X count++;
X } /* end of while can get character */
X
X} /* end of tcap_gets */
X
X
X/* end of ecutcap.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
echo 'File ecutcap.c is complete' &&
$TOUCH -am 0725125691 'ecutcap.c' &&
chmod 0644 ecutcap.c ||
echo 'restore of ecutcap.c failed'
Wc_c="`wc -c < 'ecutcap.c'`"
test 15270 -eq "$Wc_c" ||
echo 'ecutcap.c: original size 15270, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecutime.c ==============
if test -f 'ecutime.c' -a X"$1" != X"-c"; then
echo 'x - skipping ecutime.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecutime.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecutime.c' &&
X/*+-------------------------------------------------------------------------
X ecutime.c -- ecu time-related functions
X wht@n4hgf.Mt-Park.GA.US
X
X Defined functions:
X epoch_secs_to_str(epoch_secs,type,buf)
X get_elapsed_time(elapsed_seconds)
X get_tod(type,buf)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:56-wht@n4hgf-ECU release 3.10 */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include <sys/types.h>
X#include <time.h>
X#include <sys/timeb.h>
X
Xstruct tm *gmtime();
Xstruct tm *localtime();
X
X/*+-------------------------------------------------------------------------
X get_month(zflag) - month 1-12 - zflag true for UTC (Z)), else local time
X--------------------------------------------------------------------------*/
Xint
Xget_month(zflag)
Xint zflag;
X{
Xlong time();
Xlong epoch_secs = time((long *)0);
Xstruct tm *tod = (zflag) ? gmtime(&epoch_secs) : localtime(&epoch_secs);
X return(tod->tm_mon + 1);
X} /* end of get_month */
X
X/*+-------------------------------------------------------------------------
X get_day(zflag) - day 0-6 - zflag true for UTC (Z)), else local time
X--------------------------------------------------------------------------*/
Xint
Xget_day(zflag)
Xint zflag;
X{
Xlong time();
Xlong epoch_secs = time((long *)0);
Xstruct tm *tod = (zflag) ? gmtime(&epoch_secs) : localtime(&epoch_secs);
X return(tod->tm_wday);
X} /* end of get_day */
X
X/*+-----------------------------------------------------------------------
X char *epoch_secs_to_str(epoch_secs,type,buf)
X
X time of day types:
X 0 hh:mm
X 1 hh:mm:ss
X 2 mm-dd-yyyy hh:mm
X 3 mm-dd-yyyy hh:mm:ss
X 4 mm-dd-yyyy hh:mm:ss (UTC hh:mm)
X 5 mm-dd-yyyy
X 6 hh:mmZ
X 7 hh:mm:ssZ
X 8 mm-dd-yyyy (UTC date)
X
X returns 'buf' address
X
X------------------------------------------------------------------------*/
Xchar *
Xepoch_secs_to_str(epoch_secs,type,buf)
Xlong epoch_secs;
Xint type;
Xchar *buf;
X{
Xstruct tm *tod;
X
X
X if(type < 6)
X tod = localtime(&epoch_secs);
X else
X tod = gmtime(&epoch_secs);
X
X switch(type)
X {
X default:
X case 6:
X case 0:
X sprintf(buf,"%02d:%02d",tod->tm_hour,tod->tm_min);
X if(type == 6)
X strcat(buf,"Z");
X break;
X
X case 7:
X case 1:
X sprintf(buf,"%02d:%02d:%02d",tod->tm_hour,tod->tm_min,tod->tm_sec);
X if(type == 7)
X strcat(buf,"Z");
X break;
X
X case 2:
X sprintf(buf,"%02d-%02d-%04d %02d:%02d",
X tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
X tod->tm_hour,tod->tm_min);
X break;
X
X case 3:
X sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
X tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
X tod->tm_hour,tod->tm_min,tod->tm_sec);
X break;
X
X case 4:
X sprintf(buf,"%02d-%02d-%04d %02d:%02d:%02d",
X tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900,
X tod->tm_hour,tod->tm_min,tod->tm_sec);
X tod = gmtime(&epoch_secs);
X sprintf(&buf[strlen(buf) ]," (UTC %02d:%02d)",
X tod->tm_hour,tod->tm_min);
X break;
X
X case 8:
X case 5:
X sprintf(buf,"%02d-%02d-%04d",
X tod->tm_mon + 1,tod->tm_mday,tod->tm_year + 1900);
X break;
X
X }
X
X return(buf);
X} /* end of epoch_secs_to_str */
X
X/*+-----------------------------------------------------------------------
X char *get_tod(type,buf)
X
X time of day types:
X 0 hh:mm
X 1 hh:mm:ss
X 2 mm-dd-yyyy hh:mm
X 3 mm-dd-yyyy hh:mm:ss
X 4 mm-dd-yyyy hh:mm:ss (UTC hh:mm)
X 5 mm-dd-yyyy
X 6 hh:mmZ
X 7 hh:mm:ssZ
X 8 mm-dd-yyyy (UTC date)
X
X returns 'buf' address
X
X------------------------------------------------------------------------*/
Xchar *
Xget_tod(type,buf)
Xint type;
Xchar *buf;
X{
Xlong time();
X return(epoch_secs_to_str(time((long *)0),type,buf));
X} /* end of get_tod */
X
X/*+-----------------------------------------------------------------------
X char *get_elapsed_time(elapsed_seconds)
X "hh:mm:ss" returned
X static string address is returned
X------------------------------------------------------------------------*/
Xchar *
Xget_elapsed_time(elapsed_seconds)
Xlong elapsed_seconds;
X{
Xstatic char elapsed_time_str[40];
Xlong hh,mm,ss;
X
X hh = elapsed_seconds / 3600;
X elapsed_seconds -= hh * 3600;
X mm = elapsed_seconds / 60L;
X elapsed_seconds -= mm * 60L;
X ss = elapsed_seconds;
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/* end of ecutime.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0725125691 'ecutime.c' &&
chmod 0644 ecutime.c ||
echo 'restore of ecutime.c failed'
Wc_c="`wc -c < 'ecutime.c'`"
test 4303 -eq "$Wc_c" ||
echo 'ecutime.c: original size 4303, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecutty.c ==============
if test -f 'ecutty.c' -a X"$1" != X"-c"; then
echo 'x - skipping ecutty.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecutty.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecutty.c' &&
X/*+-------------------------------------------------------------------------
X ecutty.c - local tty (console) functions
X wht@n4hgf.Mt-Park.GA.US
X
X Defined functions:
X _setcolor(clrs)
X B_to_timeout_msec(c_cflag,st_rdev)
X color_name_to_num(cname)
X get_initial_colors()
X get_ttymode()
X get_ttyname()
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)
X ttygets_esd(tesd,flags,append_flag)
X ttyinit(param)
X ttymode(arg)
X ttynormal_opost()
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--------------------------------------------------------------------------*/
X/*+:EDITS:*/
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-METRLINK_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#if defined(M_SYSV)
X# include <sys/machdep.h>
X#else
X# include <sys/at_ansi.h>
X# include <sys/kd.h>
X#endif
X
X#define DEFINE_TTY_DATA
X#include "ecutty.h"
X
X/*
X * mapping table index to internal function code map
X *
X * the order of this table depends upon the pseudo-magic
X * KDEk_.. codes defined in ecufkey.h
X */
Xuchar KDEk_to_XF[] =
X{
X XF1, /* KDEk_F1 */
X XF2, /* KDEk_F2 */
X XF3, /* KDEk_F3 */
X XF4, /* KDEk_F4 */
X XF5, /* KDEk_F5 */
X XF6, /* KDEk_F6 */
X XF7, /* KDEk_F7 */
X XF8, /* KDEk_F8 */
X XF9, /* KDEk_F9 */
X XF10, /* KDEk_F10 */
X XF11, /* KDEk_F11 */
X XF12, /* KDEk_F12 */
X XFcurup, /* KDEk_CUU */
X XFcurdn, /* KDEk_CUD */
X XFcurlf, /* KDEk_CUL */
X XFcurrt, /* KDEk_CUR */
X XFcur5, /* KDEk_CU5 */
X XFpgup, /* KDEk_PGUP */
X XFpgdn, /* KDEk_PGDN */
X XFend, /* KDEk_END */
X XFins, /* KDEk_INS */
X XFbktab, /* KDEk_BKTAB */
X XFhome /* KDEk_HOME */
X};
X
Xextern int sigint;
Xextern int hz;
Xextern uint tcap_LINES;
Xextern uint tcap_COLS;
Xextern int LINES;
Xextern int COLS;
Xextern char screen_dump_file_name[];
X
X
Xuint LINESxCOLS;
Xint current_ttymode = 0;
Xint ttymode_termecu_on_sigint = 0;
Xint tty_is_ansi;
Xint tty_is_pts;
Xint tty_is_pty;
Xint tty_is_multiscreen;
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;
X#if defined(METRLINK_X11R4_PTS)
Xstruct stat pts000;
X#endif /* METRLINK_X11R4_PTS */
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
Xulong colors_current = 0x04070A00L;
Xulong colors_normal = 0x04070A00L; /* default lt_green/black red/white */
Xulong colors_initial = 0x04070A00L; /* default initial colors */
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
Xint use_colors = 0; /* set by ttyinit, but default no */
Xint tty_not_char_special;
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(c_cflag,st_rdev)
Xushort c_cflag;
Xushort st_rdev;
X{
Xlong ms = 300L;
X
X /* make pts sweat, but don't make as many mistakes */
X#if defined(METRLINK_X11R4_PTS)
X if(tty_is_pts)
X return(ms);
X#endif /* METRLINK_X11R4_PTS */
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(c_cflag & CBAUD)
X {
X /* char times * time/char */
X case B110: ms = 10 * 100;
X case B300: ms = 10 * 33;
X case B600: ms = 10 * 16;
X case B1200: ms = 10 * 8;
X case B2400: 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{
Xregister COLOR *color = colors;
Xregister 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(!use_colors || tty_not_char_special)
X return;
X
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
X colors_current = clrs;
X
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) || (new_colors == colors_alert) ||
X (new_colors == colors_error))
X {
X tcap_stand_out();
X }
X else
X tcap_stand_end();
X return;
X }
X _setcolor(new_colors);
X tcap_stand_end();
X
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{
Xulong fgnd;
Xulong bgnd;
X
X if(tty_not_char_special || !use_colors)
X return(0);
X
X 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() - under UNIX, restore color scheme at execution
X
XUnder non-SCO-S5R3, don't have initial color, so use colors_normal
X--------------------------------------------------------------------------*/
Xvoid
Xrestore_initial_colors()
X{
X#ifdef M_UNIX
X setcolor(colors_initial);
X#else
X setcolor(colors_normal);
X#endif
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 Thanks for the G2 on this to staceyc@sco.COM (Stacey Campbell)
X--------------------------------------------------------------------------*/
X#if defined(M_UNIX)
Xvoid
Xget_initial_colors()
X{
X#if !defined(GIO_ATTR)
X#define GIO_ATTR ('a' << 8) | 0 /* Ioctl call for current attribute */
X#endif
X uint cur_attr;
X ulong fgnd;
X ulong bgnd;
X
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(0, 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(0, GIO_ATTR, 0);
X fgnd = (ulong)cur_attr & 0x0F;
X bgnd = (ulong) (cur_attr >> 4) & 0x0F;
X colors_normal |= (fgnd << 8) | bgnd;
X colors_initial = colors_normal; /* save for restore_initial_colors */
X
X} /* end of get_initial_colors */
X#endif
X
X/*+-------------------------------------------------------------------------
X read_colors_file()
X--------------------------------------------------------------------------*/
Xvoid
Xread_colors_file()
X{
XFILE *fp;
Xchar s128[128];
X#define MAX_COLOR_TOKENS 6
Xchar *tokens[MAX_COLOR_TOKENS];
Xint ntokens;
Xchar *cptr;
Xint itmp;
X
X if(tty_not_char_special)
X return;
X
X#if defined(M_UNIX)
X get_initial_colors();
X#endif
X
X get_home_dir(s128);
X strcat(s128,"/.ecu/colors");
X if(access(s128,4))
X return;
X
X fp = fopen(s128,"r");
X
X while(fgets(s128,sizeof(s128),fp))
X {
X if(s128[0] == '#') /* comment? */
X continue;
X if(itmp = strlen(s128)) /* itmp = len; if > 0 ... */
X {
X itmp--;
X s128[itmp] = 0; /* ... strip trailing NL */
X }
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_str_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 fclose(fp);
X} /* end of read_colors_file */
X
X/*+-------------------------------------------------------------------------
X ring_bell()
X--------------------------------------------------------------------------*/
Xvoid
Xring_bell()
X{
X if(tty_not_char_special)
X return;
X
X fputc(7,se);
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{
Xint itmp;
Xint monitor_type;
Xchar *cptr;
Xint fddevtty = open("/dev/tty",O_RDONLY,0);
X
X /*
X * get control tty control chars in case stdin not tty
X */
X if(fddevtty >= 0)
X {
X ioctl(fddevtty,TCGETA,(char *)&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 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_ansi = (param == TTYINIT_FORCE_ANSI);
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 * if pts
X */
X
X#if defined(METRLINK_X11R4_PTS)
X memset((char *)&pts000,0xFF,sizeof(struct stat));
X stat("/dev/pts000",&pts000);
X if((tty_stat.st_rdev & 0xFF00) == (pts000.st_rdev & 0xFF00))
X tty_is_pts = 1;
X#endif /* METRLINK_X11R4_PTS */
X
X /*
X * use color if we are on a multiscreen and video supports it
X * also, remember whether or not we are on a multiscreen
X * (I ain't proud of this beyond being a valiant attempt)
X */
X use_colors = 0;
X if( ((itmp = ioctl(TTYIN,CONS_GET,&monitor_type)) >= 0) &&
X (use_colors = (monitor_type != MONO)))
X {
X read_colors_file();
X setcolor(colors_normal);
X }
X tty_is_multiscreen = !(itmp < 0);
X
X /*
X * save initial tty state
X */
X ioctl(TTYIN,TCGETA,(char *)&tty_termio_at_entry);
X tty_escape_timeout =
X B_to_timeout_msec(tty_termio_at_entry.c_cflag,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#if defined(M_SYSV)
X cptr = (char *)0;
X if(param)
X tty_is_ansi = (param == TTYINIT_FORCE_ANSI);
X else
X tty_is_ansi = ((cptr = getenv("TERM")) && (ulindex(cptr,"ansi") != -1));
X#else
X tty_is_ansi = 0; /* if not SCO, always use ~/.ecu/nonansikeys */
X cptr = getenv("TERM");
X#endif
X
X if(!tty_is_ansi && cptr)
X nonansi_key_read(cptr);
X
X/* initialize termcap */
X tcap_init(); /* read termcap strings */
X
X/* yetch - magic number gretching for lines and columns */
X if((tcap_LINES < 16) || (tcap_LINES > 43))
X {
X ff(se,"screen height must be >= 16 and <= 43 lines. (found %dx%d)\r\n",
X tcap_COLS,tcap_LINES);
X termecu(TERMECU_USAGE);
X }
X if(tcap_COLS != 80)
X {
X ff(se,"terminal width must be 80 columns.\r\n");
X termecu(TERMECU_USAGE);
X }
X if(!tcap_LINES || !tcap_COLS)
X {
X tcap_LINES = 25;
X tcap_COLS = 80;
X }
X if(tcap_LINES > 43)
X tcap_LINES = 43;
X if(tcap_COLS > 80)
X tcap_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} /* 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 attributes at start of execution, but with echo disabled and no parity
X 4 same as 2 but terminate program on SIGINT
X
X------------------------------------------------------------------------*/
Xvoid
Xttymode(arg)
Xint arg;
X{
X
X if(tty_not_char_special)
X return;
X
X ttymode_termecu_on_sigint = (arg == 4);
X
X switch(arg)
X {
X case 0:
X ioctl(TTYIN,TCSETAW,(char *)&tty_termio_at_entry);
X tty_termio_current = tty_termio_at_entry;
X current_ttymode = 0;
X break;
X
X case 1:
X case 2:
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 tty_termio_current.c_iflag &=
X ~(INLCR | ICRNL | IGNCR | IXON | IUCLC | ISTRIP);
X tty_termio_current.c_iflag |= IXOFF; /* this end will xon/xoff */
X
X tty_termio_current.c_oflag |= OPOST;
X tty_termio_current.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
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 ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
X current_ttymode = arg;
X break;
X
X case 3:
X tty_termio_current = tty_termio_at_entry;
X tty_termio_current.c_cflag &= ~(PARENB | PARODD);
X tty_termio_current.c_cflag |= CS8;
X tty_termio_current.c_iflag &= ~(ISTRIP);
X tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
X ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
X current_ttymode = 3;
X break;
X
X default:
X ff(se,"\r\nttymode: invalid argument %d\r\n",arg);
X break;
X }
X} /* end of ttymode */
X
X/*+-------------------------------------------------------------------------
X ttynormal_opost()
X--------------------------------------------------------------------------*/
Xvoid
Xttynormal_opost()
X{
X tty_termio_current.c_oflag = tty_termio_at_entry.c_oflag;
X ioctl(TTYIN,TCSETAW,(char *)&tty_termio_current);
X
X} /* end of ttynormal_opost */
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 ioctl(TTYIN,TCXONC,(char *)0); /* stop tty output */
X
X#if !defined(M_I286)
X ioctl(TTYIN,TCFLSH,(char *)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); break;
X case 1:
X ioctl(TTYIN,TCFLSH,(char *)1); break;
X case 2:
X ioctl(TTYIN,TCFLSH,(char *)2); break;
X }
X#endif
X
X ioctl(TTYIN,TCXONC,(char *)1); /* restart tty output */
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 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{
Xuchar ctmp;
Xextern int errno;
Xregister uint itmp = 0;
Xlong timeout_remaining;
Xstatic uchar tgc_accum[16];
Xuchar map_nonansi_key();
X
X if(tty_not_char_special) /* this really is unexplored territory */
X {
X ctmp = 255;
X read(0,(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 return((uint)ctmp);
X }
X
XGET_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(kbd_is_7bit)
X ctmp &= 0x7F;
X
X if(tty_is_ansi && (ctmp == ESC)) /* if escape from ansi terminal */
X {
X itmp = 0;
X timeout_remaining = tty_escape_timeout;
X while((!isalpha(ctmp)) && (itmp < sizeof(tgc_accum) - 1) &&
X (timeout_remaining > 0))
X {
X timeout_remaining -= nap(hzmsec);
X if(!rdchk(TTYIN))
X continue;
X read(TTYIN,(char *)&ctmp,1);
X if(kbd_is_7bit)
X ctmp &= 0x7F;
X if(itmp == (sizeof(tgc_accum) - 1)) /* do not allow overflow */
X break;
X tgc_accum[itmp++] = ctmp;
X if(itmp == 2)
X break;
X }
X tgc_accum[itmp] = 0;
X if(!itmp) /* no subsequent chars, so ... */
X return(ESC); /* return the escape */
X else if((itmp == 2) && (tgc_accum[0] == '['))
X {
X switch(tgc_accum[1] | 0x80)
X {
X case XFcur5:
X screen_dump(screen_dump_file_name);
X goto GET_KEY;
X case XFcurup: case XFcurdn: case XFcurrt: case XFcurlf:
X case XFend: case XFpgdn: case XFhome: case XFpgup: case XFins:
X case XF1: case XF2: case XF3: case XF4: case XF5: case XF6:
X case XF7: case XF8: case XF9: case XF10: case XF11: case XF12:
X case XFbktab:
X if(xkey_ok)
X return(tgc_accum[1] | 0x80);
X /* fall thru -- xkey not allowed */
X default:
X ring_bell();
X goto GET_KEY;
X }
X /*NOTREACHED*/
X }
X /* not func key -- must be typamatic control key */
X dole_out_tgc_accum_count = itmp - 1;
X dole_out_tgc_accum = tgc_accum + 1;
X return((uint)tgc_accum[0]);
X }
X else if(!tty_is_ansi && (ctmp >= 0x01) && (ctmp <= 0x1F) &&
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 while(((ctmp = map_nonansi_key(tgc_accum,itmp)) >= XF_no_way) &&
X (timeout_remaining > 0))
X {
X timeout_remaining -= nap(hzmsec);
X if(!rdchk(TTYIN))
X continue;
X read(TTYIN,(char *)&ctmp,1);
X timeout_remaining = tty_escape_timeout;
X if(kbd_is_7bit)
X ctmp &= 0x7F;
X if(itmp == (sizeof(tgc_accum) - 1)) /* do not allow overflow */
X break;
X tgc_accum[itmp++] = ctmp;
X }
X tgc_accum[itmp] = 0;
X if((ctmp == XF_not_yet) && (itmp == 1))
X return(tgc_accum[0]);
X else if(ctmp < XF_no_way) /* if we got a map */
X {
X if(!xkey_ok)
X {
X ring_bell();
X goto GET_KEY;
X }
X switch(ctmp)
X {
X case KDEk_CU5:
X screen_dump(screen_dump_file_name);
X goto GET_KEY;
X default:
X return(KDEk_to_XF[ctmp]);
X }
X /*NOTREACHED*/
X }
X /* not func key -- must be typamatic control key */
X dole_out_tgc_accum_count = itmp - 1;
X dole_out_tgc_accum = tgc_accum + 1;
X return((uint)tgc_accum[0]);
X }
X return(ctmp);
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{
Xregister inch;
Xregister strcount = 0;
Xregister strpos = 0;
Xint insert_mode = 0;
X
X --maxsize; /* decrement for safety */
X
X if(flags & TG_EDIT)
X {
X strpos = strcount = strlen(str);
X fputs(str,se);
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 fputc(BS,se);
X fputc(SPACE,se);
X fputc(BS,se);
X strcount--;
X }
X str[strcount] = 0;
X *delim = ESC;
X goto RETURN;
X }
X else if(inch == kbdkill)
X {
X tcap_curright(strcount - strpos);
X while(strcount)
X {
X fputc(BS,se);
X fputc(SPACE,se);
X fputc(BS,se);
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 fputc(BS,se);
X fputc(SPACE,se);
X fputc(BS,se);
X strcount--,strpos--;
X }
X else
X {
X if(!strpos)
X continue;
X mem_cpy(str + strpos - 1,str + strpos,strcount - strpos);
X fputc(BS,se);
X str[--strcount] = 0;
X strpos--;
X fputs(str + strpos,se);
X fputc(' ',se);
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 fputc(BS,se);
X fputc(SPACE,se);
X fputc(BS,se);
X strcount--;
X }
X#endif
X str[strcount] = 0;
X goto 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 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 fputs(str,se);
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 & 0x7F;
X strpos++;
X fputc(inch,se);
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 fputs(str + strpos++,se);
X tcap_curleft(strcount - strpos);
X }
X else
X {
X str[strpos++] = inch;
X fputc(inch,se);
X }
X }
X str[strcount] = 0;
X continue;
X }
X }
X
XRETURN:
X if(pstrpos)
X *pstrpos = strpos;
X
X} /* end of ttygets() */
X
X#ifdef notdef
Xvoid
Xttygets(str,maxsize,flags,delim,pstrpos)
Xregister char *str;
Xint maxsize;
Xint flags;
Xuchar *delim;
Xint *pstrpos;
X{
Xff(se,"\r\n>>>ttygets str='%s' strpos=%d flag=%d\r\n",str,*pstrpos,flags);
X _ttygets(str,maxsize,flags,delim,pstrpos);
Xff(se,"\r\n>>>ttygets buf='%s' strpos=%d delim=%02x\r\n",str,*pstrpos,*delim);
X}
X#endif
X
X/*+-------------------------------------------------------------------------
X ttygets_esd(tesd,flags,append_flag)
X--------------------------------------------------------------------------*/
Xttygets_esd(tesd,flags,append_flag)
XESD *tesd;
Xint flags;
Xint append_flag;
X{
Xchar *pb = tesd->pb;
Xint maxcb = tesd->maxcb;
Xuchar 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 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
Xchar *ttyname();
X return(ttyname(TTYIN));
X#else
Xstatic char ttname[64];
Xregister unsigned int rdev;
Xregister 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/* end of ecutty.c */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0725125791 'ecutty.c' &&
chmod 0644 ecutty.c ||
echo 'restore of ecutty.c failed'
Wc_c="`wc -c < 'ecutty.c'`"
test 29441 -eq "$Wc_c" ||
echo 'ecutty.c: original size 29441, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecutty.h ==============
if test -f 'ecutty.h' -a X"$1" != X"-c"; then
echo 'x - skipping ecutty.h (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecutty.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecutty.h' &&
X/*+-------------------------------------------------------------------------
X ecutty.h
X wht@n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
X/*:07-14-1991-18:19-wht@n4hgf-new ttygets functions */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
Xtypedef struct color_type
X{
X char *name;
X int num;
X} COLOR;
X
X#ifdef DEFINE_TTY_DATA
XCOLOR colors[] =
X{
X { "black", 0 },
X { "blue", 1 },
X { "brown", 6 },
X { "cyan", 3 },
X { "gray", 8 },
X { "green", 2 },
X { "hi_white", 15 },
X { "lt_blue", 9 },
X { "lt_cyan", 11 },
X { "lt_green", 10 },
X { "lt_magenta", 13 },
X { "lt_red", 12 },
X { "magenta", 5 },
X { "red", 4 },
X { "white", 7 },
X { "yellow", 14 },
X {(char *)0,-1}
X};
X#else
Xextern COLOR colors[];
X#endif
X
X/* color words are ulong:
X MSB: reverse video foreground
X reverse video background
X normal video foreground
X LSB: normal video background
X*/
X
X/*
X * ttygets flag bits
X */
X#define TG_CRLF 1 /* echo cr/lf terminator */
X#define TG_XDELIM 2 /* extended delimiter set */
X#define TG_EDIT 4 /* redisplay/edit current string */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of ecutty.h */
SHAR_EOF
$TOUCH -am 0725125791 'ecutty.h' &&
chmod 0644 ecutty.h ||
echo 'restore of ecutty.h failed'
Wc_c="`wc -c < 'ecutty.h'`"
test 1239 -eq "$Wc_c" ||
echo 'ecutty.h: original size 1239, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecuuclc.c ==============
if test -f 'ecuuclc.c' -a X"$1" != X"-c"; then
echo 'x - skipping ecuuclc.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecuuclc.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuuclc.c' &&
X/*+-----------------------------------------------------------------------
X ecuuclc.c - uuper/lower-case string functions
X wht@n4hgf.Mt-Park.GA.US
X
X Defined functions:
X minunique(str1,str2,minquan)
X to_lower(ch)
X to_upper(ch)
X ulcmpb(str1,str2)
X ulindex(str1,str2)
X ulrindex(str1,str2)
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X/*+-------------------------------------------------------------------------
X to_upper() / to_lower()
X one would think that these were relatively standard
X types of thing, but MSC/Xenix specifies toupper() to convert to upper
X case if not already and Unix says to adjust without testing,
X so, two stupid little routines here
X ASCII only -- no EBCDIC gradoo here please
X--------------------------------------------------------------------------*/
Xchar to_upper(ch)
Xregister char ch;
X{ return( ((ch >= 'a') && (ch <= 'z')) ? ch - 0x20 : ch);
X} /* end of to_upper() */
X
Xchar to_lower(ch)
Xregister char ch;
X{ return( ((ch >= 'A') && (ch <= 'Z')) ? ch + 0x20 : ch);
X} /* end of to_lower() */
X
X/*+----------------------------------------------------------------------------
X ulcmpb(str1,str) -- Upper/Lower [case insensitive] Compare Bytes
X
X Returns -1 if strings are equal, else failing character position
X If the second strings terminates with a null and both strings have matched
X character for character until that point, then -1 is returned.
X NOTE: this is not a test for complete equality of two strings, but allows
X discovery of a string as a substring in a larger containing string.
X-----------------------------------------------------------------------------*/
Xint
Xulcmpb(str1,str2)
Xregister unsigned char *str1;
Xregister unsigned char *str2;
X{
Xregister istr;
X
X for( istr=0 ; ; ++istr )
X {
X if(str2[istr] == '\0') /* if second string exhausts, match! */
X return(-1);
X if((str1[istr] == '\0' ) ||
X ( to_upper(str1[istr]) != to_upper(str2[istr]) ))
X return(istr);
X }
X /*NOTREACHED*/
X} /* end of ulcmpb */
X
X/*+-------------------------------------------------------------------------
X ulindex: Upper/Lower [case insensitive] Index function
X
X Returns position of 'str2' in 'str1' if found
X If 'str2' is null, then 0 is returned (null matches anything)
X Returns -1 if not found
X
X uses 'ulcmpb'
X--------------------------------------------------------------------------*/
Xint
Xulindex(str1,str2)
Xregister char *str1; /* the (target) string to search */
Xregister char *str2; /* the (comparand) string to search for */
X{
Xregister istr1 = 0; /* moving index into str1 */
Xregister char *mstr = str1; /* moving string pointer */
X
X if(str2[0] == '\0') /* null string matches anything */
X return(0);
X if(strlen(str2) > strlen(str1))
X return(-1);
X while(1)
X {
X if(*mstr == '\0') /* if we exhaust target string, flunk */
X return(-1);
X /* Can we find either case of first comparand char in target? */
X if( to_upper(*mstr) == to_upper(str2[0]) )
X {
X /* we have a first char match... does rest of string match? */
X if(ulcmpb(mstr,str2) == -1) /* if the rest matches, ... */
X return(istr1); /* ... return match position */
X }
X /* we did not match this time... increment istr1, mstr and try again */
X ++istr1;
X ++mstr;
X }
X} /* end of ulindex */
X
X/*+-------------------------------------------------------------------------
X ulrindex: Upper/Lower [case insensitive] Right Index function
X
X Returns position of 'str2' in 'str1' if found
X Returns -1 if not found
X If 'str2' is null, then -1 is returned
X
X uses 'ulcmpb'
X--------------------------------------------------------------------------*/
Xint
Xulrindex(str1,str2)
Xregister char *str1; /* the (target) string to search */
Xregister char *str2; /* the (comparand) string to search for */
X{
Xregister char *mstr;
Xregister istr1;
X
X if(!str2[0]) /* null string matches anything */
X return(-1);
X if(strlen(str2) > strlen(str1))
X return(-1);
X
X mstr = str1 + strlen(str1) - strlen(str2); /* moving string pointer */
X istr1 = mstr - str1; /* moving index into str1 */
X
X while(mstr >= str1)
X {
X /* Can we find either case of first comparand char in target? */
X if( to_upper(*mstr) == to_upper(str2[0]) )
X {
X /* we have a first char match... does rest of string match? */
X if(ulcmpb(mstr,str2) == -1) /* if the rest matches, ... */
X return(istr1); /* ... return match position */
X }
X /* we did not match this time... increment istr1, mstr and try again */
X --istr1;
X --mstr;
X }
X return(-1);
X} /* end of ulrindex */
X
X/*+----------------------------------------------------------------
X minunique(str1,str2,minquan)
X
X Returns 1 if at least 'minquan' chars of str2 match
X str1 and there are no chars after the minimum unique
X chars which do not match str1. Returns 0 on failure.
X-----------------------------------------------------------------*/
Xint
Xminunique(str1,str2,minquan)
Xregister char *str1;
Xregister char *str2;
Xregister minquan;
X{
Xregister index;
X
X if(strlen(str2) < minquan)
X return(0);
X
X index = ulcmpb(str1,str2);
X if(index < 0)
X return(1);
X
X if(index < minquan)
X return(0);
X if(index < strlen(str2))
X return(0);
X
X return(1);
X
X} /* end of minunique */
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0725125791 'ecuuclc.c' &&
chmod 0644 ecuuclc.c ||
echo 'restore of ecuuclc.c failed'
Wc_c="`wc -c < 'ecuuclc.c'`"
test 5667 -eq "$Wc_c" ||
echo 'ecuuclc.c: original size 5667, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecuungetty.h ==============
if test -f 'ecuungetty.h' -a X"$1" != X"-c"; then
echo 'x - skipping ecuungetty.h (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecuungetty.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuungetty.h' &&
X/*+-------------------------------------------------------------------------
X ecuungetty.h
X wht@n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X/* ungetty definitions */
X#define UG_NOTENAB 0 /* on no-switch exec, line not enabled */
X#define UG_ENAB 1 /* on no-switch exec, -r needed */
X#define UG_RESTART 1 /* on -t exec, restart needed */
X#define UG_FAIL 2 /* on no switch exec, line in use */
X
X/* extended ecuungetty codes */
X#define UGE_BADSWITCH 240 /* usage: bad switch */
X#define UGE_BADARGC 241 /* usage: bad arg count */
X#define UGE_NOTROOT 242 /* ecuungetty found it had no root privileges */
X#define UGE_CALLER 243 /* caller is not ecu or root */
X#define UGE_T_LOGIN 230 /* -t found utmp status US_LOGIN */
X#define UGE_T_LOGGEDIN 231 /* -t found utmp status US_LOGGGEDIN */
X#define UGE_T_NOTFOUND 232 /* -t found utmp status US_NOTFOUND */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of ecuungetty.h */
SHAR_EOF
$TOUCH -am 0725125791 'ecuungetty.h' &&
chmod 0644 ecuungetty.h ||
echo 'restore of ecuungetty.h failed'
Wc_c="`wc -c < 'ecuungetty.h'`"
test 1102 -eq "$Wc_c" ||
echo 'ecuungetty.h: original size 1102, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecuusage.c ==============
if test -f 'ecuusage.c' -a X"$1" != X"-c"; then
echo 'x - skipping ecuusage.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecuusage.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuusage.c' &&
X/*+-----------------------------------------------------------------------
X ecuusage.c - user admonishment
X wht@n4hgf.Mt-Park.GA.US
X
X Defined functions:
X general_usage(uptr)
X log_cmd_usage()
X usage()
X
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
X/*:07-04-1991-19:43-wht@n4hgf-use pputs instead of fputs to se */
X/*:04-27-1991-01:52-wht@n4hgf-overhaul revision numbers */
X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
X
X#include <stdio.h>
X#include "termecu.h"
X#define ff fprintf
X#define se stderr
X
Xextern char *makedate; /* temporary make date */
Xextern char *revstr; /* ecunumrev.c */
X
Xchar *usage_text[] =
X{
X"usage: ecu [-l /dev/tty<ttynum>] [-b <baud_rate>] [-e] [-o] [-d]\n",
X" [-c <filename>] [-h] [-k] [-t] [-v[vv...]]\n",
X" [-p <initial_proc> | <phone_number>]\n",
X"Default: 2400,N,8 (use -e for even parity, -o for odd 7 data bits)\n",
X"-c <filename> use this file rather than ~/.ecumodem\n",
X"-h half duplex ... default is full duplex\n",
X"-v verbosity ... the more 'v's the more verbosity.\n",
X"-d stop execution if -p initial procedure fails\n",
X"-D unconditionally stop execution when -p initial procedure is done\n",
X"\n",
X"For a list of built in commands, type HOME?<ENTER> once program started\n",
X"\n",
X"For access to line with no dialing try: ecu - [-eosv]\n",
X"However, program default line may be busy or not exist\n",
X (char *)0 /* terminated with null pointer */
X};
X
Xchar *log_cmd_usage_text[] =
X{
X"Usage: log [-s] [-r] <filename>\n",
X" log off turn logging off\n",
X" -s scratch any previous contents of <filename>, else append\n",
X" -r raw log, else drop 0x00-0x08,0x11-0x1F,0x7F-0xFF\n",
X (char *)0 /* terminated with null pointer */
X};
X
X/*+-----------------------------------------------------------------------
X general_usage(uptr)
X------------------------------------------------------------------------*/
Xvoid
Xgeneral_usage(uptr)
Xregister char **uptr;
X{
X while(*uptr != (char *)0)
X pputs(*(uptr++));
X} /* end of usage */
X
X/*+-----------------------------------------------------------------------
X usage()
X------------------------------------------------------------------------*/
Xvoid
Xusage()
X{
X ff(se,"ecu %s made: %s\n",revstr,makedate);
X general_usage(usage_text);
X termecu(TERMECU_USAGE);
X /*NOTREACHED*/
X}
X
X/*+-------------------------------------------------------------------------
X log_cmd_usage()
X--------------------------------------------------------------------------*/
Xvoid
Xlog_cmd_usage()
X{
X general_usage(log_cmd_usage_text);
X} /* end of log_cmd_usage */
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0725125791 'ecuusage.c' &&
chmod 0644 ecuusage.c ||
echo 'restore of ecuusage.c failed'
Wc_c="`wc -c < 'ecuusage.c'`"
test 2683 -eq "$Wc_c" ||
echo 'ecuusage.c: original size 2683, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ecuutil.c ==============
if test -f 'ecuutil.c' -a X"$1" != X"-c"; then
echo 'x - skipping ecuutil.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ecuutil.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ecuutil.c' &&
X/*+-----------------------------------------------------------------------
X ecuutil.c -- utility routines for extended calling unit
X wht@n4hgf.Mt-Park.GA.US
X
X Defined functions:
SHAR_EOF
true || echo 'restore of ecuutil.c failed'
fi
echo 'End of ecu310 part 10'
echo 'File ecuutil.c is continued in part 11'
echo 11 > _shar_seq_.tmp
exit 0
--------------------------------------------------------------------
Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
Hacker Extraordinaire d' async PADs, pods, proteins and protocols
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD UUCP: uunet!sparky!kent
Phone: (402) 291-8300 FAX: (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.