]>
Dogcows Code - chaz/tar/blob - lib/wordsplit.h
1 /* wordsplit - a word splitter
2 Copyright (C) 2009-2014 Free Software Foundation, Inc.
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.
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.
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/>.
17 Written by Sergey Poznyakoff
25 #if 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
26 # define __WORDSPLIT_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
28 # define __WORDSPLIT_ATTRIBUTE_FORMAT(spec) /* empty */
39 const char *ws_comment
;
40 const char *ws_escape
;
41 void (*ws_alloc_die
) (struct wordsplit
* wsp
);
42 void (*ws_error
) (const char *, ...)
43 __WORDSPLIT_ATTRIBUTE_FORMAT ((__printf__
, 1, 2));
44 void (*ws_debug
) (const char *, ...)
45 __WORDSPLIT_ATTRIBUTE_FORMAT ((__printf__
, 1, 2));
48 const char *(*ws_getvar
) (const char *, size_t, void *);
55 struct wordsplit_node
*ws_head
, *ws_tail
;
58 /* Wordsplit flags. Only 2 bits of a 32-bit word remain unused.
59 It is getting crowded... */
60 /* Append the words found to the array resulting from a previous
62 #define WRDSF_APPEND 0x00000001
63 /* Insert we_offs initial NULLs in the array ws_wordv.
64 (These are not counted in the returned ws_wordc.) */
65 #define WRDSF_DOOFFS 0x00000002
66 /* Don't do command substitution. Reserved for future use. */
67 #define WRDSF_NOCMD 0x00000004
68 /* The parameter p resulted from a previous call to
69 wordsplit(), and wordsplit_free() was not called. Reuse the
71 #define WRDSF_REUSE 0x00000008
73 #define WRDSF_SHOWERR 0x00000010
74 /* Consider it an error if an undefined shell variable
76 #define WRDSF_UNDEF 0x00000020
78 /* Don't do variable expansion. */
79 #define WRDSF_NOVAR 0x00000040
80 /* Abort on ENOMEM error */
81 #define WRDSF_ENOMEMABRT 0x00000080
82 /* Trim off any leading and trailind whitespace */
83 #define WRDSF_WS 0x00000100
84 /* Handle single quotes */
85 #define WRDSF_SQUOTE 0x00000200
86 /* Handle double quotes */
87 #define WRDSF_DQUOTE 0x00000400
88 /* Handle quotes and escape directives */
89 #define WRDSF_QUOTE (WRDSF_SQUOTE|WRDSF_DQUOTE)
90 /* Replace each input sequence of repeated delimiters with a single
92 #define WRDSF_SQUEEZE_DELIMS 0x00000800
93 /* Return delimiters */
94 #define WRDSF_RETURN_DELIMS 0x00001000
95 /* Treat sed expressions as words */
96 #define WRDSF_SED_EXPR 0x00002000
97 /* ws_delim field is initialized */
98 #define WRDSF_DELIM 0x00004000
99 /* ws_comment field is initialized */
100 #define WRDSF_COMMENT 0x00008000
101 /* ws_alloc_die field is initialized */
102 #define WRDSF_ALLOC_DIE 0x00010000
103 /* ws_error field is initialized */
104 #define WRDSF_ERROR 0x00020000
105 /* ws_debug field is initialized */
106 #define WRDSF_DEBUG 0x00040000
107 /* ws_env field is initialized */
108 #define WRDSF_ENV 0x00080000
109 /* ws_getvar field is initialized */
110 #define WRDSF_GETVAR 0x00100000
111 /* enable debugging */
112 #define WRDSF_SHOWDBG 0x00200000
113 /* Don't split input into words. Useful for side effects. */
114 #define WRDSF_NOSPLIT 0x00400000
115 /* Keep undefined variables in place, instead of expanding them to
117 #define WRDSF_KEEPUNDEF 0x00800000
118 /* Warn about undefined variables */
119 #define WRDSF_WARNUNDEF 0x01000000
120 /* Handle C escapes */
121 #define WRDSF_CESCAPES 0x02000000
123 /* ws_closure is set */
124 #define WRDSF_CLOSURE 0x04000000
125 /* ws_env is a Key/Value environment, i.e. the value of a variable is
126 stored in the element that follows its name. */
127 #define WRDSF_ENV_KV 0x08000000
129 /* ws_escape is set */
130 #define WRDSF_ESCAPE 0x10000000
132 /* Incremental mode */
133 #define WRDSF_INCREMENTAL 0x20000000
135 #define WRDSF_DEFFLAGS \
136 (WRDSF_NOVAR | WRDSF_NOCMD | \
137 WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | WRDSF_CESCAPES)
140 #define WRDSE_QUOTE 1
141 #define WRDSE_NOSPACE 2
142 #define WRDSE_NOSUPP 3
143 #define WRDSE_USAGE 4
144 #define WRDSE_CBRACE 5
145 #define WRDSE_UNDEF 6
146 #define WRDSE_NOINPUT 7
148 int wordsplit (const char *s
, struct wordsplit
*p
, int flags
);
149 int wordsplit_len (const char *s
, size_t len
,
150 struct wordsplit
*p
, int flags
);
151 void wordsplit_free (struct wordsplit
*p
);
152 void wordsplit_free_words (struct wordsplit
*ws
);
154 int wordsplit_c_unquote_char (int c
);
155 int wordsplit_c_quote_char (int c
);
156 size_t wordsplit_c_quoted_length (const char *str
, int quote_hex
,
158 void wordsplit_general_unquote_copy (char *dst
, const char *src
, size_t n
,
159 const char *escapable
);
160 void wordsplit_sh_unquote_copy (char *dst
, const char *src
, size_t n
);
161 void wordsplit_c_unquote_copy (char *dst
, const char *src
, size_t n
);
162 void wordsplit_c_quote_copy (char *dst
, const char *src
, int quote_hex
);
164 void wordsplit_perror (struct wordsplit
*ws
);
165 const char *wordsplit_strerror (struct wordsplit
*ws
);
This page took 0.042172 seconds and 4 git commands to generate.