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