Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-03

Including binary data making easy

28 messages · 11 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Stratmann

Would this be possible?

// get access to the data of file.dat
// have 1 executable file with containing all the data
{$ir file.dat mydata} // include resource or similar
// fpc compiler makes this
const
 mydata : array[ 0 .. 4 ] of byte =
 ($45,$44,$63,$76,$55); // file data
// the length can find out with sizeof( mydata );

Rainer

Jonas Maebe
to Rainer Stratmann

Rainer Stratmann wrote on ma, 23 mrt 2009:

Show quoted text 11 lines
Would this be possible? // get access to the data of file.dat // have 1 executable file with containing all the data {$ir file.dat mydata} // include resource or similar // fpc compiler makes this const mydata : array[ 0 .. 4 ] of byte = ($45,$44,$63,$76,$55); // file data

FPC includes a data2inc utility that you can use for this.

Jonas

---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.

Michael Van Canneyt
to Rainer Stratmann: Would this be possible? // get access to the data of file.dat // have 1 executable file…
Rainer Stratmann wrote 13 lines
Would this be possible? // get access to the data of file.dat // have 1 executable file with containing all the data {$ir file.dat mydata} // include resource or similar // fpc compiler makes this const mydata : array[ 0 .. 4 ] of byte = ($45,$44,$63,$76,$55); // file data // the length can find out with sizeof( mydata );

There are 2 fpc tools that do this for you.

bin2obj and data2inc

Michael.

Rainer Stratmann
to Michael Van Canneyt
Michael Van Canneyt wrote 18 lines
On Mon, 23 Mar 2009, Rainer Stratmann wrote: > Would this be possible? > > // get access to the data of file.dat > // have 1 executable file with containing all the data > > {$ir file.dat mydata} // include resource or similar > > // fpc compiler makes this > const > mydata : array[ 0 .. 4 ] of byte = > ($45,$44,$63,$76,$55); // file data > > // the length can find out with sizeof( mydata ); There are 2 fpc tools that do this for you. bin2obj and data2inc

Yes, but that means a step more to get the solution. It would be much easier in the way described above. And easy to implement so that all users get advantage of this.

Rainer

Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Michael Van Canneyt
to Rainer Stratmann
Rainer Stratmann wrote 23 lines
Am Montag, 23. März 2009 15:52 schrieb Michael Van Canneyt: > On Mon, 23 Mar 2009, Rainer Stratmann wrote: > > Would this be possible? > > > > // get access to the data of file.dat > > // have 1 executable file with containing all the data > > > > {$ir file.dat mydata} // include resource or similar > > > > // fpc compiler makes this > > const > > mydata : array[ 0 .. 4 ] of byte = > > ($45,$44,$63,$76,$55); // file data > > > > // the length can find out with sizeof( mydata ); > > There are 2 fpc tools that do this for you. > > bin2obj and data2inc Yes, but that means a step more to get the solution. It would be much easier in the way described above. And easy to implement so that all users get advantage of this.

You can use RCData resources, that works on all platforms. Then you need to use LoadResource()

Michael.

Rainer Stratmann
to Michael Van Canneyt
Michael Van Canneyt wrote 27 lines
On Mon, 23 Mar 2009, Rainer Stratmann wrote: > Am Montag, 23. März 2009 15:52 schrieb Michael Van Canneyt: > > On Mon, 23 Mar 2009, Rainer Stratmann wrote: > > > Would this be possible? > > > > > > // get access to the data of file.dat > > > // have 1 executable file with containing all the data > > > > > > {$ir file.dat mydata} // include resource or similar > > > > > > // fpc compiler makes this > > > const > > > mydata : array[ 0 .. 4 ] of byte = > > > ($45,$44,$63,$76,$55); // file data > > > > > > // the length can find out with sizeof( mydata ); > > > > There are 2 fpc tools that do this for you. > > > > bin2obj and data2inc > > Yes, but that means a step more to get the solution. > It would be much easier in the way described above. > And easy to implement so that all users get advantage of this. You can use RCData resources, that works on all platforms. Then you need to use LoadResource()

