Announcement

Collapse
No announcement yet.

File ended with 0A instead of 0D 0A

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

  • File ended with 0A instead of 0D 0A

    I have problems with files ended with the hexadecimal code 0A.

    How do I get files ended with the code 0D 0A with powerbasic 3.5

    regards,

    Jan

    ------------------

  • #2
    I'm not exactly sure what the question is but you might EOF(x).
    Code:
    open "somefile.txt" for input as #1
    do until eof(1)
    ...process
    ...process
    loop
    close #1
    I'm pretty sure PB/DOS will process up to the physical end of
    the file.


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Open for INPUT, LINE INPUT will not work with these files.

      You have to open the file in BINARY or RANDOM mode and parse up to the delimiter (x'0A') yourself.

      (This behavior was carried into the Windows compilers, so same rules apply there).

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        That means it is a Unix file. Unix files end with linefeeds (lf CHR$(10)), whereas DOS files end with a carriage return and a linefeed (crlf CHR$(13) CHR$(10)).

        Typically people get Unix files through FTP and FTP can be set to do the conversion during the transfer by typing ASCII at the FTP> prompt. That is by far the easiest way to get the file so that it has crlf's.

        It is kind of surprising that I wasn't able to find a conversion program in the PB forums, but maybe someone else can. What I used to do was to use a modified version of BUFIN.BAS. BUFIN.BAS can be found here:
        http://www.ethanwiner.com/WINER.ZIP

        [This message has been edited by John Hackl (edited March 20, 2004).]

        Comment


        • #5

          this works for me...

          thanks for advice.


          clean:
          open "tmp" for output as #1
          open file$ for binary as #2
          while not eof(2)
          get$ #2, 192, c$
          a$ = a$ + c$
          q$ = a$ : gosub cleanhead : a$ = q$
          again:
          p = instr(a$,chr$(10))
          if p > 0 and p <= len(a$) then
          q$ = left$(a$,p-1)
          gosub cleanhead
          gosub cleantail
          if len(q$) > 0 then print #1, q$
          a$ = mid$(a$,p+1, len(a$)-p)
          goto again
          end if
          wend
          close 2
          close 1
          shell "copy tmp "+file$+">nul
          kill "tmp"
          ?"oke file "+file$+" cleaned


          ------------------

          Comment


          • #6
            sorry I forgot something.

            cleanhead:
            while left$(q$,1) = chr$(13) or left$(q$,1) = chr$(10) or left$(q$,1) = chr$(26) or left$(q$,1) = chr$(0)
            q$ = mid$(q$,2,len(q$)-1)
            wend
            return

            cleantail:
            while right$(q$,1) = chr$(13) or right$(q$,1) = chr$(10) or right$(q$,1) = chr$(32) or right$(q$,1) = chr$(26) or left$(q$,1) = chr$(0)
            q$ = left$(q$,len(q$)-1)
            wend
            return


            ------------------

            Comment


            • #7
              >It is kind of surprising that I wasn't able to find a conversion program in the PB forums

              If you can find a suitable Win program here (and you can), and get someone to compile it for you, no reason your MS-DOS program can't..

              Code:
                 SHELL "lf2crlf " & myfile$
              MCM


              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                LF2CRLF is part of the PB/CC samples, which you can find here:

                http://www.powerbasic.com/files/pub/demos/

                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment


                • #9
                  >LF2CRLF is part of the PB/CC samples, which you can find here:

                  As written, fails if file is CRLF delimited. Uses:
                  Code:
                  REPLACE $LF WITH $CRLF IN sText
                  So if your file is CRLF-delimited (PC), it ends up CRCRLF delimited.

                  Can change easily enough...
                  Code:
                  REPLACE $CRLF WITH LF IN sText   ' change PC-delimited to Unix Delimted
                                                   ' does nothing if file not PC-delimited
                  REPLACE $LF WITH $CRLF IN sText
                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    I expect you want
                    Code:
                    REPLACE $CRLF WITH [b]$[/b]LF IN sText
                    there.

                    It's true, LF2CRLF was not intended to convert CR/LF files to CR/LF files.
                    For that, use the COPY command.

                    ------------------
                    Tom Hanlin
                    PowerBASIC Staff

                    Comment


                    • #11
                      What I meant (with typo corrected on $LF) was, a using program could SHELL the LF2CRLF program without knowing or caring how it's delimited: because what comes back is <U>always</U> CRLF-delimited.

                      i.e., no need to check the delimiters at all.

                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment

                      Working...
                      X