aboutsummaryrefslogtreecommitdiff
path: root/src/wordsplit.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wordsplit.h')
-rw-r--r--src/wordsplit.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/wordsplit.h b/src/wordsplit.h
new file mode 100644
index 0000000..35e125a
--- /dev/null
+++ b/src/wordsplit.h
@@ -0,0 +1,159 @@
1/* wordsplit - a word splitter
2 Copyright (C) 2009-2012 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
22struct wordsplit
23{
24 size_t ws_wordc;
25 char **ws_wordv;
26 size_t ws_offs;
27 size_t ws_wordn;
28 int ws_flags;
29 const char *ws_delim;
30 const char *ws_comment;
31 const char *ws_escape;
32 void (*ws_alloc_die) (struct wordsplit * wsp);
33 void (*ws_error) (const char *, ...)
34 __attribute__ ((__format__ (__printf__, 1, 2)));
35 void (*ws_debug) (const char *, ...)
36 __attribute__ ((__format__ (__printf__, 1, 2)));
37
38 const char **ws_env;
39 const char *(*ws_getvar) (const char *, size_t, void *);
40 void *ws_closure;
41
42 const char *ws_input;
43 size_t ws_len;
44 size_t ws_endp;
45 int ws_errno;
46 struct wordsplit_node *ws_head, *ws_tail;
47};
48
49/* Wordsplit flags. Only 2 bits of a 32-bit word remain unused.
50 It is getting crowded... */
51/* Append the words found to the array resulting from a previous
52 call. */
53#define WRDSF_APPEND 0x00000001
54/* Insert we_offs initial NULLs in the array ws_wordv.
55 (These are not counted in the returned ws_wordc.) */
56#define WRDSF_DOOFFS 0x00000002
57/* Don't do command substitution. Reserved for future use. */
58#define WRDSF_NOCMD 0x00000004
59/* The parameter p resulted from a previous call to
60 wordsplit(), and wordsplit_free() was not called. Reuse the
61 allocated storage. */
62#define WRDSF_REUSE 0x00000008
63/* Print errors */
64#define WRDSF_SHOWERR 0x00000010
65/* Consider it an error if an undefined shell variable
66 is expanded. */
67#define WRDSF_UNDEF 0x00000020
68
69/* Don't do variable expansion. */
70#define WRDSF_NOVAR 0x00000040
71/* Abort on ENOMEM error */
72#define WRDSF_ENOMEMABRT 0x00000080
73/* Trim off any leading and trailind whitespace */
74#define WRDSF_WS 0x00000100
75/* Handle single quotes */
76#define WRDSF_SQUOTE 0x00000200
77/* Handle double quotes */
78#define WRDSF_DQUOTE 0x00000400
79/* Handle quotes and escape directives */
80#define WRDSF_QUOTE (WRDSF_SQUOTE|WRDSF_DQUOTE)
81/* Replace each input sequence of repeated delimiters with a single
82 delimiter */
83#define WRDSF_SQUEEZE_DELIMS 0x00000800
84/* Return delimiters */
85#define WRDSF_RETURN_DELIMS 0x00001000
86/* Treat sed expressions as words */
87#define WRDSF_SED_EXPR 0x00002000
88/* ws_delim field is initialized */
89#define WRDSF_DELIM 0x00004000
90/* ws_comment field is initialized */
91#define WRDSF_COMMENT 0x00008000
92/* ws_alloc_die field is initialized */
93#define WRDSF_ALLOC_DIE 0x00010000
94/* ws_error field is initialized */
95#define WRDSF_ERROR 0x00020000
96/* ws_debug field is initialized */
97#define WRDSF_DEBUG 0x00040000
98/* ws_env field is initialized */
99#define WRDSF_ENV 0x00080000
100/* ws_getvar field is initialized */
101#define WRDSF_GETVAR 0x00100000
102/* enable debugging */
103#define WRDSF_SHOWDBG 0x00200000
104/* Don't split input into words. Useful for side effects. */
105#define WRDSF_NOSPLIT 0x00400000
106/* Keep undefined variables in place, instead of expanding them to
107 empty string */
108#define WRDSF_KEEPUNDEF 0x00800000
109/* Warn about undefined variables */
110#define WRDSF_WARNUNDEF 0x01000000
111/* Handle C escapes */
112#define WRDSF_CESCAPES 0x02000000
113
114/* ws_closure is set */
115#define WRDSF_CLOSURE 0x04000000
116/* ws_env is a Key/Value environment, i.e. the value of a variable is
117 stored in the element that follows its name. */
118#define WRDSF_ENV_KV 0x08000000
119
120/* ws_escape is set */
121#define WRDSF_ESCAPE 0x10000000
122
123/* Incremental mode */
124#define WRDSF_INCREMENTAL 0x20000000
125
126#define WRDSF_DEFFLAGS \
127 (WRDSF_NOVAR | WRDSF_NOCMD | \
128 WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | WRDSF_CESCAPES)
129
130#define WRDSE_EOF 0
131#define WRDSE_QUOTE 1
132#define WRDSE_NOSPACE 2
133#define WRDSE_NOSUPP 3
134#define WRDSE_USAGE 4
135#define WRDSE_CBRACE 5
136#define WRDSE_UNDEF 6
137#define WRDSE_NOINPUT 7
138
139int wordsplit (const char *s, struct wordsplit *p, int flags);
140int wordsplit_len (const char *s, size_t len,
141 struct wordsplit *p, int flags);
142void wordsplit_free (struct wordsplit *p);
143void wordsplit_free_words (struct wordsplit *ws);
144
145int wordsplit_c_unquote_char (int c);
146int wordsplit_c_quote_char (int c);
147size_t wordsplit_c_quoted_length (const char *str, int quote_hex,
148 int *quote);
149void wordsplit_general_unquote_copy (char *dst, const char *src, size_t n,
150 const char *escapable);
151void wordsplit_sh_unquote_copy (char *dst, const char *src, size_t n);
152void wordsplit_c_unquote_copy (char *dst, const char *src, size_t n);
153void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
154
155void wordsplit_perror (struct wordsplit *ws);
156const char *wordsplit_strerror (struct wordsplit *ws);
157
158
159#endif

Return to:

Send suggestions and report system problems to the System administrator.