Enhancement in option parsing errors
Telling getopt to produce an error message by setting opterr to 1
This commit is contained in:
parent
d89f8a64e5
commit
42457370ba
1 changed files with 3 additions and 10 deletions
|
|
@ -65,7 +65,7 @@ ttail_t *ttail_init(int argc, char **argv)
|
||||||
goto ttail_init_alloc_err;
|
goto ttail_init_alloc_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 1;
|
||||||
optind = 0;
|
optind = 0;
|
||||||
res->verbose = 0;
|
res->verbose = 0;
|
||||||
res->fmt = NULL;
|
res->fmt = NULL;
|
||||||
|
|
@ -151,13 +151,8 @@ given\n");
|
||||||
strcpy(date, optarg);
|
strcpy(date, optarg);
|
||||||
dates[c=='d'?0:1] = date;
|
dates[c=='d'?0:1] = date;
|
||||||
break;
|
break;
|
||||||
case '?':
|
default: /* ? */
|
||||||
optind--;
|
goto ttail_init_err;
|
||||||
goto init_badarg;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "Bad argument\n");
|
|
||||||
goto init_badarg;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -177,8 +172,6 @@ given\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
init_badarg:
|
|
||||||
fprintf(stderr, "Unknown option '%s'\n", argv[optind]);
|
|
||||||
ttail_init_err:
|
ttail_init_err:
|
||||||
if(dates[0]) { free(dates[0]); }
|
if(dates[0]) { free(dates[0]); }
|
||||||
if(dates[1]) { free(dates[1]); }
|
if(dates[1]) { free(dates[1]); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue