xref: /csrg-svn/sys/stand.att/gets.c (revision 33436)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  *	@(#)gets.c	7.1 (Berkeley) 02/05/88
13  */
14 
15 gets(buf)
16 	char *buf;
17 {
18 	register int c;
19 	register char *lp;
20 
21 	for (lp = buf;;)
22 		switch(c = getchar() & 0177) {
23 		case '\n':
24 		case '\r':
25 			*lp = '\0';
26 			return;
27 		case '\b':
28 			if (lp > buf) {
29 				lp--;
30 				putchar('\b');
31 				putchar(' ');
32 				putchar('\b');
33 			}
34 			break;
35 		case '#':
36 		case '\177':
37 			if (lp > buf)
38 				--lp;
39 			break;
40 		case '@':
41 		case 'u'&037:
42 			lp = buf;
43 			putchar('\n');
44 			break;
45 		default:
46 			*lp++ = c;
47 		}
48 	/*NOTREACHED*/
49 }
50