Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 99 / 6c3fc8bb7c0aa1832b10b5c1b65f98d2855b87
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 C4436431FB6\r
6         for <notmuch@notmuchmail.org>; Tue, 21 May 2013 11:42:42 -0700 (PDT)\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 g2vnzCchdrmJ for <notmuch@notmuchmail.org>;\r
16         Tue, 21 May 2013 11:42:36 -0700 (PDT)\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 82B1B431FBF\r
19         for <notmuch@notmuchmail.org>; Tue, 21 May 2013 11:42:36 -0700 (PDT)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 05B871002C4; Tue, 21 May 2013 21:42:33 +0300 (EEST)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [RFC PATCH 1/1] add --stderr option\r
25 Date: Tue, 21 May 2013 21:42:30 +0300\r
26 Message-Id: <1369161750-12342-1-git-send-email-tomi.ollila@iki.fi>\r
27 X-Mailer: git-send-email 1.8.0\r
28 Cc: tomi.ollila@iki.fi\r
29 X-BeenThere: notmuch@notmuchmail.org\r
30 X-Mailman-Version: 2.1.13\r
31 Precedence: list\r
32 List-Id: "Use and development of the notmuch mail system."\r
33         <notmuch.notmuchmail.org>\r
34 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
35         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
36 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
37 List-Post: <mailto:notmuch@notmuchmail.org>\r
38 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
39 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
41 X-List-Received-Date: Tue, 21 May 2013 18:42:42 -0000\r
42 \r
43 ---\r
44 \r
45 Note quickly written untested code (but compiles!), just to show an idea...\r
46 \r
47 This implements (i hope) curl(1) --stderr option in notmuch(1):\r
48 \r
49        --stderr <file>\r
50               Redirect  all writes to stderr to the specified file instead. If\r
51               the file name is a plain '-', it is instead written to stdout.\r
52 \r
53 This would be useful in emacs interface.\r
54 \r
55 Please comment; I'll do help and manual page changes (and NEWS) if\r
56 this is good idea :D\r
57 \r
58 Tomi\r
59 \r
60 \r
61  notmuch.c | 20 ++++++++++++++++++++\r
62  1 file changed, 20 insertions(+)\r
63 \r
64 diff --git a/notmuch.c b/notmuch.c\r
65 index f51a84f..3b8bd5d 100644\r
66 --- a/notmuch.c\r
67 +++ b/notmuch.c\r
68 @@ -21,6 +21,7 @@\r
69   */\r
70  \r
71  #include "notmuch-client.h"\r
72 +#include <fcntl.h>\r
73  \r
74  typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]);\r
75  \r
76 @@ -259,6 +260,7 @@ main (int argc, char *argv[])\r
77      const char *command_name = NULL;\r
78      command_t *command;\r
79      char *config_file_name = NULL;\r
80 +    char *stderr_file = NULL;\r
81      notmuch_config_t *config;\r
82      notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
83      int opt_index;\r
84 @@ -268,6 +270,7 @@ main (int argc, char *argv[])\r
85         { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
86         { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
87         { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },\r
88 +       { NOTMUCH_OPT_STRING, &stderr_file, "stderr", 'c', 0 },\r
89         { 0, 0, 0, 0, 0 }\r
90      };\r
91  \r
92 @@ -295,6 +298,23 @@ main (int argc, char *argv[])\r
93         return 0;\r
94      }\r
95  \r
96 +    if (stderr_file) {\r
97 +       if (strcmp (stderr_file, "-") == 0)\r
98 +           dup2 (STDOUT_FILENO, STDERR_FILENO);\r
99 +       else {\r
100 +           int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);\r
101 +           if (fd < 0) {\r
102 +               fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",\r
103 +                        stderr_file, strerror(errno));\r
104 +               return 1;\r
105 +           }\r
106 +           if (fd != STDERR_FILENO) {\r
107 +               dup2 (fd, STDERR_FILENO);\r
108 +               close (fd);\r
109 +           }\r
110 +       }\r
111 +    }\r
112 +\r
113      if (opt_index < argc)\r
114         command_name = argv[opt_index];\r
115  \r
116 -- \r
117 1.8.1.4\r
118 \r