home *** CD-ROM | disk | FTP | other *** search
- /* ==( dos/inchar.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Geo 26-Aug-88 */
- /* Modified Geo 28-Jun-90 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 28-Jun-90 Geo - newer code for exitcheck
- * 1-Mar-90 SBF - tx for CTRL-[A-Z] fixed
- * 26-Jan-90 Geo - tx mixed in for Dos/Unix
- * 25-Jul-89 Geo - Keyboard translate
- * 25-Oct-89 Geo - 1.32 Merge
- */
-
- /*
- * Input stream handler
- */
-
- # include <stdio.h>
- # include <bench.h>
-
-
- # ifdef MSDOS /* And it should be ! */
- # ifndef __TURBOC__ /* Complains about stuff - NIG */
- # ifndef LATTICE
- # include <conio.h> /* Prototye for kbhit() */
- # endif
- # endif
- # endif
-
- # include "pregs.h"
-
- static PROTO (int keyval, (unsigned char, char));
- static PROTO (int xlat_val, (int));
-
- # ifdef WDEBUG
- static PROTO (void exitcheck, (void));
- # endif
-
- /*
- * Warning do not modify this table
- * without changing corresponding table
- * says Geo 12-Dec-89
- */
- unsigned char scancodes[] =
- {
- /* Enter Tab Esc Bs Btab */
- 0x1c, 0x0f, 0x01, 0x0e, 0x00,
-
- /* Left Right Up Down */
- 0x4b, 0x4d, 0x48, 0x50,
-
- /* Ins Del Home End PgUp PgDn */
- 0x52, 0x53, 0x47, 0x4f, 0x49, 0x51,
-
- /* F1 F2 F3 F4 F5 */
- 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
-
- /* F6 F7 F8 F9 F10 */
- 0x40, 0x41, 0x42, 0x43, 0x44,
-
- /* F11 F12 F13 F14 F15 */
- 0x85, 0x86, 0x00, 0x00, 0x00,
-
- /* F16 F17 F18 F19 F20 */
- 0x00, 0x00, 0x00, 0x00, 0x00,
-
- /* AltF1 AltF2 AltF3 AltF4 AltF5 */
- 0x68, 0x69, 0x6a, 0x6b, 0x6c,
-
- /* AltF6 AltF7 AltF8 AltF9 AltF10 */
- 0x6d, 0x6e, 0x6f, 0x70, 0x71,
-
- /* ^F1 ^F2 ^F3 ^F4 ^F5 */
- 0x5e, 0x5f, 0x60, 0x61, 0x62,
-
- /* ^F6 ^F7 ^F8 ^F9 ^F10 */
- 0x63, 0x64, 0x65, 0x66, 0x67,
-
- /* AltA AltB AltC AltD AltE */
- 0x1e, 0x30, 0x2e, 0x20, 0x12,
-
- /* AltF AltG AltH AltI AltJ */
- 0x21, 0x22, 0x23, 0x17, 0x24,
-
- /* AltK AltL AltM AltN AltO */
- 0x25, 0x26, 0x32, 0x31, 0x18,
-
- /* AltP AltQ AltR AltS AltT */
- 0x19, 0x10, 0x13, 0x1f, 0x14,
-
- /* AltU AltV AltW AltX AltY */
- 0x16, 0x2f, 0x11, 0x2d, 0x15,
-
- /* AltZ */
- 0x2c,
-
- /* Alt1 Alt2 Alt3 Alt4 Alt5 */
- 0x78, 0x79, 0x7a, 0x7b, 0x7c,
-
- /* Alt6 Alt7 Alt8 Alt9 Alt0 */
- 0x7d, 0x7e, 0x7f, 0x80, 0x81,
-
- /* Alt- Alt= */
- 0x82, 0x83,
-
- /* ^Left ^Right */
- 0x73, 0x74,
-
- /* ^PrtSc */
- 0x72,
-
- /* ^End ^Home */
- 0x4f, 0x47,
-
- /* ^PgDn ^PgUp */
- 0x76, 0x84,
-
- 0
- /*
- * Add extra keys here but update crtio.h first
- * Cannot remap mouse keys
- * Also there are no scancodes for these
- */
- };
-
-
- /* Unget stuff */
- struct unget_struct
- {
- short key;
- struct unget_struct *next;
- };
-
- # define UGNULL (struct unget_struct *)0
-
- static struct unget_struct *unget_list = UGNULL;
-
- void unget_inchar(key)
- short key;
- {
- struct unget_struct *new;
- # ifdef WDEBUGI
- fprintf(stderr, "unget_inchar(%d)\r\n", key);
- # endif
-
- new = (struct unget_struct *)alloc(sizeof(struct unget_struct));
- new->key = key;
-
- if (unget_list == UGNULL)
- unget_list = new;
- else
- {
- struct unget_struct *uptr = unget_list;
-
- while (uptr->next != UGNULL)
- uptr = uptr->next;
-
- uptr->next = new;
- }
- }
-
- int inchar_hit()
- {
- # ifdef MSDOS
- return(kbhit());
- # else
- return(0);
- # endif
- }
-
- inchar_nowait()
- {
- if (unget_list != UGNULL || kbhit())
- return(inchar());
- else
- return(0);
- }
-
- int inchar()
- {
- unsigned char scode;
- char ch;
-
- /*
- * if unget_ichar was called
- */
- if (unget_list != UGNULL)
- {
- struct unget_struct *uptr;
- short ret;
-
- uptr = unget_list;
- ret = uptr->key;
- unget_list = uptr->next;
- free(uptr);
- return (ret);
- }
-
- retry:
- flushscr();
-
- # ifdef MOUSE
- /*
- * mouse support section - RN, Sept., 1989
- */
- {
- short ret;
-
- mouse_cursor(ON);
- if (ret = check_mouse())
- return(ret);
- }
- # endif
-
- {
- RegStorage;
-
- Regs_ah = 0x00;
- Keyboard();
- ch = Regs_al;
- scode = Regs_ah;
- }
-
- /* Ascii char */
- if (ch > 31)
- return(ch);
-
- /*
- * Right - can't get Ctrl-C
- * so redraw the screen - great for UNIX
- */
- if (ch == 3)
- {
- # ifdef WDEBUG
- exitcheck();
- # else
- redraws();
- # endif
- goto retry;
- }
- /* Function key */
- return(keyval(scode, ch));
- }
-
- /*
- * Re-maps input char
- * according defines in crtio.h
- */
- static int keyval(scode, ch)
- unsigned char scode;
- char ch;
- {
- int index = 0;
-
- if (scode && !ch)
- {
- unsigned char *result;
-
- /*
- * find the keyval as defined in crtio.h that corresponds to the scancode
- */
- result = memchr(scancodes, scode, sizeof(scancodes));
- if (result != NULL)
- {
-
- /* Watcom C 70 required this cast ! - Geo */
- index = (int)(result - (unsigned char *)scancodes);
- if (index < K_NULL - _K_Base(1))
- {
- extern short ttykeys[]; /* win.c */
- extern int tty_xlat;
-
- if (tty_xlat)
- return(ttykeys[index + 1]);
- else
- return(_K_Base(index + 1));
- }
- }
- }
-
- switch(ch)
- {
- /* And the rest ... */
- case '\033' : return(xlat_val(K_ESC));
- case '\n' :
- case '\r' : return(xlat_val(K_CR));
- case '\t' : return(xlat_val(K_TAB));
- case 127 : return(xlat_val(K_DEL));
- case '\b' : return(xlat_val(K_BS));
- }
-
- /*
- * Attempt to support control chars
- * any clash with standard '\n' etc.
- * will be resolved in above switch
- * DC1 & DC3 will never appear ...
- */
- if (iscntrl(ch))
- {
- /* Stronger test */
- if (ch > 0 && ch <= 26)
- return(xlat_val(K_CTRLA + (ch - 1)));
- }
- return(ch);
- }
-
- static int xlat_val(ch)
- int ch;
- {
- extern short ttykeys[]; /* win.c */
- extern int tty_xlat;
-
- if (tty_xlat)
- return(ttykeys[ch - _K_Base(0)]);
- else
- return(ch);
- }
-
-
- # ifdef WDEBUG
- /*
- * treat this routine as an interrupt
- * - go back if you don't know what
- * that means
- */
- static void exitcheck()
- {
- static int ctrlc = FALSE;
-
- /* Routine not re-entrant */
- if (ctrlc == TRUE)
- return;
-
- ctrlc = TRUE;
-
- create_w(20, 1, 4, 10);
- set_w(REVVIDBLINK, ' ');
- border_w(0, REVVIDBLINK);
-
- xdisp_w(2, 2, BOLD, " Quit ");
- xdisp_w(3, 2, BOLD, "Continue");
-
- if (inchar() == 'q')
- {
- resetscr();
- exit(1);
- }
-
- delete_w();
-
- ctrlc = FALSE;
- }
- # endif
-
-