Extract one token from a string.
49{
50 if (!dest || !line)
51 return -1;
52
53 char ch;
54 char qc = '\0';
55 char *pc = NULL;
56
58
60 while ((ch = *line->
dptr))
61 {
62 if (qc == '\0')
63 {
65 break;
67 break;
69 break;
71 break;
73 break;
75 break;
77 break;
79 break;
80 }
81
83
84 if (ch == qc)
85 {
86 qc = 0;
87 }
88 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
TOKEN_QUOTE))
89 {
90 qc = ch;
91 }
92 else if ((ch == '\\') && (qc != '\''))
93 {
94 if (line->
dptr[0] ==
'\0')
95 return -1;
96 switch (ch = *line->
dptr++)
97 {
98 case 'c':
99 case 'C':
100 if (line->
dptr[0] ==
'\0')
101 return -1;
104 break;
105 case 'e':
107 break;
108 case 'f':
110 break;
111 case 'n':
113 break;
114 case 'r':
116 break;
117 case 't':
119 break;
120 default:
123 {
126 }
127 else
128 {
130 }
131 }
132 }
134 {
135 if (line->
dptr[0] ==
'\0')
136 return -1;
138 if (ch == '^')
139 {
141 }
142 else if (ch == '[')
143 {
145 }
147 {
149 }
150 else
151 {
154 }
155 }
156 else if ((ch == '`') && (!qc || (qc == '"')))
157 {
158 FILE *fp = NULL;
159 pid_t pid;
160
162 do
163 {
164 pc = strpbrk(pc, "\\`");
165 if (pc)
166 {
167
168 if (*pc == '\\')
169 {
170 if (*(pc + 1))
171 pc += 2;
172 else
173 pc = NULL;
174 }
175 }
176 } while (pc && (pc[0] != '`'));
177 if (!pc)
178 {
180 return -1;
181 }
183 *pc = '\0';
185 {
186
190 }
191 else
192 {
194 }
195 *pc = '`';
197 if (pid < 0)
198 {
201 return -1;
202 }
203
205
206
207 char *expn = NULL;
208 size_t expn_len = 0;
212 if (rc != 0)
213 {
216 }
218
219
220
221
222
223 if (expn)
224 {
225 if (qc)
226 {
228 }
229 else
230 {
237 }
239 }
240 }
241 else if ((ch == '$') && (!qc || (qc == '"')) &&
243 {
244 const char *env = NULL;
245 char *var = NULL;
246
247 if (line->
dptr[0] ==
'{')
248 {
249 pc = strchr(line->
dptr,
'}');
250 if (pc)
251 {
254
256 {
262 }
263 }
264 }
265 else
266 {
268 ;
269
272 }
273 if (var)
274 {
277
279 {
281 }
283 {
285 }
286 else
287 {
290 }
293 }
294 }
295 else
296 {
298 }
299 }
300
302 return 0;
303}
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.
bool mutt_isspace(int arg)
Wrapper for isspace(3)
bool mutt_isalpha(int arg)
Wrapper for isalpha(3)
int mutt_toupper(int arg)
Wrapper for toupper(3)
bool mutt_isalnum(int arg)
Wrapper for isalnum(3)
bool mutt_isdigit(int arg)
Wrapper for isdigit(3)
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.