Use arg.h as much as possible and add usage() where missing

Rename eusage() to usage() as well.
This commit is contained in:
sin 2013-10-07 17:13:01 +01:00
parent 5b5f062184
commit f349dd5987
4 changed files with 29 additions and 11 deletions

10
nice.c
View File

@ -6,7 +6,7 @@
#include <unistd.h> #include <unistd.h>
#include "util.h" #include "util.h"
static void eusage(void); static void usage(void);
int int
main(int argc, char **argv) main(int argc, char **argv)
@ -15,15 +15,15 @@ main(int argc, char **argv)
ARGBEGIN { ARGBEGIN {
case 'n': case 'n':
val = estrtol(EARGF(eusage()), 10); val = estrtol(EARGF(usage()), 10);
break; break;
default: default:
eusage(); usage();
break; break;
} ARGEND; } ARGEND;
if(argc == 0) if(argc == 0)
eusage(); usage();
errno = 0; errno = 0;
nice((int)MAX(INT_MIN, MIN(val, INT_MAX))); nice((int)MAX(INT_MIN, MIN(val, INT_MAX)));
@ -38,7 +38,7 @@ main(int argc, char **argv)
} }
static void static void
eusage(void) usage(void)
{ {
eprintf("usage: nice [-n inc] command [options ...]\n"); eprintf("usage: nice [-n inc] command [options ...]\n");
} }

View File

@ -1,14 +1,26 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "util.h"
extern char **environ; extern char **environ;
static void
usage(void)
{
eprintf("usage: %s [variable...]\n", argv0);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *var; char *var;
ARGBEGIN {
default:
usage();
} ARGEND;
if(argc == 1) { if(argc == 1) {
while(*environ) while(*environ)
printf("%s\n", *environ++); printf("%s\n", *environ++);

View File

@ -11,7 +11,7 @@
static int strtop(const char *); static int strtop(const char *);
static bool renice(int, int, long); static bool renice(int, int, long);
static void eusage(void); static void usage(void);
int int
main(int argc, char **argv) main(int argc, char **argv)
@ -22,7 +22,7 @@ main(int argc, char **argv)
ARGBEGIN { ARGBEGIN {
case 'n': case 'n':
adj = EARGF(eusage()); adj = EARGF(usage());
break; break;
case 'g': case 'g':
which = PRIO_PGRP; which = PRIO_PGRP;
@ -34,12 +34,12 @@ main(int argc, char **argv)
which = PRIO_USER; which = PRIO_USER;
break; break;
default: default:
eusage(); usage();
break; break;
} ARGEND; } ARGEND;
if(argc == 0 || !adj) if(argc == 0 || !adj)
eusage(); usage();
val = estrtol(adj, 10); val = estrtol(adj, 10);
for(i = 0; i < argc; i++) { for(i = 0; i < argc; i++) {
@ -112,7 +112,7 @@ renice(int which, int who, long adj)
} }
static void static void
eusage(void) usage(void)
{ {
eprintf("renice -n inc [-g | -p | -u] ID ...\n"); eprintf("renice -n inc [-g | -p | -u] ID ...\n");
} }

8
wc.c
View File

@ -14,6 +14,12 @@ static bool wflag = false;
static char cmode = 0; static char cmode = 0;
static long tc = 0, tl = 0, tw = 0; static long tc = 0, tl = 0, tw = 0;
static void
usage(void)
{
eprintf("usage: %s [-clmw] [files...]\n", argv0);
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -34,7 +40,7 @@ main(int argc, char *argv[])
wflag = true; wflag = true;
break; break;
default: default:
eprintf("usage: %s [-clmw] [files...]\n", argv0); usage();
} ARGEND; } ARGEND;
if (argc == 0) { if (argc == 0) {