xref: /freebsd/usr.bin/file2c/file2c.1 (revision eda14cbc264d6969b02f2b1994cef11148e914f1)
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 sx
19.Op Fl n Ar count
20.Op Ar prefix Op Ar suffix
21.Sh DESCRIPTION
22The
23.Nm
24utility reads a file from stdin and writes it to stdout, converting each
25byte to its decimal or hexadecimal representation on the fly.
26The byte values are separated by a comma.
27This also means that the last byte value is not followed by a comma.
28By default the byte values are printed in decimal, but when the
29.Fl x
30option is given, the values will be printed in hexadecimal.
31When
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 , s
58and
59.Fl x
60options are useful when the binary data represents a bitmap and the output
61needs to remain readable and/or editable.
62Fonts, for example, are a good example of this.
63.Sh EXAMPLES
64The command:
65.Bd -literal -offset indent
66date | file2c 'const char date[] = {' ',0};'
67.Ed
68.Pp
69will produce:
70.Bd -literal -offset indent
71const char date[] = {
7283,97,116,32,74,97,110,32,50,56,32,49,54,58,50,56,58,48,53,
7332,80,83,84,32,49,57,57,53,10
74,0};
75.Ed
76