xref: /freebsd/usr.bin/file2c/file2c.1 (revision d37eb51047221dc3322b34db1038ff3aa533883f)
1.\"----------------------------------------------------------------------------
2.\" "THE BEER-WARE LICENSE" (Revision 42):
3.\" <phk@FreeBSD.org> wrote this file.  As long as you retain this notice, you
4.\" can do whatever you want with this file. If we meet some day, and you think
5.\" this stuff is worth it, you can buy me a beer in return.  Poul-Henning Kamp
6.\" ---------------------------------------------------------------------------
7.\"
8.Dd March 22, 2007
9.Dt FILE2C 1
10.Os
11.Sh NAME
12.Nm file2c
13.Nd convert file to c-source
14.Sh SYNOPSIS
15.Nm
16.Op Fl sx
17.Op Fl n Ar count
18.Op Ar prefix Op Ar suffix
19.Sh DESCRIPTION
20The
21.Nm
22utility reads a file from stdin and writes it to stdout, converting each
23byte to its decimal or hexadecimal representation on the fly.
24The byte values are separated by a comma.
25This also means that the last byte value is not followed by a comma.
26By default the byte values are printed in decimal, but when the
27.Fl x
28option is given, the values will be printed in hexadecimal.
29When
30.Fl s
31option is given, each line is printed with a leading tab and each comma is
32followed by a space except for the last one on the line.
33.Pp
34If more than 70 characters are printed on the same line, that line is
35ended and the output continues on the next line.
36With the
37.Fl n
38option this can be made to happen after the specified number of
39byte values have been printed.
40The length of the line will not be considered anymore.
41To have all the byte values printed on the same line, give the
42.Fl n
43option a negative number.
44.Pp
45A prefix and suffix strings can be printed before and after the byte values
46(resp.)
47If a suffix is to be printed, a prefix must also be specified.
48The first non-option word is the prefix, which may optionally be followed
49by a word that is to be used as the suffix.
50.Pp
51This program is typically used to embed binary files into C source files.
52The prefix is used to define an array type and the suffix is used to end
53the C statement.
54The
55.Fl n , s
56and
57.Fl x
58options are useful when the binary data represents a bitmap and the output
59needs to remain readable and/or editable.
60Fonts, for example, are a good example of this.
61.Sh EXAMPLES
62The command:
63.Bd -literal -offset indent
64date | file2c 'const char date[] = {' ',0};'
65.Ed
66.Pp
67will produce:
68.Bd -literal -offset indent
69const char date[] = {
7083,97,116,32,74,97,110,32,50,56,32,49,54,58,50,56,58,48,53,
7132,80,83,84,32,49,57,57,53,10
72,0};
73.Ed
74