Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for pmchoice.bat

(view source code of pmchoice.bat as plain text)

  1. @ECHO OFF
  2.  
  3. :: Keep variables local:
  4. SETLOCAL
  5.  
  6. :: Check if help was asked:
  7. IF [%1]==[/?] GOTO Syntax
  8.  
  9. :: Set default values:
  10. SET Choices=YN
  11. SET Cs=0
  12. SET Default=
  13. SET Error=0
  14. SET NoPrompt=0
  15. SET Text=
  16. SET TimeOut=0
  17. SET Type=
  18.  
  19. :: Parse command line:
  20. FOR %%A IN (%*) DO CALL :Parse %%A
  21.  
  22. :: Remove leading space from text prompt:
  23. IF "%Text%"==" " SET Text=
  24. IF "%Text%"=="" GOTO ErrCheck
  25. IF "%Text:~0,1%"==" " SET Text=%Text:~1%
  26.  
  27. :: Stop if an error occured:
  28. :ErrCheck
  29. IF NOT [%Error%]==[0] GOTO Syntax
  30.  
  31. :: Call the Kix helper script:
  32. KIX32.EXE "%~dpn0.kix" $Choices=%CHOICES% $Cs=%Cs% $Default=%Default% $NoPrompt=%NoPrompt% $Text="%Text%" $TimeOut=%TimeOut%
  33.  
  34. :: Show help if KiXtart version is too old:
  35. IF %ERRORLEVEL% GEQ 250 GOTO Syntax
  36.  
  37. :: Return the appropriate errorlevel:
  38. EXIT %ERRORLEVEL%
  39. GOTO End
  40.  
  41. :Syntax
  42. ECHO.
  43. ECHO PMCHOICE.BAT, Version 2.00 for Windows NT / 2000 / XP
  44. ECHO Poor Man's replacement for the CHOICE command
  45. ECHO Helper batch file for PMCHOICE.KIX, Version 2.00
  46. ECHO.
  47. ECHO Usage:  [CALL]  PMCHOICE  [/C[:]choices]  [/N]  [/S]  [/T[:]c,nn]  [text]
  48. ECHO.
  49. ECHO Where:  /C[:]choices Specifies allowable keys. Default is YN.
  50. ECHO         /N           Do not display choices and ? at end of prompt string.
  51. ECHO         /S           Treat choice keys as case sensitive.
  52. ECHO         /T[:]c,nn    Default choice to c after nn seconds or on pressing Enter.
  53. ECHO         text         Prompt string to display.
  54. ECHO.
  55. ECHO Result: ERRORLEVEL is set to offset of key user presses in choices.
  56. ECHO.
  57. ECHO Note:   Requires KiXtart 4.01 or later.
  58. ECHO.
  59. ECHO Written by Rob van der Woude
  60. ECHO http://www.robvanderwoude.com
  61.  
  62. :End
  63. ENDLOCAL
  64. GOTO:EOF
  65.  
  66.  
  67. :Parse
  68. :: Parse the command line one word at a time:
  69. SET Param=%1
  70. IF /I [%Type%]==[/T] (
  71. 	SET TimeOut=%Param%
  72. 	SET Type=
  73. 	GOTO:EOF
  74. )
  75. SET Type=%Param:~0,2%
  76. IF /I NOT [%Type%]==[/C] IF /I NOT [%Type%]==[/N] IF /I NOT [%Type%]==[/S] IF /I NOT [%Type%]==[/T] (
  77. 	SET Text=%Text% %Param%
  78. 	GOTO:EOF
  79. )
  80. IF /I [%Type%]==[/S] (
  81. 	SET Cs=1
  82. 	GOTO:EOF
  83. )
  84. IF /I [%Type%]==[/N] (
  85. 	SET NoPrompt=1
  86. 	GOTO:EOF
  87. )
  88. SET Param=%Param:~2%
  89. IF [%Param:~0,1%]==[:] SET Param=%Param:~1%
  90. IF /I [%Type%]==[/C] (
  91. 	SET Choices=%Param%
  92. 	GOTO:EOF
  93. )
  94. IF /I [%Type%]==[/T] SET Default=%Param%
  95. IF /I [%Type%]==[/T] (
  96. 	ECHO.%Choices% | FIND /I "%Default%" >NUL
  97. 	IF ERRORLEVEL 1 SET Error=1
  98. )
  99. GOTO:EOF
  100.  

page last modified: 2024-04-16; loaded in 0.0098 seconds