Browse Source

CONVERT TO C++.

David Mazieres 7 years ago
parent
commit
a0bc075752
13 changed files with 245 additions and 39 deletions
  1. 13
    0
      .gitignore
  2. 1
    0
      AUTHORS
  3. 12
    0
      COPYING
  4. 0
    0
      ChangeLog
  5. 0
    21
      Makefile
  6. 14
    0
      Makefile.am
  7. 0
    0
      NEWS
  8. 7
    0
      README
  9. 29
    0
      configure.ac
  10. 133
    0
      m4/ax_cxx_compile_stdcxx_11.m4
  11. 26
    0
      muchsync.cc
  12. 8
    0
      muchsync.h
  13. 2
    18
      sqlite.cc

+ 13
- 0
.gitignore View File

@@ -1,3 +1,16 @@
1 1
 *.o
2 2
 *~
3
+.deps
4
+/INSTALL
5
+/aclocal.m4
6
+/autom4te.cache
7
+/compile
8
+/config.log
9
+/config.status
10
+/configure
11
+/depcomp
12
+/install-sh
13
+/missing
3 14
 /muchsync
15
+Makefile
16
+Makefile.in

+ 1
- 0
AUTHORS View File

@@ -0,0 +1 @@
1
+David Mazieres

+ 12
- 0
COPYING View File

@@ -0,0 +1,12 @@
1
+Copyright (C) 2013 David Mazieres
2
+
3
+Distribution permitted under the GNU General Public License (GPL)
4
+version 2 or later.  Acceptable versions of this license are available
5
+at the following URLs:
6
+
7
+	http://www.gnu.org/licenses/gpl-2.0.html
8
+	http://www.gnu.org/licenses/gpl-3.0.html
9
+
10
+If the Free Software Foundation publishes a higher-numbered GPL
11
+license, you may at your option distribute this software under the
12
+terms of that license as well.

+ 0
- 0
ChangeLog View File


+ 0
- 21
Makefile View File

@@ -1,21 +0,0 @@
1
-
2
-CC=cc
3
-CFLAGS=-Wall -Werror -g -O
4
-
5
-notmuch_CPPFLAGS=
6
-notmuch_LDADD=-lnotmuch
7
-
8
-PKGS=libcrypto sqlite3 talloc
9
-
10
-CPPFLAGS=$(notmuch_CPPFLAGS) `pkg-config --cflags $(PKGS)`
11
-LDADD=$(notmuch_LDADD) `pkg-config --libs $(PKGS)`
12
-
13
-all: muchsync
14
-.PHONY: all
15
-
16
-muchsync: muchsync.c
17
-	$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ muchsync.c $(LDADD)
18
-
19
-clean:
20
-	rm -f muchsync core.* *.o *~
21
-.PHONY: clean

+ 14
- 0
Makefile.am View File

@@ -0,0 +1,14 @@
1
+
2
+AM_CPPFLAGS = $(sqlite3_CFLAGS) $(libcrypto_CFLAGS) $(xapian_CPPFLAGS) \
3
+	$(talloc_CPPFLAGS)
4
+LDADD = $(sqlite3_LIBS) $(libcrypto_LIBS) $(xapian_LIBS) \
5
+	$(talloc_LIBS) -lnotmuch
6
+
7
+bin_PROGRAMS = muchsync
8
+
9
+muchsync_SOURCES = muchsync.cc sqlite.cc muchsync.h
10
+
11
+CLEANFILES = *~
12
+maintainer-clean-local:
13
+	+@echo rm -rf `sed -ne 's!^/!!p' .gitignore` Makefile.in
14
+	rm -rf `sed -ne 's!^/!!p' .gitignore` Makefile.in

+ 0
- 0
NEWS View File


+ 7
- 0
README View File

@@ -0,0 +1,7 @@
1
+* To build this software after a git checkout, run the following
2
+  commands:
3
+
4
+autoreconf -i
5
+./configure
6
+make
7
+

+ 29
- 0
configure.ac View File

