Solved - Need help with PRINT #

General FreeBASIC programming questions.
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Solved - Need help with PRINT #

Postby Quark » Oct 26, 2015 18:29

.
I am having a problem in MS Windows, though not in Linux, in using PRINT #. Here is the test program I'm using to try to understand what is happening:

Code: Select all

'testprintnum.bas
Dim As String lines(1 To 20)

Open cons For Input As #1
For i As Integer = 1 To 20 ' deleted next useless line
  Line Input #1, lines(i) 
Next
Close #1

Open cons For Output As #2
  For i As Integer = 1 To 20
    Print #2, lines(i)
  Next
Close #2


I have a compiled version of the above code processing a chunk of FB code in a file called testme,bas. I am reading 20 lines from that file and outputting (without change) to results.bas. The command-line is: testprintnum <testme.bas> results.bas. But results.bas always has an extra blank line for each line inputted and outputted. And the hex data at each line end is 0D0D0A rather than what it should be.

Any help would be good -- either to verify you get the same result, or better, can explain what is happening. Especially if there is some fix for this.

--Quark
.
Last edited by Quark on Oct 26, 2015 22:44, edited 1 time in total.
fxm
Posts: 9553
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Need help with PRINT #

Postby fxm » Oct 26, 2015 19:16

No problem for me in Windows 7.
Remark: the line "If Eof(1) Then Exit For" is useless in this case of "Open Cons".
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Need help with PRINT #

Postby Quark » Oct 26, 2015 20:30

.
@fxm

Thanks, that helps a bit -- at least there is a version of MS Windows where the problem does not occur (I am using Vista). I did try a couple of recent versions of fbc with the bad result. And, of course, the eof(1) was dumb, just habit. I guess I was hyper-focused on the problem and wanting it to go away so I could complete a project.

While I am eagerly awaiting some good advice, I'll try other things, like re-installing FB. But i don't expect much from that.

--Quark

.
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Re: Need help with PRINT #

Postby phishguy » Oct 26, 2015 20:35

No problem for me in Windows 7.
Remark: the line "If Eof(1) Then Exit For" is useless in this case of "Open Cons".


Actually it's not completely useless. If you enter a control Z it will exit the loop.

Works OK here with Win 7 pro.
fxm
Posts: 9553
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Need help with PRINT #

Postby fxm » Oct 26, 2015 21:31

Yes, because 'Ctrl z' corresponds to the control character 'eof' (end of file).
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Need help with PRINT #

Postby Quark » Oct 26, 2015 22:41

.
Thanks to those who responded.

The problem is solved and in fact it was a pseudo-problem. The blank lines that were driving me crazy were there only because of the viewer I was always using -- Quick View in Free Commander. I relied on something unreliable. So, no problem in the compiler and no problem in MS Windows.

Whew, now I can post my little project and move on.

--Quark
.
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Solved - Need help with PRINT #

Postby dkl » Oct 27, 2015 9:08

To me it looks like a real bug in FB. It's writing \r\r\n line endings but it should just be \r\n. I've seen it happen with the DOS version before, but I didn't know the Win32 version was affected too.
https://sourceforge.net/p/fbc/bugs/786/
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Solved - Need help with PRINT #

Postby Quark » Oct 27, 2015 18:06

.
@dkl

Well, perhaps so. I got so confused during this issue, I no longer trusted my judgment. I wish I understood what i thought I saw.

I just checked your link, and found this:
The same happens on Win32 with Open Cons, at least if redirected to a file:
open cons for output as #1
print #1, "foo"
close #1

This is probably caused by Open Cons using fb_DevFileWrite() -> fwrite() on stdout.

Maybe the rtlib should have a flag on its internal file handles that tells the Print code whether to use \n or \r\n.


Maybe that is the answer. Hope it can be fixed.

--Quark
.
fxm
Posts: 9553
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Solved - Need help with PRINT #

Postby fxm » Oct 27, 2015 18:26

Yes, same behavior with the fbc 32-bit (and Win7 64-bit).
Hexadecimal sequence at end of each line:
&h0D/&h0D/&h0A
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Solved - Need help with PRINT #

Postby Quark » Oct 27, 2015 20:12

.
@fxm

So, your earlier "no problem" meant you were using a version of fbc that happened to work, I guess.

Thanks to you and dkl for looking into this. I never imagined I would stumble on a real bug in the compiler. I will be content to wait a l-o-n-g time for the next one.

--Quark
.
fxm
Posts: 9553
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Solved - Need help with PRINT #

Postby fxm » Oct 27, 2015 20:36

Quark wrote:So, your earlier "no problem" meant you were using a version of fbc that happened to work, I guess.

No (always fbc 32-bit and Win7 64-bit).
But my previous "no problem" was just the result of checking that there was not an additional blank line after each "normal" line, by using only a text editor like notepad (not an hexadecimal editor as now).
Quark
Posts: 474
Joined: May 27, 2011 18:16
Location: Pennsylvania, U.S.
Contact:

Re: Solved - Need help with PRINT #

Postby Quark » Oct 27, 2015 23:23

.
@fxm

Okay, thanks. Any idea of how long a fix might take? I would like to add a note to my SpiffyCodeFB Projects post abput the problem.

--Quark

.

Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests