xref: /titanic_51/usr/src/psm/stand/boot/sparc/common/get.c (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/promif.h>
31 
32 int
33 getchar(void)
34 {
35 	register int c;
36 
37 	while ((c = prom_mayget()) == -1)
38 		;
39 	if (c == '\r') {
40 		prom_putchar(c);
41 		c = '\n';
42 	}
43 	if (c == 0177 || c == '\b') {
44 		prom_putchar('\b');
45 		prom_putchar(' ');
46 		c = '\b';
47 	}
48 	prom_putchar(c);
49 	return (c);
50 }
51 
52 int
53 cons_gets(char *buf, int n)
54 {
55 	char *lp;
56 	char *limit;
57 	int c;
58 
59 	lp = buf;
60 	limit = &buf[n - 1];
61 	for (;;) {
62 		c = getchar() & 0177;
63 		switch (c) {
64 		case '\n':
65 		case '\r':
66 			*lp = '\0';
67 			return (0);
68 		case '\b':
69 			if (lp > buf)
70 				lp--;
71 			continue;
72 		case 'u'&037:			/* ^U */
73 			lp = buf;
74 			prom_putchar('\r');
75 			prom_putchar('\n');
76 			continue;
77 		default:
78 			if (lp < limit)
79 				*lp++ = (char)c;
80 			else
81 				prom_putchar('\a');	/* bell */
82 		}
83 	}
84 }
85