I trying to create a list of objects in an IFS directory. This weekly job
will copy all the files to an archive directory and delete the original.
The DIR command created by Peter Connell has been utilized as the guts for
my basic framework. It works, but I don't understand reasoning for the
various functions it uses.
The readdir() uses the following prototype:
Dreaddir PR * EXTPROC('readdir')
D * VALUE
The final results of the readdir() end up in this data structure...
D DirEntry DS
D d_reserved1 16A
D d_fileno_genid 10U 0
D d_fileno 10U 0
D d_reclen 10U 0
D d_reserved3 10I 0
D d_reserved4 6A
D d_reserved5 2A
D d_ccsid 10I 0
D d_country_id 2A
D d_language_id 3A
D d_nls_reserved 3A
D d_namelen 10U 0
D d_name 640A
..... and these are the other pointers and structures needed....
D ReturnDir S *
D PtrToEntry S *
D RtnEntry S BASED(PtrToEntry)
The data is retrieve through the following code and the object name ends up
C Eval PtrToEntry = readdir(ReturnDir)
C If PtrToEntry <> *Null
C Eval DirEntry = RtnEntry
C Eval EntryName = %str(%addr(d_name))
Everything works fine. My problem is I don't understand what
%str(%addr(d_name)) is doing and why it is needed.
Walking through the program in debug, I noticed that d_name has a value. I
changed the code to the "easier on the eyes" version which is simply taking
a 256 char field and truncating it in a 120 char field.
C Eval EntryName = d_name
Unfortunately, everything isn't working now. If the current object name is
smaller (fewer characters) than the previous object's name, the excess
characters are left in d_name and are transferred to EntryName.
For instance, if BIGBIGBIGFILENAME.xls is the first object and
"SMALLNAME.xls" is the next object, the value of d_name will be
"SMALLNAME.xls ME.xls" The last 6 characters of the previous name are
still in the field. In testing I've found that the value of d_name always
contains the actual object name plus two blank characters. If the previous
name was longer than that, it is still visible.
What I don't understand is why doesn't %str(%addr(d_name)) pick up the full
value (i see it in Debug), but a simple assignment does?
I've found a work around to be:
C Eval EntryName = %SubSt(d_name:1:d_namelen)
d_namelen is the actual length of the name field being passed back. So
assuming anything else is trash, it can be ignored. Only this doesn't
answer what %str & %addr is doing.
This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact