1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Edward Wang at The University of California, Berkeley. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)wwgets.c 3.15 (Berkeley) 06/06/90"; 13 #endif /* not lint */ 14 15 #include "ww.h" 16 #include "char.h" 17 18 wwgets(buf, n, w) 19 char *buf; 20 int n; 21 register struct ww *w; 22 { 23 register char *p = buf; 24 register char c; 25 char uc = w->ww_unctrl; 26 27 w->ww_unctrl = 0; 28 for (;;) { 29 wwcurtowin(w); 30 while ((c = wwgetc()) < 0) 31 wwiomux(); 32 #ifndef POSIX_TTY 33 if (c == wwoldtty.ww_sgttyb.sg_erase) 34 #else 35 if (c == wwoldtty.ww_termios.c_cc[VERASE]) 36 #endif 37 { 38 if (p > buf) 39 rub(*--p, w); 40 } else 41 #ifndef POSIX_TTY 42 if (c == wwoldtty.ww_sgttyb.sg_kill) 43 #else 44 if (c == wwoldtty.ww_termios.c_cc[VKILL]) 45 #endif 46 { 47 while (p > buf) 48 rub(*--p, w); 49 } else 50 #ifndef POSIX_TTY 51 if (c == wwoldtty.ww_ltchars.t_werasc) 52 #else 53 if (c == wwoldtty.ww_termios.c_cc[VWERASE]) 54 #endif 55 { 56 while (--p >= buf && (*p == ' ' || *p == '\t')) 57 rub(*p, w); 58 while (p >= buf && *p != ' ' && *p != '\t') 59 rub(*p--, w); 60 p++; 61 } else if (c == '\r' || c == '\n') { 62 break; 63 } else { 64 if (p >= buf + n - 1) 65 wwputc(ctrl('g'), w); 66 else 67 wwputs(unctrl(*p++ = c), w); 68 } 69 } 70 *p = 0; 71 w->ww_unctrl = uc; 72 } 73 74 static 75 rub(c, w) 76 struct ww *w; 77 { 78 register i; 79 80 for (i = strlen(unctrl(c)); --i >= 0;) 81 (void) wwwrite(w, "\b \b", 3); 82 } 83