From: david Date: Fri, 7 Dec 2012 01:26:41 +0000 (+2000) Subject: [Patch v3b 3/9] util: add string-util.[ch] X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e239b9fe06cf6b8b2c9a17873c6a32ab8a782e46;p=notmuch-archives.git [Patch v3b 3/9] util: add string-util.[ch] --- diff --git a/e8/87a602ed422411a7f072b15ea59cbadc243be3 b/e8/87a602ed422411a7f072b15ea59cbadc243be3 new file mode 100644 index 000000000..ec9d28973 --- /dev/null +++ b/e8/87a602ed422411a7f072b15ea59cbadc243be3 @@ -0,0 +1,149 @@ +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 E660B431FC2 + for ; Thu, 6 Dec 2012 17:27:28 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 DYD7vi43PWS9 for ; + Thu, 6 Dec 2012 17:27:27 -0800 (PST) +Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) + (using TLSv1 with cipher AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id ABFB9431FD6 + for ; Thu, 6 Dec 2012 17:27:13 -0800 (PST) +Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net + ([142.167.90.129] helo=zancas.localnet) + by tesseract.cs.unb.ca with esmtpsa + (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) + (envelope-from ) + id 1Tgmie-0003Ns-Fw; Thu, 06 Dec 2012 21:27:13 -0400 +Received: from bremner by zancas.localnet with local (Exim 4.80) + (envelope-from ) + id 1TgmiY-0004kT-Vz; Thu, 06 Dec 2012 21:27:07 -0400 +From: david@tethera.net +To: notmuch@notmuchmail.org +Subject: [Patch v3b 3/9] util: add string-util.[ch] +Date: Thu, 6 Dec 2012 21:26:41 -0400 +Message-Id: <1354843607-17980-4-git-send-email-david@tethera.net> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1354843607-17980-1-git-send-email-david@tethera.net> +References: <1354843607-17980-1-git-send-email-david@tethera.net> +X-Spam_bar: - +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 01:27:29 -0000 + +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 +