From 24a177d52a4da6c6f184e2818d9abf7cf2cd538e Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 25 Jul 2011 08:25:33 +0300 Subject: [PATCH] * add mu-guile-misc, with bindings for mu logging stuff --- libmuguile/Makefile.am | 5 +- libmuguile/mu-guile-misc.c | 101 +++++++++++++++++++++++++++++++++++++ libmuguile/mu-guile-misc.h | 39 ++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 libmuguile/mu-guile-misc.c create mode 100644 libmuguile/mu-guile-misc.h diff --git a/libmuguile/Makefile.am b/libmuguile/Makefile.am index 6ca617e0..6dcb00f2 100644 --- a/libmuguile/Makefile.am +++ b/libmuguile/Makefile.am @@ -36,6 +36,8 @@ libmuguile_la_SOURCES= \ mu-guile-msg.h \ mu-guile-store.c \ mu-guile-store.h \ + mu-guile-misc.c \ + mu-guile-misc.h \ mu-guile-common.c \ mu-guile-common.h @@ -45,7 +47,8 @@ libmuguile_la_LIBADD= \ XFILES= \ mu-guile-msg.x \ - mu-guile-store.x + mu-guile-store.x \ + mu-guile-misc.x BUILT_SOURCES=$(XFILES) diff --git a/libmuguile/mu-guile-misc.c b/libmuguile/mu-guile-misc.c new file mode 100644 index 00000000..72bd2b1a --- /dev/null +++ b/libmuguile/mu-guile-misc.c @@ -0,0 +1,101 @@ +/* +** Copyright (C) 2011 Dirk-Jan C. Binnema +** +** This program 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. +** +** This program 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 this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#include +#include +#include + +#include "mu-guile-msg.h" +#include "mu-guile-store.h" +#include "mu-guile-common.h" + +enum _LogType { + LOG_INFO, + LOG_WARNING, + LOG_CRITICAL +}; +typedef enum _LogType LogType; + + +static SCM +write_log (LogType logtype, SCM FRM, SCM ARGS) +#define FUNC_NAME __FUNCTION__ +{ + SCM str; + + SCM_ASSERT (scm_is_string(FRM), FRM, SCM_ARG1, ""); + SCM_VALIDATE_REST_ARGUMENT(ARGS); + + str = scm_simple_format (SCM_BOOL_F, FRM, ARGS); + + if (scm_is_string (str)) { + + gchar *output; + output = scm_to_utf8_string (str); + + switch (logtype) { + case LOG_INFO: g_message ("%s", output); break; + case LOG_WARNING: g_warning ("%s", output); break; + case LOG_CRITICAL: g_critical ("%s", output); break; + } + } + + return SCM_UNSPECIFIED; + +#undef FUNC_NAME +} + + +SCM_DEFINE (log_info, "mu:info", 1, 0, 1, (SCM FRM, SCM ARGS), + "log some message using a list of ARGS applied to FRM " + "(in 'simple-format' notation).\n") +#define FUNC_NAME s_info +{ + return write_log (LOG_INFO, FRM, ARGS); +} +#undef FUNC_NAME + +SCM_DEFINE (log_warning, "mu:warning", 1, 0, 1, (SCM FRM, SCM ARGS), + "log some warning using a list of ARGS applied to FRM (in 'simple-format' " + "notation).\n") +#define FUNC_NAME s_warning +{ + return write_log (LOG_WARNING, FRM, ARGS); +} +#undef FUNC_NAME + +SCM_DEFINE (log_critical, "mu:critical", 1, 0, 1, (SCM FRM, SCM ARGS), + "log some critical message using a list of ARGS applied to FRM " + "(in 'simple-format' notation).\n") +#define FUNC_NAME s_critical +{ + return write_log (LOG_CRITICAL, FRM, ARGS); +} +#undef FUNC_NAME + + +void* +mu_guile_misc_init (void *data) +{ +#include "mu-guile-misc.x" + + return NULL; +} + + diff --git a/libmuguile/mu-guile-misc.h b/libmuguile/mu-guile-misc.h new file mode 100644 index 00000000..22fe6e07 --- /dev/null +++ b/libmuguile/mu-guile-misc.h @@ -0,0 +1,39 @@ +/* +** Copyright (C) 2011 Dirk-Jan C. Binnema +** +** This program 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. +** +** This program 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 this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#ifndef __MU_GUILE_MISC_H__ +#define __MU_GUILE_MISC_H__ + + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +/** + * initialize misc mu functions + * + */ +void *mu_guile_misc_init (void *data); + + +#ifdef __cplusplus +} +#endif /*__cplusplus*/ + +#endif /*__MU_GUILE_MISC_H__*/