00001 /* 00002 Full-screen application (Curses) 00003 AUP2, Sec. 4.08 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 /* 00022 <stdbool.h> and <curses.h> define bool incompatibly, so the following 00023 kludge separates the two. 00024 */ 00025 #ifndef FREEBSD 00026 #define bool bool_aup 00027 #endif 00028 #include "defs.h" 00029 #ifndef FREEBSD 00030 #undef bool 00031 #endif 00032 00033 /*[scrappc]*/ 00034 #include <curses.h> 00035 00036 /* "ec" macro for ERR (used by curses) */ 00037 #define ec_ERR(x) ec_cmp(x, ERR) 00038 00039 int main(void) 00040 { 00041 int c; 00042 char s[100]; 00043 bool ok = false; 00044 00045 (void)initscr(); 00046 ec_ERR( raw() ) 00047 while (true) { 00048 ec_ERR( clear() ) 00049 ec_ERR( mvaddstr(2, 9, "What do you want to do?") ) 00050 ec_ERR( mvaddstr(3, 9, "1. Check out tape/DVD") ) 00051 ec_ERR( mvaddstr(4, 9, "2. Reserve tape/DVD") ) 00052 ec_ERR( mvaddstr(5, 9, "3. Register new member") ) 00053 ec_ERR( mvaddstr(6, 9, "4. Search for title/actor") ) 00054 ec_ERR( mvaddstr(7, 9, "5. Quit") ) 00055 ec_ERR( mvaddstr(9, 9, "(Type item number to continue)") ) 00056 ec_ERR( c = getch() ) 00057 switch (c) { 00058 case '1': 00059 case '2': 00060 case '3': 00061 case '4': 00062 ec_ERR( clear() ) 00063 snprintf(s, sizeof(s), "You typed %c", c); 00064 ec_ERR( mvaddstr(4, 9, s) ) 00065 ec_ERR( mvaddstr(9, 9, "(Press any key to continue)") ) 00066 ec_ERR( getch() ) 00067 break; 00068 case '5': 00069 ok = true; 00070 EC_CLEANUP 00071 default: 00072 ec_ERR( beep() ) 00073 } 00074 } 00075 00076 EC_CLEANUP_BGN 00077 (void)clear(); 00078 (void)refresh(); 00079 (void)endwin(); 00080 exit(ok ? EXIT_SUCCESS : EXIT_FAILURE); 00081 EC_CLEANUP_END 00082 }