summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-rw-r--r--Makefile7
-rwxr-xr-xconfigure27
-rw-r--r--eval.c30
-rw-r--r--lib.c18
-rw-r--r--lib.h2
-rw-r--r--syslog.c101
-rw-r--r--syslog.h39
-rw-r--r--txr.c4
9 files changed, 245 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index d63efe79..d4ee20ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2013-12-10 Kaz Kylheku <kaz@kylheku.com>
+
+ syslog support; bitwise logior and logand functions become variadic.
+
+ * Makefile: Use -iquote to restrict our #include search paths from being
+ processed for #include <...>. Add syslog.o to OBJS-y if have_syslog is y.
+
+ * configure (have_syslog): New variable, set by detecting syslog API.
+
+ * eval.c (eval_init): logand and logior registrations changed to
+ go to variadic versions. New syslog variables and functions registered.
+
+ * lib.c (logandv, logiorv): New functions.
+
+ * lib.h (logandv, logiorv): Declared.
+
+ * txr.c (main): Call syslog_init.
+
+ * syslog.c: New file.
+
+ * syslog.h: New file.
+
2013-12-07 Kaz Kylheku <kaz@kylheku.com>
Version 71
diff --git a/Makefile b/Makefile
index ee5a20c4..7ad3e7c3 100644
--- a/Makefile
+++ b/Makefile
@@ -28,9 +28,9 @@
include config.make
-CFLAGS := -I. -I$(top_srcdir) $(LANG_FLAGS) $(DIAG_FLAGS) \
+CFLAGS := -iquote $(top_srcdir) $(LANG_FLAGS) $(DIAG_FLAGS) \
$(OPT_FLAGS) $(DBG_FLAGS) $(PLATFORM_FLAGS) $(EXTRA_FLAGS)
-CFLAGS += -Impi-$(mpi_version)
+CFLAGS += -iquote mpi-$(mpi_version)
CFLAGS := $(filter-out $(REMOVE_FLAGS),$(CFLAGS))
ifneq ($(subst g++,@,$(notdir $(CC))),$(notdir $(CC)))
@@ -40,7 +40,8 @@ endif
# TXR objects
OBJS := txr.o lex.yy.o y.tab.o match.o lib.o regex.o gc.o unwind.o stream.o
OBJS += arith.o hash.o utf8.o filter.o eval.o rand.o
-OBJS-$(debug_support) := debug.o
+OBJS-$(debug_support) += debug.o
+OBJS-$(have_syslog) += syslog.o
# MPI objects
MPI_OBJ_BASE=mpi.o mplogic.o
diff --git a/configure b/configure
index 1e7bd517..44b5ed3b 100755
--- a/configure
+++ b/configure
@@ -100,6 +100,7 @@ have_quilt=
have_patch=
have_unistd=
have_timegm=
+have_syslog=
need_svid_source=
need_bsd_source=
@@ -573,6 +574,9 @@ compiler_prefix := $compiler_prefix
# prefix for non-compiler toolchain commands
tool_prefix := $tool_prefix
+# do we compile in syslog support?
+have_syslog := $have_syslog
+
# do we compile in debug support?
debug_support := $debug_support
@@ -1406,6 +1410,29 @@ else
have_unistd=y
fi
+printf "Checking for syslog ... "
+
+cat > conftest.c <<!
+#include <syslog.h>
+
+int main(void)
+{
+ openlog("foo", LOG_CONS, LOG_DAEMON);
+ syslog(LOG_EMERG, "bar %d\n", 3);
+ setlogmask(0);
+ closelog();
+ return 0;
+}
+!
+rm -f conftest
+if ! $make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+ printf "no\n"
+else
+ printf "yes\n"
+ printf "#define HAVE_SYSLOG 1\n" >> config.h
+ have_syslog=y
+fi
+
#
# Dependent variables
#
diff --git a/eval.c b/eval.c
index 1a3c378f..052ad450 100644
--- a/eval.c
+++ b/eval.c
@@ -48,6 +48,7 @@
#include "rand.h"
#include "filter.h"
#include "txr.h"
+#include "syslog.h"
#include "eval.h"
typedef val (*opfun_t)(val, val);
@@ -2299,8 +2300,8 @@ void eval_init(void)
reg_fun(intern(lit("/="), user_package), func_n0v(numneqv));
reg_fun(intern(lit("max"), user_package), func_n1v(maxv));
reg_fun(intern(lit("min"), user_package), func_n1v(minv));
- reg_fun(intern(lit("logand"), user_package), func_n2(logand));
- reg_fun(intern(lit("logior"), user_package), func_n2(logior));
+ reg_fun(intern(lit("logand"), user_package), func_n0v(logandv));
+ reg_fun(intern(lit("logior"), user_package), func_n0v(logiorv));
reg_fun(intern(lit("logxor"), user_package), func_n2(logxor));
reg_fun(intern(lit("logtest"), user_package), func_n2(logtest));
reg_fun(intern(lit("lognot"), user_package), func_n2o(lognot, 1));
@@ -2559,6 +2560,31 @@ void eval_init(void)
reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0));
reg_fun(intern(lit("daemon"), user_package), func_n2(daemon_wrap));
+ reg_var(intern(lit("s-ixoth"), user_package), &s_ixoth);
+
+#if HAVE_SYSLOG
+ reg_var(intern(lit("log-pid"), user_package), &log_pid_v);
+ reg_var(intern(lit("log-cons"), user_package), &log_cons_v);
+ reg_var(intern(lit("log-ndelay"), user_package), &log_ndelay_v);
+ reg_var(intern(lit("log-odelay"), user_package), &log_odelay_v);
+ reg_var(intern(lit("log-nowait"), user_package), &log_nowait_v);
+ reg_var(intern(lit("log-perror"), user_package), &log_perror_v);
+ reg_var(intern(lit("log-user"), user_package), &log_user_v);
+ reg_var(intern(lit("log-daemon"), user_package), &log_daemon_v);
+ reg_var(intern(lit("log-auth"), user_package), &log_auth_v);
+ reg_var(intern(lit("log-emerg"), user_package), &log_emerg_v);
+ reg_var(intern(lit("log-alert"), user_package), &log_alert_v);
+ reg_var(intern(lit("log-crit"), user_package), &log_crit_v);
+ reg_var(intern(lit("log-err"), user_package), &log_err_v);
+ reg_var(intern(lit("log-warning"), user_package), &log_warning_v);
+ reg_var(intern(lit("log-notice"), user_package), &log_notice_v);
+ reg_var(intern(lit("log-info"), user_package), &log_info_v);
+ reg_var(intern(lit("log-debug"), user_package), &log_debug_v);
+ reg_fun(intern(lit("openlog"), user_package), func_n3o(openlog_wrap, 1));
+ reg_fun(intern(lit("setlogmask"), user_package), func_n1(setlogmask_wrap));
+ reg_fun(intern(lit("syslog"), user_package), func_n2v(syslog_wrap));
+#endif
+
reg_fun(intern(lit("source-loc"), user_package), func_n1(source_loc));
reg_fun(intern(lit("source-loc-str"), user_package), func_n1(source_loc_str));
diff --git a/lib.c b/lib.c
index 0c60a4de..2856962f 100644
--- a/lib.c
+++ b/lib.c
@@ -1399,6 +1399,24 @@ val mulv(val nlist)
return reduce_left(func_n2(mul), cdr(nlist), car(nlist), nil);
}
+val logandv(val nlist)
+{
+ if (!nlist)
+ return negone;
+ else if (!cdr(nlist))
+ return car(nlist);
+ return reduce_left(func_n2(logand), cdr(nlist), car(nlist), nil);
+}
+
+val logiorv(val nlist)
+{
+ if (!nlist)
+ return zero;
+ else if (!cdr(nlist))
+ return car(nlist);
+ return reduce_left(func_n2(logior), cdr(nlist), car(nlist), nil);
+}
+
val gtv(val first, val rest)
{
val iter;
diff --git a/lib.h b/lib.h
index 5dee93b4..c12690cc 100644
--- a/lib.h
+++ b/lib.h
@@ -483,6 +483,8 @@ val loga(val);
val expo(val);
val logand(val, val);
val logior(val, val);
+val logandv(val nlist);
+val logiorv(val nlist);
val logxor(val, val);
val logtest(val, val);
val lognot(val, val);
diff --git a/syslog.c b/syslog.c
new file mode 100644
index 00000000..6ab5826c
--- /dev/null
+++ b/syslog.c
@@ -0,0 +1,101 @@
+/* Copyright 2012
+ * Kaz Kylheku <kaz@kylheku.com>
+ * Vancouver, Canada
+ * All rights reserved.
+ *
+ * BSD License:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <setjmp.h>
+#include <wchar.h>
+#include <dirent.h>
+#include <syslog.h>
+#include "config.h"
+#include "lib.h"
+#include "stream.h"
+#include "hash.h"
+#include "gc.h"
+#include "unwind.h"
+#include "utf8.h"
+#include "syslog.h"
+
+val log_pid_v, log_cons_v, log_ndelay_v;
+val log_odelay_v, log_nowait_v, log_perror_v;
+
+val log_user_v, log_daemon_v, log_auth_v;
+
+val log_emerg_v, log_alert_v, log_crit_v, log_err_v;
+val log_warning_v, log_notice_v, log_info_v, log_debug_v;
+
+void syslog_init(void)
+{
+ log_pid_v = num(LOG_PID);
+ log_cons_v = num(LOG_CONS);
+ log_ndelay_v = num(LOG_NDELAY);
+
+ log_odelay_v = num(LOG_ODELAY);
+ log_nowait_v = num(LOG_NOWAIT);
+ log_perror_v = num(LOG_PERROR);
+
+ log_user_v = num(LOG_USER);
+ log_daemon_v = num(LOG_DAEMON);
+ log_auth_v = num(LOG_AUTH);
+
+ log_emerg_v = num(LOG_EMERG);
+ log_alert_v = num(LOG_ALERT);
+ log_crit_v = num(LOG_CRIT);
+ log_err_v = num(LOG_ERR);
+ log_warning_v = num(LOG_WARNING);
+ log_notice_v = num(LOG_NOTICE);
+ log_info_v = num(LOG_INFO);
+ log_debug_v = num(LOG_DEBUG);
+}
+
+val openlog_wrap(val wident, val optmask, val facility)
+{
+ static char *ident;
+ char *old_ident = ident;
+
+ ident = utf8_dup_to(c_str(wident));
+ openlog(ident,
+ if3(optmask, c_num(optmask), 0),
+ if3(facility, c_num(facility), LOG_USER));
+ free(old_ident);
+
+ return nil;
+}
+
+val setlogmask_wrap(val mask)
+{
+ return num(setlogmask(c_num(mask)));
+}
+
+val syslog_wrap(val prio, val fmt, val args)
+{
+ val text = formatv(nil, fmt, args);
+ char *u8text = utf8_dup_to(c_str(text));
+ syslog(c_num(prio), "%s", u8text);
+ return nil;
+}
diff --git a/syslog.h b/syslog.h
new file mode 100644
index 00000000..2bc214cc
--- /dev/null
+++ b/syslog.h
@@ -0,0 +1,39 @@
+/* Copyright 2012
+ * Kaz Kylheku <kaz@kylheku.com>
+ * Vancouver, Canada
+ * All rights reserved.
+ *
+ * BSD License:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+
+extern val log_pid_v, log_cons_v, log_ndelay_v;
+extern val log_odelay_v, log_nowait_v, log_perror_v;
+
+extern val log_user_v, log_daemon_v, log_auth_v;
+
+extern val log_emerg_v, log_alert_v, log_crit_v, log_err_v;
+extern val log_warning_v, log_notice_v, log_info_v, log_debug_v;
+
+void syslog_init(void);
+val openlog_wrap(val ident, val optmask, val facility);
+val setlogmask_wrap(val mask);
+val syslog_wrap(val prio, val fmt, val args);
diff --git a/txr.c b/txr.c
index d614a5de..fd96d9a8 100644
--- a/txr.c
+++ b/txr.c
@@ -41,6 +41,7 @@
#include "match.h"
#include "utf8.h"
#include "debug.h"
+#include "syslog.h"
#include "txr.h"
const wchli_t *version = wli("71");
@@ -162,6 +163,9 @@ int main(int argc, char **argv)
match_init();
parse_init();
debug_init();
+#if HAVE_SYSLOG
+ syslog_init();
+#endif
return txr_main(argc, argv);
}