/*
 * 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1986,1988
 * LICENSED MATERIALS - PROPERTY OF IBM
 * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
 */
/* $Header:gets.c 12.0$ */
/* $ACIS:gets.c 12.0$ */
/* $Source: /ibm/acis/usr/sys/standca/RCS/gets.c,v $ */

#ifndef lint
static char *rcsid = "$Header:gets.c 12.0$";
#endif

char *gets(buf)
	char *buf;
{
	register char *lp;
	register c;

	lp = buf;
	for (;;) {
		c = getchar() & 0177;
store:
		switch (c) {
		case '\n':
		case '\r':
			c = '\n';      /* treat both as newline */
			*lp++ = '\0';
			return(buf);
		case '\b':
			putchar(' ');
			putchar('\b');
		case '#':
			lp--;
			if (lp < buf)
				lp = buf;
			continue;
		case '@':
		case 'u' & 037:
			lp = buf;
			putchar('\n');
			continue;
		case '\04':		/* ^D - return nul byte */
			return((char *) 0);
		case '\03':		/* ^C - exit */
			exit(1);
			continue;	/* paranoia */
		case 'o' & 037:		/* ^O - [no]suppress output */
			{
				extern int _noputchar;
				_noputchar = ! _noputchar;
				continue;
			}
		case 'w' & 037:		/* ^W - wait for a second */
			delay(1000);
			continue;
		default:
			*lp++ = c;
		}
	}
}
