Extract one token from a string.
49{
50 if (!dest || !tok)
51 return -1;
52
53 char ch;
54 char qc = '\0';
55 char *pc = NULL;
56
57
58
59
62
64
66 while ((ch = *tok->
dptr))
67 {
68 if (qc == '\0')
69 {
71 break;
73 break;
75 break;
77 break;
79 break;
81 break;
83 break;
85 break;
86 }
87
89
90 if (ch == qc)
91 {
92 qc = 0;
93 }
94 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
TOKEN_QUOTE))
95 {
96 qc = ch;
97 }
98 else if ((ch == '\\') && (qc != '\''))
99 {
100 if (tok->
dptr[0] ==
'\0')
101 return -1;
102 switch (ch = *tok->
dptr++)
103 {
104 case 'c':
105 case 'C':
106 if (tok->
dptr[0] ==
'\0')
107 return -1;
108 buf_addch(dest, (toupper((
unsigned char) tok->
dptr[0]) -
'@') & 0x7f);
110 break;
111 case 'e':
113 break;
114 case 'f':
116 break;
117 case 'n':
119 break;
120 case 'r':
122 break;
123 case 't':
125 break;
126 default:
127 if (isdigit((
unsigned char) ch) && isdigit((
unsigned char) tok->
dptr[0]) &&
128 isdigit((
unsigned char) tok->
dptr[1]))
129 {
132 }
133 else
134 {
136 }
137 }
138 }
140 {
141 if (tok->
dptr[0] ==
'\0')
142 return -1;
144 if (ch == '^')
145 {
147 }
148 else if (ch == '[')
149 {
151 }
152 else if (isalpha((unsigned char) ch))
153 {
154 buf_addch(dest, toupper((
unsigned char) ch) -
'@');
155 }
156 else
157 {
160 }
161 }
162 else if ((ch == '`') && (!qc || (qc == '"')))
163 {
164 FILE *fp = NULL;
165 pid_t pid;
166
168 do
169 {
170 pc = strpbrk(pc, "\\`");
171 if (pc)
172 {
173
174 if (*pc == '\\')
175 pc += 2;
176 }
177 } while (pc && (pc[0] != '`'));
178 if (!pc)
179 {
181 return -1;
182 }
185 *pc = '\0';
187 {
188
192 }
193 else
194 {
196 }
197 *pc = '`';
199 if (pid < 0)
200 {
203 return -1;
204 }
205
207
208
213 if (rc != 0)
217
218
219
220
221
223 {
224 if (qc)
225 {
227 }
228 else
229 {
237 }
239 }
240 }
241 else if ((ch == '$') && (!qc || (qc == '"')) &&
242 ((tok->
dptr[0] ==
'{') || isalpha((
unsigned char) tok->
dptr[0])))
243 {
244 const char *env = NULL;
245 char *var = NULL;
246
247 if (tok->
dptr[0] ==
'{')
248 {
249 pc = strchr(tok->
dptr,
'}');
250 if (pc)
251 {
254
256 {
262 }
263 }
264 }
265 else
266 {
267 for (pc = tok->
dptr; isalnum((
unsigned char) *pc) || (pc[0] ==
'_'); pc++)
268 ;
269
272 }
273 if (var)
274 {
278
280 {
283 }
285 {
287 }
288 else
289 {
292 }
294 }
295 }
296 else
297 {
299 }
300 }
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.
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new 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_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
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.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
#define MUTT_RL_NO_FLAGS
No flags are set.
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 ** EnvList
Private copy of the environment variables.
#define mutt_debug(LEVEL,...)
@ LL_DEBUG1
Log at debug level 1.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
char * mutt_str_dup(const char *str)
Copy a string, safely.
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.
size_t dsize
Length of data.
char * data
Pointer to data.
Container for Accounts, Notifications.
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.