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