xref: /csrg-svn/sys/stand.att/gets.c (revision 35481)
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 the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)gets.c	7.4 (Berkeley) 09/12/88
18  */
19 
20 gets(buf)
21 	char *buf;
22 {
23 	register int c;
24 	register char *lp;
25 
26 	for (lp = buf;;)
27 		switch(c = getchar() & 0177) {
28 		case '\n':
29 		case '\r':
30 			*lp = '\0';
31 			return;
32 		case '\b':
33 		case '\177':
34 			if (lp > buf) {
35 				lp--;
36 				putchar('\b');
37 				putchar(' ');
38 				putchar('\b');
39 			}
40 			break;
41 		case '#':
42 			if (lp > buf)
43 				--lp;
44 			break;
45 		case 'r'&037: {
46 			register char *p;
47 
48 			putchar('\n');
49 			for (p = buf; p < lp; ++p)
50 				putchar(*p);
51 			break;
52 		}
53 		case '@':
54 		case 'u'&037:
55 		case 'w'&037:
56 			lp = buf;
57 			putchar('\n');
58 			break;
59 		default:
60 			*lp++ = c;
61 		}
62 	/*NOTREACHED*/
63 }
64