Use new string trimming functions in parsers.
* include/mailutils/cstr.h (mu_str_stripws): New function. * mailbox/stripws.c: New file. * mailbox/Makefile.am (libmailutils_la_SOURCES): Add stripws.c * examples/nntpclient.c (stripwhite): Remove. Use mu_str_stripws instead. (execute_line): Rewrite using new string functions. * examples/pop3client.c: Likewise. * mailbox/mailcap.c (stripwhite): Remove. Use mu_str_stripws instead. * mailbox/mime.c (_strltrim, _strttrim, _strtrim): Remove. Use mu_str_stripws instead. * mail/mail.c: Use mu_str_stripws. * mail/mail.h (util_stripwhite): Remove prototype. * mail/util.c (util_stripwhite): Remove * examples/pop3client.c: Likewise. * imap4d/util.c: Use new string functions. * maidag/forward.c: Likewise. * maidag/lmtp.c: Likewise. * mh/mhn.c: Likewise. * libproto/imap/folder.c: Remove unused local. * libproto/mailer/smtp.c (smtp_writeline): Minor optimization.
Showing
17 changed files
with
101 additions
and
225 deletions
... | @@ -44,6 +44,7 @@ | ... | @@ -44,6 +44,7 @@ |
44 | #include <mailutils/errno.h> | 44 | #include <mailutils/errno.h> |
45 | #include <mailutils/mutil.h> | 45 | #include <mailutils/mutil.h> |
46 | #include <mailutils/cctype.h> | 46 | #include <mailutils/cctype.h> |
47 | #include <mailutils/cstr.h> | ||
47 | 48 | ||
48 | /* A structure which contains information on the commands this program | 49 | /* A structure which contains information on the commands this program |
49 | can understand. */ | 50 | can understand. */ |
... | @@ -87,7 +88,6 @@ int com_stat (char *); | ... | @@ -87,7 +88,6 @@ int com_stat (char *); |
87 | int com_verbose (char *); | 88 | int com_verbose (char *); |
88 | 89 | ||
89 | void initialize_readline (void); | 90 | void initialize_readline (void); |
90 | char *stripwhite (char *); | ||
91 | COMMAND *find_command (char *); | 91 | COMMAND *find_command (char *); |
92 | char *dupstr (const char *); | 92 | char *dupstr (const char *); |
93 | int execute_line (char *); | 93 | int execute_line (char *); |
... | @@ -274,7 +274,7 @@ main (int argc MU_ARG_UNUSED, char **argv) | ... | @@ -274,7 +274,7 @@ main (int argc MU_ARG_UNUSED, char **argv) |
274 | /* Remove leading and trailing whitespace from the line. | 274 | /* Remove leading and trailing whitespace from the line. |
275 | Then, if there is anything left, add it to the history list | 275 | Then, if there is anything left, add it to the history list |
276 | and execute it. */ | 276 | and execute it. */ |
277 | s = stripwhite (line); | 277 | s = mu_str_stripws (line); |
278 | 278 | ||
279 | if (*s) | 279 | if (*s) |
280 | { | 280 | { |
... | @@ -294,45 +294,34 @@ main (int argc MU_ARG_UNUSED, char **argv) | ... | @@ -294,45 +294,34 @@ main (int argc MU_ARG_UNUSED, char **argv) |
294 | int | 294 | int |
295 | execute_line (char *line) | 295 | execute_line (char *line) |
296 | { | 296 | { |
297 | register int i; | ||
298 | COMMAND *command; | 297 | COMMAND *command; |
299 | char *word; | 298 | char *word, *arg; |
300 | 299 | ||
301 | /* Isolate the command word. */ | 300 | /* Isolate the command word. */ |
302 | i = 0; | 301 | word = mu_str_skip_class (line, MU_CTYPE_SPACE); |
303 | while (line[i] && mu_isblank (line[i])) | 302 | arg = mu_str_skip_class_comp (word, MU_CTYPE_SPACE); |
304 | i++; | 303 | if (*arg) |
305 | word = line + i; | 304 | { |
306 | 305 | *arg++ = 0; | |
307 | while (line[i] && !mu_isblank (line[i])) | 306 | arg = mu_str_skip_class (arg, MU_CTYPE_SPACE); |
308 | i++; | 307 | } |
309 | |||
310 | if (line[i]) | ||
311 | line[i++] = '\0'; | ||
312 | 308 | ||
313 | command = find_command (word); | 309 | command = find_command (word); |
314 | 310 | ||
315 | if (!command) | 311 | if (!command) |
316 | { | 312 | { |
317 | fprintf (stderr, "%s: No such command for %s.\n", word, progname); | 313 | mu_error ("%s: No such command.", word); |
318 | return (-1); | 314 | return 0; |
319 | } | 315 | } |
320 | 316 | ||
321 | /* Get argument to command, if any. */ | ||
322 | while (mu_isblank (line[i])) | ||
323 | i++; | ||
324 | |||
325 | word = line + i; | ||
326 | |||
327 | /* Call the function. */ | 317 | /* Call the function. */ |
328 | return ((*(command->func)) (word)); | 318 | return ((*(command->func)) (arg)); |
329 | } | 319 | } |
330 | 320 | ||
331 | /* Look up NAME as the name of a command, and return a pointer to that | 321 | /* Look up NAME as the name of a command, and return a pointer to that |
332 | command. Return a NULL pointer if NAME isn't a command name. */ | 322 | command. Return a NULL pointer if NAME isn't a command name. */ |
333 | COMMAND * | 323 | COMMAND * |
334 | find_command (name) | 324 | find_command (char *name) |
335 | char *name; | ||
336 | { | 325 | { |
337 | register int i; | 326 | register int i; |
338 | 327 | ||
... | @@ -343,27 +332,6 @@ find_command (name) | ... | @@ -343,27 +332,6 @@ find_command (name) |
343 | return ((COMMAND *) NULL); | 332 | return ((COMMAND *) NULL); |
344 | } | 333 | } |
345 | 334 | ||
346 | /* Strip whitespace from the start and end of STRING. Return a pointer | ||
347 | into STRING. */ | ||
348 | char * | ||
349 | stripwhite (char *string) | ||
350 | { | ||
351 | register char *s, *t; | ||
352 | |||
353 | for (s = string; mu_isblank (*s); s++) | ||
354 | ; | ||
355 | |||
356 | if (*s == 0) | ||
357 | return (s); | ||
358 | |||
359 | t = s + strlen (s) - 1; | ||
360 | while (t > s && mu_isblank (*t)) | ||
361 | t--; | ||
362 | *++t = '\0'; | ||
363 | |||
364 | return s; | ||
365 | } | ||
366 | |||
367 | int | 335 | int |
368 | com_verbose (char *arg) | 336 | com_verbose (char *arg) |
369 | { | 337 | { | ... | ... |
... | @@ -46,6 +46,7 @@ | ... | @@ -46,6 +46,7 @@ |
46 | #include <mailutils/vartab.h> | 46 | #include <mailutils/vartab.h> |
47 | #include <mailutils/argcv.h> | 47 | #include <mailutils/argcv.h> |
48 | #include <mailutils/cctype.h> | 48 | #include <mailutils/cctype.h> |
49 | #include <mailutils/cstr.h> | ||
49 | 50 | ||
50 | /* A structure which contains information on the commands this program | 51 | /* A structure which contains information on the commands this program |
51 | can understand. */ | 52 | can understand. */ |
... | @@ -80,7 +81,6 @@ int com_verbose (char *); | ... | @@ -80,7 +81,6 @@ int com_verbose (char *); |
80 | int com_prompt (char *); | 81 | int com_prompt (char *); |
81 | 82 | ||
82 | void initialize_readline (void); | 83 | void initialize_readline (void); |
83 | char *stripwhite (char *); | ||
84 | COMMAND *find_command (char *); | 84 | COMMAND *find_command (char *); |
85 | char *dupstr (const char *); | 85 | char *dupstr (const char *); |
86 | int execute_line (char *); | 86 | int execute_line (char *); |
... | @@ -322,7 +322,7 @@ main (int argc MU_ARG_UNUSED, char **argv) | ... | @@ -322,7 +322,7 @@ main (int argc MU_ARG_UNUSED, char **argv) |
322 | /* Remove leading and trailing whitespace from the line. | 322 | /* Remove leading and trailing whitespace from the line. |
323 | Then, if there is anything left, add it to the history list | 323 | Then, if there is anything left, add it to the history list |
324 | and execute it. */ | 324 | and execute it. */ |
325 | s = stripwhite (line); | 325 | s = mu_str_stripws (line); |
326 | 326 | ||
327 | if (*s) | 327 | if (*s) |
328 | { | 328 | { |
... | @@ -342,21 +342,17 @@ main (int argc MU_ARG_UNUSED, char **argv) | ... | @@ -342,21 +342,17 @@ main (int argc MU_ARG_UNUSED, char **argv) |
342 | int | 342 | int |
343 | execute_line (char *line) | 343 | execute_line (char *line) |
344 | { | 344 | { |
345 | register int i; | ||
346 | COMMAND *command; | 345 | COMMAND *command; |
347 | char *word; | 346 | char *word, *arg; |
348 | 347 | ||
349 | /* Isolate the command word. */ | 348 | /* Isolate the command word. */ |
350 | i = 0; | 349 | word = mu_str_skip_class (line, MU_CTYPE_SPACE); |
351 | while (line[i] && mu_isblank (line[i])) | 350 | arg = mu_str_skip_class_comp (word, MU_CTYPE_SPACE); |
352 | i++; | 351 | if (*arg) |
353 | word = line + i; | 352 | { |
354 | 353 | *arg++ = 0; | |
355 | while (line[i] && !mu_isblank (line[i])) | 354 | arg = mu_str_skip_class (arg, MU_CTYPE_SPACE); |
356 | i++; | 355 | } |
357 | |||
358 | if (line[i]) | ||
359 | line[i++] = '\0'; | ||
360 | 356 | ||
361 | command = find_command (word); | 357 | command = find_command (word); |
362 | 358 | ||
... | @@ -366,21 +362,14 @@ execute_line (char *line) | ... | @@ -366,21 +362,14 @@ execute_line (char *line) |
366 | return 0; | 362 | return 0; |
367 | } | 363 | } |
368 | 364 | ||
369 | /* Get argument to command, if any. */ | ||
370 | while (mu_isblank (line[i])) | ||
371 | i++; | ||
372 | |||
373 | word = line + i; | ||
374 | |||
375 | /* Call the function. */ | 365 | /* Call the function. */ |
376 | return ((*(command->func)) (word)); | 366 | return ((*(command->func)) (arg)); |
377 | } | 367 | } |
378 | 368 | ||
379 | /* Look up NAME as the name of a command, and return a pointer to that | 369 | /* Look up NAME as the name of a command, and return a pointer to that |
380 | command. Return a NULL pointer if NAME isn't a command name. */ | 370 | command. Return a NULL pointer if NAME isn't a command name. */ |
381 | COMMAND * | 371 | COMMAND * |
382 | find_command (name) | 372 | find_command (char *name) |
383 | char *name; | ||
384 | { | 373 | { |
385 | register int i; | 374 | register int i; |
386 | 375 | ||
... | @@ -391,27 +380,6 @@ find_command (name) | ... | @@ -391,27 +380,6 @@ find_command (name) |
391 | return ((COMMAND *) NULL); | 380 | return ((COMMAND *) NULL); |
392 | } | 381 | } |
393 | 382 | ||
394 | /* Strip whitespace from the start and end of STRING. Return a pointer | ||
395 | into STRING. */ | ||
396 | char * | ||
397 | stripwhite (char *string) | ||
398 | { | ||
399 | register char *s, *t; | ||
400 | |||
401 | for (s = string; mu_isblank (*s); s++) | ||
402 | ; | ||
403 | |||
404 | if (*s == 0) | ||
405 | return (s); | ||
406 | |||
407 | t = s + strlen (s) - 1; | ||
408 | while (t > s && mu_isblank (*t)) | ||
409 | t--; | ||
410 | *++t = '\0'; | ||
411 | |||
412 | return s; | ||
413 | } | ||
414 | |||
415 | int | 383 | int |
416 | com_verbose (char *arg) | 384 | com_verbose (char *arg) |
417 | { | 385 | { | ... | ... |
... | @@ -1363,13 +1363,11 @@ imap4d_readline (struct imap4d_tokbuf *tok) | ... | @@ -1363,13 +1363,11 @@ imap4d_readline (struct imap4d_tokbuf *tok) |
1363 | char *p = mu_strcasestr (tok->buffer, "LOGIN"); | 1363 | char *p = mu_strcasestr (tok->buffer, "LOGIN"); |
1364 | if (p && p > tok->buffer && mu_isblank (p[-1])) | 1364 | if (p && p > tok->buffer && mu_isblank (p[-1])) |
1365 | { | 1365 | { |
1366 | char *q = p + 5; | 1366 | char *q = mu_str_skip_class (p + 5, MU_CTYPE_SPACE); |
1367 | while (*q && mu_isblank (*q)) | 1367 | q = mu_str_skip_class_comp (q, MU_CTYPE_SPACE); |
1368 | q++; | ||
1369 | while (*q && !mu_isblank (*q)) | ||
1370 | q++; | ||
1371 | len = q - tok->buffer; | 1368 | len = q - tok->buffer; |
1372 | mu_diag_output (MU_DIAG_DEBUG, "recv: %*.*s {censored}", len, len, | 1369 | mu_diag_output (MU_DIAG_DEBUG, |
1370 | "recv: %*.*s {censored}", len, len, | ||
1373 | tok->buffer); | 1371 | tok->buffer); |
1374 | } | 1372 | } |
1375 | else | 1373 | else | ... | ... |
... | @@ -39,6 +39,7 @@ char *mu_str_skip_cset (const char *str, const char *cset); | ... | @@ -39,6 +39,7 @@ char *mu_str_skip_cset (const char *str, const char *cset); |
39 | char *mu_str_skip_class_comp (const char *str, int class); | 39 | char *mu_str_skip_class_comp (const char *str, int class); |
40 | char *mu_str_skip_cset_comp (const char *str, const char *cset); | 40 | char *mu_str_skip_cset_comp (const char *str, const char *cset); |
41 | 41 | ||
42 | char *mu_str_stripws (char *string); | ||
42 | 43 | ||
43 | #ifdef __cplusplus | 44 | #ifdef __cplusplus |
44 | } | 45 | } | ... | ... |
... | @@ -1817,7 +1817,6 @@ imap_body (f_imap_t f_imap, char **ptr) | ... | @@ -1817,7 +1817,6 @@ imap_body (f_imap_t f_imap, char **ptr) |
1817 | { | 1817 | { |
1818 | size_t len = sep - *ptr; | 1818 | size_t len = sep - *ptr; |
1819 | char *section = malloc (len + 1); | 1819 | char *section = malloc (len + 1); |
1820 | char *p; | ||
1821 | 1820 | ||
1822 | if (!section) | 1821 | if (!section) |
1823 | return ENOMEM; | 1822 | return ENOMEM; | ... | ... |
... | @@ -1067,13 +1067,14 @@ smtp_writeline (smtp_t smtp, const char *format, ...) | ... | @@ -1067,13 +1067,14 @@ smtp_writeline (smtp_t smtp, const char *format, ...) |
1067 | 1067 | ||
1068 | smtp->ptr = smtp->buffer + len; | 1068 | smtp->ptr = smtp->buffer + len; |
1069 | 1069 | ||
1070 | while (len > 0 && mu_isblank (smtp->buffer[len - 1])) | ||
1071 | len--; | ||
1072 | |||
1073 | if ((smtp->state != SMTP_SEND && smtp->state != SMTP_SEND_DOT) | 1070 | if ((smtp->state != SMTP_SEND && smtp->state != SMTP_SEND_DOT) |
1074 | || smtp->mailer->flags & MAILER_FLAG_DEBUG_DATA) | 1071 | || smtp->mailer->flags & MAILER_FLAG_DEBUG_DATA) |
1072 | { | ||
1073 | while (len > 0 && mu_isblank (smtp->buffer[len - 1])) | ||
1074 | len--; | ||
1075 | MU_DEBUG2 (smtp->mailer->debug, MU_DEBUG_PROT, "> %.*s\n", len, | 1075 | MU_DEBUG2 (smtp->mailer->debug, MU_DEBUG_PROT, "> %.*s\n", len, |
1076 | smtp->buffer); | 1076 | smtp->buffer); |
1077 | } | ||
1077 | 1078 | ||
1078 | return 0; | 1079 | return 0; |
1079 | } | 1080 | } | ... | ... |
... | @@ -220,18 +220,10 @@ process_forward (mu_message_t msg, char *filename, const char *myname) | ... | @@ -220,18 +220,10 @@ process_forward (mu_message_t msg, char *filename, const char *myname) |
220 | 220 | ||
221 | while (getline (&buf, &size, fp) > 0) | 221 | while (getline (&buf, &size, fp) > 0) |
222 | { | 222 | { |
223 | char *p, *q; | 223 | char *p; |
224 | for (p = buf; *p && mu_isblank (*p); p++) | 224 | |
225 | ; | 225 | mu_rtrim_class (buf, MU_CTYPE_SPACE); |
226 | q = p + strlen (p); | 226 | p = mu_str_skip_class (buf, MU_CTYPE_SPACE); |
227 | if (q > p) | ||
228 | { | ||
229 | if (*--q == '\n') | ||
230 | q--; | ||
231 | for (; q > p && mu_isblank (*q); q--) | ||
232 | ; | ||
233 | q[1] = 0; | ||
234 | } | ||
235 | 227 | ||
236 | if (*p && *p != '#') | 228 | if (*p && *p != '#') |
237 | { | 229 | { | ... | ... |
... | @@ -77,16 +77,6 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...) | ... | @@ -77,16 +77,6 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...) |
77 | } | 77 | } |
78 | 78 | ||
79 | void | 79 | void |
80 | trimnl (char *arg) | ||
81 | { | ||
82 | size_t len = strlen (arg); | ||
83 | if (len > 0 && arg[len-1] == '\n') | ||
84 | arg[--len] = 0; | ||
85 | if (len > 0 && arg[len-1] == '\r') | ||
86 | arg[--len] = 0; | ||
87 | } | ||
88 | |||
89 | void | ||
90 | xlatnl (char *arg) | 80 | xlatnl (char *arg) |
91 | { | 81 | { |
92 | size_t len = strlen (arg); | 82 | size_t len = strlen (arg); |
... | @@ -543,7 +533,7 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout) | ... | @@ -543,7 +533,7 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout) |
543 | enum lmtp_command cmd = cp->cmd_code; | 533 | enum lmtp_command cmd = cp->cmd_code; |
544 | enum lmtp_state next_state = transtab[cmd][state]; | 534 | enum lmtp_state next_state = transtab[cmd][state]; |
545 | 535 | ||
546 | trimnl (buf); | 536 | mu_rtrim_cset (sp, "\r\n"); |
547 | 537 | ||
548 | if (lmtp_transcript) | 538 | if (lmtp_transcript) |
549 | mu_diag_output (MU_DIAG_INFO, "LMTP recieve: %s", buf); | 539 | mu_diag_output (MU_DIAG_INFO, "LMTP recieve: %s", buf); |
... | @@ -552,8 +542,7 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout) | ... | @@ -552,8 +542,7 @@ lmtp_loop (FILE *in, FILE *out, unsigned int timeout) |
552 | { | 542 | { |
553 | if (cp->cmd_fun) | 543 | if (cp->cmd_fun) |
554 | { | 544 | { |
555 | while (*sp && mu_isblank (*sp)) | 545 | sp = mu_str_skip_class (sp, MU_CTYPE_SPACE); |
556 | sp++; | ||
557 | if (cp->cmd_fun (out, sp)) | 546 | if (cp->cmd_fun (out, sp)) |
558 | continue; | 547 | continue; |
559 | } | 548 | } | ... | ... |
... | @@ -529,7 +529,7 @@ mail_mainloop (char *(*input) (void *, int), | ... | @@ -529,7 +529,7 @@ mail_mainloop (char *(*input) (void *, int), |
529 | command = buf; | 529 | command = buf; |
530 | len = strlen (command); | 530 | len = strlen (command); |
531 | } | 531 | } |
532 | cmd = util_stripwhite (command); | 532 | cmd = mu_str_stripws (command); |
533 | util_do_command ("%s", cmd); | 533 | util_do_command ("%s", cmd); |
534 | #ifdef WITH_READLINE | 534 | #ifdef WITH_READLINE |
535 | if (do_history && !(mu_isspace(cmd[0]) || cmd[0] == '#')) | 535 | if (do_history && !(mu_isspace(cmd[0]) || cmd[0] == '#')) | ... | ... |
... | @@ -313,7 +313,6 @@ extern size_t util_range_msg (size_t low, size_t high, int flags, | ... | @@ -313,7 +313,6 @@ extern size_t util_range_msg (size_t low, size_t high, int flags, |
313 | msg_handler_t func, void *data); | 313 | msg_handler_t func, void *data); |
314 | 314 | ||
315 | extern function_t* util_command_get (const char *cmd); | 315 | extern function_t* util_command_get (const char *cmd); |
316 | extern char *util_stripwhite (char *string); | ||
317 | 316 | ||
318 | extern void *util_find_entry (void *table, size_t nmemb, size_t size, | 317 | extern void *util_find_entry (void *table, size_t nmemb, size_t size, |
319 | const char *cmd); | 318 | const char *cmd); | ... | ... |
... | @@ -336,24 +336,6 @@ util_command_list (void *table, size_t nmemb, size_t size) | ... | @@ -336,24 +336,6 @@ util_command_list (void *table, size_t nmemb, size_t size) |
336 | } | 336 | } |
337 | 337 | ||
338 | /* | 338 | /* |
339 | * removes whitespace from the beginning and end of a string | ||
340 | */ | ||
341 | char * | ||
342 | util_stripwhite (char *string) | ||
343 | { | ||
344 | register char *s, *t; | ||
345 | for (s = string; mu_isspace ((unsigned)*s); s++) | ||
346 | ; | ||
347 | if (*s == 0) | ||
348 | return s; | ||
349 | t = s + strlen (s) - 1; | ||
350 | while (t > s && mu_isspace ((unsigned)*t)) | ||
351 | t--; | ||
352 | *++t = '\0'; | ||
353 | return s; | ||
354 | } | ||
355 | |||
356 | /* | ||
357 | * Get the number of columns on the screen | 339 | * Get the number of columns on the screen |
358 | * First try an ioctl() call not all shells set the COLUMNS environ. | 340 | * First try an ioctl() call not all shells set the COLUMNS environ. |
359 | */ | 341 | */ | ... | ... |
... | @@ -123,6 +123,7 @@ libmailutils_la_SOURCES = \ | ... | @@ -123,6 +123,7 @@ libmailutils_la_SOURCES = \ |
123 | stream.c\ | 123 | stream.c\ |
124 | strltrim.c\ | 124 | strltrim.c\ |
125 | strskip.c\ | 125 | strskip.c\ |
126 | stripws.c\ | ||
126 | strrtrim.c\ | 127 | strrtrim.c\ |
127 | syslog.c\ | 128 | syslog.c\ |
128 | system.c\ | 129 | system.c\ | ... | ... |
... | @@ -50,7 +50,6 @@ struct _mu_mailcap | ... | @@ -50,7 +50,6 @@ struct _mu_mailcap |
50 | 50 | ||
51 | static int mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream); | 51 | static int mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream); |
52 | static int mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer); | 52 | static int mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer); |
53 | static char * stripwhite (char *string); | ||
54 | static char * tokenize (char *s, char **save_ptr); | 53 | static char * tokenize (char *s, char **save_ptr); |
55 | 54 | ||
56 | int | 55 | int |
... | @@ -371,8 +370,8 @@ mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const char *key, | ... | @@ -371,8 +370,8 @@ mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const char *key, |
371 | if (value != NULL) | 370 | if (value != NULL) |
372 | { | 371 | { |
373 | value++; /* Pass the equal. */ | 372 | value++; /* Pass the equal. */ |
374 | /* Remove prepend space. */ | 373 | /* Remove leading space. */ |
375 | for (; mu_isspace ((unsigned char)*value); value++) | 374 | for (; mu_isspace (*value); value++) |
376 | ; | 375 | ; |
377 | len = strlen (value); | 376 | len = strlen (value); |
378 | /* Strip surrounding double quotes */ | 377 | /* Strip surrounding double quotes */ |
... | @@ -400,27 +399,6 @@ mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const char *key, | ... | @@ -400,27 +399,6 @@ mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const char *key, |
400 | return status; | 399 | return status; |
401 | } | 400 | } |
402 | 401 | ||
403 | /* Strip whitespace from the start and end of STRING. Return a pointer | ||
404 | into STRING. */ | ||
405 | static char * | ||
406 | stripwhite (char *string) | ||
407 | { | ||
408 | register char *s, *t; | ||
409 | |||
410 | for (s = string; mu_isspace ((unsigned char)*s); s++) | ||
411 | ; | ||
412 | |||
413 | if (*s == 0) | ||
414 | return (s); | ||
415 | |||
416 | t = s + strlen (s) - 1; | ||
417 | while (t > s && mu_isspace (*t)) | ||
418 | t--; | ||
419 | *++t = '\0'; | ||
420 | |||
421 | return s; | ||
422 | } | ||
423 | |||
424 | /* | 402 | /* |
425 | * break the line on ';'. Same as strtok() but | 403 | * break the line on ';'. Same as strtok() but |
426 | * check for escaped "\;" | 404 | * check for escaped "\;" |
... | @@ -479,12 +457,12 @@ mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer) | ... | @@ -479,12 +457,12 @@ mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer) |
479 | { | 457 | { |
480 | /* The first entry in a mailcap line is the typefield. */ | 458 | /* The first entry in a mailcap line is the typefield. */ |
481 | case 0: | 459 | case 0: |
482 | entry->typefield = strdup (stripwhite (token)); | 460 | entry->typefield = strdup (mu_str_stripws (token)); |
483 | break; | 461 | break; |
484 | 462 | ||
485 | /* The second entry in a mailcap line is the view-command. */ | 463 | /* The second entry in a mailcap line is the view-command. */ |
486 | case 1: | 464 | case 1: |
487 | entry->viewcommand = strdup (stripwhite(token)); | 465 | entry->viewcommand = strdup (mu_str_stripws (token)); |
488 | break; | 466 | break; |
489 | 467 | ||
490 | /* The rest are the optional fields. */ | 468 | /* The rest are the optional fields. */ |
... | @@ -496,7 +474,8 @@ mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer) | ... | @@ -496,7 +474,8 @@ mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer) |
496 | if (fields != NULL) | 474 | if (fields != NULL) |
497 | { | 475 | { |
498 | entry->fields = fields; | 476 | entry->fields = fields; |
499 | entry->fields[entry->fields_count] = strdup (stripwhite (token)); | 477 | entry->fields[entry->fields_count] = |
478 | strdup (mu_str_stripws (token)); | ||
500 | entry->fields_count++; | 479 | entry->fields_count++; |
501 | } | 480 | } |
502 | } | 481 | } |
... | @@ -643,7 +622,7 @@ mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream) | ... | @@ -643,7 +622,7 @@ mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream) |
643 | /* Parse the well-form mailcap line entry. */ | 622 | /* Parse the well-form mailcap line entry. */ |
644 | if (previous == NULL) { | 623 | if (previous == NULL) { |
645 | /* Nuke the trailing/prepend spaces. */ | 624 | /* Nuke the trailing/prepend spaces. */ |
646 | char *line = stripwhite(buffer); | 625 | char *line = mu_str_stripws (buffer); |
647 | /* Ignore comments or empty lines */ | 626 | /* Ignore comments or empty lines */ |
648 | if (*line != '#' && *line != '\0') | 627 | if (*line != '#' && *line != '\0') |
649 | { | 628 | { | ... | ... |
... | @@ -133,30 +133,6 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg, int offset, int len, int li | ... | @@ -133,30 +133,6 @@ _mime_append_part (mu_mime_t mime, mu_message_t msg, int offset, int len, int li |
133 | return 0; | 133 | return 0; |
134 | } | 134 | } |
135 | 135 | ||
136 | static char * | ||
137 | _strltrim (char *str) | ||
138 | { | ||
139 | char *p; | ||
140 | |||
141 | for (p = str; mu_isspace (*p) && *p != '\0'; ++p); | ||
142 | return ((p != str) ? memmove (str, p, strlen (p) + 1) : str); | ||
143 | } | ||
144 | |||
145 | static char * | ||
146 | _strttrim (char *str) | ||
147 | { | ||
148 | char *p; | ||
149 | |||
150 | for (p = str + strlen (str) - 1; | ||
151 | mu_isspace (*p) && p >= str; --p); | ||
152 | *++p = '\0'; | ||
153 | return (str); | ||
154 | } | ||
155 | |||
156 | char *_strtrim (char *str); | ||
157 | |||
158 | #define _strtrim(str) _strltrim(_strttrim(str)) | ||
159 | |||
160 | #define _ISSPECIAL(c) ( \ | 136 | #define _ISSPECIAL(c) ( \ |
161 | ((c) == '(') || ((c) == ')') || ((c) == '<') || ((c) == '>') \ | 137 | ((c) == '(') || ((c) == ')') || ((c) == '<') || ((c) == '>') \ |
162 | || ((c) == '@') || ((c) == ',') || ((c) == ';') || ((c) == ':') \ | 138 | || ((c) == '@') || ((c) == ',') || ((c) == ';') || ((c) == ':') \ |
... | @@ -169,7 +145,7 @@ _mime_munge_content_header (char *field_body) | ... | @@ -169,7 +145,7 @@ _mime_munge_content_header (char *field_body) |
169 | char *p, *e, *str = field_body; | 145 | char *p, *e, *str = field_body; |
170 | int quoted = 0; | 146 | int quoted = 0; |
171 | 147 | ||
172 | _strtrim (field_body); | 148 | mu_str_stripws (field_body); |
173 | 149 | ||
174 | if ((e = strchr (str, ';')) == NULL) | 150 | if ((e = strchr (str, ';')) == NULL) |
175 | return; | 151 | return; | ... | ... |
mailbox/stripws.c
0 → 100644
1 | /* This file is part of GNU Mailutils | ||
2 | Copyright (C) 2009 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library 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 GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include <stdlib.h> | ||
22 | #include <mailutils/cctype.h> | ||
23 | #include <mailutils/cstr.h> | ||
24 | |||
25 | /* | ||
26 | * removes whitespace from the beginning and end of a string | ||
27 | */ | ||
28 | char * | ||
29 | mu_str_stripws (char *string) | ||
30 | { | ||
31 | mu_rtrim_class (string, MU_CTYPE_SPACE); | ||
32 | return mu_str_skip_class (string, MU_CTYPE_SPACE); | ||
33 | } |
... | @@ -480,7 +480,7 @@ yylex () | ... | @@ -480,7 +480,7 @@ yylex () |
480 | { | 480 | { |
481 | curp -= rest; | 481 | curp -= rest; |
482 | yylval.builtin = bp; | 482 | yylval.builtin = bp; |
483 | while (*curp && mu_isspace(*curp)) | 483 | while (*curp && mu_isspace (*curp)) |
484 | curp++; | 484 | curp++; |
485 | return FUNCTION; | 485 | return FUNCTION; |
486 | } | 486 | } | ... | ... |
... | @@ -617,8 +617,7 @@ mhn_compose_command (char *typestr, int *flags, char *file) | ... | @@ -617,8 +617,7 @@ mhn_compose_command (char *typestr, int *flags, char *file) |
617 | %s subtype */ | 617 | %s subtype */ |
618 | 618 | ||
619 | obstack_init (&stk); | 619 | obstack_init (&stk); |
620 | for (p = str; *p && mu_isspace (*p); p++) | 620 | p = mu_str_skip_class (str, MU_CTYPE_SPACE); |
621 | ; | ||
622 | 621 | ||
623 | if (*p == '|') | 622 | if (*p == '|') |
624 | p++; | 623 | p++; |
... | @@ -661,12 +660,11 @@ mhn_compose_command (char *typestr, int *flags, char *file) | ... | @@ -661,12 +660,11 @@ mhn_compose_command (char *typestr, int *flags, char *file) |
661 | free (subtype); | 660 | free (subtype); |
662 | 661 | ||
663 | str = obstack_finish (&stk); | 662 | str = obstack_finish (&stk); |
664 | for (p = str; *p && mu_isspace (*p); p++) | 663 | p = mu_str_skip_class (str, MU_CTYPE_SPACE); |
665 | ; | ||
666 | if (!*p) | 664 | if (!*p) |
667 | str = NULL; | 665 | str = NULL; |
668 | else | 666 | else |
669 | str = strdup (str); | 667 | str = strdup (p); |
670 | 668 | ||
671 | obstack_free (&stk, NULL); | 669 | obstack_free (&stk, NULL); |
672 | return (char*) str; | 670 | return (char*) str; |
... | @@ -700,8 +698,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, | ... | @@ -700,8 +698,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, |
700 | %d content description */ | 698 | %d content description */ |
701 | 699 | ||
702 | obstack_init (&stk); | 700 | obstack_init (&stk); |
703 | for (p = str; *p && mu_isspace (*p); p++) | 701 | p = mu_str_skip_class (str, MU_CTYPE_SPACE); |
704 | ; | ||
705 | 702 | ||
706 | if (*p == '|') | 703 | if (*p == '|') |
707 | p++; | 704 | p++; |
... | @@ -777,12 +774,11 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, | ... | @@ -777,12 +774,11 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, |
777 | free (subtype); | 774 | free (subtype); |
778 | 775 | ||
779 | str = obstack_finish (&stk); | 776 | str = obstack_finish (&stk); |
780 | for (p = str; *p && mu_isspace (*p); p++) | 777 | p = mu_str_skip_class (str, MU_CTYPE_SPACE); |
781 | ; | ||
782 | if (!*p) | 778 | if (!*p) |
783 | str = NULL; | 779 | str = NULL; |
784 | else | 780 | else |
785 | str = strdup (str); | 781 | str = strdup (p); |
786 | 782 | ||
787 | obstack_free (&stk, NULL); | 783 | obstack_free (&stk, NULL); |
788 | return (char*) str; | 784 | return (char*) str; |
... | @@ -869,12 +865,11 @@ mhn_store_command (mu_message_t msg, msg_part_t part, char *name) | ... | @@ -869,12 +865,11 @@ mhn_store_command (mu_message_t msg, msg_part_t part, char *name) |
869 | free (subtype); | 865 | free (subtype); |
870 | 866 | ||
871 | str = obstack_finish (&stk); | 867 | str = obstack_finish (&stk); |
872 | for (p = str; *p && mu_isspace (*p); p++) | 868 | p = mu_str_skip_class (str, MU_CTYPE_SPACE); |
873 | ; | ||
874 | if (!*p) | 869 | if (!*p) |
875 | str = NULL; | 870 | str = NULL; |
876 | else | 871 | else |
877 | str = strdup (str); | 872 | str = strdup (p); |
878 | 873 | ||
879 | obstack_free (&stk, NULL); | 874 | obstack_free (&stk, NULL); |
880 | return (char*) str; | 875 | return (char*) str; |
... | @@ -985,9 +980,8 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) | ... | @@ -985,9 +980,8 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) |
985 | && mu_c_strncasecmp (buf, MU_HEADER_CONTENT_DESCRIPTION ":", | 980 | && mu_c_strncasecmp (buf, MU_HEADER_CONTENT_DESCRIPTION ":", |
986 | sizeof (MU_HEADER_CONTENT_DESCRIPTION)) == 0) | 981 | sizeof (MU_HEADER_CONTENT_DESCRIPTION)) == 0) |
987 | { | 982 | { |
988 | for (p = buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION); | 983 | p = mu_str_skip_class (buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION), |
989 | *p && mu_isspace (*p); p++) | 984 | MU_CTYPE_SPACE); |
990 | ; | ||
991 | *descr = strdup (p); | 985 | *descr = strdup (p); |
992 | } | 986 | } |
993 | else if (content | 987 | else if (content |
... | @@ -995,9 +989,8 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) | ... | @@ -995,9 +989,8 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) |
995 | sizeof (MU_HEADER_CONTENT_TYPE)) == 0) | 989 | sizeof (MU_HEADER_CONTENT_TYPE)) == 0) |
996 | { | 990 | { |
997 | char *q; | 991 | char *q; |
998 | for (p = buf + sizeof (MU_HEADER_CONTENT_TYPE); | 992 | p = mu_str_skip_class (buf + sizeof (MU_HEADER_CONTENT_TYPE), |
999 | *p && mu_isspace (*p); p++) | 993 | MU_CTYPE_SPACE); |
1000 | ; | ||
1001 | q = strchr (p, ';'); | 994 | q = strchr (p, ';'); |
1002 | if (q) | 995 | if (q) |
1003 | *q = 0; | 996 | *q = 0; |
... | @@ -1830,7 +1823,7 @@ parse_brace (char **pval, char **cmd, int c, struct compose_env *env) | ... | @@ -1830,7 +1823,7 @@ parse_brace (char **pval, char **cmd, int c, struct compose_env *env) |
1830 | } | 1823 | } |
1831 | 1824 | ||
1832 | #define isdelim(c) (mu_isspace (c) || strchr (";<[(", c)) | 1825 | #define isdelim(c) (mu_isspace (c) || strchr (";<[(", c)) |
1833 | #define skipws(ptr) do { while (*ptr && mu_isspace (*ptr)) ptr++; } while (0) | 1826 | #define skipws(ptr) (ptr) = mu_str_skip_class (ptr, MU_CTYPE_SPACE) |
1834 | 1827 | ||
1835 | int | 1828 | int |
1836 | parse_content_type (struct compose_env *env, | 1829 | parse_content_type (struct compose_env *env, |
... | @@ -2301,9 +2294,7 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level) | ... | @@ -2301,9 +2294,7 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level) |
2301 | if (rc) | 2294 | if (rc) |
2302 | return 1; | 2295 | return 1; |
2303 | 2296 | ||
2304 | for (p = cmd + strlen (cmd) - 1; p > cmd && mu_isspace (*p); p--) | 2297 | mu_rtrim_class (cmd, MU_CTYPE_SPACE); |
2305 | ; | ||
2306 | p[1] = 0; | ||
2307 | 2298 | ||
2308 | _get_content_type (hdr, &typestr, NULL); | 2299 | _get_content_type (hdr, &typestr, NULL); |
2309 | shell_cmd = mhn_compose_command (typestr, &flags, cmd); | 2300 | shell_cmd = mhn_compose_command (typestr, &flags, cmd); |
... | @@ -2463,9 +2454,8 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2463,9 +2454,8 @@ mhn_edit (struct compose_env *env, int level) |
2463 | finish_text_msg (env, &msg, ascii_buf); | 2454 | finish_text_msg (env, &msg, ascii_buf); |
2464 | 2455 | ||
2465 | /* Execute the directive */ | 2456 | /* Execute the directive */ |
2466 | tok = sp = buf; | 2457 | tok = buf; |
2467 | while (*sp && !mu_isspace (*sp)) | 2458 | sp = mu_str_skip_class_comp (buf, MU_CTYPE_SPACE); |
2468 | sp++; | ||
2469 | c = *sp; | 2459 | c = *sp; |
2470 | *sp = 0; | 2460 | *sp = 0; |
2471 | 2461 | ... | ... |
-
Please register or sign in to post a comment