From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 1D0426DE0BB8 for ; Wed, 10 May 2017 04:39:23 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ss_9DyY1q0w5 for ; Wed, 10 May 2017 04:39:20 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 0136B6DE091E for ; Wed, 10 May 2017 04:39:19 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1d8Pwn-0000fD-BW; Wed, 10 May 2017 07:38:25 -0400 Received: (nullmailer pid 28571 invoked by uid 1000); Wed, 10 May 2017 11:39:15 -0000 From: David Bremner To: notmuch@freelists.org, notmuch@notmuchmail.org Subject: [PATCH 3/6] lib/index: separate state table definition from scanner. Date: Wed, 10 May 2017 08:39:07 -0300 Message-Id: <20170510113910.28444-4-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170510113910.28444-1-david@tethera.net> References: <20170510113910.28444-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Wed, 10 May 2017 11:39:23 -0000 We want to reuse the scanner definition with a different table --- lib/index.cc | 81 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/lib/index.cc b/lib/index.cc index 74a750b9..02b35b81 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -31,6 +31,15 @@ typedef struct _NotmuchFilterDiscardUuencodeClass NotmuchFilterDiscardUuencodeCl typedef void (*filter_fun) (GMimeFilter *filter, char *in, size_t len, size_t prespace, char **out, size_t *outlen, size_t *outprespace); + +typedef struct { + int state; + int a; + int b; + int next_if_match; + int next_if_not_match; +} scanner_state_t; + /** * NotmuchFilterDiscardUuencode: * @@ -119,46 +128,18 @@ filter_filter (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t pres } static void -filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace, - char **outbuf, size_t *outlen, size_t *outprespace) +do_filter (const scanner_state_t states[], + int first_skipping_state, + GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace, + char **outbuf, size_t *outlen, size_t *outprespace) { NotmuchFilterDiscardUuencode *filter = (NotmuchFilterDiscardUuencode *) gmime_filter; register const char *inptr = inbuf; const char *inend = inbuf + inlen; char *outptr; - + int next; (void) prespace; - /* Simple, linear state-transition diagram for our filter. - * - * If the character being processed is within the range of [a, b] - * for the current state then we transition next_if_match - * state. If not, we transition to the next_if_not_match state. - * - * The final two states are special in that they are the states in - * which we discard data. */ - static const struct { - int state; - int a; - int b; - int next_if_match; - int next_if_not_match; - } states[] = { - {0, 'b', 'b', 1, 0}, - {1, 'e', 'e', 2, 0}, - {2, 'g', 'g', 3, 0}, - {3, 'i', 'i', 4, 0}, - {4, 'n', 'n', 5, 0}, - {5, ' ', ' ', 6, 0}, - {6, '0', '7', 7, 0}, - {7, '0', '7', 8, 0}, - {8, '0', '7', 9, 0}, - {9, ' ', ' ', 10, 0}, - {10, '\n', '\n', 11, 10}, - {11, 'M', 'M', 12, 0}, - {12, ' ', '`', 12, 11} - }; - int next; g_mime_filter_set_size (gmime_filter, inlen, FALSE); outptr = gmime_filter->outbuf; @@ -174,7 +155,7 @@ filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, si next = states[filter->state].next_if_not_match; } - if (filter->state < 11) + if (filter->state < first_skipping_state) *outptr++ = *inptr; filter->state = next; @@ -187,6 +168,38 @@ filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, si } static void +filter_filter_uuencode (GMimeFilter *gmime_filter, char *inbuf, size_t inlen, size_t prespace, + char **outbuf, size_t *outlen, size_t *outprespace) +{ + /* Simple, linear state-transition diagram for our filter. + * + * If the character being processed is within the range of [a, b] + * for the current state then we transition next_if_match + * state. If not, we transition to the next_if_not_match state. + * + * The final two states are special in that they are the states in + * which we discard data. */ + static const scanner_state_t states[] = { + {0, 'b', 'b', 1, 0}, + {1, 'e', 'e', 2, 0}, + {2, 'g', 'g', 3, 0}, + {3, 'i', 'i', 4, 0}, + {4, 'n', 'n', 5, 0}, + {5, ' ', ' ', 6, 0}, + {6, '0', '7', 7, 0}, + {7, '0', '7', 8, 0}, + {8, '0', '7', 9, 0}, + {9, ' ', ' ', 10, 0}, + {10, '\n', '\n', 11, 10}, + {11, 'M', 'M', 12, 0}, + {12, ' ', '`', 12, 11} + }; + + do_filter(states, 11, + gmime_filter, inbuf, inlen, prespace, outbuf, outlen, outprespace); +} + +static void filter_complete (GMimeFilter *filter, char *inbuf, size_t inlen, size_t prespace, char **outbuf, size_t *outlen, size_t *outprespace) { -- 2.11.0