Extract one token from a string.
51{
52 if (!dest || !tok)
53 return -1;
54
55 char ch;
56 char qc = '\0';
57 char *pc = NULL;
58
60
62 while ((ch = *tok->
dptr))
63 {
64 if (qc == '\0')
65 {
67 break;
69 break;
71 break;
73 break;
75 break;
77 break;
79 break;
81 break;
82 }
83
85
86 if (ch == qc)
87 {
88 qc = 0;
89 }
90 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
TOKEN_QUOTE))
91 {
92 qc = ch;
93 }
94 else if ((ch == '\\') && (qc != '\''))
95 {
96 if (tok->
dptr[0] ==
'\0')
97 return -1;
98 switch (ch = *tok->
dptr++)
99 {
100 case 'c':
101 case 'C':
102 if (tok->
dptr[0] ==
'\0')
103 return -1;
104 buf_addch(dest, (toupper((
unsigned char) tok->
dptr[0]) -
'@') & 0x7f);
106 break;
107 case 'e':
109 break;
110 case 'f':
112 break;
113 case 'n':
115 break;
116 case 'r':
118 break;
119 case 't':
121 break;
122 default:
123 if (isdigit((
unsigned char) ch) && isdigit((
unsigned char) tok->
dptr[0]) &&
124 isdigit((
unsigned char) tok->
dptr[1]))
125 {
128 }
129 else
130 {
132 }
133 }
134 }
136 {
137 if (tok->
dptr[0] ==
'\0')
138 return -1;
140 if (ch == '^')
141 {
143 }
144 else if (ch == '[')
145 {
147 }
148 else if (isalpha((unsigned char) ch))
149 {
150 buf_addch(dest, toupper((
unsigned char) ch) -
'@');
151 }
152 else
153 {
156 }
157 }
158 else if ((ch == '`') && (!qc || (qc == '"')))
159 {
160 FILE *fp = NULL;
161 pid_t pid;
162
164 do
165 {
166 pc = strpbrk(pc, "\\`");
167 if (pc)
168 {
169
170 if (*pc == '\\')
171 {
172 if (*(pc + 1))
173 pc += 2;
174 else
175 pc = NULL;
176 }
177 }
178 } while (pc && (pc[0] != '`'));
179 if (!pc)
180 {
182 return -1;
183 }
185 *pc = '\0';
187 {
188
192 }
193 else
194 {
196 }
197 *pc = '`';
199 if (pid < 0)
200 {
203 return -1;
204 }
205
207
208
209 char *expn = NULL;
210 size_t expn_len = 0;
214 if (rc != 0)
215 {
218 }
220
221
222
223
224
225 if (expn)
226 {
227 if (qc)
228 {
230 }
231 else
232 {
239 }
241 }
242 }
243 else if ((ch == '$') && (!qc || (qc == '"')) &&
244 ((tok->
dptr[0] ==
'{') || isalpha((
unsigned char) tok->
dptr[0])))
245 {
246 const char *env = NULL;
247 char *var = NULL;
248
249 if (tok->
dptr[0] ==
'{')
250 {
251 pc = strchr(tok->
dptr,
'}');
252 if (pc)
253 {
256
258 {
264 }
265 }
266 }
267 else
268 {
269 for (pc = tok->
dptr; isalnum((
unsigned char) *pc) || (pc[0] ==
'_'); pc++)
270 ;
271
274 }
275 if (var)
276 {
279
281 {
283 }
285 {
287 }
288 else
289 {
292 }
295 }
296 }
297 else
298 {
300 }
301 }
304 return 0;
305}
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.
char ** EnvList
Private copy of the environment variables.
#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.
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.