New file. Sieve-specific command line handling.
Showing
1 changed file
with
101 additions
and
0 deletions
libsieve/argp.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU Lesser General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include <sieve.h> | ||
22 | #include <mailutils/argp.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | list_t sieve_include_path = NULL; | ||
26 | list_t sieve_library_path = NULL; | ||
27 | |||
28 | static error_t sieve_argp_parser __P((int key, char *arg, | ||
29 | struct argp_state *state)); | ||
30 | |||
31 | /* Options used by programs that use extended authentication mechanisms. */ | ||
32 | static struct argp_option sieve_argp_option[] = { | ||
33 | { "includedir", 'I', "DIR", 0, | ||
34 | "Append directory DIR to the list of directories searched for include files", 0 }, | ||
35 | { "libdir", 'L', "DIR", 0, | ||
36 | "Append directory DIR to the list of directories searched for library files", 0 }, | ||
37 | { NULL, 0, NULL, 0, NULL, 0 } | ||
38 | }; | ||
39 | |||
40 | static struct argp sieve_argp = { | ||
41 | sieve_argp_option, | ||
42 | sieve_argp_parser, | ||
43 | }; | ||
44 | |||
45 | static struct argp_child sieve_argp_child = { | ||
46 | &sieve_argp, | ||
47 | 0, | ||
48 | "Sieve options", | ||
49 | 0 | ||
50 | }; | ||
51 | |||
52 | static error_t | ||
53 | sieve_argp_parser (int key, char *arg, struct argp_state *state) | ||
54 | { | ||
55 | list_t *plist = NULL; | ||
56 | |||
57 | switch (key) | ||
58 | { | ||
59 | case 'I': | ||
60 | plist = &sieve_include_path; | ||
61 | break; | ||
62 | |||
63 | case 'L': | ||
64 | plist = &sieve_library_path; | ||
65 | break; | ||
66 | |||
67 | case ARGP_KEY_FINI: | ||
68 | sieve_load_add_path (sieve_library_path); | ||
69 | break; | ||
70 | |||
71 | default: | ||
72 | return ARGP_ERR_UNKNOWN; | ||
73 | } | ||
74 | |||
75 | if (plist) | ||
76 | { | ||
77 | if (!*plist) | ||
78 | { | ||
79 | int rc = list_create (plist); | ||
80 | if (rc) | ||
81 | { | ||
82 | argp_error (state, "can't create list: %s", | ||
83 | mu_errstring (rc)); | ||
84 | exit (1); | ||
85 | } | ||
86 | } | ||
87 | list_append (*plist, strdup (arg)); | ||
88 | } | ||
89 | |||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | void | ||
94 | sieve_argp_init () | ||
95 | { | ||
96 | if (mu_register_capa ("sieve", &sieve_argp_child)) | ||
97 | { | ||
98 | mu_error ("INTERNAL ERROR: cannot register argp capability sieve"); | ||
99 | abort (); | ||
100 | } | ||
101 | } |
-
Please register or sign in to post a comment