1 /*
2  * Copyright (c) 1980 Regents of the University of California. All rights
3  * reserved.  The Berkeley software License Agreement specifies the terms and
4  * conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char	sccsid[] = "@(#)close.c	5.1 (Berkeley) 5/7/85";
9 #endif				/* not lint */
10 
11 #include <stdlib.h>
12 #include <signal.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include "crt.h"
16 #include <plot.h>
17 
18 void
pl_closepl(void)19 pl_closepl(void)
20 {
21 	FILE	       *ctty;
22 	char		ctty_path[L_ctermid];
23 	register char	c;
24 
25 	/* Leave cursor at top of screen. */
26 	move(0, 0);
27 	refresh();
28 
29 	/*
30 	 * Wait for 'q' from controlling terminal, because stdin and stdscr
31 	 * can be redirected.
32 	 */
33 	if (ctermid(ctty_path) != NULL && (ctty = fopen(ctty_path, "rb")) != NULL) {
34 		while ((c = fgetc(ctty)) != EOF)
35 			if (c == 'q')
36 				break;
37 
38 		fclose(ctty);
39 	}
40 
41 	pl_closevt();
42 }
43 
44 void
pl_closevt(void)45 pl_closevt(void)
46 {
47 	erase();
48 	refresh();
49 	endwin();
50 }
51