uptime: new usage & fix coding style
Coding style fixed and more readable help output. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
61db37d48f
commit
05765771c2
52
uptime.c
52
uptime.c
@ -1,17 +1,45 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include "proc/whattime.h"
|
#include "proc/whattime.h"
|
||||||
#include "proc/version.h"
|
#include "proc/version.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
static void __attribute__ ((__noreturn__))
|
||||||
if(argc == 1) {
|
usage(FILE * out)
|
||||||
print_uptime();
|
{
|
||||||
return 0;
|
fprintf(out,
|
||||||
}
|
"\nUsage: %s [options]\n"
|
||||||
if((argc == 2) && (!strcmp(argv[1], "-V"))) {
|
"\nOptions:\n", program_invocation_short_name);
|
||||||
display_version();
|
fprintf(out,
|
||||||
return 0;
|
" -h, --help display this help text\n"
|
||||||
}
|
" -V, --version display version information and exit\n");
|
||||||
fprintf(stderr, "usage: uptime [-V]\n -V display version\n");
|
fprintf(out, "\nFor more information see uptime(1).\n");
|
||||||
return 1;
|
|
||||||
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
static const struct option longopts[] = {
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{"version", no_argument, NULL, 'V'},
|
||||||
|
{NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1)
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
usage(stdout);
|
||||||
|
case 'V':
|
||||||
|
display_version();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
default:
|
||||||
|
usage(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_uptime();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user