mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:17:35 +00:00
seq: Add help option
Added a help option to the seq command that gives usage information. Further, when a user gives an incorrect argument, usage is supplied on stderr.
This commit is contained in:
parent
7b481a2c73
commit
a45ba638a7
1 changed files with 23 additions and 1 deletions
|
@ -30,12 +30,26 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
const char* g_usage = R"(Usage:
|
||||||
|
seq [-h|--help]
|
||||||
|
seq LAST
|
||||||
|
seq FIRST LAST
|
||||||
|
seq FIRST INCREMENT LAST
|
||||||
|
)";
|
||||||
|
|
||||||
|
static void print_usage(FILE* stream)
|
||||||
|
{
|
||||||
|
fprintf(stream, g_usage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static double get_double(const char* name, const char* d_string, int* number_of_decimals)
|
static double get_double(const char* name, const char* d_string, int* number_of_decimals)
|
||||||
{
|
{
|
||||||
char* end;
|
char* end;
|
||||||
double d = strtod(d_string, &end);
|
double d = strtod(d_string, &end);
|
||||||
if (d == 0 && end == d_string) {
|
if (d == 0 && end == d_string) {
|
||||||
fprintf(stderr, "%s: invalid double value \"%s\"\n", name, d_string);
|
fprintf(stderr, "%s: invalid argument \"%s\"\n", name, d_string);
|
||||||
|
print_usage(stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (char* dot = strchr(d_string, '.'))
|
if (char* dot = strchr(d_string, '.'))
|
||||||
|
@ -56,6 +70,13 @@ int main(int argc, const char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
||||||
|
print_usage(stdout);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double start = 1, step = 1, end = 1;
|
double start = 1, step = 1, end = 1;
|
||||||
int number_of_start_decimals = 0, number_of_step_decimals = 0, number_of_end_decimals = 0;
|
int number_of_start_decimals = 0, number_of_step_decimals = 0, number_of_end_decimals = 0;
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
|
@ -73,6 +94,7 @@ int main(int argc, const char* argv[])
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "%s: unexpected number of arguments\n", argv[0]);
|
fprintf(stderr, "%s: unexpected number of arguments\n", argv[0]);
|
||||||
|
print_usage(stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue