Approved: 115439
Message-ID: <002301be7005$356dfaa0$6fc806d0@default>
From: "Bruce Odum" <bodum@magicnet.net>
To: <MIDRANGE-L@midrange.com>
Subject: Re: opendir() in RPG IV
Date: Tue, 16 Mar 1999 18:32:07 -0500
MIME-Version: 1.0
Content-Type: multipart/alternative;
        boundary="----=_NextPart_000_0020_01BE6FDB.4BB49780"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.0810.800
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800

This is a multi-part message in MIME format.

------=_NextPart_000_0020_01BE6FDB.4BB49780
Content-Type: text/plain;
        charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

here is a program that I use to read a directory on the cd and open all =
files in that dir and upload all the data to a out file. Hope this helps


D FileDescr       s             10I 0                                =20
D FileR           s             10I 0                                =20
D RD              s             10I 0                                =20
D RC              s             10I 0                                =20
D RL              s             10I 0                                =20
D QS              s              1  0                                =20
                                                                     =20
 * Pointers Returned by the Read and Open For Directory              =20
D Dir             s               *                                  =20
D Entry           s               *                                  =20
D Nul             s               *   INZ(*NULL)                     =20
                                                                     =20
 * This is a Null character to add to the end of a directory and File=20
D ZeroBin         s              1A   INZ(*ALLX'00')                 =20
D NLZero          s              2A   INZ(X'1500')                   =20
                                                                     =20
 * Directory name and Pointer to Address Location ...                =20
D XSub            s             10  0                   =20
D DirNam          s             50A                     =20
D DirNamZ         s             50A   INZ(' ')          =20
D DirNamP         s               *   INZ(%ADDR(DirNamZ))
                                                        =20
 * File name and pointer to Address Location ...        =20
D FileNam         s             75A                     =20
D FileNamP        s               *   INZ(%ADDR(FileNam))
                                                        =20
 * Buffer for input from Reading of File                =20
D Buf             s           3895                      =20
D BufP            s               *   INZ(%ADDR(BUF))   =20
D BufLen          s             10U 0                   =20
D Bufsub          s             10  0                   =20
                                                        =20
 * Authority and Conversion for file  Used to Open file =20
D O_RDWR          s             10I 0 INZ(4)            =20
                                                        =20

D O_RDONLY        s             10I 0 INZ(1)                 =20
D O_TEXTDATA      s             10I 0 INZ(16777216)          =20
D Oflag           s             10I 0 INZ(0)                 =20
                                                             =20
 * Read_S is how much of the file will be read               =20
D Read_S          s             10U 0 INZ(3811)              =20
                                                             =20
 * Data structure that needs to be used with Directory Read  =20
D DirEnt          Ds                  BASED(Entry)           =20
D D_Reserved                    16A                          =20
D D_fileeno                     10U 0                        =20
D D_fileno                      10U 0                        =20
D D_reclen                      10U 0                        =20
D D_res2                        10U 0                        =20
D D_res3                         6A                          =20
D D_res4                         2A                          =20
D ccsid                         10I 0                        =20
D country_id                     2A                     =20
D language_id                    3A                     =20
D nlsres5                        3A                     =20
D D_namelen                     10U 0                   =20
D D_name                       640A                     =20
D t_asc                          3    overlay(D_name:8) =20
                                                        =20
 * Work Fields                                          =20
D ErrFlag         s              1  0 INZ(0)            =20
D Scn_tst1        s              5U 0                   =20
D Scn_tst2        s              5U 0                   =20
D x               s              4  0                   =20
D T_ani           s             10A                     =20
                                                        =20
D IDir            s             50A                     =20
 * IFSHEAD is the header file for the C API's           =20
                                                              D/copy =
IFSHEAD                                                   =20
                                                                  =
Dperror           PR            10I 0 EXTPROC('perror')                =20
D const                           *   VALUE                            =20
                                                                       =20
Dsprintf          PR            10I 0 EXTPROC('sprintf')               =20
D                                 *   VALUE                            =20
D                                 *   VALUE                            =20
D                               10I 0 VALUE OPTIONS(*NOPASS)           =20
D                                 *   VALUE OPTIONS(*NOPASS)           =20
                                                                       =20
 *  Open Operations                                                    =20
 *  value returned =3D file descriptor 0 (Ok), -1 (Error)                =
