📄 kb_input.c
字号:
default: return INVALID; break;
}
break;
default: /* <esc> followed by any other char */
esc_buff = key; /* may also be a new <esc> sequence */
return 0x1b;
break;
} /* switch (key) */
} /* <esc> sequence */
} /* check for <esc> sequence */
else
{
key = key & 0xff; /* special characters >= 0x80 are not negative ! */
return key; /* send directly */
}
} /* loc_get_1_int */
#endif
/* -FF- */
/*****************************************/
/* */
/* Other Operating Systems */
/* */
/* This is the region, to adapt the */
/* keyboard driver to a new operating */
/* system. Only some small functions */
/* have to be modified: */
/* */
/*****************************************/
#if 0
| | kb_input.c |
| | |
| application | translate vt220 | op-system specific |
| | (fix) | (to be adapted) |
---------------------------> kb_echo_off ()
---------------------------> kb_echo_on ()
<-----> get_1_key () <--+--> get_1_byte ()
|
+--> get_1_byte_with_timeout ()
|
<--------------------> +--> loc_key_pressed ()
global functions :
kb_echo_off ()
kb_echo_on ()
key_pressed ()
loc_key_pressed ()
get_1_key ()
loc_get_1_int ()
local functions :
get_1_byte ()
get_1_byte_with_timeout ()
#endif
/*****************************************/
/* */
/* OS_9 region */
/* */
/*****************************************/
#if (ACT_OP_SYSTEM == OS_9)
/* for OS-9000: simulate getstat + setstat */
#if (OS_9_PPC)
static scf_path_opts spo;
static scf_lu_opts slo;
static u_int32 size;
int getstat (int code, int path, struct _sgs *sgs)
{
int error, err1, err2;
size = sizeof(spo);
err1 = _os_gs_popt (path, &size, &spo);
size = sizeof(slo);
err2 = _os_gs_luopt (path, &size, &slo);
sgs->_sgs_class; /* file manager class code */
sgs->_sgs_case = spo.pd_case; /* 0 = upper and lower cases 1 = upper case only */
sgs->_sgs_backsp = spo.pd_backsp; /* 0 = BSE 1 = BSE-SP-BSE */
sgs->_sgs_delete = spo.pd_delete; /* delete sequence */
sgs->_sgs_echo = spo.pd_echo; /* 0 = no echo */
sgs->_sgs_alf = spo.pd_alf; /* 0 = no auto line feed */
sgs->_sgs_nulls = spo.pd_nulls; /* end of line null count */
sgs->_sgs_pause = spo.pd_pause; /* 0 = no end of page pause */
sgs->_sgs_page = spo.pd_page; /* lines per page */
sgs->_sgs_bspch = spo.pd_bspch; /* backspace character */
sgs->_sgs_dlnch; /* delete line character */
sgs->_sgs_eorch = spo.pd_eorch; /* end of record character */
sgs->_sgs_eofch = spo.pd_eofch; /* end of file character */
sgs->_sgs_rlnch; /* reprint line character */
sgs->_sgs_dulnch; /* duplicate last line character */
sgs->_sgs_psch = slo.v_psch; /* pause character */
sgs->_sgs_kbich = slo.v_intr; /* keyboard interrupt character */
sgs->_sgs_kbach = slo.v_quit; /* keyboard abort character */
sgs->_sgs_bsech; /* backspace echo character */
sgs->_sgs_bellch = spo.pd_bellch; /* line overflow character (bell) */
sgs->_sgs_parity = slo.v_parity; /* device initialization (parity) */
sgs->_sgs_baud = slo.v_baud; /* baud rate */
sgs->_sgs_d2p; /* offset to second device name string */
sgs->_sgs_xon = slo.v_xon; /* x-on char */
sgs->_sgs_xoff = slo.v_xoff; /* x-off char */
sgs->_sgs_tabcr = spo.pd_tabch; /* tab character */
sgs->_sgs_tabsiz = spo.pd_tabsiz; /* tab size */
sgs->_sgs_tbl; /* Device table address (copy) */
sgs->_sgs_col = spo.pd_col; /* Current column number */
sgs->_sgs_err = spo.pd_err; /* most recent error status */
error = 0;
if (err1) error = err1;
if (err2) error = err2;
return error;
} /* getstat */
int setstat (int code, int path, struct _sgs *sgs)
{
int error, err1, err2;
spo.pd_optsize; /* path options table size */
spo.pd_extra; /* maintain long allignment */
spo.pd_inmap[32]; /* Input control character mapping table */
spo.pd_eorch = sgs->_sgs_eorch; /* end of record character (read only) */
spo.pd_eofch = sgs->_sgs_eofch; /* end of file character */
spo.pd_tabch = sgs->_sgs_tabcr; /* Tab character */
spo.pd_bellch = sgs->_sgs_bellch; /* bell (line overflow) */
spo.pd_bspch = sgs->_sgs_bspch; /* backspace echo character */
spo.pd_case = sgs->_sgs_case; /* case 0 = both */
spo.pd_backsp = sgs->_sgs_backsp; /* backspace 0 = backspace */
spo.pd_delete = sgs->_sgs_delete; /* delete 0 = carriage return, line feed */
spo.pd_echo = sgs->_sgs_echo; /* echo 0 = no echo */
spo.pd_alf = sgs->_sgs_alf; /* auto-linefeed 0 = no auto line feed */
spo.pd_pause = sgs->_sgs_pause; /* pause 0 = no end of page pause */
spo.pd_insm; /* insert mode 0 = type over */
spo.pd_nulls = sgs->_sgs_nulls; /* end of line null count */
spo.pd_page = sgs->_sgs_page; /* lines per page */
spo.pd_tabsiz = sgs->_sgs_tabsiz; /* tab field size */
spo.pd_err = sgs->_sgs_err; /* most recent I/O error status */
spo.pd_rsvd[2]; /* reserved */
spo.pd_col = sgs->_sgs_col; /* current column number */
spo.pd_time; /* time out value for unblocked reads */
spo.pd_deventry; /* Device table address (copy) */
slo.v_optsize; /* options section size */
slo.v_class; /* device type; 0 = SCF */
slo.v_err; /* accumulated errors */
slo.v_pause; /* immediate pause request */
slo.v_line; /* lines left until end of page */
slo.v_intr = sgs->_sgs_kbich; /* keyboard interrupt character */
slo.v_quit = sgs->_sgs_kbach; /* keyboard quit character */
slo.v_psch = sgs->_sgs_psch; /* keyboard pause character */
slo.v_xon = sgs->_sgs_xon; /* x-on character */
slo.v_xoff = sgs->_sgs_xoff; /* x-off character */
slo.v_baud = sgs->_sgs_baud; /* Baud rate */
slo.v_parity = sgs->_sgs_parity; /* Parity */
slo.v_stopbits; /* Stop bits */
slo.v_wordsize; /* Word size */
slo.v_rtsstate; /* RTS state: disable = 0; enable = non-zero */
slo.v_dcdstate; /* current state of DCD line */
slo.v_reserved[9]; /* reserved for future use */
size = sizeof(spo);
err1 = _os_ss_popt (path, size, &spo);
size = sizeof(slo);
err2 = _os_ss_luopt (path, size, &slo);
error = 0;
if (err1) error = err1;
if (err2) error = err2;
return error;
} /* setstat */
#endif
#define CODE 0 /* for getstat, setstat */
static struct _sgs old; /* buffers for echo on/off */
static struct _sgs new;
/************************/
/* n msec's delay */
/************************/
void sleep_msec (int msec) /* OS_9 */
{ /* scale: msec --> timer ticks (LSB = 1 sec) */
/* msec /= TIMER_TICK; */ /* not any more */
msec = (int)(((long) msec * CLOCKS_PER_SEC) / 1000);
msec = max (2, msec); /* os/9: minimal 2 ticks */
tsleep (msec); /* do it */
return;
} /* sleep_msec (OS_9) */
/************************/
/* is key pressed ? */
/************************/
int loc_key_pressed (void)
{
/* return true, if key is pressed, else false */
if (input_redirected) return 0;
if (_gs_rdy (PATH_0) >= 0)
return 1;
else
return 0;
}
/************************/
/* get 1 single byte */
/************************/
static int get_1_byte (void)
{
char byte1;
int num;
num = read (PATH_0, &byte1, 1);
if ((input_redirected) && (num == 0))
return EOF;
else
return byte1;
} /* get_1_byte */
/************************/
/* get with timeout */
/************************/
static int get_1_byte_with_timeout (int wait_time)
{
/* if key is pressed before wait_time elapsed, key is returned, else -1 */
/* wait_time : LSB = 1 msec */
/* special cases: wait_time = 0 : no wait */
/* wait_time < 0 : wait forever */
int time;
#define SLEEP_GRANULARITY 10 /* resolution sleep_msec(), LSB = 1 msec */
/* wait forever ? */
if (wait_time < 0) return get_1_byte ();
/* is key already there ? */
if (loc_key_pressed ()) return get_1_byte ();
/* wait given time */
for (time = 0 ; time < wait_time ; time += SLEEP_GRANULARITY)
{
sleep_msec (SLEEP_GRANULARITY);
if (loc_key_pressed ()) return get_1_byte ();
}
return -1; /* timeout */
} /* get_1_byte_with_timeout */
/* -FF- */
/************************/
/* echo on / off */
/************************/
static int on_off;
void kb_echo_off (void)
{
#if (TEST_PRINT)
printf ("\n>>> kb_echo_off: input_redirected = %d, on_off = %d \n",
input_redirected, on_off);
#endif
if (input_redirected) return;
if (on_off == 0)
{
/* get current settings */
getstat (CODE, PATH_0, &old); /* saved in old */
memcpy (&new, &old, sizeof (new)); /* copied to new */
/* set options */
new._sgs_echo = 0;
new._sgs_pause = 0;
new._sgs_eorch = 0;
new._sgs_eofch = 0;
new._sgs_alf = 0; /* no auto <lf> */
new._sgs_kbich = 0; /* ^C */
new._sgs_kbach = 0; /* ^E */
new._sgs_xon = 0; /* ^S */
new._sgs_xoff = 0; /* ^Q */
/* write back new settings */
if (setstat (CODE, PATH_0, &new) != -1)
on_off = 1; /* o.k. */
}
set_wrap_off();
return;
} /* kb_echo_off */
void kb_echo_on (void)
{
#if (TEST_PRINT)
printf ("\n>>> kb_echo_on: input_redirected = %d, on_off = %d \n",
input_redirected, on_off);
#endif
if (input_redirected) return;
if (on_off == 1)
{
/* write back old settings */
if (setstat (CODE, PATH_0, &old) != -1)
on_off = 0;
}
set_wrap_on();
return;
} /* kb_echo_on */
#endif /* OS_9 */
/* -FF- */
/*****************************************/
/* */
/* UNIX region */
/* */
/*****************************************/
#if (UNIX)
static struct termio tbufsave;
static struct termio tbuf;
/* -FF- */
/* error display in status line (given text + errno) */
void syserr (char *text)
{
char ges_line [81];
char err_disp [30];
/* build complete line */
strncpy (ges_line, text, (sizeof(ges_line) - 1));
sprintf (err_disp, ", errno = %d", errno);
/* check for buffer overflow */
if ((strlen(ges_line) + strlen(err_disp)) < sizeof(ges_line))
strcat (ges_line, err_disp);
/* display */
line_2_flag = 1;
show_status_line_2 (ges_line, 0, -2, 1);
beep ();
fflush (stdout);
sleep_msec (1000); /* 1 sec. pause */
return;
} /* syserr */
/* -FF- */
/************************/
/* n msec's delay */
/************************/
void sleep_msec (int msec) /* UNIX */
{
#if (WITH_USEC_CLOCK)
long goal, limit;
/* the behaviour of clock () is different in every system: */
/* System V Rel 4 (C): ..., 0x7fffffff, 0x80000000, 0x80000001, ... */
/* OSF/1 (C): ..., 0x7fffffff, 0x80000000, 0x80000001, ... */
/* SGI IRIX (T): ..., 0x7fffffff, 0x80000000, 0x80000001, ... */
/* ultrix 4.2 (C): ..., 0x7fffffff, 0xffffffff, 0xffffffff, ... !!! */
/* others : ?? */
/* By the way, another difference is the measured value: */
/* Some operating systems measure the expired time (T), */
/* some the actual used cpu time (C) !! */
/* SO THIS "clock()" STUFF IS NOTHING EXACTLY !! */
/* */
/* The other possibility to measure times in the msec range is */
/* the function ftime(), but this is not available everywhere. */
/* check for abnormal behaviour */
if (((long) clock() == -1L) || /* overflow ? e.g. ultrix ! */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -