18a16b7a1SPedro F. Giffuni /*- 28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 38a16b7a1SPedro F. Giffuni * 49b50d902SRodney W. Grimes * Copyright (c) 1989, 1993 59b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 69b50d902SRodney W. Grimes * 79b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 89b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 99b50d902SRodney W. Grimes * are met: 109b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 129b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 139b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 149b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 169b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 179b50d902SRodney W. Grimes * without specific prior written permission. 189b50d902SRodney W. Grimes * 199b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 209b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 219b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 229b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 239b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 249b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 259b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 269b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 279b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 289b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 299b50d902SRodney W. Grimes * SUCH DAMAGE. 309b50d902SRodney W. Grimes */ 319b50d902SRodney W. Grimes 3240ccfb31STim J. Robbins #include <wchar.h> 3340ccfb31STim J. Robbins 349b50d902SRodney W. Grimes typedef struct _pr { 359b50d902SRodney W. Grimes struct _pr *nextpr; /* next print unit */ 369b50d902SRodney W. Grimes #define F_ADDRESS 0x001 /* print offset */ 379b50d902SRodney W. Grimes #define F_BPAD 0x002 /* blank pad */ 389b50d902SRodney W. Grimes #define F_C 0x004 /* %_c */ 399b50d902SRodney W. Grimes #define F_CHAR 0x008 /* %c */ 409b50d902SRodney W. Grimes #define F_DBL 0x010 /* %[EefGf] */ 419b50d902SRodney W. Grimes #define F_INT 0x020 /* %[di] */ 429b50d902SRodney W. Grimes #define F_P 0x040 /* %_p */ 439b50d902SRodney W. Grimes #define F_STR 0x080 /* %s */ 449b50d902SRodney W. Grimes #define F_U 0x100 /* %_u */ 459b50d902SRodney W. Grimes #define F_UINT 0x200 /* %[ouXx] */ 469b50d902SRodney W. Grimes #define F_TEXT 0x400 /* no conversions */ 479b50d902SRodney W. Grimes u_int flags; /* flag values */ 489b50d902SRodney W. Grimes int bcnt; /* byte count */ 499b50d902SRodney W. Grimes char *cchar; /* conversion character */ 509b50d902SRodney W. Grimes char *fmt; /* printf format */ 519b50d902SRodney W. Grimes char *nospace; /* no whitespace version */ 5240ccfb31STim J. Robbins int mbleft; /* bytes left of multibyte char. */ 5340ccfb31STim J. Robbins mbstate_t mbstate; /* conversion state */ 549b50d902SRodney W. Grimes } PR; 559b50d902SRodney W. Grimes 569b50d902SRodney W. Grimes typedef struct _fu { 579b50d902SRodney W. Grimes struct _fu *nextfu; /* next format unit */ 589b50d902SRodney W. Grimes struct _pr *nextpr; /* next print unit */ 599b50d902SRodney W. Grimes #define F_IGNORE 0x01 /* %_A */ 609b50d902SRodney W. Grimes #define F_SETREP 0x02 /* rep count set, not default */ 619b50d902SRodney W. Grimes u_int flags; /* flag values */ 629b50d902SRodney W. Grimes int reps; /* repetition count */ 639b50d902SRodney W. Grimes int bcnt; /* byte count */ 649b50d902SRodney W. Grimes char *fmt; /* format string */ 659b50d902SRodney W. Grimes } FU; 669b50d902SRodney W. Grimes 679b50d902SRodney W. Grimes typedef struct _fs { /* format strings */ 689b50d902SRodney W. Grimes struct _fs *nextfs; /* linked list of format strings */ 699b50d902SRodney W. Grimes struct _fu *nextfu; /* linked list of format units */ 709b50d902SRodney W. Grimes int bcnt; 719b50d902SRodney W. Grimes } FS; 729b50d902SRodney W. Grimes 739b50d902SRodney W. Grimes extern FS *fshead; /* head of format strings list */ 74f4ac32deSDavid Malone extern FU *endfu; /* format at end-of-data */ 759b50d902SRodney W. Grimes extern int blocksize; /* data block size */ 76f4ac32deSDavid Malone extern int exitval; /* final exit value */ 77ca9cbcecSTim J. Robbins extern int odmode; /* are we acting as od(1)? */ 781b50831dSTim J. Robbins extern int length; /* amount of data to read */ 791b50831dSTim J. Robbins extern off_t skip; /* amount of data to skip at start */ 809b50d902SRodney W. Grimes enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */ 811b50831dSTim J. Robbins extern enum _vflag vflag; 829b50d902SRodney W. Grimes 83f1bb2cd2SWarner Losh void add(const char *); 84a1217f20SXin LI void addfile(const char *); 85a1217f20SXin LI void badcnt(const char *); 86a1217f20SXin LI void badconv(const char *); 87f1bb2cd2SWarner Losh void badfmt(const char *); 88*8fb93ac9SConrad Meyer void badnoconv(void); 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