home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXXEA.ZIP / EASAMP.CMD < prev    next >
OS/2 REXX Batch file  |  1992-11-16  |  3KB  |  98 lines

  1. /*      Copyright Ammonoosuc Technology Inc., 1992   */
  2.  
  3. /*
  4.         This command file is furnished as an indicative sample of
  5.         the use of some the Extended Attribute REXX functions. It
  6.         is NOT meant to viewed as a serious application.
  7. */
  8.  
  9. do while (1 = 1)
  10.    say 'Enter an existing file or subdirectory name'
  11.    pull fname rest
  12.    if length(fname) <> 0 then leave
  13. end /* do */
  14. do while (1 = 1)
  15.    say 'Is this a file or a subdirectory? Enter F or D.'
  16.    pull fdir rest
  17.    if ((length(fdir) <> 0) & ((substr(fdir,1,1) = 'F') | (substr(fdir,1,1) = 'D'))) then leave
  18. end /* do */
  19. fdir = substr(fdir,1,1)
  20. if (fdir = 'F') then do
  21.    pathname = stream(fname,'c','query exists')
  22.    if length(pathname) = 0 then do
  23.       say 'File' fname 'does not exist.'
  24.       exit
  25.    end  /* Do */
  26. end  /* Do */
  27. else pathname = fname
  28. call RxFuncAdd 'EAType', 'RexxEA', 'EAType'
  29. call RxFuncAdd 'ASCIIEA', 'RexxEA', 'ASCIIEA'
  30. call RxFuncAdd 'PutEA', 'RexxEA', 'PutEA'
  31. call RxFuncAdd 'FetchEA', 'RexxEA', 'FetchEA'
  32. call RxFuncAdd 'DeleteEA', 'RexxEA', 'DeleteEA'
  33. data = 'This extended attribute created on' date('L') 'at' time('C')
  34. /* the next statement works only if the length of the data string is < 256.
  35.    note the swapping of bytes within words.  */
  36. EAdata = 'fdff'x || d2c(length(data)) || '00'x || data
  37. rcode = PutEA(pathname,'REXXEA.TEST',EAdata)
  38. if length(rcode) <> 0 then do
  39.    say 'Error message from PutEA is' rcode
  40.    exit
  41. end  /* Do */
  42. say 'Extended Attribute with name REXXEA.TEST and ASCII type created.'
  43. say 'Associated data is:' || data
  44. rcode = FetchEA(pathname,EAnames,EAstrings)
  45. if length(rcode) <> 0 then do
  46.    say 'Error message from FetchEA is' rcode
  47.    exit
  48. end  /* Do */
  49. if EAnames.0 = 0 then do
  50.    say 'Error. After calling PutEA, FetchEA returned a count of 0'
  51.    exit
  52. end  /* Do */
  53. index = 0
  54. do i = 1 to EAnames.0
  55.    if EAnames.i = 'REXXEA.TEST' then do
  56.       index = i
  57.       leave
  58.    end  /* Do */
  59. end /* do */
  60. if index = 0 then do
  61.    say 'Error. FetchEA did not return the name of a previously stored EA.'
  62.    exit
  63. end  /* Do */
  64. say 'FetchEA returned an Extended Attribute with name REXXEA.TEST'
  65. type = EAType(EAstrings.index)
  66. parse var type err errmsg
  67. if err = 'Error:' then do
  68.    say 'EAType returned error message:' errmsg
  69.    exit
  70. end  /* Do */
  71. if type <> 'ASCII' then do
  72.    say 'EAType did not return ASCII type. Instead, returned' type
  73.    exit
  74. end  /* Do */
  75. say 'EAType correctly reported Extended Attribute as ASCII type.'
  76. datastring = ASCIIEA(EAstrings.index)
  77. parse var datastring err errmsg
  78. if err = 'Error:' then do
  79.    say 'ASCIIEA returned error message' errmsg
  80.    exit
  81. end  /* Do */
  82. if (datastring <> data) then do
  83.    say 'ASCIIEA did not extract the associated data correctly'
  84. end  /* Do */
  85. say 'ASCIIEA correctly extracted the associated data'
  86. call DeleteEA pathname, 'REXXEA.TEST'
  87. if length(RESULT) <> 0 then do
  88.    say 'DeleteEA returned error message' RESULT
  89.    exit
  90. end  /* Do */
  91. say 'DeleteEA properly deleted Extended Attribute'
  92. call RxFuncDrop 'EAType'
  93. call RxFuncDrop 'ASCIIEA'
  94. call RxFuncDrop 'PutEA'
  95. call RxFuncDrop 'FetchEA'
  96. call RxFuncDrop 'DeleteEA'
  97. exit
  98.