/* rexx */

arg patch source destin

if (destin='') then
   do
     call Help
     exit 0
   end

if RxFuncQuery("VPatchFile") then
   do
     rc = RxFuncAdd("VPatchFile","vpatchrx","VPatchFile")
     if rc<>0 then
     do
       say '[1;31mFailed to load vpatchrx.dll! ('rc')[0;37m'
       exit 100
     end
   end

rc = VPatchFile(patch,source,destin)

select
   when rc=0 then
   do
     err=""
     say 
     say '[1;32mFile [1;37m'destin'[1;32m was created successfully[0;37m'
     say 
   end
   when rc=1 then
     err="Patch error"
   when rc=2 then
     err="Patch file corrupted"
   when rc=3 then
     err="Source file does not match"
   when rc=4 then
     err="Source file is up to date"
   when rc=5 then
     err="Unable to open patch file"
   when rc=6 then
     err="Unable to open source file"
   when rc=7 then
     err="Unable to create destination file"
otherwise   
  err="Uncknown!"
end

if err<>'' then
   do
     say
     say '[1;31mError: 'err'[0;37m'
     say
   end

if RxFuncQuery("VPatchFile")=0 then
   do
     call RxFuncDrop "VPatchFile"
   end
exit rc

Help:
   say
   say '[1;32mThis command file apply patch to source file and write result'
   say 'into destination.[1;37m'
   say
   say 'vpatch <patch_name> <source_name> <destination_file>[0;37m'
   say ''
return
