Mercurial > hg > index.cgi
diff lwlib/lw_cmdline.c @ 441:b138b4005125
Make missing command line arguments fail properly
Actually make lwasm, lwlink, and lwar exit with a nonzero status if command
line argument parsing fails due to missing arguments. This required
adjustments to lw_cmdline to return error codes in those cases.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 27 Nov 2017 22:35:53 -0700 |
parents | 8e25147c2aa8 |
children |
line wrap: on
line diff
--- a/lwlib/lw_cmdline.c Mon Nov 27 22:21:42 2017 -0700 +++ b/lwlib/lw_cmdline.c Mon Nov 27 22:35:53 2017 -0700 @@ -19,6 +19,7 @@ this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -380,7 +381,7 @@ int nextarg; char *tstr; int cch; - + /* first, permute the argv array so that all option arguments are at the start */ for (i = 1, firstarg = 1; i < argc; i++) { @@ -496,7 +497,7 @@ fprintf(stderr, "Unknown option '%c'. See %s --usage.\n", argv[i][cch - 1], argv[0]); else fprintf(stderr, "Unknown option '%s'. See %s --usage.\n", argv[i - 1], argv[0]); - exit(1); + return EINVAL; } if (parser -> options[j].arg) { @@ -516,7 +517,7 @@ if (!tstr && (parser -> options[j].flags & lw_cmdline_opt_optional) == 0) { fprintf(stderr, "Option %s requires argument.\n", parser -> options[j].name); - continue; + return EINVAL; } } r = (*(parser -> parser))(parser -> options[j].key, tstr, input);