11.5Srin/*	$NetBSD: tgets.c,v 1.5 2022/04/29 21:39:50 rin Exp $	*/
21.1Stsutsui
31.1Stsutsui/*-
41.1Stsutsui * Copyright (c) 1993
51.1Stsutsui *	The Regents of the University of California.  All rights reserved.
61.1Stsutsui *
71.1Stsutsui * Redistribution and use in source and binary forms, with or without
81.1Stsutsui * modification, are permitted provided that the following conditions
91.1Stsutsui * are met:
101.1Stsutsui * 1. Redistributions of source code must retain the above copyright
111.1Stsutsui *    notice, this list of conditions and the following disclaimer.
121.1Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
131.1Stsutsui *    notice, this list of conditions and the following disclaimer in the
141.1Stsutsui *    documentation and/or other materials provided with the distribution.
151.1Stsutsui * 3. Neither the name of the University nor the names of its contributors
161.1Stsutsui *    may be used to endorse or promote products derived from this software
171.1Stsutsui *    without specific prior written permission.
181.1Stsutsui *
191.1Stsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Stsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Stsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Stsutsui * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Stsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Stsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Stsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Stsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Stsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Stsutsui * SUCH DAMAGE.
301.1Stsutsui *
311.1Stsutsui *	@(#)gets.c	8.1 (Berkeley) 6/11/93
321.1Stsutsui */
331.1Stsutsui
341.1Stsutsui#include <lib/libsa/stand.h>
351.1Stsutsui#include "boot.h"
361.1Stsutsui
371.1Stsutsui#define USE_SCAN
381.1Stsutsui
391.1Stsutsuiint
401.3Stsutsuitgets(char *buf)
411.1Stsutsui{
421.1Stsutsui	int c;
431.1Stsutsui	char *lp;
441.1Stsutsui
451.1Stsutsui#ifdef	USE_SCAN
461.1Stsutsui	int i;
471.1Stsutsui
481.5Srin#define	SCANDELAY	10000
491.5Srin#define	SCANWAIT	500
501.5Srin	for (i = 0; i < SCANWAIT; i++) {
511.1Stsutsui		if ((c = cnscan()) != -1)
521.1Stsutsui			goto next;
531.5Srin		delay(SCANDELAY / 32); /* XXX */
541.1Stsutsui	}
551.3Stsutsui	return -1;
561.1Stsutsuinext:
571.1Stsutsui#else
581.1Stsutsui	c = getchar();
591.1Stsutsui#endif
601.1Stsutsui	for (lp = buf;; c = getchar()) {
611.1Stsutsui		switch (c & 0177) {
621.1Stsutsui		case '\n':
631.1Stsutsui		case '\r':
641.1Stsutsui			*lp = '\0';
651.1Stsutsui			putchar('\n');
661.1Stsutsui			return 0;
671.1Stsutsui		case '\b':
681.1Stsutsui		case '\177':
691.1Stsutsui			if (lp > buf) {
701.1Stsutsui				lp--;
711.1Stsutsui				putchar('\b');
721.1Stsutsui				putchar(' ');
731.1Stsutsui				putchar('\b');
741.1Stsutsui			}
751.1Stsutsui			break;
761.1Stsutsui		case 'r' & 037: {
771.1Stsutsui			char *p;
781.1Stsutsui
791.1Stsutsui			putchar('\n');
801.1Stsutsui			for (p = buf; p < lp; ++p)
811.1Stsutsui				putchar(*p);
821.1Stsutsui			break;
831.1Stsutsui		}
841.1Stsutsui		case 'u' & 037:
851.1Stsutsui		case 'w' & 037:
861.1Stsutsui			lp = buf;
871.1Stsutsui			putchar('\n');
881.1Stsutsui			break;
891.1Stsutsui		default:
901.1Stsutsui			*lp++ = c;
911.1Stsutsui			putchar(c);
921.1Stsutsui		}
931.1Stsutsui	}
941.1Stsutsui}
95