[hackers] [sbase] revert to per-cmd usage() || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Tue, 15 May 2012 14:32:58 +0200 (CEST)

changeset: 119:689e16ec4400
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Tue May 15 13:32:56 2012 +0100
files: basename.c cksum.c kill.c test.c util.h util/eprintf.c yes.c
description:
revert to per-cmd usage()


diff -r 118a80a266bf -r 689e16ec4400 basename.c
--- a/basename.c Mon May 14 21:30:02 2012 +0100
+++ b/basename.c Tue May 15 13:32:56 2012 +0100
_AT_@ -5,7 +5,7 @@
 #include <string.h>
 #include "util.h"
 
-#define USAGE() usage("name [suffix]")
+static void usage(void);
 
 int
 main(int argc, char *argv[])
_AT_@ -15,11 +15,11 @@
 
         ARGBEGIN {
         default:
- USAGE();
+ usage();
         } ARGEND;
 
         if(argc < 1)
- USAGE();
+ usage();
 
         s = basename(argv[0]);
         if(argc == 2 && argv[1]) {
_AT_@ -31,3 +31,9 @@
 
         return EXIT_SUCCESS;
 }
+
+void
+usage(void)
+{
+ eprintf("usage: %s name [suffix]\n", argv0);
+}
diff -r 118a80a266bf -r 689e16ec4400 cksum.c
--- a/cksum.c Mon May 14 21:30:02 2012 +0100
+++ b/cksum.c Tue May 15 13:32:56 2012 +0100
_AT_@ -5,9 +5,8 @@
 #include <unistd.h>
 #include "util.h"
 
-#define USAGE() usage("[files...]")
-
 static void cksum(int, const char *);
+static void usage(void);
 
 static const unsigned long crctab[] = { 0x00000000,
 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
_AT_@ -70,7 +69,7 @@
 
         ARGBEGIN {
         default:
- USAGE();
+ usage();
         } ARGEND;
 
         if(argc == 0)
_AT_@ -106,3 +105,9 @@
                 printf(" %s", s);
         putchar('\n');
 }
+
+void
+usage(void)
+{
+ eprintf("usage: %s [files...]\n", argv0);
+}
diff -r 118a80a266bf -r 689e16ec4400 kill.c
--- a/kill.c Mon May 14 21:30:02 2012 +0100
+++ b/kill.c Tue May 15 13:32:56 2012 +0100
_AT_@ -8,8 +8,6 @@
 #include <sys/wait.h>
 #include "util.h"
 
-#define USAGE() killusage()
-
 struct {
         const char *name;
         int sig;
_AT_@ -21,7 +19,7 @@
 #undef SIG
 };
 
-static void killusage(void);
+static void usage(void);
 
 int
 main(int argc, char *argv[])
_AT_@ -50,10 +48,10 @@
                                 eprintf("%s: unknown signal\n", optarg);
                         break;
                 default:
- USAGE();
+ usage();
                 }
         if(optind < argc-1)
- USAGE();
+ usage();
 
         if(lflag) {
                 sig = (optind == argc) ? 0 : estrtol(argv[optind], 0);
_AT_@ -73,8 +71,8 @@
 }
 
 void
-killusage(void)
+usage(void)
 {
- fprintf(stderr, "usage: %s [-s signal] [pid...]\n"
- " %s -l [signum]\n", argv0, argv0);
+ eprintf("usage: %s [-s signal] [pid...]\n"
+ " %s -l [signum]\n", argv0, argv0);
 }
diff -r 118a80a266bf -r 689e16ec4400 test.c
--- a/test.c Mon May 14 21:30:02 2012 +0100
+++ b/test.c Tue May 15 13:32:56 2012 +0100
_AT_@ -7,11 +7,9 @@
 #include <sys/stat.h>
 #include "util.h"
 
-#define USAGE() testusage()
-
 static bool unary(const char *, const char *);
 static bool binary(const char *, const char *, const char *);
-static void testusage(void);
+static void usage(void);
 
 int
 main(int argc, char *argv[])
_AT_@ -23,7 +21,7 @@
         /* [ ... ] alias */
         if(!strcmp(argv[0], "[")) {
                 if(strcmp(argv[argc-1], "]") != 0)
- USAGE();
+ usage();
                 argc--;
         }
         if(argc > 1 && !strcmp(argv[1], "!")) {
_AT_@ -42,7 +40,7 @@
                 ret = binary(argv[1], argv[2], argv[3]);
                 break;
         default:
- USAGE();
+ usage();
         }
         if(not)
                 ret = !ret;
_AT_@ -56,7 +54,7 @@
         int r;
 
         if(op[0] != '-' || op[1] == '\0' || op[2] != '\0')
- USAGE();
+ usage();
         switch(op[1]) {
         case 'b': case 'c': case 'd': case 'f': case 'g':
         case 'p': case 'S': case 's': case 'u':
_AT_@ -99,7 +97,7 @@
         case 'z':
                 return arg[0] == '\0';
         default:
- USAGE();
+ usage();
         }
         return false; /* should not reach */
 }
_AT_@ -112,7 +110,7 @@
 }
 
 void
-testusage(void)
+usage(void)
 {
         const char *ket = (*argv0 == '[') ? " ]" : "";
 
diff -r 118a80a266bf -r 689e16ec4400 util.h
--- a/util.h Mon May 14 21:30:02 2012 +0100
+++ b/util.h Tue May 15 13:32:56 2012 +0100
_AT_@ -40,4 +40,3 @@
 void fnck(const char *, const char *, int (*)(const char *, const char *));
 void putword(const char *);
 void recurse(const char *, void (*)(const char *));
-void usage(const char *);
diff -r 118a80a266bf -r 689e16ec4400 util/eprintf.c
--- a/util/eprintf.c Mon May 14 21:30:02 2012 +0100
+++ b/util/eprintf.c Tue May 15 13:32:56 2012 +0100
_AT_@ -30,13 +30,6 @@
 }
 
 void
-usage(const char *s)
-{
- fprintf(stderr, "usage: %s %s\n", argv0, s);
- exit(EXIT_FAILURE);
-}
-
-void
 venprintf(int status, const char *fmt, va_list ap)
 {
         /*fprintf(stderr, "%s: ", argv0);*/
diff -r 118a80a266bf -r 689e16ec4400 yes.c
--- a/yes.c Mon May 14 21:30:02 2012 +0100
+++ b/yes.c Tue May 15 13:32:56 2012 +0100
_AT_@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include "util.h"
 
-#define USAGE() usage("[string]")
+static void usage(void);
 
 int
 main(int argc, char *argv[])
_AT_@ -12,7 +12,7 @@
 
         ARGBEGIN {
         default:
- USAGE();
+ usage();
         } ARGEND;
 
         switch(argc) {
_AT_@ -24,7 +24,13 @@
                         puts(s);
                 break;
         default:
- USAGE();
+ usage();
         }
         return EXIT_FAILURE; /* should not reach */
 }
+
+void
+usage(void)
+{
+ eprintf("usage: %s [string]\n", argv0);
+}
Received on Tue May 15 2012 - 14:32:58 CEST

This archive was generated by hypermail 2.3.0 : Tue May 15 2012 - 14:36:08 CEST