|
|
1.1 ! root 1: /* get_data.c: Given a window, coordinates and a required flag, this ! 2: * function will move the cursor to the given coordinates, ! 3: * and accept keyboard input up to a limit also passed to this ! 4: * function. The data will be echoed to the screen as it is ! 5: * entered and the function will return a pointer to the ! 6: * string enetered when done. ! 7: */ ! 8: ! 9: #include "uuinstall.h" ! 10: ! 11: char * get_data(win, row, col, len, rflag, sflag) ! 12: WINDOW *win; ! 13: int row, col, len, rflag, sflag; ! 14: ! 15: /* rflag is used to tell us if a field MUST be filled in. If set, when the ! 16: * user tries to press return as the first char, it will be rejected. ! 17: * ! 18: * sflag has a couple of meanings. In some entries, no spaces are permitted, ! 19: * but we assume that the user really wants an underscore. sflag is 1 if ! 20: * this is the case. ! 21: * ! 22: * In some cases, a space is represented by a \s. If sflag is 2, we will ! 23: * convert a space to a \s. ! 24: */ ! 25: ! 26: { ! 27: ! 28: int x; ! 29: char a[80]; ! 30: char b; ! 31: ! 32: wmove(win, row, col); /* position our cursor */ ! 33: wrefresh(win); ! 34: ! 35: x = 0; ! 36: while (x < len){ ! 37: b = wgetch(win); ! 38: ! 39: /* convert space to underscore if necessary */ ! 40: if((sflag == 1) && (b == ' ')) ! 41: b = '_'; ! 42: ! 43: if((sflag ==2) && (b == ' ')){ ! 44: mvwaddstr(win,row,col + x,"\\s"); ! 45: a[x] = '\\'; ! 46: a[x+1] = 's'; ! 47: x+=2; ! 48: wrefresh(win); ! 49: continue; ! 50: } ! 51: ! 52: /* test for no data entered in field */ ! 53: if( (rflag && (x == 0)) && ((b == 10) || (b == 13))) ! 54: continue; ! 55: ! 56: /* if return was pressed, terminate loop */ ! 57: if((b == 10) || (b == 13)) ! 58: break; ! 59: ! 60: /* handle backspace */ ! 61: if( (b == 8) && (x > 0)){ ! 62: --x; ! 63: wmove(win,row,col+x); ! 64: wstandout(win); ! 65: waddch(win,' '); ! 66: wmove(win,row,col+x); ! 67: wstandend(win); ! 68: wrefresh(win); ! 69: a[x] = '\0'; ! 70: continue; ! 71: } ! 72: ! 73: wmove(win,row,col + x); ! 74: waddch(win,b); ! 75: a[x] = b; ! 76: ++x; ! 77: wrefresh(win); ! 78: ! 79: } ! 80: a[x] = '\0'; ! 81: wstandout(win); ! 82: mvwaddstr(win,row,col,a); ! 83: wstandend(win); ! 84: wrefresh(win); ! 85: ! 86: return(a); ! 87: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.