Commit 88260300 88260300b2288f9a2515bbf94339a949fea2c425 by Sergey Poznyakoff

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 ~.
1 parent 40fffffb
......@@ -71,7 +71,9 @@ extern void mu_scm_message_add_owner (SCM MESG, SCM owner);
extern void mu_scm_mutil_init (void);
extern void mu_process_mailbox (int argc, char *argv[], mu_guimb_param_t *param);
SCM mu_scm_make_debug_port (mu_debug_t debug, mu_log_level_t level);
void mu_scm_debug_port_init (void);
extern void mu_guile_init (int debug);
extern int mu_guile_load (char *filename, int argc, char **argv);
......
......@@ -26,8 +26,8 @@ EXTRA_LTLIBRARIES=libmu_scm.la
C_SRCS=\
mu_address.c\
mu_body.c\
mu_dbgport.c\
mu_guile.c\
mu_guimb.c\
mu_mailbox.c\
mu_message.c\
mu_mime.c\
......@@ -61,7 +61,6 @@ site_DATA=@GUILE_SITE_DATA@
DOT_X_FILES=\
mu_address.x\
mu_body.x\
mu_guimb.x\
mu_mailbox.x\
mu_message.x\
mu_mime.x\
......@@ -73,7 +72,6 @@ DOT_X_FILES=\
DOT_DOC_FILES=\
mu_address.doc\
mu_body.doc\
mu_guimb.doc\
mu_mailbox.doc\
mu_message.doc\
mu_mime.doc\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#include "mu_scm.h"
struct _mu_debug_port
{
mu_debug_t debug;
mu_log_level_t level;
};
static long scm_tc16_mu_debug_port;
SCM
mu_scm_make_debug_port (mu_debug_t debug, mu_log_level_t level)
{
struct _mu_debug_port *dp;
SCM port;
scm_port *pt;
dp = scm_gc_malloc (sizeof (struct _mu_debug_port), "mu-debug-port");
dp->debug = debug;
dp->level = level;
port = scm_cell (scm_tc16_mu_debug_port, 0);
pt = scm_add_to_port_table (port);
SCM_SETPTAB_ENTRY (port, pt);
pt->rw_random = 0;
SCM_SET_CELL_TYPE (port,
(scm_tc16_mu_debug_port | SCM_OPN | SCM_WRTNG |
SCM_BUF0));
SCM_SETSTREAM (port, dp);
return port;
}
#define MU_DEBUG_PORT(x) ((struct _mu_debug_port *) SCM_STREAM (x))
static SCM
_mu_debug_port_mark (SCM port)
{
return SCM_BOOL_F;
}
static void
_mu_debug_port_flush (SCM port)
{
struct _mu_debug_port *dp = MU_DEBUG_PORT (port);
/* FIXME: */
}
static int
_mu_debug_port_close (SCM port)
{
struct _mu_debug_port *dp = MU_DEBUG_PORT (port);
if (dp)
{
_mu_debug_port_flush (port);
SCM_SETSTREAM (port, NULL);
scm_gc_free (dp, sizeof (struct _mu_debug_port), "mu-debug-port");
}
return 0;
}
static scm_sizet
_mu_debug_port_free (SCM port)
{
_mu_debug_port_close (port);
return 0;
}
static int
_mu_debug_port_fill_input (SCM port)
{
return EOF;
}
static void
_mu_debug_port_write (SCM port, const void *data, size_t size)
{
struct _mu_debug_port *dp = MU_DEBUG_PORT (port);
mu_debug_printf (dp->debug, dp->level, "%.*s", size, (const char *)data);
}
static int
_mu_debug_port_print (SCM exp, SCM port, scm_print_state * pstate)
{
scm_puts ("#<Mailutis debug port>", port);
return 1;
}
void
mu_scm_debug_port_init ()
{
scm_tc16_mu_debug_port = scm_make_port_type ("mu-debug-port",
_mu_debug_port_fill_input,
_mu_debug_port_write);
scm_set_port_mark (scm_tc16_mu_debug_port, _mu_debug_port_mark);
scm_set_port_free (scm_tc16_mu_debug_port, _mu_debug_port_free);
scm_set_port_print (scm_tc16_mu_debug_port, _mu_debug_port_print);
scm_set_port_flush (scm_tc16_mu_debug_port, _mu_debug_port_flush);
scm_set_port_close (scm_tc16_mu_debug_port, _mu_debug_port_close);
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#include "mu_scm.h"
static void _scheme_main (void *closure, int argc, char **argv);
void
mu_process_mailbox (int argc, char *argv[], mu_guimb_param_t *param)
{
scm_boot_guile (argc, argv, _scheme_main, param);
}
SCM _current_mailbox;
SCM _user_name;
static SCM
catch_body (void *closure)
{
mu_guimb_param_t *param = closure;
return param->catch_body (param->data, param->mbox);
}
void
_scheme_main (void *closure, int argc, char **argv)
{
mu_guimb_param_t *param = closure;
if (param->debug_guile)
{
SCM_DEVAL_P = 1;
SCM_BACKTRACE_P = 1;
SCM_RECORD_POSITIONS_P = 1;
SCM_RESET_DEBUG_MODE;
}
/* Initialize scheme library */
mu_scm_init ();
/* Provide basic primitives */
#include <mu_guimb.x>
_current_mailbox = mu_scm_mailbox_create (param->mbox);
mu_set_variable ("current-mailbox", _current_mailbox);
_user_name = param->user_name ?
scm_makfrom0str (param->user_name) : SCM_BOOL_F;
mu_set_variable ("user-name", _user_name);
if (param->init)
param->init (param->data);
do {
scm_internal_lazy_catch (SCM_BOOL_T,
catch_body, closure,
param->catch_handler, param->data);
} while (param->next && param->next (param->data, param->mbox));
if (param->exit)
exit (param->exit (param->data, param->mbox));
exit (0);
}
......@@ -217,6 +217,8 @@ mu_scm_init ()
mu_scm_logger_init ();
mu_scm_port_init ();
mu_scm_mime_init ();
mu_scm_debug_port_init ();
#include "mu_scm.x"
mu_registrar_record (MU_DEFAULT_RECORD);
......
......@@ -32,6 +32,17 @@ scheme_check_msg (mu_message_t msg, struct mu_auth_data *auth,
if (!initialized)
{
mu_guile_init (debug_guile);
if (!log_to_stderr)
{
mu_debug_t debug;
SCM port;
mu_diag_get_debug (&debug);
port = mu_scm_make_debug_port (debug, MU_DIAG_ERROR);
scm_set_current_error_port(port);
port = mu_scm_make_debug_port (debug, MU_DIAG_INFO);
scm_set_current_output_port(port);
}
initialized = 1;
}
mu_guile_load (prog, 0, NULL);
......
......@@ -819,10 +819,10 @@ mu_unroll_symlink (char *out, size_t outsz, const char *in)
char *
mu_expand_path_pattern (const char *pattern, const char *username)
{
const char *p, *startp;
const char *p;
char *q;
char *path;
int len = 0;
size_t len = 0;
struct mu_auth_data *auth = NULL;
for (p = pattern; *p; p++)
......@@ -869,12 +869,21 @@ mu_expand_path_pattern (const char *pattern, const char *username)
if (!path)
return NULL;
startp = pattern;
p = pattern;
q = path;
while (*startp && (p = strchr (startp, '%')) != NULL)
while (*p)
{
memcpy (q, startp, p - startp);
q += p - startp;
size_t off = strcspn (p, "~%");
memcpy (q, p, off);
q += off;
p += off;
if (*p == '~')
{
strcpy (q, auth->dir);
q += strlen (auth->dir);
p++;
}
else if (*p)
switch (*++p)
{
case 'u':
......@@ -895,13 +904,8 @@ mu_expand_path_pattern (const char *pattern, const char *username)
*q++ = '%';
*q++ = *p;
}
startp = p + 1;
}
if (*startp)
{
strcpy (q, startp);
q += strlen (startp);
}
*q = 0;
if (auth)
mu_auth_data_free (auth);
......