Yes, this means also - as I understand it - that you have to make an additional step to create the resource file.
For me it looks complicated. If a file's content is change then it can happen that you forget to create the resource file and so on...

Rainer

Michael.
Graeme Geldenhuys
to Rainer Stratmann
Rainer Stratmann wrote 5 lines
Yes, this means also - as I understand it - that you have to make an additional step to create the resource file. For me it looks complicated. If a file's content is change then it can happen that you forget to create the resource file and so on...

Ah, but you are missing the point. We are programmers. We do NOT forget! :-)

I have been using bin2obj for two years now. It works perfectly for me, even though it's a (occasional) two step process. My application changes more than the resource I include.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

John Coppens
to Graeme Geldenhuys
I have been using bin2obj for two years now. It works perfectly for me, even though it's a (occasional) two step process. My application changes more than the resource I include.

... and you can add the conversion into the Makefile, so the conversion happens automatically when the data changes.

John

Marco van de Voort
to John Coppens

In our previous episode, John Coppens said:

Show quoted text 7 lines
> I have been using bin2obj for two years now. It works perfectly for > me, even though it's a (occasional) two step process. My application > changes more than the resource I include. ... and you can add the conversion into the Makefile, so the conversion happens automatically when the data changes.

Which makefile? For own projects I typically don't use any.

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 10 lines
In our previous episode, John Coppens said: > > > I have been using bin2obj for two years now. It works perfectly for > > me, even though it's a (occasional) two step process. My application > > changes more than the resource I include. > > ... and you can add the conversion into the Makefile, so the conversion > happens automatically when the data changes. Which makefile? For own projects I typically don't use any.

In Lazarus, you can create a pre-compile command that does it for you, so you'll never forget.

Michael.

Graeme Geldenhuys
to John Coppens: On Mon, 23 Mar 2009 18:22:15 +0200 ... and you can add the conversion into the Makefile,…
John Coppens wrote
... and you can add the conversion into the Makefile, so the conversion happens automatically when the data changes.

I program for the 21st century. I don't use Makefile's - they are so 80's. :-) Though Lazarus does help out here... you can execute before and after compilation actions. It's all in the Lazarus build dialogs.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Rainer Stratmann
to Michael Van Canneyt: In Lazarus, you can create a pre-compile command that does it for you, so you'll never…
Michael Van Canneyt wrote 13 lines
On Mon, 23 Mar 2009, Marco van de Voort wrote: > In our previous episode, John Coppens said: > > > I have been using bin2obj for two years now. It works perfectly for > > > me, even though it's a (occasional) two step process. My application > > > changes more than the resource I include. > > > > ... and you can add the conversion into the Makefile, so the conversion > > happens automatically when the data changes. > > Which makefile? For own projects I typically don't use any. In Lazarus, you can create a pre-compile command that does it for you, so you'll never forget.

And if you share the source-files with a friend and he compiles it on his computer?

Show quoted text 5 lines
Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Michael Van Canneyt
to Rainer Stratmann
Rainer Stratmann wrote 17 lines
Am Montag, 23. März 2009 18:18 schrieb Michael Van Canneyt: > On Mon, 23 Mar 2009, Marco van de Voort wrote: > > In our previous episode, John Coppens said: > > > > I have been using bin2obj for two years now. It works perfectly for > > > > me, even though it's a (occasional) two step process. My application > > > > changes more than the resource I include. > > > > > > ... and you can add the conversion into the Makefile, so the conversion > > > happens automatically when the data changes. > > > > Which makefile? For own projects I typically don't use any. > > In Lazarus, you can create a pre-compile command that does it for you, so > you'll never forget. And if you share the source-files with a friend and he compiles it on his computer?

The command is in the project's compiler options, and if the binary data file is also on his PC, it will work out of the box.

Michael.

Henry Vermaak
to Marco van de Voort: In our previous episode, John Coppens said: Which makefile? For own projects I typically…

2009/3/23 Marco van de Voort :

