]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Use char type for short options instead of a string.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 19 Feb 2016 14:36:00 +0000 (16:36 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 20 Feb 2016 10:53:49 +0000 (12:53 +0200)
The ":" = "has parameters" can be determined from the type.
Also removed "?" checks since it wasn't actually used.

src/doveadm/doveadm-cmd.c
src/doveadm/doveadm-cmd.h
src/doveadm/doveadm-mail-mailbox-metadata.c
src/doveadm/doveadm-mail-mailbox-status.c
src/doveadm/doveadm-mail-mailbox.c
src/doveadm/doveadm-mail.c
src/doveadm/doveadm-mail.h

index c0e3f587658882534bcc47ad8b013afe977d6f29..cb3bdedb5bc2718c000dc3dadfaa2879de9fc0bf 100644 (file)
@@ -250,9 +250,8 @@ doveadm_cmd_params_to_argv(const char *name, int pargc, const struct doveadm_cmd
        i_assert(array_count(argv) == 0);
        array_append(argv, &name, 1);
        for(i=0;i<pargc;i++) {
-               if (params[i].value_set && params[i].opt != NULL &&
-                       *(params[i].opt) != ':' && *(params[i].opt) != '?') {
-                       const char *optarg = t_strdup_printf("-%c", params[i].opt[0]);
+               if (params[i].value_set && params[i].short_opt != '\0') {
+                       const char *optarg = t_strdup_printf("-%c", params[i].short_opt);
                        if (params[i].type == CMD_PARAM_STR) {
                                array_append(argv, &optarg, 1);
                                array_append(argv, &params[i].value.v_string,1);
@@ -297,28 +296,17 @@ doveadm_build_options(const struct doveadm_cmd_param par[],
                string_t *shortopts,
                ARRAY_TYPE(getopt_option_array) *longopts)
 {
-       const char *optp;
        for(size_t i=0; par[i].name != NULL; i++) {
                struct option longopt;
                if ((par[i].flags & CMD_PARAM_FLAG_DO_NOT_EXPOSE) != 0) continue;
                longopt.name = par[i].name;
                longopt.flag = 0;
                longopt.val = 0;
-               if (par[i].opt) {
-                       optp = par[i].opt;
-                       if (*optp != ':' && *optp != '?') {
-                               longopt.val = *optp;
-                               str_append_c(shortopts, *optp);
-                               optp++;
-                               if (optp[0] != '\0')
-                                       str_append_c(shortopts, *optp);
-                       }
-                       switch(*optp) {
-                       case ':': longopt.has_arg = 1; break;
-                       case '?': longopt.has_arg = 2; break;
-                       default:
-                               longopt.has_arg = 0;
-                       }
+               if (par[i].short_opt != '\0') {
+                       longopt.val = par[i].short_opt;
+                       str_append_c(shortopts, par[i].short_opt);
+                       if (par[i].type != CMD_PARAM_BOOL)
+                               str_append_c(shortopts, ':');
                } else {
                        longopt.has_arg = 0;
                }
index 3e6732f9a6d9bcfa0b5355fff9f5159e9b24eedb..70b2345ddef567303b9d289143a9a9504e770ec5 100644 (file)
@@ -2,8 +2,8 @@
 #define DOVEADM_CMD_H
 
 #define DOVEADM_CMD_PARAMS_START .parameters = (const struct doveadm_cmd_param[]){
-#define DOVEADM_CMD_PARAM(optP, nameP, typeP, flagP ) { .opt = optP, .name = nameP, .type = typeP, .flags = flagP },
-#define DOVEADM_CMD_PARAMS_END { .opt = NULL, .name = NULL, .type = CMD_PARAM_BOOL, .flags = CMD_PARAM_FLAG_NONE } }
+#define DOVEADM_CMD_PARAM(optP, nameP, typeP, flagP ) { .short_opt = optP, .name = nameP, .type = typeP, .flags = flagP },
+#define DOVEADM_CMD_PARAMS_END { .short_opt = '\0', .name = NULL, .type = CMD_PARAM_BOOL, .flags = CMD_PARAM_FLAG_NONE } }
 
 struct doveadm_cmd_ver2;
 struct doveadm_mail_cmd_context;
@@ -25,7 +25,7 @@ typedef enum {
 } doveadm_cmd_param_flag_t;
 
 struct doveadm_cmd_param {
-       const char *opt;
+       char short_opt;
        const char *name;
        doveadm_cmd_param_t type;
        bool value_set;
index bc185fc72113a4fe7311773316798ac410a03812..5a342a099f7b28d8df0145183f4af750efd437a1 100644 (file)
@@ -292,9 +292,9 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_set_ver2 = {
        .usage = "<mailbox> <key> <value>",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM(":", "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM(":", "value", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "value", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -304,8 +304,8 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_unset_ver2 = {
        .usage = "<mailbox> <key>",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM(":", "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -315,8 +315,8 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_get_ver2 = {
        .usage = "<mailbox> <key>",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM(":", "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "key", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -326,6 +326,6 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_metadata_list_ver2 = {
        .usage = "<mailbox> [<key prefix>]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM(":", "key-prefix", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "key-prefix", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
index 6c950ef65dbaadcade8c14e6b14ddd711665c2be..4ea4c841ce2a5b07e672836b7beb2e4e1fffc55c 100644 (file)
@@ -253,9 +253,9 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_status_ver2 = {
         .usage = "<mailbox> [...]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM("t", "total-sum", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM("f:", "field", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM(":", "fieldstr", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL | CMD_PARAM_FLAG_DO_NOT_EXPOSE) /* FIXME: horrible hack, remove me when possible */
-DOVEADM_CMD_PARAM(":", "mask", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('t', "total-sum", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('f', "field", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "fieldstr", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL | CMD_PARAM_FLAG_DO_NOT_EXPOSE) /* FIXME: horrible hack, remove me when possible */
+DOVEADM_CMD_PARAM('\0', "mask", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
index 65544b2cceb09d5cd5d2c9277ee6c45f17f8ad3a..bf290be978f0cca17c71df4894553bad6065e7eb 100644 (file)
@@ -562,10 +562,10 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_list_ver2 = {
        .usage = "[-7|-8] [-s] [<mailbox mask> [...]]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM("7", "mutf7", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM("8", "no-mutf7", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM("s", "subscriptions", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM(":", "mask", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('7', "mutf7", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('8', "no-mutf7", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('s', "subscriptions", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('\0', "mask", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -575,9 +575,9 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_create_ver2 = {
        .usage = "[-s] [-g <guid>] <mailbox> [...]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM("s", "subscriptions", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM("g", "guid", CMD_PARAM_STR, 0)
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('s', "subscriptions", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('g', "guid", CMD_PARAM_STR, 0)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -587,8 +587,8 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_delete_ver2 = {
         .usage = "[-s] <mailbox> [...]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM("s", "subscriptions", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('s', "subscriptions", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -598,9 +598,9 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_rename_ver2 = {
        .usage = "[-s] <old name> <new name>",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM("s", "subscriptions", CMD_PARAM_BOOL, 0)
-DOVEADM_CMD_PARAM(":", "old", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
-DOVEADM_CMD_PARAM(":", "new", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('s', "subscriptions", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('\0', "old", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "new", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -610,7 +610,7 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_subscribe_ver2 = {
        .usage = "<mailbox> [...]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
 
@@ -620,6 +620,6 @@ struct doveadm_cmd_ver2 doveadm_cmd_mailbox_unsubscribe_ver2 = {
        .usage = "<mailbox> [...]",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_MAIL_COMMON
-DOVEADM_CMD_PARAM(":", "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "mailbox", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 };
index 7647b752fa14f6d2f631ed6f04ea2355ad8f5aa1..671a8693ebc24a9891b37f9084675df37c64a370 100644 (file)
@@ -919,10 +919,9 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(const struct doveadm_cmd_ver2* cmd,
                        ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
                        wildcard_user = "*";
                        ctx->users_list_input = argv[i].value.v_istream;
-               } else if (ctx->v.parse_arg != NULL && argv[i].opt != NULL &&
-                          *(argv[i]).opt != '?' && *(argv[i]).opt != ':') {
+               } else if (ctx->v.parse_arg != NULL && argv[i].short_opt != '\0') {
                        optarg = (char*)argv[i].value.v_string;
-                       ctx->v.parse_arg(ctx, *(argv[i].opt));
+                       ctx->v.parse_arg(ctx, argv[i].short_opt);
                } else if ((argv[i].flags & CMD_PARAM_FLAG_POSITIONAL) != 0) {
                        /* feed this into pargv */
                        if (argv[i].type == CMD_PARAM_ARRAY)
index a70e9820331ce1361e62eaca878eff5bcbe505aa..aed7848e0cc9bddfc909f8527084802c72050bc4 100644 (file)
@@ -197,9 +197,9 @@ extern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_subscribe_ver2;
 extern struct doveadm_cmd_ver2 doveadm_cmd_mailbox_unsubscribe_ver2;
 
 #define DOVEADM_CMD_MAIL_COMMON \
-DOVEADM_CMD_PARAM("A", "all-users", CMD_PARAM_BOOL, 0) \
-DOVEADM_CMD_PARAM("S:", "socket-path", CMD_PARAM_STR, 0) \
-DOVEADM_CMD_PARAM("u:", "user", CMD_PARAM_STR, 0) \
-DOVEADM_CMD_PARAM("F:", "user-file", CMD_PARAM_ISTREAM, 0)
+DOVEADM_CMD_PARAM('A', "all-users", CMD_PARAM_BOOL, 0) \
+DOVEADM_CMD_PARAM('S', "socket-path", CMD_PARAM_STR, 0) \
+DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0) \
+DOVEADM_CMD_PARAM('F', "user-file", CMD_PARAM_ISTREAM, 0)
 
 #endif