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