Bring in gnulib for getopt_long and readline support.
/missing
/stamp-h1
/install-sh
+/arg-nonnull.h
+/warn-on-use.h
+/c++defs.h
+/lib
/cdecl99
--- /dev/null
+[submodule "gnulib"]
+ path = gnulib
+ url = git://git.savannah.gnu.org/gnulib.git
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
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
--- /dev/null
+#!/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
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.])
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
--- /dev/null
+Subproject commit 90d0c4909f2b77d711ea6332a99a9332ff1bab36
+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
--- /dev/null
+# 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])
+#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;
}