Extract one token from a string.
50{
51 if (!dest || !tok)
52 return -1;
53
54 char ch;
55 char qc = '\0';
56 char *pc = NULL;
57
59
61 while ((ch = *tok->
dptr))
62 {
63 if (qc == '\0')
64 {
66 break;
68 break;
70 break;
72 break;
74 break;
76 break;
78 break;
80 break;
81 }
82
84
85 if (ch == qc)
86 {
87 qc = 0;
88 }
89 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
TOKEN_QUOTE))
90 {
91 qc = ch;
92 }
93 else if ((ch == '\\') && (qc != '\''))
94 {
95 if (tok->
dptr[0] ==
'\0')
96 return -1;
97 switch (ch = *tok->
dptr++)
98 {
99 case 'c':
100 case 'C':
101 if (tok->
dptr[0] ==
'\0')
102 return -1;
103 buf_addch(dest, (toupper((
unsigned char) tok->
dptr[0]) -
'@') & 0x7f);
105 break;
106 case 'e':
108 break;
109 case 'f':
111 break;
112 case 'n':
114 break;
115 case 'r':
117 break;
118 case 't':
120 break;
121 default:
122 if (isdigit((
unsigned char) ch) && isdigit((
unsigned char) tok->
dptr[0]) &&
123 isdigit((
unsigned char) tok->
dptr[1]))
124 {
127 }
128 else
129 {
131 }
132 }
133 }
135 {
136 if (tok->
dptr[0] ==
'\0')
137 return -1;
139 if (ch == '^')
140 {
142 }
143 else if (ch == '[')
144 {
146 }
147 else if (isalpha((unsigned char) ch))
148 {
149 buf_addch(dest, toupper((
unsigned char) ch) -
'@');
150 }
151 else
152 {
155 }
156 }
157 else if ((ch == '`') && (!qc || (qc == '"')))
158 {
159 FILE *fp = NULL;
160 pid_t pid;
161
163 do
164 {
165 pc = strpbrk(pc, "\\`");
166 if (pc)
167 {
168
169 if (*pc == '\\')
170 {
171 if (*(pc + 1))
172 pc += 2;
173 else
174 pc = NULL;
175 }
176 }
177 } while (pc && (pc[0] != '`'));
178 if (!pc)
179 {
181 return -1;
182 }
184 *pc = '\0';
186 {
187
191 }
192 else
193 {
195 }
196 *pc = '`';
198 if (pid < 0)
199 {
202 return -1;
203 }
204
206
207
208 char *expn = NULL;
209 size_t expn_len = 0;
213 if (rc != 0)
214 {
217 }
219
220
221
222
223
224 if (expn)
225 {
226 if (qc)
227 {
229 }
230 else
231 {
238 }
240 }
241 }
242 else if ((ch == '$') && (!qc || (qc == '"')) &&
243 ((tok->
dptr[0] ==
'{') || isalpha((
unsigned char) tok->
dptr[0])))
244 {
245 const char *env = NULL;
246 char *var = NULL;
247
248 if (tok->
dptr[0] ==
'{')
249 {
250 pc = strchr(tok->
dptr,
'}');
251 if (pc)
252 {
255
257 {
263 }
264 }
265 }
266 else
267 {
268 for (pc = tok->
dptr; isalnum((
unsigned char) *pc) || (pc[0] ==
'_'); pc++)
269 ;
270
273 }
274 if (var)
275 {
278
280 {
282 }
284 {
286 }
287 else
288 {
291 }
294 }
295 }
296 else
297 {
299 }
300 }
301
303 return 0;
304}
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
#define CSR_SUCCESS
Action completed successfully.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
#define mutt_file_fclose(FP)
#define MUTT_RL_NO_FLAGS
No flags are set.
#define mutt_debug(LEVEL,...)
@ LL_DEBUG1
Log at debug level 1.
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, char **envlist)
Set up filter program.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
String manipulation buffer.
char * dptr
Current read/write position.
Container for Accounts, Notifications.
char ** env
Private copy of the environment variables.
struct ConfigSubset * sub
Inherited config items.
int cs_subset_str_string_get(const struct ConfigSubset *sub, const char *name, struct Buffer *result)
Get a config item as a string.