©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c4/scrapp.c

Go to the documentation of this file.
00001 /*
00002     Full-screen application (ANSI/VT100)
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 #include "defs.h"
00022 #include "tc_setraw.h"
00023 
00024 /*
00025     Only two VT100 escape sequences are used:
00026 
00027     CUP -- Cursor Position
00028         ESC [ Pn ; Pn H
00029 
00030     ED -- Erase In Display
00031         ESC [ Ps J
00032 */
00033 
00034 /*[mvaddstr-clear]*/
00035 #define ESC "\033"
00036 
00037 bool mvaddstr(int y, int x, const char *str)
00038 {
00039     return printf(ESC "[%d;%dH%s", y, x, str) >= 0;
00040 }
00041 
00042 bool clear(void)
00043 {
00044     return printf(ESC "[2J") >= 0 &&
00045       mvaddstr(0, 0, "");
00046 }
00047 /*[getch]*/
00048 int getch(void)
00049 {
00050     char c;
00051 
00052     switch(read(STDIN_FILENO, &c, 1)) {
00053     default:
00054         errno = 0;
00055         /* fall through */
00056     case -1:
00057         return -1;
00058     case 1:
00059         break;
00060     }
00061     return c;
00062 }
00063 /*[beep]*/
00064 #define BEL "\007"
00065 
00066 int beep(void)
00067 {
00068     return printf(BEL) >= 0;
00069 }
00070 /*[main]*/
00071 int main(void)
00072 {
00073     int c;
00074     char s[100];
00075     bool ok = false;
00076 
00077     ec_false( tc_setraw() )
00078     setbuf(stdout, NULL);
00079     while (true) {
00080         ec_false( clear() )
00081         ec_false( mvaddstr( 2, 9, "What do you want to do?") )
00082         ec_false( mvaddstr( 3, 9, "1. Check out tape/DVD") )
00083         ec_false( mvaddstr( 4, 9, "2. Reserve tape/DVD") )
00084         ec_false( mvaddstr( 5, 9, "3. Register new member") )
00085         ec_false( mvaddstr( 6, 9, "4. Search for title/actor") )
00086         ec_false( mvaddstr( 7, 9, "5. Quit") )
00087         ec_false( mvaddstr( 9, 9, "(Type item number to continue)") )
00088         ec_neg1( c = getch() )
00089         switch (c) {
00090         case '1':
00091         case '2':
00092         case '3':
00093         case '4':
00094             ec_false( clear() )
00095             snprintf(s, sizeof(s), "You typed %c", c);
00096             ec_false( mvaddstr( 4, 9, s) )
00097             ec_false( mvaddstr( 9, 9, "(Press any key to continue)") )
00098             ec_neg1( getch() )
00099             break;
00100         case '5':
00101             ok = true;
00102             EC_CLEANUP
00103         default:
00104             ec_false( beep() )
00105         }
00106     }
00107 
00108 
00109 EC_CLEANUP_BGN
00110     (void)tc_restore();
00111     (void)clear();
00112     exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
00113 EC_CLEANUP_END
00114 }
00115 /*[]*/

Generated on Fri Apr 23 10:56:56 2004 for AUP2 Example Source by doxygen 1.3.1