Show quoted text 10 lines
In our previous episode, John Coppens said: > > > I have been using bin2obj for two years now. It works perfectly for > > me, even though it's a (occasional) two step process. My application > > changes more than the resource I include. > > ... and you can add the conversion into the Makefile, so the conversion > happens automatically when the data changes. Which makefile? For own projects I typically don't use any.

is there a way to do this with fpmake?

henry

Rainer Stratmann
to Jonas Maebe: Rainer Stratmann wrote on ma, 23 mrt 2009: FPC includes a data2inc utility that you can…
Jonas Maebe wrote 14 lines
Rainer Stratmann wrote on ma, 23 mrt 2009: > Would this be possible? > > // get access to the data of file.dat > // have 1 executable file with containing all the data > > {$ir file.dat mydata} // include resource or similar > > // fpc compiler makes this > const > mydata : array[ 0 .. 4 ] of byte = > ($45,$44,$63,$76,$55); // file data FPC includes a data2inc utility that you can use for this.

http://sourceware.org/binutils/docs/as/Incbin.html#Incbin http://sourceware.org/binutils/docs/as

geneb
to Zaher Dirkey: On Mon, Mar 23, 2009 at 6:22 PM, Graeme Geldenhuys I forgot that! Best Regards Zaher…
Zaher Dirkey wrote 9 lines
On Mon, Mar 23, 2009 at 6:22 PM, Graeme Geldenhuys wrote: > Ah, but you are missing the point. We are programmers. We do NOT forget! > :-) > I forgot that!

No, you mis-remembered it. :)

g.

Proud owner of F-15C 80-0007 http://www.f15sim.com - The only one of its kind. http://www.diy-cockpits.org/coll - Go Collimated or Go Home. Some people collect things for a hobby. Geeks collect hobbies. ScarletDME - The red hot Data Management Environment A Multi-Value database for the masses, not the classes. http://www.scarletdme.org - Get it _today_! Buying desktop hardware and installing a server OS doesn't make a server-class system any more than sitting in a puddle makes you a duck. [Cipher in a.s.r]
Sven Barth
to Rainer Stratmann: http://sourceware.org/binutils/docs/as/Incbin.html#Incbin…
Rainer Stratmann wrote 19 lines
Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe: > Rainer Stratmann wrote on ma, 23 mrt 2009: >> Would this be possible? >> >> // get access to the data of file.dat >> // have 1 executable file with containing all the data >> >> {$ir file.dat mydata} // include resource or similar >> >> // fpc compiler makes this >> const >> mydata : array[ 0 .. 4 ] of byte = >> ($45,$44,$63,$76,$55); // file data > > FPC includes a data2inc utility that you can use for this. http://sourceware.org/binutils/docs/as/Incbin.html#Incbin http://sourceware.org/binutils/docs/as

@Jonas: Is it just me or am I missing some mails here?

Regards,
Sven

Jonas Maebe
to Sven Barth
Sven Barth wrote 22 lines
On 27.08.2012 15:33, Rainer Stratmann wrote: > Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe: >> Rainer Stratmann wrote on ma, 23 mrt 2009: >>> Would this be possible? >>> >>> // get access to the data of file.dat >>> // have 1 executable file with containing all the data >>> >>> {$ir file.dat mydata} // include resource or similar >>> >>> // fpc compiler makes this >>> const >>> mydata : array[ 0 .. 4 ] of byte = >>> ($45,$44,$63,$76,$55); // file data >> >> FPC includes a data2inc utility that you can use for this. > > http://sourceware.org/binutils/docs/as/Incbin.html#Incbin > http://sourceware.org/binutils/docs/as > @Jonas: Is it just me or am I missing some mails here?

It's simply that some people are suddenly replying to mails from 23 March 2009 for some reason.

Jonas

