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