home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
prgramer
/
rexx
/
rexxea
/
easamp.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1992-11-16
|
3KB
|
98 lines
/* Copyright Ammonoosuc Technology Inc., 1992 */
/*
This command file is furnished as an indicative sample of
the use of some the Extended Attribute REXX functions. It
is NOT meant to viewed as a serious application.
*/
do while (1 = 1)
say 'Enter an existing file or subdirectory name'
pull fname rest
if length(fname) <> 0 then leave
end /* do */
do while (1 = 1)
say 'Is this a file or a subdirectory? Enter F or D.'
pull fdir rest
if ((length(fdir) <> 0) & ((substr(fdir,1,1) = 'F') | (substr(fdir,1,1) = 'D'))) then leave
end /* do */
fdir = substr(fdir,1,1)
if (fdir = 'F') then do
pathname = stream(fname,'c','query exists')
if length(pathname) = 0 then do
say 'File' fname 'does not exist.'
exit
end /* Do */
end /* Do */
else pathname = fname
call RxFuncAdd 'EAType', 'RexxEA', 'EAType'
call RxFuncAdd 'ASCIIEA', 'RexxEA', 'ASCIIEA'
call RxFuncAdd 'PutEA', 'RexxEA', 'PutEA'
call RxFuncAdd 'FetchEA', 'RexxEA', 'FetchEA'
call RxFuncAdd 'DeleteEA', 'RexxEA', 'DeleteEA'
data = 'This extended attribute created on' date('L') 'at' time('C')
/* the next statement works only if the length of the data string is < 256.
note the swapping of bytes within words. */
EAdata = 'fdff'x || d2c(length(data)) || '00'x || data
rcode = PutEA(pathname,'REXXEA.TEST',EAdata)
if length(rcode) <> 0 then do
say 'Error message from PutEA is' rcode
exit
end /* Do */
say 'Extended Attribute with name REXXEA.TEST and ASCII type created.'
say 'Associated data is:' || data
rcode = FetchEA(pathname,EAnames,EAstrings)
if length(rcode) <> 0 then do
say 'Error message from FetchEA is' rcode
exit
end /* Do */
if EAnames.0 = 0 then do
say 'Error. After calling PutEA, FetchEA returned a count of 0'
exit
end /* Do */
index = 0
do i = 1 to EAnames.0
if EAnames.i = 'REXXEA.TEST' then do
index = i
leave
end /* Do */
end /* do */
if index = 0 then do
say 'Error. FetchEA did not return the name of a previously stored EA.'
exit
end /* Do */
say 'FetchEA returned an Extended Attribute with name REXXEA.TEST'
type = EAType(EAstrings.index)
parse var type err errmsg
if err = 'Error:' then do
say 'EAType returned error message:' errmsg
exit
end /* Do */
if type <> 'ASCII' then do
say 'EAType did not return ASCII type. Instead, returned' type
exit
end /* Do */
say 'EAType correctly reported Extended Attribute as ASCII type.'
datastring = ASCIIEA(EAstrings.index)
parse var datastring err errmsg
if err = 'Error:' then do
say 'ASCIIEA returned error message' errmsg
exit
end /* Do */
if (datastring <> data) then do
say 'ASCIIEA did not extract the associated data correctly'
end /* Do */
say 'ASCIIEA correctly extracted the associated data'
call DeleteEA pathname, 'REXXEA.TEST'
if length(RESULT) <> 0 then do
say 'DeleteEA returned error message' RESULT
exit
end /* Do */
say 'DeleteEA properly deleted Extended Attribute'
call RxFuncDrop 'EAType'
call RxFuncDrop 'ASCIIEA'
call RxFuncDrop 'PutEA'
call RxFuncDrop 'FetchEA'
call RxFuncDrop 'DeleteEA'
exit