(root)/
util-linux-2.39/
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  #ifndef UTIL_LINUX_HEXDUMP_H
      36  #define UTIL_LINUX_HEXDUMP_H
      37  
      38  #include "c.h"
      39  #include "list.h"
      40  
      41  struct hexdump_clr {
      42  	struct list_head colorlist;	/* next color unit */
      43  	const char *fmt;		/* the color, UL_COLOR_* */
      44  	off_t offt;			/* offset where unit is valid... */
      45  	int range;			/* ... and it's range */
      46  	int val;			/* value ... */
      47  	char *str;			/* ... or string to match */
      48  	int invert;			/* invert condition? */
      49  };
      50  
      51  struct hexdump_pr {
      52  	struct list_head prlist;		/* next print unit */
      53  #define	F_ADDRESS	0x001		/* print offset */
      54  #define	F_BPAD		0x002		/* blank pad */
      55  #define	F_C		0x004		/* %_c */
      56  #define	F_CHAR		0x008		/* %c */
      57  #define	F_DBL		0x010		/* %[EefGf] */
      58  #define	F_INT		0x020		/* %[di] */
      59  #define	F_P		0x040		/* %_p */
      60  #define	F_STR		0x080		/* %s */
      61  #define	F_U		0x100		/* %_u */
      62  #define	F_UINT		0x200		/* %[ouXx] */
      63  #define	F_TEXT		0x400		/* no conversions */
      64  	unsigned int flags;		/* flag values */
      65  	int bcnt;			/* byte count */
      66  	char *cchar;			/* conversion character */
      67  	struct list_head *colorlist;	/* color settings */
      68  	char *fmt;			/* printf format */
      69  	char *nospace;			/* no whitespace version */
      70  };
      71  
      72  struct hexdump_fu {
      73  	struct list_head fulist;		/* next format unit */
      74  	struct list_head prlist;		/* next print unit */
      75  #define	F_IGNORE	0x01		/* %_A */
      76  #define	F_SETREP	0x02		/* rep count set, not default */
      77  	unsigned int flags;		/* flag values */
      78  	int reps;			/* repetition count */
      79  	int bcnt;			/* byte count */
      80  	char *fmt;			/* format string */
      81  };
      82  
      83  struct hexdump_fs {			/* format strings */
      84  	struct list_head fslist;		/* linked list of format strings */
      85  	struct list_head fulist;		/* linked list of format units */
      86  	int bcnt;
      87  };
      88  
      89  struct hexdump {
      90    struct list_head fshead;				/* head of format strings */
      91    ssize_t blocksize;			/* data block size */
      92    int exitval;				/* final exit value */
      93    ssize_t length;			/* max bytes to read */
      94    off_t skip;				/* bytes to skip */
      95  };
      96  
      97  extern struct hexdump_fu *endfu;
      98  
      99  enum _vflag { ALL, DUP, FIRST, WAIT };	/* -v values */
     100  extern enum _vflag vflag;
     101  
     102  int block_size(struct hexdump_fs *);
     103  void add_fmt(const char *, struct hexdump *);
     104  void rewrite_rules(struct hexdump_fs *, struct hexdump *);
     105  void addfile(char *, struct hexdump *);
     106  void display(struct hexdump *);
     107  void __attribute__((__noreturn__)) usage(void);
     108  void conv_c(struct hexdump_pr *, u_char *);
     109  void conv_u(struct hexdump_pr *, u_char *);
     110  int  next(char **, struct hexdump *);
     111  int parse_args(int, char **, struct hexdump *);
     112  
     113  #endif /* UTIL_LINUX_HEXDUMP_H */