[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] GNU Mailutils branch, master, updated. release-2.2-272-g9e253b3
From: |
Sergey Poznyakoff |
Subject: |
[SCM] GNU Mailutils branch, master, updated. release-2.2-272-g9e253b3 |
Date: |
Wed, 08 Dec 2010 10:41:58 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".
http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=9e253b395de6ea7839b7f2b04b1a28892af514e7
The branch, master has been updated
via 9e253b395de6ea7839b7f2b04b1a28892af514e7 (commit)
from 835ee6b03a098d8566e9b9ba2c22ab2403d41cba (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9e253b395de6ea7839b7f2b04b1a28892af514e7
Author: Sergey Poznyakoff <address@hidden>
Date: Wed Dec 8 12:38:21 2010 +0200
comsat: improve biffrc evaluation.
* comsat/.gitignore: Add biff.rc.h
* comsat/Makefile.am (comsatd_SOURCES, BUILT_SOURCES): Add biff.rc.h
(EXTRA_DIST): Add biffrc.sed and biff.rc
* comsat/action.c (default_action): Include biff.rc.h.
(biffrc_environ): New struct.
(eval_biffrc): New function.
(run_user_action): Rewrite via eval_biffrc. Default action is
evaluated if biff.rc cannot be opened, or it contains the "default"
keyword.
* comsat/tests/testsuite.at: Add "default" statement where necessary.
-----------------------------------------------------------------------
Summary of changes:
comsat/.gitignore | 1 +
comsat/Makefile.am | 9 +-
comsat/action.c | 277 +++++++++++++++----------
testsuite/testsuite.at => comsat/biff.rc | 15 +-
libmu_compat/Makefile.am => comsat/biffrc.sed | 22 ++-
comsat/tests/testsuite.at | 4 +
6 files changed, 201 insertions(+), 127 deletions(-)
copy testsuite/testsuite.at => comsat/biff.rc (80%)
copy libmu_compat/Makefile.am => comsat/biffrc.sed (71%)
diff --git a/comsat/.gitignore b/comsat/.gitignore
index 47a1551..cb7cddf 100644
--- a/comsat/.gitignore
+++ b/comsat/.gitignore
@@ -4,3 +4,4 @@ comsatd
.deps
.libs
.gdbinit
+biff.rc.h
diff --git a/comsat/Makefile.am b/comsat/Makefile.am
index af34b3a..abb1251 100644
--- a/comsat/Makefile.am
+++ b/comsat/Makefile.am
@@ -19,9 +19,16 @@ INCLUDES = @MU_APP_COMMON_INCLUDES@
SUBDIRS = . tests
sbin_PROGRAMS = comsatd
-comsatd_SOURCES = action.c comsat.c comsat.h
+comsatd_SOURCES = action.c comsat.c comsat.h biff.rc.h
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
+BUILT_SOURCES=biff.rc.h
+EXTRA_DIST=biffrc.sed biff.rc
+
+biff.rc.h: $(top_srcdir)/comsat/biff.rc
+ $(AM_V_GEN)sed -f $(top_srcdir)/comsat/biffrc.sed \
+ $(top_srcdir)/comsat/biff.rc > biff.rc.h
+
comsatd_LDADD = \
${MU_APP_LIBRARIES}\
${MU_LIB_MBOX}\
diff --git a/comsat/action.c b/comsat/action.c
index ab185c5..f064723 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -181,13 +181,8 @@ expand_line (const char *str, mu_message_t msg)
}
const char *default_action =
-"Mail to address@hidden"
-"---\n"
-"From: $H{from}\n"
-"Subject: $H{Subject}\n"
-"---\n"
-"$B(,5)\n"
-"---\n";
+#include "biff.rc.h"
+;
static void
action_beep (mu_stream_t tty)
@@ -439,126 +434,186 @@ open_default_tty (const char *device)
default_filters);
}
+struct biffrc_environ
+{
+ mu_stream_t tty;
+ mu_message_t msg;
+ mu_stream_t input;
+ struct mu_locus locus;
+ int use_default;
+};
+
+void
+eval_biffrc (struct biffrc_environ *env)
+{
+ char *stmt = NULL;
+ size_t size = 0;
+ size_t n;
+ struct mu_wordsplit ws;
+ int wsflags;
+
+ ws.ws_comment = "#";
+ wsflags = MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT;
+ while (mu_stream_getline (env->input, &stmt, &size, &n) == 0 && n > 0)
+ {
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_LOCUS, &env->locus);
+ if (mu_wordsplit (stmt, &ws, wsflags) == 0 && ws.ws_wordc)
+ {
+ if (strcmp (ws.ws_wordv[0], "beep") == 0)
+ {
+ /* FIXME: excess arguments are ignored */
+ action_beep (env->tty);
+ }
+ else
+ {
+ /* Rest of actions require keyword expansion */
+ int i;
+ int n_option = ws.ws_wordc > 1 &&
+ strcmp (ws.ws_wordv[1], "-n") == 0;
+
+ for (i = 1; i < ws.ws_wordc; i++)
+ {
+ char *oldarg = ws.ws_wordv[i];
+ ws.ws_wordv[i] = expand_line (ws.ws_wordv[i], env->msg);
+ free (oldarg);
+ if (!ws.ws_wordv[i])
+ break;
+ }
+
+ if (strcmp (ws.ws_wordv[0], "tty") == 0)
+ {
+ mu_stream_t ntty = open_tty (ws.ws_wordv[1],
+ ws.ws_wordc - 2,
+ ws.ws_wordv + 2);
+ if (!ntty)
+ {
+ mu_stream_printf (env->tty,
+ _("%s:%d: cannot open tty\n"),
+ env->locus.mu_file,
+ env->locus.mu_line);
+ break;
+ }
+ mu_stream_destroy (&env->tty);
+ env->tty = ntty;
+ }
+ else if (strcmp (ws.ws_wordv[0], "echo") == 0)
+ {
+ int argc = ws.ws_wordc - 1;
+ char **argv = ws.ws_wordv + 1;
+ if (n_option)
+ {
+ argc--;
+ argv++;
+ }
+ action_echo (env->tty, n_option, argc, argv);
+ }
+ else if (strcmp (ws.ws_wordv[0], "exec") == 0)
+ {
+ action_exec (env->tty, ws.ws_wordc - 1, ws.ws_wordv + 1);
+ }
+ else if (strcmp (ws.ws_wordv[0], "default") == 0)
+ {
+ env->use_default = 1;
+ }
+ else
+ {
+ mu_stream_printf (env->tty,
+ _("%s:%d: unknown keyword\n"),
+ env->locus.mu_file,
+ env->locus.mu_line);
+ mu_diag_output (MU_DIAG_ERROR, _("unknown keyword %s"),
+ ws.ws_wordv[0]);
+ break;
+ }
+ }
+ }
+ else
+ {
+ const char *diag = mu_wordsplit_strerror (&ws);
+ mu_stream_printf (env->tty,
+ _("%s:%d: %s\n"),
+ env->locus.mu_file,
+ env->locus.mu_line,
+ diag);
+ mu_diag_output (MU_DIAG_ERROR, "%s", diag);
+ }
+
+ wsflags |= MU_WRDSF_REUSE;
+ /* FIXME: line number is incorrect if .biffrc contains
+ escaped newlines */
+ env->locus.mu_line++;
+ }
+ free (stmt);
+ mu_wordsplit_free (&ws);
+}
+
+
void
run_user_action (const char *device, mu_message_t msg)
{
- mu_stream_t input;
- int nact = 0;
- mu_stream_t tty = open_default_tty (device);
+ mu_stream_t stream;
+ struct biffrc_environ env;
- if (!tty)
+ env.tty = open_default_tty (device);
+ if (!env.tty)
return;
- input = open_rc (biffrc, tty);
- if (input)
+ env.msg = msg;
+
+ env.input = open_rc (biffrc, env.tty);
+ if (env.input)
{
- char *stmt = NULL;
- size_t size = 0;
- size_t n;
char *cwd = mu_getcwd ();
char *rcname;
- struct mu_locus locus;
- struct mu_wordsplit ws;
- int wsflags;
-
rcname = mu_make_file_name (cwd, BIFF_RC);
free (cwd);
if (!rcname)
- {
+ {
mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
- locus.mu_file = BIFF_RC;
- }
+ env.locus.mu_file = BIFF_RC;
+ }
else
- locus.mu_file = rcname;
-
- locus.mu_line = 1;
- locus.mu_col = 0;
+ env.locus.mu_file = rcname;
+
+ env.locus.mu_line = 1;
+ env.locus.mu_col = 0;
+ env.use_default = 0;
+ eval_biffrc (&env);
+ mu_stream_destroy (&env.input);
+ free (rcname);
+ }
+ else
+ env.use_default = 1;
- ws.ws_comment = "#";
- wsflags = MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT;
- while (mu_stream_getline (input, &stmt, &size, &n) == 0 && n > 0)
+ if (env.use_default &&
+ mu_static_memory_stream_create (&stream, default_action,
+ strlen (default_action)) == 0)
+ {
+ int rc = mu_filter_create (&env.input, stream, "LINECON",
+ MU_FILTER_DECODE,
+ MU_STREAM_READ);
+ mu_stream_unref (stream);
+ if (rc)
{
- if (mu_wordsplit (stmt, &ws, wsflags) == 0 && ws.ws_wordc)
- {
- mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS, &locus);
- if (strcmp (ws.ws_wordv[0], "beep") == 0)
- {
- /* FIXME: excess arguments are ignored */
- action_beep (tty);
- nact++;
- }
- else
- {
- /* Rest of actions require keyword expansion */
- int i;
- int n_option = ws.ws_wordc > 1 &&
- strcmp (ws.ws_wordv[1], "-n") == 0;
-
- for (i = 1; i < ws.ws_wordc; i++)
- {
- char *oldarg = ws.ws_wordv[i];
- ws.ws_wordv[i] = expand_line (ws.ws_wordv[i], msg);
- free (oldarg);
- if (!ws.ws_wordv[i])
- break;
- }
-
- if (strcmp (ws.ws_wordv[0], "tty") == 0)
- {
- mu_stream_t ntty = open_tty (ws.ws_wordv[1],
- ws.ws_wordc - 2,
- ws.ws_wordv + 2);
- if (!ntty)
- {
- mu_stream_printf (tty,
- _(".biffrc:%d: cannot open tty\n"),
- locus.mu_line);
- break;
- }
- mu_stream_destroy (&tty);
- tty = ntty;
- }
- else if (strcmp (ws.ws_wordv[0], "echo") == 0)
- {
- int argc = ws.ws_wordc - 1;
- char **argv = ws.ws_wordv + 1;
- if (n_option)
- {
- argc--;
- argv++;
- }
- action_echo (tty, n_option, argc, argv);
- nact++;
- }
- else if (strcmp (ws.ws_wordv[0], "exec") == 0)
- {
- action_exec (tty, ws.ws_wordc - 1, ws.ws_wordv + 1);
- nact++;
- }
- else
- {
- mu_stream_printf (tty,
- _(".biffrc:%d: unknown keyword\n"),
- locus.mu_line);
- mu_diag_output (MU_DIAG_ERROR, _("unknown keyword %s"),
- ws.ws_wordv[0]);
- break;
- }
- }
- }
- wsflags |= MU_WRDSF_REUSE;
- /* FIXME: line number is incorrect if .biffrc contains
- escaped newlines */
- locus.mu_line++;
+ mu_stream_printf (env.tty,
+ _("Cannot create filter for the default action:
%s\n"),
+ mu_strerror (rc));
+ mu_diag_output (MU_DIAG_NOTICE,
+ _("cannot create default filter for %s: %s"),
+ username, mu_strerror (rc));
+ }
+ else
+ {
+ env.locus.mu_file = "<default>";
+ env.locus.mu_line = 1;
+ env.locus.mu_col = 0;
+ eval_biffrc (&env);
+ mu_stream_destroy (&env.input);
}
- mu_wordsplit_free (&ws);
- mu_stream_destroy (&input);
- mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
- MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
- free (rcname);
}
+
+ mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
- if (nact == 0)
- echo_string (tty, expand_line (default_action, msg));
- mu_stream_destroy (&tty);
+ mu_stream_destroy (&env.tty);
}
diff --git a/testsuite/testsuite.at b/comsat/biff.rc
similarity index 80%
copy from testsuite/testsuite.at
copy to comsat/biff.rc
index 63553e7..e500b95 100644
--- a/testsuite/testsuite.at
+++ b/comsat/biff.rc
@@ -1,4 +1,4 @@
-# This file is part of GNU Mailutils. -*- Autotest -*-
+# The default biffrc file for GNU Mailutils comsatd utility.
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
@@ -14,10 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
-m4_include([testsuite.inc])
-
-AT_INIT
-
-m4_include([mime.at])
-m4_include([mbdel.at])
-m4_include([ufms.at])
+echo "Mail to address@hidden
+From: $H{from}\n\
+Subject: $H{Subject}\n\
+---\n\
+$B(,5)\n\
+---"
diff --git a/libmu_compat/Makefile.am b/comsat/biffrc.sed
similarity index 71%
copy from libmu_compat/Makefile.am
copy to comsat/biffrc.sed
index c555908..7be2295 100644
--- a/libmu_compat/Makefile.am
+++ b/comsat/biffrc.sed
@@ -1,4 +1,4 @@
-# This file is part of GNU Mailutils
+# This file is part of GNU Mailutils.
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
@@ -14,12 +14,20 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
-SUBDIRS = . tests
-lib_LTLIBRARIES = libmu_compat.la
+# Provide leading quote
+1i\
+"\\
-libmu_compat_la_SOURCES = \
- argcv.c\
- vartab.c
+# Provide trailing quote
+$a\
+"
-INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
+# Remove empty lines and comments
+/ *#/d
+/^ *$/d
+# Escape quotes and backslashes
+s/["\]/\\&/g
+# Add newline and continuation character at the end of each line
+s/$/\\n\\/
+# End
diff --git a/comsat/tests/testsuite.at b/comsat/tests/testsuite.at
index 6da4a42..f852383 100644
--- a/comsat/tests/testsuite.at
+++ b/comsat/tests/testsuite.at
@@ -46,6 +46,7 @@ BIFFTEST([default commands],[comsatd00],
MUT_MBCOPY($abs_top_srcdir/testsuite/spool/teaparty.mbox, mailbox)
cat > biff.rc <<EOT
tty $cwd/output
+default
EOT
chmod 600 biff.rc
> $cwd/output
@@ -69,6 +70,7 @@ BIFFTEST([non-zero qid],[comsatd01],
MUT_MBCOPY($abs_top_srcdir/testsuite/spool/teaparty.mbox, mailbox)
cat > biff.rc <<EOT
tty $cwd/output
+default
EOT
chmod 600 biff.rc
> $cwd/output
@@ -93,6 +95,7 @@ BIFFTEST([maildir qid],[comsatd02],
MUT_MBCOPY($abs_top_srcdir/testsuite/maildir/teaparty, mailbox)
cat > biff.rc <<EOT
tty $cwd/output
+default
EOT
chmod 600 biff.rc
> $cwd/output
@@ -116,6 +119,7 @@ BIFFTEST([MH qid],[comsatd03],
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty, mailbox)
cat > biff.rc <<EOT
tty $cwd/output
+default
EOT
chmod 600 biff.rc
> $cwd/output
hooks/post-receive
--
GNU Mailutils
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] GNU Mailutils branch, master, updated. release-2.2-272-g9e253b3,
Sergey Poznyakoff <=