1*825dcd8dSjasper /* $OpenBSD: getchar.c,v 1.1 2014/07/12 21:54:58 jasper Exp $ */
2*825dcd8dSjasper
3*825dcd8dSjasper /*
4*825dcd8dSjasper * Copyright (c) 1982, 1986, 1990, 1993
5*825dcd8dSjasper * The Regents of the University of California. All rights reserved.
6*825dcd8dSjasper *
7*825dcd8dSjasper * Redistribution and use in source and binary forms, with or without
8*825dcd8dSjasper * modification, are permitted provided that the following conditions
9*825dcd8dSjasper * are met:
10*825dcd8dSjasper * 1. Redistributions of source code must retain the above copyright
11*825dcd8dSjasper * notice, this list of conditions and the following disclaimer.
12*825dcd8dSjasper * 2. Redistributions in binary form must reproduce the above copyright
13*825dcd8dSjasper * notice, this list of conditions and the following disclaimer in the
14*825dcd8dSjasper * documentation and/or other materials provided with the distribution.
15*825dcd8dSjasper * 3. All advertising materials mentioning features or use of this software
16*825dcd8dSjasper * must display the following acknowledgement:
17*825dcd8dSjasper * This product includes software developed by the University of
18*825dcd8dSjasper * California, Berkeley and its contributors.
19*825dcd8dSjasper * 4. Neither the name of the University nor the names of its contributors
20*825dcd8dSjasper * may be used to endorse or promote products derived from this software
21*825dcd8dSjasper * without specific prior written permission.
22*825dcd8dSjasper *
23*825dcd8dSjasper * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24*825dcd8dSjasper * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*825dcd8dSjasper * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26*825dcd8dSjasper * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27*825dcd8dSjasper * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28*825dcd8dSjasper * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29*825dcd8dSjasper * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30*825dcd8dSjasper * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31*825dcd8dSjasper * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32*825dcd8dSjasper * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*825dcd8dSjasper * SUCH DAMAGE.
34*825dcd8dSjasper *
35*825dcd8dSjasper */
36*825dcd8dSjasper
37*825dcd8dSjasper #include "stand.h"
38*825dcd8dSjasper
39*825dcd8dSjasper int
getchar(void)40*825dcd8dSjasper getchar(void)
41*825dcd8dSjasper {
42*825dcd8dSjasper int c = cngetc();
43*825dcd8dSjasper
44*825dcd8dSjasper if (c == '\r')
45*825dcd8dSjasper c = '\n';
46*825dcd8dSjasper
47*825dcd8dSjasper if ((c < ' ' && c != '\n') || c == '\177')
48*825dcd8dSjasper return c;
49*825dcd8dSjasper
50*825dcd8dSjasper putchar(c);
51*825dcd8dSjasper
52*825dcd8dSjasper return c;
53*825dcd8dSjasper }
54