2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 static const char sccsid[] = "@(#)conv.c 8.1 (Berkeley) 6/6/93";
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/types.h>
49 conv_c(PR *pr, u_char *p, size_t bufsize)
55 int converr, pad, width;
56 u_char peekbuf[MB_LEN_MAX];
97 * Multibyte characters are disabled for hexdump(1) for backwards
98 * compatibility and consistency (none of its other output formats
99 * recognize them correctly).
102 if (odmode && MB_CUR_MAX > 1) {
105 clen = mbrtowc(&wc, p, bufsize, &pr->mbstate);
108 else if (clen == (size_t)-1 || (clen == (size_t)-2 &&
110 memset(&pr->mbstate, 0, sizeof(pr->mbstate));
113 * We peeked ahead, but that didn't help --
114 * we either got an illegal sequence or still
115 * can't complete; restore original character.
123 } else if (clen == (size_t)-2) {
125 * Incomplete character; peek ahead and see if we
130 bufsize = peek(p = peekbuf, MB_CUR_MAX);
138 if (!converr && iswprint(wc)) {
141 (void)printf(pr->fmt, (int)wc);
144 assert(strcmp(pr->fmt, "%3C") == 0);
150 (void)printf("%*s%C", pad, "", wc);
151 pr->mbleft = clen - 1;
154 (void)sprintf(buf, "%03o", (int)*p);
156 strpr: *pr->cchar = 's';
157 (void)printf(pr->fmt, str);
162 conv_u(PR *pr, u_char *p)
164 static char const * list[] = {
165 "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
166 "bs", "ht", "lf", "vt", "ff", "cr", "so", "si",
167 "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
168 "can", "em", "sub", "esc", "fs", "gs", "rs", "us",
171 /* od used nl, not lf */
174 if (odmode && *p == 0x0a)
175 (void)printf(pr->fmt, "nl");
177 (void)printf(pr->fmt, list[*p]);
178 } else if (*p == 0x7f) {
180 (void)printf(pr->fmt, "del");
181 } else if (odmode && *p == 0x20) { /* od replaced space with sp */
183 (void)printf(pr->fmt, " sp");
184 } else if (isprint(*p)) {
186 (void)printf(pr->fmt, *p);
189 (void)printf(pr->fmt, (int)*p);