386BSD 0.1 development
[unix-history] / usr / src / usr.bin / hexdump / hexdump.c
index 55394a5..4b28242 100644 (file)
@@ -2,17 +2,33 @@
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -22,105 +38,30 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)hexdump.c  5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)hexdump.c  5.5 (Berkeley) 6/1/90";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include "hexdump.h"
 
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include "hexdump.h"
 
-enum _vflag vflag = FIRST;             /* display duplicate lines */
 FS *fshead;                            /* head of format strings */
 FS *fshead;                            /* head of format strings */
-off_t skip;                            /* bytes to skip */
 int blocksize;                         /* data block size */
 int exitval;                           /* final exit value */
 int blocksize;                         /* data block size */
 int exitval;                           /* final exit value */
-int length;                            /* max bytes to read */
+int length = -1;                       /* max bytes to read */
 
 main(argc, argv)
        int argc;
        char **argv;
 {
 
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int errno, optind;
-       extern char *optarg;
+       extern int errno;
        register FS *tfs;
        register FS *tfs;
-       int ch;
        char *p, *rindex();
 
        char *p, *rindex();
 
-       length = -1;
-       while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
-               switch (ch) {
-               case 'b':
-                       add("\"%07.7_Ax\n\"");
-                       add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
-                       break;
-               case 'c':
-                       add("\"%07.7_Ax\n\"");
-                       add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
-                       break;
-               case 'd':
-                       add("\"%07.7_Ax\n\"");
-                       add("\"%07.7_ax \" 8/2 \"%05u \" \"\\n\"");
-                       break;
-               case 'e':
-                       add(optarg);
-                       break;
-               case 'f':
-                       addfile(optarg);
-                       break;
-               case 'n':
-                       if ((length = atoi(optarg)) < 0) {
-                               (void)fprintf(stderr,
-                                   "hexdump: bad length value.\n");
-                               exit(1);
-                       }
-                       break;
-               case 'o':
-                       add("\"%07.7_Ax\n\"");
-                       add("\"%07.7_ax \" 8/2 \"%06o \" \"\\n\"");
-                       break;
-               case 's':
-                       if ((skip = strtol(optarg, &p, 0)) < 0) {
-                               (void)fprintf(stderr,
-                                   "hexdump: bad skip value.\n");
-                               exit(1);
-                       }
-                       switch(*p) {
-                       case 'b':
-                               skip *= 512;
-                               break;
-                       case 'k':
-                               skip *= 1024;
-                               break;
-                       case 'm':
-                               skip *= 1048576;
-                               break;
-                       }
-                       break;
-               case 'v':
-                       vflag = ALL;
-                       break;
-               case 'x':
-                       add("\"%07.7_Ax\n\"");
-                       add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
-                       break;
-               case '?':
-                       usage();
-                       exit(1);
-               }
-
-       if (!fshead) {
-               p = rindex(argv[0], 'o');
-               if (p && !strcmp(p, "od")) {
-                       add("\"%07.7_Ao\n\"");
-                       add("\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");
-               } else {
-                       add("\"%07.7_Ax\n\"");
-                       add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
-               }
-       }
-
-       argv += optind;
-       argc -= optind;
+       if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
+               newsyntax(argc, &argv);
+       else
+               oldsyntax(argc, &argv);
 
        /* figure out the data block size */
        for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
 
        /* figure out the data block size */
        for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
@@ -136,10 +77,3 @@ main(argc, argv)
        display();
        exit(exitval);
 }
        display();
        exit(exitval);
 }
-
-usage()
-{
-       (void)fprintf(stderr,
-"hexdump: [-bcdovx] [-e format] [-f file] [-n length] [-s skip] [file ...]\n");
-       exit(1);
-}