introduce INIT_STDERR_LOCKING macro
authorAndre <maan@p133.(none)>
Fri, 5 Jan 2007 19:35:47 +0000 (20:35 +0100)
committerAndre <maan@p133.(none)>
Fri, 5 Jan 2007 19:35:47 +0000 (20:35 +0100)
This makes para_{audioc,client,filter,recv,write} use the
same log function.

audioc.c
client.c
filter.c
para.h
recv.c
write.c

index 0f4c5c5084d8dbf31c726ae6d3e5ccf67bcb7d29..1679335d7cf737d37413a158d347d16cb2054357 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
  *
  *     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
  *
  *     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
@@ -30,21 +30,7 @@ INIT_AUDIOC_ERRLISTS;
 struct audioc_args_info conf;
 char *tmpfifo;
 
 struct audioc_args_info conf;
 char *tmpfifo;
 
-
-/*
- * client log function
- */
-void para_log(int ll, const char* fmt,...)
-{
-       va_list argp;
-
-       /* ignore log message if loglevel is not high enough */
-       if (ll < conf.loglevel_arg)
-               return;
-       va_start(argp, fmt);
-       vfprintf(stderr, fmt, argp);
-       va_end(argp);
-}
+INIT_STDERR_LOGGING(conf.loglevel_arg);
 
 static char *concat_args(const int argc, char * const *argv)
 {
 
 static char *concat_args(const int argc, char * const *argv)
 {
index 88ea5af2ca737f2cead9c96fc8c0ec28b523c1da..be76a491b3e1db0ce15efd194611cde12f719ccf 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 1997-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
  *
  *     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
  *
  *     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
@@ -34,20 +34,8 @@ static struct private_client_data *pcd;
 static struct stdin_task sit;
 static struct stdout_task sot;
 
 static struct stdin_task sit;
 static struct stdout_task sot;
 
-/*
- * client log function
- */
-void para_log(int ll, const char* fmt,...)
-{
-       va_list argp;
 
 
-       /* ignore log message if loglevel is not high enough */
-       if (pcd && ll < pcd->conf.loglevel_arg)
-               return;
-       va_start(argp, fmt);
-       vfprintf(stderr, fmt, argp);
-       va_end(argp);
-}
+INIT_STDERR_LOGGING(pcd->conf.loglevel_arg);
 
 static void client_event_handler(struct task *t)
 {
 
 static void client_event_handler(struct task *t)
 {
index 40fbc844b35c70fa0070ad3d9652110fc6ae83ea..ee3d965596a37069b17cab629216cbf08a05229f 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -49,27 +49,7 @@ static struct stdout_task *sot = &stdout_task_struct;
 /** gengetopt struct that holds the command line args */
 static struct filter_args_info conf;
 
 /** gengetopt struct that holds the command line args */
 static struct filter_args_info conf;
 
-
-/**
- * standard log function that always writes to stderr
- *
- * \param ll loglevel. If the loglevel of the current message
- * is less than \a ll, the message is going to be ignored.
- *
- * \param fmt the format string describing the log message.
- *
- */
-__printf_2_3 void para_log(int ll, const char* fmt,...)
-{
-       va_list argp;
-
-       /* ignore log message if loglevel is not high enough */
-       if (ll < conf.loglevel_arg)
-               return;
-       va_start(argp, fmt);
-       vfprintf(stderr, fmt, argp);
-       va_end(argp);
-}
+INIT_STDERR_LOGGING(conf.loglevel_arg);
 
 static void filter_event_handler(struct task *t)
 {
 
 static void filter_event_handler(struct task *t)
 {
diff --git a/para.h b/para.h
index 47d54a1f805d917576351dd4af5a6e660e98693d..fc0edf9a43df1e3840c5c55fe49740256f1a364c 100644 (file)
--- a/para.h
+++ b/para.h
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 1997-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
  *
  *     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
  *
  *     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
 #define PARA_EMERG_LOG(...)
 #endif
 
 #define PARA_EMERG_LOG(...)
 #endif
 
+/**
+ * define a standard log function that always writes to stderr
+ *
+ * \param loglevel_barier If the loglevel of the current message
+ * is less than that, the message is going to be ignored.
+ *
+ */
+#define INIT_STDERR_LOGGING(loglevel_barrier) \
+       __printf_2_3 void para_log(int ll, const char* fmt,...) \
+       { \
+               va_list argp; \
+               if (ll < loglevel_barrier) \
+                       return; \
+               va_start(argp, fmt); \
+               vfprintf(stderr, fmt, argp); \
+               va_end(argp); \
+       }
+
+
 #define COPYRIGHT "Copyright (c) 1997-2006 by Andre Noll"
 
 #define LICENSE "This is free software with ABSOLUTELY NO WARRANTY. " \
 #define COPYRIGHT "Copyright (c) 1997-2006 by Andre Noll"
 
 #define LICENSE "This is free software with ABSOLUTELY NO WARRANTY. " \
diff --git a/recv.c b/recv.c
index cead11a345362178b99b36a159a6bea4f496df7b..35f6948c94971edf02a71a1a7be72fb4df7f7fc1 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -15,6 +15,9 @@
  *     along with this program; if not, write to the Free Software
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  */
  *     along with this program; if not, write to the Free Software
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  */
+
+/** \file recv.c the stand-alone receiver */
+
 #include "para.h"
 
 #include "list.h"
 #include "para.h"
 
 #include "list.h"
@@ -29,18 +32,8 @@ struct recv_args_info conf;
 
 INIT_RECV_ERRLISTS;
 
 
 INIT_RECV_ERRLISTS;
 
-__printf_2_3 void para_log(int ll, const char* fmt,...)
-{
-       va_list argp;
-
-       /* ignore log message if loglevel is not high enough */
-       if (ll < conf.loglevel_arg)
-               return;
-       va_start(argp, fmt);
-       vfprintf(stderr, fmt, argp);
-       va_end(argp);
-}
 
 
+INIT_STDERR_LOGGING(conf.loglevel_arg);
 static void *parse_config(int argc, char *argv[], int *receiver_num)
 {
        int i;
 static void *parse_config(int argc, char *argv[], int *receiver_num)
 {
        int i;
diff --git a/write.c b/write.c
index ec27f3d35ac078824e03f33c3ba38572177ef38d..89831a2e448f40129e5ed6d51f8bebd863d9123b 100644 (file)
--- a/write.c
+++ b/write.c
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
  *
  *     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
  *
  *     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
@@ -113,22 +113,7 @@ static void initial_delay_pre_select(struct sched *s, struct task *t)
                s->timeout = diff;
 }
 
                s->timeout = diff;
 }
 
-/**
- * all log messages are written to stderr
- *
- * \param ll: loglevel
- * \param fmt: format string
- */
-void para_log(int ll, const char* fmt,...)
-{
-       va_list argp;
-
-       if (ll < conf.loglevel_arg)
-               return;
-       va_start(argp, fmt);
-       vfprintf(stderr, fmt, argp);
-       va_end(argp);
-}
+INIT_STDERR_LOGGING(conf.loglevel_arg)
 
 static struct writer_node_group *check_args(void)
 {
 
 static struct writer_node_group *check_args(void)
 {