home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / GETUKEY.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-31  |  2KB  |  46 lines

  1. @echo OFF
  2. REM *************************************************************************
  3. REM *** GetUKey.cmd - Batch file using CEnvi to display a prompt and user ***
  4. REM *** ver.1         choices and then set the UKEY environment variable  ***
  5. REM ***               to what was chosen.                                 ***
  6. REM *************************************************************************
  7. CALL CEnviSet.cmd %0.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
  8. GOTO CENVI_EXIT
  9.  
  10. main(argc,argv)
  11. {
  12.    if (argc < 2) {
  13.       // no arguments were given, and so show how to use
  14.       Instructions();
  15.    } else {
  16.       // everything up to the last argument is the prompt
  17.       for ( KeyArg = 1; KeyArg < (argc-1); KeyArg++ )
  18.          printf("%s ",argv[KeyArg])
  19.       KeyList = strupr(argv[KeyArg])
  20.       // flush keyboard
  21.       while kbhit() getch();
  22.       // read until one of the keys from KeyList is pressed
  23.       while ( 0==(key=toupper(getch()))  ||  NULL == strchr(KeyList,key) )
  24.          printf("\a")   // beep because an invalid key was pressed
  25.       printf("%c\n",key)
  26.       // save this key as short environment string UKEY
  27.       (UKEY = "*")[0] = key
  28.    }
  29. }
  30.  
  31. Instructions()
  32. {
  33.    printf("\a\n")
  34.    printf("GetUKey.cmd - Display a prompt and get key from user input.  The\n")
  35.    printf("              environment variable UKEY will be set to the key selected\n")
  36.    printf("\n")
  37.    printf("USAGE: GetUKey.cmd [Prompt] <KeyList>\n")
  38.    printf("Where:\n")
  39.    printf("   Prompt  - Text to display before prompting for character\n")
  40.    printf("   KeyList - A string with the characters that will be accepted\n")
  41.    printf("\n")
  42.    printf("Example: GetUKey.cmd \"Copy File, Delete it, or Quit? (C/D/Q)\" CDQ\n")
  43. }
  44.  
  45. :CENVI_EXIT
  46.