Commit 8f8d9036 8f8d9036cc943e4884b21ad050a1d443e102e47e by Sergey Poznyakoff

Implement filter chains. Revamp filter output length support.

* include/mailutils/filter.h (mu_filter_chain_create_pred)
(mu_filter_chain_create): New prototypes.
(_mu_filter_record)<max_line_length>: Remove.
* libmailutils/filter/fltchain.c: New file.
* libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Add fltchain.c.
* libmailutils/filter/base64.c: Implement line length limit for encoder.
(base64_state): New enum.
(base64_line): New struct.
(_base64_encoder): xd brings a pointer to struct base64_line. Use it
to limit the output line length.
(alloc_state): New function.
(_base64_filter): Register alloc_state.
(_base64_filter, _B_filter): Remove max_line_length initialization.

* libmailutils/filter/binflt.c: Remove max_line_length initialization.
* libmailutils/filter/crlfflt.c: Likewise.
* libmailutils/filter/dot.c: Likewise.
* libmailutils/filter/fromflt.c: Likewise.
* libmailutils/filter/header.c: Likewise.
* libmailutils/filter/inline-comment.c: Likewise.
* libmailutils/filter/linecon.c: Likewise.
* libmailutils/filter/qpflt.c: Likewise.

* libmailutils/filter/linelenflt.c: Redo line filter as a regular filter.
(mu_linelen_filter): New global.

* libmailutils/filter/filter.c (mu_filter_get_list): Register mu_linelen_filter.
(filter_create_rd, filter_create_wr): Remove.
(mu_filter_create_args): Use mu_filter_stream_create directly.

* examples/base64.c: Re-implement the -l option via filter chains.

