Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 22 / 30d858543f7846e44398871d5ff528d71fc7a0
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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
25         dir\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
32 Precedence: list\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
43 \r
44 The c files in root directory not starting with 'notmuch'.\r
45 \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
48 \r
49 No functional change.\r
50 ---\r
51 \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
54 \r
55  command-line-arguments.c | 71 +++++++++++++++++++++++++++---------------------\r
56  command-line-arguments.h | 34 +++++++++++------------\r
57  debugger.c               |  3 +-\r
58  hooks.c                  |  4 +--\r
59  mime-node.c              | 24 ++++++++--------\r
60  5 files changed, 73 insertions(+), 63 deletions(-)\r
61 \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
66 @@ -5,13 +5,14 @@\r
67  #include "command-line-arguments.h"\r
68  \r
69  /*\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
72 -  matches.\r
73 -*/\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
76 + * matches.\r
77 + */\r
78  \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
82 +{\r
83  \r
84      const notmuch_keyword_t *keywords = arg_desc->keywords;\r
85  \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
92             }\r
93             return TRUE;\r
94         }\r
95 @@ -37,18 +38,19 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char\r
96  }\r
97  \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
101 +{\r
102  \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
106         return TRUE;\r
107      }\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
111         return TRUE;\r
112      }\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
116         return TRUE;\r
117      }\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
120  }\r
121  \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
125 +{\r
126  \r
127      char *endptr;\r
128 +\r
129      if (next == '\0' || arg_str[0] == '\0') {\r
130         fprintf (stderr, "Option \"%s\" needs an integer argument.\n", arg_desc->name);\r
131         return FALSE;\r
132      }\r
133  \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
137         return TRUE;\r
138  \r
139 @@ -74,7 +78,8 @@ _process_int_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg\r
140  }\r
141  \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
145 +{\r
146  \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
151         return FALSE;\r
152      }\r
153 -    *((const char **)arg_desc->output_var) = arg_str;\r
154 +    *((const char **) arg_desc->output_var) = arg_str;\r
155      return TRUE;\r
156  }\r
157  \r
158  /*\r
159 -   Search for the {pos_arg_index}th position argument, return FALSE if\r
160 -   that does not exist.\r
161 -*/\r
162 + * Search for the {pos_arg_index}th position argument, return FALSE if\r
163 + * that does not exist.\r
164 + */\r
165  \r
166  notmuch_bool_t\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
170 +{\r
171  \r
172      int pos_arg_counter = 0;\r
173 -    while (arg_desc->opt_type != NOTMUCH_OPT_END){\r
174 +\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
181                 }\r
182                 return TRUE;\r
183             }\r
184 @@ -120,10 +127,11 @@ parse_position_arg (const char *arg_str, int pos_arg_index,\r
185  \r
186  notmuch_bool_t\r
187  parse_option (const char *arg,\r
188 -             const notmuch_opt_desc_t *options) {\r
189 +             const notmuch_opt_desc_t *options)\r
190 +{\r
191  \r
192 -    assert(arg);\r
193 -    assert(options);\r
194 +    assert (arg);\r
195 +    assert (options);\r
196  \r
197      arg += 2;\r
198  \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
205  \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
210 -           */\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
214 +            */\r
215             if (next != '=' && next != ':' && next != '\0')\r
216                 continue;\r
217  \r
218 @@ -172,13 +180,14 @@ parse_option (const char *arg,\r
219  /* See command-line-arguments.h for description */\r
220  int\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
224 +{\r
225  \r
226      int pos_arg_index = 0;\r
227      notmuch_bool_t more_args = TRUE;\r
228  \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
232  \r
233             more_args = parse_position_arg (argv[opt_index], pos_arg_index, options);\r
234  \r
235 @@ -190,7 +199,7 @@ parse_arguments (int argc, char **argv,\r
236         } else {\r
237  \r
238             if (strlen (argv[opt_index]) == 2)\r
239 -               return opt_index+1;\r
240 +               return opt_index + 1;\r
241  \r
242             more_args = parse_option (argv[opt_index], options);\r
243             if (more_args) {\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
250      void *output_var;\r
251      const char *name;\r
252 -    int  arg_id;\r
253 +    int arg_id;\r
254      const struct notmuch_keyword *keywords;\r
255  } notmuch_opt_desc_t;\r
256  \r
257  \r
258  /*\r
259 -  This is the main entry point for command line argument parsing.\r
260 -\r
261 -  Parse command line arguments according to structure options,\r
262 -  starting at position opt_index.\r
263 -\r
264 -  All output of parsed values is via pointers in options.\r
265 -\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
269 -\r
270 -  Returns the index of first non-parsed argument, or -1 in case of error.\r
271 -\r
272 -*/\r
273 + * This is the main entry point for command line argument parsing.\r
274 + *\r
275 + * Parse command line arguments according to structure options,\r
276 + * starting at position opt_index.\r
277 + *\r
278 + * All output of parsed values is via pointers in options.\r
279 + *\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
283 + *\r
284 + * Returns the index of first non-parsed argument, or -1 in case of error.\r
285 + *\r
286 + */\r
287  int\r
288  parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_index);\r
289  \r
290 @@ -69,12 +69,12 @@ parse_arguments (int argc, char **argv, const notmuch_opt_desc_t *options, int o\r
291   */\r
292  \r
293  notmuch_bool_t\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
296  \r
297  notmuch_bool_t\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
302  \r
303  \r
304  #endif\r
305 diff --git a/debugger.c b/debugger.c\r
306 index e8b9378..1d35e1f 100644\r
307 --- a/debugger.c\r
308 +++ b/debugger.c\r
309 @@ -38,8 +38,7 @@ debugger_is_active (void)\r
310  \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
314 -    {\r
315 +       strncmp (basename (buf), "gdb", 3) == 0) {\r
316         return TRUE;\r
317      }\r
318  \r
319 diff --git a/hooks.c b/hooks.c\r
320 index 44ee419..d995171 100644\r
321 --- a/hooks.c\r
322 +++ b/hooks.c\r
323 @@ -50,7 +50,7 @@ notmuch_run_hook (const char *db_path, const char *hook)\r
324         goto DONE;\r
325      }\r
326  \r
327 -    pid = fork();\r
328 +    pid = fork ();\r
329      if (pid == -1) {\r
330         fprintf (stderr, "Error: %s hook fork failed: %s\n", hook,\r
331                  strerror (errno));\r
332 @@ -75,7 +75,7 @@ notmuch_run_hook (const char *db_path, const char *hook)\r
333         goto DONE;\r
334      }\r
335  \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
343 --- a/mime-node.c\r
344 +++ b/mime-node.c\r
345 @@ -87,7 +87,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
346      }\r
347  \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
353         goto DONE;\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
356  \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
362         goto DONE;\r
363      }\r
364  \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
370         goto DONE;\r
371 @@ -124,7 +124,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
372      *root_out = root;\r
373      return NOTMUCH_STATUS_SUCCESS;\r
374  \r
375 -DONE:\r
376 +  DONE:\r
377      talloc_free (root);\r
378      return status;\r
379  }\r
380 @@ -144,6 +144,7 @@ static void\r
381  set_signature_list_destructor (mime_node_t *node)\r
382  {\r
383      GMimeSignatureList **proxy = talloc (node, GMimeSignatureList *);\r
384 +\r
385      if (proxy) {\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
389      }\r
390      g_object_unref (decrypt_result);\r
391  \r
392 - DONE:\r
393 +  DONE:\r
394      if (err)\r
395         g_error_free (err);\r
396  }\r
397 @@ -221,6 +222,7 @@ set_signature_validity_destructor (mime_node_t *node,\r
398                                    GMimeSignatureValidity *sig_validity)\r
399  {\r
400      GMimeSignatureValidity **proxy = talloc (node, GMimeSignatureValidity *);\r
401 +\r
402      if (proxy) {\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
408  \r
409 - DONE:\r
410 +  DONE:\r
411      if (err)\r
412         g_error_free (err);\r
413  }\r
414  \r
415 -#endif  /* GMIME_ATLEAST_26 */\r
416 +#endif /* GMIME_ATLEAST_26 */\r
417  \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
422      node->part = part;\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
428         return NULL;\r
429 @@ -360,7 +362,7 @@ mime_node_child (mime_node_t *parent, int child)\r
430      GMimeObject *sub;\r
431      mime_node_t *node;\r
432  \r
433 -    if (!parent || !parent->part || child < 0 || child >= parent->nchildren)\r
434 +    if (! parent || ! parent->part || child < 0 || child >= parent->nchildren)\r
435         return NULL;\r
436  \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
439         return node;\r
440  \r
441      *n -= 1;\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
446 -       if (!ret)\r
447 +       if (! ret)\r
448             talloc_free (child);\r
449      }\r
450      return ret;\r
451 -- \r
452 1.8.4.2\r
453 \r