(view source code of forf.cmd as plain text)
/* FORF, Version 2.04 */
/* Partial FOR /F (NT) "port" */
/* Written by Rob van der Woude */
parse arg "#" -1 var +2 in "(" file ")" do commandline
do = translate( strip( do ) )
in = translate( strip( in ) )
if var = "%%" then call Syntax
if do <> "DO" then call Syntax
if in <> "IN" then call Syntax
if commandline = "" then call Syntax
if file = "" then call Syntax
call SysFileTree file, "exist.", "F"
if exist.0 <> 1 then call FileNotFound
parse value commandline with commandstr paramstr
line. = ""
line.0 = 0
call linein file, 1, 0
do i = 1 by 1 until lines( file ) = 0
line.i = linein( file, , 1 )
line.0 = i
end
call lineout file
if paramstr <> "" & line.0 > 0 then do
if pos( var, paramstr ) > 0 then call ParseParamStr
end
forf_confirm = translate( value( "FORF_CONFIRM", , "OS2ENVIRONMENT" ) )
if line.0 > 0 & forf_confirm <> "NO" then do i = 1 to line.0
say right( i, 5, " " )||" "||commandstr||" "||paramstr.i
end
if forf_confirm <> "NO" then do
say
say "Are you sure you want to execute these commands?"
call SysCurState "OFF"
answer = translate( SysGetKey( "NOECHO" ) )
if answer <> "Y" then EXIT 2
end
do i = 1 to line.0
address CMD commandstr||" "||paramstr.i
end
EXIT 0
FileNotFound:
say
say "Specified file not found: "||file
call Syntax
return
ParseParamStr: procedure expose line. paramstr paramstr. var
do i = 1 to line.0
paramstr.i = paramstr
do forever
varpos = pos( var, paramstr.i )
if varpos = 0 then leave
leadstr = substr( paramstr.i, 1, varpos - 1 )
trailstr = substr( paramstr.i, varpos +2 )
paramstr.i = leadstr||line.i||trailstr
end
end
return
Syntax:
say
say "FORF, Version 2.04"
say "Partial port of Windows NT's FOR /F command"
say
say "Usage: FORF #v IN (file) DO command parameters"
say
say "#v v may be any character, except %"
say "file ASCII file, read and substituted for %v line by line"
say "command any valid OS/2 command"
say "parameters command's command line parameters; any occurrance of"
say " #v in the parameters string will be replaced with a"
say " directory from filespec"
say
say "If the environment variable FORF_CONFIRM is set to NO,"
say "the program will NOT ask for confirmation."
say
say "Written by Rob van der Woude"
say "http://www.robvanderwoude.com"
EXIT 1
return
page last modified: 2024-04-16; loaded in 0.0088 seconds