Sortix volatile manual
This manual documents Sortix volatile, a development build that has not been officially released. You can instead view this document in the latest official manual.
NAME
carray — convert binary file to C arraySYNOPSIS
carray | [-ceEgHrsv] [-G guard] [--identifier=identifier] [--includes=include-statements] [-o output] [-t type] [file ...] |
DESCRIPTION
carray encodes its input as the source code for a C array of hexadecimal constants. The input is the specified file operands concatenated, or the standard input if no input files are specified. carray writes the source code for a C array to the standard output, or output if the -o option is given. The default type is an array of unsigned char. The array contents are indented with tabs and the lines don't exceed 80 columns (tabs have the width of 8 spaces).- -c, --const
- Declare the array with the const keyword.
- -e, --extern
- Declare the array with the extern keyword. This option is mutually incompatible with the -s option.
- -E, --extern-c
- Wrap the array in extern "C" { } subject to a preprocessor check for C++.
- -f, --forward
- Forward declare the array only, do not initialize it with contents. The input files are not opened and the standard input is unused. This option is mutually incompatible with the -r option.
- -g, --use-guard
- Wrap the output in a preprocessor conditional checking the guard macro is not set, and declare the macro if it is not set. This conditional is a classic C include guard that ensures only the first inclusion of a header has any effect.
- -G, --guard guard
- Sets the guard macro to guard and enables the guard macro check as if the -g option was set as well. The guard macro is unrestricted and untransformed and will be output verbatim.
- -H, --headers
- Output inclusions of all the prerequisite headers. By default, there are no prerequisite headers, unless the array type is one of the <stdint.h> types, in which case <stdint.h> is the only prerequisite header.
- --identifier identifier
- Sets the name of the array to identifier. The identifier is unrestricted and will be output verbatim.
- --includes include-statements
- Sets the C preprocessor statements include-statements as how to include all the prerequisite headers and enables inclusion of the prerequisite headers as if the -H option was set. The preprocessor statements are unrestricted and untransformed and will be output verbatim.
- -o, -output output
- Write the output to the output path rather than the standard output.
- -r, --raw
- Output only the hexadecimally encoded array contents, and the guard macro check if set by the -g option. This option is mutually incompatible with the -f option.
- -s, --static
- Declare the array with the static keyword.
- -t, --type type
- Declare the array as an array of the specified type. The type is unrestricted and will be output verbatim.
- -v, --volatile
- Declare the array with the volatile keyword.
- --char
- Declare as array of char.
- --signed-char
- Declare as array of signed char.
- --unsigned-char
- Declare as array of unsigned char.
- --int8_t
- Declare as array of int8_t.
- --uint8_t
- Declare as array of uint8_t.
EXIT STATUS
carray will exit 0 on success and non-zero otherwise.EXAMPLES
$ echo foo | carray unsigned char carray[] = { 0x66, 0x6F, 0x6F, 0x0A, };
$ echo foo | carray -cs -o foo.inc $ cat foo.inc static const unsigned char foo[] = { 0x66, 0x6F, 0x6F, 0x0A, };
$ echo foo | carray -ceEfgH -t uint8_t -o foo.h $ cat foo.h #ifndef FOO_H #define FOO_H #include <stdint.h> #if defined(__cplusplus) extern "C" { #endif extern const uint8_t foo[]; #if defined(__cplusplus) } /* extern "C" */ #endif #endif
$ echo foo | carray -cH -t uint8_t -o foo.c $ cat foo.c #include <stdint.h> const uint8_t foo[] = { 0x66, 0x6F, 0x6F, 0x0A, };
$ echo foo | carray -r 0x66, 0x6F, 0x6F, 0x0A,