|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)readline.c 5.1 (Berkeley) 4/26/85"; ! 9: #endif not lint ! 10: ! 11: /* ! 12: * Read a line from the keyboard in the message line. The line ! 13: * goes into caller provided buffer msg, whos size is maxlen bytes. ! 14: */ ! 15: ! 16: #include "2648.h" ! 17: ! 18: readline(prompt, msg, maxlen) ! 19: char *prompt; ! 20: char *msg; ! 21: int maxlen; ! 22: { ! 23: register char c; ! 24: register char *cp; ! 25: int oldx, oldy; ! 26: int oldcuron; ! 27: int oldquiet; ! 28: extern int QUIET; ! 29: ! 30: oldx = _curx; oldy = _cury; ! 31: oldcuron = _cursoron; ! 32: areaclear(4, 4, 4+8, 719); ! 33: setset(); ! 34: zoomout(); ! 35: curon(); ! 36: movecurs(4, 4); ! 37: texton(); ! 38: ! 39: oldquiet = QUIET; ! 40: QUIET = 0; ! 41: outstr(prompt); ! 42: if (oldquiet) ! 43: outstr("\r\n"); ! 44: QUIET = oldquiet; ! 45: ! 46: for (cp=msg; ; cp) { ! 47: fflush(stdout); ! 48: c = getchar(); ! 49: switch (c) { ! 50: case '\n': ! 51: case '\r': ! 52: case ESC: ! 53: *cp++ = 0; ! 54: textoff(); ! 55: movecurs(oldx, oldy); ! 56: if (oldcuron == 0) ! 57: curoff(); ! 58: return; ! 59: case '\b': ! 60: if (--cp >= msg) ! 61: outchar(c); ! 62: else ! 63: cp = msg; ! 64: break; ! 65: default: ! 66: *cp++ = c; ! 67: outstr(rdchar(c)); ! 68: if (cp-msg >= maxlen) ! 69: error("line too long"); ! 70: } ! 71: } ! 72: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.