Annotation of 43BSDReno/usr.bin/hexdump/hexsyntax.c, revision 1.1.1.1

1.1       root        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 are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)hexsyntax.c        5.2 (Berkeley) 5/8/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include <sys/types.h>
                     25: #include <stdio.h>
                     26: #include "hexdump.h"
                     27: 
                     28: off_t skip;                            /* bytes to skip */
                     29: 
                     30: newsyntax(argc, argvp)
                     31:        int argc;
                     32:        char ***argvp;
                     33: {
                     34:        extern enum _vflag vflag;
                     35:        extern FS *fshead;
                     36:        extern char *optarg;
                     37:        extern int length, optind;
                     38:        int ch;
                     39:        char *p, **argv;
                     40: 
                     41:        argv = *argvp;
                     42:        while ((ch = getopt(argc, argv, "bcde:f:n:os:vx")) != EOF)
                     43:                switch (ch) {
                     44:                case 'b':
                     45:                        add("\"%07.7_Ax\n\"");
                     46:                        add("\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
                     47:                        break;
                     48:                case 'c':
                     49:                        add("\"%07.7_Ax\n\"");
                     50:                        add("\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
                     51:                        break;
                     52:                case 'd':
                     53:                        add("\"%07.7_Ax\n\"");
                     54:                        add("\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"");
                     55:                        break;
                     56:                case 'e':
                     57:                        add(optarg);
                     58:                        break;
                     59:                case 'f':
                     60:                        addfile(optarg);
                     61:                        break;
                     62:                case 'n':
                     63:                        if ((length = atoi(optarg)) < 0) {
                     64:                                (void)fprintf(stderr,
                     65:                                    "hexdump: bad length value.\n");
                     66:                                exit(1);
                     67:                        }
                     68:                        break;
                     69:                case 'o':
                     70:                        add("\"%07.7_Ax\n\"");
                     71:                        add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
                     72:                        break;
                     73:                case 's':
                     74:                        if ((skip = strtol(optarg, &p, 0)) < 0) {
                     75:                                (void)fprintf(stderr,
                     76:                                    "hexdump: bad skip value.\n");
                     77:                                exit(1);
                     78:                        }
                     79:                        switch(*p) {
                     80:                        case 'b':
                     81:                                skip *= 512;
                     82:                                break;
                     83:                        case 'k':
                     84:                                skip *= 1024;
                     85:                                break;
                     86:                        case 'm':
                     87:                                skip *= 1048576;
                     88:                                break;
                     89:                        }
                     90:                        break;
                     91:                case 'v':
                     92:                        vflag = ALL;
                     93:                        break;
                     94:                case 'x':
                     95:                        add("\"%07.7_Ax\n\"");
                     96:                        add("\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"");
                     97:                        break;
                     98:                case '?':
                     99:                        usage();
                    100:                        exit(1);
                    101:                }
                    102: 
                    103:        if (!fshead) {
                    104:                add("\"%07.7_Ax\n\"");
                    105:                add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
                    106:        }
                    107: 
                    108:        *argvp += optind;
                    109: }
                    110: 
                    111: usage()
                    112: {
                    113:        (void)fprintf(stderr,
                    114: "hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
                    115:        exit(1);
                    116: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.