@@ -0,0 +1,29 @@
1
+#                                               -*- Autoconf -*-
2
+# Process this file with autoconf to produce a configure script.
3
+
4
+AC_PREREQ([2.69])
5
+AC_INIT(muchsync, 0)
6
+AM_INIT_AUTOMAKE([-Wall])
7
+AC_CONFIG_SRCDIR([configure.ac])
8
+AC_CONFIG_MACRO_DIRS([m4])
9
+
10
+AC_PROG_CXX
11
+AX_CXX_COMPILE_STDCXX_11(,mandatory)
12
+dnl AC_USE_SYSTEM_EXTENSIONS
13
+
14
+PKG_CHECK_MODULES([sqlite3], [sqlite3])
15
+PKG_CHECK_MODULES([libcrypto], [libcrypto])
16
+PKG_CHECK_MODULES([talloc], [talloc])
17
+
18
+AC_PATH_PROG(XAPIAN_CONFIG, xapian-config)
19
+test -n "$XAPIAN_CONFIG" || AC_MSG_ERROR(Cannot find xapian-config)
20
+if ! xapian_CPPFLAGS=$($XAPIAN_CONFIG --cxxflags) \
21
+   || ! xapian_LIBS=$($XAPIAN_CONFIG --ltlibs); then
22
+   AC_MSG_ERROR(Error running $XAPIAN_CONFIG)
23
+fi
24
+AC_SUBST(xapian_CPPFLAGS)
25
+AC_SUBST(xapian_LIBS)
26
+
27
+AC_CONFIG_FILES([Makefile])
28
+AC_OUTPUT
29
+

+ 133
- 0
m4/ax_cxx_compile_stdcxx_11.m4 View File

@@ -0,0 +1,133 @@
1
+# ============================================================================
2
+#  http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3
+# ============================================================================
4
+#
5
+# SYNOPSIS
6
+#
7
+#   AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
8
+#
9
+# DESCRIPTION
10
+#
11
+#   Check for baseline language coverage in the compiler for the C++11
12
+#   standard; if necessary, add switches to CXXFLAGS to enable support.
13
+#
14
+#   The first argument, if specified, indicates whether you insist on an
15
+#   extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
16
+#   -std=c++11).  If neither is specified, you get whatever works, with
17
+#   preference for an extended mode.
18
+#
19
+#   The second argument, if specified 'mandatory' or if left unspecified,
20
+#   indicates that baseline C++11 support is required and that the macro
21
+#   should error out if no mode with that support is found.  If specified
22
+#   'optional', then configuration proceeds regardless, after defining
23
+#   HAVE_CXX11 if and only if a supporting mode is found.
24
+#
25
+# LICENSE
26
+#
27
+#   Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
28
+#   Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
29
+#   Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
30
+#
31
+#   Copying and distribution of this file, with or without modification, are
32
+#   permitted in any medium without royalty provided the copyright notice
33
+#   and this notice are preserved. This file is offered as-is, without any
34
+#   warranty.
35
+
36
+#serial 3
37
+
38
+m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
39
+  template <typename T>
40
+    struct check
41
+    {
42
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
43
+    };
44
+
45
+    typedef check<check<bool>> right_angle_brackets;
46
+
47
+    int a;
48
+    decltype(a) b;
49
+
50
+    typedef check<int> check_type;
51
+    check_type c;
52
+    check_type&& cr = static_cast<check_type&&>(c);
53
+
54
+    auto d = a;
55
+])
56
+
57
+AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
58
+  m4_if([$1], [], [],
59
+        [$1], [ext], [],
60
+        [$1], [noext], [],
61
+        [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
62
+  m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
63
+        [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
64
+        [$2], [optional], [ax_cxx_compile_cxx11_required=false],
65
+        [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl
66
+  AC_LANG_PUSH([C++])dnl
67
+  ac_success=no
68
+  AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
69
+  ax_cv_cxx_compile_cxx11,
70
+  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
71
+    [ax_cv_cxx_compile_cxx11=yes],
72
+    [ax_cv_cxx_compile_cxx11=no])])
73
+  if test x$ax_cv_cxx_compile_cxx11 = xyes; then
74
+    ac_success=yes
75
+  fi
76
+
77
+  m4_if([$1], [noext], [], [dnl
78
+  if test x$ac_success = xno; then
79
+    for switch in -std=gnu++11 -std=gnu++0x; do
80
+      cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
81
+      AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
82
+                     $cachevar,
83
+        [ac_save_CXXFLAGS="$CXXFLAGS"
84
+         CXXFLAGS="$CXXFLAGS $switch"
85
+         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
86
+          [eval $cachevar=yes],
87
+          [eval $cachevar=no])
88
+         CXXFLAGS="$ac_save_CXXFLAGS"])
89
+      if eval test x\$$cachevar = xyes; then
90
+        CXXFLAGS="$CXXFLAGS $switch"
91
+        ac_success=yes
92
+        break
93
+      fi
94
+    done
95
+  fi])
96
+
97
+  m4_if([$1], [ext], [], [dnl
98
+  if test x$ac_success = xno; then
99
+    for switch in -std=c++11 -std=c++0x; do
100
+      cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
101
+      AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
102
+                     $cachevar,
103
+        [ac_save_CXXFLAGS="$CXXFLAGS"
104
+         CXXFLAGS="$CXXFLAGS $switch"
105
+         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
106
+          [eval $cachevar=yes],
107
+          [eval $cachevar=no])
108
+         CXXFLAGS="$ac_save_CXXFLAGS"])
109
+      if eval test x\$$cachevar = xyes; then
110
+        CXXFLAGS="$CXXFLAGS $switch"
111
+        ac_success=yes
112
+        break
113
+      fi
114
+    done
115
+  fi])
116
+  AC_LANG_POP([C++])
117
+  if test x$ax_cxx_compile_cxx11_required = xtrue; then
118
+    if test x$ac_success = xno; then
119
+      AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
120
+    fi
121
+  else
122
+    if test x$ac_success = xno; then
123
+      HAVE_CXX11=0
124
+      AC_MSG_NOTICE([No compiler with C++11 support was found])
125
+    else
126
+      HAVE_CXX11=1
127
+      AC_DEFINE(HAVE_CXX11,1,
128
+                [define if the compiler supports basic C++11 syntax])
129
+    fi
130
+
131
+    AC_SUBST(HAVE_CXX11)
132
+  fi
133
+])

