]> git.ipfire.org Git - thirdparty/util-linux.git/blob - text-utils/hexsyntax.c
Imported from util-linux-2.11o tarball.
[thirdparty/util-linux.git] / text-utils / hexsyntax.c
1 /*-
2 * Copyright (c) 1990 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 /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
35 * - added Native Language Support
36 */
37
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include "hexdump.h"
43 #include "nls.h"
44
45 off_t skip; /* bytes to skip */
46
47 void
48 newsyntax(int argc, char ***argvp)
49 {
50 int ch;
51 char *p, **argv;
52
53 argv = *argvp;
54 while ((ch = getopt(argc, argv, "bcCde:f:n:os:vx")) != -1)
55 switch (ch) {
56 case 'b':
57 add("\"%07.7_Ax\n\"");
58 add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
59 break;
60 case 'c':
61 add("\"%07.7_Ax\n\"");
62 add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
63 break;
64 case 'C':
65 add("\"%08.8_Ax\n\"");
66 add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
67 add("\" |\" 16/1 \"%_p\" \"|\\n\"");
68 break;
69 case 'd':
70 add("\"%07.7_Ax\n\"");
71 add("\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
72 break;
73 case 'e':
74 add(optarg);
75 break;
76 case 'f':
77 addfile(optarg);
78 break;
79 case 'n':
80 if ((length = atoi(optarg)) < 0) {
81 fprintf(stderr,
82 _("hexdump: bad length value.\n"));
83 exit(1);
84 }
85 break;
86 case 'o':
87 add("\"%07.7_Ax\n\"");
88 add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
89 break;
90 case 's':
91 if ((skip = strtol(optarg, &p, 0)) < 0) {
92 fprintf(stderr,
93 _("hexdump: bad skip value.\n"));
94 exit(1);
95 }
96 switch(*p) {
97 case 'b':
98 skip *= 512;
99 break;
100 case 'k':
101 skip *= 1024;
102 break;
103 case 'm':
104 skip *= 1048576;
105 break;
106 }
107 break;
108 case 'v':
109 vflag = ALL;
110 break;
111 case 'x':
112 add("\"%07.7_Ax\n\"");
113 add("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
114 break;
115 case '?':
116 usage();
117 }
118
119 if (!fshead) {
120 add("\"%07.7_Ax\n\"");
121 add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
122 }
123
124 *argvp += optind;
125 }
126
127 void
128 usage()
129 {
130 fprintf(stderr,
131 _("hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"));
132 exit(1);
133 }