home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ADDEA.ZIP / ADDEA.CMD next >
OS/2 REXX Batch file  |  1992-03-28  |  4KB  |  101 lines

  1. /*****************************************************************************/
  2. /* ADDEA                Ver 1.0      92/03/25             MIKE at HOUVMSCC   */
  3. /*                                                                           */
  4. /* ADDEA >    for brief help, ADDEA    ANNOUNCE for details.                 */
  5. /*****************************************************************************/
  6. '@Echo off'
  7. Parse Arg addeaparm
  8. addeaparm=strip(addeaparm,'B')
  9. If addeaparm = '?' then Do
  10.    Say ' Routine to add Extended Attribute TYPE to files'
  11.    Say '  Addea [drive:]{path]filename type [/S] [/R]'
  12.    Say '    where:'
  13.    Say '      filename is the name of the file to be modified'
  14.    Say '          This may include wildcards, e.g. *.EXE'
  15.    Say '      Type is the new EA type to be added'
  16.    Say '      /S says to recursively search all subdirectories'
  17.    Say '      /R says to replace any existing types. The default is to'
  18.    Say '           add the new type.'
  19.    exit
  20.    end
  21. If Register('SysFileTree SysSearchPath SysPutEA SysGetEA')>1 then Do
  22.   Say "Error registering REXX Utils"
  23.   Exit
  24.   End
  25. sdopt = ''
  26. repopt = 0
  27. action = 'added'
  28. if addeaparm = ''  then signal tell
  29. if addeaparm = '?' then signal tell
  30. If Pos('/S',Translate(addeaparm),1) > 0 then sdopt = 'S'
  31. If Pos('/R',Translate(addeaparm),1) > 0 then repopt = 1
  32. If repopt then action = "replaced"
  33. parse var addeaparm addeaparm1 '/s' junk
  34. parse var addeaparm1 addeaparm2 '/S' junk
  35. parse var addeaparm2 addeaparm3 '/r' junk
  36. parse var addeaparm3 addeaparm4 '/R' junk
  37. parse var addeaparm4 file newea
  38. /*                                                                           */
  39. /*  Build the list of files                                                  */
  40. /*                                                                           */
  41. rc = SysFileTree(file, sfile, 'FO'||sdopt)
  42. If rc<>0 then Do
  43.     Say 'File error, RC 'rc' ==> 'file
  44.     Exit
  45.     End
  46. If sfile.0=0 then Do
  47.    Say "File "file "not found"
  48.    Exit
  49.    end
  50. Do ifile = 1 to sfile.0
  51.   header = 'DFFF0000'x || d2c(1)  || '00'x
  52.   EAs=''
  53.   If repopt=0 then Do
  54.     Call Getea
  55.     header = 'DFFF0000'x || d2c(oldea.0+1)  || '00'x
  56.     EAs = ''
  57.     do j=1 to oldea.0
  58.        EAs = EAs ||  'FDFF'x || d2c(length(oldea.j)) || '00'x || oldea.j
  59.        end
  60.     end
  61.   Typeinfo = header || EAs ||  'FDFF'x || d2c(length(newea)) || '00'x || newea
  62.   rc = SysPutEA(Sfile.ifile,".TYPE",typeinfo)
  63.   If rc <> 0 then Do
  64.     Say "Error "rc " from SysPutEA for EA " newea " on file "Sfile.ifile
  65.     exit
  66.     end
  67.   Say "TYPE EA "newea action "to file " Sfile.ifile
  68.   end
  69. exit
  70. /*****************************************************************************/
  71. /* Getea                                                                     */
  72. /*                                                                           */
  73. /* Read exiting EAs from the file                                            */
  74. /*****************************************************************************/
  75. Getea: procedure   expose Sfile. oldea.  ifile
  76.  
  77. rc = SysGETEA(Sfile.ifile, ".TYPE", "TYPEINFO")
  78. parse var typeinfo 5 num 6       typeinfo
  79. oldea.0= c2d(num)
  80. do  I = 1 to oldea.0
  81.    parse var typeinfo 'FDFF'x  len  '00'x  typeinfo
  82.    oldea.i = substr(typeinfo,1,c2d(len))
  83.    typeinfo= substr(typeinfo,c2d(len)+1)
  84.    end
  85. Return
  86. /*****************************************************************************/
  87. /* Register required REXXUTIL functions.                                     */
  88. /* RC=0, registered. RC=1 already registered. Other=error.                   */
  89. /*****************************************************************************/
  90. Register: Procedure expose curdir
  91. Parse arg funcs
  92. Do j=1 to words(funcs)
  93.   rc=RxFuncAdd(word(funcs,j),'RexxUtil',word(funcs,j))
  94.   If rc>1 then
  95.     Do
  96.       Say 'Registration of 'word(funcs,j)' failed, RC 'rc
  97.       Leave j
  98.     End
  99. End
  100. Return rc
  101.