111491Sralph /*
2*18783Sdist * Copyright (c) 1980 Regents of the University of California.
3*18783Sdist * All rights reserved. The Berkeley software License Agreement
4*18783Sdist * specifies the terms and conditions for redistribution.
5*18783Sdist */
6*18783Sdist
7*18783Sdist #ifndef lint
8*18783Sdist static char sccsid[] = "@(#)readline.c 5.1 (Berkeley) 04/26/85";
9*18783Sdist #endif not lint
10*18783Sdist
11*18783Sdist /*
1211491Sralph * Read a line from the keyboard in the message line. The line
1311491Sralph * goes into caller provided buffer msg, whos size is maxlen bytes.
1411491Sralph */
1511491Sralph
1611491Sralph #include "2648.h"
1711491Sralph
readline(prompt,msg,maxlen)1811491Sralph readline(prompt, msg, maxlen)
1911491Sralph char *prompt;
2011491Sralph char *msg;
2111491Sralph int maxlen;
2211491Sralph {
2311491Sralph register char c;
2411491Sralph register char *cp;
2511491Sralph int oldx, oldy;
2611491Sralph int oldcuron;
2711491Sralph int oldquiet;
2811491Sralph extern int QUIET;
2911491Sralph
3011491Sralph oldx = _curx; oldy = _cury;
3111491Sralph oldcuron = _cursoron;
3211491Sralph areaclear(4, 4, 4+8, 719);
3311491Sralph setset();
3411491Sralph zoomout();
3511491Sralph curon();
3611491Sralph movecurs(4, 4);
3711491Sralph texton();
3811491Sralph
3911491Sralph oldquiet = QUIET;
4011491Sralph QUIET = 0;
4111491Sralph outstr(prompt);
4211491Sralph if (oldquiet)
4311491Sralph outstr("\r\n");
4411491Sralph QUIET = oldquiet;
4511491Sralph
4611491Sralph for (cp=msg; ; cp) {
4711491Sralph fflush(stdout);
4811491Sralph c = getchar();
4911491Sralph switch (c) {
5011491Sralph case '\n':
5111491Sralph case '\r':
5211491Sralph case ESC:
5311491Sralph *cp++ = 0;
5411491Sralph textoff();
5511491Sralph movecurs(oldx, oldy);
5611491Sralph if (oldcuron == 0)
5711491Sralph curoff();
5811491Sralph return;
5911491Sralph case '\b':
6011491Sralph if (--cp >= msg)
6111491Sralph outchar(c);
6211491Sralph else
6311491Sralph cp = msg;
6411491Sralph break;
6511491Sralph default:
6611491Sralph *cp++ = c;
6711491Sralph outstr(rdchar(c));
6811491Sralph if (cp-msg >= maxlen)
6911491Sralph error("line too long");
7011491Sralph }
7111491Sralph }
7211491Sralph }
73