1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| | /* notmuch-output.h --- encapsulate handling of output selection.
*
* Copyright 2010 © David Bremner
*
* This file is part of Notmuch.
*
* Notmuch is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Notmuch is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Notmuch. If not, see <http:www.gnu.org/licenses/>.
*
* Authors: David Bremner <david@tethera.net>
*/
#include "notmuch-client.h"
#include "notmuch-output.h"
notmuch_output_options_t *
output_init(void *ctx){
notmuch_output_options_t *output_opts;
output_opts = talloc (ctx, notmuch_output_options_t);
output_opts->output_all=TRUE;
output_opts->mask=0;
return output_opts;
}
int
output_parse_arg(notmuch_output_options_t *output_opts, const char *arg){
char *opt;
struct { const char *name; notmuch_output_t key; } parse_try[]={
{"bcc", NOTMUCH_OUTPUT_BCC},
{"body", NOTMUCH_OUTPUT_BODY},
{"cc", NOTMUCH_OUTPUT_CC},
{"date",NOTMUCH_OUTPUT_DATE},
{"from",NOTMUCH_OUTPUT_FROM},
{"message-id",NOTMUCH_OUTPUT_MESSAGE_ID},
{"subject",NOTMUCH_OUTPUT_SUBJECT},
{"to", NOTMUCH_OUTPUT_TO},
};
opt = strchr(arg, '=');
if (!opt)
return 1;
opt++;
output_opts->output_all=FALSE;
while(opt) {
unsigned int i;
notmuch_bool_t found = FALSE;
notmuch_output_t key = 0;
for (i = 0; i<ARRAY_SIZE(parse_try) ; i++){
if (strncmp(opt, parse_try[i].name,
strlen(parse_try[i].name)) == 0){
key = parse_try[i].key;
found = TRUE;
}
}
if (!found) {
fprintf (stderr, "Unrecognized output selection: %s\n", opt);
return 1;
}
output_opts->mask |= (1<<key);
opt = strchr(opt, ',');
if (opt) opt++;
}
return 0;
}
notmuch_bool_t
output_get_flag(notmuch_output_options_t *opts,
notmuch_output_t flag){
if (opts->output_all)
return 1;
return (opts->mask & (1<<flag));
}
|