+ 26
- 0
muchsync.cc View File

@@ -0,0 +1,26 @@
1
+
2
+#include <stdio.h>
3
+#include <stdlib.h>
4
+#include "muchsync.h"
5
+
6
+using namespace std;
7
+
8
+int
9
+main (int argc, char **argv)
10
+{
11
+  if (argc != 3) {
12
+    fprintf (stderr, "usage error\n");
13
+    exit (1);
14
+  }
15
+
16
+  sqlite3 *db = dbopen (argv[1]);
17
+  if (!db)
18
+    exit (1);
19
+  sqlite3_exec (db, "BEGIN;", NULL, NULL, NULL);
20
+  scan_notmuch (argv[2], db);
21
+  sqlite3_exec (db, "COMMIT;", NULL, NULL, NULL);
22
+  sqlite3_close_v2 (db);
23
+
24
+
25
+  return 0;
26
+}

+ 8
- 0
muchsync.h View File

@@ -0,0 +1,8 @@
1
+#include <sqlite3.h>
2
+
3
+/* sqlite.cc */
4
+void dbperror (sqlite3 *db, const char *query);
5
+int fmtexec (sqlite3 *db, const char *fmt, ...);
6
+int fmtstep (sqlite3 *db, sqlite3_stmt **stmtpp, const char *fmt, ...);
7
+sqlite3 *dbopen (const char *path);
8
+int scan_notmuch (const char *mailpath, sqlite3 *db);

muchsync.c → sqlite.cc View File

@@ -12,6 +12,8 @@
12 12
 #include <sqlite3.h>
13 13
 #include <talloc.h>
14 14
 
15
+#include "muchsync.h"
16
+
15 17
 #define DBVERS "muchsync 0"
16 18
 
17 19
 typedef sqlite3_int64 i64;
@@ -231,21 +233,3 @@ scan_notmuch (const char *mailpath, sqlite3 *db)
231 233
 }
232 234
 
233 235
 
234
-
235
-int
236
-main (int argc, char **argv)
237
-{
238
-  if (argc != 3) {
239
-    fprintf (stderr, "usage error\n");
240
-    exit (1);
241
-  }
242
-
243
-  sqlite3 *db = dbopen (argv[1]);
244
-  if (!db)
245
-    exit (1);
246
-  sqlite3_exec (db, "BEGIN;", NULL, NULL, NULL);
247
-  scan_notmuch (argv[2], db);
248
-  sqlite3_exec (db, "COMMIT;", NULL, NULL, NULL);
249
-
250
-  return 0;
251
-}

Loading…
Cancel
Save