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 E2252431FAF for ; Fri, 7 Dec 2012 14:30:12 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 THB0CiB4yGjf for ; Fri, 7 Dec 2012 14:30:11 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D6279431FAE for ; Fri, 7 Dec 2012 14:30:10 -0800 (PST) Received: by mail-la0-f53.google.com with SMTP id w12so740845lag.26 for ; Fri, 07 Dec 2012 14:30:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type:x-gm-message-state; bh=zXDnvmf7BLZHE1AJooTBfYmmwDazhyRfUyOI8SXN6t4=; b=hwqrRzgvxU2EEde4Kmw7oGyiSX4OJNqsBzYyFQF9G1wgO2eVsQ5ED9l75bfy9jlP+G wmcjBsTyLtCn7vnGVMmQTlsvXacSY9EC1clmoPl3cZ3JkWHtXV3CDRDZj2MTcXJpqfcr V562FA0FXHkGnpNFEojwY5onlEfwFFCq/2SwGGilcbT+1Z4KYvyf/FsCPmaTBIbBgXVC qUTX/hB76xJa8riO4ZNGLPn4kqPVQh5coz4hsm2e19kCEZIz1A0EoukGJ3FwcdCQPZEJ ZbNdmndUQj+ZDyLc9hUDeUfCFOQF8RdVWmC+m/EuZ4gEZS1L/122B11+8jCbqffJqrlc W7CQ== Received: by 10.112.43.165 with SMTP id x5mr611380lbl.76.1354919409264; Fri, 07 Dec 2012 14:30:09 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id oj5sm5086470lab.8.2012.12.07.14.30.07 (version=SSLv3 cipher=OTHER); Fri, 07 Dec 2012 14:30:08 -0800 (PST) From: Jani Nikula 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+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Sat, 08 Dec 2012 00:30:05 +0200 Message-ID: <87wqwtxzpu.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQmrpRJ9C7PukVepc4RcdtqfKUiyfemh2JRk0tTbPnZlB3RBpOTC0Dte2uQSgtrlMZpJMyFl 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: Fri, 07 Dec 2012 22:30:13 -0000 LGTM. 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 > + * } > + */ > + > +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