]> git.ipfire.org Git - thirdparty/util-linux.git/blob - text-utils/hexdump.h
setterm: disallow "default" for --ulcolor/--hbcolor
[thirdparty/util-linux.git] / text-utils / hexdump.h
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)hexdump.h 5.4 (Berkeley) 6/1/90
34 */
35 #include "c.h"
36 #include "list.h"
37
38 struct hexdump_clr {
39 struct list_head colorlist; /* next color unit */
40 const char *fmt; /* the color, UL_COLOR_* */
41 off_t offt; /* offset where unit is valid... */
42 int range; /* ... and it's range */
43 int val; /* value ... */
44 char *str; /* ... or string to match */
45 int invert; /* invert condition? */
46 };
47
48 struct hexdump_pr {
49 struct list_head prlist; /* next print unit */
50 #define F_ADDRESS 0x001 /* print offset */
51 #define F_BPAD 0x002 /* blank pad */
52 #define F_C 0x004 /* %_c */
53 #define F_CHAR 0x008 /* %c */
54 #define F_DBL 0x010 /* %[EefGf] */
55 #define F_INT 0x020 /* %[di] */
56 #define F_P 0x040 /* %_p */
57 #define F_STR 0x080 /* %s */
58 #define F_U 0x100 /* %_u */
59 #define F_UINT 0x200 /* %[ouXx] */
60 #define F_TEXT 0x400 /* no conversions */
61 unsigned int flags; /* flag values */
62 int bcnt; /* byte count */
63 char *cchar; /* conversion character */
64 struct list_head *colorlist; /* color settings */
65 char *fmt; /* printf format */
66 char *nospace; /* no whitespace version */
67 };
68
69 struct hexdump_fu {
70 struct list_head fulist; /* next format unit */
71 struct list_head prlist; /* next print unit */
72 #define F_IGNORE 0x01 /* %_A */
73 #define F_SETREP 0x02 /* rep count set, not default */
74 unsigned int flags; /* flag values */
75 int reps; /* repetition count */
76 int bcnt; /* byte count */
77 char *fmt; /* format string */
78 };
79
80 struct hexdump_fs { /* format strings */
81 struct list_head fslist; /* linked list of format strings */
82 struct list_head fulist; /* linked list of format units */
83 int bcnt;
84 };
85
86 struct hexdump {
87 struct list_head fshead; /* head of format strings */
88 ssize_t blocksize; /* data block size */
89 int exitval; /* final exit value */
90 ssize_t length; /* max bytes to read */
91 off_t skip; /* bytes to skip */
92 };
93
94 extern struct hexdump_fu *endfu;
95
96 enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */
97 extern enum _vflag vflag;
98
99 int block_size(struct hexdump_fs *);
100 void add_fmt(const char *, struct hexdump *);
101 void rewrite_rules(struct hexdump_fs *, struct hexdump *);
102 void addfile(char *, struct hexdump *);
103 void display(struct hexdump *);
104 void __attribute__((__noreturn__)) usage(void);
105 void conv_c(struct hexdump_pr *, u_char *);
106 void conv_u(struct hexdump_pr *, u_char *);
107 int next(char **, struct hexdump *);
108 int parse_args(int, char **, struct hexdump *);