From 43f05b2fd39ad6209d6a9ef350bbc3183ca7c221 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Tue, 21 May 2013 21:42:30 +0300 Subject: [PATCH] [RFC PATCH 1/1] add --stderr option --- 99/6c3fc8bb7c0aa1832b10b5c1b65f98d2855b87 | 118 ++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 99/6c3fc8bb7c0aa1832b10b5c1b65f98d2855b87 diff --git a/99/6c3fc8bb7c0aa1832b10b5c1b65f98d2855b87 b/99/6c3fc8bb7c0aa1832b10b5c1b65f98d2855b87 new file mode 100644 index 000000000..1f13d2be2 --- /dev/null +++ b/99/6c3fc8bb7c0aa1832b10b5c1b65f98d2855b87 @@ -0,0 +1,118 @@ +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 C4436431FB6 + for ; Tue, 21 May 2013 11:42:42 -0700 (PDT) +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 g2vnzCchdrmJ for ; + Tue, 21 May 2013 11:42:36 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 82B1B431FBF + for ; Tue, 21 May 2013 11:42:36 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 05B871002C4; Tue, 21 May 2013 21:42:33 +0300 (EEST) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [RFC PATCH 1/1] add --stderr option +Date: Tue, 21 May 2013 21:42:30 +0300 +Message-Id: <1369161750-12342-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: Tue, 21 May 2013 18:42:42 -0000 + +--- + +Note quickly written untested code (but compiles!), just to show an idea... + +This implements (i hope) curl(1) --stderr option in notmuch(1): + + --stderr + Redirect all writes to stderr to the specified file instead. If + the file name is a plain '-', it is instead written to stdout. + +This would be useful in emacs interface. + +Please comment; I'll do help and manual page changes (and NEWS) if +this is good idea :D + +Tomi + + + notmuch.c | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/notmuch.c b/notmuch.c +index f51a84f..3b8bd5d 100644 +--- a/notmuch.c ++++ b/notmuch.c +@@ -21,6 +21,7 @@ + */ + + #include "notmuch-client.h" ++#include + + typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]); + +@@ -259,6 +260,7 @@ main (int argc, char *argv[]) + const char *command_name = NULL; + command_t *command; + char *config_file_name = NULL; ++ char *stderr_file = NULL; + notmuch_config_t *config; + notmuch_bool_t print_help=FALSE, print_version=FALSE; + int opt_index; +@@ -268,6 +270,7 @@ main (int argc, char *argv[]) + { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 }, + { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 }, + { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 }, ++ { NOTMUCH_OPT_STRING, &stderr_file, "stderr", 'c', 0 }, + { 0, 0, 0, 0, 0 } + }; + +@@ -295,6 +298,23 @@ main (int argc, char *argv[]) + return 0; + } + ++ if (stderr_file) { ++ if (strcmp (stderr_file, "-") == 0) ++ dup2 (STDOUT_FILENO, STDERR_FILENO); ++ else { ++ int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644); ++ if (fd < 0) { ++ fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n", ++ stderr_file, strerror(errno)); ++ return 1; ++ } ++ if (fd != STDERR_FILENO) { ++ dup2 (fd, STDERR_FILENO); ++ close (fd); ++ } ++ } ++ } ++ + if (opt_index < argc) + command_name = argv[opt_index]; + +-- +1.8.1.4 + -- 2.26.2