Commits

Sebastian Freundt committed 8b34b53 Merge

Merge branch 'next'

* next:
minor, mention dgrep in README
minor, catch cmp == -2
fix, do not write result in __guess_dtyp() from stack instantiated values
minor, introduce padding bits
minor, provide better compiler macros for c.ac
cosmetics, obey gcc compiler warnings
minor, do not include date-core.h in time-core
minor, list dgrep in c.ac build summary
minor, provide documentation for dgrep
minor, provide tests for dgrep, extend test suite too
minor, actually set the default later on, just check for oper ~ness
cosmetics, initialise oper var `o'
fix, make -o a flag
minor, kick output format option as it makes no sense in dgrep
fix, check for number of input arguments first
cosmetics, obey compiler warnings
minor, provide working predicate matchp()
minor, provide new tool dgrep

Comments (0)

Files changed (26)

 LANG = C
 LC_ALL = C
 
+ACLOCAL_AMFLAGS = -I m4
+
 SUBDIRS = lib src info test
 
 EXTRA_DIST = .version git-version-gen
 + `ddiff`               Compute durations from dates
 + `dseq`                Generate sequences of dates
 + `dtest`               Compare dates
++ `dgrep`               Grep dates in input streams
 + `tadd`                Add durations to times
 + `tdiff`               Compute durations between times
 + `tseq`                Generate sequences of times
     =>
       0m22d
 
+dgrep
+-----
+  A tool to extract lines from an input stream that match certain
+  criteria, showing either the line or the match:
+
+    dgrep '<2012-03-01' <<EOF
+    Feb	2012-02-28
+    Feb	2012-02-29	leap day
+    Mar	2012-03-01
+    Mar	2012-03-02
+    EOF
+    =>
+      Feb	2012-02-28
+      Feb	2012-02-29	leap day
+
 tseq
 ----
   Quite like dseq but for times, and because times are generally less
 
 ## the build chain
 AC_PROG_CC([icc gcc tcc cc])
-AC_PROG_CC_C99
+SXE_CHECK_CC
+SXE_CHECK_CFLAGS
 
 AM_MISSING_PROG([HELP2MAN], [help2man], ["${missing_dir}"])
 
 ## trivial, no special stuff needed
-apps=" dadd dcal ddiff dseq dtest strptime tseq tadd tdiff"
+apps=" dadd dcal ddiff dgrep dseq dtest strptime tseq tadd tdiff"
 
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_FILES([lib/Makefile])
 dateutils_TEXINFOS += ddiff.texi
 dateutils_TEXINFOS += dseq.texi
 dateutils_TEXINFOS += dtest.texi
-dateutils_TEXINFOS += dadd.texi
+dateutils_TEXINFOS += dgrep.texi
 dateutils_TEXINFOS += tseq.texi
 dateutils_TEXINFOS += tadd.texi
 dateutils_TEXINFOS += tdiff.texi
 dateutils_EXAMPLES += $(ddiff_EXAMPLES)
 dateutils_H2M_EX += ddiff.h2m
 
+dgrep_EXAMPLES =
+dgrep_EXAMPLES += $(top_srcdir)/test/dgrep.1.dt
+dgrep_EXAMPLES += $(top_srcdir)/test/dgrep.2.dt
+dgrep_EXAMPLES += $(top_srcdir)/test/dgrep.6.dt
+dgrep_EXAMPLES += $(top_srcdir)/test/dgrep.7.dt
+dgrep_EXAMPLES += $(top_srcdir)/test/dgrep.8.dt
+dateutils_EXAMPLES += $(dgrep_EXAMPLES)
+dateutils_H2M_EX += dgrep.h2m
+
 tseq_EXAMPLES =
 tseq_EXAMPLES += $(top_srcdir)/test/tseq.1.dt
 tseq_EXAMPLES += $(top_srcdir)/test/tseq.2.dt
 man1_MANS += dadd.man
 man1_MANS += dcal.man
 man1_MANS += ddiff.man
+man1_MANS += dgrep.man
 man1_MANS += dseq.man
 man1_MANS += dtest.man
 man1_MANS += tseq.man

info/dateutils.texi

 * dcal::                Convert dates between calendars
 * dadd::                Add durations to dates
 * ddiff::               Compute durations from dates
+* dgrep::               Find date matches in input stream
 * dseq::                Generate sequences of dates
 * dtest::               Compare dates
 * tadd::                Add durations to times
 @include dcal.texi
 @include dadd.texi
 @include ddiff.texi
+@include dgrep.texi
 @include dseq.texi
 @include dtest.texi
 @include tadd.texi
 			tmp = dur.qmb.q * 3 + dur.qmb.m;
 			break;
 		default:
+			tmp = 0;
 			break;
 		}
 
 static struct dt_d_s
 __guess_dtyp(struct strpd_s d)
 {
-	struct dt_d_s res;
+	struct dt_d_s res = {.u = 0};
 	bool bizdap;
 
 	if (UNLIKELY(d.y == -1U)) {
 	if (LIKELY(d.y && (d.m == 0 || d.c == 0) && !bizdap)) {
 		/* nearly all goes to ymd */
 		res.typ = DT_YMD;
-		res.ymd = (dt_ymd_t){
-			.y = d.y,
-			.m = d.m,
-			.d = d.d,
-		};
+		res.ymd.y = d.y;
+		res.ymd.m = d.m;
+		res.ymd.d = d.d;
 	} else if (d.y && d.c && !bizdap) {
 		/* its legit for d.w to be naught */
 		res.typ = DT_YMCW;
-		res.ymcw = (dt_ymcw_t){
-			.y = d.y,
-			.m = d.m,
-			.c = d.c,
-			.w = d.w,
-		};
+		res.ymcw.y = d.y;
+		res.ymcw.m = d.m;
+		res.ymcw.c = d.c;
+		res.ymcw.w = d.w;
 	} else if (d.y && bizdap) {
 		/* d.c can be legit'ly naught */
 		res.typ = DT_BIZDA;
-		res.bizda = (dt_bizda_t){
-			.y = d.y,
-			.m = d.m,
-			.bda = d.b,
-			.x = d.ref,
-		};
+		res.bizda.y = d.y;
+		res.bizda.m = d.m;
+		res.bizda.bda = d.b;
+		res.bizda.x = d.ref;
 	} else {
 		/* anything else is bollocks for now */
 		res.typ = DT_UNK;
 		unsigned int m:4;
 		unsigned int y:12;
 		/* 11 bits left */
+		unsigned int pad:11;
 	};
 } dt_ymd_t;
 
 		unsigned int m:4;
 		unsigned int y:12;
 		/* 10 bits left */
+		unsigned int pad:10;
 	};
 } dt_ymcw_t;
 
 		unsigned int m:4;
 		unsigned int y:12;
 		/* 5 bits left */
+		unsigned int pad:5;
 	};
 } dt_bizda_t;
 
 #include <stdio.h>
 #include <stdbool.h>
 #include <time.h>
-#include "date-core.h"
 
 #if !defined LIKELY
 # define LIKELY(_x)	__builtin_expect(!!(_x), 1)
+dnl sxe-aux.m4 -- just some auxiliary macros
+
+dnl -------------------------------------------------------------------------
+dnl Local macros
+dnl -------------------------------------------------------------------------
+
+AC_DEFUN([SXE_USAGE_ERROR], [dnl
+(echo "$progbasename: Usage error:"
+echo " " $1
+echo "  Use \`$progname --help' to show usage.") >&2 && exit 1])
+
+dnl SXE_PRINT_VAR(var var ...)  prints values of shell variables
+AC_DEFUN([SXE_PRINT_VAR],[for var in patsubst([$1],[[
+]+],[ ]); do eval "echo \"$var = '\$$var'\""; done])
+
+dnl SXE_ADD_RUNPATH_DIR(directory)
+AC_DEFUN([SXE_ADD_RUNPATH_DIR], [dnl
+{
+	xe_runpath_dir=$1
+	if test "$xe_runpath_dir" != "/lib" -a \
+		"$xe_runpath_dir" != "/usr/lib" -a \
+		-n "`ls ${xe_runpath_dir}/*.s[[ol]] 2>/dev/null`"; then
+		eval "$xe_add_unique_runpath_dir"
+	fi
+}
+])dnl SXE_ADD_RUNPATH_DIR
+
+
+AC_DEFUN([SXE_CHECK_USER_SPECIFIED_P], [dnl
+	## arg1 var-name to check for
+	## generates a variable `arg1'_uspecified_p
+	pushdef([VARNAME], [$1])
+	pushdef([VARNAME_USPECIFIED_P], [$1_uspecified_p])
+	pushdef([USER_VARNAME], [USER_$1])
+
+	AC_MSG_CHECKING([for user specified ]VARNAME)
+	if test "${[]VARNAME[]-unset}" != "unset"; then
+		VARNAME_USPECIFIED_P[]=yes;
+		USER_VARNAME=${[]VARNAME[]}
+	else
+		VARNAME_USPECIFIED_P[]=no;
+		USER_VARNAME=
+	fi
+	AC_MSG_RESULT([$]VARNAME_USPECIFIED_P)
+	popdef([VARNAME])
+	popdef([VARNAME_USPECIFIED_P])
+	popdef([USER_VARNAME])
+])dnl SXE_CHECK_USER_SPECIFIED_P
+
+AC_DEFUN([SXE_CHECK_USER_VARS], [dnl
+	## If we don't set CFLAGS here, AC_PROG_CC will set it.
+	## But we know better what's good for us, so we do our own
+	## computation of real CFLAGS later.
+	SXE_CHECK_USER_SPECIFIED_P([CFLAGS])
+	SXE_CHECK_USER_SPECIFIED_P([CPPFLAGS])
+	SXE_CHECK_USER_SPECIFIED_P([LDFLAGS])
+	SXE_CHECK_USER_SPECIFIED_P([XFLAGS])
+	SXE_CHECK_USER_SPECIFIED_P([LIBS])
+	SXE_CHECK_USER_SPECIFIED_P([CC])
+	SXE_CHECK_USER_SPECIFIED_P([CPP])
+	SXE_CHECK_USER_SPECIFIED_P([AR])
+	SXE_CHECK_USER_SPECIFIED_P([YACC])
+	SXE_CHECK_USER_SPECIFIED_P([YFLAGS])
+	SXE_CHECK_USER_SPECIFIED_P([XMKMF])
+])dnl SXE_CHECK_USER_VARS
+
+
+dnl A meta defun that can create those nifty SXE_ADD_*_OBJ macros
+m4_define([__SXE_MAKE_ADDER], [
+	## arg1 is the name to be used throughout m4
+	## arg2 is the library sans _la or _a to be used in the Makefiles
+	## arg3 are comma-separated additional vars to substitute
+	## defines SXE_ADD_<arg1>_OBJ
+	## defines SXE_ADD_<arg1>_OBJS
+	## defines SXE_SUBST_<arg1>_OBJS
+
+	m4_define([SXE_ADD_]$1[_OBJ], [
+		$2_objs="$$2_objs $2_a-]$[1]["
+		if test "$extra_verbose" = "yes"; then
+			echo "    sxemacs (cat. $1) will be linked with \"]$[1][\""
+		fi
+	])dnl
+
+	m4_define([SXE_ADD_]$1[_OBJS], [
+		for i in ]$[1][; do
+			]SXE_ADD_[]$1[]_OBJ([$i])[
+		done
+	])dnl
+	
+	m4_define([SXE_SUBST_]$1[_OBJS], [
+		AC_SUBST($2_objs)
+		## subst additional vars
+		m4_foreach_w([var], $3, [AC_SUBST(var)])
+		## also define a conditional
+		AM_CONDITIONAL([NEED_]translit([$2], [-.a-z], [__A-Z]),
+			[test -n "$$2_objs"])
+	])dnl
+
+])dnl __SXE_MAKE_ADDER
+
+
+dnl creates SXE_ADD_CORE_{OBJ,OBJS}
+__SXE_MAKE_ADDER([CORE], [libsxecore])
+
+dnl creates SXE_ADD_CRUFT_{OBJ,OBJS}
+__SXE_MAKE_ADDER([CRUFT], [libcruft])
+
+dnl creates SXE_ADD_DB_{OBJ,OBJS}
+__SXE_MAKE_ADDER([DB], [libsxedb], [DB_CPPFLAGS DB_LDFLAGS DB_LIBS])
+
+dnl creates SXE_ADD_ENT_{OBJ,OBJS}
+__SXE_MAKE_ADDER([ENT], [libent])
+
+dnl creates SXE_ADD_EVENTS_{OBJ,OBJS}
+__SXE_MAKE_ADDER([EVENTS], [libsxeevents])
+
+dnl creates SXE_ADD_MEMALLOC_{OBJ,OBJS}
+__SXE_MAKE_ADDER([MEMALLOC], [libmemalloc])
+
+dnl creates SXE_ADD_MM_{OBJ,OBJS}
+__SXE_MAKE_ADDER([MM], [libmm])
+
+dnl creates SXE_ADD_MULE_{OBJ,OBJS}
+__SXE_MAKE_ADDER([MULE], [libmule])
+
+dnl creates SXE_ADD_SXEUI_{OBJ,OBJS}
+__SXE_MAKE_ADDER([SXEUI], [libsxeui])
+
+
+dnl SXE_ADD_STATMOD_A(foo.o ...)
+AC_DEFUN([SXE_ADD_STATMOD_A], [
+	statmod_archives="$statmod_archives [$1]" && \
+	if test "$extra_verbose" = "yes"; then
+		echo "    sxemacs (cat. static module) will be linked with \"[$1]\""
+	fi
+])dnl SXE_ADD_STATMOD_A
+AC_DEFUN([SXE_SUBST_STATMOD_A], [AC_SUBST(statmod_archives)])
+
+dnl SXE_APPEND(value, varname)
+AC_DEFUN([SXE_APPEND],
+[[$2]="$[$2] [$1]" && dnl
+ if test "$extra_verbose" = "yes"; then echo "    Appending \"[$1]\" to \$[$2]"; fi])
+
+dnl SXE_PREPEND(value, varname)
+AC_DEFUN([SXE_PREPEND],
+[[$2]="[$1] $[$2]" && dnl
+ if test "$extra_verbose" = "yes"; then echo "    Prepending \"[$1]\" to \$[$2]"; fi])
+
+dnl SXE_DIE(message)
+AC_DEFUN([SXE_DIE], [{ echo "Error:" $1 >&2; exit 1; }])
+
+
+dnl some helpers
+AC_DEFUN([SXE_INIT_MSG_LEVEL], [
+	sxe_msg_level=0
+])dnl SXE_INIT_MSG_LEVEL
+
+AC_DEFUN([SXE_MSG_CHECKING], [
+	## like AC_MSG_CHECKING but nestable
+	if test "$sxe_msg_level" -le 0; then
+		AC_MSG_CHECKING([$1])
+	fi
+	sxe_msg_level=$(($sxe_msg_level + 1))
+])dnl SXE_MSG_CHECKING
+
+AC_DEFUN([SXE_MSG_RESULT], [
+	## like AC_MSG_RESULT but nestable
+	sxe_msg_level=$(($sxe_msg_level - 1))
+	if test "$sxe_msg_level" -le 0; then
+		AC_MSG_RESULT([$1])
+	fi
+])dnl SXE_MSG_RESULT
+
+dnl SXE_CHECK_FEATURE_DEPENDENCY(feature1, feature2)
+AC_DEFUN([SXE_CHECK_FEATURE_DEPENDENCY],
+[if test "$with_$1 $with_$2" = "yes no"; then
+	SXE_USAGE_ERROR("--with-$1 requires --with-$2")
+elif test "$with_$2" = "no" ; then with_$1=no
+elif test "$with_$1" = "yes"; then with_$2=yes
+fi
+])
+
+dnl SXE_STRIP_4TH_COMPONENT(var)
+dnl Changes i986-pc-linux-gnu to i986-pc-linux, as God (not RMS) intended.
+AC_DEFUN([SXE_STRIP_4TH_COMPONENT],
+[$1=`echo "$$1" | sed '[s/^\([^-][^-]*-[^-][^-]*-[^-][^-]*\)-.*$/\1/]'`])
+
+dnl AC_DEFUN([SXE_DEBUG_AC], [AS_MESSAGE($@)])
+AC_DEFUN([SXE_DEBUG_AC], [])
+
+dnl Do our best to deal with automounter brokenness
+dnl SXE_CANONICALISE_PATH(varname)
+AC_DEFUN([SXE_CANONICALISE_PATH], [dnl
+	## arg #1 is the file/path to canonicalise
+	pushdef([tmpp], [$1])
+
+	SXE_DEBUG_AC([canonicalising \$]tmpp[: "]$[]tmpp["])
+
+	if test -d "/net"; then
+		if test -d "/tmp_mnt/net"; then
+			tdir="tmp_mnt/net";
+		else
+			tdir="tmp_mnt";
+		fi
+		tmpp[]=$(echo "[$]tmpp[]" | \
+			sed -e "s|^${tdir}/|/net/|" \
+			    -e "s|^/a/|/net/|" \
+			    -e "s|^/amd/|/net/|")
+	fi
+
+dnl 	if test -d "[$]tmpp"; then
+dnl 		## the easy way ...
+dnl 		## just let the filesystem implementation do the hard work
+dnl 		tmpp[]=$(cd [$]tmpp[] && echo $(pwd))
+dnl 	elif test -f "[$]tmpp"; then
+dnl 		## the easy way ...
+dnl 		## just let the filesystem implementation do the hard work
+dnl 		tmpp[]=$(cd $(dirname [$]tmpp[]) && \
+dnl 			echo $(pwd)/$(basename [$]tmpp[]))
+dnl 	else
+		## simple magic
+		canonicalised="no"
+		while test "$canonicalised" = "no"; do
+			_SXE_CANONICALISE_STEP(tmpp,
+				[canonicalised="yes"], [canonicalised="no"])
+		done
+dnl	fi
+
+	SXE_DEBUG_AC([canonicalised \$]tmpp[: "]$[]tmpp["])
+	popdef([tmpp])
+])dnl SXE_CANONICALISE_PATH
+
+AC_DEFUN([_SXE_CANONICALISE_STEP], [
+	## _SXE_CANONICALISE_STEP( VAR, DO-ON-SUCCESS, DO-ON-FAILURE)
+	## arg #1 is the varname to canonicalise
+	## arg #2 is the code to execute on success
+	## arg #3 is the code to execute on failure
+	pushdef([tmpvar], [$1])
+	pushdef([dosucc], [$2])
+	pushdef([dofail], [$3])
+
+	tmp2=[$]tmpvar
+	tmp3=
+	tmp4=$(basename "$tmp2")
+	## assume we had success
+	dosucc
+	while test "$tmp4" != "/" -a "$tmp4" != "."; do
+		if test "$tmp4" = ".." -a \
+			$(basename $(dirname "$tmp2")) = "."; then
+			## we prepend and we know the path
+			## is still dirty but wont do anything
+			## alternative would be to prepend $(pwd) now
+			dosucc
+			tmp3="$(basename $tmp2)/$tmp3"
+		elif test "$tmp4" = ".." -a \
+			$(basename $(dirname "$tmp2")) != ".."; then
+			tmp2=$(dirname "$tmp2")
+		elif test "$tmp4" = ".."; then
+			## we prepend, but now we know the path
+			## is still dirty
+			dofail
+			tmp3="$(basename $tmp2)/$tmp3"
+		elif test -n "$tmp3"; then
+			## ordinary component, just prepend
+			tmp3="$(basename $tmp2)/$tmp3"
+		else
+			## just set
+			tmp3="$(basename $tmp2)"
+		fi
+		tmp2=$(dirname "$tmp2")
+		tmp4=$(basename "$tmp2")
+	done
+
+	tmp3="$tmp4/$tmp3"
+	tmpvar[]=$(echo "$tmp3" | sed -e "s@//@/@g")
+
+	popdef([tmpvar])
+	popdef([dosucc])
+	popdef([dofail])
+])dnl _SXE_CANONICALISE_STEP
+
+
+dnl SXE_PROTECT_LINKER_FLAGS(shell_var)
+AC_DEFUN([SXE_PROTECT_LINKER_FLAGS], [
+if test "$GCC" = "yes"; then
+  set x $[$1]; shift; [$1]=""
+  while test -n "[$]1"; do
+    case [$]1 in
+      -L  | -l  | -u               ) [$1]="$[$1] [$]1 [$]2"; shift ;;
+      -L* | -l* | -u* | -Wl* | -pg ) [$1]="$[$1] [$]1" ;;
+      -Xlinker* ) ;;
+      * ) [$1]="$[$1] -Xlinker [$]1" ;;
+    esac
+    shift
+  done
+fi])dnl
+
+
+dnl Allow use of either ":" or spaces for lists of directories
+AC_DEFUN([SXE_COLON_TO_SPACE],
+  [case "$[$1]" in *:* [)] [$1]="`echo '' $[$1] | sed -e 's/^ //' -e 's/:/ /g'`";; esac])dnl
+
+
+dnl The construct foo=`echo $w1 $w2 $w3` fails on some systems if $w1 = -e or -n
+dnl So we use the following instead.
+dnl SXE_SPACE(var, words)
+AC_DEFUN([SXE_SPACE],[
+T=""
+for W in $2; do if test -z "$T"; then T="$W"; else T="$T $W"; fi; done
+$1="$T"
+])dnl SXE_SPACE
+
+
+
+AC_DEFUN([SXE_LANG_WERROR], [dnl
+	dnl like AC_LANG_WERROR but working
+	dnl call goes: SXE_LANG_WERROR([on|off|push|pop|push+off|push+on])
+
+	pushdef([tmppush], [
+		if test -n "$ac_c_werror_flag"; then
+			sxe_cv_aux_werror_stack="on $sxe_cv_aux_werror_stack"
+		else
+			sxe_cv_aux_werror_stack="off $sxe_cv_aux_werror_stack"
+		fi
+		])
+	pushdef([tmpon], [ac_c_werror_flag="-Werror"])
+	pushdef([tmpoff], [ac_c_werror_flag=""])
+
+	m4_if([$1], [on], [tmpon])
+
+	m4_if([$1], [off], [tmpoff])
+
+	m4_if([$1], [push], [tmppush])
+	m4_if([$1], [push+off], [
+		tmppush
+		tmpoff
+		])
+	m4_if([$1], [push+on], [
+		tmppush
+		tmpon
+		])
+
+	m4_if([$1], [pop], [
+		## thanks for the tip, Aidan
+		$(echo $sxe_cv_aux_werror_stack | \
+			read sxe_cv_tmp_stackcar sxe_cv_aux_werror_stack)
+		if test "$sxe_cv_tmp_stackcar" = "on"; then
+			tmpon
+		elif test "$sxe_cv_tmp_stackcar" = "off"; then
+			tmpoff
+		else
+			## rather turn it off than on, dont ya think?
+			tmpoff
+		fi
+		])
+
+])dnl SXE_LANG_WERROR
+
+
+AC_DEFUN([SXE_DUMP_LIBS], [
+	save_c_switch_site="$c_switch_site"
+	save_LIBS="$LIBS"
+	save_ld_switch_site="$ld_switch_site"
+	save_ld_switch_machine="$ld_switch_machine"
+	save_CC="$CC"
+	save_CFLAGS="$CFLAGS"
+	save_CPPFLAGS="$CPPFLAGS"
+	save_LDFLAGS="$LDFLAGS"
+
+	SXE_LANG_WERROR([push])
+])dnl SXE_DUMP_LIBS
+
+AC_DEFUN([SXE_RESTORE_LIBS], [
+	LIBS="$save_LIBS"
+	c_switch_site="$save_c_switch_site"
+	ld_switch_site="$save_ld_switch_site"
+	ld_switch_machine="$save_ld_switch_machine"
+	CC="$save_CC"
+	CFLAGS="$save_CFLAGS"
+	CPPFLAGS="$save_CPPFLAGS"
+	LDFLAGS="$save_LDFLAGS"
+
+	SXE_LANG_WERROR([pop])
+])dnl SXE_RESTORE_LIBS
+
+AC_DEFUN([SXE_SEARCH_CONFIG_PROG], [
+	## arg #1 program to search
+	pushdef([config_prog], [$1])
+	pushdef([have_config_prog], [have_]translit([$1], [-.], [__]))
+	pushdef([CONFIG_PROG], translit([$1], [-.a-z], [__A-Z]))
+	AC_CHECK_PROG(have_config_prog, config_prog, [yes], [no])
+	AC_PATH_PROG(CONFIG_PROG, config_prog, [echo])
+	popdef([config_prog])
+	popdef([have_config_prog])
+	popdef([CONFIG_PROG])
+])dnl SXE_SEARCH_CONFIG_PROG
+
+
+AC_DEFUN([_SXE_CHECK_pkgconfig_based], [
+	## assumes $PKG_CONFIG is defined
+	## arg #1: MM param name
+	## arg #2: lib to check
+	## arg #3: version of that lib
+
+	pushdef([IO_LIB], [$1])
+
+	AC_REQUIRE([SXE_CHECK_PKGCONFIG])
+
+	AC_MSG_CHECKING([for ]IO_LIB[ support])
+	AC_MSG_RESULT([])
+
+	if test "$have_pkg_config" = "no" -o -z "$PKG_CONFIG"; then
+		AS_MESSAGE([*** pkg-config not found. See http://pkgconfig.sourceforge.net])
+		AS_MESSAGE([*** Cannot check for ]IO_LIB[.])
+		have_pkg_config=no
+		PKG_CONFIG=
+	fi
+
+	pushdef([IO_MOD], [$2])
+	pushdef([IO_MOD_REQUIRED_VERSION], [$3])
+	AC_MSG_CHECKING([whether ]IO_MOD[ is at least ]IO_MOD_REQUIRED_VERSION)
+	if test -n "$PKG_CONFIG" && \
+	     $PKG_CONFIG --atleast-version IO_MOD_REQUIRED_VERSION IO_MOD; then
+		IO_LIB[]_version=`$PKG_CONFIG --modversion []IO_MOD[]`
+		AC_MSG_RESULT([yes ($]IO_LIB[_version)])
+		have_[]IO_LIB[]_pkg="yes"
+		## define some useful variables
+		IO_LIB[]_libs=`$PKG_CONFIG --libs []IO_MOD[]`
+		IO_LIB[]_libs_L=`$PKG_CONFIG --libs-only-L []IO_MOD[]`
+		IO_LIB[]_libs_l=`$PKG_CONFIG --libs-only-l []IO_MOD[]`
+		IO_LIB[]_libs_other=`$PKG_CONFIG --libs-only-other []IO_MOD[]`
+		IO_LIB[]_cflags=`$PKG_CONFIG --cflags []IO_MOD[]`
+		IO_LIB[]_cflags_I=`$PKG_CONFIG --cflags-only-I []IO_MOD[]`
+		IO_LIB[]_cflags_other=`$PKG_CONFIG --cflags-only-other []IO_MOD[]`
+	elif test -n "$PKG_CONFIG"; then
+		IO_LIB[]_version=`$PKG_CONFIG --modversion []IO_MOD[]`
+		AC_MSG_RESULT([no ($]IO_LIB[_version)])
+		have_[]IO_LIB[]_pkg="no"
+	else
+		have_[]IO_LIB[]_pkg="uncertain"
+		AC_MSG_RESULT([$have_]IO_LIB[])
+	fi
+	popdef([IO_LIB])
+	popdef([IO_MOD_REQUIRED_VERSION])
+	popdef([IO_MOD])
+])dnl _SXE_CHECK_pkgconfig_based
+
+AC_DEFUN([_SXE_MM_CHECK_pkgconfig_based], [
+	## assumes $PKG_CONFIG is defined
+	## arg #1: MM param name
+	## arg #2: lib to check
+	## arg #3: version of that lib
+	## arg #4: funs to check
+	## arg #5: headers to check
+	## arg #6: success action
+	## arg #7: failure action
+
+	pushdef([MM_LIB], [$1])
+	pushdef([MM_SUCC], [$6])
+	pushdef([MM_FAIL], [$7])
+
+	AC_REQUIRE([SXE_CHECK_PKGCONFIG])
+
+	AC_MSG_CHECKING([for ]MM_LIB[ support])
+	AC_MSG_RESULT([])
+
+	if test "$have_pkg_config" = "no" -o -z "$PKG_CONFIG"; then
+		AS_MESSAGE([*** pkg-config not found. See http://pkgconfig.sourceforge.net])
+		AS_MESSAGE([*** Cannot check for ]MM_LIB[.])
+		have_pkg_config=no
+		PKG_CONFIG=
+		MM_FAIL
+	fi
+
+	pushdef([MM_MOD], [$2])
+	pushdef([MM_MOD_REQUIRED_VERSION], [$3])
+	pushdef([MM_MOD_FUNS], [$4])
+	pushdef([MM_MOD_HDRS], [$5])
+	AC_MSG_CHECKING([whether ]MM_MOD[ is at least ]MM_MOD_REQUIRED_VERSION)
+	if test -n "$PKG_CONFIG" && \
+	     $PKG_CONFIG --atleast-version MM_MOD_REQUIRED_VERSION MM_MOD; then
+		actual_version=`$PKG_CONFIG --modversion []MM_MOD[]`
+		AC_MSG_RESULT([yes ($actual_version)])
+		AC_MSG_CHECKING([for ]mm_lib[ libraries])
+		MM_MOD_LIBS_L=`$PKG_CONFIG --libs-only-l []MM_MOD[]`
+		MM_MOD_LIBS=`echo $MM_MOD_LIBS_L | sed -e "s/-l//g"`
+		MM_MOD_LIB=`echo $MM_MOD_LIBS | sed -e "s/ .*$//"`
+		MM_MOD_OTHER_LIBS=`echo $MM_MOD_LIBS_L | sed -e "s/^[^ ]*//"`
+		AC_MSG_RESULT([$MM_MOD_LIBS])
+
+		## backup our site flags
+		SXE_DUMP_LIBS
+		MM_MOD_LIBS_SITE=`$PKG_CONFIG --libs-only-L []MM_MOD[]`
+		MM_MOD_HDRS_SITE=`$PKG_CONFIG --cflags-only-I []MM_MOD[]`
+		SXE_PREPEND([$MM_MOD_HDRS_SITE], [CPPFLAGS])
+		SXE_PREPEND([$MM_MOD_LIBS_SITE], [LDFLAGS])
+
+		MM_SUCC
+		SXE_CHECK_HEADERS([]MM_MOD_HDRS[], [:], [MM_FAIL])
+		for i in MM_MOD_FUNS; do
+			AC_CHECK_LIB([$MM_MOD_LIB], [$i], [:], [MM_FAIL],
+				[$MM_MOD_LIBS_L])
+		done
+
+		## restore old values
+		SXE_RESTORE_LIBS
+	elif test -n "$PKG_CONFIG"; then
+		actual_version=`$PKG_CONFIG --modversion []MM_MOD[]`
+		AC_MSG_RESULT([no ($actual_version)])
+	else
+		AC_MSG_RESULT([uncertain])
+	fi
+	popdef([MM_LIB])
+	popdef([MM_MOD_FUNS])
+	popdef([MM_MOD_HDRS])
+	popdef([MM_MOD_REQUIRED_VERSION])
+	popdef([MM_MOD])
+	popdef([MM_SUCC])
+	popdef([MM_FAIL])
+])dnl _SXE_MM_CHECK_pkgconfig_based
+
+
+AC_DEFUN([SXE_CHECK_SUFFICIENCY], [dnl
+	## arg #1 is the option to check sufficiency on
+	## arg #2 is a description
+	## arg #3 are additional actions to perform when support is sufficient
+	## arg #4 are additional actions to perform when support is insufficient
+	pushdef([og_group], translit([$1], [-], [_]))
+	pushdef([og_descr], [$2])
+	pushdef([OG_GROUP], translit([$1], [-a-z], [_A-Z]))
+	pushdef([IF_YES_DO], [$3])
+	pushdef([IF_NO_DO], [$4])
+
+	tmp=${[have_]og_group[]-uncertain}
+	if test "$with_[]og_group" != "no"; then
+		AC_MSG_CHECKING([for sufficient ]og_descr[ support])
+		AC_MSG_RESULT([$tmp])
+		if test "$tmp" = "yes"; then
+			AC_DEFINE([HAVE_]OG_GROUP, [1],
+				[Whether ]og_descr[ is doable])
+			:
+			IF_YES_DO
+		else
+			:
+			IF_NO_DO
+		fi
+	else
+		:
+		IF_NO_DO
+	fi
+	AM_CONDITIONAL([HAVE_]OG_GROUP,
+		[test "$have_[]og_group" = "yes" -a "$with_[]og_group" != "no"])
+	popdef([og_group])
+	popdef([og_descr])
+	popdef([OG_GROUP])
+	popdef([IF_YES_DO])
+	popdef([IF_NO_DO])
+])dnl SXE_CHECK_SUFFICIENCY
+
+
+AC_DEFUN([SXE_CHECK_HEADERS], [dnl
+	dnl One day, this macro will only check for headers if
+	dnl their presence is yet unknown
+	AC_CHECK_HEADERS($1,$2,$3,$4)
+])dnl SXE_CHECK_HEADERS
+
+AC_DEFUN([SXE_CHECK_LIB_FUNCS], [dnl
+	pushdef([SXE_LIB], [$1])
+	pushdef([SXE_FUNCS], [$2])
+
+	for i in SXE_LIB; do
+		for j in SXE_FUNCS; do
+			AC_CHECK_LIB([$i], [$j], [:], [:])
+		done
+	done
+
+	popdef([SXE_LIB])
+	popdef([SXE_FUNCS])
+])dnl SXE_CHECK_LIB_FUNCS
+
+
+AC_DEFUN([_SXE_CHECK_PURE_OPT], [dnl
+	unq_opt=$(echo $1 | tr -d "'\"")
+
+	case "$unq_opt" in
+	## first autoconf's options
+	--enable-largefile | --disable-largefile | \
+	--enable-dependency-tracking | --disable-dependency-tracking | \
+	--enable-option-checking | --disable-option-checking | \
+	--with-x | --x-includes | --x-libraries | \
+	--build | --host | \
+	--program-prefix | --program-suffix | --program-transform-name | \
+	--prefix | --exec-prefix | --bindir | --sbindir | \
+	--libexecdir | --sysconfdir | \
+	--sharedstatedir | --localstatedir | \
+	--libdir | --includedir | --oldincludedir | \
+	--datarootdir | --datadir | --infodir | --localedir | \
+	--mandir | --docdir | --htmldir | --dvidir | --pdfdir | --psdir | \
+	-n | --no-create | -C | --config-cache | --cache-file | \
+	-q | --quiet | --silent | --version )
+		AC_MSG_CHECKING([if option $1 is known])
+		AC_MSG_RESULT([yes])
+		;;
+
+	## now the hard-coded libtool ones
+	--enable-ltdl-install | --disable-ltdl-install | \
+	--enable-ltdl-convenience | --disable-ltdl-convenience | \
+	--enable-libtool-lock | --disable-libtool-lock | \
+	--enable-fast-install | --disable-fast-install | \
+	--enable-shared | --disable-shared | \
+	--enable-static | --disable-static | \
+	--with-gcc-arch | --with-pic | --with-included-ltdl )
+		AC_MSG_CHECKING([if option $1 is known])
+		AC_MSG_RESULT([yes])
+		;;
+
+	## now our own stuff
+	--enable-* | --disable-* )
+		AC_MSG_CHECKING([if option $1 is known])
+		strp_opt=$(echo $unq_opt | \
+			sed -e "s/^--enable-//g" -e "s/^--disable-//g")
+		OG_CHECK_OPTION([enable], [$strp_opt],
+			AC_MSG_RESULT([yes]),
+			AC_MSG_RESULT([no])
+			[bogus_cmd_opts="$bogus_cmd_opts $unq_opt"])
+		;;
+	## more of our own
+	--with-* | --without-* )
+		AC_MSG_CHECKING([if option $1 is known])
+		strp_opt=$(echo $unq_opt | \
+			sed -e "s/^--with-//g" -e "s/^--without-//g")
+		OG_CHECK_OPTION([with], [$strp_opt],
+			AC_MSG_RESULT([yes]),
+			AC_MSG_RESULT([no])
+			[bogus_cmd_opts="$bogus_cmd_opts $unq_opt"])
+		;;
+
+	## strange constructions
+	-* )
+		case "$1" in
+		\'-*)
+			AC_MSG_CHECKING([if option $1 is known])
+			AC_MSG_RESULT([no])
+			bogus_cmd_opts="$bogus_cmd_opts $unq_opt"
+			;;
+		esac
+		;;
+	## rest goes here
+	* )
+		## whatever that is
+		;;
+	esac
+])dnl _SXE_CHECK_PURE_OPT
+
+AC_DEFUN([SXE_CHECK_COMMAND_LINE], [dnl
+	dnl Check for bogus options
+	sxe_with_options="$sxe_with_options x"
+	cmd_line_args="$ac_configure_args"
+
+	## make sure our bogus stuff is empty once we get into here
+	## this allows us to call this stuff more than once
+	## (which never happens of course)
+	bogus_cmd_opts=""
+
+	for opt in $cmd_line_args; do
+		pure_opt=$(echo $opt | sed -e "s/=.*$//g")
+		_SXE_CHECK_PURE_OPT([$pure_opt])
+	done
+
+	dnl Final command line argument checks.
+	dnl --with-quantify or --with-purify imply --with-system-malloc
+	if test "$with_purify" = "yes" -o "$with_quantify" = "yes"; then
+		if test "$with_system_malloc" = "default"; then
+			with_system_malloc="yes"
+		fi
+	fi
+])dnl SXE_CHECK_COMMAND_LINE
+
+
+AC_DEFUN([SXE_EXPAND_VAR], [dnl
+	## arg #1 the variable to expand
+	## arg #2 (optional) the variable to put the result in
+	pushdef([VAR], [$1])
+	pushdef([RES], ifelse($2,[],[sxe_cv_tmp_expand_var],$2))
+
+	RES=[]VAR[]
+	__tmp=
+	while test "${RES}" != "${__tmp}"; do
+		__tmp=${RES}
+		RES=$(eval echo ${__tmp})
+	done
+	popdef([RES])
+	popdef([VAR])
+])dnl SXE_EXPAND_VAR
+
+
+dnl sxe-aux.m4 ends here

