home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * kb_handl.c - keyboard handler functions.
- *
- * Purpose: Functions for getting keyboard input from the IBM PC.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include "blackstr.h"
- #include "kb_head.h"
- #include "kb_defs.h"
- #include "ut_head.h"
- #include "primitiv.h"
-
- extern void exit(int status);
-
-
- /********
- *
- * kb_getc() - raw keyboard input
- *
- **/
-
- int kb_getc(void)
- {
- int i;
- char *ptr;
-
- i = kb_getc_(); /* get it from driver */
- if(!(i & 0x00ff)) { /* extended keys */
- ptr = keystbl_; /* key scan xlate table */
- i/= 256; /* ah has character */
- while(*ptr) { /* table is null terminated */
- if(*ptr==i)
- return(0x00ff&(short int)(*(++ptr)));
- else
- ptr += 2; /* next pair */
- }
- }
- return(i & 0x00ff); /* mask off hi byte */
- }
-
-
- /********
- *
- * kb_getch() - get character w break & echo
- *
- **/
-
- int kb_getch(void)
- {
- int i;
-
- i = kb_getc();
- if((breakf_) && (kb_isbrk(i)))
- sy_abort();
- if ((echof_) && (!kb_isfun(i)))
- sc_putch(i);
- return(i);
- }
-
-
- /********
- *
- * kb_gets(str) - get string from keyboard
- *
- **/
-
- char *kb_gets(char *str)
- {
- int j;
- char *ptr;
-
- ptr = str;
- while( ((j=kb_getch())!=NEWLINE) && (j!=CR) )
- *str++ = j;
- *str = NUL;
- return(ptr);
- }
-
-
- /********
- *
- * kb_init(ftbl,xtbl,btbl) - initialize keyboard (0,0,0) for default
- *
- **/
-
- void kb_init(char *ftbl, char *xtbl, char *btbl)
- {
- keystbl_ = keystbl1_; /* scan code table */
-
- /* function key table */
- (ftbl)? (keyftbl_ = ftbl) : (keyftbl_ = keyftbl1_);
-
- /* translation table */
- (xtbl)? (keyxtbl_ = xtbl) : (keyxtbl_ = keyxtbl1_);
-
- /* break table */
- (btbl)? (keybrktbl_= btbl) : (keybrktbl_= keybrktbl1_);
-
- kb_clr(); /* clear it */
- chinf_ = FALSE; /* clear char in flag */
- echof_ = TRUE; /* turn echo on */
- insmodef_=FALSE; /* insert off */
- breakf_ = TRUE; /* break on */
- }
-
-
- /********
- *
- * kb_getchar() - get character from keyboard with break ctrl-c
- *
- **/
-
- int kb_getchar(void)
- {
- int i;
-
- i = kb_getc(); /* get character */
- if (i==CTRL_C)
- exit(0); /* just exit */
- if(echof_)
- sc_putch(i);
- return(i);
- }
-
-
- /********
- *
- * kb_ungetc(c) - return previously gotten character
- *
- **/
-
- int kb_ungetc(char c)
- {
- return(kb_ungetc_(c));
- }
-
-
- /********
- *
- * kb_inkey() - get key from keyboard if one available
- *
- **/
-
- int kb_inkey(void)
- {
- return (kb_hit()? kb_getc() : FALSE);
- }
-
-
- /********
- *
- * kb_hit() - see if key was struck on keyboard
- *
- **/
-
- int kb_hit(void)
- {
- return(kb_hit_());
- }
-
-
- /********
- *
- * kb_pause() - pause until keyboard hit
- *
- **/
-
- void kb_pause(void)
- {
- while(!kb_hit());
- kb_clr();
- }
-
-
- /********
- *
- * kb_tpause(time) - pause until keyboard hit or 100's secs passed
- *
- **/
-
- void kb_tpause(int time)
- {
- struct TIME stime;
- int t1,t2;
-
- ut_times(&stime); /* get current time */
- t1 = t2 = 100*stime.sec+stime.hsec;
-
- while((t2-t1<time) && (!kb_hit())) {
- ut_times(&stime);
- t2 = 100*stime.sec+stime.hsec;
- if(t2<t1)
- t2 += 6000; /* add a minute */
- }
- kb_clr();
- }
-
-
- /********
- *
- * kb_clr() - clear the keyboard
- *
- **/
-
- void kb_clr(void)
- {
- while(kb_hit())
- kb_getc();
- }
-