=20
                                                                       =20
Dopen             PR            10I 0 EXTPROC('open')                  =20
D                                 *   VALUE                            =20
D                               10I 0 VALUE                            =20
D                               10U 0 VALUE OPTIONS(*NOPASS)           =20

D                               10U 0 VALUE OPTIONS(*NOPASS) =20
                                                             =20
 *  Read Operations                                          =20
 *  value returned =3D number of bytes Read or , -1 (Error)    =20
                                                             =20
Dread             PR            10I 0 EXTPROC('read')        =20
D                               10I 0 VALUE                  =20
D                                 *   VALUE                  =20
D                               10U 0 VALUE                  =20
                                                             =20
 *  Write Operations                                         =20
 *  value returned =3D number of bytes Written or , -1 (Error) =20
                                                             =20
Dwrite            PR            10I 0 EXTPROC('write')       =20
D                               10I 0 VALUE                  =20
D                                 *   VALUE                  =20
D                               10U 0 VALUE
                                                                 =20
 *  Close Operations                                             =20
 *  value returned =3D 0 (Ok) , -1 (Error)                         =20
                                                                 =20
Dclose            PR            10I 0 EXTPROC('close')           =20
D                               10I 0 VALUE                      =20
                                                                 =20
 *  Open Directory Operation                                     =20
 *  value returned =3D file descriptor 0 (Ok) , -1 (Error)         =20
                                                                 =20
Dopendir          PR              *   EXTPROC('opendir')         =20
D                                 *   VALUE                      =20
                                                                 =20
 *  Read Directory Operation                                     =20
 *  value returned =3D file descriptor 0 (Ok) , -1 (Error)         =20
                                                                 =20
Dreaddir          PR              *   EXTPROC('readdir')
D                                 *   VALUE                =20
                                                           =20
 *  Close Directory Operation                              =20
 *  value returned =3D file descriptor 0 (Ok) , -1 (Error)   =20
                                                           =20
Dclosedir         PR            10I 0 EXTPROC('closedir')  =20
D                                 *   VALUE                =20
                                                           =20
 *  Unlinka File from system ... Delete File               =20
 *  value returned =3D file descriptor 0 (Ok) , -1 (Error)   =20
                                                           =20
Dunlink           PR            10I 0 EXTPROC('unlink')    =20
D                                 *   VALUE                =20
                                                                         =
            =20
       *  MainLine                                                     =20
C     *entry        plist                                        =20
C                   parm                    IDir                 =20
C                   eval      DirNam =3D %trimr(IDir)              =20
                                                                 =20
 *  Build directory and open                                     =20
C                   Eval      DirnamZ =3D %Trim(DirNam) + ZeroBin  =20
                                                                 =20
C                   Eval      Dir =3D opendir(DirNamp)             =20
                                                                 =20
C                   If        Dir =3D Nul                          =20
C                   Eval      RC =3D perror(Dir)                   =20
C                   Eval      ErrFlag =3D 1                        =20
C                   Return                                       =20
C                   EndIf                                        =20
C                   DoU       Entry =3D Nul                              =

                                                                      =20
 * Read directory entries and process                                 =20
C                   Eval      Entry =3D readdir(Dir)                     =

 * When no more files to read in directory end program  Sends a Nul   =20
C                   If        Entry =3D Nul                              =

C                   Leave                                             =20
C                   Endif                                             =20
                                                                      =20
C*                  Eval      Scn_tst1 =3D %Scan('.ASC' : D_name)        =

C*                  Eval      Scn_tst2 =3D %Scan('.asc' : D_name)        =

C*                  If        Scn_tst1 > 0 or Scn_tst2 > 0            =20
C                   If        t_asc =3D 'ASC'                            =

 * Build Directory and File name to Open                              =20
C                   Eval      FileNam =3D %Trim(DirNam) + %Trim(D_Name)  =

 * Open file for input                                                =20
 * Set Oflag for read only and convert data                    =20
                                                               =20
C                   Z-Add     O_RDONLY      Oflag              =20
C                   Add       O_TEXTDATA    Oflag              =20
                                                               =20
