Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for forf.cmd

(view source code of forf.cmd as plain text)

  1. /* FORF,  Version 2.04          */
  2. /* Partial FOR /F (NT) "port"   */
  3. /* Written by Rob van der Woude */
  4.  
  5.  
  6. parse arg "#" -1 var +2 in "(" file ")" do commandline
  7. do = translate( strip( do ) )
  8. in = translate( strip( in ) )
  9. if var         =  "%%" then call Syntax
  10. if do          <> "DO" then call Syntax
  11. if in          <> "IN" then call Syntax
  12. if commandline =  ""   then call Syntax
  13. if file        =  ""   then call Syntax
  14. call SysFileTree file, "exist.", "F"
  15. if exist.0 <> 1 then call FileNotFound
  16. parse value commandline with commandstr paramstr
  17.  
  18. line.  = ""
  19. line.0 = 0
  20. call linein file, 1, 0
  21. do i = 1 by 1 until lines( file ) = 0
  22. 	line.i = linein( file, , 1 )
  23. 	line.0 = i
  24. end
  25. call lineout file
  26.  
  27. if paramstr <> "" & line.0 > 0 then do
  28. 	if pos( var, paramstr ) > 0 then call ParseParamStr
  29. end
  30.  
  31. forf_confirm = translate( value( "FORF_CONFIRM", , "OS2ENVIRONMENT" ) )
  32. if line.0 > 0 & forf_confirm <> "NO" then do i = 1 to line.0
  33. 	say right( i, 5, " " )||"  "||commandstr||" "||paramstr.i
  34. end
  35.  
  36. if forf_confirm <> "NO" then do
  37. 	say
  38. 	say "Are you sure you want to execute these commands?"
  39. 	call SysCurState "OFF"
  40. 	answer = translate( SysGetKey( "NOECHO" ) )
  41. 	if answer <> "Y" then EXIT 2
  42. end
  43. do i = 1 to line.0
  44. 	address CMD commandstr||" "||paramstr.i
  45. end
  46. EXIT 0
  47.  
  48.  
  49. FileNotFound:
  50. 	say
  51. 	say "Specified file not found: "||file
  52. 	call Syntax
  53. return
  54.  
  55.  
  56. ParseParamStr: procedure expose line. paramstr paramstr. var
  57. 	do i = 1 to line.0
  58. 		paramstr.i = paramstr
  59. 		do forever
  60. 			varpos = pos( var, paramstr.i )
  61. 			if varpos = 0 then leave
  62. 			leadstr  = substr( paramstr.i, 1, varpos - 1 )
  63. 			trailstr = substr( paramstr.i, varpos +2 )
  64. 			paramstr.i = leadstr||line.i||trailstr
  65. 		end
  66. 	end
  67. return
  68.  
  69.  
  70. Syntax:
  71. 	say
  72. 	say "FORF,  Version 2.04"
  73. 	say "Partial port of Windows NT's FOR /F command"
  74. 	say
  75. 	say "Usage:      FORF #v IN (file) DO command parameters"
  76. 	say
  77. 	say "#v          v may be any character, except %"
  78. 	say "file        ASCII file, read and substituted for %v line by line"
  79. 	say "command     any valid OS/2 command"
  80. 	say "parameters  command's command line parameters; any occurrance of"
  81. 	say "            #v in the parameters string will be replaced with a"
  82. 	say "            directory from filespec"
  83. 	say
  84. 	say "If the environment variable FORF_CONFIRM is set to NO,"
  85. 	say "the program will NOT ask for confirmation."
  86. 	say
  87. 	say "Written by Rob van der Woude"
  88. 	say "http://www.robvanderwoude.com"
  89. 	EXIT 1
  90. return
  91.  
  92.  

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