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