Implement guile output redirection in maidag
* libmu_scm/mu_guimb.c: Remove * libmu_scm/mu_dbgport.c: New file. * libmu_scm/Makefile.am: Update. * include/mailutils/guile.h (mu_process_mailbox): Remove. (mu_scm_make_debug_port, mu_scm_debug_port_init): New prototypes. * libmu_scm/mu_scm.c (mu_scm_init): Call mu_scm_debug_port_init. * maidag/guile.c (scheme_check_msg): Redirect error/output to MU port. * mailbox/mutil.c (mu_expand_path_pattern): Expand ~.
Showing
7 changed files
with
152 additions
and
94 deletions
... | @@ -71,7 +71,9 @@ extern void mu_scm_message_add_owner (SCM MESG, SCM owner); | ... | @@ -71,7 +71,9 @@ extern void mu_scm_message_add_owner (SCM MESG, SCM owner); |
71 | 71 | ||
72 | extern void mu_scm_mutil_init (void); | 72 | extern void mu_scm_mutil_init (void); |
73 | 73 | ||
74 | extern void mu_process_mailbox (int argc, char *argv[], mu_guimb_param_t *param); | 74 | SCM mu_scm_make_debug_port (mu_debug_t debug, mu_log_level_t level); |
75 | void mu_scm_debug_port_init (void); | ||
76 | |||
75 | 77 | ||
76 | extern void mu_guile_init (int debug); | 78 | extern void mu_guile_init (int debug); |
77 | extern int mu_guile_load (char *filename, int argc, char **argv); | 79 | extern int mu_guile_load (char *filename, int argc, char **argv); | ... | ... |
... | @@ -26,8 +26,8 @@ EXTRA_LTLIBRARIES=libmu_scm.la | ... | @@ -26,8 +26,8 @@ EXTRA_LTLIBRARIES=libmu_scm.la |
26 | C_SRCS=\ | 26 | C_SRCS=\ |
27 | mu_address.c\ | 27 | mu_address.c\ |
28 | mu_body.c\ | 28 | mu_body.c\ |
29 | mu_dbgport.c\ | ||
29 | mu_guile.c\ | 30 | mu_guile.c\ |
30 | mu_guimb.c\ | ||
31 | mu_mailbox.c\ | 31 | mu_mailbox.c\ |
32 | mu_message.c\ | 32 | mu_message.c\ |
33 | mu_mime.c\ | 33 | mu_mime.c\ |
... | @@ -61,7 +61,6 @@ site_DATA=@GUILE_SITE_DATA@ | ... | @@ -61,7 +61,6 @@ site_DATA=@GUILE_SITE_DATA@ |
61 | DOT_X_FILES=\ | 61 | DOT_X_FILES=\ |
62 | mu_address.x\ | 62 | mu_address.x\ |
63 | mu_body.x\ | 63 | mu_body.x\ |
64 | mu_guimb.x\ | ||
65 | mu_mailbox.x\ | 64 | mu_mailbox.x\ |
66 | mu_message.x\ | 65 | mu_message.x\ |
67 | mu_mime.x\ | 66 | mu_mime.x\ |
... | @@ -73,7 +72,6 @@ DOT_X_FILES=\ | ... | @@ -73,7 +72,6 @@ DOT_X_FILES=\ |
73 | DOT_DOC_FILES=\ | 72 | DOT_DOC_FILES=\ |
74 | mu_address.doc\ | 73 | mu_address.doc\ |
75 | mu_body.doc\ | 74 | mu_body.doc\ |
76 | mu_guimb.doc\ | ||
77 | mu_mailbox.doc\ | 75 | mu_mailbox.doc\ |
78 | mu_message.doc\ | 76 | mu_message.doc\ |
79 | mu_mime.doc\ | 77 | mu_mime.doc\ | ... | ... |
libmu_scm/mu_dbgport.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #include "mu_scm.h" | ||
20 | |||
21 | struct _mu_debug_port | ||
22 | { | ||
23 | mu_debug_t debug; | ||
24 | mu_log_level_t level; | ||
25 | }; | ||
26 | |||
27 | static long scm_tc16_mu_debug_port; | ||
28 | |||
29 | SCM | ||
30 | mu_scm_make_debug_port (mu_debug_t debug, mu_log_level_t level) | ||
31 | { | ||
32 | struct _mu_debug_port *dp; | ||
33 | SCM port; | ||
34 | scm_port *pt; | ||
35 | |||
36 | dp = scm_gc_malloc (sizeof (struct _mu_debug_port), "mu-debug-port"); | ||
37 | dp->debug = debug; | ||
38 | dp->level = level; | ||
39 | port = scm_cell (scm_tc16_mu_debug_port, 0); | ||
40 | pt = scm_add_to_port_table (port); | ||
41 | SCM_SETPTAB_ENTRY (port, pt); | ||
42 | pt->rw_random = 0; | ||
43 | SCM_SET_CELL_TYPE (port, | ||
44 | (scm_tc16_mu_debug_port | SCM_OPN | SCM_WRTNG | | ||
45 | SCM_BUF0)); | ||
46 | SCM_SETSTREAM (port, dp); | ||
47 | return port; | ||
48 | } | ||
49 | |||
50 | #define MU_DEBUG_PORT(x) ((struct _mu_debug_port *) SCM_STREAM (x)) | ||
51 | |||
52 | static SCM | ||
53 | _mu_debug_port_mark (SCM port) | ||
54 | { | ||
55 | return SCM_BOOL_F; | ||
56 | } | ||
57 | |||
58 | static void | ||
59 | _mu_debug_port_flush (SCM port) | ||
60 | { | ||
61 | struct _mu_debug_port *dp = MU_DEBUG_PORT (port); | ||
62 | |||
63 | /* FIXME: */ | ||
64 | } | ||
65 | |||
66 | static int | ||
67 | _mu_debug_port_close (SCM port) | ||
68 | { | ||
69 | struct _mu_debug_port *dp = MU_DEBUG_PORT (port); | ||
70 | |||
71 | if (dp) | ||
72 | { | ||
73 | _mu_debug_port_flush (port); | ||
74 | SCM_SETSTREAM (port, NULL); | ||
75 | scm_gc_free (dp, sizeof (struct _mu_debug_port), "mu-debug-port"); | ||
76 | } | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static scm_sizet | ||
81 | _mu_debug_port_free (SCM port) | ||
82 | { | ||
83 | _mu_debug_port_close (port); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | static int | ||
88 | _mu_debug_port_fill_input (SCM port) | ||
89 | { | ||
90 | return EOF; | ||
91 | } | ||
92 | |||
93 | static void | ||
94 | _mu_debug_port_write (SCM port, const void *data, size_t size) | ||
95 | { | ||
96 | struct _mu_debug_port *dp = MU_DEBUG_PORT (port); | ||
97 | |||
98 | mu_debug_printf (dp->debug, dp->level, "%.*s", size, (const char *)data); | ||
99 | } | ||
100 | |||
101 | static int | ||
102 | _mu_debug_port_print (SCM exp, SCM port, scm_print_state * pstate) | ||
103 | { | ||
104 | scm_puts ("#<Mailutis debug port>", port); | ||
105 | return 1; | ||
106 | } | ||
107 | |||
108 | void | ||
109 | mu_scm_debug_port_init () | ||
110 | { | ||
111 | scm_tc16_mu_debug_port = scm_make_port_type ("mu-debug-port", | ||
112 | _mu_debug_port_fill_input, | ||
113 | _mu_debug_port_write); | ||
114 | scm_set_port_mark (scm_tc16_mu_debug_port, _mu_debug_port_mark); | ||
115 | scm_set_port_free (scm_tc16_mu_debug_port, _mu_debug_port_free); | ||
116 | scm_set_port_print (scm_tc16_mu_debug_port, _mu_debug_port_print); | ||
117 | scm_set_port_flush (scm_tc16_mu_debug_port, _mu_debug_port_flush); | ||
118 | scm_set_port_close (scm_tc16_mu_debug_port, _mu_debug_port_close); | ||
119 | } |
libmu_scm/mu_guimb.c
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001, 2007 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, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301 USA */ | ||
18 | |||
19 | #include "mu_scm.h" | ||
20 | |||
21 | static void _scheme_main (void *closure, int argc, char **argv); | ||
22 | |||
23 | void | ||
24 | mu_process_mailbox (int argc, char *argv[], mu_guimb_param_t *param) | ||
25 | { | ||
26 | scm_boot_guile (argc, argv, _scheme_main, param); | ||
27 | } | ||
28 | |||
29 | SCM _current_mailbox; | ||
30 | SCM _user_name; | ||
31 | |||
32 | static SCM | ||
33 | catch_body (void *closure) | ||
34 | { | ||
35 | mu_guimb_param_t *param = closure; | ||
36 | return param->catch_body (param->data, param->mbox); | ||
37 | } | ||
38 | |||
39 | void | ||
40 | _scheme_main (void *closure, int argc, char **argv) | ||
41 | { | ||
42 | mu_guimb_param_t *param = closure; | ||
43 | |||
44 | if (param->debug_guile) | ||
45 | { | ||
46 | SCM_DEVAL_P = 1; | ||
47 | SCM_BACKTRACE_P = 1; | ||
48 | SCM_RECORD_POSITIONS_P = 1; | ||
49 | SCM_RESET_DEBUG_MODE; | ||
50 | } | ||
51 | |||
52 | /* Initialize scheme library */ | ||
53 | mu_scm_init (); | ||
54 | |||
55 | /* Provide basic primitives */ | ||
56 | #include <mu_guimb.x> | ||
57 | |||
58 | _current_mailbox = mu_scm_mailbox_create (param->mbox); | ||
59 | mu_set_variable ("current-mailbox", _current_mailbox); | ||
60 | |||
61 | _user_name = param->user_name ? | ||
62 | scm_makfrom0str (param->user_name) : SCM_BOOL_F; | ||
63 | mu_set_variable ("user-name", _user_name); | ||
64 | |||
65 | if (param->init) | ||
66 | param->init (param->data); | ||
67 | |||
68 | do { | ||
69 | scm_internal_lazy_catch (SCM_BOOL_T, | ||
70 | catch_body, closure, | ||
71 | param->catch_handler, param->data); | ||
72 | } while (param->next && param->next (param->data, param->mbox)); | ||
73 | |||
74 | if (param->exit) | ||
75 | exit (param->exit (param->data, param->mbox)); | ||
76 | |||
77 | exit (0); | ||
78 | } |
... | @@ -217,6 +217,8 @@ mu_scm_init () | ... | @@ -217,6 +217,8 @@ mu_scm_init () |
217 | mu_scm_logger_init (); | 217 | mu_scm_logger_init (); |
218 | mu_scm_port_init (); | 218 | mu_scm_port_init (); |
219 | mu_scm_mime_init (); | 219 | mu_scm_mime_init (); |
220 | mu_scm_debug_port_init (); | ||
221 | |||
220 | #include "mu_scm.x" | 222 | #include "mu_scm.x" |
221 | 223 | ||
222 | mu_registrar_record (MU_DEFAULT_RECORD); | 224 | mu_registrar_record (MU_DEFAULT_RECORD); | ... | ... |
... | @@ -32,6 +32,17 @@ scheme_check_msg (mu_message_t msg, struct mu_auth_data *auth, | ... | @@ -32,6 +32,17 @@ scheme_check_msg (mu_message_t msg, struct mu_auth_data *auth, |
32 | if (!initialized) | 32 | if (!initialized) |
33 | { | 33 | { |
34 | mu_guile_init (debug_guile); | 34 | mu_guile_init (debug_guile); |
35 | if (!log_to_stderr) | ||
36 | { | ||
37 | mu_debug_t debug; | ||
38 | SCM port; | ||
39 | |||
40 | mu_diag_get_debug (&debug); | ||
41 | port = mu_scm_make_debug_port (debug, MU_DIAG_ERROR); | ||
42 | scm_set_current_error_port(port); | ||
43 | port = mu_scm_make_debug_port (debug, MU_DIAG_INFO); | ||
44 | scm_set_current_output_port(port); | ||
45 | } | ||
35 | initialized = 1; | 46 | initialized = 1; |
36 | } | 47 | } |
37 | mu_guile_load (prog, 0, NULL); | 48 | mu_guile_load (prog, 0, NULL); | ... | ... |
... | @@ -819,10 +819,10 @@ mu_unroll_symlink (char *out, size_t outsz, const char *in) | ... | @@ -819,10 +819,10 @@ mu_unroll_symlink (char *out, size_t outsz, const char *in) |
819 | char * | 819 | char * |
820 | mu_expand_path_pattern (const char *pattern, const char *username) | 820 | mu_expand_path_pattern (const char *pattern, const char *username) |
821 | { | 821 | { |
822 | const char *p, *startp; | 822 | const char *p; |
823 | char *q; | 823 | char *q; |
824 | char *path; | 824 | char *path; |
825 | int len = 0; | 825 | size_t len = 0; |
826 | struct mu_auth_data *auth = NULL; | 826 | struct mu_auth_data *auth = NULL; |
827 | 827 | ||
828 | for (p = pattern; *p; p++) | 828 | for (p = pattern; *p; p++) |
... | @@ -869,12 +869,21 @@ mu_expand_path_pattern (const char *pattern, const char *username) | ... | @@ -869,12 +869,21 @@ mu_expand_path_pattern (const char *pattern, const char *username) |
869 | if (!path) | 869 | if (!path) |
870 | return NULL; | 870 | return NULL; |
871 | 871 | ||
872 | startp = pattern; | 872 | p = pattern; |
873 | q = path; | 873 | q = path; |
874 | while (*startp && (p = strchr (startp, '%')) != NULL) | 874 | while (*p) |
875 | { | 875 | { |
876 | memcpy (q, startp, p - startp); | 876 | size_t off = strcspn (p, "~%"); |
877 | q += p - startp; | 877 | memcpy (q, p, off); |
878 | q += off; | ||
879 | p += off; | ||
880 | if (*p == '~') | ||
881 | { | ||
882 | strcpy (q, auth->dir); | ||
883 | q += strlen (auth->dir); | ||
884 | p++; | ||
885 | } | ||
886 | else if (*p) | ||
878 | switch (*++p) | 887 | switch (*++p) |
879 | { | 888 | { |
880 | case 'u': | 889 | case 'u': |
... | @@ -895,13 +904,8 @@ mu_expand_path_pattern (const char *pattern, const char *username) | ... | @@ -895,13 +904,8 @@ mu_expand_path_pattern (const char *pattern, const char *username) |
895 | *q++ = '%'; | 904 | *q++ = '%'; |
896 | *q++ = *p; | 905 | *q++ = *p; |
897 | } | 906 | } |
898 | startp = p + 1; | ||
899 | } | ||
900 | if (*startp) | ||
901 | { | ||
902 | strcpy (q, startp); | ||
903 | q += strlen (startp); | ||
904 | } | 907 | } |
908 | |||
905 | *q = 0; | 909 | *q = 0; |
906 | if (auth) | 910 | if (auth) |
907 | mu_auth_data_free (auth); | 911 | mu_auth_data_free (auth); | ... | ... |
-
Please register or sign in to post a comment