xref: /csrg-svn/sys/stand/gets.c (revision 63370)
163274Smckusick /*-
2*63370Sbostic  * Copyright (c) 1993
3*63370Sbostic  *	The Regents of the University of California.  All rights reserved.
463274Smckusick  *
563274Smckusick  * %sccs.include.redist.c%
663274Smckusick  *
7*63370Sbostic  *	@(#)gets.c	8.1 (Berkeley) 06/11/93
863274Smckusick  */
963274Smckusick 
gets(buf)1063274Smckusick gets(buf)
1163274Smckusick 	char *buf;
1263274Smckusick {
1363274Smckusick 	register int c;
1463274Smckusick 	register char *lp;
1563274Smckusick 
1663274Smckusick 	for (lp = buf;;)
1763274Smckusick 		switch (c = getchar() & 0177) {
1863274Smckusick 		case '\n':
1963274Smckusick 		case '\r':
2063274Smckusick 			*lp = '\0';
2163274Smckusick 			return;
2263274Smckusick 		case '\b':
2363274Smckusick 		case '\177':
2463274Smckusick 			if (lp > buf) {
2563274Smckusick 				lp--;
2663274Smckusick 				putchar('\b');
2763274Smckusick 				putchar(' ');
2863274Smckusick 				putchar('\b');
2963274Smckusick 			}
3063274Smckusick 			break;
3163274Smckusick 		case '#':
3263274Smckusick 			if (lp > buf)
3363274Smckusick 				--lp;
3463274Smckusick 			break;
3563274Smckusick 		case 'r'&037: {
3663274Smckusick 			register char *p;
3763274Smckusick 
3863274Smckusick 			putchar('\n');
3963274Smckusick 			for (p = buf; p < lp; ++p)
4063274Smckusick 				putchar(*p);
4163274Smckusick 			break;
4263274Smckusick 		}
4363274Smckusick 		case '@':
4463274Smckusick 		case 'u'&037:
4563274Smckusick 		case 'w'&037:
4663274Smckusick 			lp = buf;
4763274Smckusick 			putchar('\n');
4863274Smckusick 			break;
4963274Smckusick 		default:
5063274Smckusick 			*lp++ = c;
5163274Smckusick 		}
5263274Smckusick 	/*NOTREACHED*/
5363274Smckusick }
54