aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Makefile.am6
-rw-r--r--am/grecs.m44
-rw-r--r--doc/Makefile.am6
-rw-r--r--doc/wordsplit.31036
-rw-r--r--include/Makefile.am2
-rw-r--r--include/wordsplit.h306
-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
-rw-r--r--tests/.gitignore4
-rw-r--r--tests/Makefile.am54
-rw-r--r--tests/testsuite.at2
-rw-r--r--tests/wordsplit.at1030
-rw-r--r--tests/wsp.c756
m---------wordsplit0
18 files changed, 76 insertions, 6041 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..ec3950b
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
1[submodule "wordsplit"]
2 path = wordsplit
3 url = git://git.gnu.org.ua/wordsplit.git
diff --git a/Makefile.am b/Makefile.am
index 3eaa8df..b8482a1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
1# This file is part of Grecs 1# This file is part of Grecs
2# Copyright (C) 2007-2016 Sergey Poznyakoff 2# Copyright (C) 2007-2019 Sergey Poznyakoff
3# 3#
4# Grecs is free software; you can redistribute it and/or modify 4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -16,7 +16,9 @@
16 16
17ACLOCAL_AMFLAGS = -I am 17ACLOCAL_AMFLAGS = -I am
18SUBDIRS=. include src @GRECS_TESTDIR@ @GRECS_DOCDIR@ 18SUBDIRS=. include src @GRECS_TESTDIR@ @GRECS_DOCDIR@
19EXTRA_DIST=build-aux/yyrename @GRECS_BUILD_AUX@ @GRECS_DISTDOC@ gitid.h 19EXTRA_DIST=build-aux/yyrename @GRECS_BUILD_AUX@ @GRECS_DISTDOC@ gitid.h\
20 wordsplit/wordsplit.c wordsplit/wordsplit.h wordsplit/wordsplit.3 \
21 wordsplit/wordsplit.at wordsplit/wsp.c
20 22
21noinst_HEADERS = gitid.h 23noinst_HEADERS = gitid.h
22BUILT_SOURCES = gitid.h README 24BUILT_SOURCES = gitid.h README
diff --git a/am/grecs.m4 b/am/grecs.m4
index 33a6809..8bf3d21 100644
--- a/am/grecs.m4
+++ b/am/grecs.m4
@@ -1,5 +1,5 @@
1# This file is part of grecs - Gray's Extensible Configuration System -*- autoconf -*- 1# This file is part of grecs - Gray's Extensible Configuration System -*- autoconf -*-
2# Copyright (C) 2007-2016 Sergey Poznyakoff 2# Copyright (C) 2007-2019 Sergey Poznyakoff
3# 3#
4# Grex is free software; you can redistribute it and/or modify 4# Grex is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -202,7 +202,7 @@ AC_DEFUN([GRECS_SETUP],[
202 AC_SUBST([GRECS_CHANGELOG]) 202 AC_SUBST([GRECS_CHANGELOG])
203 AC_SUBST([GRECS_DISTCK_AT]) 203 AC_SUBST([GRECS_DISTCK_AT])
204 AC_SUBST([GRECS_README]) 204 AC_SUBST([GRECS_README])
205 AC_SUBST([GRECS_INCLUDES],['-I$(top_srcdir)/]grecsdir[include] [-I$(top_builddir)/]grecsdir[include]') 205 AC_SUBST([GRECS_INCLUDES],['-I$(top_srcdir)/]grecsdir[include] [-I$(top_srcdir)/]grecsdir[wordsplit] [-I$(top_builddir)/]grecsdir[include]')
206 AC_SUBST([GRECS_HOST_PROJECT_INCLUDES]) 206 AC_SUBST([GRECS_HOST_PROJECT_INCLUDES])
207 AC_SUBST([GRECS_HOST_PROJECT_LDADD]) 207 AC_SUBST([GRECS_HOST_PROJECT_LDADD])
208 AC_SUBST([GRECS_DISTDOC]) 208 AC_SUBST([GRECS_DISTDOC])
diff --git a/doc/Makefile.am b/doc/Makefile.am
index a646367..009537d 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,5 +1,5 @@
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#
4# Grecs is free software; you can redistribute it and/or modify 4# Grecs is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -29,5 +29,5 @@ dist_man_MANS = \
29 grecs_parse.3\ 29 grecs_parse.3\
30 grecs_stmt_path.5\ 30 grecs_stmt_path.5\
31 grecs_strdup.3\ 31 grecs_strdup.3\
32 grecs_tree_free.3 32 grecs_tree_free.3\
33 33 $(top_srcdir)/@GRECS_SUBDIR@/wordsplit/wordsplit.3
diff --git a/doc/wordsplit.3 b/doc/wordsplit.3
deleted file mode 100644
index 1a6f80b..0000000
--- a/doc/wordsplit.3
+++ /dev/null
@@ -1,1036 +0,0 @@
1.\" This file is part of grecs -*- nroff -*-
2.\" Copyright (C) 2007-2018 Sergey Poznyakoff
3.\"
4.\" Grecs is free software; you can redistribute it and/or modify
5.\" it under the terms of the GNU General Public License as published by
6.\" the Free Software Foundation; either version 3, or (at your option)
7.\" any later version.
8.\"
9.\" Grecs 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
15.\" along with Grecs. If not, see <http://www.gnu.org/licenses/>.
16.\"
17.TH WORDSPLIT 3 "May 22, 2018" "GRECS" "Grecs User Reference"
18.SH NAME
19wordsplit \- split string into words
20.SH SYNOPSIS
21.B #include <wordsplit.h>
22.sp
23\fBint wordsplit (const char *\fIs\fB,\
24 wordsplit_t *\fIws\fB, int \fIflags\fB);\fR
25.sp
26\fBint wordsplit_len (const char *\fIs\fB,\
27 \fBsize_t \fIlen\fR,\
28 \fBwordsplit_t *\fIp\fB,\
29 int \fIflags\fB);
30.sp
31\fBvoid wordsplit_free (wordsplit_t *\fIp\fB);\fR
32.sp
33\fBvoid wordsplit_free_words (wordsplit_t *\fIws\fB);\fR
34.sp
35\fBvoid wordsplit_getwords (wordsplit_t *\fIws\fB,\
36 int *\fIwordc\fB, char ***\fIwordv\fB);
37.sp
38\fBvoid wordsplit_perror (wordsplit_t *\fIws\fB);\fR
39.sp
40\fBconst char *wordsplit_strerror (wordsplit_t *\fIws\fB);\fR
41.sp
42\fBvoid wordsplit_clearerr (wordsplit_t *\fIws\fB);\fR
43.SH DESCRIPTION
44The function \fBwordsplit\fR splits the string \fIs\fR into words
45using a set of rules governed by \fIflags\fR. Depending on
46\fIflags\fR, the function performs the following operations:
47whitespace trimming, tilde expansion, variable expansion, quote
48removal, command substitution, and path expansion. On success,
49\fBwordsplit\fR returns 0 and stores the words found in the member
50\fBws_wordv\fR and the number of words in the member \fBws_wordc\fR.
51On error, a non-zero error code is returned.
52.PP
53The function \fBwordsplit_len\fR acts similarly, except that it
54accesses only first \fBlen\fR bytes of the string \fIs\fR, which is
55not required to be null-terminated.
56.PP
57When no longer needed, the resources allocated by a call to one of
58these functions must be freed using
59.BR wordsplit_free .
60.PP
61The function
62.B wordsplit_free_words
63frees only the memory allocated for elements of
64.I ws_wordv
65and initializes
66.I ws_wordc
67to zero.
68.PP
69The usual calling sequence is:
70.PP
71.EX
72wordsplit_t ws;
73int rc;
74
75if (wordsplit(s, &ws, WRDSF_DEFFLAGS)) {
76 wordsplit_perror(&ws);
77 return;
78}
79for (i = 0; i < ws.ws_wordc; i++) {
80 /* do something with ws.ws_wordv[i] */
81}
82wordsplit_free(&ws);
83.EE
84.PP
85The function
86.B wordsplit_getwords
87returns in \fIwordv\fR an array of words, and in \fIwordc\fR the number
88of elements in \fIwordv\fR. The array can be used after calling
89.BR wordsplit_free .
90The caller becomes responsible for freeing the memory allocated for
91each element of the array and the array pointer itself.
92.PP
93The function
94.B wordsplit_perror
95prints error message from the last invocation of \fBwordsplit\fR. It
96uses the function pointed to by the
97.I ws_error
98member. By default, it outputs the message on the standard error.
99.PP
100For more sophisticated error reporting, the function
101.B wordsplit_strerror
102can be used. It returns a pointer to the string describing the error.
103The caller should treat this pointer as a constant string. It should
104not try to alter or deallocate it.
105.PP
106The function
107.B wordsplit_clearerr
108clears the error condition associated with \fIws\fR.
109.SH INCREMENTAL MODE
110In incremental mode \fBwordsplit\fR parses one word per invocation.
111It returns \fBWRDSF_OK\fR on success and \fBWRDSF_NOINPUT\fR when
112entire input string has been processed.
113.PP
114This mode is enabled if the flag \fBWRDSF_INCREMENTAL\fR is set in
115the \fIflags\fR argument. Subsequent calls to \fBwordsplit\fR must
116have \fBNULL\fR as first argument. Each successful
117call will return exactly one word in \fBws.ws_wordv[0]\fR.
118.PP
119An example usage:
120.PP
121.EX
122wordsplit_t ws;
123int rc;
124flags = WRDSF_DEFFLAGS|WRDSF_INCREMENTAL;
125
126for (rc = wordsplit(s, &ws, flags); rc == WRDSF_OK;
127 rc = wordsplit(NULL, &ws, flags)) {
128 process(ws.ws_wordv[0]);
129}
130
131if (rc != WRDSE_NOINPUT)
132 wordsplit_perror(&ws);
133
134wordsplit_free(&ws);
135.EE
136.SH OPTIONS
137The number of flags is limited to 32 (the width of \fBuint32_t\fR data
138type) and each bit is occupied by a corresponding flag. However, the
139number of features \fBwordsplit\fR provides required still
140more. Additional features can be requested by setting a corresponding
141\fIoption bit\fR in the \fBws_option\fR field of the \fBstruct
142wordsplit\fR argument. To inform wordsplit functions that this field
143is initialized the \fBWRDSF_OPTIONS\fR flag must be set.
144.PP
145Option symbolic names begin with \fBWRDSO_\fR. They are discussed in
146detail in the subsequent chapters.
147.SH EXPANSION
148Expansion is performed on the input after it has been split into
149words. There are several kinds of expansion, which of them are
150performed is controlled by appropriate bits set in the \fIflags\fR
151argument. Whatever expansion