C                   Eval      FileDescr =3D open(FileNamP: Oflag)=20
                                                               =20
C                   If        FileDescr =3D -1                   =20
C                   Eval      RC =3D perror(FileNamP)            =20
C                   Iter                                       =20
C                   EndIf                                      =20
                                                               =20
 * Read the open file                                          =20
                                                               =20
C                   DoU       FileR <=3D 0 Or                    =20
C                             FileDescr =3D -1                   =20
                                                                C        =
           Eval      FileR =3D read(FileDescr: BufP: Read_S)  =20
                                                                     =20
C                   If        FileDescr =3D -1                         =20
C                   Eval      RC =3D perror(FileNamP)                  =20
C                   Eval      ErrFlag =3D 1                            =20
C                   EndIf                                            =20
                                                                     =20
 * SubString out Records and Write to file                           =20
                                                                     =20
 * I am reading in 3095 bytes each record in the stream file is 205  =20
 * bytes long and end with a carrige return and line feed.  I am     =20
 * removing the carrige return and line feed before writing the      =20
 * record out. Their are 19 records for every 3095 bytes read.       =20
C                   If        ErrFlag <> 1                           =20
C                   Eval      x =3D 1                                  =20
C                   Do        37                                     =20
C                   Eval      smdrec =3D %Subst(Buf:x:99)              =20
C                   Eval      x =3D x + 103                           =20
                                                                    =20
C                   movel     smdrec        T_ani                   =20
C                   testn                   t_ani                21 =20
C                   If        smdrec <> *blanks and *in21           =20
C                   Write     dafsmd                                =20
C                   EndIf                                           =20
C                   EndDo                                           =20
 * EndIf ErrFlag <> 1                                               =20
C                   EndIf                                           =20
 * EndDo Filer <=3D 0                                                 =20
C                   EndDo                                           =20
                                                                    =20
C                   Eval      RL =3D unlink(FileNamP)                 =20
C                   Eval      RC =3D close(FileDescr)                 =20
                                                                    =20
 * End if for IN30 & 31 scan ...                                    =20
C                   Endif                                           =20
 * EndDo for opening and reading neccessary files ...               =20
C                   EndDo                                           =20
                                                                    =20
C                   Eval      RC =3D closedir(Dir)                    =20
C                   Seton                                        LR =20





----- Original Message -----=20
From: Buck Calabro/commsoft <mcalabro@commsoft.net>
To: <midrange-l@midrange.com>
Sent: Tuesday, March 16, 1999 11:09 AM
Subject: opendir() in RPG IV


>Anybody get opendir() to work in RPG IV, or should I use the=20
>Qp0lProcessSubtree API?  It works great in C, but I get errno =3D 3025 =
(not=20
>found) when I try it in RPG IV.  I think it may be a bad mapping for =
the=20
>DIR struct.  I am hampered in using C because of shop standards.
>
>My goal is to be able to read all the file names from an IFS directory, =

>pass them one at a time to another RPG program, then delete them so =
they=20
>don't get re-processed.
>
>Thanks!
>


------=_NextPart_000_0020_01BE6FDB.4BB49780
Content-Type: text/html;
        charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
here is a program that I use to read a = directory=20 on the cd and open all files in that dir and upload all the data to a = out file.=20 Hope this helps
 
 
D FileDescr s 10I 0 = =20
D FileR s 10I 0 = =20
D RD s 10I 0 = =20
D RC s 10I 0 = =20
D RL s 10I 0 =
D=20 QS s 1 0
= =20
* = Pointers=20 Returned by the Read and Open For Directory
D Dir = =20 s *
D Entry = s =20 *
D Nul s = =20 * INZ(*NULL)
= =20
* This is a Null character to add to = the end=20 of a directory and File
D ZeroBin s 1A = INZ(*ALLX'00')=20
D NLZero s 2A INZ(X'1500') = =20
= =20
* Directory name and Pointer to Address Location ... = =20
D XSub s 10 0 = =20
D DirNam s 50A
D = DirNamZ=20 s 50A INZ(' ')
D DirNamP s = =20 * INZ(%ADDR(DirNamZ))
= =20
* File name and pointer to Address Location ... =
D=20 FileNam s 75A
D FileNamP = s =20 * INZ(%ADDR(FileNam))
= =20
* Buffer for input from Reading of File = =20
D Buf s 3895
D BufP = =20 s * INZ(%ADDR(BUF))
D BufLen s = 10U=20 0
D Bufsub s 10 0 = =20

