xref: /freebsd/usr.bin/hexdump/hexdump.h (revision a1217f20b4d4ba8ed1ed5ea8683ee9a7a03a81fe)
19b50d902SRodney W. Grimes /*
29b50d902SRodney W. Grimes  * Copyright (c) 1989, 1993
39b50d902SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
49b50d902SRodney W. Grimes  *
59b50d902SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
69b50d902SRodney W. Grimes  * modification, are permitted provided that the following conditions
79b50d902SRodney W. Grimes  * are met:
89b50d902SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
99b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
109b50d902SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
119b50d902SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
129b50d902SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
139b50d902SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
149b50d902SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
159b50d902SRodney W. Grimes  *    without specific prior written permission.
169b50d902SRodney W. Grimes  *
179b50d902SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
189b50d902SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199b50d902SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209b50d902SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
219b50d902SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229b50d902SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239b50d902SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249b50d902SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259b50d902SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269b50d902SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279b50d902SRodney W. Grimes  * SUCH DAMAGE.
289b50d902SRodney W. Grimes  *
299b50d902SRodney W. Grimes  *	@(#)hexdump.h	8.1 (Berkeley) 6/6/93
30ac3c230cSDavid E. O'Brien  * $FreeBSD$
319b50d902SRodney W. Grimes  */
329b50d902SRodney W. Grimes 
3340ccfb31STim J. Robbins #include <wchar.h>
3440ccfb31STim J. Robbins 
359b50d902SRodney W. Grimes typedef struct _pr {
369b50d902SRodney W. Grimes 	struct _pr *nextpr;		/* next print unit */
379b50d902SRodney W. Grimes #define	F_ADDRESS	0x001		/* print offset */
389b50d902SRodney W. Grimes #define	F_BPAD		0x002		/* blank pad */
399b50d902SRodney W. Grimes #define	F_C		0x004		/* %_c */
409b50d902SRodney W. Grimes #define	F_CHAR		0x008		/* %c */
419b50d902SRodney W. Grimes #define	F_DBL		0x010		/* %[EefGf] */
429b50d902SRodney W. Grimes #define	F_INT		0x020		/* %[di] */
439b50d902SRodney W. Grimes #define	F_P		0x040		/* %_p */
449b50d902SRodney W. Grimes #define	F_STR		0x080		/* %s */
459b50d902SRodney W. Grimes #define	F_U		0x100		/* %_u */
469b50d902SRodney W. Grimes #define	F_UINT		0x200		/* %[ouXx] */
479b50d902SRodney W. Grimes #define	F_TEXT		0x400		/* no conversions */
489b50d902SRodney W. Grimes 	u_int flags;			/* flag values */
499b50d902SRodney W. Grimes 	int bcnt;			/* byte count */
509b50d902SRodney W. Grimes 	char *cchar;			/* conversion character */
519b50d902SRodney W. Grimes 	char *fmt;			/* printf format */
529b50d902SRodney W. Grimes 	char *nospace;			/* no whitespace version */
5340ccfb31STim J. Robbins 	int mbleft;			/* bytes left of multibyte char. */
5440ccfb31STim J. Robbins 	mbstate_t mbstate;		/* conversion state */
559b50d902SRodney W. Grimes } PR;
569b50d902SRodney W. Grimes 
579b50d902SRodney W. Grimes typedef struct _fu {
589b50d902SRodney W. Grimes 	struct _fu *nextfu;		/* next format unit */
599b50d902SRodney W. Grimes 	struct _pr *nextpr;		/* next print unit */
609b50d902SRodney W. Grimes #define	F_IGNORE	0x01		/* %_A */
619b50d902SRodney W. Grimes #define	F_SETREP	0x02		/* rep count set, not default */
629b50d902SRodney W. Grimes 	u_int flags;			/* flag values */
639b50d902SRodney W. Grimes 	int reps;			/* repetition count */
649b50d902SRodney W. Grimes 	int bcnt;			/* byte count */
659b50d902SRodney W. Grimes 	char *fmt;			/* format string */
669b50d902SRodney W. Grimes } FU;
679b50d902SRodney W. Grimes 
689b50d902SRodney W. Grimes typedef struct _fs {			/* format strings */
699b50d902SRodney W. Grimes 	struct _fs *nextfs;		/* linked list of format strings */
709b50d902SRodney W. Grimes 	struct _fu *nextfu;		/* linked list of format units */
719b50d902SRodney W. Grimes 	int bcnt;
729b50d902SRodney W. Grimes } FS;
739b50d902SRodney W. Grimes 
749b50d902SRodney W. Grimes extern FS *fshead;			/* head of format strings list */
75f4ac32deSDavid Malone extern FU *endfu;			/* format at end-of-data */
769b50d902SRodney W. Grimes extern int blocksize;			/* data block size */
77f4ac32deSDavid Malone extern int exitval;			/* final exit value */
78ca9cbcecSTim J. Robbins extern int odmode;			/* are we acting as od(1)? */
791b50831dSTim J. Robbins extern int length;			/* amount of data to read */
801b50831dSTim J. Robbins extern off_t skip;			/* amount of data to skip at start */
819b50d902SRodney W. Grimes enum _vflag { ALL, DUP, FIRST, WAIT };	/* -v values */
821b50831dSTim J. Robbins extern enum _vflag vflag;
839b50d902SRodney W. Grimes 
84f1bb2cd2SWarner Losh void	 add(const char *);
85*a1217f20SXin LI void	 addfile(const char *);
86*a1217f20SXin LI void	 badcnt(const char *);
87*a1217f20SXin LI void	 badconv(const char *);
88f1bb2cd2SWarner Losh void	 badfmt(const char *);
89f1bb2cd2SWarner Losh void	 badsfmt(void);
90f1bb2cd2SWarner Losh void	 bpad(PR *);
9140ccfb31STim J. Robbins void	 conv_c(PR *, u_char *, size_t);
92f1bb2cd2SWarner Losh void	 conv_u(PR *, u_char *);
93f1bb2cd2SWarner Losh void	 display(void);
94f1bb2cd2SWarner Losh void	 doskip(const char *, int);
95f1bb2cd2SWarner Losh void	 escape(char *);
96f1bb2cd2SWarner Losh u_char	*get(void);
97f1bb2cd2SWarner Losh void	 newsyntax(int, char ***);
98f1bb2cd2SWarner Losh int	 next(char **);
99f1bb2cd2SWarner Losh void	 nomem(void);
100f1bb2cd2SWarner Losh void	 oldsyntax(int, char ***);
10140ccfb31STim J. Robbins size_t	 peek(u_char *, size_t);
102f1bb2cd2SWarner Losh void	 rewrite(FS *);
103f1bb2cd2SWarner Losh int	 size(FS *);
104f1bb2cd2SWarner Losh void	 usage(void);
105