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