* = Authority=20 and Conversion for file Used to Open file
D O_RDWR s = =20 10I 0 INZ(4)
= =20
 
D O_RDONLY s 10I 0 = INZ(1) =20
D O_TEXTDATA s 10I 0 INZ(16777216) = =20
D Oflag s 10I 0 INZ(0)
= =20
* Read_S is how = much of=20 the file will be read
D Read_S s = 10U 0=20 INZ(3811)
= =20
* Data structure that needs to be used with Directory Read =
D=20 DirEnt Ds BASED(Entry)
D = D_Reserved =20 16A
D D_fileeno = =20 10U 0
D D_fileno 10U 0 = =20
D D_reclen 10U 0 = =20
D D_res2 10U 0
D = D_res3 =20 6A
D D_res4 = =20 2A
D ccsid = 10I 0 =20
D country_id 2A = =20
D language_id 3A
D = nlsres5 =20 3A
D D_namelen = =20 10U 0
D D_name 640A = =20
D t_asc 3 overlay(D_name:8)
= =20
* Work Fields = =20
D ErrFlag s 1 0 = INZ(0) =20
D Scn_tst1 s 5U 0
D = Scn_tst2 s 5U 0
D x = s =20 4 0
D T_ani s = 10A =20
= =20
D IDir s 50A
* = IFSHEAD is=20 the header file for the C API's
= =20 D/copy IFSHEAD = =20
= Dperror =20 PR 10I 0 EXTPROC('perror')
D const = =20 * VALUE
= =20
Dsprintf = PR =20 10I 0 EXTPROC('sprintf')
D = =20 * VALUE
D = *=20 VALUE
D = 10I 0=20 VALUE OPTIONS(*NOPASS)
D = * =20 VALUE OPTIONS(*NOPASS)
= =20
* Open Operations = =20
* value returned =3D file descriptor 0 = (Ok), -1=20 (Error)
= =20
Dopen PR 10I 0 = EXTPROC('open') =20
D * VALUE = =20
D 10I 0 VALUE = =20
D 10U 0 VALUE OPTIONS(*NOPASS) = =20

