BLOB2C(1)

NAME
blob2c - Create C source and header files from a binary file

SYNOPSIS

blob2c blobfile > output.c 2> output.h

DESCRIPTION

blob2c prints a C source file to standard output, containing an unsigned char array, initialized to the contents of blobfile, and an int, initialized to the length of blobfile in bytes.

The name of the array is based on the input filename, with non-alphanumeric characters replaced by underscores. The name of the int is the array name, plus the string _len.

Also, a header file containing a pair of extern declarations is printed to standard error output. This header may be included multiple times in the same translation unit, since it contains "guard" preprocessor code to prevent multiple declarations.

blob2c takes no options, and requires exactly one argument (the input filename blobfile).

Exit status is zero for success and non-zero for failure. Error messages are printed to standard error output as preprocessor #error directives, since standard error is expected to be redirected to a header file. The #error directives will cause the error messages to be printed when the header file is compiled.

Although it's distributed with the author's Atari 8-bit utilities, there's nothing Atari-specific about blob2c. It could be useful for any situation where you need to include a file's contents as an array in a C program.

EXAMPLE

$ echo "Hello, World." > hello.bin
$ blob2c hello.bin >hello.c 2>hello.h
## check exit status (0=success)
$ echo $?
0
$ cat hello.h
/* C header created by blob2c from input file hello.bin */
#ifndef hello_bin_H
#define hello_bin_H
extern unsigned char hello_bin[];
extern int hello_bin_len;
#endif  /* hello_bin_H */
$ cat hello.c
/* C source created by blob2c from input file hello.bin */
unsigned char hello_bin[] = {
        /*      0 */  0x48,0x65,0x6c,0x6c,0x6f,0x2c,0x20,0x57, /* Hello, W */
        /*      8 */  0x6f,0x72,0x6c,0x64,0x2e,0x0a            /* orld.. */
}; /* hello_bin */
int hello_bin_len = 14;

COPYRIGHT

WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

AUTHOR

B.  Watson <urchlay@slackware.uk>; Urchlay on irc.libera.chat ##atari.

SEE ALSO

a8cat(1), a8eol(1), a8xd(1), atr2xfd(1), atrsize(1), axe(1), bas2aplus(1), blob2c(1), blob2xex(1), cart2xex(1), cxrefbas(1), dasm2atasm(1), diffbas(1), dumpbas(1), f2toxex(1), fenders(1), listbas(1), listamsb(1), protbas(1), renumbas(1), rom2cart(1), unmac65(1), unprotbas(1), vxrefbas(1), whichbas(1), xex1to2(1), xexamine(1), xexcat(1), xexsplit(1), xfd2atr(1), xex(5), atascii(7), fauxtari(7).

Any good Atari 8-bit book: De Re Atari, The Atari BASIC Reference Manual, the OS Users' Guide, Mapping the Atari, etc.