(view source code of choice2.cmd as plain text)
/* Rexx replacement for DOS' CHOICE command *//* Version 1.02 for OS/2 *//* Written by Rob van der Woude *//* http://www.robvanderwoude.com *//* Needs Quercus System's RexxLib for timeout function *//* Initialize RexxUtil */if RxFuncQuery( "SysLoadFuncs" ) <> 0 then do
call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
call SysLoadFuncsend/* Parse command line */parse arg commandline
/* /? switch */if commandline = "/?" then call Syntax
if commandline = "?" then call Syntax
/* /S (case sensitive) switch */selectwhen pos( "/S", commandline ) > 0 then case = 1
when pos( "/s", commandline ) > 0 then case = 1
otherwise case = 0
end/* /C (choices) switch */parse value commandline with "/C"options .
if options = "" then do
parse value commandline with "/c"options .
if options = "" then do
options = "YN"
endendif left( options, 1 ) = ":" then do
options = substr( options, 2 )
endif case = 0 then options = translate( options )
/* /T (default/timeout) switch */parse value commandline with "/T"defchoice","timeout .
if timeout = "" then parse value commandline with "/t"defchoice","timeout .
if left( defchoice, 1 ) = ":" then defchoice = substr( defchoice, 2 )
if timeout <> "" then do
if datatype( timeout, "W" ) <> 1 then call Syntax
/* Initialize Quercus System's RexxLib */if RxFuncQuery( "RexxLibRegister" ) <> 0 then do
call RxFuncAdd "RexxLibRegister", "RexxLib", "RexxLibRegister"
call RexxLibRegister end /* Quercus System's RexxLib */if RxFuncQuery( "RexxLibRegister" ) <> 0 then do
defchoice = ""
timeout = ""
endend/* /N (don't display choices) switch */selectwhen pos( "/N", commandline ) > 0 then dispchoices = 0
when pos( "/n", commandline ) > 0 then dispchoices = 0
otherwise dispchoices = 1
end/* /R (redirect) switch */selectwhen pos( "/R", commandline ) > 0 then redirect = 1
when pos( "/r", commandline ) > 0 then redirect = 1
otherwise redirect = 0
end/* Message/prompt */lastslash = lastpos( "/", commandline )
if lastslash > 0 then do
parse value substr( commandline, lastslash ) with "/". message
endelse do
message = ""
end/* Prepare message/prompt */prompt = messageif dispchoices = 1 then prompt = prompt||"? ["||options||"]"
/* Check if vertical scrolling will occur */parse value SysTextScreenSize( ) with rows cols
/* Check where answer should be displayed */parse value SysCurPos( ) with row col
promptlen = length( prompt )
if row > rows - 2 then row = row - 1
/* Display message/prompt */say promptcall SysCurPos row, col + promptlen
call SysCurState "OFF"
valid = 0
do i = 0 by 1 until valid > 0
if i > 0 then call beep 220, 240
/* Simple SysGetKey to retrieve input */ selectwhen redirect = 1 then do
parse pull choice
if case = 0 then do
choice = translate( choice )
endif choice <> "" then do
choice = left( choice, 1 )
end endwhen timeout <> "" then do
choice = ""
do j = 1 to timeout
choice = INKEY( "N", "F" )
if choice <> "" then leave
call SysSleep 1
endif choice = "" then do
choice = defchoice end endotherwise do
choice = SysGetKey( "NOECHO" )
end endif case = 0 then do
choice = translate( choice )
endvalid = pos( choice, options )
endsay choiceEXIT validSyntax: procedure
saysay "CHOICE, Version 1.01 for OS/2"
say "OS/2 replacement for MS-DOS' CHOICE command"
say "Written by Rob van der Woude"
say "http://www.robvanderwoude.com"
saysay "Usage: CHOICE [ /C[:]choices ] [ /N ] [ /R ] [ /S ]"
say " [ /T[:]default,timeout ] [ prompt ]"
saysay "/C[:]choices available keys; default is YN"
say "/N don't display choices and ?"
say "/R use with redirected input"
say "/S case sensitive keys"
say "/T[:]default, timeout chooses default after timeout"
say " (needs Quercus System's RexxLib)"
saysay "Do not combine /R and /T switches"
EXIT 0
returnpage last modified: 2025-10-11; loaded in 0.0091 seconds