Skip to main content
guest
Join | Help | Sign In
Liberty BASIC Community Wiki Home
guest| Join | Help | Sign In
Liberty BASIC Community Wiki
  • Wiki Home
  • Recent Changes
  • Pages and Files
  • Members
  • Home
    • Liberty BASIC FAQ
    • Contests
    • Tutorials
    • Science
    • Shared Code
    • Tips
    • DLLs
    • PublicDomainSprites
    • Member Pages
    • Links
    • Sandbox

WhatsMyLine

Edit 0 1 …
  • 0 Tags
    • No tags
  • Notify
  • RSS
  • Backlinks
  • Source
  • Print
  • Export (PDF)
Older Version Newer Version

harmonv harmonv Mar 1, 2008 - "Initial article -- WhatsMyLine -- for Sharefest 2008"

 ' 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 2008
Function 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$)>40000 then 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)
select case winner
case winEnds : ender$ = chr$(13)+chr$(10) ' Windows or DOS
case nixEnds : ender$ = chr$(10) ' HTML, Linux or Mac OSX
case macEnds : ender$ = chr$(13) ' Mac OS 9 or earlier
case else : ender$ = "" ' random file or one-line ASCII file
end select
WhatsMyLineType$ = ender$
End Function ' WhatsMyLineType

' count the number of times search$ occurs in source$
Function HowMany(source$, search$)
n = 0 : pos = 0
do
pos = instr(source$, search$, pos+1)
if pos>0 then n = n + 1
loop until pos=0
HowMany = n
End Function ' HowMany
Help · About · Pricing · Privacy · Terms · Support · Upgrade
Contributions to https://basic.wikispaces.com/ are licensed under a Creative Commons Attribution Share-Alike 2.5 License. Creative Commons Attribution Share-Alike 2.5 License
Portions not contributed by visitors are Copyright 2018 Tangient LLC
TES: The largest network of teachers in the world
Turn off "Getting Started"
  1. Home
  2. ...
Loading...