]> git.draconx.ca Git - cdecl99.git/commitdiff
Implement the interactive cdecl99 loop.
authorNick Bowler <nbowler@draconx.ca>
Thu, 23 Jun 2011 00:30:41 +0000 (20:30 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 23 Jun 2011 00:30:41 +0000 (20:30 -0400)
Bring in gnulib for getopt_long and readline support.

.gitignore
.gitmodules [new file with mode: 0644]
Makefile.am
bootstrap [new file with mode: 0755]
configure.ac
gnulib [new submodule]
m4/.gitignore
m4/gnulib-cache.m4 [new file with mode: 0644]
src/cdecl99.c

index 191edd065da322ebc6297b27d29c24c2d42b631b..bc85844d7643b2edce63960251de2cbc773d90fb 100644 (file)
@@ -17,4 +17,8 @@ Makefile.in
 /missing
 /stamp-h1
 /install-sh
+/arg-nonnull.h
+/warn-on-use.h
+/c++defs.h
+/lib
 /cdecl99
diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..009ae43
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "gnulib"]
+       path = gnulib
+       url = git://git.savannah.gnu.org/gnulib.git
index 8f82af4fabe34a0ec1a77838c00b461c9b4651a3..7bc77dc40675d09579aef367336f7cf5772cf819 100644 (file)
@@ -1,9 +1,12 @@
 ACLOCAL_AMFLAGS = -I m4
 
+SUBDIRS = lib .
+CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
+
 MAINTAINERCLEANFILES = src/scan.c src/scan.h src/scan.stamp \
        src/parse.c src/parse.h src/parse.stamp
 
-EXTRA_DIST = src/parse.stamp src/scan.stamp
+EXTRA_DIST = m4/gnulib-cache.m4 src/parse.stamp src/scan.stamp
 
 include_HEADERS = src/cdecl.h
 noinst_HEADERS = src/scan.h src/parse.h
@@ -14,7 +17,7 @@ libcdecl_la_SOURCES = src/scan.c src/parse.c src/parse-decl.c src/typemap.c
 
 bin_PROGRAMS = cdecl99
 cdecl99_SOURCES = src/cdecl99.c
-cdecl99_LDADD = libcdecl.la
+cdecl99_LDADD = libcdecl.la lib/libgnu.la
 
 src/parse.lo: src/scan.h
 src/scan.lo: src/parse.h
diff --git a/bootstrap b/bootstrap
new file mode 100755 (executable)
index 0000000..fa13580
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+trap 'exit 1' USR1
+die() { printf '%s\n' "$@" 1>&2; kill -USR1 $$; }
+
+git submodule update --init || echo "Failed to update Gnulib sources from git."
+if test -x gnulib/gnulib-tool; then
+       gnulib/gnulib-tool --update || die "Failed to update Gnulib."
+else
+       die "Gnulib sources are not properly installed in gnulib/."
+fi
+
+autoreconf -fis
index 5596f7475e141fe7886a788bc2212c03a2c36605..37184308e534faf4fa879c46726ee8ae94596a31 100644 (file)
@@ -7,6 +7,10 @@ AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
 AM_SILENT_RULES([yes])
 
 AC_PROG_CC_C99
+gl_EARLY
+
+LT_INIT
+gl_INIT
 
 AC_ARG_VAR([FLEX], [Command to invoke flex.  Defaults to flex.])
 AC_ARG_VAR([FLEXFLAGS], [Additional options to pass to flex.])
@@ -16,7 +20,8 @@ AC_ARG_VAR([BISON], [Command to invoke GNU Bison.  Defaults to bison.])
 AC_ARG_VAR([BISONFLAGS], [Additional options to pass to Bison.])
 AC_CHECK_PROGS([BISON], [bison], [bison])
 
-LT_INIT
-
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([
+       lib/Makefile
+       Makefile
+])
 AC_OUTPUT
diff --git a/gnulib b/gnulib
new file mode 160000 (submodule)
index 0000000..90d0c49
--- /dev/null
+++ b/gnulib
@@ -0,0 +1 @@
+Subproject commit 90d0c4909f2b77d711ea6332a99a9332ff1bab36
index 38066ddf7cadabe6ee4140de6bd3c539cf2716b5..377fc87f0b0b2517cef06a9036546df34cf51b10 100644 (file)
@@ -1,5 +1,30 @@
+00gnulib.m4
+errno_h.m4
+extensions.m4
+getdelim.m4
+getline.m4
+getopt.m4
+gnulib-common.m4
+gnulib-comp.m4
+gnulib-tool.m4
+include_next.m4
+lib-ld.m4
+lib-link.m4
+lib-prefix.m4
 libtool.m4
