xref: /csrg-svn/games/cribbage/io.c (revision 60777)
159264Sbostic /*-
2*60777Sbostic  * Copyright (c) 1980, 1993
3*60777Sbostic  *	The Regents of the University of California.  All rights reserved.
433707Sbostic  *
542576Sbostic  * %sccs.include.redist.c%
621505Smckusick  */
712572Sarnold 
821505Smckusick #ifndef lint
9*60777Sbostic static char sccsid[] = "@(#)io.c	8.1 (Berkeley) 05/31/93";
1033707Sbostic #endif /* not lint */
1121505Smckusick 
1259264Sbostic #include <ctype.h>
1359264Sbostic #include <curses.h>
1459264Sbostic #include <signal.h>
1559264Sbostic #include <stdlib.h>
1659264Sbostic #include <string.h>
1759264Sbostic #include <termios.h>
1859264Sbostic #include <unistd.h>
197709Sarnold 
2059264Sbostic #if __STDC__
2159264Sbostic #include <stdarg.h>
2259264Sbostic #else
2359264Sbostic #include <varargs.h>
2459264Sbostic #endif
257709Sarnold 
2659264Sbostic #include "deck.h"
2759264Sbostic #include "cribbage.h"
2859264Sbostic #include "cribcur.h"
297709Sarnold 
3059264Sbostic #define	LINESIZE		128
317872Sarnold 
3259264Sbostic #ifdef CTRL
3359264Sbostic #undef CTRL
3459264Sbostic #endif
3559264Sbostic #define	CTRL(X)			(X - 'A' + 1)
367709Sarnold 
3759264Sbostic char    linebuf[LINESIZE];
387709Sarnold 
3959264Sbostic char   *rankname[RANKS] = {
4059264Sbostic 	"ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
4159264Sbostic 	"EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"
4259264Sbostic };
437709Sarnold 
4459264Sbostic char   *rankchar[RANKS] = {
4559264Sbostic 	"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"
4659264Sbostic };
477709Sarnold 
4859264Sbostic char   *suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"};
497709Sarnold 
5059264Sbostic char   *suitchar[SUITS] = {"S", "H", "D", "C"};
517709Sarnold 
527709Sarnold /*
537872Sarnold  * msgcard:
547872Sarnold  *	Call msgcrd in one of two forms
557709Sarnold  */
5659264Sbostic int
msgcard(c,brief)577872Sarnold msgcard(c, brief)
5859264Sbostic 	CARD c;
5959264Sbostic 	BOOLEAN brief;
607709Sarnold {
617872Sarnold 	if (brief)
6259264Sbostic 		return (msgcrd(c, TRUE, NULL, TRUE));
637872Sarnold 	else
6459264Sbostic 		return (msgcrd(c, FALSE, " of ", FALSE));
657709Sarnold }
667709Sarnold 
677709Sarnold /*
687872Sarnold  * msgcrd:
697872Sarnold  *	Print the value of a card in ascii
707709Sarnold  */
7159264Sbostic int
msgcrd(c,brfrank,mid,brfsuit)727872Sarnold msgcrd(c, brfrank, mid, brfsuit)
7359264Sbostic 	CARD c;
7459264Sbostic 	BOOLEAN brfrank, brfsuit;
7559264Sbostic 	char *mid;
767872Sarnold {
777872Sarnold 	if (c.rank == EMPTY || c.suit == EMPTY)
7859264Sbostic 		return (FALSE);
797872Sarnold 	if (brfrank)
8059264Sbostic 		addmsg("%1.1s", rankchar[c.rank]);
817872Sarnold 	else
8259264Sbostic 		addmsg(rankname[c.rank]);
837872Sarnold 	if (mid != NULL)
8459264Sbostic 		addmsg(mid);
857872Sarnold 	if (brfsuit)
8659264Sbostic 		addmsg("%1.1s", suitchar[c.suit]);
877872Sarnold 	else
8859264Sbostic 		addmsg(suitname[c.suit]);
8959264Sbostic 	return (TRUE);
907872Sarnold }
917709Sarnold 
927872Sarnold /*
937872Sarnold  * printcard:
947872Sarnold  *	Print out a card.
957872Sarnold  */
9659264Sbostic void
printcard(win,cardno,c,blank)978073Sarnold printcard(win, cardno, c, blank)
9859264Sbostic 	WINDOW *win;
9959264Sbostic 	int     cardno;
10059264Sbostic 	CARD    c;
10159264Sbostic 	BOOLEAN blank;
1027872Sarnold {
1038073Sarnold 	prcard(win, cardno * 2, cardno, c, blank);
1047872Sarnold }
1057709Sarnold 
1067872Sarnold /*
1077872Sarnold  * prcard:
1087872Sarnold  *	Print out a card on the window at the specified location
1097872Sarnold  */
11059264Sbostic void
prcard(win,y,x,c,blank)1117946Sarnold prcard(win, y, x, c, blank)
11259264Sbostic 	WINDOW *win;
11359264Sbostic 	int y, x;
11459264Sbostic 	CARD c;
11559264Sbostic 	BOOLEAN blank;
1167709Sarnold {
1177872Sarnold 	if (c.rank == EMPTY)
11859264Sbostic 		return;
11959264Sbostic 
1207872Sarnold 	mvwaddstr(win, y + 0, x, "+-----+");
1217872Sarnold 	mvwaddstr(win, y + 1, x, "|     |");
1227872Sarnold 	mvwaddstr(win, y + 2, x, "|     |");
1237872Sarnold 	mvwaddstr(win, y + 3, x, "|     |");
1247872Sarnold 	mvwaddstr(win, y + 4, x, "+-----+");
1257946Sarnold 	if (!blank) {
1267946Sarnold 		mvwaddch(win, y + 1, x + 1, rankchar[c.rank][0]);
1277946Sarnold 		waddch(win, suitchar[c.suit][0]);
1287946Sarnold 		mvwaddch(win, y + 3, x + 4, rankchar[c.rank][0]);
1297946Sarnold 		waddch(win, suitchar[c.suit][0]);
1307946Sarnold 	}
1317709Sarnold }
1327709Sarnold 
1337709Sarnold /*
1347872Sarnold  * prhand:
1357872Sarnold  *	Print a hand of n cards
1367709Sarnold  */
13759264Sbostic void
prhand(h,n,win,blank)1388073Sarnold prhand(h, n, win, blank)
13959264Sbostic 	CARD h[];
14059264Sbostic 	int n;
14159264Sbostic 	WINDOW *win;
14259264Sbostic 	BOOLEAN blank;
1437709Sarnold {
14459264Sbostic 	register int i;
1457709Sarnold 
1467872Sarnold 	werase(win);
1477872Sarnold 	for (i = 0; i < n; i++)
14859264Sbostic 		printcard(win, i, *h++, blank);
1497872Sarnold 	wrefresh(win);
1507709Sarnold }
1517709Sarnold 
1527709Sarnold /*
1537872Sarnold  * infrom:
1547872Sarnold  *	reads a card, supposedly in hand, accepting unambigous brief
1557872Sarnold  *	input, returns the index of the card found...
1567709Sarnold  */
15759264Sbostic int
infrom(hand,n,prompt)1587872Sarnold infrom(hand, n, prompt)
15959264Sbostic 	CARD hand[];
16059264Sbostic 	int n;
16159264Sbostic 	char *prompt;
1627709Sarnold {
16359264Sbostic 	register int i, j;
16459264Sbostic 	CARD crd;
1657709Sarnold 
1667872Sarnold 	if (n < 1) {
16759264Sbostic 		printf("\nINFROM: %d = n < 1!!\n", n);
16859264Sbostic 		exit(74);
1697872Sarnold 	}
1707872Sarnold 	for (;;) {
17159264Sbostic 		msg(prompt);
17259264Sbostic 		if (incard(&crd)) {	/* if card is full card */
17359264Sbostic 			if (!isone(crd, hand, n))
17459264Sbostic 				msg("That's not in your hand");
17559264Sbostic 			else {
17659264Sbostic 				for (i = 0; i < n; i++)
17759264Sbostic 					if (hand[i].rank == crd.rank &&
17859264Sbostic 					    hand[i].suit == crd.suit)
17959264Sbostic 						break;
18059264Sbostic 				if (i >= n) {
1817872Sarnold 			printf("\nINFROM: isone or something messed up\n");
18259264Sbostic 					exit(77);
18359264Sbostic 				}
18459264Sbostic 				return (i);
18559264Sbostic 			}
18659264Sbostic 		} else			/* if not full card... */
18759264Sbostic 			if (crd.rank != EMPTY) {
18859264Sbostic 				for (i = 0; i < n; i++)
18959264Sbostic 					if (hand[i].rank == crd.rank)
19059264Sbostic 						break;
19159264Sbostic 				if (i >= n)
19259264Sbostic 					msg("No such rank in your hand");
19359264Sbostic 				else {
19459264Sbostic 					for (j = i + 1; j < n; j++)
19559264Sbostic 						if (hand[j].rank == crd.rank)
19659264Sbostic 							break;
19759264Sbostic 					if (j < n)
19859264Sbostic 						msg("Ambiguous rank");
19959264Sbostic 					else
20059264Sbostic 						return (i);
20159264Sbostic 				}
20259264Sbostic 			} else
20359264Sbostic 				msg("Sorry, I missed that");
2047872Sarnold 	}
2057872Sarnold 	/* NOTREACHED */
2067709Sarnold }
2077709Sarnold 
2087709Sarnold /*
2097872Sarnold  * incard:
2107872Sarnold  *	Inputs a card in any format.  It reads a line ending with a CR
2117872Sarnold  *	and then parses it.
2127709Sarnold  */
21359264Sbostic int
incard(crd)2147872Sarnold incard(crd)
21559264Sbostic 	CARD *crd;
2167709Sarnold {
21759264Sbostic 	register int i;
21859264Sbostic 	int rnk, sut;
21959264Sbostic 	char *line, *p, *p1;
22059264Sbostic 	BOOLEAN retval;
2217709Sarnold 
2227872Sarnold 	retval = FALSE;
2237872Sarnold 	rnk = sut = EMPTY;
2247872Sarnold 	if (!(line = getline()))
2257872Sarnold 		goto gotit;
2267872Sarnold 	p = p1 = line;
22759264Sbostic 	while (*p1 != ' ' && *p1 != NULL)
22859264Sbostic 		++p1;
2297872Sarnold 	*p1++ = NULL;
23059264Sbostic 	if (*p == NULL)
23159264Sbostic 		goto gotit;
23259264Sbostic 
23359264Sbostic 	/* IMPORTANT: no real card has 2 char first name */
23459264Sbostic 	if (strlen(p) == 2) {	/* check for short form */
23559264Sbostic 		rnk = EMPTY;
23659264Sbostic 		for (i = 0; i < RANKS; i++) {
23759264Sbostic 			if (*p == *rankchar[i]) {
23859264Sbostic 				rnk = i;
23959264Sbostic 				break;
24059264Sbostic 			}
2417872Sarnold 		}
24259264Sbostic 		if (rnk == EMPTY)
24359264Sbostic 			goto gotit;	/* it's nothing... */
24459264Sbostic 		++p;		/* advance to next char */
24559264Sbostic 		sut = EMPTY;
24659264Sbostic 		for (i = 0; i < SUITS; i++) {
24759264Sbostic 			if (*p == *suitchar[i]) {
24859264Sbostic 				sut = i;
24959264Sbostic 				break;
25059264Sbostic 			}
2517872Sarnold 		}
25259264Sbostic 		if (sut != EMPTY)
25359264Sbostic 			retval = TRUE;
25459264Sbostic 		goto gotit;
2557872Sarnold 	}
2567872Sarnold 	rnk = EMPTY;
25759264Sbostic 	for (i = 0; i < RANKS; i++) {
25859264Sbostic 		if (!strcmp(p, rankname[i]) || !strcmp(p, rankchar[i])) {
25959264Sbostic 			rnk = i;
26059264Sbostic 			break;
26159264Sbostic 		}
2627872Sarnold 	}
26359264Sbostic 	if (rnk == EMPTY)
26459264Sbostic 		goto gotit;
2657872Sarnold 	p = p1;
26659264Sbostic 	while (*p1 != ' ' && *p1 != NULL)
26759264Sbostic 		++p1;
2687872Sarnold 	*p1++ = NULL;
26959264Sbostic 	if (*p == NULL)
27059264Sbostic 		goto gotit;
27159264Sbostic 	if (!strcmp("OF", p)) {
27259264Sbostic 		p = p1;
27359264Sbostic 		while (*p1 != ' ' && *p1 != NULL)
27459264Sbostic 			++p1;
27559264Sbostic 		*p1++ = NULL;
27659264Sbostic 		if (*p == NULL)
27759264Sbostic 			goto gotit;
2787872Sarnold 	}
2797872Sarnold 	sut = EMPTY;
28059264Sbostic 	for (i = 0; i < SUITS; i++) {
28159264Sbostic 		if (!strcmp(p, suitname[i]) || !strcmp(p, suitchar[i])) {
28259264Sbostic 			sut = i;
28359264Sbostic 			break;
28459264Sbostic 		}
2857872Sarnold 	}
28659264Sbostic 	if (sut != EMPTY)
28759264Sbostic 		retval = TRUE;
2887709Sarnold gotit:
2897872Sarnold 	(*crd).rank = rnk;
2907872Sarnold 	(*crd).suit = sut;
29159264Sbostic 	return (retval);
2927709Sarnold }
2937709Sarnold 
2947709Sarnold /*
2957872Sarnold  * getuchar:
2967872Sarnold  *	Reads and converts to upper case
2977709Sarnold  */
29859264Sbostic int
getuchar()2997709Sarnold getuchar()
3007709Sarnold {
30159264Sbostic 	register int c;
3027709Sarnold 
3037872Sarnold 	c = readchar();
3047872Sarnold 	if (islower(c))
30559264Sbostic 		c = toupper(c);
30612163Sarnold 	waddch(Msgwin, c);
30759264Sbostic 	return (c);
3087709Sarnold }
3097709Sarnold 
3107709Sarnold /*
3117934Sarnold  * number:
3127934Sarnold  *	Reads in a decimal number and makes sure it is between "lo" and
3137934Sarnold  *	"hi" inclusive.
3147709Sarnold  */
31559264Sbostic int
number(lo,hi,prompt)3167934Sarnold number(lo, hi, prompt)
31759264Sbostic 	int lo, hi;
31859264Sbostic 	char *prompt;
3197709Sarnold {
32059264Sbostic 	register char *p;
32159264Sbostic 	register int sum;
3227709Sarnold 
32359264Sbostic 	for (sum = 0;;) {
32459264Sbostic 		msg(prompt);
32559264Sbostic 		if (!(p = getline()) || *p == NULL) {
32659264Sbostic 			msg(quiet ? "Not a number" :
32759264Sbostic 			    "That doesn't look like a number");
32859264Sbostic 			continue;
3297934Sarnold 		}
33059264Sbostic 		sum = 0;
3317934Sarnold 
33259264Sbostic 		if (!isdigit(*p))
33359264Sbostic 			sum = lo - 1;
33459264Sbostic 		else
33559264Sbostic 			while (isdigit(*p)) {
33659264Sbostic 				sum = 10 * sum + (*p - '0');
33759264Sbostic 				++p;
33859264Sbostic 			}
33959264Sbostic 
34059264Sbostic 		if (*p != ' ' && *p != '\t' && *p != NULL)
34159264Sbostic 			sum = lo - 1;
34259264Sbostic 		if (sum >= lo && sum <= hi)
34359264Sbostic 			break;
34459264Sbostic 		if (sum == lo - 1)
34559264Sbostic 			msg("that doesn't look like a number, try again --> ");
34659264Sbostic 		else
3477934Sarnold 		msg("%d is not between %d and %d inclusive, try again --> ",
34859264Sbostic 			    sum, lo, hi);
3497934Sarnold 	}
35059264Sbostic 	return (sum);
3517709Sarnold }
3527709Sarnold 
3537872Sarnold /*
3547872Sarnold  * msg:
3557872Sarnold  *	Display a message at the top of the screen.
3567872Sarnold  */
35759264Sbostic char    Msgbuf[BUFSIZ] = {'\0'};
35859264Sbostic int     Mpos = 0;
35959264Sbostic static int Newpos = 0;
3607709Sarnold 
36157823Storek void
36252540Storek #if __STDC__
msg(const char * fmt,...)36357823Storek msg(const char *fmt, ...)
36452540Storek #else
36552540Storek msg(fmt, va_alist)
36646264Sbostic 	char *fmt;
36752540Storek 	va_dcl
36852540Storek #endif
3697872Sarnold {
37046264Sbostic 	va_list ap;
37146264Sbostic 
37252540Storek #if __STDC__
37346264Sbostic 	va_start(ap, fmt);
37452540Storek #else
37552540Storek 	va_start(ap);
37652540Storek #endif
37746743Sbostic 	(void)vsprintf(&Msgbuf[Newpos], fmt, ap);
37846264Sbostic 	va_end(ap);
37946264Sbostic 	endmsg();
3807872Sarnold }
3817872Sarnold 
3827709Sarnold /*
3837872Sarnold  * addmsg:
3847872Sarnold  *	Add things to the current message
3857709Sarnold  */
38657823Storek void
38752540Storek #if __STDC__
addmsg(const char * fmt,...)38857823Storek addmsg(const char *fmt, ...)
38952540Storek #else
39052540Storek addmsg(fmt, va_alist)
39146264Sbostic 	char *fmt;
39252540Storek 	va_dcl
39352540Storek #endif
3947872Sarnold {
39546264Sbostic 	va_list ap;
39646264Sbostic 
39752540Storek #if __STDC__
39846264Sbostic 	va_start(ap, fmt);
39952540Storek #else
40052540Storek 	va_start(ap);
40152540Storek #endif
40246743Sbostic 	(void)vsprintf(&Msgbuf[Newpos], fmt, ap);
40346264Sbostic 	va_end(ap);
4047872Sarnold }
4057709Sarnold 
4067872Sarnold /*
4077872Sarnold  * endmsg:
40812163Sarnold  *	Display a new msg.
4097872Sarnold  */
41059264Sbostic int     Lineno = 0;
41112316Sarnold 
41259264Sbostic void
endmsg()4137872Sarnold endmsg()
4147709Sarnold {
41559264Sbostic 	static int lastline = 0;
41659264Sbostic 	register int len;
41759264Sbostic 	register char *mp, *omp;
41812163Sarnold 
41959264Sbostic 	/* All messages should start with uppercase */
42059264Sbostic 	mvaddch(lastline + Y_MSG_START, SCORE_X, ' ');
42159264Sbostic 	if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
42259264Sbostic 		Msgbuf[0] = toupper(Msgbuf[0]);
42359264Sbostic 	mp = Msgbuf;
42459264Sbostic 	len = strlen(mp);
42559264Sbostic 	if (len / MSG_X + Lineno >= MSG_Y) {
42659264Sbostic 		while (Lineno < MSG_Y) {
42759264Sbostic 			wmove(Msgwin, Lineno++, 0);
42859264Sbostic 			wclrtoeol(Msgwin);
42959264Sbostic 		}
43059264Sbostic 		Lineno = 0;
43112330Sarnold 	}
43259264Sbostic 	mvaddch(Lineno + Y_MSG_START, SCORE_X, '*');
43359264Sbostic 	lastline = Lineno;
43459264Sbostic 	do {
43559264Sbostic 		mvwaddstr(Msgwin, Lineno, 0, mp);
43659264Sbostic 		if ((len = strlen(mp)) > MSG_X) {
43759264Sbostic 			omp = mp;
43859264Sbostic 			for (mp = &mp[MSG_X - 1]; *mp != ' '; mp--)
43959264Sbostic 				continue;
44059264Sbostic 			while (*mp == ' ')
44159264Sbostic 				mp--;
44259264Sbostic 			mp++;
44359264Sbostic 			wmove(Msgwin, Lineno, mp - omp);
44459264Sbostic 			wclrtoeol(Msgwin);
44559264Sbostic 		}
44659264Sbostic 		if (++Lineno >= MSG_Y)
44759264Sbostic 			Lineno = 0;
44859264Sbostic 	} while (len > MSG_X);
44959264Sbostic 	wclrtoeol(Msgwin);
45059264Sbostic 	Mpos = len;
45159264Sbostic 	Newpos = 0;
45259264Sbostic 	wrefresh(Msgwin);
45359264Sbostic 	refresh();
45459264Sbostic 	wrefresh(Msgwin);
4557872Sarnold }
4567709Sarnold 
4577872Sarnold /*
45812316Sarnold  * do_wait:
45912316Sarnold  *	Wait for the user to type ' ' before doing anything else
46012316Sarnold  */
46159264Sbostic void
do_wait()46212316Sarnold do_wait()
46312316Sarnold {
46459264Sbostic 	static char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'};
46512316Sarnold 
46659264Sbostic 	if (Mpos + sizeof prompt < MSG_X)
46759264Sbostic 		wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos);
46859264Sbostic 	else {
46959264Sbostic 		mvwaddch(Msgwin, Lineno, 0, ' ');
47059264Sbostic 		wclrtoeol(Msgwin);
47159264Sbostic 		if (++Lineno >= MSG_Y)
47259264Sbostic 			Lineno = 0;
47359264Sbostic 	}
47459264Sbostic 	waddstr(Msgwin, prompt);
47559264Sbostic 	wrefresh(Msgwin);
47659264Sbostic 	wait_for(' ');
47712316Sarnold }
47812316Sarnold 
47912316Sarnold /*
4807872Sarnold  * wait_for
4817872Sarnold  *	Sit around until the guy types the right key
4827872Sarnold  */
48359264Sbostic void
wait_for(ch)4847872Sarnold wait_for(ch)
48559264Sbostic 	register int ch;
4867872Sarnold {
48759264Sbostic 	register char c;
4887709Sarnold 
48959264Sbostic 	if (ch == '\n')
49059264Sbostic 		while ((c = readchar()) != '\n')
49159264Sbostic 			continue;
49259264Sbostic 	else
49359264Sbostic 		while (readchar() != ch)
49459264Sbostic 			continue;
4957872Sarnold }
4967709Sarnold 
4977872Sarnold /*
4987872Sarnold  * readchar:
4997872Sarnold  *	Reads and returns a character, checking for gross input errors
5007872Sarnold  */
50159264Sbostic int
readchar()5027872Sarnold readchar()
5037872Sarnold {
50459264Sbostic 	register int cnt;
50559264Sbostic 	char c;
5067709Sarnold 
5077872Sarnold over:
50859264Sbostic 	cnt = 0;
50959264Sbostic 	while (read(STDIN_FILENO, &c, sizeof(char)) <= 0)
51059264Sbostic 		if (cnt++ > 100) {	/* if we are getting infinite EOFs */
51159264Sbostic 			bye();		/* quit the game */
51259264Sbostic 			exit(1);
51359264Sbostic 		}
51459264Sbostic 	if (c == CTRL('L')) {
51559264Sbostic 		wrefresh(curscr);
51659264Sbostic 		goto over;
51741186Sbostic 	}
51859264Sbostic 	if (c == '\r')
51959264Sbostic 		return ('\n');
52059264Sbostic 	else
52159264Sbostic 		return (c);
5227872Sarnold }
5237872Sarnold 
5247872Sarnold /*
5257872Sarnold  * getline:
5267872Sarnold  *      Reads the next line up to '\n' or EOF.  Multiple spaces are
5277872Sarnold  *	compressed to one space; a space is inserted before a ','
5287872Sarnold  */
5297872Sarnold char *
getline()5307872Sarnold getline()
5317872Sarnold {
53259264Sbostic 	register char *sp;
53359264Sbostic 	register int c, oy, ox;
53459264Sbostic 	register WINDOW *oscr;
5357872Sarnold 
53659264Sbostic 	oscr = stdscr;
53759264Sbostic 	stdscr = Msgwin;
53859264Sbostic 	getyx(stdscr, oy, ox);
53959264Sbostic 	refresh();
54059264Sbostic 	/* loop reading in the string, and put it in a temporary buffer */
54159264Sbostic 	for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
54259264Sbostic 		if (c == -1)
54359264Sbostic 			continue;
54459264Sbostic 		else
54559264Sbostic 			if (c == erasechar()) {	/* process erase character */
54659264Sbostic 				if (sp > linebuf) {
54759264Sbostic 					register int i;
5487872Sarnold 
54959264Sbostic 					sp--;
55059264Sbostic 					for (i = strlen(unctrl(*sp)); i; i--)
55159264Sbostic 						addch('\b');
55259264Sbostic 				}
55359264Sbostic 				continue;
55459264Sbostic 			} else
55559264Sbostic 				if (c == killchar()) {	/* process kill
55659264Sbostic 							 * character */
55759264Sbostic 					sp = linebuf;
55859264Sbostic 					move(oy, ox);
55959264Sbostic 					continue;
56059264Sbostic 				} else
56159264Sbostic 					if (sp == linebuf && c == ' ')
56259264Sbostic 						continue;
56359264Sbostic 		if (sp >= &linebuf[LINESIZE - 1] || !(isprint(c) || c == ' '))
56459264Sbostic 			putchar(CTRL('G'));
56559264Sbostic 		else {
56659264Sbostic 			if (islower(c))
56759264Sbostic 				c = toupper(c);
56859264Sbostic 			*sp++ = c;
56959264Sbostic 			addstr(unctrl(c));
57059264Sbostic 			Mpos++;
57159264Sbostic 		}
5727872Sarnold 	}
57359264Sbostic 	*sp = '\0';
57459264Sbostic 	stdscr = oscr;
57559264Sbostic 	return (linebuf);
5767872Sarnold }
57714910Sarnold 
57859264Sbostic void
rint(signo)57959264Sbostic rint(signo)
58059264Sbostic 	int signo;
58141186Sbostic {
58241186Sbostic 	bye();
58341186Sbostic 	exit(1);
58441186Sbostic }
58541186Sbostic 
58614910Sarnold /*
58714910Sarnold  * bye:
58814910Sarnold  *	Leave the program, cleaning things up as we go.
58914910Sarnold  */
59059264Sbostic void
bye()59114910Sarnold bye()
59214910Sarnold {
59314910Sarnold 	signal(SIGINT, SIG_IGN);
59414910Sarnold 	mvcur(0, COLS - 1, LINES - 1, 0);
59514910Sarnold 	fflush(stdout);
59614910Sarnold 	endwin();
59714910Sarnold 	putchar('\n');
59814910Sarnold }
599