Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / 51 / 0423330f6c99ac38bf6ff7024a85fb99bdb790
1 Return-Path: <bremner@pivot.cs.unb.ca>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 35505431FCB\r
6         for <notmuch@notmuchmail.org>; Sat, 19 Dec 2009 06:56:04 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id Y6RtE5gCMQK0 for <notmuch@notmuchmail.org>;\r
11         Sat, 19 Dec 2009 06:56:02 -0800 (PST)\r
12 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])\r
13         by olra.theworths.org (Postfix) with ESMTP id 13AD4431FBF\r
14         for <notmuch@notmuchmail.org>; Sat, 19 Dec 2009 06:56:02 -0800 (PST)\r
15 Received: from\r
16         fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net\r
17         ([142.167.182.194] helo=localhost)\r
18         by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
19         (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)\r
20         id 1NM0iv-0003aS-H0; Sat, 19 Dec 2009 10:56:01 -0400\r
21 Received: from bremner by localhost with local (Exim 4.69)\r
22         (envelope-from <bremner@pivot.cs.unb.ca>)\r
23         id 1NM0iq-0006ec-27; Sat, 19 Dec 2009 10:55:56 -0400\r
24 From: david@tethera.net\r
25 To: notmuch@notmuchmail.org\r
26 Date: Sat, 19 Dec 2009 10:55:24 -0400\r
27 Message-Id: <1261234524-25522-4-git-send-email-david@tethera.net>\r
28 X-Mailer: git-send-email 1.6.5.3\r
29 In-Reply-To: <1261234524-25522-3-git-send-email-david@tethera.net>\r
30 References: <87iqc4yyo8.fsf@yoom.home.cworth.org>\r
31         <1261234524-25522-1-git-send-email-david@tethera.net>\r
32         <1261234524-25522-2-git-send-email-david@tethera.net>\r
33         <1261234524-25522-3-git-send-email-david@tethera.net>\r
34 X-Sender-Verified: bremner@pivot.cs.unb.ca\r
35 Cc: David Bremner <bremner@unb.ca>\r
36 Subject: [notmuch] [PATCH 3/3] notmuch-show.c: prototype tabular output\r
37         format, with output control\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.12\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sat, 19 Dec 2009 14:56:04 -0000\r
51 \r
52 From: David Bremner <bremner@unb.ca>\r
53 \r
54 Currently this only outputs the information from the "message header";\r
55 i.e. the part before the rfc2822 header or body.\r
56 \r
57 Adding this required adding an extra parameter, currently unused, to\r
58 format_message_text and format_message_json. Also the struct\r
59 definition is changed to match the new function prototypes.\r
60 \r
61 An int (enum) is used as a mask, each bit corresponds to some part to\r
62 be shown or not shown.  This enum will need to be extended as more\r
63 things are controllable via --show.\r
64 ---\r
65  notmuch-show.c |   89 ++++++++++++++++++++++++++++++++++++++++++++++++-------\r
66  1 files changed, 77 insertions(+), 12 deletions(-)\r
67 \r
68 diff --git a/notmuch-show.c b/notmuch-show.c\r
69 index 51aa87d..99a4d3c 100644\r
70 --- a/notmuch-show.c\r
71 +++ b/notmuch-show.c\r
72 @@ -20,10 +20,18 @@\r
73  \r
74  #include "notmuch-client.h"\r
75  \r
76 +/* These should be powers of 2 */\r
77 +typedef enum {SHOW_MESSAGE_ID = 1, \r
78 +             SHOW_MATCH = 2, \r
79 +             SHOW_FILENAME = 4\r
80 +} show_mask_t;\r
81 +\r
82 +static const show_mask_t SHOW_ALL = ~0;\r
83 +\r
84  typedef struct show_format {\r
85      const char *message_set_start;\r
86      const char *message_start;\r
87 -    void (*message) (const void *ctx,\r
88 +    void (*message) (const void *ctx, show_mask_t show_mask,\r
89                      notmuch_message_t *message,\r
90                      int indent);\r
91      const char *header_start;\r
92 @@ -40,7 +48,7 @@ typedef struct show_format {\r
93  } show_format_t;\r
94  \r
95  static void\r
96 -format_message_text (unused (const void *ctx),\r
97 +format_message_text (unused (const void *ctx), show_mask_t show_mask,\r
98                      notmuch_message_t *message,\r
99                      int indent);\r
100  static void\r
101 @@ -59,7 +67,21 @@ static const show_format_t format_text = {\r
102  };\r
103  \r
104  static void\r
105 -format_message_json (const void *ctx,\r
106 +format_message_tabular (unused (const void *ctx), show_mask_t show_mask,\r
107 +                    notmuch_message_t *message,\r
108 +                    int indent);\r
109 +\r
110 +static const show_format_t format_tabular = {\r
111 +    "",         \r
112 +    "", format_message_tabular, \r
113 +    "", NULL, "", \r
114 +    "", NULL, "",    \r
115 +    "\n", "", \r
116 +    ""\r
117 +};\r
118 +\r
119 +static void\r
120 +format_message_json (const void *ctx, show_mask_t show_mask,\r
121                      notmuch_message_t *message,\r
122                      unused (int indent));\r
123  static void\r
124 @@ -124,7 +146,30 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
125  }\r
126  \r
127  static void\r
128 -format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent)\r
129 +format_message_tabular (unused (const void *ctx), show_mask_t show_mask,\r
130 +                       notmuch_message_t *message, \r
131 +                       unused(int indent))\r
132 +{\r
133 +    int count=0;\r
134 +\r
135 +    if (show_mask & SHOW_MESSAGE_ID) {\r
136 +       fputs ( notmuch_message_get_message_id (message), stdout);\r
137 +       count++;\r
138 +    }\r
139 +\r
140 +    if (show_mask & SHOW_MATCH) \r
141 +       printf ("%s%d", count++ ? "\t" : "", \r
142 +               notmuch_message_get_flag (message, \r
143 +                                         NOTMUCH_MESSAGE_FLAG_MATCH));\r
144 +\r
145 +    if (show_mask & SHOW_FILENAME) \r
146 +       printf("%s%s", count++ ? "\t" : "", \r
147 +              notmuch_message_get_filename (message));\r
148 +}\r
149 +\r
150 +static void\r
151 +format_message_text (unused (const void *ctx), unused(show_mask_t show_mask),\r
152 +                    notmuch_message_t *message, int indent)\r
153  {\r
154      printf ("id:%s depth:%d match:%d filename:%s\n",\r
155             notmuch_message_get_message_id (message),\r
156 @@ -134,7 +179,8 @@ format_message_text (unused (const void *ctx), notmuch_message_t *message, int i\r
157  }\r
158  \r
159  static void\r
160 -format_message_json (const void *ctx, notmuch_message_t *message, unused (int indent))\r
161 +format_message_json (const void *ctx, unused(show_mask_t show_mask),\r
162 +                    notmuch_message_t *message, unused (int indent))\r
163  {\r
164      void *ctx_quote = talloc_new (ctx);\r
165  \r
166 @@ -323,11 +369,12 @@ format_part_json (GMimeObject *part, int *part_count)\r
167  }\r
168  \r
169  static void\r
170 -show_message (void *ctx, const show_format_t *format, notmuch_message_t *message, int indent)\r
171 +show_message (void *ctx, const show_format_t *format, show_mask_t show_mask,\r
172 +             notmuch_message_t *message, int indent)\r
173  {\r
174      fputs (format->message_start, stdout);\r
175      if (format->message)\r
176 -       format->message(ctx, message, indent);\r
177 +       format->message(ctx, show_mask, message, indent);\r
178  \r
179      fputs (format->header_start, stdout);\r
180      if (format->header) \r
181 @@ -344,8 +391,8 @@ show_message (void *ctx, const show_format_t *format, notmuch_message_t *message\r
182  \r
183  \r
184  static void\r
185 -show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messages, int indent,\r
186 -              notmuch_bool_t entire_thread)\r
187 +show_messages (void *ctx, const show_format_t *format,  show_mask_t show_mask, \r
188 +              notmuch_messages_t *messages, int indent, notmuch_bool_t entire_thread)\r
189  {\r
190      notmuch_message_t *message;\r
191      notmuch_bool_t match;\r
192 @@ -371,13 +418,14 @@ show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messa\r
193         next_indent = indent;\r
194  \r
195         if (match || entire_thread) {\r
196 -           show_message (ctx, format, message, indent);\r
197 +           show_message (ctx, format, show_mask, message, indent);\r
198             next_indent = indent + 1;\r
199  \r
200             fputs (format->message_set_sep, stdout);\r
201         }\r
202  \r
203 -       show_messages (ctx, format, notmuch_message_get_replies (message),\r
204 +       show_messages (ctx, format, show_mask, \r
205 +                      notmuch_message_get_replies (message),\r
206                        next_indent, entire_thread);\r
207  \r
208         notmuch_message_destroy (message);\r
209 @@ -403,6 +451,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
210      int entire_thread = 0;\r
211      int i;\r
212      int first_toplevel = 1;\r
213 +    show_mask_t show_mask=SHOW_ALL;\r
214  \r
215      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
216         if (strcmp (argv[i], "--") == 0) {\r
217 @@ -422,6 +471,22 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
218                 fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
219                 return 1;\r
220             }\r
221 +       } else if (STRNCMP_LITERAL (argv[i], "--show=") == 0) {\r
222 +           char *keyword=NULL;\r
223 +           show_mask=0;\r
224 +           opt = argv[i] + sizeof ("--show=") - 1;\r
225 +           while ((keyword=strsep (&opt,", "))) {\r
226 +               if (strcmp (keyword, "message-id") == 0) {\r
227 +                   show_mask |= SHOW_MESSAGE_ID;\r
228 +               } else if (strcmp (keyword, "match") == 0) {\r
229 +                   show_mask |= SHOW_MATCH;\r
230 +               } else if (strcmp (keyword, "filename") == 0) {\r
231 +                   show_mask |= SHOW_FILENAME;\r
232 +               } else {\r
233 +                   fprintf (stderr, "Invalid value for --show: %s\n", opt);\r
234 +                   return 1;\r
235 +               }\r
236 +           }\r
237         } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {\r
238             entire_thread = 1;\r
239         } else {\r
240 @@ -477,7 +542,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
241             fputs (format->message_set_sep, stdout);\r
242         first_toplevel = 0;\r
243  \r
244 -       show_messages (ctx, format, messages, 0, entire_thread);\r
245 +       show_messages (ctx, format, show_mask, messages, 0, entire_thread);\r
246  \r
247         notmuch_thread_destroy (thread);\r
248  \r
249 -- \r
250 1.6.5.3\r
251 \r