/*****************************************************************************/ /* */ /* weditstr */ /* */ /* This function is derived from pbfname() which was written by Paul */ /* Beatty. It has been modified by Glen Weaver to be more general. */ /* This function allows the user to use the backspace and delete keys */ /* when inputing data to a program which is using windows. */ /* */ /*****************************************************************************/ #include #define BELL 0x7 #define CR 0xa #define BACKSPACE 0x08 #define DELETE 0x7f #define BEEP printf("%c",BELL) /* ------------------------------------------------------------------------- */ weditstr( window, x, y, str, leng ) WINDOW *window; int x,y; char str[]; int leng; /* contains the total length of the string */ { int count = 0; char c; c = wgetch(window); noecho(); while ( (count < leng - 1) && ( c!= CR) ) { if ((c == BACKSPACE) || (c == DELETE)) if (count > 0) { count = count - 1; wmove(window,x,count+y); wprintw(window," "); wmove(window,x,y+count); wrefresh(window); } /* end if count > 0 */ else BEEP; else { str[count] = c; wmove(window,x,y+count); wprintw(window,"%c",c); count = count + 1; wrefresh(window); } c = wgetch(window); } /* end of while */ if (count > 0) str[count] = '\0'; else { /* return a default value if nothing is specified */ str[0] = 'd'; str[1] = 'e'; str[2] = 'f'; str[3] = '\0'; } } /* end of weditstr */