ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Reading IFS-Files without ending CR and LF with Scott Clements IFS API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading IFS-Files without ending CR and LF with Scott Clements IFS API

    Hi,

    I found out, that the last line of a file is not processed with the readline-Procedure of Scott Clements IFS API, when the last line has no CR and/or no LF at the end.
    Unfortunately I have to deal with such files, that I receive via Webservice.

    I changed readline from
    Code:
         c                   if        rdlen < 1
         c                   return    -1
         c                   endif
    to
    Code:
         c                   if        rdlen < 1
         c                   if        len > 0
         c                   return    len
         c                   else
         c                   return    -1
         c                   endif
         c                   endif
    Could I get a problem with this change?


    Note: I'm still not possible to answer to posts. So please don't be mad or disappointed if you ask a question and I don't answer you.

  • #2
    Originally posted by ottersberg View Post
    Hi,

    I found out, that the last line of a file is not processed with the readline-Procedure of Scott Clements IFS API, when the last line has no CR and/or no LF at the end.
    Unfortunately I have to deal with such files, that I receive via Webservice..
    Ottersberg,

    I find it difficult to understand how an IFS file (if that is what you are referring to)... does not have some form of CRLF or other EOF kind of character involved. Scott Klement's readline() routine has worked for me reliably for every IFS file that I have used over some many years that I've had the occasion to include his readline() routine.

    Maybe your problem comes from a documentation error from many years ago, where the hexidecimal EOF was represented by X'15' and mistakenly documented as X'25'... so therefore IBM left both definitions of EOF working as equals, as to the end of the IFS stream file and they changed the OS and documentation to cover that.

    It seems unusual for me to believe that there is an IFS type of file that does not have some form of EOF indicator that is not a standard character across several platforms... especially where readline() is involved.

    Best Regards,
    Fred Williams

    Comment


    • Whitecat27
      Whitecat27 commented
      Editing a comment
      After writing and reading my post here... some questions come to mind.

      Have you modified the original readline() code from it's original form?
      Does your file that you're reading come from some kind of "non-standard" source?
      Does the transfer of your original file, somehow not transfer the EOF character(s)?

      Maybe there is something like these questions are happening within your file transferring process to the AS400... I personally can't tell how the EOF characters are being left off of your desired result.

      Fred Williams

  • #3
    The readline() routine from my old IFS tutorial was meant purely as an example to help you learn how to work with stream files. It was never meant to be used in a production program (it does not read data in file blocks, and therefore is very inefficient.) It was designed to read a file until the newline character (sometimes called "LF" or "linefeed") is encountered. It was not designed to do anything else, and I never claimed that it would fit other needs besides that.

    Again: It was to help you learn, so you'll be able to write your own routines that do what you need to do.

    Unfortunately, I was new to writing public documentation when I wrote that. I never thought people would just take it and use it without understanding it, or being willing to write their own. I learned my lesson on that a long time ago, but there's no way to go back in time and undo the things that have already been published.

    Comment


    • #4
      Uh oh. We have several production programs that have used readline() for years.

      Comment

      Working...
      X