diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-10-12 23:41:21 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-10-12 23:42:04 +0300 |
commit | 8a4ba77068e5d7f6eab2cc1c1c10f31dcbccf7a6 (patch) | |
tree | c70f38d943c778684bb9dbfc7db018e7efb21bf1 /src/diag.c | |
parent | af04ed630f18e9003756317cc627a11084d0d59a (diff) | |
download | pies-8a4ba77068e5d7f6eab2cc1c1c10f31dcbccf7a6.tar.gz pies-8a4ba77068e5d7f6eab2cc1c1c10f31dcbccf7a6.tar.bz2 |
Fix make distcheck and check-docs.
* doc/Makefile.am: Fix `check-*' goals.
* doc/pies.texi: Update and rearrange material.
Document new configuration.
* lib/Makefile.am (libpies_a_SOURCES): Remove nls.c
* src/Makefile.am (EXTRA_DIST): Remove pies.rc, add
pp-setup.
(INCLUDES): Add $(top_builddir)/gnu
* src/pies.c: Minor changes.
* src/progman.c: Minor changes.
* README-hacking: New file.
Diffstat (limited to 'src/diag.c')
-rw-r--r-- | src/diag.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/diag.c b/src/diag.c new file mode 100644 index 0000000..8ae3911 --- /dev/null +++ b/src/diag.c @@ -0,0 +1,131 @@ +/* This file is part of Pies. + Copyright (C) 2009 Sergey Poznyakoff + + Pies 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. + + Pies 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 Pies. If not, see <http://www.gnu.org/licenses/>. */ + +#include "pies.h" +#include "xvasprintf.h" + +unsigned debug_level; +int source_info_option; + +void +syslog_printer (int prio, const char *fmt, va_list ap) +{ +#if HAVE_VSYSLOG + vsyslog (prio, fmt, ap); +#else + char buf[128]; + vsnprintf (buf, sizeof buf, fmt, ap); +#endif +} + +void +vlogmsg (int prio, const char *fmt, va_list ap) +{ + if (log_to_stderr) + { + vfprintf (stderr, fmt, ap); + fprintf (stderr, "\n"); + } + else + syslog_printer (prio, fmt, ap); +} + +void +logmsg (int prio, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vlogmsg (prio, fmt, ap); + va_end (ap); +} + +void +debug_msg (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vlogmsg (LOG_DEBUG, fmt, ap); + va_end (ap); +} + + +static struct obstack log_stk; +static int log_stk_init; + +void +logmsg_vprintf (int prio, const char *fmt, va_list ap) +{ + char *str, *p; + + str = xvasprintf (fmt, ap); + + if (!log_stk_init) + { + obstack_init (&log_stk); + log_stk_init = 1; + } + for (p = str; *p; ) + { + size_t len = strcspn (p, "\n"); + if (len) + obstack_grow (&log_stk, p, len); + p += len; + if (*p) + { + char *msg; + + obstack_1grow (&log_stk, 0); + msg = obstack_finish (&log_stk); + logmsg (prio, "%s", msg); + obstack_free (&log_stk, msg); + p++; + } + } + free (str); +} + +void +logmsg_printf (int prio, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + logmsg_vprintf (prio, fmt, ap); + va_end (ap); +} + +void +grecs_print_diag (grecs_locus_t *locus, int err, int errcode, const char *msg) +{ + if (locus) + { + if (errcode) + logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s: %s", + locus->file, (unsigned long)locus->line, msg, + strerror (errcode)); + else + logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s", + locus->file, (unsigned long)locus->line, msg); + } + else + { + if (errcode) + logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s", msg, + strerror (errcode)); + else + logmsg (err ? LOG_ERR : LOG_WARNING, "%s", msg); + } +} + |