Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for ford.cmd

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

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

page last modified: 2024-02-26; loaded in 0.0276 seconds