home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * kb_field.c - keyboard input field functions.
- *
- * Purpose: This file contains input routines for the console keyboard.
- * interrupts of the IBM PC.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <string.h>
- #include <ctype.h>
- #include "blackstr.h"
- #include "kb_head.h"
- #include "sc_head.h"
-
-
- /********
- *
- * kb_getf(str,n) - get string from field width n
- *
- **/
-
- int kb_getf(char *str, int n)
- {
- int c,ret;
- extern char chinf_,insmodef_;
- char *inptr,*ptr,inp[MAX_LN];
-
- inptr = inp;
- memset(inp,NUL,MAX_LN);
- *inptr = NUL;
- ret=FALSE;
- ut_push(wrapf_); /* turn wrap off for kb_getf */
- wrapf_ = FALSE;
- sc_winpush();
- sc_windo(sc_col_,sc_row_,sc_col_+n-1,sc_row_);
- while(!ret) { /* till we're done*/
- ut_push(echof_);
- echof_ = FALSE;
- c = kb_getch(); /* get character from keyboard */
- echof_ = ut_pop();
- switch (c) {
- case CUR_RT:
- case CTRL_D:
- if((sc_col_==colen_)&& (kb_isfun(c)))
- ret=TRUE;
- else {
- sc_movcur(1,0);
- ++inptr;
- }
- break;
- case BKSP:
- case CUR_LF:
- case CTRL_S:
- if((sc_col_==colst_)&&(kb_isfun(c)))
- ret=TRUE;
- else {
- sc_movcur(-1,0);
- --inptr;
- inptr=max(inp,inptr);
- }
- break;
- case DEL:
- if(strlen(inp)<n)
- sc_movcur(-1,0);
- --inptr;
- inptr= max(inp,inptr);
- case CTRL_G:
- st_movl(inptr,1); /* move string left */
- ut_push(sc_col_);
- sc_putsfl(inptr,n); /* put field w clear*/
- sc_col_=ut_pop();
- sc_setcur(sc_col_,sc_row_);
- chinf_=TRUE;
- break;
- case CTRL_V:
- case INS:
- insmodef_= (insmodef_-1) ? TRUE:FALSE;
- break;
- case HOME:
- sc_setcur(colst_,rowst_);
- break;
- case END_KY:
- sc_setcur(colen_,rowen_);
- break;
- default:
- if(kb_isfun(c)) {
- ret=TRUE; /* return function key */
- break;
- } else if(!kb_iskey(c))
- break;
-
- if(strlen(inp)<n)
- break; /* keep cursor inside field */
- if(insmodef_ && echof_) {
- st_movr(inptr,1);/* mov string over 1 space */
- ut_push(sc_col_);
- sc_putsf(inptr,n);
- sc_col_=ut_pop();
- sc_setcur(sc_col_,sc_row_);
- }
- if(echof_)
- sc_putc(c); /* display character */
- ptr = inp -1;
- while(++ptr<inptr)
- if(*ptr==NUL)
- *ptr=BLANK; /* blank fill*/
- *inptr++=c;
- chinf_=TRUE;
- break;
- }/* switch c */
-
- }/* while !ret */
- strcpy(str,inp);
- sc_winpop();
- wrapf_ = ut_pop(); /* restore old wrap flag */
- return(c);
- }
-
-
- /********
- *
- * kb_isfun(c) - see if c is function byte
- *
- **/
-
- int kb_isfun(char c)
- {
- char *ptr;
-
- ptr = keyftbl_; /* point to function key table */
- while(*ptr)
- if(*ptr++==c)
- return(TRUE);
- return(FALSE);
- }
-
-
- /********
- *
- * kb_iskey(c) - see if c is valid printable key
- *
- **/
-
- int kb_iskey(char c)
- {
- return(isprint(c));
- }
-
-
- /********
- *
- * kb_isbrk(c) - see if c is break key
- *
- **/
-
- int kb_isbrk(char c)
- {
- char *ptr;
-
- ptr = keybrktbl_;
- while(*ptr)
- if(*ptr++==c)
- return(TRUE);
- return(FALSE);
- }
-
-
- /********
- *
- * kb_input(msg,str) - input string with message
- *
- **/
-
- int kb_input(char *msg, char *str)
- {
- sc_puts(msg); /* output message */
- return(kb_getf(str,colen_-sc_col_)); /* get from field to eol*/
- }
-
-
- /********
- *
- * kb_inyorn(prompt) - input yes or no
- *
- **/
-
- int kb_inyorn(char *prompt)
- {
- char c;
-
- sc_puts(prompt);
- c = kb_getch();
- return ((toupper(c)=='Y')? TRUE : FALSE);
- }
-