m4/sxe-compiler.m4

+dnl compiler.m4 --- compiler magic
+dnl
+dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
+dnl Copyright (c) 2005 Steven G. Johnson
+dnl Copyright (c) 2005 Matteo Frigo
+dnl
+dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
+dnl
+dnl Redistribution and use in source and binary forms, with or without
+dnl modification, are permitted provided that the following conditions
+dnl are met:
+dnl
+dnl 1. Redistributions of source code must retain the above copyright
+dnl    notice, this list of conditions and the following disclaimer.
+dnl
+dnl 2. Redistributions in binary form must reproduce the above copyright
+dnl    notice, this list of conditions and the following disclaimer in the
+dnl    documentation and/or other materials provided with the distribution.
+dnl
+dnl 3. Neither the name of the author nor the names of any contributors
+dnl    may be used to endorse or promote products derived from this
+dnl    software without specific prior written permission.
+dnl
+dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
+dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+dnl DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+dnl
+dnl This file is part of SXEmacs.
+
+AC_DEFUN([SXE_DEBUGFLAGS], [dnl
+	## distinguish between different compilers, no?
+	SXE_CHECK_COMPILER_FLAGS([-g])
+	SXE_CHECK_COMPILER_FLAGS([-g3])
+
+	AC_PATH_PROG([DBX], [dbx])
+	if test -n "$ac_cv_path_DBX"; then
+		SXE_CHECK_COMPILER_FLAGS([-gstabs])
+		SXE_CHECK_COMPILER_FLAGS([-gstabs3])
+		SXE_CHECK_COMPILER_FLAGS([-gxcoff])
+		SXE_CHECK_COMPILER_FLAGS([-gxcoff3])
+	fi
+
+	AC_PATH_PROG([GDB], [gdb])
+	if test -n "$ac_cv_path_GDB"; then
+		SXE_CHECK_COMPILER_FLAGS([-ggdb])
+		SXE_CHECK_COMPILER_FLAGS([-ggdb3])
+	fi
+
+	AC_PATH_PROG([SDB], [sdb])
+	if test -n "$ac_cv_path_SDB"; then
+		SXE_CHECK_COMPILER_FLAGS([-gcoff])
+		SXE_CHECK_COMPILER_FLAGS([-gcoff3])
+	fi
+
+	## final evaluation
+	debugflags=""
+	## gdb
+	if test "$sxe_cv_c_flags__ggdb3" = "yes"; then
+		debugflags="$debugflags -ggdb3"
+	elif test "$sxe_cv_c_flags__ggdb" = "yes"; then
+		debugflags="$debugflags -ggdb"
+	fi
+	## stabs
+	if test "$sxe_cv_c_flags__gstabs3" = "yes"; then
+		debugflags="$debugflags -gstabs3"
+	elif test "$sxe_cv_c_flags__gstabs" = "yes"; then
+		debugflags="$debugflags -gstabs"
+	fi
+	## coff
+	if test "$sxe_cv_c_flags__gcoff3" = "yes"; then
+		debugflags="$debugflags -gcoff3"
+	elif test "$sxe_cv_c_flags__gcoff" = "yes"; then
+		debugflags="$debugflags -gcoff"
+	fi
+	## xcoff
+	if test "$sxe_cv_c_flags__gxcoff3" = "yes"; then
+		debugflags="$debugflags -gxcoff3"
+	elif test "$sxe_cv_c_flags__gxcoff" = "yes"; then
+		debugflags="$debugflags -gxcoff"
+	fi
+
+	if test -z "debugflags" -a \
+		"$sxe_cv_c_flags__g" = "yes"; then
+		debugflags="$debugflags -g"
+	fi
+
+	SXE_CHECK_COMPILER_FLAGS([-ftime-report])
+	SXE_CHECK_COMPILER_FLAGS([-fmem-report])
+	SXE_CHECK_COMPILER_FLAGS([-fvar-tracking])
+	SXE_CHECK_COMPILER_FLAGS([-save-temps])
+
+	#if test "$sxe_cv_c_flags__ggdb3" = "yes" -a \
+	#	"$sxe_cv_c_flags__fvar_tracking" = "yes"; then
+	#	debugflags="$debugflags -fvar-tracking"
+	#fi
+
+	AC_MSG_CHECKING([for preferred debugging flags])
+	AC_MSG_RESULT([${debugflags}])
+])dnl SXE_DEBUGFLAGS
+
+AC_DEFUN([SXE_WARNFLAGS], [dnl
+	## Calculate warning flags.  We separate the flags for warnings from
+	## the other flags because we want to force the warnings to be seen
+	## by everyone who doesn't specifically override them.
+
+	## by default we want the -Wall level
+	SXE_CHECK_COMPILER_FLAGS([-Wall], [warnflags="-Wall"])
+
+	## Yuck, bad compares have been worth at
+	## least 3 crashes!
+	## Warnings about char subscripts are pretty
+	## pointless, though,
+	## and we use them in various places.
+	SXE_CHECK_COMPILER_FLAGS([-Wsign-compare], [
+		warnflags="$warnflags -Wsign-compare"])
+	SXE_CHECK_COMPILER_FLAGS([-Wno-char-subscripts], [
+		warnflags="$warnflags -Wno-char-subscripts"])
+	SXE_CHECK_COMPILER_FLAGS([-Wundef], [
+		warnflags="$warnflags -Wundef"])
+
+	## too much at the moment, we rarely define protos
+	#warnflags="$warnflags -Wmissing-prototypes -Wstrict-prototypes"
+	SXE_CHECK_COMPILER_FLAGS([-Wpacked], [
+		warnflags="$warnflags -Wpacked"])
+
+	## glibc is intentionally not `-Wpointer-arith'-clean.
+	## Ulrich Drepper has rejected patches to fix
+	## the glibc header files.
+	## we dont care
+	SXE_CHECK_COMPILER_FLAGS([-Wpointer-arith], [
+		warnflags="$warnflags -Wpointer-arith"])
+
+	SXE_CHECK_COMPILER_FLAGS([-Wshadow], [
+		warnflags="$warnflags -Wshadow"])
+
+	## our code lacks declarations almost all the time
+	SXE_CHECK_COMPILER_FLAGS([-Wmissing-declarations], [
+		warnflags="$warnflags -Wmissing-declarations"])
+	SXE_CHECK_COMPILER_FLAGS([-Wmissing-prototypes], [
+		warnflags="$warnflags -Wmissing-prototypes"])
+	SXE_CHECK_COMPILER_FLAGS([-Winline], [
+		warnflags="$warnflags -Winline"])
+	SXE_CHECK_COMPILER_FLAGS([-Wbad-function-cast], [
+		warnflags="$warnflags -Wbad-function-cast"])
+	SXE_CHECK_COMPILER_FLAGS([-Wcast-qual], [
+		warnflags="$warnflags -Wcast-qual"])
+	SXE_CHECK_COMPILER_FLAGS([-Wcast-align], [
+		warnflags="$warnflags -Wcast-align"])
+
+	## warn about incomplete switches
+	SXE_CHECK_COMPILER_FLAGS([-Wswitch], [
+		warnflags="$warnflags -Wswitch"])
+	SXE_CHECK_COMPILER_FLAGS([-Wswitch-default], [
+		warnflags="$warnflags -Wswitch-default"])
+	SXE_CHECK_COMPILER_FLAGS([-Wswitch-enum], [
+		warnflags="$warnflags -Wswitch-enum"])
+
+	SXE_CHECK_COMPILER_FLAGS([-Wunused-function], [
+		warnflags="$warnflags -Wunused-function"])
+	SXE_CHECK_COMPILER_FLAGS([-Wunused-variable], [
+		warnflags="$warnflags -Wunused-variable"])
+	SXE_CHECK_COMPILER_FLAGS([-Wunused-parameter], [
+		warnflags="$warnflags -Wunused-parameter"])
+	SXE_CHECK_COMPILER_FLAGS([-Wunused-value], [
+		warnflags="$warnflags -Wunused-value"])
+	SXE_CHECK_COMPILER_FLAGS([-Wunused], [
+		warnflags="$warnflags -Wunused"])
+
+	SXE_CHECK_COMPILER_FLAGS([-Wnopragma], [
+		warnflags="$warnflags -Wnopragma"])
+
+	SXE_CHECK_COMPILER_FLAGS([-fdiagnostics-show-option], [
+		warnflags="${warnflags} -fdiagnostics-show-option"])
+
+	SXE_CHECK_COMPILER_FLAGS([-Wunknown-pragmas], [
+		warnflags="$warnflags -Wunknown-pragmas"])
+	SXE_CHECK_COMPILER_FLAGS([-Wuninitialized], [
+		warnflags="$warnflags -Wuninitialized"])
+	SXE_CHECK_COMPILER_FLAGS([-Wreorder], [
+		warnflags="$warnflags -Wreorder"])
+	SXE_CHECK_COMPILER_FLAGS([-Wdeprecated], [
+		warnflags="$warnflags -Wdeprecated"])
+
+	SXE_CHECK_COMPILER_FLAGS([-w2], [
+		warnflags="$warnflags -w2"])
+
+	AC_MSG_CHECKING([for preferred warning flags])
+	AC_MSG_RESULT([${warnflags}])
+])dnl SXE_WARNFLAGS
+
+AC_DEFUN([SXE_OPTIFLAGS], [dnl
+	optiflags="-O3"
+])dnl SXE_OPTIFLAGS
+
+AC_DEFUN([SXE_FEATFLAGS], [dnl
+	## if libtool then
+	dnl XFLAG="-XCClinker"
+	## default flags for needed features
+	SXE_CHECK_COMPILER_FLAGS([-static-intel], [
+		ldflags="${ldflags} ${XFLAG} -static-intel"])
+	SXE_CHECK_COMPILER_FLAGS([-static-libgcc], [
+		ldflags="${ldflags} ${XFLAG} -static-libgcc"])
+])dnl SXE_FEATFLAGS
+
+
+##### http://autoconf-archive.cryp.to/ax_check_compiler_flags.html
+## renamed the prefix to SXE_
+AC_DEFUN([SXE_CHECK_COMPILER_FLAGS], [dnl
+dnl SXE_CHECK_COMPILER_FLAGS([flag], [do-if-works], [do-if-not-works])
+	AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1])
+
+	dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
+	SXE_LANG_WERROR([push+on])
+	AS_LITERAL_IF([$1], [
+		AC_CACHE_VAL(AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1), [
+			sxe_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
+			_AC_LANG_PREFIX[]FLAGS="$1"
+			AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+				AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="yes",
+				AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="no")
+			_AC_LANG_PREFIX[]FLAGS=$sxe_save_FLAGS])], [
+		sxe_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
+		_AC_LANG_PREFIX[]FLAGS="$1"
+		AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+			eval AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="yes",
+			eval AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)="no")
+		_AC_LANG_PREFIX[]FLAGS=$sxe_save_FLAGS])
+	eval sxe_check_compiler_flags=$AS_TR_SH(sxe_cv_[]_AC_LANG_ABBREV[]_flags_$1)
+	SXE_LANG_WERROR([pop])
+
+	AC_MSG_RESULT([$sxe_check_compiler_flags])
+	if test "$sxe_check_compiler_flags" = "yes"; then
+		m4_default([$2], :)
+	else
+		m4_default([$3], :)
+	fi
+])dnl SXE_CHECK_COMPILER_FLAGS
+
+
+AC_DEFUN([SXE_CHECK_CFLAGS], [dnl
+	dnl #### This may need to be overhauled so that all of SXEMACS_CC's flags
+	dnl are handled separately, not just the xe_cflags_warning stuff.
+
+	## Use either command line flag, environment var, or autodetection
+	SXE_DEBUGFLAGS
+	SXE_WARNFLAGS
+	SXE_OPTIFLAGS
+	SXE_FEATFLAGS
+	SXE_CFLAGS="$debugflags $featflags $optiflags $warnflags"
+
+	## unset the werror flag again
+	SXE_LANG_WERROR([off])
+
+	CFLAGS="$SXE_CFLAGS ${ac_cv_env_CFLAGS_value}"
+	AC_MSG_CHECKING([for preferred CFLAGS])
+	AC_MSG_RESULT([${CFLAGS}])
+
+	AC_MSG_NOTICE([
+If you wish to ADD your own flags you want to stop here and rerun the
+configure script like so:
+  configure CFLAGS=<to-be-added-flags>
+
+You can always override the determined CFLAGS, partially or totally,
+using
+  make -C <directory> CFLAGS=<your-own-flags> [target]
+or
+  make CFLAGS=<your-own-flags> [target]
+respectively
+		])
+
+	LDFLAGS="${ldflags} ${ac_cv_env_LDFLAGS_value}"
+	AC_MSG_CHECKING([for preferred LDFLAGS])
+	AC_MSG_RESULT([${LDFLAGS}])
+
+])dnl SXE_CHECK_CFLAGS
+
+AC_DEFUN([SXE_CHECK_CC], [dnl
+	for i in "gnu1x" "c1x" "gnu99" "c99"; do
+		SXE_CHECK_COMPILER_FLAGS([-std="${i}"], [
+			std="-std=${i}"
+			break
+		])
+	done
+
+	AC_MSG_CHECKING([for preferred CC std])
+	AC_MSG_RESULT([${std}])
+	CC="${CC} ${std}"
+])dnl SXE_CHECK_CC
+
+dnl sxe-compiler.m4 ends here
 ddiff_LDFLAGS = $(AM_LDFLAGS)
 BUILT_SOURCES += ddiff-clo.c ddiff-clo.h
 
