buildgcc: Fix colors for dash
[coreboot.git] / util / nvramtool / hexdump.h
1 /*****************************************************************************\
2  * hexdump.h
3 \*****************************************************************************/
4
5 #ifndef _HEXDUMP_H
6 #define _HEXDUMP_H
7
8 /* hexdump.h
9  *
10  * Copyright (C) 2002
11  *     David S. Peterson.  All rights reserved.
12  *
13  * Author: David S. Peterson <dave_peterson@pobox.com>
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met:
18  * 1. Redistributions of source code must retain the above copyright notice,
19  *    this list of conditions, and the entire permission notice, including
20  *    the following disclaimer of warranties.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions, and the entire permission notice,
23  *    including the following disclaimer in the documentation and/or other
24  *    materials provided with the distribution.
25  * 3. The name(s) of the author(s) may not be used to endorse or promote
26  *    products derived from this software without specific prior written
27  *    permission.
28  *
29  * ALTERNATIVELY, this product may be distributed under the terms of the GNU
30  * General Public License, in which case the provisions of the GPL are
31  * required INSTEAD OF the above restrictions.  (This clause is necessary due
32  * to a potential bad interaction between the GPL and the restrictions
33  * contained in a BSD-style copyright.)
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
36  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
38  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
39  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
40  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
44  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  */
46
47 #include <stdint.h>
48 #include <sys/types.h>
49 #include <stdio.h>
50
51 /*--------------------------------------------------------------------------
52  * hexdump_format_t
53  *
54  * This specifies how the output of the 'hexdump' function should look.
55  *
56  * fields:
57  *     bytes_per_line:  the number of data bytes to display per line of
58  *                      output
59  *     addrprint_width: Each line of output begins with the address of the
60  *                      first data byte displayed on that line.  This
61  *                      specifies the number of bytes wide the address
62  *                      should be displayed as.  This value must be from 1
63  *                      to 8.
64  *     indent:          This is a string to display at the start of each
65  *                      output line.  Its purpose is to indent the output.
66  *     sep1:            This is a string to display between the address and
67  *                      the bytes of data displayed in hex.  It serves as a
68  *                      separator.
69  *     sep2:            This is a string to display between individual hex
70  *                      values.  It serves as a separator.
71  *     sep3:            This is a string to display between the bytes of
72  *                      data in hex and the bytes of data displayed as
73  *                      characters.  It serves as a separator.
74  *     nonprintable:    This is a substitute character to display in place
75  *                      of nonprintable characters.
76  *--------------------------------------------------------------------------*/
77 typedef struct {
78         int bytes_per_line;
79         int addrprint_width;
80         const char *indent;
81         const char *sep1;
82         const char *sep2;
83         const char *sep3;
84         unsigned char nonprintable;
85 } hexdump_format_t;
86
87 /*--------------------------------------------------------------------------
88  * hexdump
89  *
90  * Write a hex dump of 'mem' to 'outfile'.
91  *
92  * parameters:
93  *     mem:             a pointer to the memory to display
94  *     bytes:           the number of bytes of data to display
95  *     addrprint_start: The address to associate with the first byte of
96  *                      data.  For instance, a value of 0 indicates that the
97  *                      first byte displayed should be labeled as byte 0.
98  *     outfile:         The place where the hex dump should be written.
99  *                      For instance, stdout or stderr may be passed here.
100  *     format:          A structure specifying how the hex dump should be
101  *                      formatted.
102  *--------------------------------------------------------------------------*/
103 void hexdump(const void *mem, int bytes, uint64_t addrprint_start,
104              FILE * outfile, const hexdump_format_t * format);
105
106 #endif                          /* _HEXDUMP_H */