From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 78F72431FAF for ; Fri, 30 Nov 2012 15:41:19 -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 aFBT+GJPZGGG for ; Fri, 30 Nov 2012 15:41:14 -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 88BE4431FAE for ; Fri, 30 Nov 2012 15:41:14 -0800 (PST) Received: by mail-la0-f53.google.com with SMTP id w12so856013lag.26 for ; Fri, 30 Nov 2012 15:41:13 -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=1EGn6wO1dSLpXY+kkHKIjg5LDDjuTdbAzUiqTGtYMvE=; b=bj46xxPARHmrT7Hlstl2rfv0UMDqK8teBWsXfcJ+zXlWQ5SBpKedjiDUCCOtSnQLME CySZU3PP0FdO/kpY5er2RSSDCHtvk9oIDc9Yxgr0EMA/9am+uinc/YaverTt/3vi7FeI FjFgTQ4Te4TX43HpKx8qal1jDgOHYrSd7OGv/3ZYiqm4a7q7xXABTU4ef4w0b05p/rcE 1MZzlsmTJt97ZVp3AE4U44i7nMM8a1Aop5KbdhTNfyAZimzjtJgUZz4O1l9NwQi3wvq7 1/3FhFvCGuTOfhFz4zmb0lh33ze/M/z/P1dAB2KggmqQ259nZ73SjTY253GicYKoOm8w RZoA== Received: by 10.112.87.40 with SMTP id u8mr1507442lbz.50.1354318873013; Fri, 30 Nov 2012 15:41:13 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id y10sm2591311lbg.4.2012.11.30.15.41.11 (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 15:41:12 -0800 (PST) From: Jani Nikula To: david@tethera.net, notmuch@notmuchmail.org Subject: Re: [Patch v2 08/17] util: add string-util.[ch] In-Reply-To: <1353792017-31459-9-git-send-email-david@tethera.net> References: <1353792017-31459-1-git-send-email-david@tethera.net> <1353792017-31459-9-git-send-email-david@tethera.net> User-Agent: Notmuch/0.14+124~g3b17402 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Sat, 01 Dec 2012 01:41:10 +0200 Message-ID: <87fw3qacbt.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQlPD5mWqDrmF9iww2q0eKzzno/lhBpTRYocnHH5V5ePHXAn4i6XiR7XJB1ni12aMBHwTgpl 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, 30 Nov 2012 23:41:19 -0000 On Sat, 24 Nov 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). Good stuff! ;) Jani. > --- > 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