diff options
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | am/grecs.m4 | 4 | ||||
-rw-r--r-- | doc/Makefile.am | 6 | ||||
-rw-r--r-- | doc/wordsplit.3 | 1036 | ||||
-rw-r--r-- | include/Makefile.am | 2 | ||||
-rw-r--r-- | include/wordsplit.h | 306 | ||||
-rw-r--r-- | src/Make-inst.am | 4 | ||||
-rw-r--r-- | src/Make-shared.am | 3 | ||||
-rw-r--r-- | src/Make-static.am | 3 | ||||
-rw-r--r-- | src/Make.am | 6 | ||||
-rw-r--r-- | src/wordsplit.c | 2892 | ||||
-rw-r--r-- | tests/.gitignore | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 54 | ||||
-rw-r--r-- | tests/testsuite.at | 2 | ||||
-rw-r--r-- | tests/wordsplit.at | 1030 | ||||
-rw-r--r-- | tests/wsp.c | 756 | ||||
m--------- | wordsplit | 0 |
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 | ||
17 | ACLOCAL_AMFLAGS = -I am | 17 | ACLOCAL_AMFLAGS = -I am |
18 | SUBDIRS=. include src @GRECS_TESTDIR@ @GRECS_DOCDIR@ | 18 | SUBDIRS=. include src @GRECS_TESTDIR@ @GRECS_DOCDIR@ |
19 | EXTRA_DIST=build-aux/yyrename @GRECS_BUILD_AUX@ @GRECS_DISTDOC@ gitid.h | 19 | EXTRA_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 | ||
21 | noinst_HEADERS = gitid.h | 23 | noinst_HEADERS = gitid.h |
22 | BUILT_SOURCES = gitid.h README | 24 | BUILT_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 | ||
19 | wordsplit \- 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 | ||
44 | The function \fBwordsplit\fR splits the string \fIs\fR into words | ||
45 | using a set of rules governed by \fIflags\fR. Depending on | ||
46 | \fIflags\fR, the function performs the following operations: | ||
47 | whitespace trimming, tilde expansion, variable expansion, quote | ||
48 | removal, 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. | ||
51 | On error, a non-zero error code is returned. | ||
52 | .PP | ||
53 | The function \fBwordsplit_len\fR acts similarly, except that it | ||
54 | accesses only first \fBlen\fR bytes of the string \fIs\fR, which is | ||
55 | not required to be null-terminated. | ||
56 | .PP | ||
57 | When no longer needed, the resources allocated by a call to one of | ||
58 | these functions must be freed using | ||
59 | .BR wordsplit_free . | ||
60 | .PP | ||
61 | The function | ||
62 | .B wordsplit_free_words | ||
63 | frees only the memory allocated for elements of | ||
64 | .I ws_wordv | ||
65 | and initializes | ||
66 | .I ws_wordc | ||
67 | to zero. | ||
68 | .PP | ||
69 | The usual calling sequence is: | ||
70 | .PP | ||
71 | .EX | ||
72 | wordsplit_t ws; | ||
73 | int rc; | ||
74 | |||
75 | if (wordsplit(s, &ws, WRDSF_DEFFLAGS)) { | ||
76 | wordsplit_perror(&ws); | ||
77 | return; | ||
78 | } | ||
79 | for (i = 0; i < ws.ws_wordc; i++) { | ||
80 | /* do something with ws.ws_wordv[i] */ | ||
81 | } | ||
82 | wordsplit_free(&ws); | ||
83 | .EE | ||
84 | .PP | ||
85 | The function | ||
86 | .B wordsplit_getwords | ||
87 | returns in \fIwordv\fR an array of words, and in \fIwordc\fR the number | ||
88 | of elements in \fIwordv\fR. The array can be used after calling | ||
89 | .BR wordsplit_free . | ||
90 | The caller becomes responsible for freeing the memory allocated for | ||
91 | each element of the array and the array pointer itself. | ||
92 | .PP | ||
93 | The function | ||
94 | .B wordsplit_perror | ||
95 | prints error message from the last invocation of \fBwordsplit\fR. It | ||
96 | uses the function pointed to by the | ||
97 | .I ws_error | ||
98 | member. By default, it outputs the message on the standard error. | ||
99 | .PP | ||
100 | For more sophisticated error reporting, the function | ||
101 | .B wordsplit_strerror | ||
102 | can be used. It returns a pointer to the string describing the error. | ||
103 | The caller should treat this pointer as a constant string. It should | ||
104 | not try to alter or deallocate it. | ||
105 | .PP | ||
106 | The function | ||
107 | .B wordsplit_clearerr | ||
108 | clears the error condition associated with \fIws\fR. | ||
109 | .SH INCREMENTAL MODE | ||
110 | In incremental mode \fBwordsplit\fR parses one word per invocation. | ||
111 | It returns \fBWRDSF_OK\fR on success and \fBWRDSF_NOINPUT\fR when | ||
112 | entire input string has been processed. | ||
113 | .PP | ||
114 | This mode is enabled if the flag \fBWRDSF_INCREMENTAL\fR is set in | ||
115 | the \fIflags\fR argument. Subsequent calls to \fBwordsplit\fR must | ||
116 | have \fBNULL\fR as first argument. Each successful | ||
117 | call will return exactly one word in \fBws.ws_wordv[0]\fR. | ||
118 | .PP | ||
119 | An example usage: | ||
120 | .PP | ||
121 | .EX | ||
122 | wordsplit_t ws; | ||
123 | int rc; | ||
124 | flags = WRDSF_DEFFLAGS|WRDSF_INCREMENTAL; | ||
125 | |||
126 | for (rc = wordsplit(s, &ws, flags); rc == WRDSF_OK; | ||
127 | rc = wordsplit(NULL, &ws, flags)) { | ||
128 | process(ws.ws_wordv[0]); | ||
129 | } | ||
130 | |||
131 | if (rc != WRDSE_NOINPUT) | ||
132 | wordsplit_perror(&ws); | ||
133 | |||
134 | wordsplit_free(&ws); | ||
135 | .EE | ||
136 | .SH OPTIONS | ||
137 | The number of flags is limited to 32 (the width of \fBuint32_t\fR data | ||
138 | type) and each bit is occupied by a corresponding flag. However, the | ||
139 | number of features \fBwordsplit\fR provides required still | ||
140 | more. Additional features can be requested by setting a corresponding | ||
141 | \fIoption bit\fR in the \fBws_option\fR field of the \fBstruct | ||
142 | wordsplit\fR argument. To inform wordsplit functions that this field | ||
143 | is initialized the \fBWRDSF_OPTIONS\fR flag must be set. | ||
144 | .PP | ||
145 | Option symbolic names begin with \fBWRDSO_\fR. They are discussed in | ||
146 | detail in the subsequent chapters. | ||
147 | .SH EXPANSION | ||
148 | Expansion is performed on the input after it has been split into | ||
149 | words. There are several kinds of expansion, which of them are | ||
150 | performed is controlled by appropriate bits set in the \fIflags\fR | ||
151 | argument. Whatever expansion |