Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/hexdump revert and fix the usage to be consistent wi...



details:   https://anonhg.NetBSD.org/src/rev/6f30ef8d4c75
branches:  trunk
changeset: 759083:6f30ef8d4c75
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 27 20:46:38 2010 +0000

description:
revert and fix the usage to be consistent with other programs.

diffstat:

 usr.bin/hexdump/hexdump.c   |  30 +++++++++++++++++++++++-------
 usr.bin/hexdump/hexdump.h   |   7 +++----
 usr.bin/hexdump/hexsyntax.c |  15 +++------------
 usr.bin/hexdump/odsyntax.c  |  22 ++++++----------------
 4 files changed, 35 insertions(+), 39 deletions(-)

diffs (202 lines):

diff -r b8950a5767c2 -r 6f30ef8d4c75 usr.bin/hexdump/hexdump.c
--- a/usr.bin/hexdump/hexdump.c Sat Nov 27 20:18:46 2010 +0000
+++ b/usr.bin/hexdump/hexdump.c Sat Nov 27 20:46:38 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hexdump.c,v 1.15 2010/02/09 14:06:37 drochner Exp $    */
+/*     $NetBSD: hexdump.c,v 1.16 2010/11/27 20:46:38 christos Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)hexdump.c  8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: hexdump.c,v 1.15 2010/02/09 14:06:37 drochner Exp $");
+__RCSID("$NetBSD: hexdump.c,v 1.16 2010/11/27 20:46:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -58,8 +58,7 @@
 int blocksize;                         /* data block size */
 int exitval;                           /* final exit value */
 int length = -1;                       /* max bytes to read */
-
-int    main(int, char **);
+static int isod = 0;
 
 int
 main(int argc, char *argv[])
@@ -69,10 +68,11 @@
 
        setlocale(LC_ALL, "");
 
-       if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od"))
-               newsyntax(argc, &argv);
+       isod = (p = strrchr(argv[0], 'o')) == NULL || strcmp(p, "od") == 0;
+       if (isod)
+               odsyntax(argc, &argv);
        else
-               odsyntax(argc, &argv);
+               hexsyntax(argc, &argv);
 
        /* figure out the data block size */
        for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
@@ -88,3 +88,19 @@
        display();
        exit(exitval);
 }
+
+void
+usage(void)
+{
+       const char *pname = getprogname();
+
+       (void)fprintf(stderr, "Usage: %s ", pname);
+       if (isod)
+               (void)fprintf(stderr, "[-aBbcDdeFfHhIiLlOovXx] [-A base] "
+                   "[-j skip] [-N length] [-t type_string] [[+]offset[.][Bb]] "
+                   "[file ...]\n");
+       else
+               (void)fprintf(stderr, "[-bcCdovx] [-e fmt] [-f fmt_file] "
+                   "[-n length] [-s skip] [file ...]\n");
+       exit(1);
+}
diff -r b8950a5767c2 -r 6f30ef8d4c75 usr.bin/hexdump/hexdump.h
--- a/usr.bin/hexdump/hexdump.h Sat Nov 27 20:18:46 2010 +0000
+++ b/usr.bin/hexdump/hexdump.h Sat Nov 27 20:46:38 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hexdump.h,v 1.11 2010/02/09 14:06:37 drochner Exp $    */
+/*     $NetBSD: hexdump.h,v 1.12 2010/11/27 20:46:38 christos Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -90,12 +90,11 @@
 void    conv_u(PR *, u_char *);
 void    display(void);
 void    doskip(const char *, int);
-/*void  err(const char *, ...);*/
 void    escape(char *);
 u_char *get(void);
-void    newsyntax(int, char ***);
+void    hexsyntax(int, char ***);
 int     next(char **);
 void    odsyntax(int, char ***);
 void    rewrite(FS *);
 int     size(FS *);
-void    usage(void);
+void    usage(void) __attribute__((__noreturn__));
diff -r b8950a5767c2 -r 6f30ef8d4c75 usr.bin/hexdump/hexsyntax.c
--- a/usr.bin/hexdump/hexsyntax.c       Sat Nov 27 20:18:46 2010 +0000
+++ b/usr.bin/hexdump/hexsyntax.c       Sat Nov 27 20:46:38 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hexsyntax.c,v 1.13 2006/01/04 01:30:21 perry Exp $     */
+/*     $NetBSD: hexsyntax.c,v 1.14 2010/11/27 20:46:38 christos Exp $  */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)hexsyntax.c        8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: hexsyntax.c,v 1.13 2006/01/04 01:30:21 perry Exp $");
+__RCSID("$NetBSD: hexsyntax.c,v 1.14 2010/11/27 20:46:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -55,7 +55,7 @@
 off_t skip;                            /* bytes to skip */
 
 void
-newsyntax(int argc, char ***argvp)
+hexsyntax(int argc, char ***argvp)
 {
        int ch;
        char *p, **argv;
@@ -127,12 +127,3 @@
 
        *argvp += optind;
 }
-
-void
-usage(void)
-{
-       (void)fprintf(stderr,
-"hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"
-       );
-       exit(1);
-}
diff -r b8950a5767c2 -r 6f30ef8d4c75 usr.bin/hexdump/odsyntax.c
--- a/usr.bin/hexdump/odsyntax.c        Sat Nov 27 20:18:46 2010 +0000
+++ b/usr.bin/hexdump/odsyntax.c        Sat Nov 27 20:46:38 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: odsyntax.c,v 1.27 2010/11/27 00:42:58 dholland Exp $   */
+/*     $NetBSD: odsyntax.c,v 1.28 2010/11/27 20:46:38 christos Exp $   */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: odsyntax.c,v 1.27 2010/11/27 00:42:58 dholland Exp $");
+__RCSID("$NetBSD: odsyntax.c,v 1.28 2010/11/27 20:46:38 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -72,7 +72,6 @@
 
 static void odoffset(int, char ***);
 static void posixtypes(char const *);
-static void odusage(void);
 
 void
 odsyntax(int argc, char ***argvp)
@@ -177,7 +176,7 @@
                        break;
                case '?':
                default:
-                       odusage();
+                       usage();
                }
 
        if (fshead->nextfs->nextfs == NULL)
@@ -247,7 +246,7 @@
                                default:
                                        warnx("Bad type-size qualifier '%c'",
                                            *type_string);
-                                       odusage();
+                                       usage();
                                }
                                type_string++;
                        } else if (isdigit((unsigned char)*type_string)) {
@@ -277,7 +276,7 @@
                                default:
                                        warnx("Bad type-size qualifier '%c'",
                                            *type_string);
-                                       odusage();
+                                       usage();
                                }
                                type_string++;
                        } else if (isdigit((unsigned char)*type_string)) {
@@ -287,7 +286,7 @@
                                nbytes = 4;
                        break;
                default:
-                       odusage();
+                       usage();
                }
                for (odf = odftab; odf->type != 0; odf++)
                        if (odf->type == type && odf->nbytes == nbytes)
@@ -397,12 +396,3 @@
        /* Terminate file list. */
        (*argvp)[1] = NULL;
 }
-
-static void
-odusage(void)
-{
-       (void)warnx("Usage: od [-aBbcDdeFfHhIiLlOovXx] [-A base] [-j skip]"
-                   " [-N length]");
-       (void)warnx("   [-t type_string] [[+]offset[.][Bb]] [file ...]");
-       exit(1);
-}



Home | Main Index | Thread Index | Old Index