]>
Commit | Line | Data |
---|---|---|
6dbe3af9 KZ |
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 | ||
34 | #ifndef lint | |
35 | static char sccsid[] = "@(#)conv.c 5.4 (Berkeley) 6/1/90"; | |
36 | #endif /* not lint */ | |
37 | ||
fd6b7a7f | 38 | #include <stdio.h> |
6dbe3af9 | 39 | #include <ctype.h> |
fd6b7a7f | 40 | #include <sys/types.h> |
6dbe3af9 KZ |
41 | #include "hexdump.h" |
42 | ||
fd6b7a7f | 43 | void conv_c(PR *pr, u_char *p) |
6dbe3af9 KZ |
44 | { |
45 | extern int deprecated; | |
46 | char buf[10], *str; | |
47 | ||
48 | switch(*p) { | |
49 | case '\0': | |
50 | str = "\\0"; | |
51 | goto strpr; | |
52 | /* case '\a': */ | |
53 | case '\007': | |
54 | if (deprecated) /* od didn't know about \a */ | |
55 | break; | |
56 | str = "\\a"; | |
57 | goto strpr; | |
58 | case '\b': | |
59 | str = "\\b"; | |
60 | goto strpr; | |
61 | case '\f': | |
62 | str = "\\f"; | |
63 | goto strpr; | |
64 | case '\n': | |
65 | str = "\\n"; | |
66 | goto strpr; | |
67 | case '\r': | |
68 | str = "\\r"; | |
69 | goto strpr; | |
70 | case '\t': | |
71 | str = "\\t"; | |
72 | goto strpr; | |
73 | case '\v': | |
74 | if (deprecated) | |
75 | break; | |
76 | str = "\\v"; | |
77 | goto strpr; | |
78 | default: | |
79 | break; | |
80 | } | |
81 | if (isprint(*p)) { | |
82 | *pr->cchar = 'c'; | |
83 | (void)printf(pr->fmt, *p); | |
84 | } else { | |
85 | (void)sprintf(str = buf, "%03o", (int)*p); | |
86 | strpr: *pr->cchar = 's'; | |
87 | (void)printf(pr->fmt, str); | |
88 | } | |
89 | } | |
90 | ||
fd6b7a7f | 91 | void conv_u(PR *pr, u_char *p) |
6dbe3af9 KZ |
92 | { |
93 | extern int deprecated; | |
94 | static char *list[] = { | |
95 | "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", | |
96 | "bs", "ht", "lf", "vt", "ff", "cr", "so", "si", | |
97 | "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb", | |
98 | "can", "em", "sub", "esc", "fs", "gs", "rs", "us", | |
99 | }; | |
100 | ||
101 | /* od used nl, not lf */ | |
102 | if (*p <= 0x1f) { | |
103 | *pr->cchar = 's'; | |
104 | if (deprecated && *p == 0x0a) | |
105 | (void)printf(pr->fmt, "nl"); | |
106 | else | |
107 | (void)printf(pr->fmt, list[*p]); | |
108 | } else if (*p == 0x7f) { | |
109 | *pr->cchar = 's'; | |
110 | (void)printf(pr->fmt, "del"); | |
111 | } else if (deprecated && *p == 0x20) { /* od replace space with sp */ | |
112 | *pr->cchar = 's'; | |
113 | (void)printf(pr->fmt, " sp"); | |
114 | } else if (isprint(*p)) { | |
115 | *pr->cchar = 'c'; | |
116 | (void)printf(pr->fmt, *p); | |
117 | } else { | |
118 | *pr->cchar = 'x'; | |
119 | (void)printf(pr->fmt, (int)*p); | |
120 | } | |
121 | } |