CatchFile for Ascii included file

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

CatchFile for Ascii included file

Post by flaith »

hi

i had a large text file to include to a project (must be included inside the executable). The only way was to make a little code to read the file, export it as a pb file (with datasection, Data.s ...) and put it inside my project.

maybe that way will be better :wink:

Code: Select all

#file_open_inside = 0

Global NewList liste_txt.s()

Filename$ = CatchFile(?Txt_File,#PB_Ascii)

If ReadFile(#file_open_inside,Filename$)
  While Eof(#file_open_inside) = 0
    AddElement(list_txt())
      list_txt() = ReadString(#file_open_inside)
  Wend
Else
  MessageRequester("Information","Impossible d'ouvrir le fichier!")
EndIf

End

DataSection

  Txt_File: IncludeAscii "liste_file.txt"
EndDataSection
Thanks :D
Last edited by flaith on Sat Nov 22, 2008 2:58 pm, edited 1 time in total.
“Fear is a reaction. Courage is a decision.” - WC
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Why IncludeBinary doesn't do the job here ?
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Post by flaith »

Hey Fred, thanks for answering :D
Why IncludeBinary doesn't do the job here ?
well, yes it does, but my aim is to use the 970 lines of words inside the text file :?
So, you're right, the request is not for "IncludeAscii" but for a "CatchFile(file$,type.l)" instead
“Fear is a reaction. Courage is a decision.” - WC
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

PeekS() should do easily the trick.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Post by flaith »

djes wrote:PeekS() should do easily the trick.
I know, but doing a PeekS(?included_file, ?end-?included_file) gives a var containing 970 lines of text i need to explode to an array of string :?
“Fear is a reaction. Courage is a decision.” - WC
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

You need to make a simple data format in this case: 4bytelen,nbytestring
Make a small tool that does this, then simply use includebinary.
The included datafile will have the len infront of each string so it's easy to calculate where the next start.

Alternatively include a text file, build this data at startup and parse for end of line.

In both cases the best is to put the date into a dim array of strings, or a dim array of pointers to the data.

There is no "easy" way to do this. Just search the forum, I think there should be a handfull of example code for something similar to the last case.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Post by flaith »

Thanks for your answers
Rescator wrote:There is no "easy" way to do this
That's why i'm making a wish to Santa fred :D
“Fear is a reaction. Courage is a decision.” - WC
Post Reply