mhn: implement mhn-suffix-<type> profile component.
* mh/mhn.c (_mhn_profile_get): All arguments are const. (mhn_tempfile_name): New function. (mhn_show_command): Use mhn_tempfile_name.
Showing
1 changed file
with
26 additions
and
4 deletions
... | @@ -576,7 +576,8 @@ msg_part_subpart (msg_part_t p, int level) | ... | @@ -576,7 +576,8 @@ msg_part_subpart (msg_part_t p, int level) |
576 | /* *********************** Context file accessors ************************* */ | 576 | /* *********************** Context file accessors ************************* */ |
577 | 577 | ||
578 | const char * | 578 | const char * |
579 | _mhn_profile_get (char *prefix, char *type, char *subtype, char *defval) | 579 | _mhn_profile_get (const char *prefix, const char *type, const char *subtype, |
580 | const char *defval) | ||
580 | { | 581 | { |
581 | char *name; | 582 | char *name; |
582 | const char *str; | 583 | const char *str; |
... | @@ -670,6 +671,26 @@ mhn_compose_command (char *typestr, int *flags, char *file) | ... | @@ -670,6 +671,26 @@ mhn_compose_command (char *typestr, int *flags, char *file) |
670 | return (char*) str; | 671 | return (char*) str; |
671 | } | 672 | } |
672 | 673 | ||
674 | static void | ||
675 | mhn_tempfile_name (char **tempfile, const char *type, const char *subtype) | ||
676 | { | ||
677 | struct mu_tempfile_hints hints; | ||
678 | int flags = 0, rc; | ||
679 | const char *s = _mhn_profile_get ("suffix", type, subtype, NULL);; | ||
680 | |||
681 | if (s) | ||
682 | { | ||
683 | hints.suffix = (char*) s; | ||
684 | flags |= MU_TEMPFILE_SUFFIX; | ||
685 | } | ||
686 | rc = mu_tempfile (&hints, flags, NULL, tempfile); | ||
687 | if (rc) | ||
688 | { | ||
689 | mu_diag_funcall (MU_DIAG_ERROR, "mu_tempfile", NULL, rc); | ||
690 | exit (1); | ||
691 | } | ||
692 | } | ||
693 | |||
673 | char * | 694 | char * |
674 | mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, | 695 | mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, |
675 | char **tempfile) | 696 | char **tempfile) |
... | @@ -722,7 +743,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, | ... | @@ -722,7 +743,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, |
722 | case 'f': | 743 | case 'f': |
723 | /* filename containing content */ | 744 | /* filename containing content */ |
724 | if (!*tempfile) | 745 | if (!*tempfile) |
725 | *tempfile = mu_tempname (NULL); | 746 | mhn_tempfile_name (tempfile, type, subtype); |
726 | obstack_grow (&stk, *tempfile, strlen (*tempfile)); | 747 | obstack_grow (&stk, *tempfile, strlen (*tempfile)); |
727 | break; | 748 | break; |
728 | 749 | ||
... | @@ -730,7 +751,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, | ... | @@ -730,7 +751,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags, |
730 | /* %e, %f, and stdin is terminal not content */ | 751 | /* %e, %f, and stdin is terminal not content */ |
731 | *flags |= MHN_STDIN|MHN_EXCLUSIVE_EXEC; | 752 | *flags |= MHN_STDIN|MHN_EXCLUSIVE_EXEC; |
732 | if (!*tempfile) | 753 | if (!*tempfile) |
733 | *tempfile = mu_tempname (NULL); | 754 | mhn_tempfile_name (tempfile, type, subtype); |
734 | obstack_grow (&stk, *tempfile, strlen (*tempfile)); | 755 | obstack_grow (&stk, *tempfile, strlen (*tempfile)); |
735 | break; | 756 | break; |
736 | 757 | ||
... | @@ -1318,7 +1339,8 @@ mhn_run_command (mu_message_t msg, msg_part_t part, | ... | @@ -1318,7 +1339,8 @@ mhn_run_command (mu_message_t msg, msg_part_t part, |
1318 | return ENOSYS; | 1339 | return ENOSYS; |
1319 | } | 1340 | } |
1320 | 1341 | ||
1321 | rc = mu_file_stream_create (&tmp, tempfile, MU_STREAM_RDWR); | 1342 | rc = mu_file_stream_create (&tmp, tempfile, |
1343 | MU_STREAM_RDWR|MU_STREAM_CREAT); | ||
1322 | if (rc) | 1344 | if (rc) |
1323 | { | 1345 | { |
1324 | mu_error (_("cannot create temporary stream (file %s): %s"), | 1346 | mu_error (_("cannot create temporary stream (file %s): %s"), | ... | ... |
-
Please register or sign in to post a comment