[PATCH 2/4] Compile the date/time parser into notmuch library

2011-01-23 Thread Michal Sojka
---
 Makefile.local |3 +
 configure  |8 ++
 lib/Makefile.local |5 +-
 lib/config.h   |   45 +
 lib/getdate.c  |  185 +++-
 lib/getdate.h  |9 +++
 lib/getdate.y  |   15 -
 7 files changed, 178 insertions(+), 92 deletions(-)
 create mode 100644 lib/config.h

diff --git a/Makefile.local b/Makefile.local
index f9b5a9b..ce35c59 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -205,6 +205,9 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
 %.o: %.c $(global_deps)
$(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@

+%.c: %.y
+   $(call quiet,YACC $(YFLAGS)) $(YFLAGS) $< -o $@
+
 .deps/%.d: %.c $(global_deps)
@set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
$(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@. 2>/dev/null ; \
diff --git a/configure b/configure
index c58dd0f..6d9fda4 100755
--- a/configure
+++ b/configure
@@ -12,9 +12,11 @@ tab="$(printf '\t')"
 # environemnt variables)
 CC=${CC:-gcc}
 CXX=${CXX:-g++}
+YACC=${YACC:-yacc}
 CFLAGS=${CFLAGS:--O2}
 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
 LDFLAGS=${LDFLAGS:-}
+YFLAGS=${YFLAGS}
 XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}

 # We don't allow the EMACS or GZIP Makefile variables inherit values
@@ -477,6 +479,9 @@ CC = ${CC}
 # The C++ compiler to use
 CXX = ${CXX}

+# The parser generator to use
+YACC = ${YACC}
+
 # Command to execute emacs from Makefiles
 EMACS = emacs --quick

@@ -495,6 +500,9 @@ WARN_CXXFLAGS=${WARN_CXXFLAGS}
 # Flags to enable warnings when using the C compiler
 WARN_CFLAGS=${WARN_CFLAGS}

+# Default FLAGS for parser generator (can be overridden by user such as "make 
YFLAGS=-y")
+YFLAGS = ${YFLAGS}
+
 # The prefix to which notmuch should be installed
 # Note: If you change this value here, be sure to ensure that the
 # LIBDIR_IN_LDCONFIG value below is still set correctly.
diff --git a/lib/Makefile.local b/lib/Makefile.local
index 37d3735..89b5bb7 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -56,7 +56,10 @@ libnotmuch_c_srcs =  \
$(dir)/messages.c   \
$(dir)/sha1.c   \
$(dir)/tags.c   \
-   $(dir)/xutil.c
+   $(dir)/xutil.c  \
+   $(dir)/getdate.c\
+   $(dir)/c-ctype.c\
+   $(dir)/gettime.c

 libnotmuch_cxx_srcs =  \
$(dir)/database.cc  \
diff --git a/lib/config.h b/lib/config.h
new file mode 100644
index 000..e8bc5b7
--- /dev/null
+++ b/lib/config.h
@@ -0,0 +1,45 @@
+/* lib/config.h.  Generated from config.hin by configure.  */
+/* lib/config.hin.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the `clock_gettime' function. */
+#define HAVE_CLOCK_GETTIME 1
+
+/* Define if you have compound literals. */
+#define HAVE_COMPOUND_LITERALS 1
+
+/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
+   */
+/* #undef HAVE_DECL_TZNAME */
+
+/* Define to 1 if you have the `nanotime' function. */
+/* #undef HAVE_NANOTIME */
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define if struct tm has the tm_gmtoff member. */
+#define HAVE_TM_GMTOFF 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#define HAVE_TM_ZONE 1
+
+/* Define to 1 if you don't have `tm_zone' but do have the external array
+   `tzname'. */
+/* #undef HAVE_TZNAME */
+
+/* Define to 1 if you have the `tzset' function. */
+#define HAVE_TZSET 1
+
+
+/* Define as a marker that can be attached to declarations that might not
+be used.  This helps to reduce warnings, such as from
+GCC -Wunused-parameter.  */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED __attribute__ ((__unused__))
+#else
+# define _GL_UNUSED
+#endif
+/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
+   is a misnomer outside of parameter lists.  */
+#define _UNUSED_PARAMETER_ _GL_UNUSED
diff --git a/lib/getdate.c b/lib/getdate.c
index 5b20eeb..57f33e9 100644
--- a/lib/getdate.c
+++ b/lib/getdate.c
@@ -68,7 +68,7 @@
 /* Copy the first part of user declarations.  */

 /* Line 189 of yacc.c  */
-#line 1 "getdate.y"
+#line 1 "lib/getdate.y"

 /* Parse a string into an internal time stamp.

@@ -102,6 +102,8 @@
 /* FIXME: Check for arithmetic overflow in all cases, not just
some of them.  */

+#include "notmuch-private.h"   /* For xmalloc() */
+
 #include 

 #include "getdate.h"
@@ -137,9 +139,6 @@
 #include 
 #include 

-#include "xalloc.h"
-
-
 /* ISDIGIT differs from isdigit, as follows:
- Its arg may be any int or unsigned int; it need not be an unsigned char
  or EOF.
@@ -344,7 +343,7 @@ set_hhmmss (parser_control *pc, long int hour, long int 
minutes,


 /* Line 189 of yacc.c  */
-#line 348 "getdate.c"
+#line 347 "lib/getdate.c"

 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -423,7 +422,7 @@ typedef union YY

[PATCH 2/4] Compile the date/time parser into notmuch library

2011-01-23 Thread Michal Sojka
---
 Makefile.local |3 +
 configure  |8 ++
 lib/Makefile.local |5 +-
 lib/config.h   |   45 +
 lib/getdate.c  |  185 +++-
 lib/getdate.h  |9 +++
 lib/getdate.y  |   15 -
 7 files changed, 178 insertions(+), 92 deletions(-)
 create mode 100644 lib/config.h

diff --git a/Makefile.local b/Makefile.local
index f9b5a9b..ce35c59 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -205,6 +205,9 @@ quiet ?= $($(shell echo $1 | sed -e s'/ .*//'))
 %.o: %.c $(global_deps)
$(call quiet,CC $(CFLAGS)) -c $(FINAL_CFLAGS) $< -o $@
 
+%.c: %.y
+   $(call quiet,YACC $(YFLAGS)) $(YFLAGS) $< -o $@
+
 .deps/%.d: %.c $(global_deps)
@set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
$(CC) -M $(CPPFLAGS) $(FINAL_CFLAGS) $< > $@. 2>/dev/null ; \
diff --git a/configure b/configure
index c58dd0f..6d9fda4 100755
--- a/configure
+++ b/configure
@@ -12,9 +12,11 @@ tab="$(printf '\t')"
 # environemnt variables)
 CC=${CC:-gcc}
 CXX=${CXX:-g++}
+YACC=${YACC:-yacc}
 CFLAGS=${CFLAGS:--O2}
 CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
 LDFLAGS=${LDFLAGS:-}
+YFLAGS=${YFLAGS}
 XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}
 
 # We don't allow the EMACS or GZIP Makefile variables inherit values
