Source code all on one line (no CRLF?)

New to FreeBASIC? Post your questions here.
nobozoz
Posts: 238
Joined: Nov 17, 2005 6:24
Location: Chino Hills, CA, USA

Source code all on one line (no CRLF?)

Postby nobozoz » Dec 01, 2010 19:59

I just tried to open a .BAS file in FBEDIT and when the file loaded, there was only one extremely long line of text - no CRLF termination I guess?

Is this a an FBEDIT problem?
A Linux format vs Windows format problem?
Something else?

Can this be fixed (by automation)?

Thanx-
rdc
Posts: 1713
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Re: Source code all on one line (no CRLF?)

Postby rdc » Dec 01, 2010 20:24

nobozoz wrote:A Linux format vs Windows format problem?


This is probably the case. You can open it in another program like PSPad and save it as DOS/Windows. This is what I normally do.
MOD
Posts: 554
Joined: Jun 11, 2009 20:15

Postby MOD » Dec 01, 2010 20:40

Code: Select all

'CRLF

#Define CRLF Chr(13, 10)
#Define CR 13
#Define LF 10

Declare Function main (argc As Integer, argv As ZString Ptr Ptr ) As Integer

End main(__FB_ARGC__, __FB_ARGV__)

Function main (argc As Integer, argv As ZString Ptr Ptr ) As Integer
        If argc < 2 Then
                Print "Not supported."
        Else
                Dim As String file, ret
                Dim As Integer FF
                Dim As UByte temp
                Dim As Integer direct
               
               For j As Integer = 1 To argc - 1
                file = *argv[j]
                Print "File: " & file
                FF = FreeFile
                Open file For Binary As #FF
                        For i As Integer = 1 To Lof(FF)
                                Get #FF, , temp
                               
                                If temp = CR Then
                                        'CRLF->LF
                                        direct = 1
                                ElseIf temp = LF Then
                                        'LF->CRLF
                                        If Right(ret, 1) <> Chr(CR) And direct = 0 Then
                                                ret &= CRLF
                                        Else
                                                ret &= Chr(temp)
                                        EndIf
                                Else
                                        ret &= Chr(temp)
                                EndIf
                        Next
                Close #FF
               
                Print "Saving..."
                FF = FreeFile
                Open file For Output As #FF
                        Print #FF, ret
                Close #FF
                ret = ""
                direct = 0
               Next
        EndIf
       
        Print "Done."
        Return 0
End Function


Compile it without any compiler switches, drag&drop your file at the icon and done.

This program converts CRLFs to LF and LF to CRLF, depending on what the file uses before converting.
Last edited by MOD on Jun 01, 2011 14:36, edited 1 time in total.
TJF
Posts: 3434
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Postby TJF » Dec 01, 2010 20:56

Use Geany IDE ...
nobozoz
Posts: 238
Joined: Nov 17, 2005 6:24
Location: Chino Hills, CA, USA

Postby nobozoz » Dec 01, 2010 22:02

Thank you, all.

rdc - you are correct! Unix format. I have text editors: Textpad and Notepad++. Both can do the conversion from Unix to PC format for me - though too many mouse clicks.

TJF - I will look into Geany.

MOD - An fb solution that is simple, direct and effective. Works a treat! Drag,drop, done!
TJF
Posts: 3434
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Postby TJF » Dec 02, 2010 6:34

@MOD:

I had a look at your tool. Some questions:
    What about write protected files?
    What about files with mixed line ends (sometimes LF, sometimes CRLF: ie the original GTK headers include such files)?
MOD
Posts: 554
Joined: Jun 11, 2009 20:15

Postby MOD » Dec 02, 2010 19:30

Sorry TJF, it is a solution-in-5min-program. I haven't made any thoughts about protected or mixed files and I won't think about it. If you need it, be free to use my code as you want...WTFPL ftw^^
TJF
Posts: 3434
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Postby TJF » Dec 03, 2010 6:44

MOD wrote:If you need it, be free to use my code as you want...WTFPL ftw^^

Thank you! But: I'm Geany user, I needn't think about tools like this :)

BTW: I like quick-and-dirty tools, closing any gap -- not perfect but helping a lot. Unfortunately it allways raises some problems if these tools are published without communicating their limits.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 0 guests