00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022 #include "tc_setraw.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00048 int getch(void)
00049 {
00050 char c;
00051
00052 switch(read(STDIN_FILENO, &c, 1)) {
00053 default:
00054 errno = 0;
00055
00056 case -1:
00057 return -1;
00058 case 1:
00059 break;
00060 }
00061 return c;
00062 }
00063
00064 #define BEL "\007"
00065
00066 int beep(void)
00067 {
00068 return printf(BEL) >= 0;
00069 }
00070
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