' Code to recognize file endings. Windows/DOS, Linux/HTML/Mac OSX, or Max OS9 (and earlier)' Written in Liberty BASIC by Harmon V.' Released as public domain, Jan 2008Function WhatsMyLineType$(path$, file$)' open file, read entire file into a string variable, close file
open path$+file$ for input as #fin
text$ =input$(#fin, lof(#fin))
close #fin
if len(text$)>40000then text$ =left$(text$, 40000)' 40K ought to be enough. :-)' count number of CRs,LFs and pairs.
winEnds = HowMany(text$, chr$(13)+chr$(10))
nixEnds = HowMany(text$, chr$(10))- winEnds
macEnds = HowMany(text$, chr$(13))- winEnds
' max number determines filetype
winner = Max(winEnds,macEnds)
winner = Max(winner, nixEnds)selectcase winner
case winEnds : ender$ =chr$(13)+chr$(10)' Windows or DOScase nixEnds : ender$ =chr$(10)' HTML, Linux or Mac OSXcase macEnds : ender$ =chr$(13)' Mac OS 9 or earliercaseelse : ender$ =""' random file or one-line ASCII fileendselect
WhatsMyLineType$ = ender$
EndFunction' WhatsMyLineType' count the number of times search$ occurs in source$Function HowMany(source$, search$)
n =0 : pos =0do
pos =instr(source$, search$, pos+1)if pos>0then n = n +1loop until pos=0
HowMany = n
EndFunction' HowMany