1*d01aab43Srin /* $NetBSD: tgets.c,v 1.5 2022/04/29 21:39:50 rin Exp $ */
269e73705Stsutsui
369e73705Stsutsui /*-
469e73705Stsutsui * Copyright (c) 1993
569e73705Stsutsui * The Regents of the University of California. All rights reserved.
669e73705Stsutsui *
769e73705Stsutsui * Redistribution and use in source and binary forms, with or without
869e73705Stsutsui * modification, are permitted provided that the following conditions
969e73705Stsutsui * are met:
1069e73705Stsutsui * 1. Redistributions of source code must retain the above copyright
1169e73705Stsutsui * notice, this list of conditions and the following disclaimer.
1269e73705Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
1369e73705Stsutsui * notice, this list of conditions and the following disclaimer in the
1469e73705Stsutsui * documentation and/or other materials provided with the distribution.
1569e73705Stsutsui * 3. Neither the name of the University nor the names of its contributors
1669e73705Stsutsui * may be used to endorse or promote products derived from this software
1769e73705Stsutsui * without specific prior written permission.
1869e73705Stsutsui *
1969e73705Stsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2069e73705Stsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2169e73705Stsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2269e73705Stsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2369e73705Stsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2469e73705Stsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2569e73705Stsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2669e73705Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2769e73705Stsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2869e73705Stsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2969e73705Stsutsui * SUCH DAMAGE.
3069e73705Stsutsui *
3169e73705Stsutsui * @(#)gets.c 8.1 (Berkeley) 6/11/93
3269e73705Stsutsui */
3369e73705Stsutsui
3469e73705Stsutsui #include <lib/libsa/stand.h>
3569e73705Stsutsui #include "boot.h"
3669e73705Stsutsui
3769e73705Stsutsui #define USE_SCAN
3869e73705Stsutsui
3969e73705Stsutsui int
tgets(char * buf)4051b5e07bStsutsui tgets(char *buf)
4169e73705Stsutsui {
4269e73705Stsutsui int c;
4369e73705Stsutsui char *lp;
4469e73705Stsutsui
4569e73705Stsutsui #ifdef USE_SCAN
4669e73705Stsutsui int i;
4769e73705Stsutsui
48*d01aab43Srin #define SCANDELAY 10000
49*d01aab43Srin #define SCANWAIT 500
50*d01aab43Srin for (i = 0; i < SCANWAIT; i++) {
5169e73705Stsutsui if ((c = cnscan()) != -1)
5269e73705Stsutsui goto next;
53*d01aab43Srin delay(SCANDELAY / 32); /* XXX */
5469e73705Stsutsui }
5551b5e07bStsutsui return -1;
5669e73705Stsutsui next:
5769e73705Stsutsui #else
5869e73705Stsutsui c = getchar();
5969e73705Stsutsui #endif
6069e73705Stsutsui for (lp = buf;; c = getchar()) {
6169e73705Stsutsui switch (c & 0177) {
6269e73705Stsutsui case '\n':
6369e73705Stsutsui case '\r':
6469e73705Stsutsui *lp = '\0';
6569e73705Stsutsui putchar('\n');
6669e73705Stsutsui return 0;
6769e73705Stsutsui case '\b':
6869e73705Stsutsui case '\177':
6969e73705Stsutsui if (lp > buf) {
7069e73705Stsutsui lp--;
7169e73705Stsutsui putchar('\b');
7269e73705Stsutsui putchar(' ');
7369e73705Stsutsui putchar('\b');
7469e73705Stsutsui }
7569e73705Stsutsui break;
7669e73705Stsutsui case 'r' & 037: {
7769e73705Stsutsui char *p;
7869e73705Stsutsui
7969e73705Stsutsui putchar('\n');
8069e73705Stsutsui for (p = buf; p < lp; ++p)
8169e73705Stsutsui putchar(*p);
8269e73705Stsutsui break;
8369e73705Stsutsui }
8469e73705Stsutsui case 'u' & 037:
8569e73705Stsutsui case 'w' & 037:
8669e73705Stsutsui lp = buf;
8769e73705Stsutsui putchar('\n');
8869e73705Stsutsui break;
8969e73705Stsutsui default:
9069e73705Stsutsui *lp++ = c;
9169e73705Stsutsui putchar(c);
9269e73705Stsutsui }
9369e73705Stsutsui }
9469e73705Stsutsui }
95