+bin_PROGRAMS += dgrep
+dgrep_SOURCES = dgrep.c dgrep-clo.ggo
+dgrep_CPPFLAGS = $(AM_CPPFLAGS) $(DT_INCLUDES)
+dgrep_LDFLAGS = $(AM_LDFLAGS)
+BUILT_SOURCES += dgrep-clo.c dgrep-clo.h
+
 bin_PROGRAMS += tseq
 tseq_SOURCES = tseq.c tseq-clo.ggo
 tseq_CPPFLAGS = $(AM_CPPFLAGS) $(DT_INCLUDES)
 
 
 /* error messages, warnings, etc. */
-static void
+static void __attribute__((unused))
 dt_io_warn_strpd(const char *inp)
 {
 	fprintf(stderr, "\

src/dgrep-clo.ggo

+args "--unamed-opts --long-help"
+package "dgrep"
+usage "dgrep [OPTION]... DATE"
+description "Grep DATE in stdin.
+DATE may be prefixed with an operator \
+`<', `<=', '=', '>=', '>', `!=', `<>' \
+meaning, also find lines whose dates are older, older-equal, equal, \
+newer-equal, newer, or not equal respectively.  By default dgrep looks
+for equality."
+
+QUIET
+INPUT_FORMAT
+BACKSLASH_ESCAPES
+
+option "only-matching" o
+	"Show only the part of a line matching DATE."
+	optional
+
+defgroup "op" groupdesc="Operations can be specified by options as well"
+
+groupoption "eq" -
+	"DATE1 is the same as DATE2"
+	group="op"
+
+groupoption "ne" -
+	"DATE1 is not the same as DATE2"
+	group="op"
+
+groupoption "gt" -
+	"DATE1 is newer than DATE2"
+	group="op"
+
+groupoption "lt" -
+	"DATE1 is older than DATE2"
+	group="op"
+
+groupoption "ge" -
+	"DATE1 is newer than or equals DATE2"
+	group="op"
+
+groupoption "le" -
+	"DATE1 is older than or equals DATE2"
+	group="op"
+
+## convenience
+groupoption "nt" -
+	"DATE1 is newer than DATE2"
+	group="op"
+
+groupoption "ot" -
+	"DATE1 is older than DATE2"
+	group="op"
+/*** dgrep.c -- grep for lines with dates
+ *
+ * Copyright (C) 2011 Sebastian Freundt
+ *
+ * Author:  Sebastian Freundt <freundt@ga-group.nl>
+ *
+ * This file is part of dateutils.
+ *
+ * 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. Neither the name of the author nor the names of any contributors
+ *    may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ **/
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/time.h>
+#include <time.h>
+#include "date-core.h"
+#include "date-io.h"
+
+typedef uint32_t oper_t;
+
+enum {
+	OP_UNK = 0,
+	/* bit 1 set */
+	OP_EQ,
+	/* bit 2 set */
+	OP_LT,
+	OP_LE,
+	/* bit 3 set */
+	OP_GT,
+	OP_GE,
+	/* bits 2 and 3 set */
+	OP_NE,
+	/* bits 1, 2 and 3 set */
+	OP_FUCKED,
+};
+
+
+static oper_t
+find_oper(const char *s, char **ep)
+{
+	oper_t res = OP_UNK;
+
+	switch (*s) {
+	default:
+		break;
+	case '<':
+		switch (*++s) {
+		default:
+			res = OP_LT;
+			break;
+		case '=':
+			res = OP_LE;
+			s++;
+			break;
+		case '>':
+			res = OP_NE;
+			s++;
+			break;
+		}
+		break;
+	case '>':
+		switch (*++s) {
+		default:
+			res = OP_GT;
+			break;
+		case '=':
+			res = OP_GE;
+			s++;
+			break;
+		}
+		break;
+	case '=':
+		switch (*++s) {
+		case '=':
+			s++;
+		default:
+			res = OP_EQ;
+			break;
+		case '>':
+			res = OP_GE;
+			s++;
+			break;
+		}
+		break;
+	case '!':
+		switch (*++s) {
+		case '=':
+			s++;
+		default:
+			res = OP_NE;
+			break;
+		}
+		break;
+	}
+	if (ep) {
+		*ep = (char*)s;
+	}
+	return res;
+}
+
+static bool
+matchp(struct dt_d_s lined, struct dt_d_s refd, oper_t o)
+{
+	int cmp;
+
+	if ((cmp = dt_cmp(lined, refd)) == -2) {
+		return false;
+	}
+
+	switch (o) {
+	case OP_EQ:
+		return cmp == 0;
+	case OP_LT:
+		return cmp < 0;
+	case OP_LE:
+		return cmp <= 0;
+	case OP_GT:
+		return cmp > 0;
+	case OP_GE:
+		return cmp >= 0;
+	case OP_NE:
+	case OP_FUCKED:
+		return cmp != 0;
+	case OP_UNK:
+	default:
+		return false;
+	}
+}
+
+
+#if defined __INTEL_COMPILER
+# pragma warning (disable:593)
+# pragma warning (disable:181)
+#endif	/* __INTEL_COMPILER */
+#include "dgrep-clo.h"
+#include "dgrep-clo.c"
+#if defined __INTEL_COMPILER
+# pragma warning (default:593)
+# pragma warning (default:181)
+#endif	/* __INTEL_COMPILER */
+
+int
+main(int argc, char *argv[])
+{
+	struct gengetopt_args_info argi[1];
+	struct dt_d_s refd;
+	char **fmt;
+	size_t nfmt;
+	char *inp;
+	oper_t o = OP_UNK;
+	int res = 0;
+
+	if (cmdline_parser(argc, argv, argi)) {
+		res = 1;
+		goto out;
+	}
+
+	/* init and unescape sequences, maybe */
+	fmt = argi->input_format_arg;
+	nfmt = argi->input_format_given;
+	if (argi->backslash_escapes_given) {
+		for (size_t i = 0; i < nfmt; i++) {
+			dt_io_unescape(fmt[i]);
+		}
+	}
+
+	if (argi->eq_given) {
+		o = OP_EQ;
+	} else if (argi->ne_given) {
+		o = OP_NE;
+	} else if (argi->lt_given || argi->ot_given) {
+		o = OP_LT;
+	} else if (argi->le_given) {
+		o = OP_LE;
+	} else if (argi->gt_given || argi->nt_given) {
+		o = OP_GT;
+	} else if (argi->ge_given) {
+		o = OP_GE;
+	}
+	if (argi->inputs_num != 1 ||
+	    (o |= find_oper(argi->inputs[0], &inp)) == OP_FUCKED ||
+	    (refd = dt_io_strpd(inp, fmt, nfmt)).typ == DT_UNK) {
+		res = 1;
+		fputs("need a DATE to grep\n", stderr);
+		goto out;
+	}
+
+	/* fixup o, default is OP_EQ */
+	o = o ?: OP_EQ;
+	{
+		/* read from stdin */
+		FILE *fp = stdin;
+		char *line;
+		size_t lno = 0;
+		const char *needle = "\t";
+		size_t needlen = 1;
+
+		/* no threads reading this stream */
+		__fsetlocking(fp, FSETLOCKING_BYCALLER);
+		/* no threads reading this stream */
+		__fsetlocking(stdout, FSETLOCKING_BYCALLER);
+
+		for (line = NULL; !feof_unlocked(fp); lno++) {
+			ssize_t n;
+			size_t len;
+			struct dt_d_s d;
+			const char *sp = NULL;
+			const char *ep = NULL;
+
+			n = getline(&line, &len, fp);
+			if (n < 0) {
+				break;
+			}
+			/* check if line matches,
+			 * there is currently no way to specify NEEDLE */
+			d = dt_io_find_strpd(
+				line, fmt, nfmt,
+				needle, needlen,
+				(char**)&sp, (char**)&ep);
+			if (d.typ && matchp(d, refd, o)) {
+				if (!argi->only_matching_given) {
+					sp = line;
+					ep = line + n - 1;
+				}
+				fwrite(sp, sizeof(*sp), ep - sp, stdout);
+				fputc('\n', stdout);
+			}
+		}
+		/* get rid of resources */
+		free(line);
+	}
+
+out:
+	cmdline_parser_free(argi);
+	return res;
+}
+
+/* dcal.c ends here */
 TESTS += ddiff.4.dt
 TESTS += ddiff.5.dt
 
+TESTS += dgrep.1.dt
+TESTS += dgrep.2.dt
+TESTS += dgrep.3.dt
+TESTS += dgrep.4.dt
+TESTS += dgrep.5.dt
+TESTS += dgrep.6.dt
+TESTS += dgrep.7.dt
+TESTS += dgrep.8.dt
+TESTS += dgrep.9.dt
+TESTS += dgrep.10.dt
+
 TESTS += tseq.1.dt
 TESTS += tseq.2.dt
 TESTS += tseq.3.dt
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-03-01
+EOF
+
+## dgrep.1.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="--ge \\<2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+Feb	2012-02-28
+Feb	2012-02-29	leap day
+Mar	2012-03-01
+Mar	2012-03-02
+EOF
+
+EXPECT_EXIT_CODE="1"
+
+## dgrep.10.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="'<2012-03-01'"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-02-28
+2012-02-29
+EOF
+
+## dgrep.2.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="\\<=2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+EOF
+
+## dgrep.3.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="\\>2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-03-02
+EOF
+
+## dgrep.4.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="\\>=2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-03-01
+2012-03-02
+EOF
+
+## dgrep.5.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="\\!=2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-01
+2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-02-28
+2012-02-29
+2012-03-02
+EOF
+
+## dgrep.6.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="=2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+Feb	2012-02-28
+Feb	2012-02-29	leap day
+Mar	2012-03-01
+Mar	2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+Mar	2012-03-01
+EOF
+
+## dgrep.7.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="-o \\<2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+Feb	2012-02-28
+Feb	2012-02-29	leap day
+Mar	2012-03-01
+Mar	2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+2012-02-28
+2012-02-29
+EOF
+
+## dgrep.8.dt ends here
+## -*- shell-script -*-
+
+TOOL=dgrep
+CMDLINE="--ge 2012-03-01"
+
+## STDIN
+stdin=$(mktemp)
+cat > "${stdin}" <<EOF
+Feb	2012-02-28
+Feb	2012-02-29	leap day
+Mar	2012-03-01
+Mar	2012-03-02
+EOF
+
+## STDOUT
+stdout=$(mktemp)
+cat > "${stdout}" <<EOF
+Mar	2012-03-01
+Mar	2012-03-02
+EOF
+
+## dgrep.9.dt ends here
 
 eval "${builddir}/${TOOL}" "${CMDLINE}" \
 	< "${stdin:-/dev/null}" \
-	> "${tool_stdout}" 2> "${tool_stderr}" || myexit 1
+	> "${tool_stdout}" 2> "${tool_stderr}" || fail=${?}
+
+if test "${EXPECT_EXIT_CODE}" = "${fail}"; then
+	fail=0
+fi
 
 if test -r "${stdout}"; then
 	diff -u "${stdout}" "${tool_stdout}" || fail=1