diff options
-rw-r--r-- | include/mailutils/locus.h | 21 | ||||
-rw-r--r-- | include/mailutils/types.hin | 6 | ||||
-rw-r--r-- | include/mailutils/yyloc.h | 23 | ||||
-rw-r--r-- | libmailutils/locus/ident.c | 39 | ||||
-rw-r--r-- | libmailutils/locus/locus.c | 31 | ||||
-rw-r--r-- | libmailutils/stream/logstream.c | 10 | ||||
-rw-r--r-- | libmailutils/tests/linetrack.c | 1 | ||||
-rw-r--r-- | libmailutils/tests/logstr.c | 27 |
8 files changed, 136 insertions, 22 deletions
diff --git a/include/mailutils/locus.h b/include/mailutils/locus.h index 50efc53fb..1f94c69e4 100644 --- a/include/mailutils/locus.h +++ b/include/mailutils/locus.h @@ -1,3 +1,20 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 2017 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/>. */ + #ifndef _MAILUTILS_LOCUS_H #define _MAILUTILS_LOCUS_H @@ -34,6 +51,7 @@ struct mu_linetrack_stat int mu_ident_ref (char const *name, char const **refname); int mu_ident_deref (char const *); +void mu_ident_stat (mu_stream_t str); int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename); int mu_locus_point_init (struct mu_locus_point *pt, const char *filename); @@ -60,9 +78,6 @@ mu_locus_point_same_line (struct mu_locus_point const *a, return mu_locus_point_same_file (a, b) && a->mu_line == b->mu_line; } -void mu_lrange_debug (struct mu_locus_range const *loc, - char const *fmt, ...); - int mu_linetrack_create (mu_linetrack_t *ret, char const *file_name, size_t max_lines); int mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt); diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin index 5c15c6253..e1a9ac46a 100644 --- a/include/mailutils/types.hin +++ b/include/mailutils/types.hin @@ -155,7 +155,11 @@ typedef unsigned int mu_debug_level_t; <mailutils/locus.h>. This definition is provided for backward compatibility. Authors are - urged to switch to the new API as soon as their time permits. */ + urged to switch to the new API as soon as their time permits. + + Please see http://mailutils.org/wiki/Source_location_API#Deprecated_interface + for detailed guidelines. +*/ struct mu_locus_DEPRECATED { char *mu_file; diff --git a/include/mailutils/yyloc.h b/include/mailutils/yyloc.h index 40e395ee2..951ccf0a6 100644 --- a/include/mailutils/yyloc.h +++ b/include/mailutils/yyloc.h @@ -1,3 +1,23 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 2017 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/>. */ + +#ifndef _MAILUTILS_YYLOC_H +#define _MAILUTILS_YYLOC_H + void mu_file_print_locus_point (FILE *, struct mu_locus_point const *lpt); void mu_file_print_locus_range (FILE *, @@ -18,8 +38,9 @@ void mu_file_print_locus_range (FILE *, (Current).end = (Current).beg; \ } \ } while (0) + #define YY_LOCATION_PRINT(File, Loc) \ mu_file_print_locus_range (File, &(Loc)) - +#endif diff --git a/libmailutils/locus/ident.c b/libmailutils/locus/ident.c index 029a12f61..cb7591ea8 100644 --- a/libmailutils/locus/ident.c +++ b/libmailutils/locus/ident.c @@ -23,6 +23,9 @@ #include <mailutils/errno.h> #include <mailutils/diag.h> #include <mailutils/list.h> +#include <mailutils/io.h> +#include <mailutils/stream.h> +#include <mailutils/iterator.h> struct mu_ident_ref { @@ -111,5 +114,39 @@ mu_ident_deref (char const *name) return 0; } - +void +mu_ident_stat (mu_stream_t str) +{ + size_t count, i; + mu_iterator_t itr; + + mu_stream_printf (str, "BEGIN IDENT STAT\n"); + + mu_assoc_count (nametab, &count); + mu_stream_printf (str, "N=%zu\n", count); + + if (count > 0) + { + int rc = mu_assoc_get_iterator (nametab, &itr); + if (rc) + mu_stream_printf (str, "mu_assoc_get_iterator: %s\n", + mu_strerror (rc)); + else + { + i = 0; + for (mu_iterator_first (itr); !mu_iterator_is_done (itr); + mu_iterator_next (itr), i) + { + const char *key; + struct mu_ident_ref *ref; + + mu_iterator_current_kv (itr, + (const void **)&key, (void **)&ref); + mu_stream_printf (str, "%04zu: %s: %zu\n", i, key, ref->count); + } + } + mu_iterator_destroy (&itr); + } + mu_stream_printf (str, "END IDENT STAT\n"); +} diff --git a/libmailutils/locus/locus.c b/libmailutils/locus/locus.c index 8183294c8..49648fdc5 100644 --- a/libmailutils/locus/locus.c +++ b/libmailutils/locus/locus.c @@ -20,6 +20,7 @@ #include <mailutils/types.h> #include <mailutils/locus.h> #include <mailutils/error.h> +#include <mailutils/errno.h> int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) @@ -38,9 +39,13 @@ mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) int mu_locus_point_init (struct mu_locus_point *pt, const char *filename) { - pt->mu_line = 0; - pt->mu_col = 0; - return mu_locus_point_set_file (pt, filename); + int rc = mu_locus_point_set_file (pt, filename); + if (rc == 0) + { + pt->mu_line = 0; + pt->mu_col = 0; + } + return rc; } void @@ -54,9 +59,13 @@ int mu_locus_point_copy (struct mu_locus_point *dest, struct mu_locus_point const *src) { - dest->mu_col = src->mu_col; - dest->mu_line = src->mu_line; - return mu_locus_point_set_file (dest, src->mu_file); + int rc = mu_locus_point_set_file (dest, src->mu_file); + if (rc == 0) + { + dest->mu_col = src->mu_col; + dest->mu_line = src->mu_line; + } + return rc; } int @@ -65,7 +74,10 @@ mu_locus_range_copy (struct mu_locus_range *dest, { int rc; struct mu_locus_range tmp = MU_LOCUS_RANGE_INITIALIZER; - + + if (!dest) + return MU_ERR_OUT_PTR_NULL; + rc = mu_locus_point_copy (&tmp.beg, &src->beg); if (rc == 0) { @@ -73,7 +85,10 @@ mu_locus_range_copy (struct mu_locus_range *dest, if (rc) mu_locus_point_deinit (&tmp.beg); else - *dest = tmp; + { + mu_locus_range_deinit (dest); + *dest = tmp; + } } return rc; } diff --git a/libmailutils/stream/logstream.c b/libmailutils/stream/logstream.c index e79b27514..1cc2b4b08 100644 --- a/libmailutils/stream/logstream.c +++ b/libmailutils/stream/logstream.c @@ -258,11 +258,7 @@ _log_write (struct _mu_stream *str, const char *buf, size_t size, severity = MU_LOG_EMERG; if (save_locus) - { - sp->locrange = loc; - mu_ident_ref (sp->locrange.beg.mu_file, &sp->locrange.beg.mu_file); - mu_ident_ref (sp->locrange.end.mu_file, &sp->locrange.end.mu_file); - } + mu_locus_range_copy (&sp->locrange, &loc); if (severity < sp->threshold) rc = 0; @@ -649,6 +645,8 @@ mu_log_stream_create (mu_stream_t *pstr, mu_stream_t transport) return 0; } +static char wiki_url[] = "http://mailutils.org/wiki/Source_location_API#Deprecated_interface"; + int mu_ioctl_logstream_get_locus_deprecated (void) { @@ -656,6 +654,7 @@ mu_ioctl_logstream_get_locus_deprecated (void) if (!warned) { mu_error (_("the program uses MU_IOCTL_LOGSTREAM_GET_LOCUS, which is deprecated")); + mu_error (_("please see %s, for detailed guidelines"), wiki_url); warned = 1; } return MU_IOCTL_LOGSTREAM_GET_LOCUS_DEPRECATED; @@ -668,6 +667,7 @@ mu_ioctl_logstream_set_locus_deprecated (void) if (!warned) { mu_error (_("program uses MU_IOCTL_LOGSTREAM_SET_LOCUS, which is deprecated")); + mu_error (_("please see %s, for detailed guidelines"), wiki_url); warned = 1; } return MU_IOCTL_LOGSTREAM_SET_LOCUS_DEPRECATED; diff --git a/libmailutils/tests/linetrack.c b/libmailutils/tests/linetrack.c index 3ca5ceb4f..c99440e1f 100644 --- a/libmailutils/tests/linetrack.c +++ b/libmailutils/tests/linetrack.c @@ -59,6 +59,7 @@ main (int argc, char **argv) } mu_locus_range_deinit (&lr); } + mu_linetrack_destroy (&trk); return 0; } diff --git a/libmailutils/tests/logstr.c b/libmailutils/tests/logstr.c index 638f9b8a7..269a6137f 100644 --- a/libmailutils/tests/logstr.c +++ b/libmailutils/tests/logstr.c @@ -629,6 +629,7 @@ struct testcase { char const *id; void (*handler) (mu_stream_t); + int enabled; }; struct testcase testcases[] = { @@ -689,17 +690,37 @@ main (int argc, char **argv) mu_stream_t log; struct testcase *tp; int i; + int ena = 0; mu_set_program_name (argv[0]); mu_stdstream_setup (MU_STDSTREAM_RESET_NONE); + if (argc > 1) + { + ena = 1; + for (i = 1; i < argc; i++) + { + char *p; + int n = strtol (argv[i], &p, 10); + if (! (*p == 0 && n >= 0) ) + { + mu_error ("erroneous argument %s\n", argv[i]); + return 1; + } + testcases[n].enabled = ena; + } + } + log = create_log (); for (i = 0, tp = testcases; tp->id; tp++, i++) { - mu_stream_printf (log, "%02d. %s\n", i, tp->id); - tp->handler (log); - log_reset (log); + if (tp->enabled == ena) + { + mu_stream_printf (log, "%02d. %s\n", i, tp->id); + tp->handler (log); + log_reset (log); + } } return 0; |