.. RST source for blob2c(1) man page. Convert with:
..   rst2man.py blob2c.rst > blob2c.1
.. rst2man.py comes from the SBo development/docutils package.

======
blob2c
======

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

.. include:: manhdr.rst

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;

.. include:: manftr.rst
