handle our own flag errors

This commit is contained in:
anon
2025-01-24 11:34:15 +01:00
parent f0319cf147
commit b07b6c75c4
3 changed files with 11 additions and 4 deletions

View File

@ -5,9 +5,11 @@
#include <string.h>
#include <getopt.h>
#include "global.h"
#include "error.h"
#include "dictate.h"
void usage() {
static
void usage(void) {
dictate(
"$B$gvimdir$0 $y[$boptions$y] <$bpath$y>$0\n"
" $B$g-h$0 : print help\n"
@ -44,6 +46,9 @@ void get_env(void) {
void parse_args(int argc, char * * argv) {
int opt;
opterr = 0; // suppress default getopt error messages
while ((opt = getopt(argc, argv, "hnpor")) != -1) {
switch (opt) {
case 'h': {
@ -62,11 +67,11 @@ void parse_args(int argc, char * * argv) {
case 'r': {
is_recursive = true;
} break;
default: {
fprintf(stderr, "Unknown option: -%c\n", optopt);
case '?': {
errorn(E_FLAG, optopt);
usage();
exit(1);
} break;
}
}
}