From 08f437587948bf70e61d86654e0e098d2000ae20 Mon Sep 17 00:00:00 2001 From: Juli Mallett Date: Wed, 22 May 2002 16:09:52 +0000 Subject: [PATCH] Add a usage(). Print usage() if right before executing the specified command, it comes to be that *argv is NULL (i.e. a flag was specified without a command being given). --- usr.bin/sccs/sccs.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/usr.bin/sccs/sccs.c b/usr.bin/sccs/sccs.c index 7ef5f796693..6f0ec6d1f43 100644 --- a/usr.bin/sccs/sccs.c +++ b/usr.bin/sccs/sccs.c @@ -296,6 +296,8 @@ char *gstrcat(char *, const char *, size_t); char *gstrcpy(char *, const char *, size_t); char *gstrncat(char *, const char *, size_t, size_t); +static void usage(void); + #define FBUFSIZ BUFSIZ #define PFILELG 120 @@ -345,8 +347,7 @@ main(int argc, char *argv[]) if (argc < 2) { - fprintf(stderr, "Usage: %s [flags] command [flags]\n", MyName); - exit(EX_USAGE); + usage(); } argv[argc] = NULL; @@ -392,11 +393,27 @@ main(int argc, char *argv[]) SccsPath = "."; } + if (*argv == NULL) + { + usage(); + } i = command(argv, FALSE, ""); exit(i); } /* +** USAGE -- print usage +** +** This function prints the usage for this program. +*/ +static void +usage(void) +{ + fprintf(stderr, "Usage: %s [flags] command [flags]\n", MyName); + exit(EX_USAGE); +} + +/* ** COMMAND -- look up and perform a command ** ** This routine is the guts of this program. Given an