1 Return-Path: <too@guru-group.fi>
\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 34CD0431FC0
\r
6 for <notmuch@notmuchmail.org>; Sat, 4 Jan 2014 05:47:45 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id owfyC3rUGyy1 for <notmuch@notmuchmail.org>;
\r
16 Sat, 4 Jan 2014 05:47:39 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id AEB02431FBD
\r
19 for <notmuch@notmuchmail.org>; Sat, 4 Jan 2014 05:47:38 -0800 (PST)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 8A41E10014F; Sat, 4 Jan 2014 15:47:32 +0200 (EET)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH 1/1] cli: tuned coding style on a small set of c files in root
\r
26 Date: Sat, 4 Jan 2014 15:47:30 +0200
\r
27 Message-Id: <1388843250-4714-1-git-send-email-tomi.ollila@iki.fi>
\r
28 X-Mailer: git-send-email 1.8.0
\r
29 Cc: tomi.ollila@iki.fi
\r
30 X-BeenThere: notmuch@notmuchmail.org
\r
31 X-Mailman-Version: 2.1.13
\r
33 List-Id: "Use and development of the notmuch mail system."
\r
34 <notmuch.notmuchmail.org>
\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
36 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
38 List-Post: <mailto:notmuch@notmuchmail.org>
\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
42 X-List-Received-Date: Sat, 04 Jan 2014 13:47:45 -0000
\r
44 The c files in root directory not starting with 'notmuch'.
\r
46 gmime-filter-reply.c used 8-character indenting and seems to
\r
47 be "external" in this project; therefore it was left intact.
\r
49 No functional change.
\r
52 Based on the response to this patch I may submit much larger
\r
53 patch which tunes the style in ./notmuch*.[ch] files...
\r
55 command-line-arguments.c | 71 +++++++++++++++++++++++++++---------------------
\r
56 command-line-arguments.h | 34 +++++++++++------------
\r
59 mime-node.c | 24 ++++++++--------
\r
60 5 files changed, 73 insertions(+), 63 deletions(-)
\r
62 diff --git a/command-line-arguments.c b/command-line-arguments.c
\r
63 index bf9aeca..969269c 100644
\r
64 --- a/command-line-arguments.c
\r
65 +++ b/command-line-arguments.c
\r
67 #include "command-line-arguments.h"
\r
70 - Search the array of keywords for a given argument, assigning the
\r
71 - output variable to the corresponding value. Return FALSE if nothing
\r
74 + * Search the array of keywords for a given argument, assigning the
\r
75 + * output variable to the corresponding value. Return FALSE if nothing
\r
79 static notmuch_bool_t
\r
80 -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
\r
81 +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str)
\r
84 const notmuch_keyword_t *keywords = arg_desc->keywords;
\r
86 @@ -23,7 +24,7 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
\r
87 while (keywords->name) {
\r
88 if (strcmp (arg_str, keywords->name) == 0) {
\r
89 if (arg_desc->output_var) {
\r
90 - *((int *)arg_desc->output_var) = keywords->value;
\r
91 + *((int *) arg_desc->output_var) = keywords->value;
\r
95 @@ -37,18 +38,19 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
\r
98 static notmuch_bool_t
\r
99 -_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
\r
100 +_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str)
\r
103 if (next == '\0') {
\r
104 - *((notmuch_bool_t *)arg_desc->output_var) = TRUE;
\r
105 + *((notmuch_bool_t *) arg_desc->output_var) = TRUE;
\r
108 if (strcmp (arg_str, "false") == 0) {
\r
109 - *((notmuch_bool_t *)arg_desc->output_var) = FALSE;
\r
110 + *((notmuch_bool_t *) arg_desc->output_var) = FALSE;
\r
113 if (strcmp (arg_str, "true") == 0) {
\r
114 - *((notmuch_bool_t *)arg_desc->output_var) = TRUE;
\r
115 + *((notmuch_bool_t *) arg_desc->output_var) = TRUE;
\r
118 fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name);
\r
119 @@ -56,15 +58,17 @@ _process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
\r
122 static notmuch_bool_t
\r
123 -_process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
\r
124 +_process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str)
\r
129 if (next == '\0' || arg_str[0] == '\0') {
\r
130 fprintf (stderr, "Option \"%s\" needs an integer argument.\n", arg_desc->name);
\r
134 - *((int *)arg_desc->output_var) = strtol (arg_str, &endptr, 10);
\r
135 + *((int *) arg_desc->output_var) = strtol (arg_str, &endptr, 10);
\r
136 if (*endptr == '\0')
\r
139 @@ -74,7 +78,8 @@ _process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg
\r
142 static notmuch_bool_t
\r
143 -_process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
\r
144 +_process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str)
\r
147 if (next == '\0') {
\r
148 fprintf (stderr, "Option \"%s\" needs a string argument.\n", arg_desc->name);
\r
149 @@ -84,25 +89,27 @@ _process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *
\r
150 fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name);
\r
153 - *((const char **)arg_desc->output_var) = arg_str;
\r
154 + *((const char **) arg_desc->output_var) = arg_str;
\r
159 - Search for the {pos_arg_index}th position argument, return FALSE if
\r
160 - that does not exist.
\r
162 + * Search for the {pos_arg_index}th position argument, return FALSE if
\r
163 + * that does not exist.
\r
167 parse_position_arg (const char *arg_str, int pos_arg_index,
\r
168 - const notmuch_opt_desc_t *arg_desc) {
\r
169 + const notmuch_opt_desc_t *arg_desc)
\r
172 int pos_arg_counter = 0;
\r
173 - while (arg_desc->opt_type != NOTMUCH_OPT_END){
\r
175 + while (arg_desc->opt_type != NOTMUCH_OPT_END) {
\r
176 if (arg_desc->opt_type == NOTMUCH_OPT_POSITION) {
\r
177 if (pos_arg_counter == pos_arg_index) {
\r
178 if (arg_desc->output_var) {
\r
179 - *((const char **)arg_desc->output_var) = arg_str;
\r
180 + *((const char **) arg_desc->output_var) = arg_str;
\r
184 @@ -120,10 +127,11 @@ parse_position_arg (const char *arg_str, int pos_arg_index,
\r
187 parse_option (const char *arg,
\r
188 - const notmuch_opt_desc_t *options) {
\r
189 + const notmuch_opt_desc_t *options)
\r
195 + assert (options);
\r
199 @@ -131,13 +139,13 @@ parse_option (const char *arg,
\r
200 for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {
\r
201 if (try->name && strncmp (arg, try->name, strlen (try->name)) == 0) {
\r
202 char next = arg[strlen (try->name)];
\r
203 - const char *value= arg+strlen(try->name)+1;
\r
204 + const char *value = arg + strlen (try->name) + 1;
\r
206 /* If we have not reached the end of the argument
\r
207 - (i.e. the next character is not a space or delimiter)
\r
208 - then the argument could still match a longer option
\r
209 - name later in the option table.
\r
211 + * (i.e. the next character is not a space or delimiter)
\r
212 + * then the argument could still match a longer option
\r
213 + * name later in the option table.
\r
215 if (next != '=' && next != ':' && next != '\0')
\r
218 @@ -172,13 +180,14 @@ parse_option (const char *arg,
\r
219 /* See command-line-arguments.h for description */
\r
221 parse_arguments (int argc, char **argv,
\r
222 - const notmuch_opt_desc_t *options, int opt_index) {
\r
223 + const notmuch_opt_desc_t *options, int opt_index)
\r
226 int pos_arg_index = 0;
\r
227 notmuch_bool_t more_args = TRUE;
\r
229 while (more_args && opt_index < argc) {
\r
230 - if (strncmp (argv[opt_index],"--",2) != 0) {
\r
231 + if (strncmp (argv[opt_index], "--", 2) != 0) {
\r
233 more_args = parse_position_arg (argv[opt_index], pos_arg_index, options);
\r
235 @@ -190,7 +199,7 @@ parse_arguments (int argc, char **argv,
\r
238 if (strlen (argv[opt_index]) == 2)
\r
239 - return opt_index+1;
\r
240 + return opt_index + 1;
\r
242 more_args = parse_option (argv[opt_index], options);
\r
244 diff --git a/command-line-arguments.h b/command-line-arguments.h
\r
245 index de1734a..3ac714e 100644
\r
246 --- a/command-line-arguments.h
\r
247 +++ b/command-line-arguments.h
\r
248 @@ -37,26 +37,26 @@ typedef struct notmuch_opt_desc {
\r
249 enum notmuch_opt_type opt_type;
\r
254 const struct notmuch_keyword *keywords;
\r
255 } notmuch_opt_desc_t;
\r
259 - This is the main entry point for command line argument parsing.
\r
261 - Parse command line arguments according to structure options,
\r
262 - starting at position opt_index.
\r
264 - All output of parsed values is via pointers in options.
\r
266 - Parsing stops at -- (consumed) or at the (k+1)st argument
\r
267 - not starting with -- (a "positional argument") if options contains
\r
268 - k positional argument descriptors.
\r
270 - Returns the index of first non-parsed argument, or -1 in case of error.
\r
273 + * This is the main entry point for command line argument parsing.
\r
275 + * Parse command line arguments according to structure options,
\r
276 + * starting at position opt_index.
\r
278 + * All output of parsed values is via pointers in options.
\r
280 + * Parsing stops at -- (consumed) or at the (k+1)st argument
\r
281 + * not starting with -- (a "positional argument") if options contains
\r
282 + * k positional argument descriptors.
\r
284 + * Returns the index of first non-parsed argument, or -1 in case of error.
\r
288 parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index);
\r
290 @@ -69,12 +69,12 @@ parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int o
\r
294 -parse_option (const char *arg, const notmuch_opt_desc_t* options);
\r
295 +parse_option (const char *arg, const notmuch_opt_desc_t *options);
\r
298 parse_position_arg (const char *arg,
\r
299 int position_arg_index,
\r
300 - const notmuch_opt_desc_t* options);
\r
301 + const notmuch_opt_desc_t *options);
\r
305 diff --git a/debugger.c b/debugger.c
\r
306 index e8b9378..1d35e1f 100644
\r
309 @@ -38,8 +38,7 @@ debugger_is_active (void)
\r
311 sprintf (buf, "/proc/%d/exe", getppid ());
\r
312 if (readlink (buf, buf, sizeof (buf)) != -1 &&
\r
313 - strncmp (basename (buf), "gdb", 3) == 0)
\r
315 + strncmp (basename (buf), "gdb", 3) == 0) {
\r
319 diff --git a/hooks.c b/hooks.c
\r
320 index 44ee419..d995171 100644
\r
323 @@ -50,7 +50,7 @@ notmuch_run_hook (const char *db_path, const char *hook)
\r
330 fprintf (stderr, "Error: %s hook fork failed: %s\n", hook,
\r
332 @@ -75,7 +75,7 @@ notmuch_run_hook (const char *db_path, const char *hook)
\r
336 - if (!WIFEXITED (status) || WEXITSTATUS (status)) {
\r
337 + if (! WIFEXITED (status) || WEXITSTATUS (status)) {
\r
338 if (WIFEXITED (status)) {
\r
339 fprintf (stderr, "Error: %s hook failed with status %d\n",
\r
340 hook, WEXITSTATUS (status));
\r
341 diff --git a/mime-node.c b/mime-node.c
\r
342 index fd9e4a4..2ff93de 100644
\r
345 @@ -87,7 +87,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
348 mctx->stream = g_mime_stream_file_new (mctx->file);
\r
349 - if (!mctx->stream) {
\r
350 + if (! mctx->stream) {
\r
351 fprintf (stderr, "Out of memory.\n");
\r
352 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
354 @@ -95,14 +95,14 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
355 g_mime_stream_file_set_owner (GMIME_STREAM_FILE (mctx->stream), FALSE);
\r
357 mctx->parser = g_mime_parser_new_with_stream (mctx->stream);
\r
358 - if (!mctx->parser) {
\r
359 + if (! mctx->parser) {
\r
360 fprintf (stderr, "Out of memory.\n");
\r
361 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
365 mctx->mime_message = g_mime_parser_construct_message (mctx->parser);
\r
366 - if (!mctx->mime_message) {
\r
367 + if (! mctx->mime_message) {
\r
368 fprintf (stderr, "Failed to parse %s\n", filename);
\r
369 status = NOTMUCH_STATUS_FILE_ERROR;
\r
371 @@ -124,7 +124,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
373 return NOTMUCH_STATUS_SUCCESS;
\r
377 talloc_free (root);
\r
380 @@ -144,6 +144,7 @@ static void
\r
381 set_signature_list_destructor (mime_node_t *node)
\r
383 GMimeSignatureList **proxy = talloc (node, GMimeSignatureList *);
\r
386 *proxy = node->sig_list;
\r
387 talloc_set_destructor (proxy, _signature_list_free);
\r
388 @@ -200,7 +201,7 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
\r
390 g_object_unref (decrypt_result);
\r
395 g_error_free (err);
\r
397 @@ -221,6 +222,7 @@ set_signature_validity_destructor (mime_node_t *node,
\r
398 GMimeSignatureValidity *sig_validity)
\r
400 GMimeSignatureValidity **proxy = talloc (node, GMimeSignatureValidity *);
\r
403 *proxy = sig_validity;
\r
404 talloc_set_destructor (proxy, _signature_validity_free);
\r
405 @@ -279,12 +281,12 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
\r
406 fprintf (stderr, "Failed to verify encrypted signed part: %s\n",
\r
407 err ? err->message : "no error explanation given");
\r
412 g_error_free (err);
\r
415 -#endif /* GMIME_ATLEAST_26 */
\r
416 +#endif /* GMIME_ATLEAST_26 */
\r
418 static mime_node_t *
\r
419 _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
420 @@ -295,7 +297,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
421 /* Set basic node properties */
\r
423 node->ctx = parent->ctx;
\r
424 - if (!talloc_reference (node, node->ctx)) {
\r
425 + if (! talloc_reference (node, node->ctx)) {
\r
426 fprintf (stderr, "Out of memory.\n");
\r
427 talloc_free (node);
\r
429 @@ -360,7 +362,7 @@ mime_node_child (mime_node_t *parent, int child)
\r
433 - if (!parent || !parent->part || child < 0 || child >= parent->nchildren)
\r
434 + if (! parent || ! parent->part || child < 0 || child >= parent->nchildren)
\r
437 if (GMIME_IS_MULTIPART (parent->part)) {
\r
438 @@ -412,10 +414,10 @@ _mime_node_seek_dfs_walk (mime_node_t *node, int *n)
\r
442 - for (i = 0; i < node->nchildren && !ret; i++) {
\r
443 + for (i = 0; i < node->nchildren && ! ret; i++) {
\r
444 mime_node_t *child = mime_node_child (node, i);
\r
445 ret = _mime_node_seek_dfs_walk (child, n);
\r
448 talloc_free (child);
\r