× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Unix API read()
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Thu, 28 Dec 2000 10:45:46 -0600 (CST)



On Wed, 27 Dec 2000, Richard Jackson wrote:

> Perhaps one of the rocket scientists knows, I don't know.

I have no idea how to take this. :)  I'll provide an example of fgets
(since I disapprove of fscanf) at the bottom of this message.


> 
> -----Original Message-----
> From: owner-rpg400-l@midrange.com [mailto:owner-rpg400-l@midrange.com]On
> Behalf Of Phil Groschwitz
> Sent: Wednesday, December 27, 2000 7:14 PM
> To: RPG400-L@midrange.com
> Subject: RE: Unix API read()
> 
> 
> Richard,
> 
> This looks good.  Can I call this from an rpg pgm?  It
> isn't one of the UNIX-like api's.  The 400 I'm using
> doesn't have a c compiler.  Without that I don't know
> if I can some how prototype it.
> 
> Phil
> 
> 

This is an example of reading a stream file line-by-line with fopen/fgets,
etc.  Hope it helps.

     D fopen           PR              *   ExtProc('_C_IFS_fopen')
     D   path                          *   value
     D   mode                          *   value

     D fgets           PR              *   ExtProc('_C_IFS_fgets')
     D   string                        *   value
     D   size                        10I 0 value
     D   stream                        *   value

     D fclose          PR                  ExtProc('_C_IFS_fclose')
     D   stream                        *   value


     D MyFile          S               *
     D path            S             64A
     D mode            S              5A
     D Msg             S             50A
     D line            S            512A
     D pos             S              3  0


     c                   eval      path = '/QOpenSys/rc.conf' + x'00'
     c                   eval      mode = 'r' + x'00'
     c                   eval      MyFile = fopen(%addr(path): %addr(mode))

     c                   if        MyFile = *NULL
     c                   eval      Msg = 'fopen() failed!'
     c                   dsply                   Msg
     c                   eval      *inlr = *on
     c                   return
     c                   endif

     c                   dow       fgets(%addr(line): 512: MyFile) <> *NULL

     C* cut data off at null
     c     x'00'         scan      line          pos
     c                   if        pos > 1
     c                   eval      line = %subst(line:1:pos-1)
     c                   else
     c                   eval      line = *blanks
     c                   endif

     C* strip LF
     c     x'25'         scan      line          pos
     c                   if        pos > 0
     c                   eval      line = %subst(line:1:pos-1)
     c                   endif

     C* strip CR
     c     x'0D'         scan      line          pos
     c                   if        pos > 0
     c                   eval      line = %subst(line:1:pos-1)
     c                   endif

     C* you probably want to do something a bit more constructive with
     C*  the data than this :)
     c                   eval      msg = line
     c     Msg           dsply

     c                   enddo

     c                   callp     fclose(MyFile)
     c                   eval      *inlr = *on

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.