D 10U = 0 VALUE=20 OPTIONS(*NOPASS)
= =20
* Read Operations =
* =20 value returned =3D number of bytes Read or , -1 (Error)
= =20
Dread PR = =20 10I 0 EXTPROC('read')
D 10I 0 = VALUE =20
D * VALUE = =20
D 10U 0 VALUE
= =20
* Write = Operations =20
* value returned =3D number of = bytes=20 Written or , -1 (Error)
= =20
Dwrite PR 10I 0 EXTPROC('write') = =20
D 10I 0 VALUE
D = =20 * VALUE
D = =20 10U 0 VALUE
= =20
* Close Operations = =20
* value returned =3D 0 (Ok) , -1 (Error) =
=20 =
Dclose =20 PR 10I 0 EXTPROC('close')
D = =20 10I 0 VALUE
= =20
* Open Directory Operation = =20
* value returned =3D file descriptor 0 (Ok) , = -1 (Error) =20
= =20
Dopendir PR * EXTPROC('opendir') =
D =20 * VALUE
= =20
* Read Directory = Operation=20
* value returned =3D file = descriptor 0=20 (Ok) , -1 (Error)
= =20
Dreaddir PR * =20 EXTPROC('readdir')
D * = VALUE =20
=
* =20 Close Directory Operation
* value = returned =3D=20 file descriptor 0 (Ok) , -1 (Error)
= =20
Dclosedir PR 10I 0=20 EXTPROC('closedir')
D * VALUE = =20
=
* =20 Unlinka File from system ... Delete File
* value = returned =3D=20 file descriptor 0 (Ok) , -1 (Error)
= =20
Dunlink PR 10I 0=20 EXTPROC('unlink')
D * VALUE = =20
= =20 =
=20 * MainLine = =20
C *entry plist = =20
C parm IDir = =20
C eval DirNam =3D %trimr(IDir) =
=20
* Build = directory and open
C = =20 Eval DirnamZ =3D %Trim(DirNam) + ZeroBin
= =20
C Eval Dir = =3D=20 opendir(DirNamp)
= =20
C If Dir =3D Nul = =20
C Eval RC =3D perror(Dir) = =20
C Eval ErrFlag =3D 1 =
C =20 Return
C = =20 EndIf
C DoU Entry =3D = Nul =20
= =20
* Read directory entries and process = =20
C Eval Entry =3D readdir(Dir) = =20
* When no more files to read in directory end program Sends a = Nul =20
C If Entry =3D Nul =
C=20 Leave =
C =20 Endif
= =20
C* = =20 Eval Scn_tst1 =3D %Scan('.ASC' : D_name)
C* = Eval =20 Scn_tst2 =3D %Scan('.asc' : D_name)
C* = If =20 Scn_tst1 > 0 or Scn_tst2 > 0
C = If =20 t_asc =3D 'ASC'
* Build Directory and = File name to=20 Open
C Eval = FileNam =3D=20 %Trim(DirNam) + %Trim(D_Name)
* Open file for input = =20
* Set Oflag for read only and convert = data =20
= =20
C Z-Add O_RDONLY Oflag =
C =20 Add O_TEXTDATA Oflag
= =20
C Eval = =20 FileDescr =3D open(FileNamP: Oflag)
= =20
C If FileDescr =3D -1 = =20
C Eval RC =3D perror(FileNamP) = =20
C Iter =
C =20 EndIf
= =20
* Read the open file = =20
= =20
C DoU FileR <=3D 0 Or = =20
C FileDescr =3D -1 =
=20 C = =20 Eval FileR =3D read(FileDescr: BufP: Read_S)
= =20
C If = =20 FileDescr =3D -1
C Eval = RC =3D=20 perror(FileNamP)
C Eval = ErrFlag =3D 1=20
C EndIf = =20
= =20
* SubString out Records and Write to file = =20
= =20
* I am reading in 3095 bytes each record in the stream file is 205 =
*=20 bytes long and end with a carrige return and line feed. I am
= *=20 removing the carrige return and line feed before writing the
= * record=20 out. Their are 19 records for every 3095 bytes read.
C = =20 If ErrFlag <> 1
C = =20 Eval x =3D 1
C = Do =20 37
C = Eval =20 smdrec =3D %Subst(Buf:x:99)
C Eval x =3D x + = 103 =20
= =20
C movel smdrec T_ani = =20
C testn t_ani = 21
C=20 If smdrec <> *blanks and *in21 =
C =20 Write dafsmd
C = =20 EndIf
C = =20 EndDo
* EndIf ErrFlag = <> 1=20
C = EndIf =20
* EndDo Filer <=3D 0 = =20
C EndDo = =20
= =20
C Eval RL =3D = unlink(FileNamP) =20
C Eval RC =3D close(FileDescr) = =20
=
=20 * End if for IN30 & 31 scan ... =20
C Endif = =20
* EndDo for opening and reading neccessary files = ... =20
C EndDo = =20
=
C=20 Eval RC =3D closedir(Dir) =
C =20 Seton LR
 
 
 
 
 
----- Original Message -----
From: Buck Calabro/commsoft <mcalabro@commsoft.net>
To: <midrange-l@midrange.com>
Sent: Tuesday, March 16, 1999 11:09=20 AM
Subject: opendir() in RPG = IV

>Anybody get opendir() to work in RPG IV, or = should I use=20 the
>Qp0lProcessSubtree API?  It works great in C, but I get = errno =3D=20 3025 (not
>found) when I try it in RPG IV.  I think it may = be a bad=20 mapping for the
>DIR struct.  I am hampered in using C = because of=20 shop standards.
>
>My goal is to be able to read all the = file names=20 from an IFS directory,
>pass them one at a time to another RPG = program,=20 then delete them so they
>don't get=20 re-processed.
>
>Thanks!
>


------=_NextPart_000_0020_01BE6FDB.4BB49780--



This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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 [javascript protected email address].