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