logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

bin2c — embed data files into C as variables

Description

       bin2c converts files to C variables. It does so by reading the contents of  each  file  supplied  on  the
       argument line and writes out C program code that defines a variable with the file's contents.

       hxtools's bin2c implementation supports:

       •   space-efficient encoding of the arbitrary data

       •   multiple input files

       •   creation of either a standalone .h file, or a .c/.h file pair. (See examples below.)

Examples

       To generate a single C header file that behaves like XPM files and which is suitable for inclusion into a
       C program file of your own:

       bin2c -H images.h foo.png bar.png

       To generate a .c/.h pair instead, the invocation is:

       bin2c -C images.c foo.png bar.png

       This  will  create  a C program file "images.c" containing all the definitions and a "images.h" that your
       code can use to get ahold of the declarations.

History

       hxtools's bin2c developed from the earlier png2wx.pl utility.

Name

       bin2c — embed data files into C as variables

Options

-Cfile
              If specified, causes the variable definition to be emitted to the given filename.

       -Ddir_prefix
              All  filenames  on  the  command  line  will  be  prefixed with the given directory.  This has the
              implication that files will be searched relative to dir_prefix, while the variable name ending  up
              in the C source for an image will remain non-prefixed.

       -Gname
              Request  that an include guard by the identifier guard-name is emitted into the header file. If -C
              was specified and a .c/.h pair is generated, an include guard is always emitted, and the -G option
              can be used to set that name.

       -Hfile
              The file where the variable declarations will be emitted to. If -C was not specified, h-file  will
              not  contain  any header guard by default, and it will contain the variable definition, the latter
              of which will be marked as static (file scope).

       -pnum Strip num leading path components when transforming input paths  to  variable  names.  If  num  is
              negative,  that many trailing path components are retained. If -p is not specified, the default is
              -1.

       -v     Be verbose. Show all the names and filenames that bin2c will write.

       --ultra
              Writeout the raw data as a string literal. As the literal contains a trailing NUL byte,  the  size
              of the array is necessarily also one byte longer than the raw data, which you need to account for.
              (In  C,  it  would be possible to write char x[3] = "ABC", but this leads to an error in C++ where
              x[4] is required.)

       --wxbitmap
              Generate C++ code that generates wxBitmap objects. (Implies Ultra  encoding,  and  deals  with  it
              appropriately, too.)

See Also

hxtools(7)

hxtools                                            2013-09-29                                           bin2c(1)

Syntax

bin2c  [-Cprogram-file]  [-Ddir_prefix]  [-Hheader-file]  [-Gguard-name]  [-pnum] [-v] [--ultra]
       [--wxbitmap] file...

See Also