Use mu_argp_parse.
Showing
7 changed files
with
85 additions
and
28 deletions
... | @@ -53,6 +53,8 @@ static char doc[] = "GNU comsatd"; | ... | @@ -53,6 +53,8 @@ static char doc[] = "GNU comsatd"; |
53 | 53 | ||
54 | static struct argp_option options[] = | 54 | static struct argp_option options[] = |
55 | { | 55 | { |
56 | {NULL, 0, NULL, 0, | ||
57 | "comsatd specific switches:", 0}, | ||
56 | {"config", 'c', "FILE", 0, "Read configuration from FILE", 0}, | 58 | {"config", 'c', "FILE", 0, "Read configuration from FILE", 0}, |
57 | { NULL, 0, NULL, 0, NULL, 0 } | 59 | { NULL, 0, NULL, 0, NULL, 0 } |
58 | }; | 60 | }; |
... | @@ -64,10 +66,17 @@ static struct argp argp = { | ... | @@ -64,10 +66,17 @@ static struct argp argp = { |
64 | comsatd_parse_opt, | 66 | comsatd_parse_opt, |
65 | NULL, | 67 | NULL, |
66 | doc, | 68 | doc, |
67 | mu_daemon_argp_child, | 69 | NULL, |
68 | NULL, NULL | 70 | NULL, NULL |
69 | }; | 71 | }; |
70 | 72 | ||
73 | static const char *comsat_argp_capa[] = { | ||
74 | "mailutils", | ||
75 | "daemon", | ||
76 | "logging", | ||
77 | NULL | ||
78 | }; | ||
79 | |||
71 | #define SUCCESS 0 | 80 | #define SUCCESS 0 |
72 | #define NOT_HERE 1 | 81 | #define NOT_HERE 1 |
73 | #define PERMISSION_DENIED 2 | 82 | #define PERMISSION_DENIED 2 |
... | @@ -106,7 +115,7 @@ comsatd_parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -106,7 +115,7 @@ comsatd_parse_opt (int key, char *arg, struct argp_state *state) |
106 | switch (key) | 115 | switch (key) |
107 | { | 116 | { |
108 | case ARGP_KEY_INIT: | 117 | case ARGP_KEY_INIT: |
109 | state->child_inputs[0] = state->input; | 118 | state->child_inputs[1] = state->input; |
110 | break; | 119 | break; |
111 | 120 | ||
112 | case 'c': | 121 | case 'c': |
... | @@ -124,9 +133,9 @@ int | ... | @@ -124,9 +133,9 @@ int |
124 | main(int argc, char **argv) | 133 | main(int argc, char **argv) |
125 | { | 134 | { |
126 | int c; | 135 | int c; |
127 | 136 | ||
128 | mu_create_argcv (argc, argv, &argc, &argv); | 137 | mu_argp_parse (&argp, &argc, &argv, 0, comsat_argp_capa, |
129 | argp_parse (&argp, argc, argv, 0, 0, &daemon_param); | 138 | NULL, &daemon_param); |
130 | 139 | ||
131 | if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) | 140 | if (daemon_param.timeout > 0 && daemon_param.mode == MODE_DAEMON) |
132 | { | 141 | { | ... | ... |
... | @@ -58,6 +58,8 @@ const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; | ... | @@ -58,6 +58,8 @@ const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
58 | static char doc[] = "GNU frm -- display From: lines"; | 58 | static char doc[] = "GNU frm -- display From: lines"; |
59 | 59 | ||
60 | static struct argp_option options[] = { | 60 | static struct argp_option options[] = { |
61 | {NULL, 0, NULL, 0, | ||
62 | "frm specific switches:", 0}, | ||
61 | {"debug", 'd', NULL, 0, "Enable debugging output", 0}, | 63 | {"debug", 'd', NULL, 0, "Enable debugging output", 0}, |
62 | {"field", 'f', "NAME", 0, | 64 | {"field", 'f', "NAME", 0, |
63 | "Header field to display", 0}, | 65 | "Header field to display", 0}, |
... | @@ -148,10 +150,14 @@ static struct argp argp = { | ... | @@ -148,10 +150,14 @@ static struct argp argp = { |
148 | parse_opt, | 150 | parse_opt, |
149 | NULL, | 151 | NULL, |
150 | doc, | 152 | doc, |
151 | mu_common_argp_child, | 153 | NULL, |
152 | NULL, NULL | 154 | NULL, NULL |
153 | }; | 155 | }; |
154 | 156 | ||
157 | static const char *frm_argp_capa[] = { | ||
158 | "mailutils", | ||
159 | NULL | ||
160 | }; | ||
155 | 161 | ||
156 | /* Retrieve the Personal Name from the header To: or From: */ | 162 | /* Retrieve the Personal Name from the header To: or From: */ |
157 | static int | 163 | static int |
... | @@ -292,8 +298,7 @@ main(int argc, char **argv) | ... | @@ -292,8 +298,7 @@ main(int argc, char **argv) |
292 | int c; | 298 | int c; |
293 | int status = 0; | 299 | int status = 0; |
294 | 300 | ||
295 | mu_create_argcv (argc, argv, &argc, &argv); | 301 | mu_argp_parse (&argp, &argc, &argv, 0, frm_argp_capa, &c, NULL); |
296 | argp_parse (&argp, argc, argv, 0, &c, NULL); | ||
297 | 302 | ||
298 | /* have an argument */ | 303 | /* have an argument */ |
299 | argc -= c; | 304 | argc -= c; | ... | ... |
... | @@ -77,11 +77,13 @@ parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -77,11 +77,13 @@ parse_opt (int key, char *arg, struct argp_state *state) |
77 | { | 77 | { |
78 | case 'c': | 78 | case 'c': |
79 | program_expr = optarg; | 79 | program_expr = optarg; |
80 | *(int *)state->input = state->next; | ||
80 | state->next = state->argc; | 81 | state->next = state->argc; |
81 | break; | 82 | break; |
82 | 83 | ||
83 | case 's': | 84 | case 's': |
84 | program_file = optarg; | 85 | program_file = optarg; |
86 | *(int *)state->input = state->next; | ||
85 | state->next = state->argc; | 87 | state->next = state->argc; |
86 | break; | 88 | break; |
87 | 89 | ||
... | @@ -127,10 +129,11 @@ static struct argp argp = { | ... | @@ -127,10 +129,11 @@ static struct argp argp = { |
127 | parse_opt, | 129 | parse_opt, |
128 | args_doc, | 130 | args_doc, |
129 | doc, | 131 | doc, |
130 | mu_common_argp_child, | 132 | NULL, |
131 | NULL, NULL | 133 | NULL, NULL |
132 | }; | 134 | }; |
133 | 135 | ||
136 | static const char *guimb_argp_capa[] = {"mailutils", NULL}; | ||
134 | 137 | ||
135 | int | 138 | int |
136 | main (int argc, char *argv[]) | 139 | main (int argc, char *argv[]) |
... | @@ -140,9 +143,8 @@ main (int argc, char *argv[]) | ... | @@ -140,9 +143,8 @@ main (int argc, char *argv[]) |
140 | struct guimb_data gd; | 143 | struct guimb_data gd; |
141 | 144 | ||
142 | append_arg (""); | 145 | append_arg (""); |
143 | mu_create_argcv (argc, argv, &argc, &argv); | 146 | mu_argp_parse (&argp, &argc, &argv, 0, guimb_argp_capa, NULL, &c); |
144 | argp_parse (&argp, argc, argv, 0, &c, NULL); | 147 | |
145 | |||
146 | for (; c < argc; c++) | 148 | for (; c < argc; c++) |
147 | append_arg (argv[c]); | 149 | append_arg (argv[c]); |
148 | 150 | ... | ... |
... | @@ -42,6 +42,8 @@ static char doc[] = "GNU imap4d -- the IMAP4D daemon"; | ... | @@ -42,6 +42,8 @@ static char doc[] = "GNU imap4d -- the IMAP4D daemon"; |
42 | 42 | ||
43 | static struct argp_option options[] = | 43 | static struct argp_option options[] = |
44 | { | 44 | { |
45 | {NULL, 0, NULL, 0, | ||
46 | "imap4d specific switches:", 0}, | ||
45 | {"other-namespace", 'O', "PATHLIST", 0, | 47 | {"other-namespace", 'O', "PATHLIST", 0, |
46 | "set the `other' namespace", 0}, | 48 | "set the `other' namespace", 0}, |
47 | {"shared-namespace", 'S', "PATHLIST", 0, | 49 | {"shared-namespace", 'S', "PATHLIST", 0, |
... | @@ -56,10 +58,18 @@ static struct argp argp = { | ... | @@ -56,10 +58,18 @@ static struct argp argp = { |
56 | imap4d_parse_opt, | 58 | imap4d_parse_opt, |
57 | NULL, | 59 | NULL, |
58 | doc, | 60 | doc, |
59 | mu_daemon_argp_child, | 61 | NULL, |
60 | NULL, NULL | 62 | NULL, NULL |
61 | }; | 63 | }; |
62 | 64 | ||
65 | static const char *imap4d_capa[] = { | ||
66 | "mailutils", | ||
67 | "daemon", | ||
68 | "logging", | ||
69 | "auth", | ||
70 | NULL | ||
71 | }; | ||
72 | |||
63 | static int imap4d_mainloop __P ((int, int)); | 73 | static int imap4d_mainloop __P ((int, int)); |
64 | static void imap4d_daemon_init __P ((void)); | 74 | static void imap4d_daemon_init __P ((void)); |
65 | static void imap4d_daemon __P ((unsigned int, unsigned int)); | 75 | static void imap4d_daemon __P ((unsigned int, unsigned int)); |
... | @@ -71,7 +81,7 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -71,7 +81,7 @@ imap4d_parse_opt (int key, char *arg, struct argp_state *state) |
71 | switch (key) | 81 | switch (key) |
72 | { | 82 | { |
73 | case ARGP_KEY_INIT: | 83 | case ARGP_KEY_INIT: |
74 | state->child_inputs[0] = state->input; | 84 | state->child_inputs[1] = state->input; |
75 | break; | 85 | break; |
76 | 86 | ||
77 | case 'O': | 87 | case 'O': |
... | @@ -96,8 +106,7 @@ main (int argc, char **argv) | ... | @@ -96,8 +106,7 @@ main (int argc, char **argv) |
96 | 106 | ||
97 | state = STATE_NONAUTH; /* Starting state in non-auth. */ | 107 | state = STATE_NONAUTH; /* Starting state in non-auth. */ |
98 | 108 | ||
99 | mu_create_argcv (argc, argv, &argc, &argv); | 109 | mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa, NULL, &daemon_param); |
100 | argp_parse (&argp, argc, argv, 0, 0, &daemon_param); | ||
101 | 110 | ||
102 | #ifdef USE_LIBPAM | 111 | #ifdef USE_LIBPAM |
103 | if (!pam_service) | 112 | if (!pam_service) | ... | ... |
... | @@ -31,6 +31,8 @@ static char doc[] = "GNU mail -- the standard /bin/mail interface"; | ... | @@ -31,6 +31,8 @@ static char doc[] = "GNU mail -- the standard /bin/mail interface"; |
31 | static char args_doc[] = "[address...]"; | 31 | static char args_doc[] = "[address...]"; |
32 | 32 | ||
33 | static struct argp_option options[] = { | 33 | static struct argp_option options[] = { |
34 | {NULL, 0, NULL, 0, | ||
35 | "mail specific switches:", 0}, | ||
34 | {"exist", 'e', 0, 0, "Return true if mail exists", 0}, | 36 | {"exist", 'e', 0, 0, "Return true if mail exists", 0}, |
35 | {"file", 'f', "FILE", OPTION_ARG_OPTIONAL, | 37 | {"file", 'f', "FILE", OPTION_ARG_OPTIONAL, |
36 | "Operate on mailbox FILE (default ~/mbox)", 0}, | 38 | "Operate on mailbox FILE (default ~/mbox)", 0}, |
... | @@ -129,10 +131,12 @@ static struct argp argp = { | ... | @@ -129,10 +131,12 @@ static struct argp argp = { |
129 | parse_opt, | 131 | parse_opt, |
130 | args_doc, | 132 | args_doc, |
131 | doc, | 133 | doc, |
132 | mu_common_argp_child, | 134 | NULL, |
133 | NULL, NULL | 135 | NULL, NULL |
134 | }; | 136 | }; |
135 | 137 | ||
138 | static const char *mail_capa[] = { "mailutils", NULL }; | ||
139 | |||
136 | static char * | 140 | static char * |
137 | mail_cmdline(void *closure, int cont) | 141 | mail_cmdline(void *closure, int cont) |
138 | { | 142 | { |
... | @@ -287,9 +291,8 @@ main (int argc, char **argv) | ... | @@ -287,9 +291,8 @@ main (int argc, char **argv) |
287 | args.user = NULL; | 291 | args.user = NULL; |
288 | 292 | ||
289 | /* argument parsing */ | 293 | /* argument parsing */ |
290 | 294 | ||
291 | mu_create_argcv (argc, argv, &argc, &argv); | 295 | mu_argp_parse (&argp, &argc, &argv, 0, mail_capa, NULL, &args); |
292 | argp_parse (&argp, argc, argv, 0, 0, &args); | ||
293 | 296 | ||
294 | /* read system-wide mail.rc and user's .mailrc */ | 297 | /* read system-wide mail.rc and user's .mailrc */ |
295 | if ((util_find_env ("rc"))->set) | 298 | if ((util_find_env ("rc"))->set) | ... | ... |
... | @@ -11,11 +11,18 @@ static char doc[] = "GNU messages -- count the number of messages in a mailbox"; | ... | @@ -11,11 +11,18 @@ static char doc[] = "GNU messages -- count the number of messages in a mailbox"; |
11 | static char args_doc[] = "[mailbox...]"; | 11 | static char args_doc[] = "[mailbox...]"; |
12 | 12 | ||
13 | static struct argp_option options[] = { | 13 | static struct argp_option options[] = { |
14 | {NULL, 0, NULL, 0, | ||
15 | "messages specific switches:", 0}, | ||
14 | {"quiet", 'q', 0, 0, "Only display number of messages"}, | 16 | {"quiet", 'q', 0, 0, "Only display number of messages"}, |
15 | {"silent", 's', 0, 0, "Same as -q"}, | 17 | {"silent", 's', 0, 0, "Same as -q"}, |
16 | { 0 } | 18 | { 0 } |
17 | }; | 19 | }; |
18 | 20 | ||
21 | static const char *argp_capa[] = { | ||
22 | "mailutils", | ||
23 | NULL | ||
24 | }; | ||
25 | |||
19 | struct arguments | 26 | struct arguments |
20 | { | 27 | { |
21 | int argc; | 28 | int argc; |
... | @@ -53,7 +60,7 @@ static struct argp argp = { | ... | @@ -53,7 +60,7 @@ static struct argp argp = { |
53 | parse_opt, | 60 | parse_opt, |
54 | args_doc, | 61 | args_doc, |
55 | doc, | 62 | doc, |
56 | mu_common_argp_child, | 63 | NULL, |
57 | NULL, NULL | 64 | NULL, NULL |
58 | }; | 65 | }; |
59 | 66 | ||
... | @@ -65,8 +72,7 @@ main (int argc, char **argv) | ... | @@ -65,8 +72,7 @@ main (int argc, char **argv) |
65 | int err = 0; | 72 | int err = 0; |
66 | struct arguments args = {0, NULL}; | 73 | struct arguments args = {0, NULL}; |
67 | 74 | ||
68 | mu_create_argcv (argc, argv, &argc, &argv); | 75 | mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, NULL, &args); |
69 | argp_parse (&argp, argc, argv, 0, 0, &args); | ||
70 | 76 | ||
71 | registrar_get_list (&bookie); | 77 | registrar_get_list (&bookie); |
72 | list_append (bookie, path_record); | 78 | list_append (bookie, path_record); | ... | ... |
... | @@ -41,20 +41,44 @@ volatile size_t children; | ... | @@ -41,20 +41,44 @@ volatile size_t children; |
41 | static int pop3d_mainloop __P ((int, int)); | 41 | static int pop3d_mainloop __P ((int, int)); |
42 | static void pop3d_daemon_init __P ((void)); | 42 | static void pop3d_daemon_init __P ((void)); |
43 | static void pop3d_daemon __P ((unsigned int, unsigned int)); | 43 | static void pop3d_daemon __P ((unsigned int, unsigned int)); |
44 | 44 | static error_t pop3d_parse_opt __P((int key, char *arg, | |
45 | struct argp_state *state)); | ||
45 | const char *argp_program_version = "pop3d (" PACKAGE ") " VERSION; | 46 | const char *argp_program_version = "pop3d (" PACKAGE ") " VERSION; |
46 | const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; | 47 | const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
47 | static char doc[] = "GNU pop3d -- the POP3 daemon"; | 48 | static char doc[] = "GNU pop3d -- the POP3 daemon"; |
48 | 49 | ||
49 | static struct argp argp = { | 50 | static struct argp argp = { |
50 | NULL, | 51 | NULL, |
51 | NULL, | 52 | pop3d_parse_opt, |
52 | NULL, | 53 | NULL, |
53 | doc, | 54 | doc, |
54 | mu_daemon_argp_child, | 55 | NULL, |
55 | NULL, NULL | 56 | NULL, NULL |
56 | }; | 57 | }; |
57 | 58 | ||
59 | static const char *pop3d_argp_capa[] = { | ||
60 | "mailutils", | ||
61 | "daemon", | ||
62 | "logging", | ||
63 | "auth", | ||
64 | NULL | ||
65 | }; | ||
66 | |||
67 | static error_t | ||
68 | pop3d_parse_opt (int key, char *arg, struct argp_state *state) | ||
69 | { | ||
70 | switch (key) | ||
71 | { | ||
72 | case ARGP_KEY_INIT: | ||
73 | state->child_inputs[1] = state->input; | ||
74 | break; | ||
75 | |||
76 | default: | ||
77 | return ARGP_ERR_UNKNOWN; | ||
78 | } | ||
79 | return 0; | ||
80 | } | ||
81 | |||
58 | 82 | ||
59 | int | 83 | int |
60 | main (int argc, char **argv) | 84 | main (int argc, char **argv) |
... | @@ -62,8 +86,7 @@ main (int argc, char **argv) | ... | @@ -62,8 +86,7 @@ main (int argc, char **argv) |
62 | struct group *gr; | 86 | struct group *gr; |
63 | int status = OK; | 87 | int status = OK; |
64 | 88 | ||
65 | mu_create_argcv (argc, argv, &argc, &argv); | 89 | mu_argp_parse (&argp, &argc, &argv, 0, pop3d_argp_capa, NULL, &daemon_param); |
66 | argp_parse (&argp, argc, argv, 0, 0, &daemon_param); | ||
67 | 90 | ||
68 | #ifdef USE_LIBPAM | 91 | #ifdef USE_LIBPAM |
69 | if (!pam_service) | 92 | if (!pam_service) | ... | ... |
-
Please register or sign in to post a comment