Commit 4e7f5b5c 4e7f5b5c08095818d7876a86ad6657c57c9a8ad1 by Sergey Poznyakoff

Fix logstream to support mu_locus_range.

* include/mailutils/locus.h (mu_stream_print_locus_range)
(mu_stream_vlprintf, mu_stream_lprintf, mu_lrange_debug): New protos.
* include/mailutils/stream.h (MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE)
(MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE): New ioctls.
* include/mailutils/sys/logstream.h (_mu_log_stream): Replace
locus with struct mu_locus_range locrange.
* libmailutils/locus/debug.c: Rewrite.
* libmailutils/locus/ident.c (mu_ident_ref): Accept NULL argument.
Fix initialization.
(mu_ident_deref): Accept NULL argument.
* libmailutils/stream/logstream.c: Rewrite.
* libmailutils/tests/.gitignore: Update.
* libmailutils/tests/Makefile.am: Add new tests.
* libmailutils/tests/testsuite.at: Likewise.
* libmailutils/tests/logstr.at: New testcase.
* libmailutils/tests/logstr.c: New file.
* libmailutils/tests/xscript.at: Minor change.
* sieve/tests/i-numeric.at: Minor change.
1 parent 7bca245a
......@@ -106,7 +106,7 @@ int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset);
if (mu_debug_line_info) \
{ \
mu_debug_log_begin ("\033X<%d>%s:%d: ", \
MU_LOGMODE_LOCUS, __FILE__, __LINE__); \
MU_LOGMODE_LOCUS, __FILE__, __LINE__); \
mu_debug_log_end s; \
} \
else \
......
......@@ -2,6 +2,7 @@
#define _MAILUTILS_LOCUS_H
#include <string.h>
#include <stdarg.h>
struct mu_locus_point
{
......@@ -49,6 +50,17 @@ void mu_locus_tracker_advance (struct mu_locus_track *trk,
char const *text, size_t leng);
void mu_locus_tracker_retreat (struct mu_locus_track *trk, size_t n);
void mu_stream_print_locus_range (mu_stream_t stream,
struct mu_locus_range const *loc);
void mu_stream_vlprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, va_list ap);
void mu_stream_lprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, ...);
void mu_lrange_debug (struct mu_locus_range const *loc,
char const *fmt, ...);
#endif
......
......@@ -32,8 +32,8 @@ extern "C" {
#define MU_LOG_ALERT 6
#define MU_LOG_EMERG 7
#define MU_LOGMODE_SEVERITY 0x0001
#define MU_LOGMODE_LOCUS 0x0002
#define MU_LOGMODE_SEVERITY 0x0001
#define MU_LOGMODE_LOCUS 0x0002
int mu_log_stream_create (mu_stream_t *, mu_stream_t);
int mu_syslog_stream_create (mu_stream_t *, int);
......
......@@ -36,6 +36,7 @@
#include <mailutils/header.h>
#include <mailutils/iterator.h>
#include <mailutils/kwd.h>
/* FIXME #include <mailutils/locus.h> */
#include <mailutils/sieve.h>
#include <mailutils/list.h>
#include <mailutils/locker.h>
......
......@@ -83,7 +83,7 @@ enum mu_buffer_type
/* Opcodes common for various families */
#define MU_IOCTL_OP_GET 0
#define MU_IOCTL_OP_SET 1
/* Opcodes for MU_IOCTL_PROGSTREAM */
#define MU_IOCTL_PROG_STATUS 0
#define MU_IOCTL_PROG_PID 1
......@@ -158,6 +158,15 @@ enum mu_buffer_type
Arg: mu_stream_t*
*/
#define MU_IOCTL_LOGSTREAM_CLONE 14
/* Get locus range.
Arg: struct mu_locus_range *
*/
#define MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE 15
/* Set locus range.
Arg: struct mu_locus_range *
*/
#define MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE 16
/* Opcodes for MU_IOCTL_XSCRIPTSTREAM */
/* Swap transcript levels.
......
......@@ -19,6 +19,7 @@
#include <mailutils/types.h>
#include <mailutils/sys/stream.h>
#include <mailutils/locus.h>
struct _mu_log_stream
{
......@@ -30,7 +31,7 @@ struct _mu_log_stream
int logmode; /* Mode flags */
int sevmask; /* Mask out the output of severity level for
these severities. */
struct mu_locus locus; /* Location */
struct mu_locus_range locrange; /* Location in the source file */
};
void _mu_log_stream_setup (struct _mu_log_stream *sp, mu_stream_t transport);
......
......@@ -9,12 +9,78 @@
#include <mailutils/stdstream.h>
void
mu_stream_print_locus_range (mu_stream_t stream,
struct mu_locus_range const *loc)
{
if (loc->beg.mu_col == 0)
{
if (loc->end.mu_file
&& (!mu_locus_point_same_file (&loc->beg, &loc->end)
|| loc->beg.mu_line != loc->end.mu_line))
mu_stream_printf (stream, "%s:%u-%u",
loc->beg.mu_file,
loc->beg.mu_line,
loc->end.mu_line);
else
mu_stream_printf (stream, "%s:%u",
loc->beg.mu_file,
loc->beg.mu_line);
}
else
{
if (loc->end.mu_file
&& !mu_locus_point_same_file (&loc->beg, &loc->end))
mu_stream_printf (stream, "%s:%u.%u-%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_file,
loc->end.mu_line, loc->end.mu_col);
else if (loc->end.mu_file && loc->beg.mu_line != loc->end.mu_line)
mu_stream_printf (stream, "%s:%u.%u-%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_line, loc->end.mu_col);
else if (loc->end.mu_file && loc->beg.mu_col != loc->end.mu_col)
mu_stream_printf (stream, "%s:%u.%u-%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_col);
else
mu_stream_printf (stream, "%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col);
}
}
void
mu_stream_vlprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, va_list ap)
{
mu_stream_print_locus_range (stream, loc);
mu_stream_write (stream, ": ", 2, NULL);
mu_stream_vprintf (mu_strerr, fmt, ap);
mu_stream_write (stream, "\n", 1, NULL);
}
void
mu_stream_lprintf (mu_stream_t stream,
struct mu_locus_range const *loc,
char const *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_stream_vlprintf (stream, loc, fmt, ap);
va_end (ap);
}
void
mu_lrange_debug (struct mu_locus_range const *loc,
char const *fmt, ...)
{
va_list ap;
int rc, mode;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &mode);
if (rc == 0)
......@@ -23,37 +89,13 @@ mu_lrange_debug (struct mu_locus_range const *loc,
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &new_mode);
}
if (loc->beg.mu_col == 0)
mu_debug_log_begin ("%s:%u", loc->beg.mu_file, loc->beg.mu_line);
else if (!mu_locus_point_same_file (&loc->beg, &loc->end))
mu_debug_log_begin ("%s:%u.%u-%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_file,
loc->end.mu_line, loc->end.mu_col);
else if (loc->beg.mu_line != loc->end.mu_line)
mu_debug_log_begin ("%s:%u.%u-%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_line, loc->end.mu_col);
else if (loc->beg.mu_col != loc->end.mu_col)
mu_debug_log_begin ("%s:%u.%u-%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col,
loc->end.mu_col);
else
mu_debug_log_begin ("%s:%u.%u",
loc->beg.mu_file,
loc->beg.mu_line, loc->beg.mu_col);
mu_stream_write (mu_strerr, ": ", 2, NULL);
va_start (ap, fmt);
mu_stream_vprintf (mu_strerr, fmt, ap);
mu_stream_lprintf (mu_strerr, loc, fmt, ap);
va_end (ap);
mu_debug_log_nl ();
if (rc == 0)
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
}
......
......@@ -20,10 +20,13 @@ mu_ident_ref (char const *name, char const **refname)
int rc;
struct mu_ident_ref *ref, **refptr;
if (!name)
return EINVAL;
if (!refname)
return MU_ERR_OUT_PTR_NULL;
if (!name)
{
*refname = NULL;
return 0;
}
if (!nametab)
{
......@@ -46,6 +49,7 @@ mu_ident_ref (char const *name, char const **refname)
mu_assoc_remove (nametab, name);
return rc;
}
*refptr = ref;
ref->count = 0;
break;
......@@ -68,9 +72,7 @@ mu_ident_deref (char const *name)
struct mu_ident_ref *ref;
int rc;
if (!name)
return EINVAL;
if (!nametab)
if (!name || !nametab)
return 0;
rc = mu_assoc_lookup (nametab, name, &ref);
......
......@@ -19,6 +19,7 @@ fsfolder
globtest
imapio
listop
logstr
mailcap
mimehdr
modmesg
......
......@@ -54,6 +54,7 @@ noinst_PROGRAMS = \
globtest\
imapio\
listop\
logstr\
mailcap\
mimehdr\
modtofsaf\
......@@ -106,6 +107,7 @@ TESTSUITE_AT = \
inline-comment.at\
linecon.at\
list.at\
logstr.at\
mailcap.at\
mimehdr.at\
modmesg00.at\
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2017 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP(Logger stream)
AT_KEYWORDS([logstream])
AT_CHECK([logstr],
[0],
[00. simple print
hello world
01. severity
info: one
emerg: two
mode was: 0x0001
02. suppress severity
info: this message is seen
emerg: and this one as well
03. suppress severity name
info: this message is seen
emerg: and this one as well
04. severity mask
one
two
emerg: three
05. set/get locus point
input:1: filename and line number
input:1.3: filename, line and column numbers
06. locus: file, line
input:1: file, line
07. locus: file, line, col
input:1.1-10: file, line, col
08. locus: file, line-range
input:1-2: file, line-range
09. locus: file, line-range, col
input:1.1-2.10: file, line-range, col
10. locus: file-range, line-range, col-range
input:1.1-next:2.10: file-range, line-range, col-range
11. set locus line
input:1.1-next:2.10: initial
input:8.1-next:2.10: locus line changed
12. advance locus line
input:1.1-next:5.10: initial
input:3.1-next:5.10: locus line advanced
13. set locus column
input:1.1-next:2.10: initial
input:1.8-next:2.10: locus column changed
14. advance locus column
input:1.1-next:5.10: initial
input:1.5-next:5.10: locus line advanced
15. fmt: severity
info: severity
16. fmt: locus (file, line)
a:10: one
17. fmt: locus (file, line, column)
a:10.5: one
18. fmt: locus (range)
a:10.5-b:14.8: one
19. fmt: locus; restore defaults
a:10.5-b:14.8: one
default
20. fmt: locus; restore defaults, display locus
a:10.5-b:14.8: one
input:1.1-next:5.10: default
21. fmt: set locus
a:10.5-b:14.8: one
a:10.5-b:14.8: default
])
AT_CLEANUP
\ No newline at end of file
......@@ -152,6 +152,10 @@ m4_include([strin.at])
m4_include([strout.at])
m4_include([strerr.at])
AT_BANNER([Streams])
m4_include([logstr.at])
m4_include([xscript.at])
m4_include([list.at])
m4_include([address.at])
m4_include([wordsplit.at])
......@@ -208,4 +212,3 @@ m4_include([msgset.at])
m4_include([globtest.at])
m4_include([xscript.at])
......
......@@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_BANNER([Transcript stream])
AT_SETUP([Transcript stream])
AT_KEYWORDS([stream xscript])
AT_DATA([input],[first line
......
......@@ -38,7 +38,7 @@ if header :comparator "i;ascii-numeric" :contains "X-Number" "15"
discard;
}
],[78],[],
[sieve: prog:4:1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
[sieve: prog:4.1: comparator `i;ascii-numeric' is incompatible with match type `contains' in call to `header'
])
AT_CLEANUP
......
atconfig
atlocal
bs
cwdrepl
fldel
lstuid
package.m4
......