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