aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-07-10 10:09:45 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-07-10 10:09:45 +0300
commitd73567ebdf054eb6de6dea72250ef164e4c50eec (patch)
treec8d48504b02786e13215923b3e2654fe42275f0d /src
parentee35adccec058a5a8cc62f5030b9a925168236d6 (diff)
downloadgrecs-d73567ebdf054eb6de6dea72250ef164e4c50eec.tar.gz
grecs-d73567ebdf054eb6de6dea72250ef164e4c50eec.tar.bz2
Import wordsplit as a submodule
* .gitmodules: New module: wordsplit * Makefile.am: Distribute wordsplit files. * am/grecs.m4 (GRECS_INCLUDES): Add wordsplit directory * doc/Makefile.am (dist_man_MANS): Distribute wordsplit/wordsplit.3 * doc/wordsplit.3: Remove. * include/Makefile.am (GRECS_HDR): Add wordsplit/wordsplit. * include/wordsplit.h: Remove. * src/Make-inst.am: Define nodist_libgrecs_la_SOURCES. * src/Make-shared.am: Likewise. * src/Make-static.am: Define nodist_libgrecs_a_SOURCES. * src/Make.am (GRECS_SRC): Remove wordsplit.c (NODIST_GRECS_SRC): Define to wordsplit.c (VPATH): Add the wordsplit directory. * src/wordsplit.c: Remove. * tests/wordsplit.at: Remove. * tests/wsp.c: Remove. * tests/Makefile.am: Build separate testsuite for wordsplit. Use VPATH to build wsp. * tests/.gitignore: Update.
Diffstat (limited to 'src')
-rw-r--r--src/Make-inst.am4
-rw-r--r--src/Make-shared.am3
-rw-r--r--src/Make-static.am3
-rw-r--r--src/Make.am6
-rw-r--r--src/wordsplit.c2892
5 files changed, 11 insertions, 2897 deletions
diff --git a/src/Make-inst.am b/src/Make-inst.am
index a4b6aea..1eb04bb 100644
--- a/src/Make-inst.am
+++ b/src/Make-inst.am
@@ -1,3 +1,3 @@
1# This file is part of grecs - Gray's Extensible Configuration System 1# This file is part of grecs - Gray's Extensible Configuration System
2# Copyright (C) 2007-2016 Sergey Poznyakoff 2# Copyright (C) 2007-2019 Sergey Poznyakoff
3# 3#
@@ -21 +21,3 @@ m4datadir = $(datadir)/aclocal
21dist_m4data_DATA = libgrecs.m4 21dist_m4data_DATA = libgrecs.m4
22nodist_libgrecs_la_SOURCES = $(NODIST_GRECS_SRC)
23
diff --git a/src/Make-shared.am b/src/Make-shared.am
index 9a762a4..f080e46 100644
--- a/src/Make-shared.am
+++ b/src/Make-shared.am
@@ -1,3 +1,3 @@
1# This file is part of grecs - Gray's Extensible Configuration System 1# This file is part of grecs - Gray's Extensible Configuration System
2# Copyright (C) 2007-2016 Sergey Poznyakoff 2# Copyright (C) 2007-2019 Sergey Poznyakoff
3# 3#
@@ -18,2 +18,3 @@ noinst_LTLIBRARIES=libgrecs.la
18libgrecs_la_SOURCES = $(GRECS_SRC) 18libgrecs_la_SOURCES = $(GRECS_SRC)
19nodist_libgrecs_la_SOURCES = $(NODIST_GRECS_SRC)
19 20
diff --git a/src/Make-static.am b/src/Make-static.am
index 2688b40..1f4cd3e 100644
--- a/src/Make-static.am
+++ b/src/Make-static.am
@@ -1,3 +1,3 @@
1# This file is part of grecs - Gray's Extensible Configuration System 1# This file is part of grecs - Gray's Extensible Configuration System
2# Copyright (C) 2007-2016 Sergey Poznyakoff 2# Copyright (C) 2007-2019 Sergey Poznyakoff
3# 3#
@@ -18,2 +18,3 @@ noinst_LIBRARIES=libgrecs.a
18libgrecs_a_SOURCES = $(GRECS_SRC) 18libgrecs_a_SOURCES = $(GRECS_SRC)
19nodist_libgrecs_a_SOURCES = $(NODIST_GRECS_SRC)
19 20
diff --git a/src/Make.am b/src/Make.am
index 9fa7688..5199991 100644
--- a/src/Make.am
+++ b/src/Make.am
@@ -1,3 +1,3 @@
1# This file is part of grecs - Gray's Extensible Configuration System 1# This file is part of grecs - Gray's Extensible Configuration System
2# Copyright (C) 2007-2016 Sergey Poznyakoff 2# Copyright (C) 2007-2019 Sergey Poznyakoff
3# 3#
@@ -71,3 +71,2 @@ GRECS_SRC = \
71 version.c\ 71 version.c\
72 wordsplit.c\
73 $(GRECS_JSON)\ 72 $(GRECS_JSON)\
@@ -78,2 +77,5 @@ GRECS_SRC = \
78 77
78VPATH += $(top_srcdir)/@GRECS_SUBDIR@/wordsplit
79NODIST_GRECS_SRC = wordsplit.c
80
79if GRECS_COND_SOCKADDR_LIST 81if GRECS_COND_SOCKADDR_LIST
diff --git a/src/wordsplit.c b/src/wordsplit.c
deleted file mode 100644
index 9179a87..0000000
--- a/src/wordsplit.c
+++ /dev/null
@@ -1,2892 +0,0 @@
1/* wordsplit - a word splitter
2 Copyright (C) 2009-2019 Sergey Poznyakoff
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20
21#include <errno.h>
22#include <ctype.h>
23#include <unistd.h>
24#include <stdlib.h>
25#include <string.h>
26#include <stdio.h>
27#include <stdarg.h>
28#include <pwd.h>
29#include <glob.h>
30#include <limits.h>
31
32#if ENABLE_NLS
33# include <gettext.h>
34#else
35# define gettext(msgid) msgid
36#endif
37#define _(msgid) gettext (msgid)
38#define N_(msgid) msgid
39
40#include <wordsplit.h>
41
42#define ISWS(c) ((c)==' '||(c)=='\t'||(c)=='\n')
43#define ISDELIM(ws,c) \
44 (strchr ((ws)->ws_delim, (c)) != NULL)
45#define ISPUNCT(c) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",(c))!=NULL)
46#define ISUPPER(c) ('A' <= ((unsigned) (c)) && ((unsigned) (c)) <= 'Z')
47#define ISLOWER(c) ('a' <= ((unsigned) (c)) && ((unsigned) (c)) <= 'z')
48#define ISALPHA(c) (ISUPPER(c) || ISLOWER(c))
49#define ISDIGIT(c) ('0' <= ((unsigned) (c)) && ((unsigned) (c)) <= '9')
50#define ISXDIGIT(c) (strchr("abcdefABCDEF", c)!=NULL)
51#define ISALNUM(c) (ISALPHA(c) || ISDIGIT(c))
52#define ISPRINT(c) (' ' <= ((unsigned) (c)) && ((unsigned) (c)) <= 127)
53
54#define ISVARBEG(c) (ISALPHA(c) || c == '_')
55#define ISVARCHR(c) (ISALNUM(c) || c == '_')
56
57#define WSP_RETURN_DELIMS(wsp) \
58 ((wsp)->ws_flags & WRDSF_RETURN_DELIMS || ((wsp)->ws_options & WRDSO_MAXWORDS))
59
60#define to_num(c) \
61 (ISDIGIT(c) ? c - '0' : (ISXDIGIT(c) ? toupper(c) - 'A' + 10 : 255 ))
62
63#define ALLOC_INIT 128
64#define ALLOC_INCR 128
65
66static void
67_wsplt_alloc_die (struct wordsplit *wsp)
68{
69 wsp->ws_error ("%s", _("memory exhausted"));
70 abort ();
71}
72
73static void
74_wsplt_error (const char *fmt, ...)
75{
76 va_list ap;
77
78 va_start (ap, fmt);
79 vfprintf (stderr, fmt, ap);
80 va_end (ap);
81 fputc ('\n', stderr);
82}
83
84static void wordsplit_free_nodes (struct wordsplit *);
85
86static int
87_wsplt_seterr (struct wordsplit *wsp, int ec)
88{
89 wsp->ws_errno = ec;
90 if (wsp->ws_flags & WRDSF_SHOWERR)
91 wordsplit_perror (wsp);
92 return ec;
93}
94
95static int
96_wsplt_nomem (struct wordsplit *wsp)
97{
98 errno = ENOMEM;
99 wsp->ws_errno = WRDSE_NOSPACE;
100 if (wsp->ws_flags & WRDSF_ENOMEMABRT)
101 wsp->ws_alloc_die (wsp);
102 if (wsp->ws_flags & WRDSF_SHOWERR)
103 wordsplit_perror (wsp);
104 if (!(wsp->ws_flags & WRDSF_REUSE))
105 wordsplit_free (wsp);
106 wordsplit_free_nodes (wsp);
107 return wsp->ws_errno;
108}
109
110static void
111_wsplt_store_errctx (struct wordsplit *wsp, char const *str, size_t len)
112{
113 free (wsp->ws_errctx);
114 wsp->ws_errctx = malloc (len + 1);
115 if (!wsp->ws_errctx)
116 {
117 wsp->ws_error ("%s",
118 _("memory exhausted while trying to store error context"));
119 }
120 else
121 {
122 memcpy (wsp->ws_errctx, str, len);
123 wsp->ws_errctx[len] = 0;
124 }
125}
126
127static inline int
128_wsplt_setctxerr (struct wordsplit *wsp, int ec, char const *str, size_t len)
129{
130 _wsplt_store_errctx (wsp, str, len);
131 return _wsplt_seterr (wsp, ec);
132}
133
134static int wordsplit_run (const char *command, size_t length,
135 struct wordsplit *wsp,
136 int flags, int lvl);
137
138static int wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
139 int flags);
140static int wordsplit_process_list (struct wordsplit *wsp, size_t start);
141static int wordsplit_finish (struct wordsplit *wsp);
142
143static int
144_wsplt_subsplit (struct wordsplit *wsp, struct wordsplit *wss,
145 char const *str, int len,
146 int flags, int finalize)
147{
148 int rc;
149
150 wss->ws_delim = wsp->ws_delim;
151 wss->ws_debug = wsp->ws_debug;
152 wss->ws_error = wsp->ws_error;
153 wss->ws_alloc_die = wsp->ws_alloc_die;
154
155 if (!(flags & WRDSF_NOVAR))
156 {
157 wss->ws_env = wsp->ws_env;
158 wss->ws_getvar = wsp->ws_getvar;
159 flags |= wsp->ws_flags & (WRDSF_ENV | WRDSF_ENV_KV | WRDSF_GETVAR);
160 }
161 if (!(flags & WRDSF_NOCMD))
162 {
163 wss->ws_command = wsp->ws_command;
164 }
165
166 if ((flags & (WRDSF_NOVAR|WRDSF_NOCMD)) != (WRDSF_NOVAR|WRDSF_NOCMD))
167 {
168 wss->ws_closure = wsp->ws_closure;
169 flags |= wsp->ws_flags & WRDSF_CLOSURE;
170 }
171
172 wss->ws_options = wsp->ws_options;
173
174 flags |= WRDSF_DELIM
175 | WRDSF_ALLOC_DIE
176 | WRDSF_ERROR
177 | WRDSF_DEBUG
178 | (wsp->ws_flags & (WRDSF_SHOWDBG | WRDSF_SHOWERR | WRDSF_OPTIONS));
179
180 rc = wordsplit_init (wss, str, len, flags);
181 if (rc)
182