tgets.c revision 1.1
11.1Stsutsui/*	$NetBSD: tgets.c,v 1.1 2004/04/10 12:30:26 tsutsui 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.1Stsutsuitgets(buf)
411.1Stsutsui	char *buf;
421.1Stsutsui{
431.1Stsutsui	int c;
441.1Stsutsui	char *lp;
451.1Stsutsui
461.1Stsutsui#ifdef	USE_SCAN
471.1Stsutsui	int i;
481.1Stsutsui
491.1Stsutsui#define	SCANWAIT	10000
501.1Stsutsui#define	PWAIT		500
511.1Stsutsui	for (i = 0; i < PWAIT; i++) {
521.1Stsutsui		if ((c = cnscan()) != -1)
531.1Stsutsui			goto next;
541.1Stsutsui		delay(SCANWAIT / 32); /* XXX */
551.1Stsutsui	}
561.1Stsutsui	return (-1);
571.1Stsutsuinext:
581.1Stsutsui#else
591.1Stsutsui	c = getchar();
601.1Stsutsui#endif
611.1Stsutsui	for (lp = buf;; c = getchar()) {
621.1Stsutsui		switch (c & 0177) {
631.1Stsutsui		case '\n':
641.1Stsutsui		case '\r':
651.1Stsutsui			*lp = '\0';
661.1Stsutsui			putchar('\n');
671.1Stsutsui			return 0;
681.1Stsutsui		case '\b':
691.1Stsutsui		case '\177':
701.1Stsutsui			if (lp > buf) {
711.1Stsutsui				lp--;
721.1Stsutsui				putchar('\b');
731.1Stsutsui				putchar(' ');
741.1Stsutsui				putchar('\b');
751.1Stsutsui			}
761.1Stsutsui			break;
771.1Stsutsui		case 'r' & 037: {
781.1Stsutsui			char *p;
791.1Stsutsui
801.1Stsutsui			putchar('\n');
811.1Stsutsui			for (p = buf; p < lp; ++p)
821.1Stsutsui				putchar(*p);
831.1Stsutsui			break;
841.1Stsutsui		}
851.1Stsutsui		case 'u' & 037:
861.1Stsutsui		case 'w' & 037:
871.1Stsutsui			lp = buf;
881.1Stsutsui			putchar('\n');
891.1Stsutsui			break;
901.1Stsutsui		default:
911.1Stsutsui			*lp++ = c;
921.1Stsutsui			putchar(c);
931.1Stsutsui		}
941.1Stsutsui	}
951.1Stsutsui}
96