1*d01aab43Srin /* $NetBSD: tgets.c,v 1.2 2022/04/29 21:39:51 rin Exp $ */
268fe5b6fSgarbled
368fe5b6fSgarbled /*-
468fe5b6fSgarbled * Copyright (c) 1993
568fe5b6fSgarbled * The Regents of the University of California. All rights reserved.
668fe5b6fSgarbled *
768fe5b6fSgarbled * Redistribution and use in source and binary forms, with or without
868fe5b6fSgarbled * modification, are permitted provided that the following conditions
968fe5b6fSgarbled * are met:
1068fe5b6fSgarbled * 1. Redistributions of source code must retain the above copyright
1168fe5b6fSgarbled * notice, this list of conditions and the following disclaimer.
1268fe5b6fSgarbled * 2. Redistributions in binary form must reproduce the above copyright
1368fe5b6fSgarbled * notice, this list of conditions and the following disclaimer in the
1468fe5b6fSgarbled * documentation and/or other materials provided with the distribution.
1568fe5b6fSgarbled * 3. Neither the name of the University nor the names of its contributors
1668fe5b6fSgarbled * may be used to endorse or promote products derived from this software
1768fe5b6fSgarbled * without specific prior written permission.
1868fe5b6fSgarbled *
1968fe5b6fSgarbled * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2068fe5b6fSgarbled * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2168fe5b6fSgarbled * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2268fe5b6fSgarbled * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2368fe5b6fSgarbled * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2468fe5b6fSgarbled * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2568fe5b6fSgarbled * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2668fe5b6fSgarbled * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2768fe5b6fSgarbled * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2868fe5b6fSgarbled * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2968fe5b6fSgarbled * SUCH DAMAGE.
3068fe5b6fSgarbled *
3168fe5b6fSgarbled * @(#)gets.c 8.1 (Berkeley) 6/11/93
3268fe5b6fSgarbled */
3368fe5b6fSgarbled
3468fe5b6fSgarbled #include <lib/libsa/stand.h>
3568fe5b6fSgarbled #include "boot.h"
3668fe5b6fSgarbled
3768fe5b6fSgarbled int
tgets(char * buf)3868fe5b6fSgarbled tgets(char *buf)
3968fe5b6fSgarbled {
4068fe5b6fSgarbled register int c;
4168fe5b6fSgarbled register char *lp;
4268fe5b6fSgarbled
4368fe5b6fSgarbled #ifdef USE_SCAN
4468fe5b6fSgarbled int i;
4568fe5b6fSgarbled
46*d01aab43Srin #define SCANDELAY 10000
47*d01aab43Srin #define SCANWAIT 500
48*d01aab43Srin for (i = 0; i < SCANWAIT; i++) {
4968fe5b6fSgarbled if ((c = cnscan()) != -1)
5068fe5b6fSgarbled goto next;
51*d01aab43Srin delay(SCANDELAY);
5268fe5b6fSgarbled }
5368fe5b6fSgarbled return (-1);
5468fe5b6fSgarbled next:
5568fe5b6fSgarbled #else
5668fe5b6fSgarbled c = getchar();
5768fe5b6fSgarbled #endif
5868fe5b6fSgarbled for (lp = buf;; c = getchar()) {
5968fe5b6fSgarbled switch (c & 0177) {
6068fe5b6fSgarbled case '\n':
6168fe5b6fSgarbled case '\r':
6268fe5b6fSgarbled *lp = '\0';
6368fe5b6fSgarbled putchar('\n');
6468fe5b6fSgarbled return 0;
6568fe5b6fSgarbled case '\b':
6668fe5b6fSgarbled case '\177':
6768fe5b6fSgarbled if (lp > buf) {
6868fe5b6fSgarbled lp--;
6968fe5b6fSgarbled putchar('\b');
7068fe5b6fSgarbled putchar(' ');
7168fe5b6fSgarbled putchar('\b');
7268fe5b6fSgarbled }
7368fe5b6fSgarbled break;
7468fe5b6fSgarbled case 'r'&037: {
7568fe5b6fSgarbled register char *p;
7668fe5b6fSgarbled
7768fe5b6fSgarbled putchar('\n');
7868fe5b6fSgarbled for (p = buf; p < lp; ++p)
7968fe5b6fSgarbled putchar(*p);
8068fe5b6fSgarbled break;
8168fe5b6fSgarbled }
8268fe5b6fSgarbled case 'u'&037:
8368fe5b6fSgarbled case 'w'&037:
8468fe5b6fSgarbled lp = buf;
8568fe5b6fSgarbled putchar('\n');
8668fe5b6fSgarbled break;
8768fe5b6fSgarbled default:
8868fe5b6fSgarbled *lp++ = c;
8968fe5b6fSgarbled putchar(c);
9068fe5b6fSgarbled }
9168fe5b6fSgarbled }
9268fe5b6fSgarbled }
93