README file for b2c version 2.2 Copyright (c) 1991-2000 Joerg Heitkoetter. All rights reserved. USER COMMANDS B2C(1) NAME b2c - a binary to C file converter SYNOPSIS b2c [-hvCHO] [-c #columns] [-i identifier] [-t type] [-o file] [-D sizemacro] [-G guardmacro] file(s) DESCRIPTION b2c is a tool for generating C source chunks or C header files from binaries. b2c automagically generates complete C header files which can directly be included using the C pre- processors's #include directive. (See the APPLICATION sec- tion below.) By default b2c encodes it's output into hex- adecimal constants, which can be changed if (See the follow- ing OPTIONS section.) OPTIONS b2c recognizes the following options: -C Use decimal encoding of output constants. -H Use hexadecimal encoding of output constants. -O Use octal encoding of output constants. -c #columns The output routine's column counter (8 by default) is set to the number specified. Negative numbers are treated as No-Ops. -h Produce a valid C header file, ready for inclusion. (See also the -G option.) -i identifier Overwrite the output's routine default identifier foo with identifier. (Should be a valid C identifier.) -o file The output is redirected to file, instead of the default stdout. -t type Overwrite the output's routine default type definition unsigned char with type. (Should be a valid C type.) -v Prints the version number and a copyright note on stderr. -D sizemacro Overwrite the output's routine default `size' macro FOOSIZ with sizemacro. (Should be a valid C pre-pro- cessor macro name.) Version 2.2 Last change: January 2000 1 USER COMMANDS B2C(1) -G guardmacro Overwrite the output's routine default `guardian' macro _foo_h_ with guardmacro. (Should be a valid C pre-pro- cessor macro name.) Specifying `-G' implies option `-h'. OPTION SUMMARY To give no option at all is the same as to give the options -H -c 8 -D FOOSIZ -i foo -t 'unsigned char' EXAMPLE Hence the following binary file `foobar' containing the 9 bytes: \001 - \011. Now type: b2c -h foobar which produces the following output: /* foobar */ #ifndef _foo_h_ #define _foo_h_ unsigned char foo [] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; #define FOOSIZ ((sizeof(foo)/sizeof(unsigned char)) #endif /* _foo_h_ */ In more general terms: /* */ #ifndef #define [] = { }; #define ((sizeof()/sizeof()) #endif /* */ APPLICATION Step 1. Convert one of your favourite audio files into a C definition, e.g. laughter.au b2c -i laughter -D LAUGHSIZ -G _laugh_h_ -o laughter.h Version 2.2 Last change: January 2000 2 USER COMMANDS B2C(1) Step 2. Write a simple application program like: #include #include "laughter.h" FILE* audio; if ((audio = fopen ("/dev/audio", "w")) != NULL) { fwrite (laughter, LAUGHSIZ, 1, audio); fclose (audio); } Step 3. Enjoy! SEE ALSO btoa(1), atob(1), mtools(1). The GNU recode manual. AUTHOR Copyright (c) 1991-2000 Joerg Heitkoetter. All rights reserved. Send bugs, comments, and all the fish to CREDITS Thanks for thoughtful comments from David W. Sanderson (dws@ssec.wisc.edu), who made me believe that `-CDH options' would be nice. And Fran,cois Pinard (pinard@iro.umon- treal.ca) for his comments on `spurious trailing blanks' in previous releases of b2c. Look at his GNU recode utility for more ideas on how to use b2c. AVAILABILITY b2c has been posted to alt.sources and should be available from your local alt.sources news archive. It is also avail- able on the web via http://gnu.de.uu.net/b2c which is virtu- ally the same as http://surf.de.uu.net/gnuland/b2c This work is protected by the terms of the GNU General Pub- lic License. Please refer to the COPYING file accompanying the sources of this software package for a lengthy, boring but, absolute complete description. FINAL NOTE The author used b2c (back in 1991) to convert disk boot sec- tors from diverse DOS versions to write formatter programs. E.g. an MSDOS formatter for an ATARI ST, that alloweed him to circumvent the Kermit-bottleneck, using mtools(1); which made exchanging data between theses systems `a doodle'. (Yeah, this really used to be a problem those days!) Version 2.2 Last change: January 2000 3