1*6d3ceb1dSskrll /* $NetBSD: tgets.c,v 1.1 2014/02/24 07:23:43 skrll Exp $ */
2*6d3ceb1dSskrll
3*6d3ceb1dSskrll /*-
4*6d3ceb1dSskrll * Copyright (c) 1993
5*6d3ceb1dSskrll * The Regents of the University of California. All rights reserved.
6*6d3ceb1dSskrll *
7*6d3ceb1dSskrll * Redistribution and use in source and binary forms, with or without
8*6d3ceb1dSskrll * modification, are permitted provided that the following conditions
9*6d3ceb1dSskrll * are met:
10*6d3ceb1dSskrll * 1. Redistributions of source code must retain the above copyright
11*6d3ceb1dSskrll * notice, this list of conditions and the following disclaimer.
12*6d3ceb1dSskrll * 2. Redistributions in binary form must reproduce the above copyright
13*6d3ceb1dSskrll * notice, this list of conditions and the following disclaimer in the
14*6d3ceb1dSskrll * documentation and/or other materials provided with the distribution.
15*6d3ceb1dSskrll * 3. Neither the name of the University nor the names of its contributors
16*6d3ceb1dSskrll * may be used to endorse or promote products derived from this software
17*6d3ceb1dSskrll * without specific prior written permission.
18*6d3ceb1dSskrll *
19*6d3ceb1dSskrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*6d3ceb1dSskrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*6d3ceb1dSskrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*6d3ceb1dSskrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*6d3ceb1dSskrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*6d3ceb1dSskrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*6d3ceb1dSskrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*6d3ceb1dSskrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*6d3ceb1dSskrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*6d3ceb1dSskrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*6d3ceb1dSskrll * SUCH DAMAGE.
30*6d3ceb1dSskrll *
31*6d3ceb1dSskrll * @(#)gets.c 8.1 (Berkeley) 6/11/93
32*6d3ceb1dSskrll */
33*6d3ceb1dSskrll
34*6d3ceb1dSskrll #include <sys/types.h>
35*6d3ceb1dSskrll #include <arch/hppa/stand/common/libsa.h>
36*6d3ceb1dSskrll #include <lib/libsa/net.h>
37*6d3ceb1dSskrll
38*6d3ceb1dSskrll int tgets(char *);
39*6d3ceb1dSskrll
40*6d3ceb1dSskrll int
tgets(char * buf)41*6d3ceb1dSskrll tgets(char *buf)
42*6d3ceb1dSskrll {
43*6d3ceb1dSskrll int c, i;
44*6d3ceb1dSskrll char *p, *lp = buf;
45*6d3ceb1dSskrll satime_t seconds1, seconds2;
46*6d3ceb1dSskrll
47*6d3ceb1dSskrll seconds1 = getsecs();
48*6d3ceb1dSskrll for (i = 10; i > 0; ) {
49*6d3ceb1dSskrll c = tgetchar() & 0177;
50*6d3ceb1dSskrll if (c) {
51*6d3ceb1dSskrll for (;;) {
52*6d3ceb1dSskrll switch (c) {
53*6d3ceb1dSskrll case '\n':
54*6d3ceb1dSskrll case '\r':
55*6d3ceb1dSskrll *lp = '\0';
56*6d3ceb1dSskrll putchar('\n');
57*6d3ceb1dSskrll return (1);
58*6d3ceb1dSskrll
59*6d3ceb1dSskrll case '\b':
60*6d3ceb1dSskrll case '\177':
61*6d3ceb1dSskrll if (lp > buf) {
62*6d3ceb1dSskrll lp--;
63*6d3ceb1dSskrll putchar('\b');
64*6d3ceb1dSskrll putchar(' ');
65*6d3ceb1dSskrll putchar('\b');
66*6d3ceb1dSskrll }
67*6d3ceb1dSskrll break;
68*6d3ceb1dSskrll
69*6d3ceb1dSskrll case '#':
70*6d3ceb1dSskrll if (lp > buf)
71*6d3ceb1dSskrll --lp;
72*6d3ceb1dSskrll break;
73*6d3ceb1dSskrll
74*6d3ceb1dSskrll case 'r'&037:
75*6d3ceb1dSskrll putchar('\n');
76*6d3ceb1dSskrll for (p = buf; p < lp; ++p)
77*6d3ceb1dSskrll putchar(*p);
78*6d3ceb1dSskrll break;
79*6d3ceb1dSskrll
80*6d3ceb1dSskrll case '@':
81*6d3ceb1dSskrll case 'u'&037:
82*6d3ceb1dSskrll case 'w'&037:
83*6d3ceb1dSskrll lp = buf;
84*6d3ceb1dSskrll putchar('\n');
85*6d3ceb1dSskrll break;
86*6d3ceb1dSskrll
87*6d3ceb1dSskrll default:
88*6d3ceb1dSskrll *lp++ = c;
89*6d3ceb1dSskrll putchar(c);
90*6d3ceb1dSskrll }
91*6d3ceb1dSskrll c = getchar() & 0177;
92*6d3ceb1dSskrll }
93*6d3ceb1dSskrll }
94*6d3ceb1dSskrll if ((seconds2 = getsecs()) != seconds1) {
95*6d3ceb1dSskrll seconds1 = seconds2;
96*6d3ceb1dSskrll i--;
97*6d3ceb1dSskrll }
98*6d3ceb1dSskrll }
99*6d3ceb1dSskrll return (0);
100*6d3ceb1dSskrll }
101