don't call setbuf, use optimal size.
[unix-history] / usr / src / old / lib2648 / readline.c
CommitLineData
b61b76c5
RC
1/* readline.c 4.1 83/03/09 */
2/*
3 * Read a line from the keyboard in the message line. The line
4 * goes into caller provided buffer msg, whos size is maxlen bytes.
5 */
6
7#include "2648.h"
8
9readline(prompt, msg, maxlen)
10char *prompt;
11char *msg;
12int maxlen;
13{
14 register char c;
15 register char *cp;
16 int oldx, oldy;
17 int oldcuron;
18 int oldquiet;
19 extern int QUIET;
20
21 oldx = _curx; oldy = _cury;
22 oldcuron = _cursoron;
23 areaclear(4, 4, 4+8, 719);
24 setset();
25 zoomout();
26 curon();
27 movecurs(4, 4);
28 texton();
29
30 oldquiet = QUIET;
31 QUIET = 0;
32 outstr(prompt);
33 if (oldquiet)
34 outstr("\r\n");
35 QUIET = oldquiet;
36
37 for (cp=msg; ; cp) {
38 fflush(stdout);
39 c = getchar();
40 switch (c) {
41 case '\n':
42 case '\r':
43 case ESC:
44 *cp++ = 0;
45 textoff();
46 movecurs(oldx, oldy);
47 if (oldcuron == 0)
48 curoff();
49 return;
50 case '\b':
51 if (--cp >= msg)
52 outchar(c);
53 else
54 cp = msg;
55 break;
56 default:
57 *cp++ = c;
58 outstr(rdchar(c));
59 if (cp-msg >= maxlen)
60 error("line too long");
61 }
62 }
63}