Sven Barth
to Jonas Maebe
Jonas Maebe wrote 27 lines
On 28 Aug 2012, at 09:03, Sven Barth wrote: > On 27.08.2012 15:33, Rainer Stratmann wrote: >> Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe: >>> Rainer Stratmann wrote on ma, 23 mrt 2009: >>>> Would this be possible? >>>> >>>> // get access to the data of file.dat >>>> // have 1 executable file with containing all the data >>>> >>>> {$ir file.dat mydata} // include resource or similar >>>> >>>> // fpc compiler makes this >>>> const >>>> mydata : array[ 0 .. 4 ] of byte = >>>> ($45,$44,$63,$76,$55); // file data >>> >>> FPC includes a data2inc utility that you can use for this. >> >> http://sourceware.org/binutils/docs/as/Incbin.html#Incbin >> http://sourceware.org/binutils/docs/as >> > > @Jonas: Is it just me or am I missing some mails here? It's simply that some people are suddenly replying to mails from 23 March 2009 for some reason.

Ah ha! That explains it. I wasn't a list member back then. :)

(I should have looked at the date of the quote from you...)

Regards,
Sven

Rainer Stratmann
to Sven Barth
Sven Barth wrote 28 lines
On 28.08.2012 09:10, Jonas Maebe wrote: > On 28 Aug 2012, at 09:03, Sven Barth wrote: >> On 27.08.2012 15:33, Rainer Stratmann wrote: >>> Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe: >>>> Rainer Stratmann wrote on ma, 23 mrt 2009: >>>>> Would this be possible? >>>>> >>>>> // get access to the data of file.dat >>>>> // have 1 executable file with containing all the data >>>>> >>>>> {$ir file.dat mydata} // include resource or similar >>>>> >>>>> // fpc compiler makes this >>>>> const >>>>> mydata : array[ 0 .. 4 ] of byte = >>>>> ($45,$44,$63,$76,$55); // file data >>>> >>>> FPC includes a data2inc utility that you can use for this. >>> >>> http://sourceware.org/binutils/docs/as/Incbin.html#Incbin >>> http://sourceware.org/binutils/docs/as >> >> @Jonas: Is it just me or am I missing some mails here? > > It's simply that some people are suddenly replying to mails from 23 March > 2009 for some reason. Ah ha! That explains it. I wasn't a list member back then. :)

It is one of my great ideas to simplify programming. But every time Jonas reflexively look in his arsenal of tools and try to shot me down with them.

(I should have looked at the date of the quote from you...)
Mark Morgan Lloyd
to Rainer Stratmann
Rainer Stratmann wrote 8 lines
>>> On 27.08.2012 15:33, Rainer Stratmann wrote: >>>> Am Monday 23 March 2009 15:51:24 schrieb Jonas Maebe: >>>>> Rainer Stratmann wrote on ma, 23 mrt 2009: >>>>>> Would this be possible? It is one of my great ideas to simplify programming. But every time Jonas reflexively look in his arsenal of tools and try to shot me down with them.

No doubt it is, but that still doesn't give you an excuse to quote a three-year-old thread without enough context to explain why you're trying to do what you're trying to do. And it definitely doesn't give you an excuse to be rude about Jonas, when in actual fact multiple experienced developers had pointed you at a solution.

Looking at the earlier thread, what you appear to be suggesting is some way of using $i for pulling binary data into your program. However, $i is by definition for including source fragments, if you want to merge something that cannot be a valid source fragment (e.g. because it contains illegal characters, or because sequences such as \n\r must be preserved) then it's outside the remit of the compiler and you should be bothering the developers of ld etc. :-)

I fairly regularly ask peculiar questions, for reasons that might make sense to me but not to others. I've generally got the grace to respect core developers' recommendations and to recognise that they've got other things to get on with- including a job to keep them fed and clothed.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Rainer Stratmann
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 6 lines
Looking at the earlier thread, what you appear to be suggesting is some way of using $i for pulling binary data into your program. However, $i is by definition for including source fragments, if you want to merge something that cannot be a valid source fragment (e.g. because it contains illegal characters, or because sequences such as \n\r must be preserved) ...

You are trying to make a very simple thing complicated. I know bytes with values from 0 to 255. I do not see an illegal character/byte there. If you read exactly I did not type $i but $ir which I think is not reserved for another thing.

