@@ 5,6 5,14 @@
#define TOTAL 300
#define DELAY 200
+static char usage_string[] =
+ "Usage: use_progress [options]...\n\n"
+ "Options:\n"
+ " -t, --total <int> The total progress.\n"
+ " -d, --delay <int> The delay to add.\n"
+ " -m, --message <msg> Set process message.\n"
+ " -h, --help Print this help message and exit.\n";
+
/* Keep the configuration in a struct */
static struct {
int delay;
@@ 37,24 45,27 @@ read_cmd_args(int nargs, char **argv)
for (i=0 ; i < nargs ; i++) {
arg = argv[i];
- if (!strcmp(arg, "--delay") || !strcmp(arg, "-d")) {
+ if (!strcmp(arg, "-d") || !strcmp(arg, "--delay")) {
if (i+1 > nargs) {
printf("Missing integer argument to %s.\n", arg);
exit(EXIT_FAILURE);
}
parse_int_arg(arg, argv[++i], &config.delay);
- } else if (!strcmp(arg, "--total") || !strcmp(arg, "-t")) {
+ } else if (!strcmp(arg, "-t") || !strcmp(arg, "--total")) {
if (i+1 > nargs) {
printf("Missing integer argument to %s.\n", arg);
exit(EXIT_FAILURE);
}
parse_int_arg(arg, argv[++i], &config.total);
- } else if (!strcmp(arg, "--message") || !strcmp(arg, "-m")) {
+ } else if (!strcmp(arg, "-m") || !strcmp(arg, "--message")) {
if (i+1 > nargs) {
printf("Missing string argument to %s.\n", arg);
exit(EXIT_FAILURE);
}
config.msg = argv[++i]; /* No errors here */
+ } else if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) {
+ printf("%s", usage_string);
+ exit(EXIT_SUCCESS);
} else {
if (arg[0] == '-')
printf("Unrecognized option: %s\n", arg);