home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_01 / cmenu.exe / RMENU3.C < prev    next >
Text File  |  1991-10-17  |  3KB  |  153 lines

  1. /************************************************************
  2.  *    Program: RMENU Menu Interpreter
  3.  *  Module: rmenu3.c
  4.  *        Execute a Menu Item
  5.  *    Written by: Leor Zolman, 7/91
  6.  ************************************************************/
  7.  
  8. #include "cmenu.h"
  9. #include "rcmenu.h"
  10.  
  11.  
  12. /************************************************************
  13.  * do_item():
  14.  *    Perform the action associated with a particular item.
  15.  *    Default path is supplied as "path":
  16.  ************************************************************/
  17.  
  18. int do_item(M2p, curr, path)
  19. MENU2 *M2p;
  20. int curr;
  21. char *path;
  22. {
  23.     ITEM *Ip = M2p -> Items[curr];
  24.     char newpath[MAX_PATH];
  25.     int i, j;
  26.  
  27.     strcpy(newpath, make_path(path, Ip -> path));
  28.  
  29.     switch (Ip -> acttyp)
  30.     {
  31.         case ACT_CMND:
  32.             do_cmnd(Ip, newpath);
  33.             break;
  34.  
  35.         case ACT_LMENU:
  36.             if (sub_menu(Ip->lmenunum, newpath) == EXITALL)
  37.                 return EXITALL;
  38.             break;
  39.                 
  40.         case ACT_EMENU:
  41.             if (do_emenu(Ip, newpath) == EXITALL)
  42.                 return EXITALL;
  43.             break;
  44.     }
  45.     return OK;
  46. }
  47.  
  48.  
  49. /************************************************************
  50.  * do_cmnd():
  51.  *    Run a directly executable item.
  52.  ************************************************************/
  53.  
  54. Void do_cmnd(Ip, path)
  55. ITEM *Ip;
  56. char *path;
  57. {
  58.     char *cmd_line;
  59.     int retval;
  60.  
  61.     cmd_line = make_cmd(path, Ip -> action);
  62.  
  63.     if (Ip -> pre_clear == YES ||
  64.         (Ip -> pre_clear == DEFAULT && DEF_PRECLEAR == YES))
  65.             clear();
  66.  
  67.     move(0, 0);
  68.     refresh();
  69.  
  70.     if (debug)
  71.         put_msg(0, "About to exec: %s", cmd_line);
  72.  
  73.     pre_shell();                /* set up for shell call    */
  74.     retval = system0(cmd_line);    /* make the shell call        */
  75.  
  76.     switch (Ip -> prompt)        /* decide whether to prompt */
  77.     {                            /* or not after the command */
  78.         case NO:                /* explicit no is clear        */
  79.             break;
  80.  
  81.         case DEFAULT:            /* if unspecified, then...    */
  82.  
  83. #if (DEF_PROMPT == NO)            /* if default is NO,        */
  84.                 break;            /* then don't prompt        */
  85. #endif
  86.  
  87. #if (DEF_PROMPT == ON_ERROR)    /* if prompting on errors,    */
  88.             if (!retval)        /* but there wasn't any        */
  89.                 break;            /* error, then don't prompt    */
  90. #endif
  91.                                 /* else fall through to YES */
  92.         case YES:
  93.             puts("\nPress RETURN to continue . . .");
  94.             (Void) getchar();
  95.     }
  96.                                 /* Upon return from shell,    */
  97.     post_shell();                /* restore everything        */
  98. }
  99.  
  100.  
  101. /**************************************************************
  102.  * do_emenu():
  103.  *    Run an external menu specification.
  104.  **************************************************************/
  105.  
  106. int do_emenu(Ip, path)
  107. ITEM *Ip;
  108. char *path;
  109. {
  110.     char filename[MAX_PATH];
  111.     int retval;
  112.     
  113.     if (nestlev == MAX_NEST - 1)
  114.         fatal("Too many nested external menus (increase MAX_NEST)");
  115.  
  116.     strcpy(filename, make_path(path, Ip -> action));
  117.  
  118.     nestlev++;
  119.     retval = do_menu("", filename);
  120.     nestlev--;
  121.  
  122.     return retval;
  123. }
  124.  
  125.  
  126. /************************************************************
  127.  * pre_shell()
  128.  *    Set tty mode for a shell call
  129.  *    DOS only: save drive and path for later restoration
  130.  ************************************************************/
  131.  
  132.  
  133. Void pre_shell()
  134. {
  135.     push_path();
  136.     tty_shell();
  137. }
  138.  
  139.  
  140. /************************************************************
  141.  * post_shell()
  142.  *    Set tty mode for curses
  143.  *    DOS only: restore drive and path from before shell call
  144.  ************************************************************/
  145.  
  146. Void post_shell()
  147. {
  148.     pop_path();
  149.     tty_curses();
  150. }
  151.  
  152.  
  153.