xref: /csrg-svn/sys/stand.att/gets.c (revision 63370)
133436Sbostic /*
2*63370Sbostic  * Copyright (c) 1988, 1993
3*63370Sbostic  *	The Regents of the University of California.  All rights reserved.
433436Sbostic  *
544516Sbostic  * %sccs.include.redist.c%
633436Sbostic  *
7*63370Sbostic  *	@(#)gets.c	8.1 (Berkeley) 06/11/93
833436Sbostic  */
933436Sbostic 
gets(buf)1033436Sbostic gets(buf)
1133436Sbostic 	char *buf;
1233436Sbostic {
1333436Sbostic 	register int c;
1433436Sbostic 	register char *lp;
1533436Sbostic 
1633436Sbostic 	for (lp = buf;;)
1733436Sbostic 		switch(c = getchar() & 0177) {
1833436Sbostic 		case '\n':
1933436Sbostic 		case '\r':
2033436Sbostic 			*lp = '\0';
2133436Sbostic 			return;
2233436Sbostic 		case '\b':
2335481Sbostic 		case '\177':
2433436Sbostic 			if (lp > buf) {
2533436Sbostic 				lp--;
2633436Sbostic 				putchar('\b');
2733436Sbostic 				putchar(' ');
2833436Sbostic 				putchar('\b');
2933436Sbostic 			}
3033436Sbostic 			break;
3133436Sbostic 		case '#':
3233436Sbostic 			if (lp > buf)
3333436Sbostic 				--lp;
3433436Sbostic 			break;
3533546Sbostic 		case 'r'&037: {
3633546Sbostic 			register char *p;
3733546Sbostic 
3833546Sbostic 			putchar('\n');
3933546Sbostic 			for (p = buf; p < lp; ++p)
4033546Sbostic 				putchar(*p);
4133546Sbostic 			break;
4233546Sbostic 		}
4333436Sbostic 		case '@':
4433436Sbostic 		case 'u'&037:
4533546Sbostic 		case 'w'&037:
4633436Sbostic 			lp = buf;
4733436Sbostic 			putchar('\n');
4833436Sbostic 			break;
4933436Sbostic 		default:
5033436Sbostic 			*lp++ = c;
5133436Sbostic 		}
5233436Sbostic 	/*NOTREACHED*/
5333436Sbostic }
54