1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 47593431FC2
\r
6 for <notmuch@notmuchmail.org>; Sat, 8 Dec 2012 14:57:51 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id MCDtX-xUCeIS for <notmuch@notmuchmail.org>;
\r
16 Sat, 8 Dec 2012 14:57:49 -0800 (PST)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 98D1F431FCB
\r
21 for <notmuch@notmuchmail.org>; Sat, 8 Dec 2012 14:57:42 -0800 (PST)
\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([142.167.90.129] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>)
\r
27 id 1ThTL3-00066f-Ef; Sat, 08 Dec 2012 18:57:41 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1ThTKx-0000qX-Vo; Sat, 08 Dec 2012 18:57:36 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v5 03/11] util: add string-util.[ch]
\r
34 Date: Sat, 8 Dec 2012 18:56:53 -0400
\r
35 Message-Id: <1355007421-3069-4-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1355007421-3069-1-git-send-email-david@tethera.net>
\r
38 References: <1355007421-3069-1-git-send-email-david@tethera.net>
\r
40 Cc: David Bremner <bremner@debian.org>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sat, 08 Dec 2012 22:57:51 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 This is to give a home to strtok_len. It's a bit silly to add a header
\r
58 for one routine, but it needs to be shared between several compilation
\r
59 units (or at least that's the most natural design).
\r
61 util/Makefile.local | 3 ++-
\r
62 util/string-util.c | 34 ++++++++++++++++++++++++++++++++++
\r
63 util/string-util.h | 22 ++++++++++++++++++++++
\r
64 3 files changed, 58 insertions(+), 1 deletion(-)
\r
65 create mode 100644 util/string-util.c
\r
66 create mode 100644 util/string-util.h
\r
68 diff --git a/util/Makefile.local b/util/Makefile.local
\r
69 index 3ca623e..a11e35b 100644
\r
70 --- a/util/Makefile.local
\r
71 +++ b/util/Makefile.local
\r
74 extra_cflags += -I$(srcdir)/$(dir)
\r
76 -libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c
\r
77 +libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
\r
78 + $(dir)/string-util.c
\r
80 libutil_modules := $(libutil_c_srcs:.c=.o)
\r
82 diff --git a/util/string-util.c b/util/string-util.c
\r
83 new file mode 100644
\r
84 index 0000000..44f8cd3
\r
86 +++ b/util/string-util.c
\r
88 +/* string-util.c - Extra or enhanced routines for null terminated strings.
\r
90 + * Copyright (c) 2012 Jani Nikula
\r
92 + * This program is free software: you can redistribute it and/or modify
\r
93 + * it under the terms of the GNU General Public License as published by
\r
94 + * the Free Software Foundation, either version 3 of the License, or
\r
95 + * (at your option) any later version.
\r
97 + * This program is distributed in the hope that it will be useful,
\r
98 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
99 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
100 + * GNU General Public License for more details.
\r
102 + * You should have received a copy of the GNU General Public License
\r
103 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
105 + * Author: Jani Nikula <jani@nikula.org>
\r
109 +#include "string-util.h"
\r
112 +strtok_len (char *s, const char *delim, size_t *len)
\r
114 + /* skip initial delims */
\r
115 + s += strspn (s, delim);
\r
117 + /* length of token */
\r
118 + *len = strcspn (s, delim);
\r
120 + return *len ? s : NULL;
\r
122 diff --git a/util/string-util.h b/util/string-util.h
\r
123 new file mode 100644
\r
124 index 0000000..ac7676c
\r
126 +++ b/util/string-util.h
\r
128 +#ifndef _STRING_UTIL_H
\r
129 +#define _STRING_UTIL_H
\r
131 +#include <string.h>
\r
133 +/* like strtok(3), but without state, and doesn't modify s. Return
\r
134 + * value is indicated by pointer and length, not null terminator.
\r
138 + * const char *tok = input;
\r
139 + * const char *delim = " \t";
\r
140 + * size_t tok_len = 0;
\r
142 + * while ((tok = strtok_len (tok + tok_len, delim, &tok_len)) != NULL) {
\r
143 + * // do stuff with string tok of length tok_len
\r
147 +char *strtok_len (char *s, const char *delim, size_t *len);
\r