Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 34CD0431FC0 for ; Sat, 4 Jan 2014 05:47:45 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id owfyC3rUGyy1 for ; Sat, 4 Jan 2014 05:47:39 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id AEB02431FBD for ; Sat, 4 Jan 2014 05:47:38 -0800 (PST) Received: by guru.guru-group.fi (Postfix, from userid 501) id 8A41E10014F; Sat, 4 Jan 2014 15:47:32 +0200 (EET) From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH 1/1] cli: tuned coding style on a small set of c files in root dir Date: Sat, 4 Jan 2014 15:47:30 +0200 Message-Id: <1388843250-4714-1-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.8.0 Cc: tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jan 2014 13:47:45 -0000 The c files in root directory not starting with 'notmuch'. gmime-filter-reply.c used 8-character indenting and seems to be "external" in this project; therefore it was left intact. No functional change. --- Based on the response to this patch I may submit much larger patch which tunes the style in ./notmuch*.[ch] files... command-line-arguments.c | 71 +++++++++++++++++++++++++++--------------------- command-line-arguments.h | 34 +++++++++++------------ debugger.c | 3 +- hooks.c | 4 +-- mime-node.c | 24 ++++++++-------- 5 files changed, 73 insertions(+), 63 deletions(-) diff --git a/command-line-arguments.c b/command-line-arguments.c index bf9aeca..969269c 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -5,13 +5,14 @@ #include "command-line-arguments.h" /* - Search the array of keywords for a given argument, assigning the - output variable to the corresponding value. Return FALSE if nothing - matches. -*/ + * Search the array of keywords for a given argument, assigning the + * output variable to the corresponding value. Return FALSE if nothing + * matches. + */ static notmuch_bool_t -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) +{ const notmuch_keyword_t *keywords = arg_desc->keywords; @@ -23,7 +24,7 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char while (keywords->name) { if (strcmp (arg_str, keywords->name) == 0) { if (arg_desc->output_var) { - *((int *)arg_desc->output_var) = keywords->value; + *((int *) arg_desc->output_var) = keywords->value; } return TRUE; } @@ -37,18 +38,19 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char } static notmuch_bool_t -_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { +_process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) +{ if (next == '\0') { - *((notmuch_bool_t *)arg_desc->output_var) = TRUE; + *((notmuch_bool_t *) arg_desc->output_var) = TRUE; return TRUE; } if (strcmp (arg_str, "false") == 0) { - *((notmuch_bool_t *)arg_desc->output_var) = FALSE; + *((notmuch_bool_t *) arg_desc->output_var) = FALSE; return TRUE; } if (strcmp (arg_str, "true") == 0) { - *((notmuch_bool_t *)arg_desc->output_var) = TRUE; + *((notmuch_bool_t *) arg_desc->output_var) = TRUE; return TRUE; } fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name); @@ -56,15 +58,17 @@ _process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char } static notmuch_bool_t -_process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { +_process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) +{ char *endptr; + if (next == '\0' || arg_str[0] == '\0') { fprintf (stderr, "Option \"%s\" needs an integer argument.\n", arg_desc->name); return FALSE; } - *((int *)arg_desc->output_var) = strtol (arg_str, &endptr, 10); + *((int *) arg_desc->output_var) = strtol (arg_str, &endptr, 10); if (*endptr == '\0') return TRUE; @@ -74,7 +78,8 @@ _process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg } static notmuch_bool_t -_process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { +_process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) +{ if (next == '\0') { fprintf (stderr, "Option \"%s\" needs a string argument.\n", arg_desc->name); @@ -84,25 +89,27 @@ _process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char * fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name); return FALSE; } - *((const char **)arg_desc->output_var) = arg_str; + *((const char **) arg_desc->output_var) = arg_str; return TRUE; } /* - Search for the {pos_arg_index}th position argument, return FALSE if - that does not exist. -*/ + * Search for the {pos_arg_index}th position argument, return FALSE if + * that does not exist. + */ notmuch_bool_t parse_position_arg (const char *arg_str, int pos_arg_index, - const notmuch_opt_desc_t *arg_desc) { + const notmuch_opt_desc_t *arg_desc) +{ int pos_arg_counter = 0; - while (arg_desc->opt_type != NOTMUCH_OPT_END){ + + while (arg_desc->opt_type != NOTMUCH_OPT_END) { if (arg_desc->opt_type == NOTMUCH_OPT_POSITION) { if (pos_arg_counter == pos_arg_index) { if (arg_desc->output_var) { - *((const char **)arg_desc->output_var) = arg_str; + *((const char **) arg_desc->output_var) = arg_str; } return TRUE; } @@ -120,10 +127,11 @@ parse_position_arg (const char *arg_str, int pos_arg_index, notmuch_bool_t parse_option (const char *arg, - const notmuch_opt_desc_t *options) { + const notmuch_opt_desc_t *options) +{ - assert(arg); - assert(options); + assert (arg); + assert (options); arg += 2; @@ -131,13 +139,13 @@ parse_option (const char *arg, for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) { if (try->name && strncmp (arg, try->name, strlen (try->name)) == 0) { char next = arg[strlen (try->name)]; - const char *value= arg+strlen(try->name)+1; + const char *value = arg + strlen (try->name) + 1; /* If we have not reached the end of the argument - (i.e. the next character is not a space or delimiter) - then the argument could still match a longer option - name later in the option table. - */ + * (i.e. the next character is not a space or delimiter) + * then the argument could still match a longer option + * name later in the option table. + */ if (next != '=' && next != ':' && next != '\0') continue; @@ -172,13 +180,14 @@ parse_option (const char *arg, /* See command-line-arguments.h for description */ int parse_arguments (int argc, char **argv, - const notmuch_opt_desc_t *options, int opt_index) { + const notmuch_opt_desc_t *options, int opt_index) +{ int pos_arg_index = 0; notmuch_bool_t more_args = TRUE; while (more_args && opt_index < argc) { - if (strncmp (argv[opt_index],"--",2) != 0) { + if (strncmp (argv[opt_index], "--", 2) != 0) { more_args = parse_position_arg (argv[opt_index], pos_arg_index, options); @@ -190,7 +199,7 @@ parse_arguments (int argc, char **argv, } else { if (strlen (argv[opt_index]) == 2) - return opt_index+1; + return opt_index + 1; more_args = parse_option (argv[opt_index], options); if (more_args) { diff --git a/command-line-arguments.h b/command-line-arguments.h index de1734a..3ac714e 100644 --- a/command-line-arguments.h +++ b/command-line-arguments.h @@ -37,26 +37,26 @@ typedef struct notmuch_opt_desc { enum notmuch_opt_type opt_type; void *output_var; const char *name; - int arg_id; + int arg_id; const struct notmuch_keyword *keywords; } notmuch_opt_desc_t; /* - This is the main entry point for command line argument parsing. - - Parse command line arguments according to structure options, - starting at position opt_index. - - All output of parsed values is via pointers in options. - - Parsing stops at -- (consumed) or at the (k+1)st argument - not starting with -- (a "positional argument") if options contains - k positional argument descriptors. - - Returns the index of first non-parsed argument, or -1 in case of error. - -*/ + * This is the main entry point for command line argument parsing. + * + * Parse command line arguments according to structure options, + * starting at position opt_index. + * + * All output of parsed values is via pointers in options. + * + * Parsing stops at -- (consumed) or at the (k+1)st argument + * not starting with -- (a "positional argument") if options contains + * k positional argument descriptors. + * + * Returns the index of first non-parsed argument, or -1 in case of error. + * + */ int parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index); @@ -69,12 +69,12 @@ parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int o */ notmuch_bool_t -parse_option (const char *arg, const notmuch_opt_desc_t* options); +parse_option (const char *arg, const notmuch_opt_desc_t *options); notmuch_bool_t parse_position_arg (const char *arg, int position_arg_index, - const notmuch_opt_desc_t* options); + const notmuch_opt_desc_t *options); #endif diff --git a/debugger.c b/debugger.c index e8b9378..1d35e1f 100644 --- a/debugger.c +++ b/debugger.c @@ -38,8 +38,7 @@ debugger_is_active (void) sprintf (buf, "/proc/%d/exe", getppid ()); if (readlink (buf, buf, sizeof (buf)) != -1 && - strncmp (basename (buf), "gdb", 3) == 0) - { + strncmp (basename (buf), "gdb", 3) == 0) { return TRUE; } diff --git a/hooks.c b/hooks.c index 44ee419..d995171 100644 --- a/hooks.c +++ b/hooks.c @@ -50,7 +50,7 @@ notmuch_run_hook (const char *db_path, const char *hook) goto DONE; } - pid = fork(); + pid = fork (); if (pid == -1) { fprintf (stderr, "Error: %s hook fork failed: %s\n", hook, strerror (errno)); @@ -75,7 +75,7 @@ notmuch_run_hook (const char *db_path, const char *hook) goto DONE; } - if (!WIFEXITED (status) || WEXITSTATUS (status)) { + if (! WIFEXITED (status) || WEXITSTATUS (status)) { if (WIFEXITED (status)) { fprintf (stderr, "Error: %s hook failed with status %d\n", hook, WEXITSTATUS (status)); diff --git a/mime-node.c b/mime-node.c index fd9e4a4..2ff93de 100644 --- a/mime-node.c +++ b/mime-node.c @@ -87,7 +87,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message, } mctx->stream = g_mime_stream_file_new (mctx->file); - if (!mctx->stream) { + if (! mctx->stream) { fprintf (stderr, "Out of memory.\n"); status = NOTMUCH_STATUS_OUT_OF_MEMORY; goto DONE; @@ -95,14 +95,14 @@ mime_node_open (const void *ctx, notmuch_message_t *message, g_mime_stream_file_set_owner (GMIME_STREAM_FILE (mctx->stream), FALSE); mctx->parser = g_mime_parser_new_with_stream (mctx->stream); - if (!mctx->parser) { + if (! mctx->parser) { fprintf (stderr, "Out of memory.\n"); status = NOTMUCH_STATUS_OUT_OF_MEMORY; goto DONE; } mctx->mime_message = g_mime_parser_construct_message (mctx->parser); - if (!mctx->mime_message) { + if (! mctx->mime_message) { fprintf (stderr, "Failed to parse %s\n", filename); status = NOTMUCH_STATUS_FILE_ERROR; goto DONE; @@ -124,7 +124,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message, *root_out = root; return NOTMUCH_STATUS_SUCCESS; -DONE: + DONE: talloc_free (root); return status; } @@ -144,6 +144,7 @@ static void set_signature_list_destructor (mime_node_t *node) { GMimeSignatureList **proxy = talloc (node, GMimeSignatureList *); + if (proxy) { *proxy = node->sig_list; talloc_set_destructor (proxy, _signature_list_free); @@ -200,7 +201,7 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part, } g_object_unref (decrypt_result); - DONE: + DONE: if (err) g_error_free (err); } @@ -221,6 +222,7 @@ set_signature_validity_destructor (mime_node_t *node, GMimeSignatureValidity *sig_validity) { GMimeSignatureValidity **proxy = talloc (node, GMimeSignatureValidity *); + if (proxy) { *proxy = sig_validity; talloc_set_destructor (proxy, _signature_validity_free); @@ -279,12 +281,12 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part, fprintf (stderr, "Failed to verify encrypted signed part: %s\n", err ? err->message : "no error explanation given"); - DONE: + DONE: if (err) g_error_free (err); } -#endif /* GMIME_ATLEAST_26 */ +#endif /* GMIME_ATLEAST_26 */ static mime_node_t * _mime_node_create (mime_node_t *parent, GMimeObject *part) @@ -295,7 +297,7 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part) /* Set basic node properties */ node->part = part; node->ctx = parent->ctx; - if (!talloc_reference (node, node->ctx)) { + if (! talloc_reference (node, node->ctx)) { fprintf (stderr, "Out of memory.\n"); talloc_free (node); return NULL; @@ -360,7 +362,7 @@ mime_node_child (mime_node_t *parent, int child) GMimeObject *sub; mime_node_t *node; - if (!parent || !parent->part || child < 0 || child >= parent->nchildren) + if (! parent || ! parent->part || child < 0 || child >= parent->nchildren) return NULL; if (GMIME_IS_MULTIPART (parent->part)) { @@ -412,10 +414,10 @@ _mime_node_seek_dfs_walk (mime_node_t *node, int *n) return node; *n -= 1; - for (i = 0; i < node->nchildren && !ret; i++) { + for (i = 0; i < node->nchildren && ! ret; i++) { mime_node_t *child = mime_node_child (node, i); ret = _mime_node_seek_dfs_walk (child, n); - if (!ret) + if (! ret) talloc_free (child); } return ret; -- 1.8.4.2