xref: /netbsd-src/lib/libcurses/EXAMPLES/ex1.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: ex1.c,v 1.4 2003/08/07 16:44:26 agc Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #ifndef lint
34 static char copyright[] =
35 "@(#) Copyright (c) 1992, 1993\n\
36 	The Regents of the University of California.  All rights reserved.\n";
37 #endif /* not lint */
38 
39 #ifndef lint
40 static char sccsid[] = "@(#)ex1.c	8.1 (Berkeley) 6/4/93";
41 #endif /* not lint */
42 #include <sys/types.h>
43 #include <curses.h>
44 #include <stdio.h>
45 #include <signal.h>
46 
47 
48 #define YSIZE 10
49 #define XSIZE 20
50 
51 int quit();
52 
53 main()
54 {
55 	int i, j, c;
56 	size_t len;
57 	char id[100];
58 	FILE *fp;
59 	char *s;
60 
61 	initscr();			/* Always call initscr() first */
62 	signal(SIGINT, quit);		/* Make sure wou have a 'cleanup' fn */
63 	crmode();			/* We want cbreak mode */
64 	noecho();			/* We want to have control of chars */
65 	delwin(stdscr);			/* Create our own stdscr */
66 	stdscr = newwin(YSIZE, XSIZE, 10, 35);
67 	flushok(stdscr, TRUE);		/* Enable flushing of stdout */
68 	scrollok(stdscr, TRUE);		/* Enable scrolling */
69 	erase();			/* Initially, clear the screen */
70 
71 	standout();
72 	move(0,0);
73 	while (1) {
74 		c = getchar();
75 		switch(c) {
76 		case 'q':		/* Quit on 'q' */
77 			quit();
78 			break;
79 		case 's':		/* Go into standout mode on 's' */
80 			standout();
81 			break;
82 		case 'e':		/* Exit standout mode on 'e' */
83 			standend();
84 			break;
85 		case 'r':		/* Force a refresh on 'r' */
86 			wrefresh(curscr);
87 			break;
88 		default:		/* By default output the character */
89 			addch(c);
90 			refresh();
91 		}
92 	}
93 }
94 
95 
96 int
97 quit()
98 {
99 	erase();		/* Terminate by erasing the screen */
100 	refresh();
101 	endwin();		/* Always end with endwin() */
102 	delwin(curscr);		/* Return storage */
103 	delwin(stdscr);
104 	putchar('\n');
105 	exit(0);
106 }
107 
108 
109 
110 
111