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 2B13241733A for ; Sat, 24 Apr 2010 04:45:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] autolearn=ham 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 Y0BwFBsn-rMo for ; Sat, 24 Apr 2010 04:45:29 -0700 (PDT) Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57]) by olra.theworths.org (Postfix) with ESMTP id 6B4C741733F for ; Sat, 24 Apr 2010 04:45:29 -0700 (PDT) Received: from fctnnbsc30w-142167190087.pppoe-dynamic.high-speed.nb.bellaliant.net ([142.167.190.87] helo=rocinante.cs.unb.ca) by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1O5dnc-00030i-Vj; Sat, 24 Apr 2010 08:45:29 -0300 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.71) (envelope-from ) id 1O5dn6-0005Qi-Ja; Sat, 24 Apr 2010 08:44:56 -0300 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH 2/3] notmuch-output.[ch]: initial implementation of output selection argument handling. Date: Sat, 24 Apr 2010 08:44:37 -0300 Message-Id: <1272109478-20686-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1272109478-20686-1-git-send-email-david@tethera.net> References: <1272109478-20686-1-git-send-email-david@tethera.net> X-Sender-Verified: bremner@pivot.cs.unb.ca Cc: David Bremner 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, 24 Apr 2010 11:45:32 -0000 From: David Bremner These two files provide a more or less "object oriented" approach to parsing output selection arguments. The use of a struct to track which output pieces are selected is intended to hide the implementation, which currently uses bitmasks. --- Makefile.local | 1 + notmuch-output.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ notmuch-output.h | 49 ++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 0 deletions(-) create mode 100644 notmuch-output.c create mode 100644 notmuch-output.h diff --git a/Makefile.local b/Makefile.local index 5bb570b..eb78679 100644 --- a/Makefile.local +++ b/Makefile.local @@ -240,6 +240,7 @@ notmuch_client_srcs = \ notmuch-count.c \ notmuch-dump.c \ notmuch-new.c \ + notmuch-output.c \ notmuch-reply.c \ notmuch-restore.c \ notmuch-search.c \ diff --git a/notmuch-output.c b/notmuch-output.c new file mode 100644 index 0000000..a84bbe1 --- /dev/null +++ b/notmuch-output.c @@ -0,0 +1,95 @@ +/* notmuch-output.h --- encapsulate handling of output selection. + * + * Copyright 2010 © David Bremner + * + * This file is part of Notmuch. + * + * Notmuch is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Notmuch is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Notmuch. If not, see . + * + * Authors: David Bremner + */ + +#include "notmuch-client.h" +#include "notmuch-output.h" + +notmuch_output_options_t * +output_init(void *ctx){ + notmuch_output_options_t *output_opts; + + output_opts = talloc (ctx, notmuch_output_options_t); + output_opts->output_all=TRUE; + output_opts->mask=0; + return output_opts; +} + +int +output_parse_arg(notmuch_output_options_t *output_opts, const char *arg){ + + char *opt; + + struct { const char *name; notmuch_output_t key; } parse_try[]={ + {"bcc", NOTMUCH_OUTPUT_BCC}, + {"body", NOTMUCH_OUTPUT_BODY}, + {"cc", NOTMUCH_OUTPUT_CC}, + {"date",NOTMUCH_OUTPUT_DATE}, + {"from",NOTMUCH_OUTPUT_FROM}, + {"message-id",NOTMUCH_OUTPUT_MESSAGE_ID}, + {"subject",NOTMUCH_OUTPUT_SUBJECT}, + {"to", NOTMUCH_OUTPUT_TO}, + }; + + opt = strchr(arg, '='); + if (!opt) + return 1; + + opt++; + + output_opts->output_all=FALSE; + + while(opt) { + unsigned int i; + notmuch_bool_t found = FALSE; + notmuch_output_t key = 0; + + for (i = 0; imask |= (1<output_all) + return 1; + + return (opts->mask & (1<. + * + * Authors: David Bremner + */ + +#ifndef NOTMUCH_OUTPUT_H +#define NOTMUCH_OUTPUT_H + +typedef struct notmuch_output_struct { + notmuch_bool_t output_all; + int mask; +} notmuch_output_options_t; + +typedef enum notmuch_output_enum { + NOTMUCH_OUTPUT_BCC, + NOTMUCH_OUTPUT_BODY, + NOTMUCH_OUTPUT_CC, + NOTMUCH_OUTPUT_DATE, + NOTMUCH_OUTPUT_FROM, + NOTMUCH_OUTPUT_MESSAGE_ID, + NOTMUCH_OUTPUT_SUBJECT, + NOTMUCH_OUTPUT_TO +} notmuch_output_t; + +notmuch_output_options_t *output_init(void *ctx); + +int output_parse_arg(notmuch_output_options_t *opts, + const char* arg); + +notmuch_bool_t output_get_flag(notmuch_output_options_t *opts, + notmuch_output_t flag); +#endif -- 1.7.0