Mark Morgan Lloyd
to Rainer Stratmann
Rainer Stratmann wrote 12 lines
Am Wednesday 29 August 2012 10:58:52 schrieb Mark Morgan Lloyd: > Looking at the earlier thread, what you appear to be suggesting is some > way of using $i for pulling binary data into your program. However, $i > is by definition for including source fragments, if you want to merge > something that cannot be a valid source fragment (e.g. because it > contains illegal characters, or because sequences such as \n\r must be > preserved) ... You are trying to make a very simple thing complicated. I know bytes with values from 0 to 255. I do not see an illegal character/byte there. If you read exactly I did not type $i but $ir which I think is not reserved for another thing.

Yes, I saw what you wrote. /You're/ the one trying to make life difficult, since you seem to think that it's going to be easier for the core developers to change the compiler (i.e. extend $i or possibly $r) than it is for you to learn how to use a makefile (or to do something equivalent with Lazarus's "Execute before" facility).

Jonas and others have already suggested that you use data2inc or bin2obj. You objected on the basis that you might forget to run it: that's hardly our problem.

I'm not denying that some variant of what you're asking could be useful. For example, in various cases I've needed to build the specification of a scripting language into a program, and having something like your extended $i that ensured that quotes etc. were properly escaped (i.e. the expansion of $i is guaranteed never to break Pascal syntax) could be useful. But in practice there are other ways of doing it.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Rainer Stratmann
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 10 lines
> You are trying to make a very simple thing complicated. > I know bytes with values from 0 to 255. I do not see an illegal > character/byte there. If you read exactly I did not type $i but $ir which > I think is not reserved for another thing. Yes, I saw what you wrote. /You're/ the one trying to make life difficult, since you seem to think that it's going to be easier for the core developers to change the compiler (i.e. extend $i or possibly $r) than it is for you to learn how to use a makefile (or to do something equivalent with Lazarus's "Execute before" facility).

That's the point. For me I would accept some month working if it makes life easier for the rest of my life. The reject of my suggestion is based on the work that comes with it. And not because the other solution with an additional tool (means more work) is better/simpler.

One time longer work against less, but every time work/attention to handle the tools the right way and to collect all the tools and so on...

I really hope that I am not the only one who will benefit from the suggestions I make here.

Mark Morgan Lloyd
to Rainer Stratmann
Rainer Stratmann wrote 13 lines
Am Wednesday 29 August 2012 11:59:01 schrieb Mark Morgan Lloyd: >> You are trying to make a very simple thing complicated. >> I know bytes with values from 0 to 255. I do not see an illegal >> character/byte there. If you read exactly I did not type $i but $ir which >> I think is not reserved for another thing. > Yes, I saw what you wrote. /You're/ the one trying to make life > difficult, since you seem to think that it's going to be easier for the > core developers to change the compiler (i.e. extend $i or possibly $r) > than it is for you to learn how to use a makefile (or to do something > equivalent with Lazarus's "Execute before" facility). That's the point. For me I would accept some month working if it makes life easier for the rest of my life.

Excellent, we're in full agreement! You're going to learn how to use makefiles! :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Rainer Stratmann
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 18 lines
Rainer Stratmann wrote: > Am Wednesday 29 August 2012 11:59:01 schrieb Mark Morgan Lloyd: >>> You are trying to make a very simple thing complicated. >>> I know bytes with values from 0 to 255. I do not see an illegal >>> character/byte there. If you read exactly I did not type $i but $ir >>> which I think is not reserved for another thing. >> >> Yes, I saw what you wrote. /You're/ the one trying to make life >> difficult, since you seem to think that it's going to be easier for the >> core developers to change the compiler (i.e. extend $i or possibly $r) >> than it is for you to learn how to use a makefile (or to do something >> equivalent with Lazarus's "Execute before" facility). > > That's the point. For me I would accept some month working if it makes > life easier for the rest of my life. Excellent, we're in full agreement! You're going to learn how to use makefiles! :-)

You are funny.
Using {$ir file.dat mydata} would be easier, I guess.

Even the assembler supports this kind of making things easy. http://sourceware.org/binutils/docs/as/Incbin.html#Incbin