xref: /original-bsd/sys/luna68k/stand/getline.c (revision 36940495)
1 /*
2  * Copyright (c) 1992 OMRON Corporation.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * OMRON Corporation.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)getline.c	8.1 (Berkeley) 06/10/93
12  */
13 
14 /*
15  * getline -- simple getline function
16  * 	by A.Fujita, Dec-11-1992
17  */
18 
19 int
20 getline(prompt, buff)
21 	char *prompt, *buff;
22 {
23 	register int c;
24 	register char *p = buff;
25 
26 	printf("%s", prompt);
27 
28 	for(;;) {
29 		c = cngetc() & 0x7F;
30 
31 		switch (c) {
32 		case 0x0a:
33 		case 0x0d:
34 			cnputc('\r');
35 			cnputc('\n');
36 			*p = '\0';
37 			goto outloop;
38 
39 		case 0x08:
40 		case 0x7f:
41 			if (p > buff) {
42 				cnputc(0x08);
43 				cnputc(' ');
44 				cnputc(0x08);
45 				p--;
46 			}
47 			break;
48 
49 		default:
50 			*p++ = c;
51 			cnputc(c);
52 			break;
53 		}
54 	}
55 
56  outloop:
57 	return(strlen(buff));
58 }
59