/* Program: MENU.C Author : Kim Moser Date : 15 August 1989 System : IBM PC / Borland Turbo-C 2.0 Descrip: Generic menu system Usage : MENU */ #include #include #include #include #include #include "kmvid.h" char *NEXTNAME="E:\\NEXT.BAT"; /* Batch file to be executed next */ char *PNAME; /* Needed only because argv[0] isn't global, and must be copied to PNAME */ #define NORMFG WHITE #define NORMBG BLACK #define HIGHFG YELLOW #define HIGHBG BLUE int MAXCHOICE=0; /* # of choices; determined at runtime */ #define STARTROW 6 /* Row at which to start writing menu choices */ char ERR[255]; /* Error msgs are written to this string via sprintf() */ char CURDRIVE; /* Letter of current drive; set at runtime */ struct { scrncoord x, y; /* 'y' is just an offset from STARTROW */ char name[80]; char descrip[80]; char batch[80]; } MENU[] = { 0,0, " RepTools Demo ", "Demonstration of RepTools (Modula-2 utility library for programmers)", "A:\nCD\\TOOLDEMO\nTOOLDEMO", 0,1, " RepTools documentation and demo source ", "Documentation for RepTools, and Modula-2 source code for demo", "A:\\UTIL\\L A:\\TOOLDEMO\\REPTOOLS.DOC A:\\TOOLDEMO\\TOOLDEMO.MOD", 0,3, " Slide Show ", "Slide show demonstration (requires EGA)", "A:\nCD\\SLIDE\nSS", 0,5, " Life ", "John Conway's game of Life", "A:\nCD\\LIFE\nLIFE", 0,6, " Life documentation and source ", "Documentation and C source code for Life", "A:\\UTIL\\L A:\\LIFE\\LIFE.DOC A:\\LIFE\\LIFE.C", 0,8, " ViewC64 Demo ", "Demonstration of ViewC64 (view C-64 graphics on a PC; requires EGA)", "A:\nCD\\VIEWC64\nVIEWDEMO.BAT", 0,9, " ViewC64 documentation ", "Documentation for ViewC64", "A:\\UTIL\\L A:\\VIEWC64\\VIEWC64.DOC", 0,0, "", "", "" }; void halt(s) char *s; { fprintf(stderr,s); fprintf(stderr, "\nNote: the DOS environment variable COMSPEC must be set to the\n" ); fprintf(stderr, "fully qualified filename (including drive and path) of COMMAND.COM\n" ); exit(1); } void hilite( n ) int n; { set_color( HIGHFG, HIGHBG ); writeat( MENU[n].x, MENU[n].y, MENU[n].name ); set_color( NORMFG, NORMBG ); writeat( MENU[n].x-1, MENU[n].y, "\020" ); writeat( MENU[n].x+strlen(MENU[n].name), MENU[n].y, "\021" ); set_color( GREEN, BLACK ); writeatcenter( 18, " " ); writeatcenter( 18, MENU[n].descrip ); } void unhilite( n ) int n; { set_color( NORMFG, NORMBG ); writeat( MENU[n].x, MENU[n].y, MENU[n].name ); writeat( MENU[n].x-1, MENU[n].y, " " ); writeat( MENU[n].x+strlen(MENU[n].name), MENU[n].y, " " ); } void run(n) int n; /* Choice (0=first, etc.) */ { char s[255]; /* Temp */ int i=0, j=0; /* Indexes into MENU[n].batch and s, respectively */ while(MENU[n].batch[i]) { for (j=0; (MENU[n].batch[i]!='\n') && MENU[n].batch[i]; j++) { s[j]=MENU[n].batch[i]; i++; } s[j]='\n'; s[j+1]=0; /* Terminate string */ i++; if ( system(s) ) { sprintf( ERR, "Unable to perform command:\n%s", s ); halt(ERR); } } /* FILE *f; if ((f=fopen(NEXTNAME, "w")) == NULL) { fclose(f); sprintf( ERR, "%s: Error creating '%s'\n", PNAME, NEXTNAME ); halt(err); } fprintf( f, MENU[n].batch ); /* If we're making a blank batch file... */ if (n != MAXCHOICE) { /* ...put line in batch file to restart */ fprintf( f, "\nA:\\DEMO" ); } if (fclose(f)) { fprintf( stderr, "%s: Error closing '%s'\n", PNAME, NEXTNAME ); exit(1); } */ } void draw(n) int n; /* Which choice should start hilighted */ { int i; clearscr(WHITE, BLACK); set_color(LIGHTGRAY, BLACK); box( 1, 4, 80, 17, SINGLEBOX ); box( 1, 17, 80, 19, SINGLEBOX ); writeatch(1, 17, '\xC3'); writeatch(80, 17, '\xB4'); set_color(CYAN,BLACK); writeatcenter(21, "For more information on these programs, please contact:" ); set_color(LIGHTCYAN, BLACK); writeatcenter(22, "Kim Moser"); writeatcenter(23, "127 East 15th Street" ); writeatcenter(24, "New York, NY 10003" ); writeatcenter(25, "(212) 674-7205" ); set_color(LIGHTBLUE, BLACK); writeatcenter( 1, "Use the \030 \031 \032 \033 keys to highlight an item from the menu below," ); writeatcenter( 2, "then press the key to select the highlighted item." ); writeatcenter( 3, "Press 'Q' or to quit." ); for (i=0; i