Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Embedding binary data in C code

2005-06-11 by Don Ingram

Hi All,

Stumbled across this very simple but nonetheless neat tool when I should 
have been working ;-)

File lives at http://www.azillionmonkeys.com/qed/metac.zip

It allows you to create arrays of binary or text data in a C source file.

The tool looks for a tag in the source and then inserts the external 
file data from that point.

Useful for tables of constants or for regionalising display strings.

Just call metac on a .c file & pipe the output to a new file, the name 
of the file to be inserted is in the source file.

The output from metac.exe /? is shown below.

-- 
Cheers

Don




METAC: A program for inlining binary data into C
written by Paul Hsieh

         Metac will take a C-like file, simply output the file's
         contents to standard out until it reads an inline file
         token.  Such tokens appear with the syntax:

             @filename

         So, for example, if you wanted to include a string that you
         have authored as an ordinary text file into your C code you
         could simply write:

             char Msg1[] = {@readme.txt};

         then filtering through metac, the @readme.txt contents are
         injected inline between the quotes as standard C syntax
         chars, replacing the occurrence of @readme.txt.

         The idea was inspired by Window's resources which were in
         turn inspired by people who would arbitrarily tack data on
         the ends of their executables.  Clearly this idea is more
         general and easier on the programmer.  But it has the
         disadvantage or necessarily including the inlined data in
         memory during execution.

         KNOWN BUGS:

         Intrudes on otherwise legal uses of the @ symbol.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.