File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037
0038 #ifndef lint
0039 #if 0
0040 static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
0041 #include <sys/cdefs.h>
0042 __FBSDID("$FreeBSD: src/usr.bin/hexdump/hexsyntax.c,v 1.12 2002/09/04 23:29:01 dwmalone Exp $");
0043 #endif
0044 #endif
0045
0046 #include <sys/types.h>
0047
0048 #include "err.h"
0049 #include <stdio.h>
0050 #include <stdlib.h>
0051 #include <string.h>
0052 #include <unistd.h>
0053
0054 #define rindex(s,c) strrchr(s,c)
0055
0056 #include "hexdump.h"
0057
0058 #define __need_getopt_newlib
0059 #include <getopt.h>
0060
0061 #if RTEMS_REMOVED
0062 off_t skip;
0063 #endif
0064
0065 void
0066 newsyntax(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
0067 {
0068 int ch;
0069 char *p, **argv;
0070
0071 struct getopt_data getopt_reent;
0072 memset(&getopt_reent, 0, sizeof(getopt_data));
0073
0074 argv = *argvp;
0075 if ((p = rindex(argv[0], 'h')) != NULL &&
0076 strcmp(p, "hd") == 0) {
0077
0078 add(globals, "\"%08.8_Ax\n\"");
0079 add(globals, "\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
0080 add(globals, "\" |\" 16/1 \"%_p\" \"|\\n\"");
0081 }
0082 while ((ch = getopt_r(argc, argv, "bcCde:f:n:os:vx", &getopt_reent)) != -1)
0083 switch (ch) {
0084 case 'b':
0085 add(globals, "\"%07.7_Ax\n\"");
0086 add(globals, "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
0087 break;
0088 case 'c':
0089 add(globals, "\"%07.7_Ax\n\"");
0090 add(globals, "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
0091 break;
0092 case 'C':
0093 add(globals, "\"%08.8_Ax\n\"");
0094 add(globals, "\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
0095 add(globals, "\" |\" 16/1 \"%_p\" \"|\\n\"");
0096 break;
0097 case 'd':
0098 add(globals, "\"%07.7_Ax\n\"");
0099 add(globals, "\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"");
0100 break;
0101 case 'e':
0102 add(globals, getopt_reent.optarg);
0103 break;
0104 case 'f':
0105 addfile(globals, getopt_reent.optarg);
0106 break;
0107 case 'n':
0108 if ((length = atoi(getopt_reent.optarg)) < 0)
0109 errx(exit_jump, 1, "%s: bad length value", getopt_reent.optarg);
0110 break;
0111 case 'o':
0112 add(globals, "\"%07.7_Ax\n\"");
0113 add(globals, "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
0114 break;
0115 case 's':
0116 if ((skip = strtoll(getopt_reent.optarg, &p, 0)) < 0)
0117 errx(exit_jump, 1, "%s: bad skip value", getopt_reent.optarg);
0118 switch(*p) {
0119 case 'b':
0120 skip *= 512;
0121 break;
0122 case 'k':
0123 skip *= 1024;
0124 break;
0125 case 'm':
0126 skip *= 1048576;
0127 break;
0128 }
0129 break;
0130 case 'v':
0131 vflag = ALL;
0132 break;
0133 case 'x':
0134 add(globals, "\"%07.7_Ax\n\"");
0135 add(globals, "\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"");
0136 break;
0137 case '?':
0138 usage(globals);
0139 }
0140
0141 if (!fshead) {
0142 add(globals, "\"%07.7_Ax\n\"");
0143 add(globals, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
0144 }
0145
0146 *argvp += getopt_reent.optind;
0147 }
0148
0149 void
0150 usage(rtems_shell_hexdump_globals* globals)
0151 {
0152 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
0153 "usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]",
0154 " [-s skip] [file ...]",
0155 " hd [-bcdovx] [-e fmt] [-f fmt_file] [-n length]",
0156 " [-s skip] [file ...]");
0157 exit(1);
0158 }