mirror of
https://github.com/sigmasternchen/libsfuid
synced 2025-03-16 00:19:07 +00:00
added help + better error messages
This commit is contained in:
parent
f06c8f68b1
commit
c8bd4d71ab
1 changed files with 25 additions and 11 deletions
36
main.c
36
main.c
|
@ -58,7 +58,7 @@ unsigned long long convertFromString(const char* string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
error("Parsing error.\n");
|
error("Parsing error.\nUnexpected character '%c'.\n", string[i]);
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ settings_t getSettings() {
|
||||||
maxBits = findMax(maxValue);
|
maxBits = findMax(maxValue);
|
||||||
|
|
||||||
if (maxBits <= 0) {
|
if (maxBits <= 0) {
|
||||||
error("length or charset is too big.");
|
error("Length or charset is too big. This should not have happend.\n");
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,26 +258,37 @@ void prepareCharset() {
|
||||||
charset = inflatedCharset;
|
charset = inflatedCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
void help(const char* name) {
|
||||||
int opt;
|
printf("SYNOPSIS: %s [OPTIONS] INPUT\n\n", name);
|
||||||
|
printf("options: \n");
|
||||||
|
printf(" -e encode INPUT (default)\n");
|
||||||
|
printf(" -d decode INPUT\n");
|
||||||
|
printf(" -l LENGTH set the length (default: 10)\n");
|
||||||
|
printf(" -c CHARSET set the charset (default: a-zA-Z0-9)\n");
|
||||||
|
printf(" -o OFFSET set the offset (default: 5)\n");
|
||||||
|
printf(" -v enable verbose mode\n");
|
||||||
|
printf(" -h show this help message\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
bool decodeMode = false;
|
bool decodeMode = false;
|
||||||
|
|
||||||
|
int opt;
|
||||||
char* endptr;
|
char* endptr;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "o:c:l:dev")) != -1) {
|
while((opt = getopt(argc, argv, "o:c:l:devh")) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'o':
|
case 'o':
|
||||||
offset = strtol(optarg, &endptr, 10);
|
offset = strtol(optarg, &endptr, 10);
|
||||||
if (*endptr != 0) {
|
if (*endptr != 0) {
|
||||||
error("Argument for -o has to be a number.\n");
|
error("Argument for -o has to be a number.\nTry -h to get help.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
resultLength = strtol(optarg, &endptr, 10);
|
resultLength = strtol(optarg, &endptr, 10);
|
||||||
if (*endptr != 0) {
|
if (*endptr != 0) {
|
||||||
error("Argument of -l has to be a number.\n");
|
error("Argument of -l has to be a number.\nTry -h to get help.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -293,14 +304,17 @@ int main(int argc, char** argv) {
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
help(argv[0]);
|
||||||
|
exit(0);
|
||||||
default:
|
default:
|
||||||
error("Unknown option.\n");
|
error("Unknown option.\nTry -h to get help.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc) {
|
if (optind >= argc) {
|
||||||
error("Expected data after options.\n");
|
error("Expected data after options.\nTry -h to get help.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,12 +336,12 @@ int main(int argc, char** argv) {
|
||||||
} else {
|
} else {
|
||||||
unsigned long long value = strtoll(argv[optind], &endptr, 10);
|
unsigned long long value = strtoll(argv[optind], &endptr, 10);
|
||||||
if (*endptr != 0) {
|
if (*endptr != 0) {
|
||||||
error("Value has to be a number.\n");
|
error("Value has to be a number for encoding.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
value += offset;
|
value += offset;
|
||||||
if (value > settings.max) {
|
if (value > settings.max) {
|
||||||
error("value is too big!\n");
|
error("value is too big!\nThe maximum value for the current settings is %llu.\n", settings.max - offset);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
verbose("encode mode\n");
|
verbose("encode mode\n");
|
||||||
|
|
Loading…
Reference in a new issue