From: Mark Walters Date: Sat, 18 Jan 2014 13:16:33 +0000 (+0000) Subject: Re: [PATCH 1/1] cli: tuned coding style on a small set of c files in root dir X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b5af828e19df6be3aac902a460f70afd6fa727dd;p=notmuch-archives.git Re: [PATCH 1/1] cli: tuned coding style on a small set of c files in root dir --- diff --git a/30/0086261a92b07341725657dfd622c3ae86906c b/30/0086261a92b07341725657dfd622c3ae86906c new file mode 100644 index 000000000..466bc01ea --- /dev/null +++ b/30/0086261a92b07341725657dfd622c3ae86906c @@ -0,0 +1,499 @@ +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 130FB431FBD + for ; Sat, 18 Jan 2014 05:16:46 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 xhGhAMJq2WuZ for ; + Sat, 18 Jan 2014 05:16:38 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id CD175431FBC + for ; Sat, 18 Jan 2014 05:16:37 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1W4VlL-00011V-7F; Sat, 18 Jan 2014 13:16:35 +0000 +Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) + (envelope-from ) + id 1W4VlK-0004Ni-E4; Sat, 18 Jan 2014 13:16:35 +0000 +From: Mark Walters +To: Tomi Ollila , notmuch@notmuchmail.org +Subject: Re: [PATCH 1/1] cli: tuned coding style on a small set of c files in + root dir +In-Reply-To: <1388843250-4714-1-git-send-email-tomi.ollila@iki.fi> +References: <1388843250-4714-1-git-send-email-tomi.ollila@iki.fi> +User-Agent: Notmuch/0.15.2+484~gfb59956 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sat, 18 Jan 2014 13:16:33 +0000 +Message-ID: <87lhydctvy.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 93.97.24.31 +X-QM-Geographic: According to ripencc, + this message was delivered by a machine in Britain (UK) (GB). +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: de2d6c0d930d895c26e44591c04790f2 (of first 20000 bytes) +X-SpamAssassin-Score: 0.0 +X-SpamAssassin-SpamBar: / +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored 0.0 points. Summary of the scoring: + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * 0.0 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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, 18 Jan 2014 13:16:46 -0000 + + +This basically looks good. There was one type of change I was unsure +about. + +On Sat, 04 Jan 2014, Tomi Ollila wrote: +> 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; +> + +Should the blank line be deleted now the { is on its own line? This type +of change occurred several times. + +Best wishes + +Mark + +> @@ -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 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch