home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / dosmenu.c < prev    next >
C/C++ Source or Header  |  1991-05-22  |  2KB  |  103 lines

  1. static char helptext[] =
  2.  
  3. " DOSMENU - a menu program for batch files.\n"
  4. "    PARAMETERS:\n"
  5. "         a list of menu choices, separated by spaces.\n"
  6. "         to place a space inside a line, use double quotes\n"
  7. "         optionally, the first parameter may start with a '!'\n"
  8. "         ...in which case it is the menu title.\n"
  9. "    RETURN:\n"
  10. "         DOSMENU sets the errorlevel to the number of the choice, 1,2,3....\n"
  11. "                 or to 0 if user pressed ESCAPE\n"
  12. "    NOTES:\n"
  13. "         remember that test for ERRORLEVEL is EQUAL OR GREATER than value\n"
  14. "    EXAMPLE (in a .BAT file):\n"
  15. "      DOSMENU !select  \"word perfect\"  dbase  lotus\n"
  16. "      if ERRORLEVEL 3 goto :lotus\n"
  17. "      if ERRORLEVEL 2 goto :dbase           ...NOTE tests for 2 or higher\n"
  18. "      if ERRORLEVEL 1 goto :wordpf          ...NOTE tests for 1 or higher\n"
  19. "      goto :quit                            ...ERRORLEVEL=0 means ESCAPE\n"
  20. "      ... follow with labels :lotus  :dbase  :wordpf in .BAT file \n"
  21. "\n"
  22. " copyright David Blum 1987, 1989";
  23.  
  24. /* to compile using TurboC and WTWG window toolkit:
  25.  *        tcc -ms dosmenu.c wts.lib 
  26.  */
  27.  
  28.  
  29. #include <stdlib.h>
  30. #include "wtwg.h"
  31.  
  32.  
  33. /* slide()
  34.  * utility routine. The argv list comes with element 0 pointing to prog name
  35.  * and no terminal NULL.
  36.  *
  37.  * Slide moves all the argv's down 1 and creates a terminal NULL
  38.  * also  it translates underscores to spaces
  39.  */
  40. static void slide ( int n, char **list );
  41.  
  42. static void slide ( int n, char **list )
  43.     {
  44.     char **next;
  45.     while ( --n )
  46.         {
  47.         next = list +1;
  48.         *list = *next;
  49.         list = next;
  50.         }
  51.     *list = NULL;
  52.  
  53.     return;
  54.     }
  55.  
  56.  
  57. main (int argc, char **argv)
  58.     {
  59.     int code;
  60.     char *title;
  61.     char **list;
  62.  
  63.     winit ('T');
  64.  
  65.     if ( argc == 1 || argv[1][0] == '?' )
  66.         {
  67.         wclear();
  68.         wputs (helptext);
  69.         exit (0);
  70.         }
  71.  
  72.     slide (argc, argv);
  73.  
  74.     if ( argv[0][0] == '!' )
  75.         {
  76.         /* first choice is a title
  77.          */
  78.         title = (argv[0])+1;
  79.         list  = argv +1;
  80.         }
  81.     else
  82.         {
  83.         title = NULL;
  84.         list = argv;
  85.         }
  86.  
  87.     code = wpicklist (title, list);
  88.  
  89.     /* the returned code is 0 for first parm, 1 for second, so forth,
  90.      * but if user picked ESCAPE, the returned value points to the NULL
  91.      */
  92.     if ( argv[code] == NULL )
  93.         {
  94.         code = 0;
  95.         }
  96.     else
  97.         {
  98.         ++code;
  99.         }
  100.  
  101.     return (code);
  102.     }
  103. /*------------------------ end of DOSMENU.C -------------------------*/