|
|
1.1 root 1: /*********************************************************************
2: * COPYRIGHT NOTICE *
3: **********************************************************************
4: * This software is copyright (C) 1982 by Pavel Curtis *
5: * *
6: * Permission is granted to reproduce and distribute *
7: * this file by any means so long as no fee is charged *
8: * above a nominal handling fee and so long as this *
9: * notice is always included in the copies. *
10: * *
11: * Other rights are reserved except as explicitly granted *
12: * by written permission of the author. *
13: * Pavel Curtis *
14: * Computer Science Dept. *
15: * 405 Upson Hall *
16: * Cornell University *
17: * Ithaca, NY 14853 *
18: * *
19: * Ph- (607) 256-4934 *
20: * *
21: * Pavel.Cornell@Udel-Relay (ARPAnet) *
22: * decvax!cornell!pavel (UUCPnet) *
23: *********************************************************************/
24:
25: /*
26: ** lib_getstr.c
27: **
28: ** The routine wgetstr().
29: **
30: ** $Log: lib_getstr.c,v $
31: * Revision 1.8 93/04/12 14:13:42 bin
32: * Udo: third color update
33: *
34: * Revision 1.2 92/04/13 14:37:34 bin
35: * update by vlad
36: *
37: * Revision 2.2 91/04/20 19:07:12 munk
38: * Usage of register variables
39: *
40: * Revision 2.1 82/10/25 14:47:33 pavel
41: * Added Copyright Notice
42: *
43: * Revision 2.0 82/10/25 13:45:39 pavel
44: * Beta-one Test Release
45: *
46: **
47: */
48:
49: #ifdef RCSHDR
50: static char RCSid[] =
51: "$Header: /src386/usr/lib/ncurses/RCS/lib_getstr.c,v 1.8 93/04/12 14:13:42 bin Exp Locker: bin $";
52: #endif
53:
54: #include "curses.h"
55: #include "curses.priv.h"
56: #include "unctrl.h"
57:
58: #define backspace() { \
59: mvwaddstr(curscr, win->_begy + win->_cury, \
60: win->_begx + win->_curx, "\b \b");\
61: waddstr(win, "\b \b"); \
62: fputs("\b \b", SP->_ofp); \
63: fflush(SP->_ofp); \
64: }
65:
66:
67: wgetstr(win,str)
68: register WINDOW *win;
69: register char *str;
70: {
71: char erasechar(), killchar();
72: bool oldnl, oldecho, oldraw, oldcbreak;
73: char erasec;
74: char killc;
75: char *oldstr;
76:
77: #ifdef TRACE
78: if (_tracing)
79: _tracef("wgetstr(%o,%o) called", win, str);
80: #endif
81:
82: oldnl = SP->_nl;
83: oldecho = SP->_echo;
84: oldraw = SP->_raw;
85: oldcbreak = SP->_cbreak;
86: nl();
87: noecho();
88: noraw();
89: cbreak();
90:
91: erasec = erasechar();
92: killc = killchar();
93:
94: oldstr = str;
95:
96: while ((*str = getc(SP->_ifp)) != ERR && *str != '\n')
97: {
98: if (*str == erasec)
99: {
100: if (str > oldstr)
101: {
102: str--;
103: backspace();
104: if (*str < ' ' || *str == '\177')
105: backspace();
106: }
107: }
108: else if (*str == killc)
109: {
110: while (str > oldstr)
111: {
112: str--;
113: backspace();
114: if (*str < ' ' || *str == '\177')
115: backspace();
116: }
117: }
118: else
119: {
120: mvwaddstr(curscr, win->_begy + win->_cury,
121: win->_begx + win->_curx, unctrl(*str));
122: waddstr(win, unctrl(*str));
123: fputs(unctrl(*str), SP->_ofp);
124: fflush(SP->_ofp);
125: str++;
126: }
127: }
128:
129: if (! oldnl)
130: nonl();
131:
132: if (oldecho)
133: echo();
134:
135: if (oldraw)
136: raw();
137:
138: if (! oldcbreak)
139: nocbreak();
140:
141: if (*str == ERR)
142: {
143: *str = '\0';
144: return(ERR);
145: }
146:
147: *str = '\0';
148:
149: #ifdef TRACE
150: if (_tracing)
151: _tracef("\twgetstr returns %s", oldstr);
152: #endif
153:
154: return(OK);
155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.