diff options
author | pjd <pjd@FreeBSD.org> | 2010-09-13 13:48:18 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2010-09-13 13:48:18 +0000 |
commit | 3d8ce965d3cc7199c39bd29a375291b4276bab53 (patch) | |
tree | 80fa9ced0ed4ae38bb90b62555eb33be45347414 /sbin/geom/core | |
parent | 7dc7517414123c9d33d848a1cb615f3adbb59e51 (diff) | |
download | FreeBSD-src-3d8ce965d3cc7199c39bd29a375291b4276bab53.zip FreeBSD-src-3d8ce965d3cc7199c39bd29a375291b4276bab53.tar.gz |
- Remove gc_argname field. It was introduced for gpart(8), but if I
understand everything correctly, we don't really need it.
- Provide default numeric value as strings. This allows to simplify
a lot of code.
- Bump version number.
Diffstat (limited to 'sbin/geom/core')
-rw-r--r-- | sbin/geom/core/geom.c | 51 | ||||
-rw-r--r-- | sbin/geom/core/geom.h | 5 |
2 files changed, 19 insertions, 37 deletions
diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index b891098..4a3dcd4 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -75,8 +75,8 @@ static void std_load(struct gctl_req *req, unsigned flags); static void std_unload(struct gctl_req *req, unsigned flags); struct g_command std_commands[] = { - { "help", 0, std_help, G_NULL_OPTS, NULL, NULL }, - { "list", 0, std_list, G_NULL_OPTS, NULL, + { "help", 0, std_help, G_NULL_OPTS, NULL }, + { "list", 0, std_list, G_NULL_OPTS, "[name ...]" }, { "status", 0, std_status, @@ -84,11 +84,11 @@ struct g_command std_commands[] = { { 's', "script", NULL, G_TYPE_BOOL }, G_OPT_SENTINEL }, - NULL, "[-s] [name ...]" + "[-s] [name ...]" }, { "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS, - NULL, NULL }, - { "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL, NULL }, + NULL }, + { "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL }, G_CMD_SENTINEL }; @@ -129,8 +129,6 @@ usage_command(struct g_command *cmd, const char *prefix) if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL) fprintf(stderr, "]"); } - if (cmd->gc_argname) - fprintf(stderr, " %s", cmd->gc_argname); fprintf(stderr, "\n"); } @@ -348,39 +346,24 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc, warnx("Option '%c' not specified.", opt->go_char); usage(); + } else if (G_OPT_TYPE(opt) == G_TYPE_ASCNUM && + *(const char *)opt->go_val == '\0') { + ; /* add nothing. */ } else { - if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) { - gctl_ro_param(req, opt->go_name, - sizeof(intmax_t), opt->go_val); - } else if (G_OPT_TYPE(opt) == G_TYPE_STRING || - G_OPT_TYPE(opt) == G_TYPE_ASCNUM) { - if (cmd->gc_argname == NULL || - opt->go_val == NULL || - *(const char *)opt->go_val != '\0') - gctl_ro_param(req, opt->go_name, - -1, opt->go_val); - } else { - assert(!"Invalid type"); - } + set_option(req, opt, opt->go_val); } } } - if (cmd->gc_argname == NULL) { - /* - * Add rest of given arguments. - */ - gctl_ro_param(req, "nargs", sizeof(int), argc); - for (i = 0; i < (unsigned)*argc; i++) { - char argname[16]; + /* + * Add rest of given arguments. + */ + gctl_ro_param(req, "nargs", sizeof(int), argc); + for (i = 0; i < (unsigned)*argc; i++) { + char argname[16]; - snprintf(argname, sizeof(argname), "arg%u", i); - gctl_ro_param(req, argname, -1, (*argv)[i]); - } - } else { - if (*argc != 1) - usage(); - gctl_ro_param(req, cmd->gc_argname, -1, (*argv)[0]); + snprintf(argname, sizeof(argname), "arg%u", i); + gctl_ro_param(req, argname, -1, (*argv)[i]); } } diff --git a/sbin/geom/core/geom.h b/sbin/geom/core/geom.h index e2f96e9..92c97a3 100644 --- a/sbin/geom/core/geom.h +++ b/sbin/geom/core/geom.h @@ -28,7 +28,7 @@ #ifndef _GEOM_H_ #define _GEOM_H_ -#define G_LIB_VERSION 4 +#define G_LIB_VERSION 5 #define G_FLAG_NONE 0x0000 #define G_FLAG_VERBOSE 0x0001 @@ -49,7 +49,7 @@ #define G_OPT_SENTINEL { '\0', NULL, NULL, G_TYPE_NONE } #define G_NULL_OPTS { G_OPT_SENTINEL } -#define G_CMD_SENTINEL { NULL, 0, NULL, G_NULL_OPTS, NULL, NULL } +#define G_CMD_SENTINEL { NULL, 0, NULL, G_NULL_OPTS, NULL } struct g_option { char go_char; @@ -63,7 +63,6 @@ struct g_command { unsigned gc_flags; void (*gc_func)(struct gctl_req *, unsigned); struct g_option gc_options[G_OPT_MAX]; - const char *gc_argname; const char *gc_usage; }; #endif /* !_GEOM_H_ */ |