* libmailutils/tests/fltst.c: Remove the linelen option.
* libmailutils/tests/base64d.at: Remove the linelen option from fltst
invocations.
* mu/filter.c: Remove the --line-length option.  Not needed now, its
effect is achieved by "FLT + [~]linelen" chain.
1 parent aa1caef5
......@@ -93,23 +93,6 @@ c_copy (mu_stream_t out, mu_stream_t in)
}
}
/* Set the maximum line length for the filter NAME to LENGTH.
FIXME: This is a kludge. Perhaps API should provide a function
for that. */
static void
reset_line_length (const char *name, size_t length)
{
mu_list_t list;
int status;
mu_filter_record_t frec;
mu_filter_get_list (&list);
status = mu_list_locate (list, (void*)name, (void**)&frec);
if (status == 0)
frec->max_line_length = length;
/* don't bail out, leave that to mu_filter_create */
}
int
main (int argc, char * argv [])
{
......@@ -120,8 +103,9 @@ main (int argc, char * argv [])
char *input = NULL, *output = NULL;
char *encoding = "base64";
mu_off_t shift = 0;
size_t line_length;
int line_length_option = 0;
char *line_length_option = NULL;
char *fargv[5];
size_t fargc = 0;
while ((c = getopt (argc, argv, "deE:hi:l:o:ps:vw")) != EOF)
switch (c)
......@@ -147,8 +131,7 @@ main (int argc, char * argv [])
break;
case 'l':
line_length = strtoul (optarg, NULL, 10);
line_length_option = 1;
line_length_option = optarg;
break;
case 'p':
......@@ -186,22 +169,33 @@ main (int argc, char * argv [])
else
MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
if (line_length_option)
reset_line_length (encoding, line_length);
fargv[fargc++] = encoding;
if (line_length_option && strcmp (line_length_option, "0"))
{
if (mu_c_strcasecmp (encoding, "base64") == 0)
fargv[0] = "B"; /* B encoding has no length limit */
fargv[fargc++] = "+";
fargv[fargc++] = (mode == MU_FILTER_DECODE) ? "~linelen" : "linelen";
fargv[fargc++] = line_length_option;
}
fargv[fargc] = NULL;
if (flags == MU_STREAM_READ)
{
MU_ASSERT (mu_filter_create (&flt, in, encoding, mode,
MU_STREAM_READ|MU_STREAM_SEEK|
MU_STREAM_AUTOCLOSE));
MU_ASSERT (mu_filter_chain_create (&flt, in, mode,
MU_STREAM_READ|MU_STREAM_SEEK,
fargc, fargv));
mu_stream_unref (in);
if (shift)
MU_ASSERT (mu_stream_seek (flt, shift, MU_SEEK_SET, NULL));
c_copy (out, flt);
}
else
{
MU_ASSERT (mu_filter_create (&flt, out, encoding, mode,
MU_STREAM_WRITE|MU_STREAM_AUTOCLOSE));
MU_ASSERT (mu_filter_chain_create (&flt, out, mode,
MU_STREAM_WRITE,
fargc, fargv));
mu_stream_unref (out);
if (shift)
MU_ASSERT (mu_stream_seek (in, shift, MU_SEEK_SET, NULL));
c_copy (flt, in);
......
......@@ -81,11 +81,19 @@ int mu_filter_stream_create (mu_stream_t *pflt,
void *xdata,
int flags);
int mu_filter_chain_create_pred (mu_stream_t *pret, mu_stream_t transport,
int defmode, int flags,
size_t argc, char **argv,
int (*pred) (void *, mu_stream_t,
const char *),
void *closure);
int mu_filter_chain_create (mu_stream_t *pret, mu_stream_t transport,
int defmode, int flags,
size_t argc, char **argv);
struct _mu_filter_record
{
const char *name;
size_t max_line_length;
mu_filter_new_data_t newdata;
mu_filter_xcode_t encoder;
mu_filter_xcode_t decoder;
......@@ -111,6 +119,7 @@ extern mu_filter_record_t mu_from_filter;
extern mu_filter_record_t mu_inline_comment_filter;
extern mu_filter_record_t mu_header_filter;
extern mu_filter_record_t mu_linecon_filter;
extern mu_filter_record_t mu_linelen_filter;
enum mu_iconv_fallback_mode
{
......
......@@ -26,6 +26,7 @@ libfilter_la_SOURCES =\
dot.c\
filter.c\
filter_iconv.c\
fltchain.c\
fromflt.c\
header.c\
inline-comment.c\
......
......@@ -175,25 +175,54 @@ _base64_decoder (void *xd MU_ARG_UNUSED,
return mu_filter_ok;
}
enum base64_state
{
base64_init,
base64_newline,
base64_rollback
};
struct base64_line
{
enum base64_state state;
size_t max_len;
size_t cur_len;
char save[3];
int idx;
};
static enum mu_filter_result
_base64_encoder (void *xd MU_ARG_UNUSED,
_base64_encoder (void *xd,
enum mu_filter_command cmd,
struct mu_filter_io *iobuf)
{
struct base64_line bline, *lp = xd;
size_t consumed = 0;
int pad = 0;
const unsigned char *ptr = (const unsigned char*) iobuf->input;
const unsigned char *ptr;
size_t nbytes = 0;
size_t isize;
char *optr;
size_t osize;
enum mu_filter_result res;
if (!lp)
{
lp = &bline;
lp->max_len = 0;
lp->state = base64_init;
}
switch (cmd)
{
case mu_filter_init:
lp->state = base64_init;
lp->cur_len = 0;
lp->idx = 3;
return mu_filter_ok;
case mu_filter_done:
return mu_filter_ok;
default:
break;
}
......@@ -214,15 +243,48 @@ _base64_encoder (void *xd MU_ARG_UNUSED,
return mu_filter_moreoutput;
}
ptr = (const unsigned char*) iobuf->input;
isize = iobuf->isize;
optr = iobuf->output;
osize = iobuf->osize;
while ((consumed + 3 <= isize && nbytes + 4 <= osize) || pad)
while (nbytes < osize)
{
unsigned char c1 = 0, c2 = 0, x = '=', y = '=';
if (lp->max_len && lp->cur_len == lp->max_len)
{
if (lp->state == base64_init)
lp->idx = 3;
lp->state = base64_newline;
}
switch (lp->state)
{
case base64_init:
break;
case base64_newline:
*optr++ = '\n';
nbytes++;
lp->cur_len = 0;
lp->state = base64_rollback;
/* Fall through */
case base64_rollback:
if (lp->idx < 3)
{
*optr++ = lp->save[lp->idx++];
nbytes++;
lp->cur_len++;
continue;
}
lp->state = base64_init;
}
if (!(consumed + 3 <= isize || pad))
break;
*optr++ = b64tab[ptr[0] >> 2];
nbytes++;
lp->cur_len++;
consumed++;
switch (isize - consumed)
{
......@@ -235,20 +297,22 @@ _base64_encoder (void *xd MU_ARG_UNUSED,
x = b64tab[((ptr[1] << 2) + c2) & 0x3f];
c1 = (ptr[1] >> 4);
case 0:
*optr++ = b64tab[((ptr[0] << 4) + c1) & 0x3f];
*optr++ = x;
*optr++ = y;
lp->save[0] = b64tab[((ptr[0] << 4) + c1) & 0x3f];
lp->save[1] = x;
lp->save[2] = y;
lp->idx = 0;
lp->state = base64_rollback;
}
ptr += 3;
nbytes += 4;
pad = 0;
}
/* Consumed may grow bigger than isize if cmd is mu_filter_lastbuf */
if (consumed > iobuf->isize)
consumed = iobuf->isize;
if (cmd == mu_filter_lastbuf && consumed < iobuf->isize)
if (cmd == mu_filter_lastbuf &&
(consumed < iobuf->isize || lp->state == base64_rollback))
res = mu_filter_again;
else
res = mu_filter_ok;
......@@ -257,10 +321,25 @@ _base64_encoder (void *xd MU_ARG_UNUSED,
return res;
}
static int
alloc_state (void **pret, int mode, int argc, const char **argv)
{
if (mode == MU_FILTER_ENCODE)
{
struct base64_line *lp = malloc (sizeof (*lp));
if (!lp)
return ENOMEM;
lp->max_len = 76;
*pret = lp;
}
else
*pret = NULL;
return 0;
}
static struct _mu_filter_record _base64_filter = {
"base64",
76,
NULL,
alloc_state,
_base64_encoder,
_base64_decoder
};
......@@ -269,7 +348,6 @@ mu_filter_record_t mu_base64_filter = &_base64_filter;
static struct _mu_filter_record _B_filter = {
"B",
0,
NULL,
_base64_encoder,
_base64_decoder
......
......@@ -83,7 +83,6 @@ _bit7_coder (void *xd MU_ARG_UNUSED,
static struct _mu_filter_record _binary_filter = {
"binary",
0,
NULL,
_copy_codec,
_copy_codec
......@@ -94,7 +93,6 @@ mu_filter_record_t mu_binary_filter = &_binary_filter;
static struct _mu_filter_record _bit8_filter = {
"8bit",
0,
NULL,
_copy_codec,
_copy_codec
......@@ -104,7 +102,6 @@ mu_filter_record_t mu_bit8_filter = &_bit8_filter;
static struct _mu_filter_record _bit7_filter = {
"7bit",
0,
NULL,
_bit7_coder,
_copy_codec
......
......@@ -327,7 +327,6 @@ alloc_state (void **pret, int mode MU_ARG_UNUSED,
static struct _mu_filter_record _crlfdot_filter = {
"CRLFDOT",
0,
alloc_state,
_crlfdot_encoder,
_crlfdot_decoder
......
......@@ -160,7 +160,6 @@ alloc_state (void **pret, int mode,
static struct _mu_filter_record _crlf_filter = {
"CRLF",
0,
alloc_state,
_crlf_encoder,
_crlf_decoder
......@@ -172,7 +171,6 @@ mu_filter_record_t mu_crlf_filter = &_crlf_filter;
/* For compatibility with previous versions */
static struct _mu_filter_record _rfc822_filter = {
"RFC822",
0,
alloc_state,
_crlf_encoder,
_crlf_decoder
......
......@@ -259,7 +259,6 @@ alloc_state (void **pret, int mode MU_ARG_UNUSED,
static struct _mu_filter_record _dot_filter = {
"DOT",
0,
alloc_state,
_dot_encoder,
_dot_decoder
......
......@@ -81,6 +81,7 @@ mu_filter_get_list (mu_list_t *plist)
mu_list_append (filter_list, mu_inline_comment_filter);
mu_list_append (filter_list, mu_header_filter);
mu_list_append (filter_list, mu_linecon_filter);
mu_list_append (filter_list, mu_linelen_filter);
/* FIXME: add the default encodings? */
}
*plist = filter_list;
......@@ -88,77 +89,6 @@ mu_filter_get_list (mu_list_t *plist)
return 0;
}
static int
filter_create_rd (mu_stream_t *pstream, mu_stream_t stream,
size_t max_line_length,
int mode,
mu_filter_xcode_t xcode, void *xdata,
int flags)
{
int status;
mu_stream_t fltstream;
flags &= ~MU_STREAM_AUTOCLOSE;
status = mu_filter_stream_create (&fltstream, stream,
mode, xcode, xdata,
flags);
if (status == 0)
{
if (max_line_length)
{
status = mu_linelen_filter_create (pstream, fltstream,
max_line_length,
flags);
mu_stream_unref (fltstream);
if (status)
return status;
}
else
*pstream = fltstream;
if (flags & MU_STREAM_AUTOCLOSE)
mu_stream_unref (stream);
}
return status;
}
static int
filter_create_wr (mu_stream_t *pstream, mu_stream_t stream,
size_t max_line_length,
int mode,
mu_filter_xcode_t xcode, void *xdata,
int flags)
{
int status;
mu_stream_t fltstream, instream = NULL, tmpstr;
flags &= ~MU_STREAM_AUTOCLOSE;
if (max_line_length)
{
status = mu_linelen_filter_create (&instream, stream,
max_line_length,
flags);
if (status)
return status;
tmpstr = instream;
}
else
tmpstr = stream;
status = mu_filter_stream_create (&fltstream, tmpstr,
mode, xcode, xdata,
flags);
mu_stream_unref (instream);
if (status)
return status;
*pstream = fltstream;
if (flags & MU_STREAM_AUTOCLOSE)
mu_stream_unref (stream);
return status;
}
int
mu_filter_create_args (mu_stream_t *pstream, mu_stream_t stream,
const char *name, int argc, const char **argv,
......@@ -189,15 +119,12 @@ mu_filter_create_args (mu_stream_t *pstream, mu_stream_t stream,
return status;
}
status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd)
(pstream, stream,
mode == MU_FILTER_ENCODE ? frec->max_line_length : 0,
mode,
xcode,
xdata,
status = mu_filter_stream_create (pstream, stream,
mode, xcode, xdata,
flags);
if (status)
free (xdata);
return status;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2009, 2010 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, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <mailutils/filter.h>
#include <mailutils/stream.h>
#include <mailutils/errno.h>
static int
negate_filter_mode (int mode)
{
if (mode == MU_FILTER_DECODE)
return MU_FILTER_ENCODE;
else if (mode == MU_FILTER_ENCODE)
return MU_FILTER_DECODE;
abort ();
}
static int
_add_next_link (mu_stream_t *pret, mu_stream_t transport,
int defmode, int flags,
size_t argc, char **argv,
int (*pred) (void *, mu_stream_t, const char *),
void *closure)
{
int mode;
int qmark = 0;
char *fltname;
int status = 0;
fltname = argv[0];
if (fltname[0] == '?')
{
if (pred)
qmark = 1;
fltname++;
}
if (fltname[0] == '~')
{
mode = negate_filter_mode (defmode);
fltname++;
}
else
mode = defmode;
if (qmark == 0 || pred (closure, transport, fltname))
{
status = mu_filter_create_args (pret, transport, fltname,
argc, (const char **)argv,
mode, flags);
mu_stream_unref (transport);
}
return status;
}
int
_filter_chain_create (mu_stream_t *pret, mu_stream_t transport,
int defmode,
int flags,
size_t argc, char **argv,
int (*pred) (void *, mu_stream_t, const char *),
void *closure)
{
while (argc)
{
size_t i;
int status;
mu_stream_t stream;
for (i = 1; i < argc; i++)
if (strcmp (argv[i], "+") == 0)
break;
status = _add_next_link (&stream, transport,
defmode, flags,
i, argv,
pred, closure);
if (status)
return status;
transport = stream;
argc -= i;
argv += i;
if (argc)
{
argc--;
argv++;
}
}
*pret = transport;
return 0;
}
int
_filter_chain_create_rev (mu_stream_t *pret, mu_stream_t transport,
int defmode,
int flags,
size_t argc, char **argv,
int (*pred) (void *, mu_stream_t, const char *),
void *closure)
{
size_t pos;
for (pos = argc; pos > 0;)
{
size_t i;
int status;
mu_stream_t stream;
for (i = pos; i > 0; i--)
{
if (strcmp (argv[i - 1], "+") == 0)
break;
}
status = _add_next_link (&stream, transport,
defmode, flags,
pos - i, argv + i,
pred, closure);
if (status)
return status;
transport = stream;
if (i > 0)
i--;
pos = i;
}
*pret = transport;
return 0;
}
int
mu_filter_chain_create_pred (mu_stream_t *pret, mu_stream_t transport,
int defmode,
int flags,
size_t argc, char **argv,
int (*pred) (void *, mu_stream_t, const char *),
void *closure)
{
int rc;
mu_stream_ref (transport);
if (flags & MU_STREAM_WRITE)
rc = _filter_chain_create_rev (pret, transport,
defmode, flags,
argc, argv,
pred, closure);
else
rc = _filter_chain_create (pret, transport,
defmode, flags,
argc, argv, pred, closure);
if (rc)
mu_stream_unref (transport);
return rc;
}
int
mu_filter_chain_create (mu_stream_t *pret, mu_stream_t transport,
int defmode, int flags,
size_t argc, char **argv)
{
return mu_filter_chain_create_pred (pret, transport, defmode, flags,
argc, argv, NULL, NULL);
}
......@@ -273,7 +273,6 @@ _from_alloc_state (void **pret, int mode,
static struct _mu_filter_record _from_filter = {
"FROM",
0,
_from_alloc_state,
_from_encoder,
_from_decoder
......
......@@ -112,7 +112,6 @@ alloc_state (void **pret, int mode MU_ARG_UNUSED,
static struct _mu_filter_record _header_filter = {
"HEADER",
0,
alloc_state,
NULL,
_hflt_decoder
......
......@@ -487,7 +487,6 @@ alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
static struct _mu_filter_record _inline_comment_filter = {
"INLINE-COMMENT",
0,
alloc_state,
_ilcmt_encoder,
_ilcmt_decoder
......
......@@ -213,7 +213,6 @@ alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
static struct _mu_filter_record _linecon_filter = {
"LINECON",
0,
alloc_state,
NULL,
_linecon_decoder,
......
......@@ -108,3 +108,34 @@ mu_linelen_filter_create (mu_stream_t *pstream, mu_stream_t stream,
MU_FILTER_ENCODE, _ll_encoder, flt, flags);
}
static int
alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
{
struct _mu_linelen_filter *flt = malloc (sizeof (flt[0]));
if (!flt)
return ENOMEM;
flt->cur_len = 0;
flt->max_len = 76;
if (argc > 1)
{
char *p;
flt->max_len = strtoul (argv[1], &p, 10);
if (*p)
{
free (flt);
return MU_ERR_PARSE;
}
}
*pret = flt;
return 0;
}
static struct _mu_filter_record _linelen_filter = {
"LINELEN",
alloc_state,
_ll_encoder,
NULL,
};
mu_filter_record_t mu_linelen_filter = &_linelen_filter;
......
......@@ -243,7 +243,6 @@ _qp_encoder (void *xd MU_ARG_UNUSED,
static struct _mu_filter_record _qp_filter = {
"quoted-printable",
0,
NULL,
_qp_encoder,
_qp_decoder
......@@ -253,7 +252,6 @@ mu_filter_record_t mu_qp_filter = &_qp_filter;
static struct _mu_filter_record _Q_filter = {
"Q",
0,
NULL,
_qp_encoder,
_qp_decoder
......
......@@ -19,7 +19,7 @@ AT_KEYWORDS([base64 base64d base64dr decode filter])
AT_CHECK([
cp $abs_top_srcdir/libmailutils/tests/Encode expout
fltst base64 decode read linelen=0 < $abs_top_srcdir/libmailutils/tests/Decode],
fltst base64 decode read < $abs_top_srcdir/libmailutils/tests/Decode],
[0],
[expout])
......@@ -31,7 +31,7 @@ AT_KEYWORDS([base64 base64d base64dw decode filter])
AT_CHECK([
cp $abs_top_srcdir/libmailutils/tests/Encode expout
fltst base64 decode write linelen=0 < $abs_top_srcdir/libmailutils/tests/Decode],
fltst base64 decode write < $abs_top_srcdir/libmailutils/tests/Decode],
[0],
[expout])
......
......@@ -68,23 +68,6 @@ c_copy (mu_stream_t out, mu_stream_t in)
}
/* Set the maximum line length for the filter NAME to LENGTH.
FIXME: This is a kludge. Perhaps API should provide a function
for that. */
static void
reset_line_length (const char *name, size_t length)
{
mu_list_t list;
int status;
mu_filter_record_t frec;
mu_filter_get_list (&list);
status = mu_list_locate (list, (void*)name, (void**)&frec);
if (status == 0)
frec->max_line_length = length;
/* don't bail out, leave that to mu_filter_create */
}
void
usage (const char *diag)
{
......@@ -99,7 +82,7 @@ usage (const char *diag)
fp = stdout;
fprintf (fp, "%s",
"usage: fltst FILTER {encode|decode} {read|write} [shift=N] [linelen=N] [verbose] [printable] [nl] [-- args]\n");
"usage: fltst FILTER {encode|decode} {read|write} [shift=N] [verbose] [printable] [nl] [-- args]\n");
exit (diag ? 1 : 0);
}
......@@ -112,8 +95,6 @@ main (int argc, char * argv [])
int flags = MU_STREAM_READ;
char *fltname;
mu_off_t shift = 0;
size_t line_length;
int line_length_option = 0;
int newline_option = 0;
if (argc == 1)
......@@ -141,11 +122,6 @@ main (int argc, char * argv [])
{
if (strncmp (argv[i], "shift=", 6) == 0)
shift = strtoul (argv[i] + 6, NULL, 0);
else if (strncmp (argv[i], "linelen=", 8) == 0)
{
line_length = strtoul (argv[i] + 8, NULL, 10);
line_length_option = 1;
}
else if (strcmp (argv[i], "verbose") == 0)
verbose++;
else if (strcmp (argv[i], "printable") == 0)
......@@ -167,9 +143,6 @@ main (int argc, char * argv [])
MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0));
MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
if (line_length_option)
reset_line_length (fltname, line_length);
if (flags == MU_STREAM_READ)
{
MU_ASSERT (mu_filter_create_args (&flt, in, fltname,
......
......@@ -30,7 +30,6 @@ static char filter_args_doc[] = N_("[~]NAME [ARGS] [+ [~]NAME [ARGS]...]");
static struct argp_option filter_options[] = {
{ "encode", 'e', NULL, 0, N_("encode the input (default)") },
{ "decode", 'd', NULL, 0, N_("decode the input") },
{ "line-length", 'l', N_("NUMBER"), 0, N_("limit output line length") },
{ "newline", 'n', NULL, 0, N_("print additional newline") },
{ "list", 'L', NULL, 0, N_("list supported filters") },
{ NULL }
......@@ -38,15 +37,11 @@ static struct argp_option filter_options[] = {
static int filter_mode = MU_FILTER_ENCODE;
static int newline_option = 0;
static size_t line_length;
static int line_length_option = 0;
static int list_option;
static error_t
filter_parse_opt (int key, char *arg, struct argp_state *state)
{
char *p;
switch (key)
{
case 'e':
......@@ -61,13 +56,6 @@ filter_parse_opt (int key, char *arg, struct argp_state *state)
newline_option = 1;
break;
case 'l':
line_length = strtoul (arg, &p, 10);
if (*p)
argp_error (state, N_("not a number"));
line_length_option = 1;
break;
case 'L':
list_option = 1;
break;
......@@ -88,22 +76,6 @@ static struct argp filter_argp = {
NULL
};
/* FIXME: This is definitely a kludge. The API should provide a function
for that. */
static void
reset_line_length (const char *name, size_t length)
{
mu_list_t list;
int status;
mu_filter_record_t frec;
mu_filter_get_list (&list);
status = mu_list_locate (list, (void*)name, (void**)&frec);
if (status == 0)
frec->max_line_length = length;
/* don't bail out, leave that to mu_filter_create */
}
static int
filter_printer (void *item, void *data)
{
......@@ -184,9 +156,6 @@ mutool_filter (int argc, char **argv)
if (strcmp (argv[i], "+") == 0)
break;
if (line_length_option)
reset_line_length (fltname, line_length);
rc = mu_filter_create_args (&flt, prev_stream, fltname,
i, (const char **)argv,
mode, MU_STREAM_READ);
......