From 43a358112ca45de87b074f9bcfcee75c87efcddf Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sat, 8 Dec 2012 10:23:31 +0000 Subject: [PATCH] Re: [Patch v3b 3/9] util: add string-util.[ch] --- 19/a0d879feae6b21d1394961665213b01e54899e | 188 ++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 19/a0d879feae6b21d1394961665213b01e54899e diff --git a/19/a0d879feae6b21d1394961665213b01e54899e b/19/a0d879feae6b21d1394961665213b01e54899e new file mode 100644 index 000000000..eff84c05d --- /dev/null +++ b/19/a0d879feae6b21d1394961665213b01e54899e @@ -0,0 +1,188 @@ +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 BBB18431FAF + for ; Sat, 8 Dec 2012 02:23:30 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 g8IqSLKq5Q1g for ; + Sat, 8 Dec 2012 02:23:29 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D3D8A431FAE + for ; Sat, 8 Dec 2012 02:23:28 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1ThHZ8-0001Cm-Je; Sat, 08 Dec 2012 10:23:27 +0000 +Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1ThHZ8-0005nd-8F; Sat, 08 Dec 2012 10:23:26 +0000 +From: Mark Walters +To: david@tethera.net, notmuch@notmuchmail.org +Subject: Re: [Patch v3b 3/9] util: add string-util.[ch] +In-Reply-To: <1354843607-17980-4-git-send-email-david@tethera.net> +References: <1354843607-17980-1-git-send-email-david@tethera.net> + <1354843607-17980-4-git-send-email-david@tethera.net> +User-Agent: Notmuch/0.14+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sat, 08 Dec 2012 10:23:31 +0000 +Message-ID: <87624chmfw.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 93.97.24.31 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: 474b2fde85e2a27169ebced9ccff334b (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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, 08 Dec 2012 10:23:30 -0000 + + +On Fri, 07 Dec 2012, david@tethera.net wrote: +> From: David Bremner +> +> This is to give a home to strtok_len. It's a bit silly to add a header +> for one routine, but it needs to be shared between several compilation +> units (or at least that's the most natural design). +> --- +> util/Makefile.local | 3 ++- +> util/string-util.c | 34 ++++++++++++++++++++++++++++++++++ +> util/string-util.h | 19 +++++++++++++++++++ +> 3 files changed, 55 insertions(+), 1 deletion(-) +> create mode 100644 util/string-util.c +> create mode 100644 util/string-util.h +> +> diff --git a/util/Makefile.local b/util/Makefile.local +> index 3ca623e..a11e35b 100644 +> --- a/util/Makefile.local +> +++ b/util/Makefile.local +> @@ -3,7 +3,8 @@ +> dir := util +> extra_cflags += -I$(srcdir)/$(dir) +> +> -libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c +> +libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \ +> + $(dir)/string-util.c +> +> libutil_modules := $(libutil_c_srcs:.c=.o) +> +> diff --git a/util/string-util.c b/util/string-util.c +> new file mode 100644 +> index 0000000..44f8cd3 +> --- /dev/null +> +++ b/util/string-util.c +> @@ -0,0 +1,34 @@ +> +/* string-util.c - Extra or enhanced routines for null terminated strings. +> + * +> + * Copyright (c) 2012 Jani Nikula +> + * +> + * This program 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. +> + * +> + * This program 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 this program. If not, see http://www.gnu.org/licenses/ . +> + * +> + * Author: Jani Nikula +> + */ +> + +> + +> +#include "string-util.h" +> + +> +char * +> +strtok_len (char *s, const char *delim, size_t *len) +> +{ +> + /* skip initial delims */ +> + s += strspn (s, delim); +> + +> + /* length of token */ +> + *len = strcspn (s, delim); +> + +> + return *len ? s : NULL; +> +} +> diff --git a/util/string-util.h b/util/string-util.h +> new file mode 100644 +> index 0000000..696da40 +> --- /dev/null +> +++ b/util/string-util.h +> @@ -0,0 +1,19 @@ +> +#ifndef _STRING_UTIL_H +> +#define _STRING_UTIL_H +> + +> +#include +> + +> +/* like strtok(3), but without state, and doesn't modify s. usage pattern: +> + * +> + * const char *tok = input; +> + * const char *delim = " \t"; +> + * size_t tok_len = 0; +> + * +> + * while ((tok = strtok_len (tok + tok_len, delim, &tok_len)) != NULL) { +> + * // do stuff with string tok of length tok_len +> + * } + +Hi + +Some possibly silly comments on the comment. strtok(3) seems to return a +null terminated string and this does not. Might be worth including in +the comment? Secondly every time I read this I read "..modify s. usage +pattern" as one ongoing sentence with s. an abbreviation. Perhaps a +capital u? and maybe str or string rather than s? + +Best wishes + +Mark + +> + */ +> + +> +char *strtok_len (char *s, const char *delim, size_t *len); +> + +> +#endif +> -- +> 1.7.10.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2