home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_04 / 1104034a < prev    next >
Text File  |  1992-12-15  |  2KB  |  144 lines

  1. /*
  2.   listing 4 - menu.c
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <signal.h>
  8. #include <time.h>
  9. #include <string.h>
  10.  
  11. #ifdef BCC
  12. #include <dos.h>
  13. #include <conio.h>
  14. #endif
  15.  
  16. #include "curses.h"
  17. #include "menu.h"
  18. #include "internal.h"
  19.  
  20. char choice;
  21.  
  22. /* windows global to all routines */
  23.  
  24. WINDOW *dialogue;
  25. WINDOW *tbar;
  26.  
  27. /* define menubar with three options */
  28.  
  29. MENUBAR menubar[TCHOICES] = {
  30.   "file",    'f',    0,
  31.   "edit",    'e',    0,
  32.   "options", 'o',    0,
  33. };
  34.  
  35. /* define pulldown menu sub-choices */
  36.  
  37. CHOICES choices1[3] = {
  38.   "open ", 'o', c_open,
  39.   "close", 'c', c_close,
  40.   "exit ", 'e', c_exit,
  41. };
  42.  
  43. CHOICES choices2[4] = {
  44.   "copy  ", 'c', c_copy,
  45.   "paste ", 'p', c_paste,
  46.   "delete", 'd', c_delete,
  47.   "move  ", 'm', c_move,
  48. };
  49.  
  50. CHOICES choices3[4] = {
  51.   "version", 'v', c_version,
  52.   "compile", 'c', c_compile,
  53.   "link   ", 'l', c_link,
  54.   "run    ", 'r', c_run,
  55. };
  56.  
  57. /* tie all choices into one struct */
  58.  
  59. PULLDOWN pullmenu[TCHOICES] = {
  60.   3, 5, choices1,
  61.   4, 6, choices2,
  62.   4, 7, choices3,
  63. };
  64.  
  65. main()
  66. {
  67.  
  68.  
  69.   int i,j,k;
  70.  
  71.  
  72.   initscr();
  73.  
  74.   /* needed to return one keystroke at a time */
  75.  
  76. #ifndef VMS
  77.   cbreak();
  78. #else
  79.   crmode();
  80. #endif
  81.  
  82.   /* activate keypad code */
  83.  
  84. #ifdef HPUX
  85.   keypad(stdscr, TRUE);
  86. #endif
  87.  
  88.   noecho();
  89.  
  90. #ifdef BCC
  91.   cursoff();
  92. #endif
  93.  
  94.   /* set up screen */
  95.  
  96.   set_stdscr();
  97.  
  98.   dialogue = popup(3, MAX_COLUMNS-4, MAX_ROWS-4, 2);
  99.  
  100.   clear_dialogue();
  101.  
  102.   tbar = topbar(stdscr);
  103.  
  104.   /* enter loop to process options */
  105.  
  106.   for (;;) {
  107.  
  108.     choice = do_menubar(tbar, menubar);
  109.  
  110.     for (i=0;i<TCHOICES;i++) {
  111.  
  112.         if ( choice == menubar[i].letter) {
  113.  
  114.           choice = do_pulldown(i,pullmenu,menubar);
  115.  
  116.           execute_command(i, choice, pullmenu);
  117.  
  118.           break;
  119.  
  120.         }  /* if */
  121.     }    /* for loop */
  122.  
  123.   }       /* end main loop (for (;;))*/
  124.  
  125. }
  126.  
  127.  
  128. /* these commands must be called at exit */
  129. int clean_up()
  130. {
  131.  
  132.   erase();
  133.   refresh();
  134.   endwin();
  135.  
  136. #ifdef BCC
  137.   clrscr();
  138. #endif
  139.  
  140.   exit(0);
  141.  
  142.   return(0);
  143. }
  144.