@@ -477,6 +479,9 @@ CC = ${CC}
 # The C++ compiler to use
 CXX = ${CXX}
 
+# The parser generator to use
+YACC = ${YACC}
+
 # Command to execute emacs from Makefiles
 EMACS = emacs --quick
 
@@ -495,6 +500,9 @@ WARN_CXXFLAGS=${WARN_CXXFLAGS}
 # Flags to enable warnings when using the C compiler
 WARN_CFLAGS=${WARN_CFLAGS}
 
+# Default FLAGS for parser generator (can be overridden by user such as "make 
YFLAGS=-y")
+YFLAGS = ${YFLAGS}
+
 # The prefix to which notmuch should be installed
 # Note: If you change this value here, be sure to ensure that the
 # LIBDIR_IN_LDCONFIG value below is still set correctly.
diff --git a/lib/Makefile.local b/lib/Makefile.local
index 37d3735..89b5bb7 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -56,7 +56,10 @@ libnotmuch_c_srcs =  \
$(dir)/messages.c   \
$(dir)/sha1.c   \
$(dir)/tags.c   \
-   $(dir)/xutil.c
+   $(dir)/xutil.c  \
+   $(dir)/getdate.c\
+   $(dir)/c-ctype.c\
+   $(dir)/gettime.c
 
 libnotmuch_cxx_srcs =  \
$(dir)/database.cc  \
diff --git a/lib/config.h b/lib/config.h
new file mode 100644
index 000..e8bc5b7
--- /dev/null
+++ b/lib/config.h
@@ -0,0 +1,45 @@
+/* lib/config.h.  Generated from config.hin by configure.  */
+/* lib/config.hin.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the `clock_gettime' function. */
+#define HAVE_CLOCK_GETTIME 1
+
+/* Define if you have compound literals. */
+#define HAVE_COMPOUND_LITERALS 1
+
+/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
+   */
+/* #undef HAVE_DECL_TZNAME */
+
+/* Define to 1 if you have the `nanotime' function. */
+/* #undef HAVE_NANOTIME */
+
+/* Define to 1 if `tm_zone' is a member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define if struct tm has the tm_gmtoff member. */
+#define HAVE_TM_GMTOFF 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+   `HAVE_STRUCT_TM_TM_ZONE' instead. */
+#define HAVE_TM_ZONE 1
+
+/* Define to 1 if you don't have `tm_zone' but do have the external array
+   `tzname'. */
+/* #undef HAVE_TZNAME */
+
+/* Define to 1 if you have the `tzset' function. */
+#define HAVE_TZSET 1
+
+
+/* Define as a marker that can be attached to declarations that might not
+be used.  This helps to reduce warnings, such as from
+GCC -Wunused-parameter.  */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED __attribute__ ((__unused__))
+#else
+# define _GL_UNUSED
+#endif
+/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
+   is a misnomer outside of parameter lists.  */
+#define _UNUSED_PARAMETER_ _GL_UNUSED
diff --git a/lib/getdate.c b/lib/getdate.c
index 5b20eeb..57f33e9 100644
--- a/lib/getdate.c
+++ b/lib/getdate.c
@@ -68,7 +68,7 @@
 /* Copy the first part of user declarations.  */
 
 /* Line 189 of yacc.c  */
-#line 1 "getdate.y"
+#line 1 "lib/getdate.y"
 
 /* Parse a string into an internal time stamp.
 
@@ -102,6 +102,8 @@
 /* FIXME: Check for arithmetic overflow in all cases, not just
some of them.  */
 
+#include "notmuch-private.h"   /* For xmalloc() */
+
 #include 
 
 #include "getdate.h"
@@ -137,9 +139,6 @@
 #include 
 #include 
 
-#include "xalloc.h"
-
-
 /* ISDIGIT differs from isdigit, as follows:
- Its arg may be any int or unsigned int; it need not be an unsigned char
  or EOF.
@@ -344,7 +343,7 @@ set_hhmmss (parser_control *pc, long int hour, long int 
minutes,
 
 
 /* Line 189 of yacc.c  */
-#line 348 "getdate.c"
+#line 347 "lib/getdate.c"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -423,7 +422,7 @@ t