Page 1 of 1

Including text files with IncludeBinary (Problems)

Posted: Fri Mar 05, 2004 3:44 pm
by Karbon
I'm including several text files into my EXE via the IncludeBinary command.

The problem occurs when I want to access the text I do peeks(?label_name) but that spits *everything* that was included in the DataSection using IncludeBinary after the text file - including other text, binary icon data, RTF data etc. Should I just not do that, or access that data in another way?

Thanks!

Posted: Fri Mar 05, 2004 3:52 pm
by freak
Well, the problem here is, that PeekS() only stops at a NULL character, not
CRLF, which marks the end of a line in a text file.
(ReadString() does stop at both.)
There is no NULL in the file, even not at the end, so it never stopps reading.

You could put a "Data.b 0" directly after the includebinary command. This
would make PeekS() stop there. But still gives you the whole file, not
just a line.

If you want a single line, you'll have to parse that string yourself i guess.

Timo

Re: Including text files with IncludeBinary (Problems)

Posted: Fri Mar 05, 2004 3:53 pm
by tinman
Well the files will be included but you won't have null terminators on them. You'll need to have something like:

DataSection
text1:
IncludeBinary "my_text_file"
Data.b 0
text2:
IncludeBinary "blahblah"
Data.b 0
EndDataSection

Posted: Fri Mar 05, 2004 3:54 pm
by Karbon
Yea, I wanted the whole file. Excellent guys, thank you!

Posted: Fri Mar 05, 2004 3:54 pm
by Paul
Did you try adding a ?label_end flag in your includebinary data so you can specify where PeekS() should stop reading?

Notice the syntax for PeekS() ...
Text$ = PeekS(*MemoryBuffer [, Length])


so try this maybe...
Text$ = PeekS(?Label_Start,?Label_End-?Label_Start)

DataSection
?Label_Start:IncludeBinary "Textfile.txt"
?Label_End
EndDataSection

Posted: Tue Jun 22, 2004 6:44 am
by blueznl
you probably already solved it, but it might be usefull to someone else...

Code: Select all

Procedure.s x_peeks(addr.l,terminator.s,l.l)
  Protected p.l, string.s,terminator_l.l
  Global x_peeks_read.l
  ;
  ; *** read a string from memory until terminating condition is met
  ;
  ;
  ; in:     addr.l         - location in memory
  ;         terminator.s   - seperator, if you're looking for zeroes use regular peeks()
  ;         l.l            - max length
  ; retval:                - string found
  ; out:    x_peeks_read.l - nr. of bytes read from memory
  ;
  ; notes:
  ;
  ; - x_peeks_read does not have To be equal To Length of string found
  ; - terminating condition can be string, a null character, or a maximal length
  ;
  terminator_l = Len(terminator)
  p = 0
  string = ""
  If l > 0 And terminator_l > 0
    Repeat
      string = string+Chr(PeekB(addr+p) & $FF)
      p = p+1
    Until Right(string,terminator_l) = terminator Or p=l Or PeekB(addr+p)=0
    If Right(string, terminator_l) = terminator
      string = x_chop(string,0,terminator_l)
    EndIf
  EndIf
  x_peeks_read = p
  ProcedureReturn string
EndProcedure