+longlong.m4
 ltoptions.m4
 ltsugar.m4
 ltversion.m4
 lt~obsolete.m4
+malloc.m4
+multiarch.m4
+readline.m4
+realloc.m4
+stddef_h.m4
+stdint.m4
+stdio_h.m4
+stdlib_h.m4
+unistd_h.m4
+warn-on-use.m4
+wchar_t.m4
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
new file mode 100644 (file)
index 0000000..fdf347b
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2002-2011 Free Software Foundation, Inc.
+#
+# This file is free software, distributed under the terms of the GNU
+# General Public License.  As a special exception to the GNU General
+# Public License, this file may be distributed as part of a program
+# that contains a configuration script generated by Autoconf, under
+# the same distribution terms as the rest of that program.
+#
+# Generated by gnulib-tool.
+#
+# This file represents the specification of how gnulib-tool is used.
+# It acts as a cache: It is written and read by gnulib-tool.
+# In projects that use version control, this file is meant to be put under
+# version control, like the configure.ac and various Makefile.am files.
+
+
+# Specification in the form of a command-line invocation:
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files getopt-gnu readline
+
+# Specification in the form of a few gnulib-tool.m4 macro invocations:
+gl_LOCAL_DIR([])
+gl_MODULES([
+  getopt-gnu
+  readline
+])
+gl_AVOID([])
+gl_SOURCE_BASE([lib])
+gl_M4_BASE([m4])
+gl_PO_BASE([])
+gl_DOC_BASE([doc])
+gl_TESTS_BASE([tests])
+gl_LIB([libgnu])
+gl_MAKEFILE_NAME([])
+gl_LIBTOOL
+gl_MACRO_PREFIX([gl])
+gl_PO_DOMAIN([])
+gl_WITNESS_C_DOMAIN([])
+gl_VC_FILES([false])
index 6eb07cc71c5188ee765ea86f536963701103881e..76e64bc4d1932d91c0eaa6148a4169b77143562a 100644 (file)
@@ -1,21 +1,74 @@
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <getopt.h>
+#include "readline.h"
 #include "cdecl.h"
 
-int main(int argc, char **argv)
+static const char *progname = "cdecl99";
+static const char sopts[] = "VH";
+static const struct option lopts[] = {
+       { "version", 0, NULL, 'V' },
+       { "help",    0, NULL, 'H' },
+       { 0 }
+};
+
+static void print_version(void)
+{
+       puts(PACKAGE_STRING);
+       puts("Copyright (C) 2011 Nick Bowler.");
+       puts("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.");
+       puts("This is free software: you are free to change and redistribute it.");
+       puts("There is NO WARRANTY, to the extent permitted by law.");
+}
+
+static void print_usage(FILE *f)
+{
+       fprintf(f, "Usage: %s [options]\n", progname);
+}
+
+static void print_help(void)
+{
+       print_usage(stdout);
+       puts("Detailed help coming soon.");
+}
+
+static int repl(void)
 {
        struct cdecl *decl;
+       print_version();
 
-       if (argc < 2) {
-               fprintf(stderr, "usage: cdecl99 decl\n");
-               return EXIT_FAILURE;
+       for (char *line; (line = readline("> ")); free(line)) {
+               decl = cdecl_parse_decl(line);
+               cdecl_free(decl);
        }
 
-       decl = cdecl_parse_decl(argv[1]);
-       if (!decl) {
-               return EXIT_FAILURE;
+       return 0;
+}
+
+int main(int argc, char **argv)
+{
+       int opt;
+
+       if (argc > 0)
+               progname = argv[0];
+
+       while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+               switch (opt) {
+               case 'V':
+                       print_version();
+                       return EXIT_SUCCESS;
+               case 'H':
+                       print_help();
+                       return EXIT_SUCCESS;
+               default:
+                       print_usage(stderr);
+                       return EXIT_FAILURE;
+               }
        }
 
-       cdecl_free(decl);
-       return 0;
+       if (repl() != 0)
+               return EXIT_FAILURE;
+
+       return EXIT_SUCCESS;
 }