aboutsummaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/Makefile.am2
-rw-r--r--include/wordsplit.h306
2 files changed, 1 insertions, 307 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 6a017a3..5934d40 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,5 +1,5 @@
1SUBDIRS = grecs 1SUBDIRS = grecs
2GRECS_HDR = grecs.h wordsplit.h 2GRECS_HDR = grecs.h $(top_srcdir)/@GRECS_SUBDIR@/wordsplit/wordsplit.h
3 3
4if GRECS_COND_BUILD_INSTALL 4if GRECS_COND_BUILD_INSTALL
5 include_HEADERS = $(GRECS_HDR) 5 include_HEADERS = $(GRECS_HDR)
diff --git a/include/wordsplit.h b/include/wordsplit.h
deleted file mode 100644
index 3451979..0000000
--- a/include/wordsplit.h
+++ /dev/null
@@ -1,306 +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#ifndef __WORDSPLIT_H
18#define __WORDSPLIT_H
19
20#include <stddef.h>
21
22typedef struct wordsplit wordsplit_t;
23
24/* Structure used to direct the splitting. Members marked with [Input]
25 can be defined before calling wordsplit(), those marked with [Output]
26 provide return values when the function returns. If neither mark is
27 used, the member is internal and must not be used by the caller.
28
29 In the comments below, the identifiers in parentheses indicate bits that
30 must be set (or unset, if starting with !) in ws_flags (if starting with
31 WRDSF_) or ws_options (if starting with WRDSO_) to initialize or use the
32 given member.
33
34 If not redefined explicitly, most of them are set to some reasonable
35 default value upon entry to wordsplit(). */
36struct wordsplit
37{
38 size_t ws_wordc; /* [Output] Number of words in ws_wordv. */
39 char **ws_wordv; /* [Output] Array of parsed out words. */
40 size_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial
41 elements in ws_wordv to fill with NULLs. */
42 size_t ws_wordn; /* Number of elements ws_wordv can accomodate. */
43 int ws_flags; /* [Input] Flags passed to wordsplit. */
44 int ws_options; /* [Input] (WRDSF_OPTIONS)
45 Additional options. */
46 size_t ws_maxwords; /* [Input] (WRDSO_MAXWORDS) Return at most that
47 many words */
48 size_t ws_wordi; /* [Output] (WRDSF_INCREMENTAL) Total number of
49 words returned so far */
50
51 const char *ws_delim; /* [Input] (WRDSF_DELIM) Word delimiters. */
52 const char *ws_comment; /* [Input] (WRDSF_COMMENT) Comment characters. */
53 const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped
54 with backslash. */
55 void (*ws_alloc_die) (wordsplit_t *wsp);
56 /* [Input] (WRDSF_ALLOC_DIE) Function called when
57 out of memory. Must not return. */
58 void (*ws_error) (const char *, ...)
59 __attribute__ ((__format__ (__printf__, 1, 2)));
60 /* [Input] (WRDSF_ERROR) Function used for error
61 reporting */
62 void (*ws_debug) (const char *, ...)
63 __attribute__ ((__format__ (__printf__, 1, 2)));
64 /* [Input] (WRDSF_DEBUG) Function used for debug
65 output. */
66 const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of
67 environment variables. */
68
69 /* Temporary storage for environment variables. It is initialized
70 upon first assignment which occurs during the parsing process
71 (e.g. ${x:=2}). When this happens, all variables from ws_env are
72 moved to ws_envbuf first, and the ws_envbuf address is assigned
73 to ws_env. From this moment on, all variable expansions are served
74 from ws_envbuf. */
75 char **ws_envbuf; /* Storage for variables */
76 size_t ws_envidx; /* Index of first free slot */
77 size_t ws_envsiz; /* Size of the ws_envbuf array */
78
79 char const **ws_paramv; /* [WRDSO_PARAMV] User-supplied positional
80 parameters */
81 size_t ws_paramc; /* Number of positional parameters */
82
83 /* Temporary storage for parameters. Works similarly to ws_enbuf.
84 */
85 char **ws_parambuf;
86 size_t ws_paramidx;
87 size_t ws_paramsiz;
88
89 int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
90 /* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up
91 the name VAR (LEN bytes long) in the table of
92 variables and if found returns in memory
93 location pointed to by RET the value of that
94 variable. Returns WRDSE_OK (0) on success,
95 and an error code (see WRDSE_* defines below)
96 on error. User-specific errors can be returned
97 by storing the error diagnostic string in RET
98 and returning WRDSE_USERERR.
99 Whatever is stored in RET, it must be allocated
100 using malloc(3). */
101 void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS
102 argument to ws_getvar and ws_command. */
103 int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv,
104 void *clos);
105 /* [Input] (!WRDSF_NOCMD) Returns in the memory
106 location pointed to by RET the expansion of
107 the command CMD (LEN bytes long). On input,
108 ARGV contains CMD split out to words.
109
110 See ws_getvar for a discussion of possible
111 return values. */
112
113 const char *ws_input; /* Input string (the S argument to wordsplit). */
114 size_t ws_len; /* Length of ws_input. */
115 size_t ws_endp; /* Points past the last processed byte in
116 ws_input. */
117 int ws_errno; /* [Output] Error code, if an error occurred. */
118 char *ws_usererr; /* Points to textual description of
119 the error, if ws_errno is WRDSE_USERERR. Must
120 be allocated with malloc(3). */
121 char *ws_errctx; /* Context in which the error occurred:
122 For WRDSE_UNDEF - name of the undefined variable,
123 For WRDSE_GLOBERR - pattern that caused error.
124 */
125 struct wordsplit_node *ws_head, *ws_tail;
126 /* Doubly-linked list of parsed out nodes. */
127 char ws_sep[2]; /* Temporary storage used during splitting */
128 int ws_lvl; /* Invocation nesting level. */
129};
130
131/* Initial size for ws_env, if allocated automatically */
132#define WORDSPLIT_ENV_INIT 16
133
134/* Wordsplit flags. */
135/* Append the words found to the array resulting from a previous
136 call. */
137#define WRDSF_APPEND 0x00000001
138/* Insert ws_offs initial NULLs in the array ws_wordv.
139 (These are not counted in the returned ws_wordc.) */
140#define WRDSF_DOOFFS 0x00000002
141/* Don't do command substitution. */
142#define WRDSF_NOCMD 0x00000004
143/* The parameter p resulted from a previous call to
144 wordsplit(), and wordsplit_free() was not called. Reuse the
145 allocated storage. */
146#define WRDSF_REUSE 0x00000008
147/* Print errors */
148#define WRDSF_SHOWERR 0x00000010
149/* Consider it an error if an undefined variable is expanded. */
150#define WRDSF_UNDEF 0x00000020
151/* Don't do variable expansion. */
152#define WRDSF_NOVAR 0x00000040
153/* Abort on ENOMEM error */
154#define WRDSF_ENOMEMABRT 0x00000080
155/* Trim off any leading and trailind whitespace */
156#define WRDSF_WS 0x00000100
157/* Handle single quotes */
158#define WRDSF_SQUOTE 0x00000200
159/* Handle double quotes */
160#define WRDSF_DQUOTE 0x00000400
161/* Handle single and double quotes */
162#define WRDSF_QUOTE (WRDSF_SQUOTE|WRDSF_DQUOTE)
163/* Replace each input sequence of repeated delimiters with a single
164 delimiter */
165#define WRDSF_SQUEEZE_DELIMS 0x00000800
166/* Return delimiters */
167#define WRDSF_RETURN_DELIMS 0x00001000
168/* Treat sed expressions as words */
169#define WRDSF_SED_EXPR 0x00002000
170/* ws_delim field is initialized */
171#define WRDSF_DELIM 0x00004000
172/* ws_comment field is initialized */
173#define WRDSF_COMMENT 0x00008000
174/* ws_alloc_die field is initialized */
175#define WRDSF_ALLOC_DIE 0x00010000
176/* ws_error field is initialized */
177#define WRDSF_ERROR 0x00020000
178/* ws_debug field is initialized */
179#define WRDSF_DEBUG 0x00040000
180/* ws_env field is initialized */
181#define WRDSF_ENV 0x00080000
182/* ws_getvar field is initialized */
183#define WRDSF_GETVAR 0x00100000
184/* enable debugging */
185#define WRDSF_SHOWDBG 0x00200000
186/* Don't split input into words. Useful for side effects. */
187#define WRDSF_NOSPLIT 0x00400000
188/* Keep undefined variables in place, instead of expanding them to
189 empty strings. */
190#define WRDSF_KEEPUNDEF 0x00800000
191/* Warn about undefined variables */
192#define WRDSF_WARNUNDEF 0x01000000
193/* Handle C escapes */
194#define WRDSF_CESCAPES 0x02000000
195/* ws_closure is set */
196#define WRDSF_CLOSURE 0x04000000
197/* ws_env is a Key/Value environment, i.e. the value of a variable is
198 stored in the element that follows its name. */
199#define WRDSF_ENV_KV 0x08000000
200/* ws_escape is set */
201#define WRDSF_ESCAPE 0x10000000
202/* Incremental mode */
203#define WRDSF_INCREMENTAL 0x20000000
204/* Perform pathname and tilde expansion */
205#define WRDSF_PATHEXPAND 0x40000000
206/* ws_options is initialized */
207#define WRDSF_OPTIONS 0x80000000
208