Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:19

0001 /*-
0002  * Copyright (c) 1990, 1993
0003  *  The Regents of the University of California.  All rights reserved.
0004  *
0005  * Redistribution and use in source and binary forms, with or without
0006  * modification, are permitted provided that the following conditions
0007  * are met:
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  * 3. All advertising materials mentioning features or use of this software
0014  *    must display the following acknowledgement:
0015  *  This product includes software developed by the University of
0016  *  California, Berkeley and its contributors.
0017  * 4. Neither the name of the University nor the names of its contributors
0018  *    may be used to endorse or promote products derived from this software
0019  *    without specific prior written permission.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0031  * SUCH DAMAGE.
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 /* not lint */
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;             /* bytes to 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         /* "Canonical" format, implies -C. */
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 }