Browse Source

Import upstream version 4.2.4

Fred Klassen 6 years ago
parent
commit
25da238943
100 changed files with 28796 additions and 24202 deletions
  1. 70 1
      INSTALL
  2. 5 10
      Makefile.am
  3. 266 167
      Makefile.in
  4. 0 48
      README
  5. 88 0
      acinclude.m4
  6. 481 8278
      aclocal.m4
  7. 4 4
      autogen.sh
  8. 265 54
      config/compile
  9. 239 320
      config/config.guess
  10. 196 102
      config/config.sub
  11. 455 190
      config/depcomp
  12. 400 191
      config/install-sh
  13. 2647 1392
      config/ltmain.sh
  14. 156 301
      config/missing
  15. 0 150
      config/mkinstalldirs
  16. 8027 4949
      configure
  17. 831 203
      configure.ac
  18. 242 66
      docs/CHANGELOG
  19. 24 3
      docs/CREDIT
  20. 13 11
      docs/HACKING
  21. 301 4
      docs/INSTALL
  22. 681 31
      docs/LICENSE
  23. 10 3
      docs/Makefile.am
  24. 130 32
      docs/Makefile.in
  25. 2 2
      docs/TODO
  26. 1 1
      docs/Win32Readme.txt
  27. 16 4
      doxygen.cfg.in
  28. 2 1
      lib/Makefile.am
  29. 208 81
      lib/Makefile.in
  30. 8 0
      lib/queue.h
  31. 0 9
      lib/sll.h
  32. 27 0
      lib/strlcpy.h
  33. 3 3
      libopts/COPYING.gplv3
  34. 1 1
      libopts/COPYING.lgplv3
  35. 47 15
      libopts/Makefile.am
  36. 271 118
      libopts/Makefile.in
  37. 64 35
      libopts/README
  38. 487 121
      libopts/ag-char-map.h
  39. 116 0
      libopts/alias.c
  40. 374 0
      libopts/ao-strs.c
  41. 330 0
      libopts/ao-strs.h
  42. 144 911
      libopts/autoopts.c
  43. 230 110
      libopts/autoopts.h
  44. 765 561
      libopts/autoopts/options.h
  45. 77 0
      libopts/autoopts/project.h
  46. 627 363
      libopts/autoopts/usage-txt.h
  47. 30 26
      libopts/boolean.c
  48. 177 0
      libopts/check.c
  49. 10 0
      libopts/compat/_Noreturn.h
  50. 86 69
      libopts/compat/compat.h
  51. 39 94
      libopts/compat/pathfind.c
  52. 2 0
      libopts/compat/snprintf.c
  53. 12 6
      libopts/compat/strchr.c
  54. 3 0
      libopts/compat/strdup.c
  55. 58 61
      libopts/compat/windows-config.h
  56. 718 587
      libopts/configfile.c
  57. 132 100
      libopts/cook.c
  58. 652 0
      libopts/enum.c
  59. 0 512
      libopts/enumeration.c
  60. 89 63
      libopts/environment.c
  61. 133 102
      libopts/file.c
  62. 780 0
      libopts/find.c
  63. 689 200
      libopts/genshell.c
  64. 127 83
      libopts/genshell.h
  65. 288 0
      libopts/gettext.h
  66. 298 0
      libopts/init.c
  67. 320 0
      libopts/intprops.h
  68. 18 10
      libopts/libopts.c
  69. 283 235
      libopts/load.c
  70. 188 144
      libopts/m4/libopts.m4
  71. 19 35
      libopts/m4/liboptschk.m4
  72. 41 0
      libopts/m4/stdnoreturn.m4
  73. 562 710
      libopts/makeshell.c
  74. 450 357
      libopts/nested.c
  75. 85 82
      libopts/numeric.c
  76. 156 0
      libopts/option-value-type.c
  77. 60 0
      libopts/option-value-type.h
  78. 148 0
      libopts/option-xat-attribute.c
  79. 57 0
      libopts/option-xat-attribute.h
  80. 85 63
      libopts/parse-duration.c
  81. 20 12
      libopts/parse-duration.h
  82. 107 60
      libopts/pgusage.c
  83. 96 62
      libopts/proto.h
  84. 340 149
      libopts/putshell.c
  85. 34 21
      libopts/reset.c
  86. 31 35
      libopts/restore.c
  87. 261 243
      libopts/save.c
  88. 86 82
      libopts/sort.c
  89. 66 63
      libopts/stack.c
  90. 50 0
      libopts/stdnoreturn.in.h
  91. 50 32
      libopts/streqvcmp.c
  92. 253 257
      libopts/text_mmap.c
  93. 99 44
      libopts/time.c
  94. 129 113
      libopts/tokenize.c
  95. 891 311
      libopts/usage.c
  96. 0 120
      libopts/value-type.c
  97. 0 25
      libopts/value-type.h
  98. 157 77
      libopts/version.c
  99. 0 111
      libopts/xat-attribute.c
  100. 0 0
      libopts/xat-attribute.h

+ 70 - 1
INSTALL

@@ -2,14 +2,24 @@ Installation Instructions
 *************************
 
 Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
-2006 Free Software Foundation, Inc.
+2006, 2014 Free Software Foundation, Inc.
 
 This file is free documentation; the Free Software Foundation gives
 unlimited permission to copy, distribute and modify it.
 
+
+Advanced Installation
+=====================
+Visit http://tcpreplay.appneta.com/wiki/installation.html
+
+
 Basic Installation
 ==================
 
+    ./configure 
+    make
+    sudo make install
+
 Briefly, the shell commands `./configure; make; make install' should
 configure, build, and install this package.  The following
 more-detailed instructions are generic; see the `README' file for
@@ -67,6 +77,58 @@ The simplest way to compile this package is:
      all sorts of other programs in order to regenerate files that came
      with the distribution.
 
+
+How to make Tcpreplay go fast
+=============================
+
+1) netmap
+   ------
+This feature will detect netmap capable network drivers on Linux and
+BSD systems. If detected, the network driver is bypassed for the
+execution duration of tcpreplay and tcpreplay-edit, and network buffers
+will be written to directly. This will allow you to achieve full 10GigE
+line rates on commodity 10GigE network adapters, similar to rates 
+achieved by commercial network traffic generators.
+
+Note that bypassing the network driver will disrupt other applications
+connected through the test interface. Use caution when testing on the
+same interface you ssh'ed into.
+
+Ensure that you have supported NICs installed. Most Intel and nForce 
+(nVidia) adapters will work. Some virtual adapters are supported.
+
+FreeBSD 10 and higher already contains netmap capabilities and should
+be detected automatically by "configure". But first you must enable
+netmap on the system by adding 'device netmap' to your kernel config
+and rebuilding the kernel. When complete, /dev/netmap will be
+available.
+
+For Linux, download latest netmap sources from http://info.iet.unipi.it/~luigi/netmap/
+or run 'git clone https://code.google.com/p/netmap/'. You will also need to have 
+kernel sources installed so the build system can patch the sources and build 
+netmap-enabled drivers. If kernel sources are in /a/b/c/linux-A.B.C/ , then you
+should do:
+
+    cd netmap/LINUX
+    make KSRC=/a/b/c/linux-A.B.C/       # builds the kernel modules
+    make KSRC=/a/b/c/linux-A.B.C/ apps  # builds sample applications
+
+You can omit KSRC if your kernel sources are in a standard place.
+
+Once you load the netmap.lin.ko module on your Linux machine, /dev/netmap 
+will be available. You will also need to replace your existing network drivers
+(beyond the scope of this document).
+
+Building netmap-aware Tcpreplay suite is relatively straight forward. For
+FreeBSD, build normally. For Linux, if you extracted netmap into /usr/src/ you 
+can also build normally. Otherwise you will have to specify the netmap source
+directory, for example:
+
+    ./configure --with-netmap=/home/fklassen/git/netmap
+    make
+    sudo make install
+
+
 Compilers and Options
 =====================
 
@@ -82,6 +144,7 @@ is an example:
 
    *Note Defining Variables::, for more details.
 
+
 Compiling For Multiple Architectures
 ====================================
 
@@ -97,6 +160,7 @@ architecture at a time in the source code directory.  After you have
 installed the package for one architecture, use `make distclean' before
 reconfiguring for another architecture.
 
+
 Installation Names
 ==================
 
@@ -120,6 +184,7 @@ you can set and what kinds of files go in them.
 with an extra prefix or suffix on their names by giving `configure' the
 option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
 
+
 Optional Features
 =================
 
@@ -135,6 +200,7 @@ find the X include and library files automatically, but if it doesn't,
 you can use the `configure' options `--x-includes=DIR' and
 `--x-libraries=DIR' to specify their locations.
 
+
 Specifying the System Type
 ==========================
 
@@ -165,6 +231,7 @@ platform different from the build platform, you should specify the
 "host" platform (i.e., that on which the generated programs will
 eventually be run) with `--host=TYPE'.
 
+
 Sharing Defaults
 ================
 
@@ -176,6 +243,7 @@ values for variables like `CC', `cache_file', and `prefix'.
 `CONFIG_SITE' environment variable to the location of the site script.
 A warning: not all `configure' scripts look for a site script.
 
+
 Defining Variables
 ==================
 
@@ -195,6 +263,7 @@ an Autoconf bug.  Until the bug is fixed you can use this workaround:
 
      CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
 
+
 `configure' Invocation
 ======================
 

+ 5 - 10
Makefile.am

@@ -1,6 +1,4 @@
 # $Id$
-AUTOMAKE_OPTIONS = foreign
-
 ACLOCAL_AMFLAGS = -I m4 -I libopts/m4
 
 if NEED_LIBOPTS
@@ -13,10 +11,7 @@ DIST_SUBDIRS = scripts lib libopts src docs test
 .PHONY: manpages docs test man2html
 
 
-dist-hook: version manpages update
-
-update:
-	svn update
+dist-hook: version manpages
 
 DOCS_DIR = $(top_builddir)/docs
 
@@ -46,8 +41,8 @@ dlt_names:
 	cat @SAVEFILE_C@ | $(top_builddir)/scripts/dlt2name.pl src/dlt_names.h
 
 version:
-	-rm -f src/common/svn_version.c
-	cd src/common && make svn_version.c
+	-rm -f src/common/git_version.c
+	cd src/common && make git_version.c
 
 distclean-local:
 	-rm -rf autom4te.cache doxygen
@@ -57,7 +52,7 @@ doxygen: version
 
 ncc:
 	CC=ncc make
-
+	
 MOSTLYCLEANFILES = tcpreplay.spec *~
 
 DISTCLEANFILES = .tm_project.cache stamp-h1 *.tar.*
@@ -66,4 +61,4 @@ MAINTAINERCLEANFILES = Makefile.in configure *.bak
 
 EXTRA_DIST = doxygen.cfg.in autogen.sh \
 	m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 \
-	m4/ltversion.m4 m4/lt~obsolete.m4
+	m4/ltversion.m4 m4/lt~obsolete.m4 acinclude.m4

+ 266 - 167
Makefile.in

@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -15,6 +14,51 @@
 
 @SET_MAKE@
 VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -35,46 +79,95 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 subdir = .
-DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
-	$(srcdir)/Makefile.in $(srcdir)/doxygen.cfg.in \
-	$(top_srcdir)/configure INSTALL config/compile \
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/configure $(am__configure_deps) \
+	$(srcdir)/doxygen.cfg.in INSTALL config/compile \
 	config/config.guess config/config.sub config/depcomp \
-	config/install-sh config/ltmain.sh config/missing \
-	config/mkinstalldirs
+	config/install-sh config/missing config/ltmain.sh \
+	$(top_srcdir)/config/compile $(top_srcdir)/config/config.guess \
+	$(top_srcdir)/config/config.sub \
+	$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
+	$(top_srcdir)/config/missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \
-	$(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
+	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+	$(top_srcdir)/libopts/m4/libopts.m4 \
+	$(top_srcdir)/libopts/m4/stdnoreturn.m4 \
+	$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
 am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
  configure.lineno config.status.lineno
-mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
+mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/src/config.h
 CONFIG_CLEAN_FILES = doxygen.cfg
 CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
 SOURCES =
 DIST_SOURCES =
-RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
-	html-recursive info-recursive install-data-recursive \
-	install-dvi-recursive install-exec-recursive \
-	install-html-recursive install-info-recursive \
-	install-pdf-recursive install-ps-recursive install-recursive \
-	installcheck-recursive installdirs-recursive pdf-recursive \
-	ps-recursive uninstall-recursive
+RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
+	ctags-recursive dvi-recursive html-recursive info-recursive \
+	install-data-recursive install-dvi-recursive \
+	install-exec-recursive install-html-recursive \
+	install-info-recursive install-pdf-recursive \
+	install-ps-recursive install-recursive installcheck-recursive \
+	installdirs-recursive pdf-recursive ps-recursive \
+	tags-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
   distclean-recursive maintainer-clean-recursive
-AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
-	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
-	distdir dist dist-all distcheck
+am__recursive_targets = \
+  $(RECURSIVE_TARGETS) \
+  $(RECURSIVE_CLEAN_TARGETS) \
+  $(am__extra_recursive_targets)
+AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
+	cscope distdir dist dist-all distcheck
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates.  Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+  BEGIN { nonempty = 0; } \
+  { items[$$0] = 1; nonempty = 1; } \
+  END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique.  This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+  list='$(am__tagged_files)'; \
+  unique=`for i in $$list; do \
+    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+  done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
+CSCOPE = cscope
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
 am__remove_distdir = \
-  { test ! -d "$(distdir)" \
-    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
-         && rm -fr "$(distdir)"; }; }
+  if test -d "$(distdir)"; then \
+    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+      && rm -rf "$(distdir)" \
+      || { sleep 5 && rm -rf "$(distdir)"; }; \
+  else :; fi
+am__post_remove_distdir = $(am__remove_distdir)
 am__relativize = \
   dir0=`pwd`; \
   sed_first='s,^\([^/]*\)/.*$$,\1,'; \
@@ -102,10 +195,14 @@ am__relativize = \
   reldir="$$dir2"
 DIST_ARCHIVES = $(distdir).tar.gz
 GZIP_ENV = --best
+DIST_TARGETS = dist-gzip
 distuninstallcheck_listfiles = find . -type f -print
+am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
+  | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
 distcleancheck_listfiles = find . -type f -print
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 AR = @AR@
 AUTOCONF = @AUTOCONF@
 AUTOGEN = @AUTOGEN@
@@ -117,6 +214,8 @@ CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CROSS_ARCH = @CROSS_ARCH@
+CROSS_LD = @CROSS_LD@
 CUT = @CUT@
 CXX = @CXX@
 CXXCPP = @CXXCPP@
@@ -125,6 +224,7 @@ CXXFLAGS = @CXXFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
 DMALLOC_LIB = @DMALLOC_LIB@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
@@ -159,9 +259,15 @@ LN_S = @LN_S@
 LPCAPINC = @LPCAPINC@
 LPCAPLIB = @LPCAPLIB@
 LTLIBOBJS = @LTLIBOBJS@
+MACOSX_SDK_PATH = @MACOSX_SDK_PATH@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MKDIR_P = @MKDIR_P@
+NETMAPFLAGS = @NETMAPFLAGS@
+NETMAPINC = @NETMAPINC@
+NETMAPINCDIR = @NETMAPINCDIR@
+NETMAPUSERINC = @NETMAPUSERINC@
 NM = @NM@
 NMEDIT = @NMEDIT@
 OBJDUMP = @OBJDUMP@
@@ -177,11 +283,14 @@ PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 PCAP_BPF_H_FILE = @PCAP_BPF_H_FILE@
+PCAP_CONFIG = @PCAP_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
 PRINTF = @PRINTF@
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STDNORETURN_H = @STDNORETURN_H@
 STRIP = @STRIP@
 TCPREPLAY_RELEASE = @TCPREPLAY_RELEASE@
 TCPREPLAY_VERSION = @TCPREPLAY_VERSION@
@@ -190,6 +299,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_CXX = @ac_ct_CXX@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
@@ -208,9 +318,12 @@ builddir = @builddir@
 datadir = @datadir@
 datarootdir = @datarootdir@
 debug_flag = @debug_flag@
+debug_run_time_flag = @debug_run_time_flag@
+depmod = @depmod@
 docdir = @docdir@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+extra_debug_flag = @extra_debug_flag@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -219,12 +332,12 @@ host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
 infodir = @infodir@
+insmod = @insmod@
 install_sh = @install_sh@
 libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 nic1 = @nic1@
@@ -235,6 +348,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+rmmod = @rmmod@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -245,12 +359,12 @@ target_cpu = @target_cpu@
 target_os = @target_os@
 target_vendor = @target_vendor@
 tcpdump_path = @tcpdump_path@
+timestamp_trace_flag = @timestamp_trace_flag@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 
 # $Id$
-AUTOMAKE_OPTIONS = foreign
 ACLOCAL_AMFLAGS = -I m4 -I libopts/m4
 @NEED_LIBOPTS_FALSE@SUBDIRS = scripts lib src
 @NEED_LIBOPTS_TRUE@SUBDIRS = scripts lib $(LIBOPTS_DIR) src
@@ -262,12 +376,12 @@ DISTCLEANFILES = .tm_project.cache stamp-h1 *.tar.*
 MAINTAINERCLEANFILES = Makefile.in configure *.bak
 EXTRA_DIST = doxygen.cfg.in autogen.sh \
 	m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 \
-	m4/ltversion.m4 m4/lt~obsolete.m4
+	m4/ltversion.m4 m4/lt~obsolete.m4 acinclude.m4
 
 all: all-recursive
 
 .SUFFIXES:
-am--refresh:
+am--refresh: Makefile
 	@:
 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
 	@for dep in $?; do \
@@ -314,22 +428,25 @@ distclean-libtool:
 	-rm -f libtool config.lt
 
 # This directory's subdirectories are mostly independent; you can cd
-# into them and run `make' without going through this Makefile.
-# To change the values of `make' variables: instead of editing Makefiles,
-# (1) if the variable is set in `config.status', edit `config.status'
-#     (which will cause the Makefiles to be regenerated when you run `make');
-# (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
-	@fail= failcom='exit 1'; \
-	for f in x $$MAKEFLAGS; do \
-	  case $$f in \
-	    *=* | --[!k]*);; \
-	    *k*) failcom='fail=yes';; \
-	  esac; \
-	done; \
+# into them and run 'make' without going through this Makefile.
+# To change the values of 'make' variables: instead of editing Makefiles,
+# (1) if the variable is set in 'config.status', edit 'config.status'
+#     (which will cause the Makefiles to be regenerated when you run 'make');
+# (2) otherwise, pass the desired values on the 'make' command line.
+$(am__recursive_targets):
+	@fail=; \
+	if $(am__make_keepgoing); then \
+	  failcom='fail=yes'; \
+	else \
+	  failcom='exit 1'; \
+	fi; \
 	dot_seen=no; \
 	target=`echo $@ | sed s/-recursive//`; \
-	list='$(SUBDIRS)'; for subdir in $$list; do \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	for subdir in $$list; do \
 	  echo "Making $$target in $$subdir"; \
 	  if test "$$subdir" = "."; then \
 	    dot_seen=yes; \
@@ -344,57 +461,12 @@ $(RECURSIVE_TARGETS):
 	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
 	fi; test -z "$$fail"
 
-$(RECURSIVE_CLEAN_TARGETS):
-	@fail= failcom='exit 1'; \
-	for f in x $$MAKEFLAGS; do \
-	  case $$f in \
-	    *=* | --[!k]*);; \
-	    *k*) failcom='fail=yes';; \
-	  esac; \
-	done; \
-	dot_seen=no; \
-	case "$@" in \
-	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
-	  *) list='$(SUBDIRS)' ;; \
-	esac; \
-	rev=''; for subdir in $$list; do \
-	  if test "$$subdir" = "."; then :; else \
-	    rev="$$subdir $$rev"; \
-	  fi; \
-	done; \
-	rev="$$rev ."; \
-	target=`echo $@ | sed s/-recursive//`; \
-	for subdir in $$rev; do \
-	  echo "Making $$target in $$subdir"; \
-	  if test "$$subdir" = "."; then \
-	    local_target="$$target-am"; \
-	  else \
-	    local_target="$$target"; \
-	  fi; \
-	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
-	  || eval $$failcom; \
-	done && test -z "$$fail"
-tags-recursive:
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
-	done
-ctags-recursive:
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
-	done
+ID: $(am__tagged_files)
+	$(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-recursive
+TAGS: tags
 
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
-	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	mkid -fID $$unique
-tags: TAGS
-
-TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
 	set x; \
 	here=`pwd`; \
 	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
@@ -410,12 +482,7 @@ TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
 	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
 	  fi; \
 	done; \
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	$(am__define_uniq_tagged_files); \
 	shift; \
 	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
 	  test -n "$$unique" || unique=$$empty_fix; \
@@ -427,15 +494,11 @@ TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
 	      $$unique; \
 	  fi; \
 	fi
-ctags: CTAGS
-CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-recursive
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	$(am__define_uniq_tagged_files); \
 	test -z "$(CTAGS_ARGS)$$unique" \
 	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
 	     $$unique
@@ -444,9 +507,31 @@ GTAGS:
 	here=`$(am__cd) $(top_builddir) && pwd` \
 	  && $(am__cd) $(top_srcdir) \
 	  && gtags -i $(GTAGS_ARGS) "$$here"
+cscope: cscope.files
+	test ! -s cscope.files \
+	  || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS)
+clean-cscope:
+	-rm -f cscope.files
+cscope.files: clean-cscope cscopelist
+cscopelist: cscopelist-recursive
+
+cscopelist-am: $(am__tagged_files)
+	list='$(am__tagged_files)'; \
+	case "$(srcdir)" in \
+	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+	  *) sdir=$(subdir)/$(srcdir) ;; \
+	esac; \
+	for i in $$list; do \
+	  if test -f "$$i"; then \
+	    echo "$(subdir)/$$i"; \
+	  else \
+	    echo "$$sdir/$$i"; \
+	  fi; \
+	done >> $(top_builddir)/cscope.files
 
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+	-rm -f cscope.out cscope.in.out cscope.po.out cscope.files
 
 distdir: $(DISTFILES)
 	$(am__remove_distdir)
@@ -482,13 +567,10 @@ distdir: $(DISTFILES)
 	done
 	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
 	  if test "$$subdir" = .; then :; else \
-	    test -d "$(distdir)/$$subdir" \
-	    || $(MKDIR_P) "$(distdir)/$$subdir" \
-	    || exit 1; \
-	  fi; \
-	done
-	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-	  if test "$$subdir" = .; then :; else \
+	    $(am__make_dryrun) \
+	      || test -d "$(distdir)/$$subdir" \
+	      || $(MKDIR_P) "$(distdir)/$$subdir" \
+	      || exit 1; \
 	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
 	    $(am__relativize); \
 	    new_distdir=$$reldir; \
@@ -520,36 +602,42 @@ distdir: $(DISTFILES)
 	|| chmod -R a+r "$(distdir)"
 dist-gzip: distdir
 	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
-	$(am__remove_distdir)
+	$(am__post_remove_distdir)
 
 dist-bzip2: distdir
-	tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
-	$(am__remove_distdir)
+	tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
+	$(am__post_remove_distdir)
 
-dist-lzma: distdir
-	tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
-	$(am__remove_distdir)
+dist-lzip: distdir
+	tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
+	$(am__post_remove_distdir)
 
 dist-xz: distdir
-	tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
-	$(am__remove_distdir)
+	tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
+	$(am__post_remove_distdir)
 
 dist-tarZ: distdir
+	@echo WARNING: "Support for shar distribution archives is" \
+	               "deprecated." >&2
+	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
 	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
-	$(am__remove_distdir)
+	$(am__post_remove_distdir)
 
 dist-shar: distdir
+	@echo WARNING: "Support for distribution archives compressed with" \
+		       "legacy program 'compress' is deprecated." >&2
+	@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
 	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
-	$(am__remove_distdir)
+	$(am__post_remove_distdir)
 
 dist-zip: distdir
 	-rm -f $(distdir).zip
 	zip -rq $(distdir).zip $(distdir)
-	$(am__remove_distdir)
+	$(am__post_remove_distdir)
 
-dist dist-all: distdir
-	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
-	$(am__remove_distdir)
+dist dist-all:
+	$(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:'
+	$(am__post_remove_distdir)
 
 # This target untars the dist file and tries a VPATH configuration.  Then
 # it guarantees that the distribution is self-contained by making another
@@ -560,8 +648,8 @@ distcheck: dist
 	  GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
 	*.tar.bz2*) \
 	  bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
-	*.tar.lzma*) \
-	  lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
+	*.tar.lz*) \
+	  lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
 	*.tar.xz*) \
 	  xz -dc $(distdir).tar.xz | $(am__untar) ;;\
 	*.tar.Z*) \
@@ -571,17 +659,19 @@ distcheck: dist
 	*.zip*) \
 	  unzip $(distdir).zip ;;\
 	esac
-	chmod -R a-w $(distdir); chmod a+w $(distdir)
-	mkdir $(distdir)/_build
-	mkdir $(distdir)/_inst
+	chmod -R a-w $(distdir)
+	chmod u+w $(distdir)
+	mkdir $(distdir)/_build $(distdir)/_inst
 	chmod a-w $(distdir)
 	test -d $(distdir)/_build || exit 0; \
 	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
 	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
 	  && am__cwd=`pwd` \
 	  && $(am__cd) $(distdir)/_build \
-	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+	  && ../configure \
+	    $(AM_DISTCHECK_CONFIGURE_FLAGS) \
 	    $(DISTCHECK_CONFIGURE_FLAGS) \
+	    --srcdir=.. --prefix="$$dc_install_base" \
 	  && $(MAKE) $(AM_MAKEFLAGS) \
 	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
 	  && $(MAKE) $(AM_MAKEFLAGS) check \
@@ -604,13 +694,21 @@ distcheck: dist
 	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
 	  && cd "$$am__cwd" \
 	  || exit 1
-	$(am__remove_distdir)
+	$(am__post_remove_distdir)
 	@(echo "$(distdir) archives ready for distribution: "; \
 	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
 	  sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
 distuninstallcheck:
-	@$(am__cd) '$(distuninstallcheck_dir)' \
-	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+	@test -n '$(distuninstallcheck_dir)' || { \
+	  echo 'ERROR: trying to run $@ with an empty' \
+	       '$$(distuninstallcheck_dir)' >&2; \
+	  exit 1; \
+	}; \
+	$(am__cd) '$(distuninstallcheck_dir)' || { \
+	  echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \
+	  exit 1; \
+	}; \
+	test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \
 	   || { echo "ERROR: files left after uninstall:" ; \
 	        if test -n "$(DESTDIR)"; then \
 	          echo "  (check DESTDIR support)"; \
@@ -641,10 +739,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
 mostlyclean-generic:
 	-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
 
@@ -729,32 +832,28 @@ ps-am:
 
 uninstall-am:
 
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
-	install-am install-strip tags-recursive
-
-.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
-	all all-am am--refresh check check-am clean clean-generic \
-	clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \
-	dist-gzip dist-hook dist-lzma dist-shar dist-tarZ dist-xz \
-	dist-zip distcheck distclean distclean-generic \
-	distclean-libtool distclean-local distclean-tags \
-	distcleancheck distdir distuninstallcheck dvi dvi-am html \
-	html-am info info-am install install-am install-data \
-	install-data-am install-dvi install-dvi-am install-exec \
-	install-exec-am install-html install-html-am install-info \
-	install-info-am install-man install-pdf install-pdf-am \
-	install-ps install-ps-am install-strip installcheck \
-	installcheck-am installdirs installdirs-am maintainer-clean \
-	maintainer-clean-generic mostlyclean mostlyclean-generic \
-	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
-	uninstall uninstall-am
+.MAKE: $(am__recursive_targets) install-am install-strip
+
+.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \
+	am--refresh check check-am clean clean-cscope clean-generic \
+	clean-libtool cscope cscopelist-am ctags ctags-am dist \
+	dist-all dist-bzip2 dist-gzip dist-hook dist-lzip dist-shar \
+	dist-tarZ dist-xz dist-zip distcheck distclean \
+	distclean-generic distclean-libtool distclean-local \
+	distclean-tags distcleancheck distdir distuninstallcheck dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-ps install-ps-am install-strip \
+	installcheck installcheck-am installdirs installdirs-am \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags tags-am uninstall uninstall-am
 
 .PHONY: manpages docs test man2html
 
-dist-hook: version manpages update
-
-update:
-	svn update
+dist-hook: version manpages
 
 manpages:
 	cd src && make manpages
@@ -780,8 +879,8 @@ dlt_names:
 	cat @SAVEFILE_C@ | $(top_builddir)/scripts/dlt2name.pl src/dlt_names.h
 
 version:
-	-rm -f src/common/svn_version.c
-	cd src/common && make svn_version.c
+	-rm -f src/common/git_version.c
+	cd src/common && make git_version.c
 
 distclean-local:
 	-rm -rf autom4te.cache doxygen

+ 0 - 48
README

@@ -1,48 +0,0 @@
-$Id: README 1796 2007-04-11 04:55:14Z aturner $
-[Please note that licensing, compiling, usage and other documentation can be 
-found in the docs subdirectory.]
-
-If you have a question or think you are experiancing a bug, it is important
-that you provide enough information for us to help you.  Failure to provide
-enough information will likely cause your email to be ignored or get an
-annoyed reply from the author.
-
-If your problem has to do with COMPILING tcpreplay:
-- Version of tcpreplay you are trying to compile
-- Platform (Red Hat Linux 9 on x86, Solaris 7 on SPARC, OS X on PPC, etc)
-- ./configure arguments
-- Contents of config.log
-- Output from 'make'
-- Any additional information you think that would be useful.
-
-If your problem has to do with RUNNING tcpreplay or one of the sub-tools:
-- Version information (output of -V)
-- Command line used (options and arguments)
-- Platform (Red Hat Linux 9 on Intel, Solaris 7 on SPARC, etc)
-- Make & model of the network card(s) and driver(s) version
-- Error message (if available) and/or description of problem
-- If possible, attach the pcap file used (compressed with bzip2 or gzip
-    preferred)
-- The core dump or backtrace if available
-- Detailed description of your problem or what you are trying to accomplish
-
-Note: The author of tcpreplay primarily uses OS X; hence, if you're reporting
-an issue on another platform, it is important that you give very detailed
-information as I may not be able to reproduce your issue.
-
-You are also strongly encouraged to read the extensive documentation (man
-pages, FAQ, documents in /docs and email list archives) BEFORE posting to the
-tcpreplay-users email list:
-
-http://lists.sourceforge.net/lists/listinfo/tcpreplay-users
-
-Lastly, please don't email the author directly with your questions.  Doing so
-prevents others from potentially helping you and your question/answer from
-showing up in the list archives.
-
-Thanks,
-Aaron (tcpreplay author)
-
-PS:
-This product includes software developed by the University of
-California, Berkeley, Lawrence Berkeley Laboratory and its contributors.

+ 88 - 0
acinclude.m4

@@ -0,0 +1,88 @@
+##
+## additional m4 macros
+##
+## (C) 1999 Christoph Bartelmus (lirc@bartelmus.de)
+##
+
+
+dnl check for kernel source
+
+AC_DEFUN([AC_PATH_KERNEL_SOURCE_SEARCH],
+[
+    kerneldir=missing
+    kernelext=ko
+    no_kernel=yes
+
+    if test `uname` != "Linux"; then
+        kerneldir="not running Linux"
+    else
+        shortvers="$( uname -r | sed -r 's/(@<:@2-9@:>@\.@<:@0-9@:>@+).*/\1/' )"
+        if test x${ac_kerneldir} != x; then
+            if test -d ${ac_kerneldir}; then
+                kerneldir=`dirname ${ac_kerneldir}/Makefile`/
+                no_kernel=no
+            fi
+        else
+            for dir in /lib/modules/`uname -r`/build \
+                    /lib/modules/`uname -r`/source \
+                    /usr/src/kernel-source-`uname -r` \
+                    /usr/src/linux-source-`uname -r` \
+                    /usr/src/kernel-source-$shortvers \
+                    /usr/src/linux-source-$shortvers \
+                    /usr/src/linux
+            do
+                if test -d $dir; then
+                    kerneldir=`dirname $dir/Makefile`/
+                    no_kernel=no
+                    break
+                fi
+            done
+        fi
+    fi
+
+    if test x${no_kernel} != xyes; then
+        if test -f ${kerneldir}/Makefile -a -f ${kerneldir}/.config; then
+            version=$( sed -n '/^VERSION/s/.*=\ *//p' ${kerneldir}/Makefile )
+            patchlevel=$( sed -n -e '/^PATCHLEVEL/s/.*=\ *//p' ${kerneldir}/Makefile )
+            kerneluname=$( sed -n '/Linux kernel version/s/.*:\ *//p' ${kerneldir}/.config )
+            if test "${version}" -eq 2; then
+                if test "${patchlevel}" -lt 5; then
+                    kernelext=o
+                fi
+            fi
+        else
+            kerneldir="not found"
+            no_kernel=yes
+        fi
+    fi
+
+    ac_cv_have_kernel="no_kernel=${no_kernel} \
+            kerneldir=\"${kerneldir}\" \
+            kernelext=\"${kernelext}\""
+
+]
+)
+
+AC_DEFUN([AC_PATH_KERNEL_SOURCE],
+[
+    AC_CHECK_PROG(ac_pkss_mktemp,mktemp,yes,no)
+    AC_PROVIDE([AC_PATH_KERNEL_SOURCE])
+    AC_MSG_CHECKING(for Linux kernel sources)
+
+    AC_ARG_WITH(kernel,
+        [  --with-kernel=DIR       Use Linux kernel sources in DIR],
+
+        ac_kerneldir=${withval}
+        AC_PATH_KERNEL_SOURCE_SEARCH,
+
+        ac_kerneldir=""
+        AC_CACHE_VAL(ac_cv_have_kernel,AC_PATH_KERNEL_SOURCE_SEARCH)
+    )
+
+    eval "$ac_cv_have_kernel"
+
+    AC_SUBST(kerneldir)
+    AC_SUBST(kernelext)
+    AC_MSG_RESULT(${kerneldir})
+]
+)

File diff suppressed because it is too large
+ 481 - 8278
aclocal.m4


+ 4 - 4
autogen.sh

@@ -2,11 +2,11 @@
 rm -f config/config.guess config/config.sub config/ltmain.sh 2>/dev/null
 rm -f aclocal.m4 2>/dev/null
 aclocal  -I libopts/m4/
-if test -x "`which libtoolize`" ; then
-    libtoolize --copy
-else
+if test -x "$(which glibtoolize)" ; then
     # Necessary under OS X
-    glibtoolize --copy
+    glibtoolize --copy --automake --force
+else
+    libtoolize --copy --force
 fi
 autoheader
 automake --add-missing --copy

+ 265 - 54
config/compile

@@ -1,9 +1,9 @@
 #! /bin/sh
-# Wrapper for compilers which do not understand `-c -o'.
+# Wrapper for compilers which do not understand '-c -o'.
 
-scriptversion=2003-11-09.00
+scriptversion=2012-10-14.11; # UTC
 
-# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -17,8 +17,7 @@ scriptversion=2003-11-09.00
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -29,102 +28,313 @@ scriptversion=2003-11-09.00
 # bugs to <bug-automake@gnu.org> or send patches to
 # <automake-patches@gnu.org>.
 
+nl='
+'
+
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent tools from complaining about whitespace usage.
+IFS=" ""	$nl"
+
+file_conv=
+
+# func_file_conv build_file lazy
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Windows hosts. If the determined conversion
+# type is listed in (the comma separated) LAZY, no conversion will
+# take place.
+func_file_conv ()
+{
+  file=$1
+  case $file in
+    / | /[!/]*) # absolute file, and not a UNC file
+      if test -z "$file_conv"; then
+	# lazily determine how to convert abs files
+	case `uname -s` in
+	  MINGW*)
+	    file_conv=mingw
+	    ;;
+	  CYGWIN*)
+	    file_conv=cygwin
+	    ;;
+	  *)
+	    file_conv=wine
+	    ;;
+	esac
+      fi
+      case $file_conv/,$2, in
+	*,$file_conv,*)
+	  ;;
+	mingw/*)
+	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+	  ;;
+	cygwin/*)
+	  file=`cygpath -m "$file" || echo "$file"`
+	  ;;
+	wine/*)
+	  file=`winepath -w "$file" || echo "$file"`
+	  ;;
+      esac
+      ;;
+  esac
+}
+
+# func_cl_dashL linkdir
+# Make cl look for libraries in LINKDIR
+func_cl_dashL ()
+{
+  func_file_conv "$1"
+  if test -z "$lib_path"; then
+    lib_path=$file
+  else
+    lib_path="$lib_path;$file"
+  fi
+  linker_opts="$linker_opts -LIBPATH:$file"
+}
+
+# func_cl_dashl library
+# Do a library search-path lookup for cl
+func_cl_dashl ()
+{
+  lib=$1
+  found=no
+  save_IFS=$IFS
+  IFS=';'
+  for dir in $lib_path $LIB
+  do
+    IFS=$save_IFS
+    if $shared && test -f "$dir/$lib.dll.lib"; then
+      found=yes
+      lib=$dir/$lib.dll.lib
+      break
+    fi
+    if test -f "$dir/$lib.lib"; then
+      found=yes
+      lib=$dir/$lib.lib
+      break
+    fi
+    if test -f "$dir/lib$lib.a"; then
+      found=yes
+      lib=$dir/lib$lib.a
+      break
+    fi
+  done
+  IFS=$save_IFS
+
+  if test "$found" != yes; then
+    lib=$lib.lib
+  fi
+}
+
+# func_cl_wrapper cl arg...
+# Adjust compile command to suit cl
+func_cl_wrapper ()
+{
+  # Assume a capable shell
+  lib_path=
+  shared=:
+  linker_opts=
+  for arg
+  do
+    if test -n "$eat"; then
+      eat=
+    else
+      case $1 in
+	-o)
+	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
+	  eat=1
+	  case $2 in
+	    *.o | *.[oO][bB][jJ])
+	      func_file_conv "$2"
+	      set x "$@" -Fo"$file"
+	      shift
+	      ;;
+	    *)
+	      func_file_conv "$2"
+	      set x "$@" -Fe"$file"
+	      shift
+	      ;;
+	  esac
+	  ;;
+	-I)
+	  eat=1
+	  func_file_conv "$2" mingw
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-I*)
+	  func_file_conv "${1#-I}" mingw
+	  set x "$@" -I"$file"
+	  shift
+	  ;;
+	-l)
+	  eat=1
+	  func_cl_dashl "$2"
+	  set x "$@" "$lib"
+	  shift
+	  ;;
+	-l*)
+	  func_cl_dashl "${1#-l}"
+	  set x "$@" "$lib"
+	  shift
+	  ;;
+	-L)
+	  eat=1
+	  func_cl_dashL "$2"
+	  ;;
+	-L*)
+	  func_cl_dashL "${1#-L}"
+	  ;;
+	-static)
+	  shared=false
+	  ;;
+	-Wl,*)
+	  arg=${1#-Wl,}
+	  save_ifs="$IFS"; IFS=','
+	  for flag in $arg; do
+	    IFS="$save_ifs"
+	    linker_opts="$linker_opts $flag"
+	  done
+	  IFS="$save_ifs"
+	  ;;
+	-Xlinker)
+	  eat=1
+	  linker_opts="$linker_opts $2"
+	  ;;
+	-*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
+	  func_file_conv "$1"
+	  set x "$@" -Tp"$file"
+	  shift
+	  ;;
+	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
+	  func_file_conv "$1" mingw
+	  set x "$@" "$file"
+	  shift
+	  ;;
+	*)
+	  set x "$@" "$1"
+	  shift
+	  ;;
+      esac
+    fi
+    shift
+  done
+  if test -n "$linker_opts"; then
+    linker_opts="-link$linker_opts"
+  fi
+  exec "$@" $linker_opts
+  exit 1
+}
+
+eat=
+
 case $1 in
   '')
-     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
      exit 1;
      ;;
   -h | --h*)
     cat <<\EOF
 Usage: compile [--help] [--version] PROGRAM [ARGS]
 
-Wrapper for compilers which do not understand `-c -o'.
-Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
+Wrapper for compilers which do not understand '-c -o'.
+Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
 arguments, and rename the output as expected.
 
 If you are trying to build a whole package this is not the
-right script to run: please start by reading the file `INSTALL'.
+right script to run: please start by reading the file 'INSTALL'.
 
 Report bugs to <bug-automake@gnu.org>.
 EOF
-    exit 0
+    exit $?
     ;;
   -v | --v*)
     echo "compile $scriptversion"
-    exit 0
+    exit $?
+    ;;
+  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
+    func_cl_wrapper "$@"      # Doesn't return...
     ;;
 esac
 
-
-prog=$1
-shift
-
 ofile=
 cfile=
-args=
-while test $# -gt 0; do
-  case "$1" in
-    -o)
-      # configure might choose to run compile as `compile cc -o foo foo.c'.
-      # So we do something ugly here.
-      ofile=$2
-      shift
-      case "$ofile" in
-	*.o | *.obj)
-	  ;;
-	*)
-	  args="$args -o $ofile"
-	  ofile=
-	  ;;
-      esac
-       ;;
-    *.c)
-      cfile=$1
-      args="$args $1"
-      ;;
-    *)
-      args="$args $1"
-      ;;
-  esac
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as 'compile cc -o foo foo.c'.
+	# So we strip '-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
   shift
 done
 
 if test -z "$ofile" || test -z "$cfile"; then
-  # If no `-o' option was seen then we might have been invoked from a
+  # If no '-o' option was seen then we might have been invoked from a
   # pattern rule where we don't need one.  That is ok -- this is a
   # normal compilation that the losing compiler can handle.  If no
-  # `.c' file was seen then we are probably linking.  That is also
+  # '.c' file was seen then we are probably linking.  That is also
   # ok.
-  exec "$prog" $args
+  exec "$@"
 fi
 
 # Name of file we expect compiler to create.
-cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
+cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
 
 # Create the lock directory.
-# Note: use `[/.-]' here to ensure that we don't use the same name
+# Note: use '[/\\:.-]' here to ensure that we don't use the same name
 # that we are using for the .o file.  Also, base the name on the expected
 # object file name, since that is what matters with a parallel build.
-lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
+lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
 while true; do
-  if mkdir $lockdir > /dev/null 2>&1; then
+  if mkdir "$lockdir" >/dev/null 2>&1; then
     break
   fi
   sleep 1
 done
 # FIXME: race condition here if user kills between mkdir and trap.
-trap "rmdir $lockdir; exit 1" 1 2 15
+trap "rmdir '$lockdir'; exit 1" 1 2 15
 
 # Run the compile.
-"$prog" $args
-status=$?
+"$@"
+ret=$?
 
 if test -f "$cofile"; then
-  mv "$cofile" "$ofile"
+  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
 fi
 
-rmdir $lockdir
-exit $status
+rmdir "$lockdir"
+exit $ret
 
 # Local Variables:
 # mode: shell-script
@@ -132,5 +342,6 @@ exit $status
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:

+ 239 - 320
config/config.guess

@@ -1,14 +1,12 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-#   Free Software Foundation, Inc.
+#   Copyright 1992-2014 Free Software Foundation, Inc.
 
-timestamp='2009-11-20'
+timestamp='2014-03-23'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
@@ -17,26 +15,22 @@ timestamp='2009-11-20'
 # General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-# 02110-1301, USA.
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-
-# Originally written by Per Bothner.  Please send patches (context
-# diff format) to <config-patches@gnu.org> and include a ChangeLog
-# entry.
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
 #
-# This script attempts to guess a canonical system name similar to
-# config.sub.  If it succeeds, it prints the system name on stdout, and
-# exits with 0.  Otherwise, it exits with 1.
+# Originally written by Per Bothner.
 #
 # You can get the latest version of this script from:
 # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+#
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+
 
 me=`echo "$0" | sed -e 's,.*/,,'`
 
@@ -56,8 +50,7 @@ version="\
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+Copyright 1992-2014 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -139,12 +132,33 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
 UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
 
+case "${UNAME_SYSTEM}" in
+Linux|GNU|GNU/*)
+	# If the system lacks a compiler, then just pick glibc.
+	# We could probably try harder.
+	LIBC=gnu
+
+	eval $set_cc_for_build
+	cat <<-EOF > $dummy.c
+	#include <features.h>
+	#if defined(__UCLIBC__)
+	LIBC=uclibc
+	#elif defined(__dietlibc__)
+	LIBC=dietlibc
+	#else
+	LIBC=gnu
+	#endif
+	EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
+	;;
+esac
+
 # Note: order is significant - the case branches are not exclusive.
 
 case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
     *:NetBSD:*:*)
 	# NetBSD (nbsd) targets should (where applicable) match one or
-	# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
 	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
 	# switched to ELF, *-*-netbsd* would select the old
 	# object file format.  This provides both forward
@@ -180,7 +194,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 		fi
 		;;
 	    *)
-	        os=netbsd
+		os=netbsd
 		;;
 	esac
 	# The OS release
@@ -201,6 +215,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	echo "${machine}-${os}${release}"
 	exit ;;
+    *:Bitrig:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
+	exit ;;
     *:OpenBSD:*:*)
 	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
 	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
@@ -223,7 +241,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
 		;;
 	*5.*)
-	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
 		;;
 	esac
 	# According to Compaq, /usr/sbin/psrinfo has been available on
@@ -269,7 +287,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 	# A Xn.n version is an unreleased experimental baselevel.
 	# 1.2 uses "1.2" for uname -r.
 	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-	exit ;;
+	# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+	exitcode=$?
+	trap '' 0
+	exit $exitcode ;;
     Alpha\ *:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# Should we change UNAME_MACHINE based on the output of uname instead
@@ -295,12 +316,12 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 	echo s390-ibm-zvmoe
 	exit ;;
     *:OS400:*:*)
-        echo powerpc-ibm-os400
+	echo powerpc-ibm-os400
 	exit ;;
     arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
 	echo arm-acorn-riscix${UNAME_RELEASE}
 	exit ;;
-    arm:riscos:*:*|arm:RISCOS:*:*)
+    arm*:riscos:*:*|arm*:RISCOS:*:*)
 	echo arm-unknown-riscos
 	exit ;;
     SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
@@ -394,23 +415,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
     # MiNT.  But MiNT is downward compatible to TOS, so this should
     # be no problem.
     atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
-        echo m68k-atari-mint${UNAME_RELEASE}
+	echo m68k-atari-mint${UNAME_RELEASE}
 	exit ;;
     atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
 	echo m68k-atari-mint${UNAME_RELEASE}
-        exit ;;
+	exit ;;
     *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
-        echo m68k-atari-mint${UNAME_RELEASE}
+	echo m68k-atari-mint${UNAME_RELEASE}
 	exit ;;
     milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
-        echo m68k-milan-mint${UNAME_RELEASE}
-        exit ;;
+	echo m68k-milan-mint${UNAME_RELEASE}
+	exit ;;
     hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
-        echo m68k-hades-mint${UNAME_RELEASE}
-        exit ;;
+	echo m68k-hades-mint${UNAME_RELEASE}
+	exit ;;
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
-        echo m68k-unknown-mint${UNAME_RELEASE}
-        exit ;;
+	echo m68k-unknown-mint${UNAME_RELEASE}
+	exit ;;
     m68k:machten:*:*)
 	echo m68k-apple-machten${UNAME_RELEASE}
 	exit ;;
@@ -480,8 +501,8 @@ EOF
 	echo m88k-motorola-sysv3
 	exit ;;
     AViiON:dgux:*:*)
-        # DG/UX returns AViiON for all architectures
-        UNAME_PROCESSOR=`/usr/bin/uname -p`
+	# DG/UX returns AViiON for all architectures
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
 	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
 	then
 	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
@@ -494,7 +515,7 @@ EOF
 	else
 	    echo i586-dg-dgux${UNAME_RELEASE}
 	fi
- 	exit ;;
+	exit ;;
     M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
 	echo m88k-dolphin-sysv3
 	exit ;;
@@ -551,7 +572,7 @@ EOF
 		echo rs6000-ibm-aix3.2
 	fi
 	exit ;;
-    *:AIX:*:[456])
+    *:AIX:*:[4567])
 	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
 	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
 		IBM_ARCH=rs6000
@@ -594,52 +615,52 @@ EOF
 	    9000/[678][0-9][0-9])
 		if [ -x /usr/bin/getconf ]; then
 		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
-                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
-                    case "${sc_cpu_version}" in
-                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
-                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
-                      532)                      # CPU_PA_RISC2_0
-                        case "${sc_kernel_bits}" in
-                          32) HP_ARCH="hppa2.0n" ;;
-                          64) HP_ARCH="hppa2.0w" ;;
+		    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+		    case "${sc_cpu_version}" in
+		      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+		      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+		      532)                      # CPU_PA_RISC2_0
+			case "${sc_kernel_bits}" in
+			  32) HP_ARCH="hppa2.0n" ;;
+			  64) HP_ARCH="hppa2.0w" ;;
 			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
-                        esac ;;
-                    esac
+			esac ;;
+		    esac
 		fi
 		if [ "${HP_ARCH}" = "" ]; then
 		    eval $set_cc_for_build
-		    sed 's/^              //' << EOF >$dummy.c
+		    sed 's/^		//' << EOF >$dummy.c
 
-              #define _HPUX_SOURCE
-              #include <stdlib.h>
-              #include <unistd.h>
+		#define _HPUX_SOURCE
+		#include <stdlib.h>
+		#include <unistd.h>
 
-              int main ()
-              {
-              #if defined(_SC_KERNEL_BITS)
-                  long bits = sysconf(_SC_KERNEL_BITS);
-              #endif
-                  long cpu  = sysconf (_SC_CPU_VERSION);
+		int main ()
+		{
+		#if defined(_SC_KERNEL_BITS)
+		    long bits = sysconf(_SC_KERNEL_BITS);
+		#endif
+		    long cpu  = sysconf (_SC_CPU_VERSION);
 
-                  switch (cpu)
-              	{
-              	case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
-              	case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
-              	case CPU_PA_RISC2_0:
-              #if defined(_SC_KERNEL_BITS)
-              	    switch (bits)
-              		{
-              		case 64: puts ("hppa2.0w"); break;
-              		case 32: puts ("hppa2.0n"); break;
-              		default: puts ("hppa2.0"); break;
-              		} break;
-              #else  /* !defined(_SC_KERNEL_BITS) */
-              	    puts ("hppa2.0"); break;
-              #endif
-              	default: puts ("hppa1.0"); break;
-              	}
-                  exit (0);
-              }
+		    switch (cpu)
+			{
+			case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+			case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+			case CPU_PA_RISC2_0:
+		#if defined(_SC_KERNEL_BITS)
+			    switch (bits)
+				{
+				case 64: puts ("hppa2.0w"); break;
+				case 32: puts ("hppa2.0n"); break;
+				default: puts ("hppa2.0"); break;
+				} break;
+		#else  /* !defined(_SC_KERNEL_BITS) */
+			    puts ("hppa2.0"); break;
+		#endif
+			default: puts ("hppa1.0"); break;
+			}
+		    exit (0);
+		}
 EOF
 		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
 		    test -z "$HP_ARCH" && HP_ARCH=hppa
@@ -730,22 +751,22 @@ EOF
 	exit ;;
     C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
 	echo c1-convex-bsd
-        exit ;;
+	exit ;;
     C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-        exit ;;
+	exit ;;
     C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
 	echo c34-convex-bsd
-        exit ;;
+	exit ;;
     C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
 	echo c38-convex-bsd
-        exit ;;
+	exit ;;
     C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
 	echo c4-convex-bsd
-        exit ;;
+	exit ;;
     CRAY*Y-MP:*:*:*)
 	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	exit ;;
@@ -769,14 +790,14 @@ EOF
 	exit ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
-        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
-        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-        exit ;;
+	FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+	echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
     5000:UNIX_System_V:4.*:*)
-        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
-        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
-        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+	echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
 	exit ;;
     i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
 	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
@@ -788,30 +809,35 @@ EOF
 	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
 	exit ;;
     *:FreeBSD:*:*)
-	case ${UNAME_MACHINE} in
-	    pc98)
-		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	case ${UNAME_PROCESSOR} in
 	    amd64)
 		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
 	    *)
-		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+		echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
 	esac
 	exit ;;
     i*:CYGWIN*:*)
 	echo ${UNAME_MACHINE}-pc-cygwin
 	exit ;;
+    *:MINGW64*:*)
+	echo ${UNAME_MACHINE}-pc-mingw64
+	exit ;;
     *:MINGW*:*)
 	echo ${UNAME_MACHINE}-pc-mingw32
 	exit ;;
+    *:MSYS*:*)
+	echo ${UNAME_MACHINE}-pc-msys
+	exit ;;
     i*:windows32*:*)
-    	# uname -m includes "-pc" on this system.
-    	echo ${UNAME_MACHINE}-mingw32
+	# uname -m includes "-pc" on this system.
+	echo ${UNAME_MACHINE}-mingw32
 	exit ;;
     i*:PW*:*)
 	echo ${UNAME_MACHINE}-pc-pw32
 	exit ;;
     *:Interix*:*)
-    	case ${UNAME_MACHINE} in
+	case ${UNAME_MACHINE} in
 	    x86)
 		echo i586-pc-interix${UNAME_RELEASE}
 		exit ;;
@@ -848,15 +874,22 @@ EOF
 	exit ;;
     *:GNU:*:*)
 	# the GNU system
-	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
 	exit ;;
     *:GNU/*:*:*)
 	# other systems with GNU libc and userland
-	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
 	exit ;;
     i*86:Minix:*:*)
 	echo ${UNAME_MACHINE}-pc-minix
 	exit ;;
+    aarch64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    aarch64_be:Linux:*:*)
+	UNAME_MACHINE=aarch64_be
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
     alpha:Linux:*:*)
 	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
@@ -866,52 +899,56 @@ EOF
 	  EV6)   UNAME_MACHINE=alphaev6 ;;
 	  EV67)  UNAME_MACHINE=alphaev67 ;;
 	  EV68*) UNAME_MACHINE=alphaev68 ;;
-        esac
+	esac
 	objdump --private-headers /bin/sh | grep -q ld.so.1
-	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
-	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+	if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arc:Linux:*:* | arceb:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     arm*:Linux:*:*)
 	eval $set_cc_for_build
 	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
 	    | grep -q __ARM_EABI__
 	then
-	    echo ${UNAME_MACHINE}-unknown-linux-gnu
+	    echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	else
-	    echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+	    if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+		| grep -q __ARM_PCS_VFP
+	    then
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
+	    else
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
+	    fi
 	fi
 	exit ;;
     avr32*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     cris:Linux:*:*)
-	echo cris-axis-linux-gnu
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
 	exit ;;
     crisv32:Linux:*:*)
-	echo crisv32-axis-linux-gnu
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
 	exit ;;
     frv:Linux:*:*)
-    	echo frv-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    hexagon:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     i*86:Linux:*:*)
-	LIBC=gnu
-	eval $set_cc_for_build
-	sed 's/^	//' << EOF >$dummy.c
-	#ifdef __dietlibc__
-	LIBC=dietlibc
-	#endif
-EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
-	echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+	echo ${UNAME_MACHINE}-pc-linux-${LIBC}
 	exit ;;
     ia64:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     m32r*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     m68*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     mips:Linux:*:* | mips64:Linux:*:*)
 	eval $set_cc_for_build
@@ -930,51 +967,63 @@ EOF
 	#endif
 EOF
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
-	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
 	;;
-    or32:Linux:*:*)
-	echo or32-unknown-linux-gnu
+    openrisc*:Linux:*:*)
+	echo or1k-unknown-linux-${LIBC}
+	exit ;;
+    or32:Linux:*:* | or1k*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     padre:Linux:*:*)
-	echo sparc-unknown-linux-gnu
+	echo sparc-unknown-linux-${LIBC}
 	exit ;;
     parisc64:Linux:*:* | hppa64:Linux:*:*)
-	echo hppa64-unknown-linux-gnu
+	echo hppa64-unknown-linux-${LIBC}
 	exit ;;
     parisc:Linux:*:* | hppa:Linux:*:*)
 	# Look for CPU level
 	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
-	  PA7*) echo hppa1.1-unknown-linux-gnu ;;
-	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
-	  *)    echo hppa-unknown-linux-gnu ;;
+	  PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
+	  PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
+	  *)    echo hppa-unknown-linux-${LIBC} ;;
 	esac
 	exit ;;
     ppc64:Linux:*:*)
-	echo powerpc64-unknown-linux-gnu
+	echo powerpc64-unknown-linux-${LIBC}
 	exit ;;
     ppc:Linux:*:*)
-	echo powerpc-unknown-linux-gnu
+	echo powerpc-unknown-linux-${LIBC}
+	exit ;;
+    ppc64le:Linux:*:*)
+	echo powerpc64le-unknown-linux-${LIBC}
+	exit ;;
+    ppcle:Linux:*:*)
+	echo powerpcle-unknown-linux-${LIBC}
 	exit ;;
     s390:Linux:*:* | s390x:Linux:*:*)
-	echo ${UNAME_MACHINE}-ibm-linux
+	echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
 	exit ;;
     sh64*:Linux:*:*)
-    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     sh*:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     sparc:Linux:*:* | sparc64:Linux:*:*)
-	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    tile*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     vax:Linux:*:*)
-	echo ${UNAME_MACHINE}-dec-linux-gnu
+	echo ${UNAME_MACHINE}-dec-linux-${LIBC}
 	exit ;;
     x86_64:Linux:*:*)
-	echo x86_64-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     xtensa*:Linux:*:*)
-    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
 	exit ;;
     i*86:DYNIX/ptx:4*:*)
 	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
@@ -983,11 +1032,11 @@ EOF
 	echo i386-sequent-sysv4
 	exit ;;
     i*86:UNIX_SV:4.2MP:2.*)
-        # Unixware is an offshoot of SVR4, but it has its own version
-        # number series starting with 2...
-        # I am not positive that other SVR4 systems won't match this,
+	# Unixware is an offshoot of SVR4, but it has its own version
+	# number series starting with 2...
+	# I am not positive that other SVR4 systems won't match this,
 	# I just have to hope.  -- rms.
-        # Use sysv4.2uw... so that sysv4* matches it.
+	# Use sysv4.2uw... so that sysv4* matches it.
 	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
 	exit ;;
     i*86:OS/2:*:*)
@@ -1019,7 +1068,7 @@ EOF
 	fi
 	exit ;;
     i*86:*:5:[678]*)
-    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	# UnixWare 7.x, OpenUNIX and OpenServer 6.
 	case `/bin/uname -X | grep "^Machine"` in
 	    *486*)	     UNAME_MACHINE=i486 ;;
 	    *Pentium)	     UNAME_MACHINE=i586 ;;
@@ -1047,13 +1096,13 @@ EOF
 	exit ;;
     pc:*:*:*)
 	# Left here for compatibility:
-        # uname -m prints for DJGPP always 'pc', but it prints nothing about
-        # the processor, so we play safe by assuming i586.
+	# uname -m prints for DJGPP always 'pc', but it prints nothing about
+	# the processor, so we play safe by assuming i586.
 	# Note: whatever this is, it MUST be the same as what config.sub
 	# prints for the "djgpp" host, or else GDB configury will decide that
 	# this is a cross-build.
 	echo i586-pc-msdosdjgpp
-        exit ;;
+	exit ;;
     Intel:Mach:3*:*)
 	echo i386-pc-mach3
 	exit ;;
@@ -1088,8 +1137,8 @@ EOF
 	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
 	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
     3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
-        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-          && { echo i486-ncr-sysv4; exit; } ;;
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4; exit; } ;;
     NCR*:*:4.2:* | MPRAS*:*:4.2:*)
 	OS_REL='.3'
 	test -r /etc/.relid \
@@ -1132,10 +1181,10 @@ EOF
 		echo ns32k-sni-sysv
 	fi
 	exit ;;
-    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
-                      # says <Richard.M.Bartel@ccMail.Census.GOV>
-        echo i586-unisys-sysv4
-        exit ;;
+    PENTIUM:*:4.0*:*)	# Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+			# says <Richard.M.Bartel@ccMail.Census.GOV>
+	echo i586-unisys-sysv4
+	exit ;;
     *:UNIX_System_V:4*:FTX*)
 	# From Gerald Hewes <hewes@openmarket.com>.
 	# How about differentiating between stratus architectures? -djm
@@ -1161,11 +1210,11 @@ EOF
 	exit ;;
     R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
 	if [ -d /usr/nec ]; then
-	        echo mips-nec-sysv${UNAME_RELEASE}
+		echo mips-nec-sysv${UNAME_RELEASE}
 	else
-	        echo mips-unknown-sysv${UNAME_RELEASE}
+		echo mips-unknown-sysv${UNAME_RELEASE}
 	fi
-        exit ;;
+	exit ;;
     BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
 	echo powerpc-be-beos
 	exit ;;
@@ -1178,6 +1227,9 @@ EOF
     BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
 	echo i586-pc-haiku
 	exit ;;
+    x86_64:Haiku:*:*)
+	echo x86_64-unknown-haiku
+	exit ;;
     SX-4:SUPER-UX:*:*)
 	echo sx4-nec-superux${UNAME_RELEASE}
 	exit ;;
@@ -1204,19 +1256,31 @@ EOF
 	exit ;;
     *:Darwin:*:*)
 	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
-	case $UNAME_PROCESSOR in
-	    i386)
-		eval $set_cc_for_build
-		if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
-		  if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
-		      (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
-		      grep IS_64BIT_ARCH >/dev/null
-		  then
-		      UNAME_PROCESSOR="x86_64"
-		  fi
-		fi ;;
-	    unknown) UNAME_PROCESSOR=powerpc ;;
-	esac
+	eval $set_cc_for_build
+	if test "$UNAME_PROCESSOR" = unknown ; then
+	    UNAME_PROCESSOR=powerpc
+	fi
+	if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
+	    if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+		if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+		    (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		    grep IS_64BIT_ARCH >/dev/null
+		then
+		    case $UNAME_PROCESSOR in
+			i386) UNAME_PROCESSOR=x86_64 ;;
+			powerpc) UNAME_PROCESSOR=powerpc64 ;;
+		    esac
+		fi
+	    fi
+	elif test "$UNAME_PROCESSOR" = i386 ; then
+	    # Avoid executing cc on OS X 10.9, as it ships with a stub
+	    # that puts up a graphical alert prompting to install
+	    # developer tools.  Any system running Mac OS X 10.7 or
+	    # later (Darwin 11 and later) is required to have a 64-bit
+	    # processor. This is not true of the ARM version of Darwin
+	    # that Apple uses in portable devices.
+	    UNAME_PROCESSOR=x86_64
+	fi
 	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
 	exit ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
@@ -1230,7 +1294,10 @@ EOF
     *:QNX:*:4*)
 	echo i386-pc-qnx
 	exit ;;
-    NSE-?:NONSTOP_KERNEL:*:*)
+    NEO-?:NONSTOP_KERNEL:*:*)
+	echo neo-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSE-*:NONSTOP_KERNEL:*:*)
 	echo nse-tandem-nsk${UNAME_RELEASE}
 	exit ;;
     NSR-?:NONSTOP_KERNEL:*:*)
@@ -1275,13 +1342,13 @@ EOF
 	echo pdp10-unknown-its
 	exit ;;
     SEI:*:*:SEIUX)
-        echo mips-sei-seiux${UNAME_RELEASE}
+	echo mips-sei-seiux${UNAME_RELEASE}
 	exit ;;
     *:DragonFly:*:*)
 	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
 	exit ;;
     *:*VMS:*:*)
-    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	UNAME_MACHINE=`(uname -p) 2>/dev/null`
 	case "${UNAME_MACHINE}" in
 	    A*) echo alpha-dec-vms ; exit ;;
 	    I*) echo ia64-dec-vms ; exit ;;
@@ -1299,158 +1366,10 @@ EOF
     i*86:AROS:*:*)
 	echo ${UNAME_MACHINE}-pc-aros
 	exit ;;
-esac
-
-#echo '(No uname command or uname output not recognized.)' 1>&2
-#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
-
-eval $set_cc_for_build
-cat >$dummy.c <<EOF
-#ifdef _SEQUENT_
-# include <sys/types.h>
-# include <sys/utsname.h>
-#endif
-main ()
-{
-#if defined (sony)
-#if defined (MIPSEB)
-  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
-     I don't know....  */
-  printf ("mips-sony-bsd\n"); exit (0);
-#else
-#include <sys/param.h>
-  printf ("m68k-sony-newsos%s\n",
-#ifdef NEWSOS4
-          "4"
-#else
-	  ""
-#endif
-         ); exit (0);
-#endif
-#endif
-
-#if defined (__arm) && defined (__acorn) && defined (__unix)
-  printf ("arm-acorn-riscix\n"); exit (0);
-#endif
-
-#if defined (hp300) && !defined (hpux)
-  printf ("m68k-hp-bsd\n"); exit (0);
-#endif
-
-#if defined (NeXT)
-#if !defined (__ARCHITECTURE__)
-#define __ARCHITECTURE__ "m68k"
-#endif
-  int version;
-  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
-  if (version < 4)
-    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
-  else
-    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
-  exit (0);
-#endif
-
-#if defined (MULTIMAX) || defined (n16)
-#if defined (UMAXV)
-  printf ("ns32k-encore-sysv\n"); exit (0);
-#else
-#if defined (CMU)
-  printf ("ns32k-encore-mach\n"); exit (0);
-#else
-  printf ("ns32k-encore-bsd\n"); exit (0);
-#endif
-#endif
-#endif
-
-#if defined (__386BSD__)
-  printf ("i386-pc-bsd\n"); exit (0);
-#endif
-
-#if defined (sequent)
-#if defined (i386)
-  printf ("i386-sequent-dynix\n"); exit (0);
-#endif
-#if defined (ns32000)
-  printf ("ns32k-sequent-dynix\n"); exit (0);
-#endif
-#endif
-
-#if defined (_SEQUENT_)
-    struct utsname un;
-
-    uname(&un);
-
-    if (strncmp(un.version, "V2", 2) == 0) {
-	printf ("i386-sequent-ptx2\n"); exit (0);
-    }
-    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
-	printf ("i386-sequent-ptx1\n"); exit (0);
-    }
-    printf ("i386-sequent-ptx\n"); exit (0);
-
-#endif
-
-#if defined (vax)
-# if !defined (ultrix)
-#  include <sys/param.h>
-#  if defined (BSD)
-#   if BSD == 43
-      printf ("vax-dec-bsd4.3\n"); exit (0);
-#   else
-#    if BSD == 199006
-      printf ("vax-dec-bsd4.3reno\n"); exit (0);
-#    else
-      printf ("vax-dec-bsd\n"); exit (0);
-#    endif
-#   endif
-#  else
-    printf ("vax-dec-bsd\n"); exit (0);
-#  endif
-# else
-    printf ("vax-dec-ultrix\n"); exit (0);
-# endif
-#endif
-
-#if defined (alliant) && defined (i860)
-  printf ("i860-alliant-bsd\n"); exit (0);
-#endif
-
-  exit (1);
-}
-EOF
-
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
-	{ echo "$SYSTEM_NAME"; exit; }
-
-# Apollos put the system type in the environment.
-
-test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
-
-# Convex versions that predate uname can use getsysinfo(1)
-
-if [ -x /usr/convex/getsysinfo ]
-then
-    case `getsysinfo -f cpu_type` in
-    c1*)
-	echo c1-convex-bsd
-	exit ;;
-    c2*)
-	if getsysinfo -f scalar_acc
-	then echo c32-convex-bsd
-	else echo c2-convex-bsd
-	fi
-	exit ;;
-    c34*)
-	echo c34-convex-bsd
-	exit ;;
-    c38*)
-	echo c38-convex-bsd
-	exit ;;
-    c4*)
-	echo c4-convex-bsd
+    x86_64:VMkernel:*:*)
+	echo ${UNAME_MACHINE}-unknown-esx
 	exit ;;
-    esac
-fi
+esac
 
 cat >&2 <<EOF
 $0: unable to guess system type

+ 196 - 102
config/config.sub

@@ -1,38 +1,31 @@
 #! /bin/sh
 # Configuration validation subroutine script.
-#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-#   Free Software Foundation, Inc.
+#   Copyright 1992-2014 Free Software Foundation, Inc.
 
-timestamp='2009-11-20'
+timestamp='2014-09-11'
 
-# This file is (in principle) common to ALL GNU software.
-# The presence of a machine in this file suggests that SOME GNU software
-# can handle that machine.  It does not imply ALL GNU software can.
-#
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-# 02110-1301, USA.
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
 
 
-# Please send patches to <config-patches@gnu.org>.  Submit a context
-# diff and a properly formatted GNU ChangeLog entry.
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
 #
 # Configuration subroutine to validate and canonicalize a configuration type.
 # Supply the specified configuration type as an argument.
@@ -75,8 +68,7 @@ Report bugs and patches to <config-patches@gnu.org>."
 version="\
 GNU config.sub ($timestamp)
 
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+Copyright 1992-2014 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -123,13 +115,18 @@ esac
 # Here we must recognize all the valid KERNEL-OS combinations.
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
-  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
-  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
+  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+  knetbsd*-gnu* | netbsd*-gnu* | \
   kopensolaris*-gnu* | \
   storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
+  android-linux)
+    os=-linux-android
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+    ;;
   *)
     basic_machine=`echo $1 | sed 's/-[^-]*$//'`
     if [ $basic_machine != $1 ]
@@ -152,12 +149,12 @@ case $os in
 	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
 	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
 	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-	-apple | -axis | -knuth | -cray | -microblaze)
+	-apple | -axis | -knuth | -cray | -microblaze*)
 		os=
 		basic_machine=$1
 		;;
-        -bluegene*)
-	        os=-cnk
+	-bluegene*)
+		os=-cnk
 		;;
 	-sim | -cisco | -oki | -wec | -winbond)
 		os=
@@ -173,10 +170,10 @@ case $os in
 		os=-chorusos
 		basic_machine=$1
 		;;
- 	-chorusrdb)
- 		os=-chorusrdb
+	-chorusrdb)
+		os=-chorusrdb
 		basic_machine=$1
- 		;;
+		;;
 	-hiux*)
 		os=-hiuxwe2
 		;;
@@ -221,6 +218,12 @@ case $os in
 	-isc*)
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
 		;;
+	-lynx*178)
+		os=-lynxos178
+		;;
+	-lynx*5)
+		os=-lynxos5
+		;;
 	-lynx*)
 		os=-lynxos
 		;;
@@ -245,20 +248,28 @@ case $basic_machine in
 	# Some are omitted here because they have special meanings below.
 	1750a | 580 \
 	| a29k \
+	| aarch64 | aarch64_be \
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
 	| am33_2.0 \
-	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+	| arc | arceb \
+	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
+	| avr | avr32 \
+	| be32 | be64 \
 	| bfin \
-	| c4x | clipper \
+	| c4x | c8051 | clipper \
 	| d10v | d30v | dlx | dsp16xx \
+	| epiphany \
 	| fido | fr30 | frv \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| hexagon \
 	| i370 | i860 | i960 | ia64 \
 	| ip2k | iq2000 \
+	| k1om \
+	| le32 | le64 \
 	| lm32 \
 	| m32c | m32r | m32rle | m68000 | m68k | m88k \
-	| maxq | mb | microblaze | mcore | mep | metag \
+	| maxq | mb | microblaze | microblazeel | mcore | mep | metag \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips16 \
 	| mips64 | mips64el \
@@ -272,38 +283,51 @@ case $basic_machine in
 	| mips64vr5900 | mips64vr5900el \
 	| mipsisa32 | mipsisa32el \
 	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa32r6 | mipsisa32r6el \
 	| mipsisa64 | mipsisa64el \
 	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64r6 | mipsisa64r6el \
 	| mipsisa64sb1 | mipsisa64sb1el \
 	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipsr5900 | mipsr5900el \
 	| mipstx39 | mipstx39el \
 	| mn10200 | mn10300 \
 	| moxie \
 	| mt \
 	| msp430 \
-	| nios | nios2 \
+	| nds32 | nds32le | nds32be \
+	| nios | nios2 | nios2eb | nios2el \
 	| ns16k | ns32k \
-	| or32 \
+	| open8 | or1k | or1knd | or32 \
 	| pdp10 | pdp11 | pj | pjl \
-	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+	| powerpc | powerpc64 | powerpc64le | powerpcle \
 	| pyramid \
-	| rx \
+	| riscv32 | riscv64 \
+	| rl78 | rx \
 	| score \
 	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
 	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
 	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
-	| spu | strongarm \
-	| tahoe | thumb | tic4x | tic80 | tron \
+	| spu \
+	| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
 	| ubicom32 \
-	| v850 | v850e \
+	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
 	| we32k \
-	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
+	| x86 | xc16x | xstormy16 | xtensa \
 	| z8k | z80)
 		basic_machine=$basic_machine-unknown
 		;;
-	m6811 | m68hc11 | m6812 | m68hc12 | picochip)
-		# Motorola 68HC11/12.
+	c54x)
+		basic_machine=tic54x-unknown
+		;;
+	c55x)
+		basic_machine=tic55x-unknown
+		;;
+	c6x)
+		basic_machine=tic6x-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
 		basic_machine=$basic_machine-unknown
 		os=-none
 		;;
@@ -313,6 +337,21 @@ case $basic_machine in
 		basic_machine=mt-unknown
 		;;
 
+	strongarm | thumb | xscale)
+		basic_machine=arm-unknown
+		;;
+	xgate)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	xscaleeb)
+		basic_machine=armeb-unknown
+		;;
+
+	xscaleel)
+		basic_machine=armel-unknown
+		;;
+
 	# We use `pc' rather than `unknown'
 	# because (1) that's what they normally are, and
 	# (2) the word "unknown" tends to confuse beginning users.
@@ -327,25 +366,31 @@ case $basic_machine in
 	# Recognize the basic CPU types with company name.
 	580-* \
 	| a29k-* \
+	| aarch64-* | aarch64_be-* \
 	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
 	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
-	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
 	| avr-* | avr32-* \
+	| be32-* | be64-* \
 	| bfin-* | bs2000-* \
-	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
-	| clipper-* | craynv-* | cydra-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* \
+	| c8051-* | clipper-* | craynv-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| elxsi-* \
 	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
 	| h8300-* | h8500-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| hexagon-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
 	| ip2k-* | iq2000-* \
+	| k1om-* \
+	| le32-* | le64-* \
 	| lm32-* \
 	| m32c-* | m32r-* | m32rle-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
-	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+	| microblaze-* | microblazeel-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
 	| mips16-* \
 	| mips64-* | mips64el-* \
@@ -359,33 +404,41 @@ case $basic_machine in
 	| mips64vr5900-* | mips64vr5900el-* \
 	| mipsisa32-* | mipsisa32el-* \
 	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa32r6-* | mipsisa32r6el-* \
 	| mipsisa64-* | mipsisa64el-* \
 	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64r6-* | mipsisa64r6el-* \
 	| mipsisa64sb1-* | mipsisa64sb1el-* \
 	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipsr5900-* | mipsr5900el-* \
 	| mipstx39-* | mipstx39el-* \
 	| mmix-* \
 	| mt-* \
 	| msp430-* \
-	| nios-* | nios2-* \
+	| nds32-* | nds32le-* | nds32be-* \
+	| nios-* | nios2-* | nios2eb-* | nios2el-* \
 	| none-* | np1-* | ns16k-* | ns32k-* \
+	| open8-* \
+	| or1k*-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
-	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
 	| pyramid-* \
-	| romp-* | rs6000-* | rx-* \
+	| rl78-* | romp-* | rs6000-* | rx-* \
 	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
 	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
 	| sparclite-* \
-	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
-	| tahoe-* | thumb-* \
-	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+	| tahoe-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tile*-* \
 	| tron-* \
 	| ubicom32-* \
-	| v850-* | v850e-* | vax-* \
+	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+	| vax-* \
 	| we32k-* \
-	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* \
 	| xstormy16-* | xtensa*-* \
 	| ymp-* \
 	| z8k-* | z80-*)
@@ -410,7 +463,7 @@ case $basic_machine in
 		basic_machine=a29k-amd
 		os=-udi
 		;;
-    	abacus)
+	abacus)
 		basic_machine=abacus-unknown
 		;;
 	adobe68k)
@@ -480,11 +533,20 @@ case $basic_machine in
 		basic_machine=powerpc-ibm
 		os=-cnk
 		;;
+	c54x-*)
+		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c55x-*)
+		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c6x-*)
+		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	c90)
 		basic_machine=c90-cray
 		os=-unicos
 		;;
-        cegcc)
+	cegcc)
 		basic_machine=arm-unknown
 		os=-cegcc
 		;;
@@ -516,7 +578,7 @@ case $basic_machine in
 		basic_machine=craynv-cray
 		os=-unicosmp
 		;;
-	cr16)
+	cr16 | cr16-*)
 		basic_machine=cr16-unknown
 		os=-elf
 		;;
@@ -674,7 +736,6 @@ case $basic_machine in
 	i370-ibm* | ibm*)
 		basic_machine=i370-ibm
 		;;
-# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
 	i*86v32)
 		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
 		os=-sysv32
@@ -732,11 +793,15 @@ case $basic_machine in
 		basic_machine=ns32k-utek
 		os=-sysv
 		;;
-        microblaze)
+	microblaze*)
 		basic_machine=microblaze-xilinx
 		;;
+	mingw64)
+		basic_machine=x86_64-pc
+		os=-mingw64
+		;;
 	mingw32)
-		basic_machine=i386-pc
+		basic_machine=i686-pc
 		os=-mingw32
 		;;
 	mingw32ce)
@@ -764,6 +829,10 @@ case $basic_machine in
 		basic_machine=powerpc-unknown
 		os=-morphos
 		;;
+	moxiebox)
+		basic_machine=moxie-unknown
+		os=-moxiebox
+		;;
 	msdos)
 		basic_machine=i386-pc
 		os=-msdos
@@ -771,10 +840,18 @@ case $basic_machine in
 	ms1-*)
 		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
 		;;
+	msys)
+		basic_machine=i686-pc
+		os=-msys
+		;;
 	mvs)
 		basic_machine=i370-ibm
 		os=-mvs
 		;;
+	nacl)
+		basic_machine=le32-unknown
+		os=-nacl
+		;;
 	ncr3000)
 		basic_machine=i486-ncr
 		os=-sysv4
@@ -839,6 +916,12 @@ case $basic_machine in
 	np1)
 		basic_machine=np1-gould
 		;;
+	neo-tandem)
+		basic_machine=neo-tandem
+		;;
+	nse-tandem)
+		basic_machine=nse-tandem
+		;;
 	nsr-tandem)
 		basic_machine=nsr-tandem
 		;;
@@ -921,9 +1004,10 @@ case $basic_machine in
 		;;
 	power)	basic_machine=power-ibm
 		;;
-	ppc)	basic_machine=powerpc-unknown
+	ppc | ppcbe)	basic_machine=powerpc-unknown
 		;;
-	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+	ppc-* | ppcbe-*)
+		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 	ppcle | powerpclittle | ppc-le | powerpc-little)
 		basic_machine=powerpcle-unknown
@@ -948,7 +1032,11 @@ case $basic_machine in
 		basic_machine=i586-unknown
 		os=-pw32
 		;;
-	rdos)
+	rdos | rdos64)
+		basic_machine=x86_64-pc
+		os=-rdos
+		;;
+	rdos32)
 		basic_machine=i386-pc
 		os=-rdos
 		;;
@@ -1017,6 +1105,9 @@ case $basic_machine in
 		basic_machine=i860-stratus
 		os=-sysv4
 		;;
+	strongarm-* | thumb-*)
+		basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	sun2)
 		basic_machine=m68000-sun
 		;;
@@ -1073,20 +1164,8 @@ case $basic_machine in
 		basic_machine=t90-cray
 		os=-unicos
 		;;
-	tic54x | c54x*)
-		basic_machine=tic54x-unknown
-		os=-coff
-		;;
-	tic55x | c55x*)
-		basic_machine=tic55x-unknown
-		os=-coff
-		;;
-	tic6x | c6x*)
-		basic_machine=tic6x-unknown
-		os=-coff
-		;;
 	tile*)
-		basic_machine=tile-unknown
+		basic_machine=$basic_machine-unknown
 		os=-linux-gnu
 		;;
 	tx39)
@@ -1156,6 +1235,9 @@ case $basic_machine in
 	xps | xps100)
 		basic_machine=xps100-honeywell
 		;;
+	xscale-* | xscalee[bl]-*)
+		basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+		;;
 	ymp)
 		basic_machine=ymp-cray
 		os=-unicos
@@ -1253,11 +1335,11 @@ esac
 if [ x"$os" != x"" ]
 then
 case $os in
-        # First match some system type aliases
-        # that might get confused with valid system types.
+	# First match some system type aliases
+	# that might get confused with valid system types.
 	# -solaris* is a basic system type, with this one exception.
-        -auroraux)
-	        os=-auroraux
+	-auroraux)
+		os=-auroraux
 		;;
 	-solaris1 | -solaris1.*)
 		os=`echo $os | sed -e 's|solaris1|sunos4|'`
@@ -1281,28 +1363,29 @@ case $os in
 	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
 	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
 	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
-	      | -sym* | -kopensolaris* \
+	      | -sym* | -kopensolaris* | -plan9* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
 	      | -aos* | -aros* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
 	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
-	      | -openbsd* | -solidbsd* \
+	      | -bitrig* | -openbsd* | -solidbsd* \
 	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
 	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -chorusos* | -chorusrdb* | -cegcc* \
-	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
-	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
 	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
 	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
 	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
-	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*)
 	# Remember, each alternative MUST END IN *, to match a version number.
 		;;
 	-qnx*)
@@ -1341,7 +1424,7 @@ case $os in
 	-opened*)
 		os=-openedition
 		;;
-        -os400*)
+	-os400*)
 		os=-os400
 		;;
 	-wince*)
@@ -1390,7 +1473,7 @@ case $os in
 	-sinix*)
 		os=-sysv4
 		;;
-        -tpf*)
+	-tpf*)
 		os=-tpf
 		;;
 	-triton*)
@@ -1426,15 +1509,14 @@ case $os in
 	-aros*)
 		os=-aros
 		;;
-	-kaos*)
-		os=-kaos
-		;;
 	-zvmoe)
 		os=-zvmoe
 		;;
 	-dicos*)
 		os=-dicos
 		;;
+	-nacl*)
+		;;
 	-none)
 		;;
 	*)
@@ -1457,10 +1539,10 @@ else
 # system, and we'll never get to this point.
 
 case $basic_machine in
-        score-*)
+	score-*)
 		os=-elf
 		;;
-        spu-*)
+	spu-*)
 		os=-elf
 		;;
 	*-acorn)
@@ -1472,8 +1554,23 @@ case $basic_machine in
 	arm*-semi)
 		os=-aout
 		;;
-        c4x-* | tic4x-*)
-        	os=-coff
+	c4x-* | tic4x-*)
+		os=-coff
+		;;
+	c8051-*)
+		os=-elf
+		;;
+	hexagon-*)
+		os=-elf
+		;;
+	tic54x-*)
+		os=-coff
+		;;
+	tic55x-*)
+		os=-coff
+		;;
+	tic6x-*)
+		os=-coff
 		;;
 	# This must come before the *-dec entry.
 	pdp10-*)
@@ -1493,14 +1590,11 @@ case $basic_machine in
 		;;
 	m68000-sun)
 		os=-sunos3
-		# This also exists in the configure program, but was not the
-		# default.
-		# os=-sunos4
 		;;
 	m68*-cisco)
 		os=-aout
 		;;
-        mep-*)
+	mep-*)
 		os=-elf
 		;;
 	mips*-cisco)
@@ -1527,7 +1621,7 @@ case $basic_machine in
 	*-ibm)
 		os=-aix
 		;;
-    	*-knuth)
+	*-knuth)
 		os=-mmixware
 		;;
 	*-wec)

+ 455 - 190
config/depcomp

@@ -1,9 +1,9 @@
 #! /bin/sh
 # depcomp - compile a program generating dependencies as side-effects
 
-scriptversion=2004-04-25.13
+scriptversion=2013-05-30.07; # UTC
 
-# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -16,9 +16,7 @@ scriptversion=2004-04-25.13
 # GNU General Public License for more details.
 
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -29,9 +27,9 @@ scriptversion=2004-04-25.13
 
 case $1 in
   '')
-     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
-     exit 1;
-     ;;
+    echo "$0: No command.  Try '$0 --help' for more information." 1>&2
+    exit 1;
+    ;;
   -h | --h*)
     cat <<\EOF
 Usage: depcomp [--help] [--version] PROGRAM [ARGS]
@@ -41,42 +39,98 @@ as side-effects.
 
 Environment variables:
   depmode     Dependency tracking mode.
-  source      Source file read by `PROGRAMS ARGS'.
-  object      Object file output by `PROGRAMS ARGS'.
+  source      Source file read by 'PROGRAMS ARGS'.
+  object      Object file output by 'PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
   depfile     Dependency file to output.
-  tmpdepfile  Temporary file to use when outputing dependencies.
+  tmpdepfile  Temporary file to use when outputting dependencies.
   libtool     Whether libtool is used (yes/no).
 
 Report bugs to <bug-automake@gnu.org>.
 EOF
-    exit 0
+    exit $?
     ;;
   -v | --v*)
     echo "depcomp $scriptversion"
-    exit 0
+    exit $?
     ;;
 esac
 
+# Get the directory component of the given path, and save it in the
+# global variables '$dir'.  Note that this directory component will
+# be either empty or ending with a '/' character.  This is deliberate.
+set_dir_from ()
+{
+  case $1 in
+    */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
+      *) dir=;;
+  esac
+}
+
+# Get the suffix-stripped basename of the given path, and save it the
+# global variable '$base'.
+set_base_from ()
+{
+  base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
+}
+
+# If no dependency file was actually created by the compiler invocation,
+# we still have to create a dummy depfile, to avoid errors with the
+# Makefile "include basename.Plo" scheme.
+make_dummy_depfile ()
+{
+  echo "#dummy" > "$depfile"
+}
+
+# Factor out some common post-processing of the generated depfile.
+# Requires the auxiliary global variable '$tmpdepfile' to be set.
+aix_post_process_depfile ()
+{
+  # If the compiler actually managed to produce a dependency file,
+  # post-process it.
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form 'foo.o: dependency.h'.
+    # Do two passes, one to just change these to
+    #   $object: dependency.h
+    # and one to simply output
+    #   dependency.h:
+    # which is needed to avoid the deleted-header problem.
+    { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
+      sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
+    } > "$depfile"
+    rm -f "$tmpdepfile"
+  else
+    make_dummy_depfile
+  fi
+}
+
+# A tabulation character.
+tab='	'
+# A newline character.
+nl='
+'
+# Character ranges might be problematic outside the C locale.
+# These definitions help.
+upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
+lower=abcdefghijklmnopqrstuvwxyz
+digits=0123456789
+alpha=${upper}${lower}
+
 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
   echo "depcomp: Variables source, object and depmode must be set" 1>&2
   exit 1
 fi
-# `libtool' can also be set to `yes' or `no'.
-
-if test -z "$depfile"; then
-   base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
-   dir=`echo "$object" | sed 's,/.*$,/,'`
-   if test "$dir" = "$object"; then
-      dir=
-   fi
-   # FIXME: should be _deps on DOS.
-   depfile="$dir.deps/$base"
-fi
 
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
 
 rm -f "$tmpdepfile"
 
+# Avoid interferences from the environment.
+gccflag= dashmflag=
+
 # Some modes work just like other modes, but use different flags.  We
 # parameterize here, but still list the modes in the big case below,
 # to make depend.m4 easier to write.  Note that we *cannot* use a case
@@ -88,9 +142,32 @@ if test "$depmode" = hp; then
 fi
 
 if test "$depmode" = dashXmstdout; then
-   # This is just like dashmstdout with a different argument.
-   dashmflag=-xM
-   depmode=dashmstdout
+  # This is just like dashmstdout with a different argument.
+  dashmflag=-xM
+  depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+  # This is just like msvisualcpp but w/o cygpath translation.
+  # Just convert the backslash-escaped backslashes to single forward
+  # slashes to satisfy depend.m4
+  cygpath_u='sed s,\\\\,/,g'
+  depmode=msvisualcpp
+fi
+
+if test "$depmode" = msvc7msys; then
+  # This is just like msvc7 but w/o cygpath translation.
+  # Just convert the backslash-escaped backslashes to single forward
+  # slashes to satisfy depend.m4
+  cygpath_u='sed s,\\\\,/,g'
+  depmode=msvc7
+fi
+
+if test "$depmode" = xlc; then
+  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
+  gccflag=-qmakedep=gcc,-MF
+  depmode=gcc
 fi
 
 case "$depmode" in
@@ -98,10 +175,22 @@ gcc3)
 ## gcc 3 implements dependency tracking that does exactly what
 ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
 ## it if -MD -MP comes after the -MF stuff.  Hmm.
-  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
   stat=$?
-  if test $stat -eq 0; then :
-  else
+  if test $stat -ne 0; then
     rm -f "$tmpdepfile"
     exit $stat
   fi
@@ -109,13 +198,17 @@ gcc3)
   ;;
 
 gcc)
+## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
+## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
+## (see the conditional assignment to $gccflag above).
 ## There are various ways to get dependency output from gcc.  Here's
 ## why we pick this rather obscure method:
 ## - Don't want to use -MD because we'd like the dependencies to end
 ##   up in a subdir.  Having to rename by hand is ugly.
 ##   (We might end up doing this anyway to support other compilers.)
 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
-##   -MM, not -M (despite what the docs say).
+##   -MM, not -M (despite what the docs say).  Also, it might not be
+##   supported by the other compilers which use the 'gcc' depmode.
 ## - Using -M directly means running the compiler twice (even worse
 ##   than renaming).
   if test -z "$gccflag"; then
@@ -123,31 +216,31 @@ gcc)
   fi
   "$@" -Wp,"$gccflag$tmpdepfile"
   stat=$?
-  if test $stat -eq 0; then :
-  else
+  if test $stat -ne 0; then
     rm -f "$tmpdepfile"
     exit $stat
   fi
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
-  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
-## The second -e expression handles DOS-style file names with drive letters.
+  # The second -e expression handles DOS-style file names with drive
+  # letters.
   sed -e 's/^[^:]*: / /' \
       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
-## This next piece of magic avoids the `deleted header file' problem.
+## This next piece of magic avoids the "deleted header file" problem.
 ## The problem is that when a header file which appears in a .P file
 ## is deleted, the dependency causes make to die (because there is
 ## typically no way to rebuild the header).  We avoid this by adding
 ## dummy dependencies for each header file.  Too bad gcc doesn't do
 ## this for us directly.
-  tr ' ' '
-' < "$tmpdepfile" |
-## Some versions of gcc put a space before the `:'.  On the theory
+## Some versions of gcc put a space before the ':'.  On the theory
 ## that the space means something, we add a space to the output as
-## well.
+## well.  hp depmode also adds that space, but also prefixes the VPATH
+## to the object.  Take care to not repeat it in the output.
 ## Some versions of the HPUX 10.20 sed can't process this invocation
 ## correctly.  Breaking it into two sed invocations is a workaround.
-    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  tr ' ' "$nl" < "$tmpdepfile" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
@@ -165,8 +258,7 @@ sgi)
     "$@" -MDupdate "$tmpdepfile"
   fi
   stat=$?
-  if test $stat -eq 0; then :
-  else
+  if test $stat -ne 0; then
     rm -f "$tmpdepfile"
     exit $stat
   fi
@@ -174,99 +266,156 @@ sgi)
 
   if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
     echo "$object : \\" > "$depfile"
-
     # Clip off the initial element (the dependent).  Don't try to be
     # clever and replace this with sed code, as IRIX sed won't handle
     # lines with more than a fixed number of characters (4096 in
     # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
-    # the IRIX cc adds comments like `#:fec' to the end of the
+    # the IRIX cc adds comments like '#:fec' to the end of the
     # dependency line.
-    tr ' ' '
-' < "$tmpdepfile" \
-    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
-    tr '
-' ' ' >> $depfile
-    echo >> $depfile
-
+    tr ' ' "$nl" < "$tmpdepfile" \
+      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
+      | tr "$nl" ' ' >> "$depfile"
+    echo >> "$depfile"
     # The second pass generates a dummy entry for each header file.
-    tr ' ' '
-' < "$tmpdepfile" \
-   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
-   >> $depfile
+    tr ' ' "$nl" < "$tmpdepfile" \
+      | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+      >> "$depfile"
   else
-    # The sourcefile does not contain any dependencies, so just
-    # store a dummy comment line, to avoid errors with the Makefile
-    # "include basename.Plo" scheme.
-    echo "#dummy" > "$depfile"
+    make_dummy_depfile
   fi
   rm -f "$tmpdepfile"
   ;;
 
+xlc)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
 aix)
   # The C for AIX Compiler uses -M and outputs the dependencies
   # in a .u file.  In older versions, this file always lives in the
-  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # current directory.  Also, the AIX compiler puts '$object:' at the
   # start of each line; $object doesn't have directory information.
   # Version 6 uses the directory in both cases.
-  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
-  tmpdepfile="$stripped.u"
+  set_dir_from "$object"
+  set_base_from "$object"
   if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
     "$@" -Wc,-M
   else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
     "$@" -M
   fi
   stat=$?
-
-  if test -f "$tmpdepfile"; then :
-  else
-    stripped=`echo "$stripped" | sed 's,^.*/,,'`
-    tmpdepfile="$stripped.u"
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
   fi
 
-  if test $stat -eq 0; then :
-  else
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  aix_post_process_depfile
+  ;;
+
+tcc)
+  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
+  # FIXME: That version still under development at the moment of writing.
+  #        Make that this statement remains true also for stable, released
+  #        versions.
+  # It will wrap lines (doesn't matter whether long or short) with a
+  # trailing '\', as in:
+  #
+  #   foo.o : \
+  #    foo.c \
+  #    foo.h \
+  #
+  # It will put a trailing '\' even on the last line, and will use leading
+  # spaces rather than leading tabs (at least since its commit 0394caf7
+  # "Emit spaces for -MD").
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -ne 0; then
     rm -f "$tmpdepfile"
     exit $stat
   fi
-
-  if test -f "$tmpdepfile"; then
-    outname="$stripped.o"
-    # Each line is of the form `foo.o: dependent.h'.
-    # Do two passes, one to just change these to
-    # `$object: dependent.h' and one to simply `dependent.h:'.
-    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
-    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
-  else
-    # The sourcefile does not contain any dependencies, so just
-    # store a dummy comment line, to avoid errors with the Makefile
-    # "include basename.Plo" scheme.
-    echo "#dummy" > "$depfile"
-  fi
+  rm -f "$depfile"
+  # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
+  # We have to change lines of the first kind to '$object: \'.
+  sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
+  # And for each line of the second kind, we have to emit a 'dep.h:'
+  # dummy dependency, to avoid the deleted-header problem.
+  sed -n -e 's|^  *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
-icc)
-  # Intel's C compiler understands `-MD -MF file'.  However on
-  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
-  # ICC 7.0 will fill foo.d with something like
-  #    foo.o: sub/foo.c
-  #    foo.o: sub/foo.h
-  # which is wrong.  We want:
-  #    sub/foo.o: sub/foo.c
-  #    sub/foo.o: sub/foo.h
-  #    sub/foo.c:
-  #    sub/foo.h:
-  # ICC 7.1 will output
+## The order of this option in the case statement is important, since the
+## shell code in configure will try each of these formats in the order
+## listed in this file.  A plain '-MD' option would be understood by many
+## compilers, so we must ensure this comes after the gcc and icc options.
+pgcc)
+  # Portland's C compiler understands '-MD'.
+  # Will always output deps to 'file.d' where file is the root name of the
+  # source file under compilation, even if file resides in a subdirectory.
+  # The object file name does not affect the name of the '.d' file.
+  # pgcc 10.2 will output
   #    foo.o: sub/foo.c sub/foo.h
-  # and will wrap long lines using \ :
+  # and will wrap long lines using '\' :
   #    foo.o: sub/foo.c ... \
   #     sub/foo.h ... \
   #     ...
+  set_dir_from "$object"
+  # Use the source, not the object, to determine the base name, since
+  # that's sadly what pgcc will do too.
+  set_base_from "$source"
+  tmpdepfile=$base.d
+
+  # For projects that build the same source file twice into different object
+  # files, the pgcc approach of using the *source* file root name can cause
+  # problems in parallel builds.  Use a locking strategy to avoid stomping on
+  # the same $tmpdepfile.
+  lockdir=$base.d-lock
+  trap "
+    echo '$0: caught signal, cleaning up...' >&2
+    rmdir '$lockdir'
+    exit 1
+  " 1 2 13 15
+  numtries=100
+  i=$numtries
+  while test $i -gt 0; do
+    # mkdir is a portable test-and-set.
+    if mkdir "$lockdir" 2>/dev/null; then
+      # This process acquired the lock.
+      "$@" -MD
+      stat=$?
+      # Release the lock.
+      rmdir "$lockdir"
+      break
+    else
+      # If the lock is being held by a different process, wait
+      # until the winning process is done or we timeout.
+      while test -d "$lockdir" && test $i -gt 0; do
+        sleep 1
+        i=`expr $i - 1`
+      done
+    fi
+    i=`expr $i - 1`
+  done
+  trap - 1 2 13 15
+  if test $i -le 0; then
+    echo "$0: failed to acquire lock after $numtries attempts" >&2
+    echo "$0: check lockdir '$lockdir'" >&2
+    exit 1
+  fi
 
-  "$@" -MD -MF "$tmpdepfile"
-  stat=$?
-  if test $stat -eq 0; then :
-  else
+  if test $stat -ne 0; then
     rm -f "$tmpdepfile"
     exit $stat
   fi
@@ -278,58 +427,141 @@ icc)
   sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
   # Some versions of the HPUX 10.20 sed can't process this invocation
   # correctly.  Breaking it into two sed invocations is a workaround.
-  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
-    sed -e 's/$/ :/' >> "$depfile"
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
+    | sed -e 's/$/ :/' >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  set_dir_from  "$object"
+  set_base_from "$object"
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -ne 0; then
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add 'dependent.h:' lines.
+    sed -ne '2,${
+               s/^ *//
+               s/ \\*$//
+               s/$/:/
+               p
+             }' "$tmpdepfile" >> "$depfile"
+  else
+    make_dummy_depfile
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
 tru64)
-   # The Tru64 compiler uses -MD to generate dependencies as a side
-   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
-   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
-   # dependencies in `foo.d' instead, so we check for that too.
-   # Subdirectories are respected.
-   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
-   test "x$dir" = "x$object" && dir=
-   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
-
-   if test "$libtool" = yes; then
-      # Dependencies are output in .lo.d with libtool 1.4.
-      # They are output in .o.d with libtool 1.5.
-      tmpdepfile1="$dir.libs/$base.lo.d"
-      tmpdepfile2="$dir.libs/$base.o.d"
-      tmpdepfile3="$dir.libs/$base.d"
-      "$@" -Wc,-MD
-   else
-      tmpdepfile1="$dir$base.o.d"
-      tmpdepfile2="$dir$base.d"
-      tmpdepfile3="$dir$base.d"
-      "$@" -MD
-   fi
-
-   stat=$?
-   if test $stat -eq 0; then :
-   else
-      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
-      exit $stat
-   fi
-
-   if test -f "$tmpdepfile1"; then
-      tmpdepfile="$tmpdepfile1"
-   elif test -f "$tmpdepfile2"; then
-      tmpdepfile="$tmpdepfile2"
-   else
-      tmpdepfile="$tmpdepfile3"
-   fi
-   if test -f "$tmpdepfile"; then
-      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
-      # That's a tab and a space in the [].
-      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
-   else
-      echo "#dummy" > "$depfile"
-   fi
-   rm -f "$tmpdepfile"
-   ;;
+  # The Tru64 compiler uses -MD to generate dependencies as a side
+  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
+  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+  # dependencies in 'foo.d' instead, so we check for that too.
+  # Subdirectories are respected.
+  set_dir_from  "$object"
+  set_base_from "$object"
+
+  if test "$libtool" = yes; then
+    # Libtool generates 2 separate objects for the 2 libraries.  These
+    # two compilations output dependencies in $dir.libs/$base.o.d and
+    # in $dir$base.o.d.  We have to check for both files, because
+    # one of the two compilations can be disabled.  We should prefer
+    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+    # automatically cleaned when .libs/ is deleted, while ignoring
+    # the former would cause a distcleancheck panic.
+    tmpdepfile1=$dir$base.o.d          # libtool 1.5
+    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.
+    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504
+    "$@" -Wc,-MD
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    tmpdepfile3=$dir$base.d
+    "$@" -MD
+  fi
+
+  stat=$?
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  # Same post-processing that is required for AIX mode.
+  aix_post_process_depfile
+  ;;
+
+msvc7)
+  if test "$libtool" = yes; then
+    showIncludes=-Wc,-showIncludes
+  else
+    showIncludes=-showIncludes
+  fi
+  "$@" $showIncludes > "$tmpdepfile"
+  stat=$?
+  grep -v '^Note: including file: ' "$tmpdepfile"
+  if test $stat -ne 0; then
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  # The first sed program below extracts the file names and escapes
+  # backslashes for cygpath.  The second sed program outputs the file
+  # name when reading, but also accumulates all include files in the
+  # hold buffer in order to output them again at the end.  This only
+  # works with sed implementations that can handle large buffers.
+  sed < "$tmpdepfile" -n '
+/^Note: including file:  *\(.*\)/ {
+  s//\1/
+  s/\\/\\\\/g
+  p
+}' | $cygpath_u | sort -u | sed -n '
+s/ /\\ /g
+s/\(.*\)/'"$tab"'\1 \\/p
+s/.\(.*\) \\/\1:/
+H
+$ {
+  s/.*/'"$tab"'/
+  G
+  p
+}' >> "$depfile"
+  echo >> "$depfile" # make sure the fragment doesn't end with a backslash
+  rm -f "$tmpdepfile"
+  ;;
+
+msvc7msys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
 
 #nosideeffect)
   # This comment above is used by automake to tell side-effect
@@ -342,13 +574,13 @@ dashmstdout)
 
   # Remove the call to Libtool.
   if test "$libtool" = yes; then
-    while test $1 != '--mode=compile'; do
+    while test "X$1" != 'X--mode=compile'; do
       shift
     done
     shift
   fi
 
-  # Remove `-o $object'.
+  # Remove '-o $object'.
   IFS=" "
   for arg
   do
@@ -368,18 +600,18 @@ dashmstdout)
   done
 
   test -z "$dashmflag" && dashmflag=-M
-  # Require at least two characters before searching for `:'
+  # Require at least two characters before searching for ':'
   # in the target name.  This is to cope with DOS-style filenames:
-  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
   "$@" $dashmflag |
-    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
+    sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
   rm -f "$depfile"
   cat < "$tmpdepfile" > "$depfile"
-  tr ' ' '
-' < "$tmpdepfile" | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly.  Breaking it into two sed invocations is a workaround.
-    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this sed invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  tr ' ' "$nl" < "$tmpdepfile" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
@@ -393,41 +625,51 @@ makedepend)
   "$@" || exit $?
   # Remove any Libtool call
   if test "$libtool" = yes; then
-    while test $1 != '--mode=compile'; do
+    while test "X$1" != 'X--mode=compile'; do
       shift
     done
     shift
   fi
   # X makedepend
   shift
-  cleared=no
-  for arg in "$@"; do
+  cleared=no eat=no
+  for arg
+  do
     case $cleared in
     no)
       set ""; shift
       cleared=yes ;;
     esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
     case "$arg" in
     -D*|-I*)
       set fnord "$@" "$arg"; shift ;;
     # Strip any option that makedepend may not understand.  Remove
     # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
     -*|$object)
       ;;
     *)
       set fnord "$@" "$arg"; shift ;;
     esac
   done
-  obj_suffix="`echo $object | sed 's/^.*\././'`"
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
   touch "$tmpdepfile"
   ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
   rm -f "$depfile"
-  cat < "$tmpdepfile" > "$depfile"
-  sed '1,2d' "$tmpdepfile" | tr ' ' '
-' | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly.  Breaking it into two sed invocations is a workaround.
-    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  # makedepend may prepend the VPATH from the source file name to the object.
+  # No need to regex-escape $object, excess matching of '.' is harmless.
+  sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process the last invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed '1,2d' "$tmpdepfile" \
+    | tr ' ' "$nl" \
+    | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
+    | sed -e 's/$/ :/' >> "$depfile"
   rm -f "$tmpdepfile" "$tmpdepfile".bak
   ;;
 
@@ -438,13 +680,13 @@ cpp)
 
   # Remove the call to Libtool.
   if test "$libtool" = yes; then
-    while test $1 != '--mode=compile'; do
+    while test "X$1" != 'X--mode=compile'; do
       shift
     done
     shift
   fi
 
-  # Remove `-o $object'.
+  # Remove '-o $object'.
   IFS=" "
   for arg
   do
@@ -463,9 +705,10 @@ cpp)
     esac
   done
 
-  "$@" -E |
-    sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
-    sed '$ s: \\$::' > "$tmpdepfile"
+  "$@" -E \
+    | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+             -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+    | sed '$ s: \\$::' > "$tmpdepfile"
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
   cat < "$tmpdepfile" >> "$depfile"
@@ -475,35 +718,56 @@ cpp)
 
 msvisualcpp)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the preprocessed file to stdout, regardless of -o,
-  # because we must use -o when running libtool.
+  # always write the preprocessed file to stdout.
   "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
   IFS=" "
   for arg
   do
     case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
     "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
-	set fnord "$@"
-	shift
-	shift
-	;;
+        set fnord "$@"
+        shift
+        shift
+        ;;
     *)
-	set fnord "$@" "$arg"
-	shift
-	shift
-	;;
+        set fnord "$@" "$arg"
+        shift
+        shift
+        ;;
     esac
   done
-  "$@" -E |
-  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
-  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
-  echo "	" >> "$depfile"
-  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
+  echo "$tab" >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
   rm -f "$tmpdepfile"
   ;;
 
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
 none)
   exec "$@"
   ;;
@@ -522,5 +786,6 @@ exit 0
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:

+ 400 - 191
config/install-sh

@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2004-04-01.17
+scriptversion=2011-11-20.07; # UTC
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -35,152 +35,224 @@ scriptversion=2004-04-01.17
 # FSF changes to this file are in the public domain.
 #
 # Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
+# 'make' implicit rules from creating a file called install from it
 # when there is no Makefile.
 #
 # This script is compatible with the BSD install script, but was written
-# from scratch.  It can only install one file at a time, a restriction
-# shared with many OS's install programs.
+# from scratch.
+
+nl='
+'
+IFS=" ""	$nl"
 
 # set DOITPROG to echo to test this script
 
 # Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
-
-# put in absolute paths if you don't have them in your path; or use env. vars.
-
-mvprog="${MVPROG-mv}"
-cpprog="${CPPROG-cp}"
-chmodprog="${CHMODPROG-chmod}"
-chownprog="${CHOWNPROG-chown}"
-chgrpprog="${CHGRPPROG-chgrp}"
-stripprog="${STRIPPROG-strip}"
-rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
-
-transformbasename=
-transform_arg=
-instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
-chowncmd=
+doit=${DOITPROG-}
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_glob='?'
+initialize_posix_glob='
+  test "$posix_glob" != "?" || {
+    if (set -f) 2>/dev/null; then
+      posix_glob=
+    else
+      posix_glob=:
+    fi
+  }
+'
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
 chgrpcmd=
-stripcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
 rmcmd="$rmprog -f"
-mvcmd="$mvprog"
+stripcmd=
+
 src=
 dst=
 dir_arg=
+dst_arg=
 
-usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
+copy_on_change=false
+no_target_directory=
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
    or: $0 [OPTION]... SRCFILES... DIRECTORY
-   or: $0 -d DIRECTORIES...
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
 
-In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
-In the second, create the directory path DIR.
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
 
 Options:
--b=TRANSFORMBASENAME
--c         copy source (using $cpprog) instead of moving (using $mvprog).
--d         create directories instead of installing files.
--g GROUP   $chgrp installed files to GROUP.
--m MODE    $chmod installed files to MODE.
--o USER    $chown installed files to USER.
--s         strip installed files (using $stripprog).
--t=TRANSFORM
---help     display this help and exit.
---version  display version info and exit.
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
 
 Environment variables override the default commands:
-  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
 "
 
-while test -n "$1"; do
+while test $# -ne 0; do
   case $1 in
-    -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-        shift
-        continue;;
+    -c) ;;
 
-    -c) instcmd=$cpprog
-        shift
-        continue;;
+    -C) copy_on_change=true;;
 
-    -d) dir_arg=true
-        shift
-        continue;;
+    -d) dir_arg=true;;
 
     -g) chgrpcmd="$chgrpprog $2"
-        shift
-        shift
-        continue;;
+	shift;;
 
-    --help) echo "$usage"; exit 0;;
+    --help) echo "$usage"; exit $?;;
 
-    -m) chmodcmd="$chmodprog $2"
-        shift
-        shift
-        continue;;
+    -m) mode=$2
+	case $mode in
+	  *' '* | *'	'* | *'
+'*	  | *'*'* | *'?'* | *'['*)
+	    echo "$0: invalid mode: $mode" >&2
+	    exit 1;;
+	esac
+	shift;;
 
     -o) chowncmd="$chownprog $2"
-        shift
-        shift
-        continue;;
-
-    -s) stripcmd=$stripprog
-        shift
-        continue;;
-
-    -t=*) transformarg=`echo $1 | sed 's/-t=//'`
-        shift
-        continue;;
-
-    --version) echo "$0 $scriptversion"; exit 0;;
-
-    *)  # When -d is used, all remaining arguments are directories to create.
-	test -n "$dir_arg" && break
-        # Otherwise, the last argument is the destination.  Remove it from $@.
-	for arg
-	do
-          if test -n "$dstarg"; then
-	    # $@ is not empty: it contains at least $arg.
-	    set fnord "$@" "$dstarg"
-	    shift # fnord
-	  fi
-	  shift # arg
-	  dstarg=$arg
-	done
+	shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t) dst_arg=$2
+	# Protect names problematic for 'test' and other utilities.
+	case $dst_arg in
+	  -* | [=\(\)!]) dst_arg=./$dst_arg;;
+	esac
+	shift;;
+
+    -T) no_target_directory=true;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)	shift
 	break;;
+
+    -*)	echo "$0: invalid option: $1" >&2
+	exit 1;;
+
+    *)  break;;
   esac
+  shift
 done
 
-if test -z "$1"; then
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+    # Protect names problematic for 'test' and other utilities.
+    case $dst_arg in
+      -* | [=\(\)!]) dst_arg=./$dst_arg;;
+    esac
+  done
+fi
+
+if test $# -eq 0; then
   if test -z "$dir_arg"; then
     echo "$0: no input file specified." >&2
     exit 1
   fi
-  # It's OK to call `install-sh -d' without argument.
+  # It's OK to call 'install-sh -d' without argument.
   # This can happen when creating conditional directories.
   exit 0
 fi
 
+if test -z "$dir_arg"; then
+  do_exit='(exit $ret); exit $ret'
+  trap "ret=129; $do_exit" 1
+  trap "ret=130; $do_exit" 2
+  trap "ret=141; $do_exit" 13
+  trap "ret=143; $do_exit" 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
 for src
 do
-  # Protect names starting with `-'.
+  # Protect names problematic for 'test' and other utilities.
   case $src in
-    -*) src=./$src ;;
+    -* | [=\(\)!]) src=./$src;;
   esac
 
   if test -n "$dir_arg"; then
     dst=$src
-    src=
-
-    if test -d "$dst"; then
-      instcmd=:
-      chmodcmd=
-    else
-      instcmd=$mkdirprog
-    fi
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
   else
-    # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
     # might cause directories to be created, which would be especially bad
     # if $src (and thus $dsttmp) contains '*'.
     if test ! -f "$src" && test ! -d "$src"; then
@@ -188,138 +260,275 @@ do
       exit 1
     fi
 
-    if test -z "$dstarg"; then
+    if test -z "$dst_arg"; then
       echo "$0: no destination specified." >&2
       exit 1
     fi
-
-    dst=$dstarg
-    # Protect names starting with `-'.
-    case $dst in
-      -*) dst=./$dst ;;
-    esac
+    dst=$dst_arg
 
     # If destination is a directory, append the input filename; won't work
     # if double slashes aren't ignored.
     if test -d "$dst"; then
-      dst=$dst/`basename "$src"`
+      if test -n "$no_target_directory"; then
+	echo "$0: $dst_arg: Is a directory" >&2
+	exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+	(dirname "$dst") 2>/dev/null ||
+	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	     X"$dst" : 'X\(//\)[^/]' \| \
+	     X"$dst" : 'X\(//\)$' \| \
+	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+	echo X"$dst" |
+	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)[^/].*/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\).*/{
+		   s//\1/
+		   q
+		 }
+		 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
     fi
   fi
 
-  # This sed command emulates the dirname command.
-  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+	# Create intermediate dirs using mode 755 as modified by the umask.
+	# This is like FreeBSD 'install' as of 1997-10-28.
+	umask=`umask`
+	case $stripcmd.$umask in
+	  # Optimize common cases.
+	  *[2367][2367]) mkdir_umask=$umask;;
+	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+	  *[0-7])
+	    mkdir_umask=`expr $umask + 22 \
+	      - $umask % 100 % 40 + $umask % 20 \
+	      - $umask % 10 % 4 + $umask % 2
+	    `;;
+	  *) mkdir_umask=$umask,go-w;;
+	esac
+
+	# With -d, create the new directory with the user-specified mode.
+	# Otherwise, rely on $mkdir_umask.
+	if test -n "$dir_arg"; then
+	  mkdir_mode=-m$mode
+	else
+	  mkdir_mode=
+	fi
+
+	posix_mkdir=false
+	case $umask in
+	  *[123567][0-7][0-7])
+	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
+	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+	    ;;
+	  *)
+            # $RANDOM is not portable (e.g. dash);  use it when possible to
+            # lower collision chance
+	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+	    trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+	     # As "mkdir -p" follows symlinks and we work in /tmp possibly;  so
+	     # create the $tmpdir first (and fail if unsuccessful) to make sure
+	     # that nobody tries to guess the $tmpdir name.
+	    if (umask $mkdir_umask &&
+		$mkdirprog $mkdir_mode "$tmpdir" &&
+		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
+	    then
+	      if test -z "$dir_arg" || {
+		   # Check for POSIX incompatibilities with -m.
+		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+		   # other-writable bit of parent directory when it shouldn't.
+		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+		   test_tmpdir="$tmpdir/a"
+		   ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
+		   case $ls_ld_tmpdir in
+		     d????-?r-*) different_mode=700;;
+		     d????-?--*) different_mode=755;;
+		     *) false;;
+		   esac &&
+		   $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
+		     ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
+		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+		   }
+		 }
+	      then posix_mkdir=:
+	      fi
+	      rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
+	    else
+	      # Remove any dirs left behind by ancient mkdir implementations.
+	      rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
+	    fi
+	    trap '' 0;;
+	esac;;
+    esac
 
-  # Make sure that the destination directory exists.
+    if
+      $posix_mkdir && (
+	umask $mkdir_umask &&
+	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
 
-  # Skip lots of stat calls in the usual case.
-  if test ! -d "$dstdir"; then
-    defaultIFS='
-	 '
-    IFS="${IFS-$defaultIFS}"
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
 
-    oIFS=$IFS
-    # Some sh's can't handle IFS=/ for some reason.
-    IFS='%'
-    set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
-    IFS=$oIFS
+      case $dstdir in
+	/*) prefix='/';;
+	[-=\(\)!]*) prefix='./';;
+	*)  prefix='';;
+      esac
 
-    pathcomp=
+      eval "$initialize_posix_glob"
 
-    while test $# -ne 0 ; do
-      pathcomp=$pathcomp$1
+      oIFS=$IFS
+      IFS=/
+      $posix_glob set -f
+      set fnord $dstdir
       shift
-      if test ! -d "$pathcomp"; then
-        $mkdirprog "$pathcomp" || lasterr=$?
-	# mkdir can fail with a `File exist' error in case several
-	# install-sh are creating the directory concurrently.  This
-	# is OK.
-	test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
+      $posix_glob set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+	test X"$d" = X && continue
+
+	prefix=$prefix$d
+	if test -d "$prefix"; then
+	  prefixes=
+	else
+	  if $posix_mkdir; then
+	    (umask=$mkdir_umask &&
+	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+	    # Don't fail if two instances are running concurrently.
+	    test -d "$prefix" || exit 1
+	  else
+	    case $prefix in
+	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+	      *) qprefix=$prefix;;
+	    esac
+	    prefixes="$prefixes '$qprefix'"
+	  fi
+	fi
+	prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+	# Don't fail if two instances are running concurrently.
+	(umask $mkdir_umask &&
+	 eval "\$doit_exec \$mkdirprog $prefixes") ||
+	  test -d "$dstdir" || exit 1
+	obsolete_mkdir_used=true
       fi
-      pathcomp=$pathcomp/
-    done
+    fi
   fi
 
   if test -n "$dir_arg"; then
-    $doit $instcmd "$dst" \
-      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
-      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
-      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
-      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
-
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
   else
-    # If we're going to rename the final executable, determine the name now.
-    if test -z "$transformarg"; then
-      dstfile=`basename "$dst"`
-    else
-      dstfile=`basename "$dst" $transformbasename \
-               | sed $transformarg`$transformbasename
-    fi
-
-    # don't allow the sed command to completely eliminate the filename.
-    test -z "$dstfile" && dstfile=`basename "$dst"`
 
     # Make a couple of temp file names in the proper directory.
     dsttmp=$dstdir/_inst.$$_
     rmtmp=$dstdir/_rm.$$_
 
     # Trap to clean up those temp files at exit.
-    trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
-    trap '(exit $?); exit' 1 2 13 15
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
 
-    # Move or copy the file name to the temp name
-    $doit $instcmd "$src" "$dsttmp" &&
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
 
     # and set any options; do chmod last to preserve setuid bits.
     #
     # If any of these fail, we abort the whole thing.  If we want to
     # ignore errors from any of these, just make sure not to ignore
-    # errors from the above "$doit $instcmd $src $dsttmp" command.
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
     #
-    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
-      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
-      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
-      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
-
-    # Now rename the file to the real destination.
-    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
-      || {
-	   # The rename failed, perhaps because mv can't rename something else
-	   # to itself, or perhaps because mv is so ancient that it does not
-	   # support -f.
-
-	   # Now remove or move aside any old file at destination location.
-	   # We try this two ways since rm can't unlink itself on some
-	   # systems and the destination file might be busy for other
-	   # reasons.  In this case, the final cleanup might fail but the new
-	   # file should still install successfully.
-	   {
-	     if test -f "$dstdir/$dstfile"; then
-	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
-	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
-	       || {
-		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
-		 (exit 1); exit
-	       }
-	     else
-	       :
-	     fi
-	   } &&
-
-	   # Now rename the file to the real destination.
-	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
-	 }
-    }
-  fi || { (exit 1); exit; }
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
+
+       eval "$initialize_posix_glob" &&
+       $posix_glob set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       $posix_glob set +f &&
+
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+	# Now remove or move aside any old file at destination location.
+	# We try this two ways since rm can't unlink itself on some
+	# systems and the destination file might be busy for other
+	# reasons.  In this case, the final cleanup might fail but the new
+	# file should still install successfully.
+	{
+	  test ! -f "$dst" ||
+	  $doit $rmcmd -f "$dst" 2>/dev/null ||
+	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+	  } ||
+	  { echo "$0: cannot unlink or rename $dst" >&2
+	    (exit 1); exit 1
+	  }
+	} &&
+
+	# Now rename the file to the real destination.
+	$doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
 done
 
-# The final little trick to "correctly" pass the exit status to the exit trap.
-{
-  (exit 0); exit
-}
-
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:

File diff suppressed because it is too large
+ 2647 - 1392
config/ltmain.sh


+ 156 - 301
config/missing

@@ -1,11 +1,10 @@
 #! /bin/sh
-# Common stub for a few missing GNU programs while installing.
+# Common wrapper for a few potentially missing GNU programs.
 
-scriptversion=2003-09-02.23
+scriptversion=2013-10-28.13; # UTC
 
-# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 
-#   Free Software Foundation, Inc.
-# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -18,9 +17,7 @@ scriptversion=2003-09-02.23
 # GNU General Public License for more details.
 
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -28,333 +25,191 @@ scriptversion=2003-09-02.23
 # the same distribution terms that you use for the rest of that program.
 
 if test $# -eq 0; then
-  echo 1>&2 "Try \`$0 --help' for more information"
+  echo 1>&2 "Try '$0 --help' for more information"
   exit 1
 fi
 
-run=:
+case $1 in
 
-# In the cases where this matters, `missing' is being run in the
-# srcdir already.
-if test -f configure.ac; then
-  configure_ac=configure.ac
-else
-  configure_ac=configure.in
-fi
-
-msg="missing on your system"
-
-case "$1" in
---run)
-  # Try to run requested program, and just exit if it succeeds.
-  run=
-  shift
-  "$@" && exit 0
-  # Exit code 63 means version mismatch.  This often happens
-  # when the user try to use an ancient version of a tool on
-  # a file that requires a minimum version.  In this case we
-  # we should proceed has if the program had been absent, or
-  # if --run hadn't been passed.
-  if test $? = 63; then
-    run=:
-    msg="probably too old"
-  fi
-  ;;
-esac
+  --is-lightweight)
+    # Used by our autoconf macros to check whether the available missing
+    # script is modern enough.
+    exit 0
+    ;;
 
-# If it does not exist, or fails to run (possibly an outdated version),
-# try to emulate it.
-case "$1" in
+  --run)
+    # Back-compat with the calling convention used by older automake.
+    shift
+    ;;
 
   -h|--h|--he|--hel|--help)
     echo "\
 $0 [OPTION]... PROGRAM [ARGUMENT]...
 
-Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
-error status if there is no known handling for PROGRAM.
+Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
+to PROGRAM being missing or too old.
 
 Options:
   -h, --help      display this help and exit
   -v, --version   output version information and exit
-  --run           try to run the given command, and emulate it if it fails
 
 Supported PROGRAM values:
-  aclocal      touch file \`aclocal.m4'
-  autoconf     touch file \`configure'
-  autoheader   touch file \`config.h.in'
-  automake     touch all \`Makefile.in' files
-  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
-  flex         create \`lex.yy.c', if possible, from existing .c
-  help2man     touch the output file
-  lex          create \`lex.yy.c', if possible, from existing .c
-  makeinfo     touch the output file
-  tar          try tar, gnutar, gtar, then tar without non-portable flags
-  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
+  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
+  bison     yacc      flex         lex       help2man
+
+Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
+'g' are ignored when checking the name.
 
 Send bug reports to <bug-automake@gnu.org>."
+    exit $?
     ;;
 
   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
     echo "missing $scriptversion (GNU Automake)"
+    exit $?
     ;;
 
   -*)
-    echo 1>&2 "$0: Unknown \`$1' option"
-    echo 1>&2 "Try \`$0 --help' for more information"
+    echo 1>&2 "$0: unknown '$1' option"
+    echo 1>&2 "Try '$0 --help' for more information"
     exit 1
     ;;
 
-  aclocal*)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
-         to install the \`Automake' and \`Perl' packages.  Grab them from
-         any GNU archive site."
-    touch aclocal.m4
-    ;;
-
-  autoconf)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`${configure_ac}'.  You might want to install the
-         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
-         archive site."
-    touch configure
-    ;;
-
-  autoheader)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
-         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
-         from any GNU archive site."
-    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
-    test -z "$files" && files="config.h"
-    touch_files=
-    for f in $files; do
-      case "$f" in
-      *:*) touch_files="$touch_files "`echo "$f" |
-				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
-      *) touch_files="$touch_files $f.in";;
-      esac
-    done
-    touch $touch_files
-    ;;
-
-  automake*)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
-         You might want to install the \`Automake' and \`Perl' packages.
-         Grab them from any GNU archive site."
-    find . -type f -name Makefile.am -print |
-	   sed 's/\.am$/.in/' |
-	   while read f; do touch "$f"; done
-    ;;
-
-  autom4te)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is needed, but is $msg.
-         You might have modified some files without having the
-         proper tools for further handling them.
-         You can get \`$1' as part of \`Autoconf' from any GNU
-         archive site."
-
-    file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
-    test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
-    if test -f "$file"; then
-	touch $file
-    else
-	test -z "$file" || exec >$file
-	echo "#! /bin/sh"
-	echo "# Created by GNU Automake missing as a replacement of"
-	echo "#  $ $@"
-	echo "exit 0"
-	chmod +x $file
-	exit 1
-    fi
-    ;;
-
-  bison|yacc)
-    echo 1>&2 "\
-WARNING: \`$1' $msg.  You should only need it if
-         you modified a \`.y' file.  You may need the \`Bison' package
-         in order for those modifications to take effect.  You can get
-         \`Bison' from any GNU archive site."
-    rm -f y.tab.c y.tab.h
-    if [ $# -ne 1 ]; then
-        eval LASTARG="\${$#}"
-	case "$LASTARG" in
-	*.y)
-	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
-	    if [ -f "$SRCFILE" ]; then
-	         cp "$SRCFILE" y.tab.c
-	    fi
-	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
-	    if [ -f "$SRCFILE" ]; then
-	         cp "$SRCFILE" y.tab.h
-	    fi
-	  ;;
-	esac
-    fi
-    if [ ! -f y.tab.h ]; then
-	echo >y.tab.h
-    fi
-    if [ ! -f y.tab.c ]; then
-	echo 'main() { return 0; }' >y.tab.c
-    fi
-    ;;
-
-  lex|flex)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified a \`.l' file.  You may need the \`Flex' package
-         in order for those modifications to take effect.  You can get
-         \`Flex' from any GNU archive site."
-    rm -f lex.yy.c
-    if [ $# -ne 1 ]; then
-        eval LASTARG="\${$#}"
-	case "$LASTARG" in
-	*.l)
-	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
-	    if [ -f "$SRCFILE" ]; then
-	         cp "$SRCFILE" lex.yy.c
-	    fi
-	  ;;
-	esac
-    fi
-    if [ ! -f lex.yy.c ]; then
-	echo 'main() { return 0; }' >lex.yy.c
-    fi
-    ;;
-
-  help2man)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-	 you modified a dependency of a manual page.  You may need the
-	 \`Help2man' package in order for those modifications to take
-	 effect.  You can get \`Help2man' from any GNU archive site."
-
-    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
-    if test -z "$file"; then
-	file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
-    fi
-    if [ -f "$file" ]; then
-	touch $file
-    else
-	test -z "$file" || exec >$file
-	echo ".ab help2man is required to generate this page"
-	exit 1
-    fi
-    ;;
-
-  makeinfo)
-    if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
-       # We have makeinfo, but it failed.
-       exit 1
-    fi
-
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified a \`.texi' or \`.texinfo' file, or any other file
-         indirectly affecting the aspect of the manual.  The spurious
-         call might also be the consequence of using a buggy \`make' (AIX,
-         DU, IRIX).  You might want to install the \`Texinfo' package or
-         the \`GNU make' package.  Grab either from any GNU archive site."
-    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
-    if test -z "$file"; then
-      file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
-      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
-    fi
-    touch $file
-    ;;
-
-  tar)
-    shift
-    if test -n "$run"; then
-      echo 1>&2 "ERROR: \`tar' requires --run"
-      exit 1
-    fi
-
-    # We have already tried tar in the generic part.
-    # Look for gnutar/gtar before invocation to avoid ugly error
-    # messages.
-    if (gnutar --version > /dev/null 2>&1); then
-       gnutar "$@" && exit 0
-    fi
-    if (gtar --version > /dev/null 2>&1); then
-       gtar "$@" && exit 0
-    fi
-    firstarg="$1"
-    if shift; then
-	case "$firstarg" in
-	*o*)
-	    firstarg=`echo "$firstarg" | sed s/o//`
-	    tar "$firstarg" "$@" && exit 0
-	    ;;
-	esac
-	case "$firstarg" in
-	*h*)
-	    firstarg=`echo "$firstarg" | sed s/h//`
-	    tar "$firstarg" "$@" && exit 0
-	    ;;
-	esac
-    fi
+esac
 
-    echo 1>&2 "\
-WARNING: I can't seem to be able to run \`tar' with the given arguments.
-         You may want to install GNU tar or Free paxutils, or check the
-         command line arguments."
-    exit 1
-    ;;
+# Run the given program, remember its exit status.
+"$@"; st=$?
+
+# If it succeeded, we are done.
+test $st -eq 0 && exit 0
+
+# Also exit now if we it failed (or wasn't found), and '--version' was
+# passed; such an option is passed most likely to detect whether the
+# program is present and works.
+case $2 in --version|--help) exit $st;; esac
+
+# Exit code 63 means version mismatch.  This often happens when the user
+# tries to use an ancient version of a tool on a file that requires a
+# minimum version.
+if test $st -eq 63; then
+  msg="probably too old"
+elif test $st -eq 127; then
+  # Program was missing.
+  msg="missing on your system"
+else
+  # Program was found and executed, but failed.  Give up.
+  exit $st
+fi
 
-  *)
-    echo 1>&2 "\
-WARNING: \`$1' is needed, and is $msg.
-         You might have modified some files without having the
-         proper tools for further handling them.  Check the \`README' file,
-         it often tells you about the needed prerequisites for installing
-         this package.  You may also peek at any GNU archive site, in case
-         some other package would contain this missing \`$1' program."
-    exit 1
+perl_URL=http://www.perl.org/
+flex_URL=http://flex.sourceforge.net/
+gnu_software_URL=http://www.gnu.org/software
+
+program_details ()
+{
+  case $1 in
+    aclocal|automake)
+      echo "The '$1' program is part of the GNU Automake package:"
+      echo "<$gnu_software_URL/automake>"
+      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/autoconf>"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+    autoconf|autom4te|autoheader)
+      echo "The '$1' program is part of the GNU Autoconf package:"
+      echo "<$gnu_software_URL/autoconf/>"
+      echo "It also requires GNU m4 and Perl in order to run:"
+      echo "<$gnu_software_URL/m4/>"
+      echo "<$perl_URL>"
+      ;;
+  esac
+}
+
+give_advice ()
+{
+  # Normalize program name to check for.
+  normalized_program=`echo "$1" | sed '
+    s/^gnu-//; t
+    s/^gnu//; t
+    s/^g//; t'`
+
+  printf '%s\n' "'$1' is $msg."
+
+  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
+  case $normalized_program in
+    autoconf*)
+      echo "You should only need it if you modified 'configure.ac',"
+      echo "or m4 files included by it."
+      program_details 'autoconf'
+      ;;
+    autoheader*)
+      echo "You should only need it if you modified 'acconfig.h' or"
+      echo "$configure_deps."
+      program_details 'autoheader'
+      ;;
+    automake*)
+      echo "You should only need it if you modified 'Makefile.am' or"
+      echo "$configure_deps."
+      program_details 'automake'
+      ;;
+    aclocal*)
+      echo "You should only need it if you modified 'acinclude.m4' or"
+      echo "$configure_deps."
+      program_details 'aclocal'
+      ;;
+   autom4te*)
+      echo "You might have modified some maintainer files that require"
+      echo "the 'autom4te' program to be rebuilt."
+      program_details 'autom4te'
+      ;;
+    bison*|yacc*)
+      echo "You should only need it if you modified a '.y' file."
+      echo "You may want to install the GNU Bison package:"
+      echo "<$gnu_software_URL/bison/>"
+      ;;
+    lex*|flex*)
+      echo "You should only need it if you modified a '.l' file."
+      echo "You may want to install the Fast Lexical Analyzer package:"
+      echo "<$flex_URL>"
+      ;;
+    help2man*)
+      echo "You should only need it if you modified a dependency" \
+           "of a man page."
+      echo "You may want to install the GNU Help2man package:"
+      echo "<$gnu_software_URL/help2man/>"
     ;;
-esac
-
-exit 0
+    makeinfo*)
+      echo "You should only need it if you modified a '.texi' file, or"
+      echo "any other file indirectly affecting the aspect of the manual."
+      echo "You might want to install the Texinfo package:"
+      echo "<$gnu_software_URL/texinfo/>"
+      echo "The spurious makeinfo call might also be the consequence of"
+      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
+      echo "want to install GNU make:"
+      echo "<$gnu_software_URL/make/>"
+      ;;
+    *)
+      echo "You might have modified some files without having the proper"
+      echo "tools for further handling them.  Check the 'README' file, it"
+      echo "often tells you about the needed prerequisites for installing"
+      echo "this package.  You may also peek at any GNU archive site, in"
+      echo "case some other package contains this missing '$1' program."
+      ;;
+  esac
+}
+
+give_advice "$1" | sed -e '1s/^/WARNING: /' \
+                       -e '2,$s/^/         /' >&2
+
+# Propagate the correct exit status (expected to be 127 for a program
+# not found, 63 for a program that failed due to version mismatch).
+exit $st
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
 # End:

+ 0 - 150
config/mkinstalldirs

@@ -1,150 +0,0 @@
-#! /bin/sh
-# mkinstalldirs --- make directory hierarchy
-
-scriptversion=2004-02-15.20
-
-# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
-# Created: 1993-05-16
-# Public domain.
-#
-# This file is maintained in Automake, please report
-# bugs to <bug-automake@gnu.org> or send patches to
-# <automake-patches@gnu.org>.
-
-errstatus=0
-dirmode=""
-
-usage="\
-Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
-
-Create each directory DIR (with mode MODE, if specified), including all
-leading file name components.
-
-Report bugs to <bug-automake@gnu.org>."
-
-# process command line arguments
-while test $# -gt 0 ; do
-  case $1 in
-    -h | --help | --h*)         # -h for help
-      echo "$usage"
-      exit 0
-      ;;
-    -m)                         # -m PERM arg
-      shift
-      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
-      dirmode=$1
-      shift
-      ;;
-    --version)
-      echo "$0 $scriptversion"
-      exit 0
-      ;;
-    --)                         # stop option processing
-      shift
-      break
-      ;;
-    -*)                         # unknown option
-      echo "$usage" 1>&2
-      exit 1
-      ;;
-    *)                          # first non-opt arg
-      break
-      ;;
-  esac
-done
-
-for file
-do
-  if test -d "$file"; then
-    shift
-  else
-    break
-  fi
-done
-
-case $# in
-  0) exit 0 ;;
-esac
-
-# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
-# mkdir -p a/c at the same time, both will detect that a is missing,
-# one will create a, then the other will try to create a and die with
-# a "File exists" error.  This is a problem when calling mkinstalldirs
-# from a parallel make.  We use --version in the probe to restrict
-# ourselves to GNU mkdir, which is thread-safe.
-case $dirmode in
-  '')
-    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
-      echo "mkdir -p -- $*"
-      exec mkdir -p -- "$@"
-    else
-      # On NextStep and OpenStep, the `mkdir' command does not
-      # recognize any option.  It will interpret all options as
-      # directories to create, and then abort because `.' already
-      # exists.
-      test -d ./-p && rmdir ./-p
-      test -d ./--version && rmdir ./--version
-    fi
-    ;;
-  *)
-    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
-       test ! -d ./--version; then
-      echo "mkdir -m $dirmode -p -- $*"
-      exec mkdir -m "$dirmode" -p -- "$@"
-    else
-      # Clean up after NextStep and OpenStep mkdir.
-      for d in ./-m ./-p ./--version "./$dirmode";
-      do
-        test -d $d && rmdir $d
-      done
-    fi
-    ;;
-esac
-
-for file
-do
-  set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
-  shift
-
-  pathcomp=
-  for d
-  do
-    pathcomp="$pathcomp$d"
-    case $pathcomp in
-      -*) pathcomp=./$pathcomp ;;
-    esac
-
-    if test ! -d "$pathcomp"; then
-      echo "mkdir $pathcomp"
-
-      mkdir "$pathcomp" || lasterr=$?
-
-      if test ! -d "$pathcomp"; then
-	errstatus=$lasterr
-      else
-	if test ! -z "$dirmode"; then
-	  echo "chmod $dirmode $pathcomp"
-	  lasterr=""
-	  chmod "$dirmode" "$pathcomp" || lasterr=$?
-
-	  if test ! -z "$lasterr"; then
-	    errstatus=$lasterr
-	  fi
-	fi
-      fi
-    fi
-
-    pathcomp="$pathcomp/"
-  done
-done
-
-exit $errstatus
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
-# End:

File diff suppressed because it is too large
+ 8027 - 4949
configure


File diff suppressed because it is too large
+ 831 - 203
configure.ac


+ 242 - 66
docs/CHANGELOG

@@ -1,4 +1,180 @@
-$Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
+04/26/2017 Version 4.2.4
+    - Fix Lintian detected spelling errors (#362)
+
+04/12/2017 Version 4.2.3
+    - Archive (remove) QuickTX until maintainer found (#357)
+    - Ubuntu precise 32bit_build (#356)
+
+03/08/2017 Version 4.2.2
+    - Archive (remove) QuickTX (#357)
+    - Missing symbol pcap_version on macOS 10.12.4 (#356)
+
+03/23/2017 Version 4.2.1
+    - Fix reporting of rates < 1Mbps (#348)
+    - Option --unique-ip not working properly (#346)
+
+02/26/2017 Version 4.2.0
+    - MAC rewriting capabilities (#313)
+    - Fix several issues identified by Coverity (#305)
+    - Packet destortion --fuzz-seed option by Gabriel Ganne (#302)
+    - Add --unique-ip-loops option to modify IPs every few loops (#296)
+    - Netmap startup delay increase (#290)
+    - tcpcapinfo buffer overflow vulnerablily (#278)
+    - Update git-clone instructions by Kyle McDonald (#277)
+    - Allow fractions for --pps option (#270)
+    - Print per-loop stats with --stats=0 (#269)
+    - Add protection against packet drift by Guillaume Scott (#268)
+    - Print flow stats periodically with --stats output (#262)
+    - Include Travis-CI build support by Ilya Shipitsin (#264) (#285)
+    - tcpreplay won't replay all packets in a pcap file with --netmap  (#255)
+    - First and last packet times in --stats output (#239)
+    - Switch to wire speed after 30 minutes at 6 Gbps (#210)
+    - tcprewrite fix checksum properly for fragmented packets (#190)
+
+11/19/2016 Version 4.1.2
+    - Fix compilation with musl C library (#260)
+    - Support parallel builds (#259)
+    - Give user CFLAGS precedence (#256)
+    - Properly detect Brew install when Xcode is not available (#254)
+    - Increase max packet size to 65549 (#251)
+    - Handle IP headers with zero length (#247)
+
+01/11/2016 Version 4.1.1
+    - Improve --pps accuracy and performance (#236)
+    - Option --unique-ip accepts --duration (#227)
+    - RFC1624 incremental checksums (#225)
+    - Option --duration performance optimizations (#223)
+    - Correct company name in license (#217)
+    - Compile and mult-arch cross-compile on ARM (#211)
+    - Tap device support for Linux and FreeBSD from Murat Demirten (#207)
+    - Handle loopback for linux cooked capture files from corentin-p1(Linux SLL) (#204)
+    - Master doesn't compile on OS X 10.11 (#203)
+    - Recognise tbd stubs from Dominyk Tiller (#202)
+    - Support for tcprewrite multiple IP CIDR (#199)
+    - Fix incorrect checksums after editing fragmented packets (#190)
+    - Option --loop=0 full wire wire speed after 1st pass (#172 #191)
+    - Big-endian tcpliveplay work-around from Brian Micek (#194)
+    - Build OS X using existing XCode SDK (#185)
+    - Update to autogen version 5.18.6 and libopts 46.0.16 (#182)
+    - netmap reports impossibly high capacity (#176)
+    - Duration feature from dexteradeus (#175)
+    - Stop sending and exit when limit is reached (#174)
+    - Extra packets sent with -L option (#173)
+    - Buffer overflow bug in tcpprep (#167)
+    - netmap optimizations (#93)
+
+12/17/2014 Version 4.1.0
+    - Do not build Quick TX modules on OS X (#164)
+    - Add a flag to customize netmap delay (#160)
+    - Fix some compile wwarnings (#159)
+    - Disabled QuickTX build by default (#157)
+    - Less verbose build (#154)
+    - Add a loop delay option (#125)
+    - CentOS 6.5 kernel panic on Quick TX init (#146)
+    - Fix libpcap not found on CentOS 7 (#145)
+    - Segfault in tcpliveplay on x86_64 (#132)
+    - Sometimes unable to interrupt with Ctrl-C (#129)
+
+10/08/2014 Version 4.1.0beta1
+    - Fix cross compiling (#140)
+    - Add Quick TX module for Linux (#136)
+	- Better recovery for missing static libpcap libs (#128)
+
+09/05/2014 Version 4.0.5
+    - Fix build failure with latest netmap 11 (#123)
+    - Fix unable to use Zero Copy interfaces on PF_RING (#118)
+    - Corrected build for latest version of PF_RING (#81)
+    - Proper error message when vale is unconfigured (#113)
+    - Avoid a netmap module debug message (#110)
+    - Add missing header to distribution (#108)
+    - Make --netmap version agnostic (#106)
+    - Fix netmap hang in FreeBSD 11 (#103)
+    - Fix netmap hang if network cables unplugged (#96)
+    - Support for Vale Switch (#91)
+    - Prevent file retransmissions when selecting multiple files (#86)
+    - Fix max replay rate for all loops except first when omitting --mbps (#85)
+    - Add missing sanity check in libopt (#84)
+    - Seg fault on some IPv6 files when using -C option with tcprewrite (#83)
+    - Support for PF_RING DNA version of libpcap (#81)
+    - Fix segfault when using '-F pad' (#80)
+    - Disallow netmap on multiple interfaces (#79)
+    - Fix build for FreeBSD version 8.4 (#78)
+
+03/22/2014 Version 4.0.4
+    - Number of packets inaccurate when using --netmap method (#76)
+    - Unexpected packet counts with --loop and --cachefile enabled (#75)
+    - Improved error messages when interface is a file (#74)
+    - Missing interfaces with --listnics option (#67)
+    - Compile issue with netmap v10 and debugging (#66)
+    - Bad values with --stats and -t options (#65)
+
+02/04/2014 Version 4.0.3
+    - Fix build errors when ENABLE_VERBOSE is not set (#60)
+    - Build error on host without tcpdump (#59)
+
+01/17/2014 Version 4.0.2
+    - Fix hangs with --mbps command (#54)
+
+01/16/2014 Version 4.0.1
+    - Support for netmap version 10 API (#53)
+    - Remove deprecated "absolute time" for OS X (#52)
+    - Make dosleep() rentrant to support API concurrency (#51)
+    - Remove compiler warnings (#50)
+    - Fix slow netmap in Intel GigE "igb" server NICS (#49)
+
+01/05/2014 Version 4.0.0
+    - Implemented wiki page for 4.X - http://tcpreplay.appneta.com
+    - Support for ARM aarch64 (appneta #43)
+    - Add Juniper Encapsulated Ethernet DLT (appneta #42)
+    - Fixed seg fault on -K and --dualfile options (appneta #41)
+
+12/22/2013 Version 4.0.0beta2
+    - Restored -K option which somehow disappeared (appneta #35)
+    - Improve printing with small pcaps at high rates (appneta #34)
+    - Fixed build errors on BSD and Fedora 20 (appneta #32 #33)
+
+12/20/2013 Version 4.0.0beta1
+    - Compile and cross compile on ARM (appneta #26)
+    - Add flow statistics (appneta #23)
+    - Merge code cleanups from old 4.0alpha1 project (appneta #18)
+    - Deprecated file-cache option - use preload-pcap instead (appneta #17)
+    - Removed obsolete sleep-mode and sleep-accel options (appneta #16)
+    - Remove unreliable RDTSC option (appneta #16)
+    - Switch from BSD to GPLv3 license (appneta #5)
+    - Add --unique-ip option to tcpreplay (appneta #4)
+    - Removed sleep-accel option (appneta #2)
+    - Enhance accuracy and performance of --mbps option (appneta #2)
+    - Add netmap injector (appneta #1)
+    - Properly process IPv6 extension headers (#396)
+    - Update URL's to point to new tcpreplay website (#430)
+    - Improve & fix bugs in tcpcapinfo (#437)
+    - Fix statistics to be more industry standard (#443)
+    - Add --nofixcsum (#449)
+    - Fix compile failure under FreeBSD 9.0 (#450)
+    - Don't checksum packets before going through fragroute engine (#452)
+    - Add support for --maxsleep option to tcpreplay (#453)
+    - Fix segfault when rewriting multiple ports (#459)
+    - Fix bug with printing stats after CTRL-C (#482)
+    - Update autotools (#483)
+    - Don't recalculate UDP checksums if it's value is 0 (#490)
+    - Fix documentation of --efcs option to be 4, not 2 bytes (#495)
+    - Fix libdnet header detection under Debian distros (#499)
+    - Update GNU Autogen to 5.11.5 (#501)
+    - Fix --stats option for tcpreplay (#503)
+    - Add support for injecting directly via custom Linux kernel module (#505)
+    - Fix cidr code debugging (#506)
+    - Standardize on primary/secondary meaning of interfaces/tcpprep split (#507)
+
+08/15/2010 Version 3.4.5beta1
+    - First pass at fixing 'make test' on many little-endian systems (#429)
+    - Warn users when processing LINUX_SLL frames w/o an Ethernet source MAC (#434)
+    - Don't try to fragroute non-IPv4/v6 packets so we don't error out (#432)
+    - Initial Linux TX_RING sending support (#435)
+    - Update to GNU Autoconf 2.67 (#436)
+    - Add tcpcapinfo which dumps information about the pcap header/packets (#437)
+    - Add --dualfile support for replaying two files at the same time (#439)
+    - Fix bug where --tos=0 didn't do anything (#440)
+    - Fix crash when processing CIDR data (#441)
 
 04/04/2010 Version 3.4.4
     - Set default timing method to either gtod or abstime (#404)
@@ -76,7 +252,7 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
     - Re-enable tcpreplay --listnics (#319)
     - Fix sendpacket always reporting using PF_PACKET, even when it doesn't (#322)
     - Fix major packet timing issue under old versions of glibc (#324)
-    
+
 05/17/2008: Version 3.3.1
     - Fix limitation of PF_PACKET only supporting Ethernet (#123)
     - Fix (again) /dev/bpf detection in FreeBSD 8.0 (#292)
@@ -111,7 +287,7 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
 
 11/01/2007: Version 3.2.3
     - Fix compile issue under Linux and other OS's (#275)
-    
+
 10/31/2007: Version 3.2.2
     - Enable source MAC spoofing for OS X (#142, #151)
         * Tcpreplay now requires OS X 10.5 (Leopard)
@@ -125,7 +301,7 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
     - Remove flowreplay code (#262)
     - Fix DLT rewrite code causing corrupted ethernet protocol type (#268)
     - Try to fix inet_aton() issue under Solaris (#260)
-    
+
 08/26/2007: Version 3.2
     - Return a more useful error message when tcpprep fails (#187)
     - Add Tomahawk test tool client/server detection algorithm (#186)
@@ -133,7 +309,7 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
     - Improved documentation (#164, #198)
     - Added Doxygen markup (#176)
     - configure now honors --with-tcpdump flag (#192)
-    - configure now defaults to --enable-64bits which breaks backwards 
+    - configure now defaults to --enable-64bits which breaks backwards
         compatibility in certain situations.  Use --disable-64bits if this
         concerns you (#195)
     - Use safe_free() to detect bugs earlier in development (#197)
@@ -159,49 +335,49 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
         - 802.11 w/ Radiotap (#177)
 
 05/01/2007: Version 3.0.1
-	- Stop tcpreplay causing OS X WiFi from disassociating (#167)
-	- --pnat incorrectly matched all IP addresses (#170)
-	- Fix serious memory leak in core common library (#175)
-	- Fix tcprewrite --enet-vlan on little endian systems (#174)
-	- Bad pcap timestamps were causing excessive delays (#169)
-	- Code cleanup (#173)
+    - Stop tcpreplay causing OS X WiFi from disassociating (#167)
+    - --pnat incorrectly matched all IP addresses (#170)
+    - Fix serious memory leak in core common library (#175)
+    - Fix tcprewrite --enet-vlan on little endian systems (#174)
+    - Bad pcap timestamps were causing excessive delays (#169)
+    - Code cleanup (#173)
 
 04/20/2007: Version 3.0
-	- By default, no longer try to use libnet.  You must now specify --enable-libnet (#148)
-	- Improve documentation (#30)
-	- General code cleanup (#47)
-	- Warn when GNU Autogen version < 5.9 (#153)
-	- Remove support for pcap_snapshot_override which was never added to libpcap (#140)
-	- Fix support for C99/GCC 4.3 "inline".  Rely on -O3 for better performance. (#149)
-	- Prioritize 64 bit libraries over 32 bit counterparts (#150)
+    - By default, no longer try to use libnet.  You must now specify --enable-libnet (#148)
+    - Improve documentation (#30)
+    - General code cleanup (#47)
+    - Warn when GNU Autogen version < 5.9 (#153)
+    - Remove support for pcap_snapshot_override which was never added to libpcap (#140)
+    - Fix support for C99/GCC 4.3 "inline".  Rely on -O3 for better performance. (#149)
+    - Prioritize 64 bit libraries over 32 bit counterparts (#150)
 
 04/14/2007: Version 3.0.RC1
     - Fix tcpbridge and make it compile by default (#15)
-	- Fix tcprewrite crash on little-endian systems (#127)
-	- Gracefully handle broken pcap files where the snaplen < caplen (#130)
-		- Note: Fix was made in libpcap and will be part of 0.9.6
-	- Fix numerous bugs with the sendpacket code (#137)
-	- Add optional support for editing packets with tcpreplay (#61)
-	- Fix 'make test' on little endian systems (#64)
-	- tcprewrite -s is no longer endian dependent (#65)
-	- /docs cleaned up (#66)
-	- Fix detection/compile of libpcap.  Now support versions >= 0.7.2 (#80, #144)
-	- Add official support Cygwin/Win32 support (#110)
-	- Clean up libpcap version code (#111)
-	- Add support for interface alias names for Win32 (#113)
-	- Warn user on DLT miss-match (#125)
-	- Fix tcprewrite segfault with --fixlen=pad (#134)
-	- Add loop/cache support for better performance (#136)
-	- inline debugging code for better performance (#138)
-	- configure now supports selecting injection method (#139)
-	- Fix configure/compile errors under OpenBSD (#146)
-	- Add tcpbridge --verbose mode (#28)
-	- Fix compile issues under HP-UX & strictly aligned systems (#141)
-	- --enable-dynamic-link supports 64bit libraries (#143)
-	
-	
+    - Fix tcprewrite crash on little-endian systems (#127)
+    - Gracefully handle broken pcap files where the snaplen < caplen (#130)
+        - Note: Fix was made in libpcap and will be part of 0.9.6
+    - Fix numerous bugs with the sendpacket code (#137)
+    - Add optional support for editing packets with tcpreplay (#61)
+    - Fix 'make test' on little endian systems (#64)
+    - tcprewrite -s is no longer endian dependent (#65)
+    - /docs cleaned up (#66)
+    - Fix detection/compile of libpcap.  Now support versions >= 0.7.2 (#80, #144)
+    - Add official support Cygwin/Win32 support (#110)
+    - Clean up libpcap version code (#111)
+    - Add support for interface alias names for Win32 (#113)
+    - Warn user on DLT miss-match (#125)
+    - Fix tcprewrite segfault with --fixlen=pad (#134)
+    - Add loop/cache support for better performance (#136)
+    - inline debugging code for better performance (#138)
+    - configure now supports selecting injection method (#139)
+    - Fix configure/compile errors under OpenBSD (#146)
+    - Add tcpbridge --verbose mode (#28)
+    - Fix compile issues under HP-UX & strictly aligned systems (#141)
+    - --enable-dynamic-link supports 64bit libraries (#143)
+
+
 03/22/2007: Version 3.0.beta13
-	- Fixed detection of IPv4 packets in libtcpedit on little-endian boxes (#115, #116)
+    - Fixed detection of IPv4 packets in libtcpedit on little-endian boxes (#115, #116)
     - Fixed TCP/UDP checksum calculation on little-endian boxes (#126)
     - Added --quiet flag to tcpreplay for Lothar (#109)
     - The --seed flag should now generate the same IPs on both little-endian & big-endian boxes (#65)
@@ -209,29 +385,29 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
     - Adding L2 header for DLT_RAW encapsulated packets now works (#16)
     - Clean up documentation (#66, #75)
     - Start initial support for Win32 port (#110, #111)
-	- Finish DLT plugin rewrite (#82)
-	- Fix compile on systems without tcpdump installed
+    - Finish DLT plugin rewrite (#82)
+    - Fix compile on systems without tcpdump installed
 
 02/22/2007: Version 3.0.beta12
-	- Fix compile under RH ES 3.x (gcc 3.2.2) (#79)
-	- Fix compile on MIPS, ARM, HPPA, etc (#81, #88)
-	- Rewrite L2/DLT code in tcpedit/tcprewrite to be plugin based (#82)
-		- Create Ethernet Plugin (#99)
-		- Create User Plugin (#100)
-		- Create Cisco HDLC Plugin (#101)
-		- Create DLT_LINUX_SLL Plugin (#102)
-		- Create DLT_RAW Plugin (#104)
-		- Create DLT_NULL Plugin (#105)
-		- Create DLT_LOOP Plugin (#106)
-	- Properly decode ethernet frames when they are VLAN tagged (#84)
-	- Do not install man2html (#85)
-	- Add configure --disable-libopts-install option (#86)
-	- Enhance tcpreplay --oneatatime (#90)
-	- libtcpedit can now return warnings & errors (#92)
-	- Fix tcpprep --include/exclude (#96)
-	- Upgrade AutoGen tearoff (libopts) to latest version (5.9.0) (#97)
-	- Don't do L4 checksums for non-fragment offset == 0 (#107)
-	
+    - Fix compile under RH ES 3.x (gcc 3.2.2) (#79)
+    - Fix compile on MIPS, ARM, HPPA, etc (#81, #88)
+    - Rewrite L2/DLT code in tcpedit/tcprewrite to be plugin based (#82)
+        - Create Ethernet Plugin (#99)
+        - Create User Plugin (#100)
+        - Create Cisco HDLC Plugin (#101)
+        - Create DLT_LINUX_SLL Plugin (#102)
+        - Create DLT_RAW Plugin (#104)
+        - Create DLT_NULL Plugin (#105)
+        - Create DLT_LOOP Plugin (#106)
+    - Properly decode ethernet frames when they are VLAN tagged (#84)
+    - Do not install man2html (#85)
+    - Add configure --disable-libopts-install option (#86)
+    - Enhance tcpreplay --oneatatime (#90)
+    - libtcpedit can now return warnings & errors (#92)
+    - Fix tcpprep --include/exclude (#96)
+    - Upgrade AutoGen tearoff (libopts) to latest version (5.9.0) (#97)
+    - Don't do L4 checksums for non-fragment offset == 0 (#107)
+
 08/07/2006: Version 3.0.beta11
     - Fix distribution to ship missing src/tcpr.h (#73)
     - Add support to tcprewrite to alter output file DLT (#74)
@@ -266,7 +442,7 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
     - Improve tcpbridge man page
     - Massive tcprewrite fixes & cleanup (#50)
     - Much improved README document
-    - Reorganize packet editing code into a standalone module (tcpedit) 
+    - Reorganize packet editing code into a standalone module (tcpedit)
           which has been librarized. (#5)
     - Strict code cleanup (#27)
     - Fix tcpprep from generating bad cache files (#48)
@@ -368,8 +544,8 @@ $Id: CHANGELOG 2449 2010-04-04 06:39:38Z aturner $
       - tcprewrite
 
     - Removed Applications: (Ethereal has better utilities)
-      - capinfo 
-      - pcapmerge 
+      - capinfo
+      - pcapmerge
 
     - Merge fixes from 2.x/stable branch:
       - portmap.c endian bugs

+ 24 - 3
docs/CREDIT

@@ -1,7 +1,8 @@
-$Id: CREDIT 2308 2009-05-06 19:05:38Z aturner $ 
+$Id$ 
 
 tcpreplay and it's associated utilities (tcpprep, tcprewrite and flowreplay)
-were designed and written by Aaron Turner.
+were designed and written by Aaron Turner, and maintained and updated by 
+Fred Klassen of AppNeta
 
 This product includes software developed by the University of California,
 Berkeley, Lawrence Berkeley Laboratory and its contributors. 
@@ -36,7 +37,7 @@ Nick Mathewson <nickm@freehaven.net>
     - Kindly giving me his BSD licensed implimentation of poll()
       using select() so I don't have to worry about cross platform
       issues.
-          
+
 Denis McLaughlin <denism@cyberus.ca>
     - Patch to allow TCP/UDP port translation
 
@@ -57,3 +58,23 @@ Bojan Smojver <bojan@rexursive.com>
 Stas Grabois <sagig@radware.com>
     - For his efforts to add IPv6 support to tcpprep and the tcpedit engine
     - For adding IPv6 support to fragroute
+    
+Fred Klassen <tcpreplay@appneta.com> - AppNeta 
+    - New maintainer of Tcpreplay
+    - Added netmap support for wire-rate performance on commodity hardware
+    - Improve accuracy and performance of the --mbps option
+    - Implement pseudo-CRC to improve tcpedit performance
+    - Add --fast-flows option to tcpreplay
+
+Luigi Rizzo <rizzo@iet.unipi.it>
+	- Creator of netmap
+	- Assisted with netmap performance tuning
+
+Alexey Indeev <alexey.indeev@gmail.com> - AppNeta
+    - Quick TX module for Linux
+
+Pedro Arthur Duarte [aka JEdi] <GitHub @pedroarthur>
+    - MAC rewrite feature
+
+Gabriel Ganne <GitHub @GabrielGanne>
+    - Data fuzz rewrite feature

+ 13 - 11
docs/HACKING

@@ -1,4 +1,4 @@
-$Id: HACKING 1782 2007-04-02 04:21:30Z aturner $ 
+$Id$ 
                           Guide to Hacking Tcpreplay
 
 [Note: Pay attention to the last update date at the top of this file.  If it
@@ -9,7 +9,8 @@ was significantly long ago, this document may be out of date.]
 If you contribute code the following will happen:
     a) You will be given credit in the CREDITS file
     b) Your code will be licensed under the same license as that of tcpreplay
-    c) You will be assigning your copyright to me- Aaron Turner
+    c) You will be assigning your copyright to Aaron Turner 
+       and Fred Klassen - Appneta Inc.
 
 If you have any questions regarding any of the three above stipulations,
 feel free to email the list at: tcpreplay-users@lists.sourceforge.net
@@ -26,14 +27,15 @@ etc.
 
 The file layout is pretty simple:
 
-/            - Base directory
-/lib         - 3rd party libraries stolen verbatim
-/libopts     - GNU AutoOpts tearoff
-/src         - Main code routines
-/src/common  - Common routines for all binaries
-/src/tcpedit - libtcpedit
-/docs        - Where to find documentation
-/test        - Test scripts and stuff which is used during 'make test'
+/                    - Base directory
+/lib                 - 3rd party libraries stolen verbatim
+/libopts             - GNU AutoOpts tearoff
+/src                 - Main code routines
+/src/common          - Common routines for all binaries
+/src/tcpedit         - libtcpedit
+/src/tcpedit/plugins - plugins for libtcpedit (mostly DLT)
+/docs                - Where to find documentation
+/test                - Test scripts and stuff which is used during 'make test'
 
 3. Coding Standards
 1) Indent 4 spaces using spaces, not tabs
@@ -49,7 +51,7 @@ The file layout is pretty simple:
 libtcpedit supports a plugin based architecture for handling different DLT
 types.  If you wish to add support for another DLT type, you should read:
 
-http://tcpreplay.synfin.net/trac/wiki/tcpeditDeveloper
+http://tcpreplay.synfin.net/wiki/tcpeditDeveloper
 
 Which contains information on creating new DLT plugins.
 

+ 301 - 4
docs/INSTALL

@@ -1,6 +1,303 @@
-$Id: INSTALL 1762 2007-03-24 20:42:05Z aturner $
+Installation Instructions
+*************************
 
-NOTE: This information is out of date.  Please see the tcpreplay wiki
-for updated information: 
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
+2006, 2014 Free Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+
+Advanced Installation
+=====================
+Visit http://tcpreplay.appneta.com/wiki/installation.html
+
+
+Basic Installation
+==================
+
+    ./configure 
+    make
+    sudo make install
+
+Briefly, the shell commands `./configure; make; make install' should
+configure, build, and install this package.  The following
+more-detailed instructions are generic; see the `README' file for
+instructions specific to this package.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You need `configure.ac' if
+you want to change it or regenerate `configure' using a newer version
+of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.
+
+     Running `configure' might take a while.  While running, it prints
+     some messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+
+How to make Tcpreplay go fast
+=============================
+
+1) netmap
+   ------
+This feature will detect netmap capable network drivers on Linux and
+BSD systems. If detected, the network driver is bypassed for the
+execution duration of tcpreplay and tcpreplay-edit, and network buffers
+will be written to directly. This will allow you to achieve full 10GigE
+line rates on commodity 10GigE network adapters, similar to rates 
+achieved by commercial network traffic generators.
+
+Note that bypassing the network driver will disrupt other applications
+connected through the test interface. Use caution when testing on the
+same interface you ssh'ed into.
+
+Ensure that you have supported NICs installed. Most Intel and nForce 
+(nVidia) adapters will work. Some virtual adapters are supported.
+
+FreeBSD 10 and higher already contains netmap capabilities and should
+be detected automatically by "configure". But first you must enable
+netmap on the system by adding 'device netmap' to your kernel config
+and rebuilding the kernel. When complete, /dev/netmap will be
+available.
+
+For Linux, download latest netmap sources from http://info.iet.unipi.it/~luigi/netmap/
+or run 'git clone https://code.google.com/p/netmap/'. You will also need to have 
+kernel sources installed so the build system can patch the sources and build 
+netmap-enabled drivers. If kernel sources are in /a/b/c/linux-A.B.C/ , then you
+should do:
+
+    cd netmap/LINUX
+    make KSRC=/a/b/c/linux-A.B.C/       # builds the kernel modules
+    make KSRC=/a/b/c/linux-A.B.C/ apps  # builds sample applications
+
+You can omit KSRC if your kernel sources are in a standard place.
+
+Once you load the netmap.lin.ko module on your Linux machine, /dev/netmap 
+will be available. You will also need to replace your existing network drivers
+(beyond the scope of this document).
+
+Building netmap-aware Tcpreplay suite is relatively straight forward. For
+FreeBSD, build normally. For Linux, if you extracted netmap into /usr/src/ you 
+can also build normally. Otherwise you will have to specify the netmap source
+directory, for example:
+
+    ./configure --with-netmap=/home/fklassen/git/netmap
+    make
+    sudo make install
+
+
+Compilers and Options
+=====================
+
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about.  Run `./configure --help' for
+details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c99 CFLAGS=-g LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+
+Compiling For Multiple Architectures
+====================================
+
+You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you can use GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   With a non-GNU `make', it is safer to compile the package for one
+architecture at a time in the source code directory.  After you have
+installed the package for one architecture, use `make distclean' before
+reconfiguring for another architecture.
+
+
+Installation Names
+==================
+
+By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc.  You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+
+Optional Features
+=================
+
+Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+
+Specifying the System Type
+==========================
+
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+
+Sharing Defaults
+================
+
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+
+Defining Variables
+==================
+
+Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+Unfortunately, this technique does not work for `CONFIG_SHELL' due to
+an Autoconf bug.  Until the bug is fixed you can use this workaround:
+
+     CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+
+`configure' Invocation
+======================
+
+`configure' recognizes the following options to control how it operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
 
-http://tcpreplay.synfin.net/trac/wiki/manual#GettingTcpreplayInstalled

+ 681 - 31
docs/LICENSE

@@ -1,31 +1,681 @@
-$Id: LICENSE 2441 2010-03-30 03:21:52Z aturner $
-Copyright (c) 2001-2010 Aaron Turner.  aturner at synfin dot net
-All rights reserved.
-
-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 names of the copyright owners nor the names of its
-   contributors may be used to endorse or promote products derived from
-   this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED ``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 AUTHORS OR COPYRIGHT HOLDERS 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.
-
-This product includes software developed by the University of California,
-Berkeley, Lawrence Berkeley Laboratory and its contributors.
+Please note that this license covers the files that I have written.
+Some files distributed with the Tcpreplay Suite are copyrighted by 
+other authors and have a different license.  These files & directories
+are marked as such.  If you have questions about the licensing that
+applies to various Tcpreplay files or modules, please contact the 
+author: Aaron Turner.
+
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.

+ 10 - 3
docs/Makefile.am

@@ -5,7 +5,7 @@ MAKEFLAGS=-s
 docs: clean-docs manpages
 
 web/tcpreplay.html:
-	@GROFF@ -Thtml -mman ../src/tcpreplay.1 > web/tcpreplay.html
+	mkdir -p web; @GROFF@ -Thtml -mman ../src/tcpreplay.1 > web/tcpreplay.html
 
 web/tcpprep.html:
 	@GROFF@ -Thtml -mman ../src/tcpprep.1 > web/tcpprep.html
@@ -19,11 +19,18 @@ web/tcpbridge.html:
 web/tcpreplay-edit.html:
 	@GROFF@ -Thtml -mman ../src/tcpreplay-edit.1 > web/tcpreplay-edit.html
 
+web/tcpliveplay.html:
+	@GROFF@ -Thtml -mman ../src/tcpliveplay.1 > web/tcpliveplay.html
+
+web/tcpcapinfo.html:
+	@GROFF@ -Thtml -mman ../src/tcpcapinfo.1 > web/tcpcapinfo.html
+
 manpages: web/tcpreplay.html web/tcpprep.html web/tcprewrite.html \
-    web/tcpbridge.html web/tcpreplay-edit.html
+    web/tcpbridge.html web/tcpreplay-edit.html web/tcpliveplay.html \
+    web/tcpcapinfo.html
 
 postweb: manpages
-	rsync -qe ssh --exclude '.svn/' --exclude '/**/.svn/' --exclude '/**~' \
+	rsync -qe ssh --exclude '.git/' --exclude '/**/.git/' --exclude '/**~' \
 	--exclude '*~' -avz web/ \
 	aturner@malbec.synfin.net:/var/vhosts/tcpreplay/
 	scp CHANGELOG TODO aturner@malbec.synfin.net:/var/vhosts/tcpreplay/

+ 130 - 32
docs/Makefile.in

@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -15,6 +14,51 @@
 
 @SET_MAKE@
 VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -35,21 +79,44 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 subdir = docs
-DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in INSTALL TODO
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am INSTALL TODO
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \
-	$(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
+	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+	$(top_srcdir)/libopts/m4/libopts.m4 \
+	$(top_srcdir)/libopts/m4/stdnoreturn.m4 \
+	$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
+mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/src/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
 SOURCES =
 DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 AR = @AR@
 AUTOCONF = @AUTOCONF@
 AUTOGEN = @AUTOGEN@
@@ -61,6 +128,8 @@ CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CROSS_ARCH = @CROSS_ARCH@
+CROSS_LD = @CROSS_LD@
 CUT = @CUT@
 CXX = @CXX@
 CXXCPP = @CXXCPP@
@@ -69,6 +138,7 @@ CXXFLAGS = @CXXFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
 DMALLOC_LIB = @DMALLOC_LIB@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
@@ -103,9 +173,15 @@ LN_S = @LN_S@
 LPCAPINC = @LPCAPINC@
 LPCAPLIB = @LPCAPLIB@
 LTLIBOBJS = @LTLIBOBJS@
+MACOSX_SDK_PATH = @MACOSX_SDK_PATH@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MKDIR_P = @MKDIR_P@
+NETMAPFLAGS = @NETMAPFLAGS@
+NETMAPINC = @NETMAPINC@
+NETMAPINCDIR = @NETMAPINCDIR@
+NETMAPUSERINC = @NETMAPUSERINC@
 NM = @NM@
 NMEDIT = @NMEDIT@
 OBJDUMP = @OBJDUMP@
@@ -121,11 +197,14 @@ PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 PCAP_BPF_H_FILE = @PCAP_BPF_H_FILE@
+PCAP_CONFIG = @PCAP_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
 PRINTF = @PRINTF@
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STDNORETURN_H = @STDNORETURN_H@
 STRIP = @STRIP@
 TCPREPLAY_RELEASE = @TCPREPLAY_RELEASE@
 TCPREPLAY_VERSION = @TCPREPLAY_VERSION@
@@ -134,6 +213,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_CXX = @ac_ct_CXX@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
@@ -152,9 +232,12 @@ builddir = @builddir@
 datadir = @datadir@
 datarootdir = @datarootdir@
 debug_flag = @debug_flag@
+debug_run_time_flag = @debug_run_time_flag@
+depmod = @depmod@
 docdir = @docdir@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+extra_debug_flag = @extra_debug_flag@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -163,12 +246,12 @@ host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
 infodir = @infodir@
+insmod = @insmod@
 install_sh = @install_sh@
 libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 nic1 = @nic1@
@@ -179,6 +262,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+rmmod = @rmmod@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -189,6 +273,7 @@ target_cpu = @target_cpu@
 target_os = @target_os@
 target_vendor = @target_vendor@
 tcpdump_path = @tcpdump_path@
+timestamp_trace_flag = @timestamp_trace_flag@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
@@ -207,9 +292,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu docs/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign docs/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu docs/Makefile
+	  $(AUTOMAKE) --foreign docs/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
@@ -234,11 +319,11 @@ mostlyclean-libtool:
 
 clean-libtool:
 	-rm -rf .libs _libs
-tags: TAGS
-TAGS:
+tags TAGS:
+
+ctags CTAGS:
 
-ctags: CTAGS
-CTAGS:
+cscope cscopelist:
 
 
 distdir: $(DISTFILES)
@@ -285,10 +370,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
 mostlyclean-generic:
 
 clean-generic:
@@ -371,16 +461,17 @@ uninstall-am:
 .MAKE: install-am install-strip
 
 .PHONY: all all-am check check-am clean clean-generic clean-libtool \
-	distclean distclean-generic distclean-libtool distdir dvi \
-	dvi-am html html-am info info-am install install-am \
-	install-data install-data-am install-dvi install-dvi-am \
-	install-exec install-exec-am install-html install-html-am \
-	install-info install-info-am install-man install-pdf \
-	install-pdf-am install-ps install-ps-am install-strip \
-	installcheck installcheck-am installdirs maintainer-clean \
-	maintainer-clean-generic maintainer-clean-local mostlyclean \
-	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
-	uninstall uninstall-am
+	cscopelist-am ctags-am distclean distclean-generic \
+	distclean-libtool distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic \
+	maintainer-clean-local mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags-am uninstall \
+	uninstall-am
 
 
 .PHONY: manpages
@@ -388,7 +479,7 @@ uninstall-am:
 docs: clean-docs manpages
 
 web/tcpreplay.html:
-	@GROFF@ -Thtml -mman ../src/tcpreplay.1 > web/tcpreplay.html
+	mkdir -p web; @GROFF@ -Thtml -mman ../src/tcpreplay.1 > web/tcpreplay.html
 
 web/tcpprep.html:
 	@GROFF@ -Thtml -mman ../src/tcpprep.1 > web/tcpprep.html
@@ -402,11 +493,18 @@ web/tcpbridge.html:
 web/tcpreplay-edit.html:
 	@GROFF@ -Thtml -mman ../src/tcpreplay-edit.1 > web/tcpreplay-edit.html
 
+web/tcpliveplay.html:
+	@GROFF@ -Thtml -mman ../src/tcpliveplay.1 > web/tcpliveplay.html
+
+web/tcpcapinfo.html:
+	@GROFF@ -Thtml -mman ../src/tcpcapinfo.1 > web/tcpcapinfo.html
+
 manpages: web/tcpreplay.html web/tcpprep.html web/tcprewrite.html \
-    web/tcpbridge.html web/tcpreplay-edit.html
+    web/tcpbridge.html web/tcpreplay-edit.html web/tcpliveplay.html \
+    web/tcpcapinfo.html
 
 postweb: manpages
-	rsync -qe ssh --exclude '.svn/' --exclude '/**/.svn/' --exclude '/**~' \
+	rsync -qe ssh --exclude '.git/' --exclude '/**/.git/' --exclude '/**~' \
 	--exclude '*~' -avz web/ \
 	aturner@malbec.synfin.net:/var/vhosts/tcpreplay/
 	scp CHANGELOG TODO aturner@malbec.synfin.net:/var/vhosts/tcpreplay/

+ 2 - 2
docs/TODO

@@ -1,7 +1,7 @@
 This is a general list of things which should/could/may be done.
-If any of these features interest you let me know- especially if you're
+If any of these features interest you let us know- especially if you're
 willing and able to help code it.  In general, higher priority tasks are
-tracked on the tcpreplay website: http://tcpreplay.synfin.net/
+tracked on the tcpreplay GitHub wiki https://github.com/appneta/tcpreplay/wiki
 
 Legend:
     - = Not started

+ 1 - 1
docs/Win32Readme.txt

@@ -1,4 +1,4 @@
-$Id: Win32Readme.txt 2102 2009-01-04 22:52:51Z aturner $
+$Id$
 This document attempts to explain how to get tcpreplay compiled and running
 under Windows.  Please note that this document is a work in progress and
 Windows support in general considered EXPERIMENTAL right now.

+ 16 - 4
doxygen.cfg.in

@@ -33,7 +33,7 @@ PROJECT_NAME           = TCPREPLAY
 # This could be handy for archiving the generated documentation or 
 # if some version control system is used.
 
-PROJECT_NUMBER         = @TCPREPLAY_VERSION@
+PROJECT_NUMBER         = @VERSION@
 
 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
 # base path where the generated documentation will be put. 
@@ -462,7 +462,19 @@ libopts/autoopts \
 src \
 src/common \
 src/tcpedit \
-src/flow 
+src/tcpedit/plugins \
+src/tcpedit/plugins/dlt_en10mb \
+src/tcpedit/plugins/dlt_hdlc \
+src/tcpedit/plugins/dlt_ieee80211 \
+src/tcpedit/plugins/dlt_jnpr_ether \
+src/tcpedit/plugins/dlt_linuxsll \
+src/tcpedit/plugins/dlt_loop \
+src/tcpedit/plugins/dlt_null \
+src/tcpedit/plugins/dlt_radiotap \
+src/tcpedit/plugins/dlt_raw \
+src/tcpedit/plugins/dlt_user \
+src/gui \
+src/fragroute
 
 # If the value of the INPUT tag contains directories, you can use the 
 # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
@@ -495,7 +507,7 @@ EXCLUDE_SYMLINKS       = NO
 # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 
 # certain files from those directories.
 
-EXCLUDE_PATTERNS       = 
+EXCLUDE_PATTERNS       = .git
 
 # The EXAMPLE_PATH tag can be used to specify one or more files or 
 # directories that contain example code fragments that are included (see 
@@ -568,7 +580,7 @@ INLINE_SOURCES         = NO
 # doxygen to hide any special comment blocks from generated source code 
 # fragments. Normal C and C++ comments will always remain visible.
 
-STRIP_CODE_COMMENTS    = YES
+STRIP_CODE_COMMENTS    = NO
 
 # If the REFERENCED_BY_RELATION tag is set to YES (the default) 
 # then for each documented function all documented 

+ 2 - 1
lib/Makefile.am

@@ -1,6 +1,7 @@
+if ! SYSTEM_STRLCPY
 noinst_LIBRARIES = libstrl.a
-
 libstrl_a_SOURCES = strlcat.c strlcpy.c
+endif
 
 noinst_HEADERS = strlcpy.h tree.h queue.h sll.h
 

+ 208 - 81
lib/Makefile.in

@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -17,6 +16,51 @@
 
 
 VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -37,44 +81,102 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 subdir = lib
-DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
-	$(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/config/depcomp $(noinst_HEADERS)
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \
-	$(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
+	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+	$(top_srcdir)/libopts/m4/libopts.m4 \
+	$(top_srcdir)/libopts/m4/stdnoreturn.m4 \
+	$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
+mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/src/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 LIBRARIES = $(noinst_LIBRARIES)
 ARFLAGS = cru
+AM_V_AR = $(am__v_AR_@AM_V@)
+am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@)
+am__v_AR_0 = @echo "  AR      " $@;
+am__v_AR_1 = 
 libstrl_a_AR = $(AR) $(ARFLAGS)
 libstrl_a_LIBADD =
-am_libstrl_a_OBJECTS = strlcat.$(OBJEXT) strlcpy.$(OBJEXT)
+am__libstrl_a_SOURCES_DIST = strlcat.c strlcpy.c
+@SYSTEM_STRLCPY_FALSE@am_libstrl_a_OBJECTS = strlcat.$(OBJEXT) \
+@SYSTEM_STRLCPY_FALSE@	strlcpy.$(OBJEXT)
 libstrl_a_OBJECTS = $(am_libstrl_a_OBJECTS)
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 = 
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+	$(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC      " $@;
+am__v_CC_1 = 
 CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
-	$(LDFLAGS) -o $@
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD    " $@;
+am__v_CCLD_1 = 
 SOURCES = $(libstrl_a_SOURCES)
-DIST_SOURCES = $(libstrl_a_SOURCES)
+DIST_SOURCES = $(am__libstrl_a_SOURCES_DIST)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 HEADERS = $(noinst_HEADERS)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates.  Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+  BEGIN { nonempty = 0; } \
+  { items[$$0] = 1; nonempty = 1; } \
+  END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique.  This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+  list='$(am__tagged_files)'; \
+  unique=`for i in $$list; do \
+    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+  done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 AR = @AR@
 AUTOCONF = @AUTOCONF@
 AUTOGEN = @AUTOGEN@
@@ -86,6 +188,8 @@ CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CROSS_ARCH = @CROSS_ARCH@
+CROSS_LD = @CROSS_LD@
 CUT = @CUT@
 CXX = @CXX@
 CXXCPP = @CXXCPP@
@@ -94,6 +198,7 @@ CXXFLAGS = @CXXFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
 DMALLOC_LIB = @DMALLOC_LIB@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
@@ -128,9 +233,15 @@ LN_S = @LN_S@
 LPCAPINC = @LPCAPINC@
 LPCAPLIB = @LPCAPLIB@
 LTLIBOBJS = @LTLIBOBJS@
+MACOSX_SDK_PATH = @MACOSX_SDK_PATH@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MKDIR_P = @MKDIR_P@
+NETMAPFLAGS = @NETMAPFLAGS@
+NETMAPINC = @NETMAPINC@
+NETMAPINCDIR = @NETMAPINCDIR@
+NETMAPUSERINC = @NETMAPUSERINC@
 NM = @NM@
 NMEDIT = @NMEDIT@
 OBJDUMP = @OBJDUMP@
@@ -146,11 +257,14 @@ PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 PCAP_BPF_H_FILE = @PCAP_BPF_H_FILE@
+PCAP_CONFIG = @PCAP_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
 PRINTF = @PRINTF@
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STDNORETURN_H = @STDNORETURN_H@
 STRIP = @STRIP@
 TCPREPLAY_RELEASE = @TCPREPLAY_RELEASE@
 TCPREPLAY_VERSION = @TCPREPLAY_VERSION@
@@ -159,6 +273,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_CXX = @ac_ct_CXX@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
@@ -177,9 +292,12 @@ builddir = @builddir@
 datadir = @datadir@
 datarootdir = @datarootdir@
 debug_flag = @debug_flag@
+debug_run_time_flag = @debug_run_time_flag@
+depmod = @depmod@
 docdir = @docdir@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+extra_debug_flag = @extra_debug_flag@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -188,12 +306,12 @@ host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
 infodir = @infodir@
+insmod = @insmod@
 install_sh = @install_sh@
 libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 nic1 = @nic1@
@@ -204,6 +322,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+rmmod = @rmmod@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -214,11 +333,12 @@ target_cpu = @target_cpu@
 target_os = @target_os@
 target_vendor = @target_vendor@
 tcpdump_path = @tcpdump_path@
+timestamp_trace_flag = @timestamp_trace_flag@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-noinst_LIBRARIES = libstrl.a
-libstrl_a_SOURCES = strlcat.c strlcpy.c
+@SYSTEM_STRLCPY_FALSE@noinst_LIBRARIES = libstrl.a
+@SYSTEM_STRLCPY_FALSE@libstrl_a_SOURCES = strlcat.c strlcpy.c
 noinst_HEADERS = strlcpy.h tree.h queue.h sll.h
 MOSTLYCLEANFILES = *~ *.o *.a
 MAINTAINERCLEANFILES = Makefile.in
@@ -235,9 +355,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu lib/Makefile
+	  $(AUTOMAKE) --foreign lib/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
@@ -259,10 +379,11 @@ $(am__aclocal_m4_deps):
 
 clean-noinstLIBRARIES:
 	-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
-libstrl.a: $(libstrl_a_OBJECTS) $(libstrl_a_DEPENDENCIES) 
-	-rm -f libstrl.a
-	$(libstrl_a_AR) libstrl.a $(libstrl_a_OBJECTS) $(libstrl_a_LIBADD)
-	$(RANLIB) libstrl.a
+
+libstrl.a: $(libstrl_a_OBJECTS) $(libstrl_a_DEPENDENCIES) $(EXTRA_libstrl_a_DEPENDENCIES) 
+	$(AM_V_at)-rm -f libstrl.a
+	$(AM_V_AR)$(libstrl_a_AR) libstrl.a $(libstrl_a_OBJECTS) $(libstrl_a_LIBADD)
+	$(AM_V_at)$(RANLIB) libstrl.a
 
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
@@ -274,25 +395,25 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcpy.Po@am__quote@
 
 .c.o:
-@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
 
 .c.obj:
-@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
 .c.lo:
-@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 mostlyclean-libtool:
 	-rm -f *.lo
@@ -300,26 +421,15 @@ mostlyclean-libtool:
 clean-libtool:
 	-rm -rf .libs _libs
 
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
-	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	mkid -fID $$unique
-tags: TAGS
-
-TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
+ID: $(am__tagged_files)
+	$(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
 	set x; \
 	here=`pwd`; \
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	$(am__define_uniq_tagged_files); \
 	shift; \
 	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
 	  test -n "$$unique" || unique=$$empty_fix; \
@@ -331,15 +441,11 @@ TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
 	      $$unique; \
 	  fi; \
 	fi
-ctags: CTAGS
-CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	$(am__define_uniq_tagged_files); \
 	test -z "$(CTAGS_ARGS)$$unique" \
 	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
 	     $$unique
@@ -348,6 +454,21 @@ GTAGS:
 	here=`$(am__cd) $(top_builddir) && pwd` \
 	  && $(am__cd) $(top_srcdir) \
 	  && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+	list='$(am__tagged_files)'; \
+	case "$(srcdir)" in \
+	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+	  *) sdir=$(subdir)/$(srcdir) ;; \
+	esac; \
+	for i in $$list; do \
+	  if test -f "$$i"; then \
+	    echo "$(subdir)/$$i"; \
+	  else \
+	    echo "$$sdir/$$i"; \
+	  fi; \
+	done >> $(top_builddir)/cscope.files
 
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -396,10 +517,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
 mostlyclean-generic:
 	-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
 
@@ -486,18 +612,19 @@ uninstall-am:
 
 .MAKE: install-am install-strip
 
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
-	clean-libtool clean-noinstLIBRARIES ctags distclean \
-	distclean-compile distclean-generic distclean-libtool \
-	distclean-tags distdir dvi dvi-am html html-am info info-am \
-	install install-am install-data install-data-am install-dvi \
-	install-dvi-am install-exec install-exec-am install-html \
-	install-html-am install-info install-info-am install-man \
-	install-pdf install-pdf-am install-ps install-ps-am \
-	install-strip installcheck installcheck-am installdirs \
-	maintainer-clean maintainer-clean-generic mostlyclean \
-	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
-	pdf pdf-am ps ps-am tags uninstall uninstall-am
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
+	clean-libtool clean-noinstLIBRARIES cscopelist-am ctags \
+	ctags-am distclean distclean-compile distclean-generic \
+	distclean-libtool distclean-tags distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags tags-am uninstall uninstall-am
 
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.

+ 8 - 0
lib/queue.h

@@ -334,6 +334,14 @@ struct {								\
 	(head)->tqh_last = &(head)->tqh_first;				\
 } while (0)
 
+#define TAILQ_COPY(dst, src, field) do {						\
+	*(dst) = *(src);											\
+	if (((dst)->tqh_first) != NULL)								\
+		(dst)->tqh_first->field.tqe_prev = &(dst)->tqh_first;	\
+	else														\
+		(dst)->tqh_last = &(dst)->tqh_first;					\
+} while (0)
+
 #define TAILQ_INSERT_HEAD(head, elm, field) do {			\
 	if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)	\
 		(head)->tqh_first->field.tqe_prev =			\

+ 0 - 9
lib/sll.h

@@ -128,12 +128,3 @@ struct sll_header {
 #define LINUX_SLL_P_802_2	0x0004  /* 802.2 frames (not D/I/X Ethernet) */
 
 #endif
-
-/*
- Local Variables:
- mode:c
- indent-tabs-mode:nil
- c-basic-offset:4
- End:
-*/
-

+ 27 - 0
lib/strlcpy.h

@@ -1,8 +1,31 @@
+/*
+ *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
+ *   Copyright (c) 2013-2017 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
+ *
+ *   The Tcpreplay Suite of tools is free software: you can redistribute it 
+ *   and/or modify it under the terms of the GNU General Public License as 
+ *   published by the Free Software Foundation, either version 3 of the 
+ *   License, or with the authors permission any later version.
+ *
+ *   The Tcpreplay Suite is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef _STRLCPY_H_
 #define _STRLCPY_H_
 
 #include <sys/types.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 size_t
 strlcpy(char *dst, const char *src, size_t size);
 
@@ -10,3 +33,7 @@ size_t
 strlcat(char *dst, const char *src, size_t size);
 
 #endif
+#ifdef __cplusplus
+}
+#endif
+

+ 3 - 3
libopts/COPYING.gplv3

@@ -1,7 +1,7 @@
                     GNU GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
- copyright (c) 2009 by Bruce Korb - all rights reserved
+ Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
@@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
 the "copyright" line and a pointer to where the full notice is found.
 
     <one line to give the program's name and a brief idea of what it does.>
-    copyright (c) by Bruce Korb - all rights reserved
+    Copyright (C) by Bruce Korb - all rights reserved
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
   If the program does terminal interaction, make it output a short
 notice like this when it starts in an interactive mode:
 
-    <program>  copyright (c)  by Bruce Korb - all rights reserved
+    <program>  Copyright (C)  by Bruce Korb - all rights reserved
     This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
     This is free software, and you are welcome to redistribute it
     under certain conditions; type `show c' for details.

+ 1 - 1
libopts/COPYING.lgplv3

@@ -1,7 +1,7 @@
 		   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
- copyright (c) 2009 by Bruce Korb - all rights reserved
+ Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 

+ 47 - 15
libopts/Makefile.am

@@ -6,23 +6,55 @@ else
 noinst_LTLIBRARIES      = libopts.la
 endif
 libopts_la_SOURCES      = libopts.c
-libopts_la_CPPFLAGS     = -I$(top_srcdir)
-libopts_la_LDFLAGS      = -version-info  32:2:7
-EXTRA_DIST              = \
+libopts_la_CPPFLAGS     = -I$(srcdir)
+libopts_la_LDFLAGS      = -version-info  41:0:16
+EXTRA_DIST		=
+BUILT_SOURCES		=
+MOSTLYCLEANFILES	=
+
+libopts.c:		$(BUILT_SOURCES)
+	@: do-nothing rule to avoid default SCCS get
+
+
+# Makefile fragment from gnulib-s stdnoreturn module:
+#
+_NORETURN_H=$(srcdir)/compat/_Noreturn.h
+EXTRA_DIST += $(srcdir)/compat/_Noreturn.h
+BUILT_SOURCES += $(STDNORETURN_H)
+if GL_GENERATE_STDNORETURN_H
+stdnoreturn.h: stdnoreturn.in.h $(top_builddir)/config.status $(_NORETURN_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+	  sed -e '/definition of _Noreturn/r $(_NORETURN_H)' \
+              < $(srcdir)/stdnoreturn.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+else
+stdnoreturn.h: $(top_builddir)/config.status
+	rm -f $@
+endif
+MOSTLYCLEANFILES += stdnoreturn.h stdnoreturn.h-t
+EXTRA_DIST += stdnoreturn.in.h
+
+EXTRA_DIST += \
     COPYING.gplv3           COPYING.lgplv3          COPYING.mbsd  \
     MakeDefs.inc            README                  ag-char-map.h  \
-    autoopts/options.h      autoopts/usage-txt.h    autoopts.c  \
-    autoopts.h              boolean.c               compat/compat.h  \
-    compat/pathfind.c       compat/snprintf.c       compat/strchr.c  \
-    compat/strdup.c         compat/windows-config.h configfile.c  \
-    cook.c                  enumeration.c           environment.c  \
-    file.c                  genshell.c              genshell.h  \
-    load.c                  m4/libopts.m4           m4/liboptschk.m4  \
-    makeshell.c             nested.c                numeric.c  \
+    alias.c                 ao-strs.c               ao-strs.h  \
+    autoopts/options.h      autoopts/project.h      autoopts/usage-txt.h  \
+    autoopts.c              autoopts.h              boolean.c  \
+    check.c                 compat/strdup.c         compat/snprintf.c  \
+    compat/compat.h         compat/_Noreturn.h      compat/pathfind.c  \
+    compat/windows-config.h compat/strchr.c         configfile.c  \
+    cook.c                  enum.c                  env.c  \
+    file.c                  find.c                  genshell.c  \
+    genshell.h              gettext.h               init.c  \
+    intprops.h              load.c                  m4/libopts.m4  \
+    m4/liboptschk.m4        m4/stdnoreturn.m4       makeshell.c  \
+    nested.c                numeric.c               option-value-type.c  \
+    option-value-type.h     option-xat-attribute.c  option-xat-attribute.h  \
     parse-duration.c        parse-duration.h        pgusage.c  \
     proto.h                 putshell.c              reset.c  \
     restore.c               save.c                  sort.c  \
-    stack.c                 streqvcmp.c             text_mmap.c  \
-    time.c                  tokenize.c              usage.c  \
-    value-type.c            value-type.h            version.c  \
-    xat-attribute.c         xat-attribute.h
+    stack.c                 stdnoreturn.in.h        streqvcmp.c  \
+    text_mmap.c             time.c                  tokenize.c  \
+    usage.c                 version.c

+ 271 - 118
libopts/Makefile.in

@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -16,6 +15,51 @@
 @SET_MAKE@
 
 VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -36,13 +80,18 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 subdir = libopts
-DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+	$(top_srcdir)/config/depcomp README
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \
-	$(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
+	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+	$(top_srcdir)/libopts/m4/libopts.m4 \
+	$(top_srcdir)/libopts/m4/stdnoreturn.m4 \
+	$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
-mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
+mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/src/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
@@ -67,36 +116,90 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
 libopts_la_LIBADD =
 am_libopts_la_OBJECTS = libopts_la-libopts.lo
 libopts_la_OBJECTS = $(am_libopts_la_OBJECTS)
-libopts_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 = 
+libopts_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
 	$(libopts_la_LDFLAGS) $(LDFLAGS) -o $@
 @INSTALL_LIBOPTS_FALSE@am_libopts_la_rpath =
 @INSTALL_LIBOPTS_TRUE@am_libopts_la_rpath = -rpath $(libdir)
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+	$(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC      " $@;
+am__v_CC_1 = 
 CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
-	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
-	$(LDFLAGS) -o $@
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD    " $@;
+am__v_CCLD_1 = 
 SOURCES = $(libopts_la_SOURCES)
 DIST_SOURCES = $(libopts_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates.  Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+  BEGIN { nonempty = 0; } \
+  { items[$$0] = 1; nonempty = 1; } \
+  END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique.  This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+  list='$(am__tagged_files)'; \
+  unique=`for i in $$list; do \
+    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+  done | $(am__uniquify_input)`
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
 AR = @AR@
 AUTOCONF = @AUTOCONF@
 AUTOGEN = @AUTOGEN@
@@ -108,6 +211,8 @@ CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
+CROSS_ARCH = @CROSS_ARCH@
+CROSS_LD = @CROSS_LD@
 CUT = @CUT@
 CXX = @CXX@
 CXXCPP = @CXXCPP@
@@ -116,6 +221,7 @@ CXXFLAGS = @CXXFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
 DMALLOC_LIB = @DMALLOC_LIB@
 DSYMUTIL = @DSYMUTIL@
 DUMPBIN = @DUMPBIN@
@@ -150,9 +256,15 @@ LN_S = @LN_S@
 LPCAPINC = @LPCAPINC@
 LPCAPLIB = @LPCAPLIB@
 LTLIBOBJS = @LTLIBOBJS@
+MACOSX_SDK_PATH = @MACOSX_SDK_PATH@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MKDIR_P = @MKDIR_P@
+NETMAPFLAGS = @NETMAPFLAGS@
+NETMAPINC = @NETMAPINC@
+NETMAPINCDIR = @NETMAPINCDIR@
+NETMAPUSERINC = @NETMAPUSERINC@
 NM = @NM@
 NMEDIT = @NMEDIT@
 OBJDUMP = @OBJDUMP@
@@ -168,11 +280,14 @@ PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 PCAP_BPF_H_FILE = @PCAP_BPF_H_FILE@
+PCAP_CONFIG = @PCAP_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
 PRINTF = @PRINTF@
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STDNORETURN_H = @STDNORETURN_H@
 STRIP = @STRIP@
 TCPREPLAY_RELEASE = @TCPREPLAY_RELEASE@
 TCPREPLAY_VERSION = @TCPREPLAY_VERSION@
@@ -181,6 +296,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_CXX = @ac_ct_CXX@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
@@ -199,9 +315,12 @@ builddir = @builddir@
 datadir = @datadir@
 datarootdir = @datarootdir@
 debug_flag = @debug_flag@
+debug_run_time_flag = @debug_run_time_flag@
+depmod = @depmod@
 docdir = @docdir@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+extra_debug_flag = @extra_debug_flag@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -210,12 +329,12 @@ host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
 infodir = @infodir@
+insmod = @insmod@
 install_sh = @install_sh@
 libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 nic1 = @nic1@
@@ -226,6 +345,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+rmmod = @rmmod@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -236,6 +356,7 @@ target_cpu = @target_cpu@
 target_os = @target_os@
 target_vendor = @target_vendor@
 tcpdump_path = @tcpdump_path@
+timestamp_trace_flag = @timestamp_trace_flag@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
@@ -243,28 +364,31 @@ MAINTAINERCLEANFILES = Makefile.in
 @INSTALL_LIBOPTS_TRUE@lib_LTLIBRARIES = libopts.la
 @INSTALL_LIBOPTS_FALSE@noinst_LTLIBRARIES = libopts.la
 libopts_la_SOURCES = libopts.c
-libopts_la_CPPFLAGS = -I$(top_srcdir)
-libopts_la_LDFLAGS = -version-info  32:2:7
-EXTRA_DIST = \
-    COPYING.gplv3           COPYING.lgplv3          COPYING.mbsd  \
-    MakeDefs.inc            README                  ag-char-map.h  \
-    autoopts/options.h      autoopts/usage-txt.h    autoopts.c  \
-    autoopts.h              boolean.c               compat/compat.h  \
-    compat/pathfind.c       compat/snprintf.c       compat/strchr.c  \
-    compat/strdup.c         compat/windows-config.h configfile.c  \
-    cook.c                  enumeration.c           environment.c  \
-    file.c                  genshell.c              genshell.h  \
-    load.c                  m4/libopts.m4           m4/liboptschk.m4  \
-    makeshell.c             nested.c                numeric.c  \
-    parse-duration.c        parse-duration.h        pgusage.c  \
-    proto.h                 putshell.c              reset.c  \
-    restore.c               save.c                  sort.c  \
-    stack.c                 streqvcmp.c             text_mmap.c  \
-    time.c                  tokenize.c              usage.c  \
-    value-type.c            value-type.h            version.c  \
-    xat-attribute.c         xat-attribute.h
-
-all: all-am
+libopts_la_CPPFLAGS = -I$(srcdir)
+libopts_la_LDFLAGS = -version-info  41:0:16
+EXTRA_DIST = $(srcdir)/compat/_Noreturn.h stdnoreturn.in.h \
+	COPYING.gplv3 COPYING.lgplv3 COPYING.mbsd MakeDefs.inc README \
+	ag-char-map.h alias.c ao-strs.c ao-strs.h autoopts/options.h \
+	autoopts/project.h autoopts/usage-txt.h autoopts.c autoopts.h \
+	boolean.c check.c compat/strdup.c compat/snprintf.c \
+	compat/compat.h compat/_Noreturn.h compat/pathfind.c \
+	compat/windows-config.h compat/strchr.c configfile.c cook.c \
+	enum.c env.c file.c find.c genshell.c genshell.h gettext.h \
+	init.c intprops.h load.c m4/libopts.m4 m4/liboptschk.m4 \
+	m4/stdnoreturn.m4 makeshell.c nested.c numeric.c \
+	option-value-type.c option-value-type.h option-xat-attribute.c \
+	option-xat-attribute.h parse-duration.c parse-duration.h \
+	pgusage.c proto.h putshell.c reset.c restore.c save.c sort.c \
+	stack.c stdnoreturn.in.h streqvcmp.c text_mmap.c time.c \
+	tokenize.c usage.c version.c
+BUILT_SOURCES = $(STDNORETURN_H)
+MOSTLYCLEANFILES = stdnoreturn.h stdnoreturn.h-t
+
+# Makefile fragment from gnulib-s stdnoreturn module:
+#
+_NORETURN_H = $(srcdir)/compat/_Noreturn.h
+all: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) all-am
 
 .SUFFIXES:
 .SUFFIXES: .c .lo .o .obj
@@ -277,9 +401,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__confi
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libopts/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libopts/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu libopts/Makefile
+	  $(AUTOMAKE) --foreign libopts/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
@@ -298,9 +422,9 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
 $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
+
 install-libLTLIBRARIES: $(lib_LTLIBRARIES)
 	@$(NORMAL_INSTALL)
-	test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
 	@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
 	list2=; for p in $$list; do \
 	  if test -f $$p; then \
@@ -308,6 +432,8 @@ install-libLTLIBRARIES: $(lib_LTLIBRARIES)
 	  else :; fi; \
 	done; \
 	test -z "$$list2" || { \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
 	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
 	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
 	}
@@ -323,23 +449,28 @@ uninstall-libLTLIBRARIES:
 
 clean-libLTLIBRARIES:
 	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
-	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
-	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
-	  test "$$dir" != "$$p" || dir=.; \
-	  echo "rm -f \"$${dir}/so_locations\""; \
-	  rm -f "$${dir}/so_locations"; \
-	done
+	@list='$(lib_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
 
 clean-noinstLTLIBRARIES:
 	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
-	@list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
-	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
-	  test "$$dir" != "$$p" || dir=.; \
-	  echo "rm -f \"$${dir}/so_locations\""; \
-	  rm -f "$${dir}/so_locations"; \
-	done
-libopts.la: $(libopts_la_OBJECTS) $(libopts_la_DEPENDENCIES) 
-	$(libopts_la_LINK) $(am_libopts_la_rpath) $(libopts_la_OBJECTS) $(libopts_la_LIBADD) $(LIBS)
+	@list='$(noinst_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+
+libopts.la: $(libopts_la_OBJECTS) $(libopts_la_DEPENDENCIES) $(EXTRA_libopts_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(libopts_la_LINK) $(am_libopts_la_rpath) $(libopts_la_OBJECTS) $(libopts_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
@@ -350,32 +481,32 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libopts_la-libopts.Plo@am__quote@
 
 .c.o:
-@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
 
 .c.obj:
-@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
 .c.lo:
-@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 libopts_la-libopts.lo: libopts.c
-@am__fastdepCC_TRUE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libopts_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libopts_la-libopts.lo -MD -MP -MF $(DEPDIR)/libopts_la-libopts.Tpo -c -o libopts_la-libopts.lo `test -f 'libopts.c' || echo '$(srcdir)/'`libopts.c
-@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/libopts_la-libopts.Tpo $(DEPDIR)/libopts_la-libopts.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='libopts.c' object='libopts_la-libopts.lo' libtool=yes @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libopts_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libopts_la-libopts.lo -MD -MP -MF $(DEPDIR)/libopts_la-libopts.Tpo -c -o libopts_la-libopts.lo `test -f 'libopts.c' || echo '$(srcdir)/'`libopts.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libopts_la-libopts.Tpo $(DEPDIR)/libopts_la-libopts.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libopts.c' object='libopts_la-libopts.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libopts_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libopts_la-libopts.lo `test -f 'libopts.c' || echo '$(srcdir)/'`libopts.c
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libopts_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libopts_la-libopts.lo `test -f 'libopts.c' || echo '$(srcdir)/'`libopts.c
 
 mostlyclean-libtool:
 	-rm -f *.lo
@@ -383,26 +514,15 @@ mostlyclean-libtool:
 clean-libtool:
 	-rm -rf .libs _libs
 
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
-	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	mkid -fID $$unique
-tags: TAGS
-
-TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
+ID: $(am__tagged_files)
+	$(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
 	set x; \
 	here=`pwd`; \
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	$(am__define_uniq_tagged_files); \
 	shift; \
 	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
 	  test -n "$$unique" || unique=$$empty_fix; \
@@ -414,15 +534,11 @@ TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
 	      $$unique; \
 	  fi; \
 	fi
-ctags: CTAGS
-CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	$(am__define_uniq_tagged_files); \
 	test -z "$(CTAGS_ARGS)$$unique" \
 	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
 	     $$unique
@@ -431,6 +547,21 @@ GTAGS:
 	here=`$(am__cd) $(top_builddir) && pwd` \
 	  && $(am__cd) $(top_srcdir) \
 	  && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+	list='$(am__tagged_files)'; \
+	case "$(srcdir)" in \
+	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+	  *) sdir=$(subdir)/$(srcdir) ;; \
+	esac; \
+	for i in $$list; do \
+	  if test -f "$$i"; then \
+	    echo "$(subdir)/$$i"; \
+	  else \
+	    echo "$$sdir/$$i"; \
+	  fi; \
+	done >> $(top_builddir)/cscope.files
 
 distclean-tags:
 	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -466,13 +597,15 @@ distdir: $(DISTFILES)
 	  fi; \
 	done
 check-am: all-am
-check: check-am
+check: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) check-am
 all-am: Makefile $(LTLIBRARIES)
 installdirs:
 	for dir in "$(DESTDIR)$(libdir)"; do \
 	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 	done
-install: install-am
+install: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-am
 install-exec: install-exec-am
 install-data: install-data-am
 uninstall: uninstall-am
@@ -482,11 +615,17 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
 mostlyclean-generic:
+	-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
 
 clean-generic:
 
@@ -497,6 +636,7 @@ distclean-generic:
 maintainer-clean-generic:
 	@echo "This command is intended for maintainers to use"
 	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
 	-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
 clean: clean-am
 
@@ -569,22 +709,35 @@ ps-am:
 
 uninstall-am: uninstall-libLTLIBRARIES
 
-.MAKE: install-am install-strip
+.MAKE: all check install install-am install-strip
 
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
 	clean-libLTLIBRARIES clean-libtool clean-noinstLTLIBRARIES \
-	ctags distclean distclean-compile distclean-generic \
-	distclean-libtool distclean-tags distdir dvi dvi-am html \
-	html-am info info-am install install-am install-data \
-	install-data-am install-dvi install-dvi-am install-exec \
-	install-exec-am install-html install-html-am install-info \
-	install-info-am install-libLTLIBRARIES install-man install-pdf \
-	install-pdf-am install-ps install-ps-am install-strip \
-	installcheck installcheck-am installdirs maintainer-clean \
-	maintainer-clean-generic mostlyclean mostlyclean-compile \
-	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
-	tags uninstall uninstall-am uninstall-libLTLIBRARIES
-
+	cscopelist-am ctags ctags-am distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-libLTLIBRARIES \
+	install-man install-pdf install-pdf-am install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
+	uninstall-am uninstall-libLTLIBRARIES
+
+
+libopts.c:		$(BUILT_SOURCES)
+	@: do-nothing rule to avoid default SCCS get
+@GL_GENERATE_STDNORETURN_H_TRUE@stdnoreturn.h: stdnoreturn.in.h $(top_builddir)/config.status $(_NORETURN_H)
+@GL_GENERATE_STDNORETURN_H_TRUE@	$(AM_V_GEN)rm -f $@-t $@ && \
+@GL_GENERATE_STDNORETURN_H_TRUE@	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+@GL_GENERATE_STDNORETURN_H_TRUE@	  sed -e '/definition of _Noreturn/r $(_NORETURN_H)' \
+@GL_GENERATE_STDNORETURN_H_TRUE@              < $(srcdir)/stdnoreturn.in.h; \
+@GL_GENERATE_STDNORETURN_H_TRUE@	} > $@-t && \
+@GL_GENERATE_STDNORETURN_H_TRUE@	mv $@-t $@
+@GL_GENERATE_STDNORETURN_H_FALSE@stdnoreturn.h: $(top_builddir)/config.status
+@GL_GENERATE_STDNORETURN_H_FALSE@	rm -f $@
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.

+ 64 - 35
libopts/README

@@ -1,11 +1,11 @@
         THIS TARBALL IS NOT A FULL DISTRIBUTION.
 
 The contents of this tarball is designed to be incorporated into
-software packages that utilize the AutoOpts option automation
-package and are intended to be installed on systems that may not
-have libopts installed.  It is redistributable under the terms
-of either the LGPL (see COPYING.lgpl) or under the terms of
-the advertising clause free BSD license (see COPYING.mbsd).
+software packages that utilize the AutoOpts option automation package
+and are intended to be installed on systems that may not have libopts
+installed.  It is redistributable under the terms of either the LGPL
+(see COPYING.lgpl) or under the terms of the advertising clause free BSD
+license (see COPYING.mbsd).
 
 Usage Instructions for autoconf/automake/libtoolized projects:
 
@@ -28,20 +28,8 @@ Usage Instructions for autoconf/automake/libtoolized projects:
    This is one macro where you *MUST* remember to *NOT* quote
    the argument.  If you do, automake will get lost.
 
-2. Add the following to your ``configure.ac'' file:
-
-      LIBOPTS_CHECK
-
-   or:
-
-      LIBOPTS_CHECK([relative/path/to/libopts])
-
-   This macro will automatically invoke
-
-      AC_CONFIG_FILES( [relative/path/to/libopts/Makefile] )
-
-   The default ``relative/path/to/libopts'' is simply
-   ``libopts''.
+2. Add an invocation of either LIBOPTS_CHECK or LIBOPTS_CHECK_NOBUILD
+   to your configure.ac file.  See LIBOPTS_CHECK: below for details.
 
 3. Add the following to your top level ``Makefile.am'' file:
 
@@ -49,13 +37,13 @@ Usage Instructions for autoconf/automake/libtoolized projects:
          SUBDIRS += $(LIBOPTS_DIR)
       endif
 
-   where ``<...>'' can be whatever other files or directories
-   you may need.  The SUBDIRS must be properly ordered.
-   *PLEASE NOTE* it is crucial that the SUBDIRS be set under the
-   control of an automake conditional.  To work correctly,
-   automake has to know the range of possible values of SUBDIRS.
-   It's a magical name with magical properties.  ``NEED_LIBOPTS''
-   will be correctly set by the ``LIBOPTS_CHECK'' macro, above.
+   where ``<...>'' can be whatever other files or directories you may
+   need.  The SUBDIRS must be properly ordered.  *PLEASE NOTE* it is
+   crucial that the SUBDIRS be set under the control of an automake
+   conditional.  To work correctly, automake has to know the range of
+   possible values of SUBDIRS.  It's a magical name with magical
+   properties.  ``NEED_LIBOPTS'' will be correctly set by the
+   ``LIBOPTS_CHECK'' macro, above.
 
 4. Add ``$(LIBOPTS_CFLAGS)'' to relevant compiler flags and
    ``$(LIBOPTS_LDADD)'' to relevant link options whereever
@@ -75,19 +63,60 @@ Usage Instructions for autoconf/automake/libtoolized projects:
 
      man_MANS = prog.1
      prog.1 : prog-opts.def
-         autogen -Tagman1.tpl -bprog prog-opts.def
+         autogen -Tagman-cmd.tpl -bprog prog-opts.def
 
-     prog-invoke.texi : prog-opts.def
-         autogen -Taginfo.tpl -bprog-invoke prog-opts.def
+     invoke-prog.texi : prog-opts.def
+         autogen -Tagtexi-cmd.tpl prog-opts.def
 
 If your package does not utilize the auto* tools, then you
 will need to hand craft the rules for building the library.
 
+LIBOPTS_CHECK:
+
+The arguments to both macro are a relative path to the directory with
+the libopts source code.  It is optional and defaults to "libopts".
+These macros work as follows:
+
+1.  LIBOPTS_CHECK([libopts/rel/path/optional])
+
+    Adds two command-line options to the generated configure script,
+    --enable-local-libopts and --disable-libopts-install.  AC_SUBST's
+    LIBOPTS_CFLAGS, LIBOPTS_LDADD, and LIBOPTS_DIR for use in
+    Makefile.am files.  Adds Automake conditional NEED_LIBOPTS which
+    will be true when the local copy of libopts should be built.  Uses
+    AC_CONFIG_FILES([$libopts-dir/Makefile]) to cause the local libopts
+    into the package build.  If the optional relative path to libopts is
+    not provided, it defaults to simply "libopts".
+
+2.  LIBOPTS_CHECK_NOBUILD([libopts/rel/path/optional])
+
+    This variant of LIBOPTS_CHECK is useful when multiple configure.ac
+    files in a package make use of a single libopts tearoff.  In that
+    case, only one of the configure.ac files should build libopts and
+    others should simply use it.  Consider this package arrangment:
+
+    all-tools/
+      configure.ac
+      common-tools/
+        configure.ac
+        libopts/
+
+    The parent package all-tools contains a subpackage common-tools
+    which can be torn off and used independently.  Programs configured
+    by both configure.ac files link against the common-tools/libopts
+    tearoff, when not using the system's libopts.  The top-level
+    configure.ac uses LIBOPTS_CHECK_NOBUILD([common-tools/libopts]),
+    while common-tools/configure.ac uses LIBOPTS_CHECK.  The difference
+    is LIBOPTS_CHECK_NOBUILD will never build the libopts tearoff,
+    leaving that to the subpackage configure.ac's LIBOPTS_CHECK.
+    Specifically, LIBOPTS_CHECK_NOBUILD always results in the
+    NEED_LIBOPTS Automake conditional being false, and does not invoke
+    AC_CONFIG_FILES(path-to-libopts/Makefile).
+
 LICENSING:
 
-This material is copyright (c) 1993-2009 by Bruce Korb.
-You are licensed to use this under the terms of either
-the GNU Lesser General Public License (see: COPYING.lgpl), or,
-at your option, the modified Berkeley Software Distribution
-License (see:  COPYING.mbsd).  Both of these files should be
-included with this tarball.
+This material is Copyright (C) 1992-2014 by Bruce Korb.  You are
+licensed to use this under the terms of either the GNU Lesser General
+Public License (see: COPYING.lgpl), or, at your option, the modified
+Berkeley Software Distribution License (see: COPYING.mbsd).  Both of
+these files should be included with this tarball.

+ 487 - 121
libopts/ag-char-map.h

@@ -1,160 +1,526 @@
 /*
- *   Character mapping generated 08/08/09 10:14:55
+ *  29 bits for 46 character classifications
+ *  generated by char-mapper on 08/30/14 at 10:36:23
  *
  *  This file contains the character classifications
  *  used by AutoGen and AutoOpts for identifying tokens.
+ *  The table is static scope, so %guard is empty.
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *  The GNU Lesser General Public License, version 3 or later
+ *  See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *  The Modified Berkeley Software Distribution License
+ *  See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 #ifndef AG_CHAR_MAP_H_GUARD
 #define AG_CHAR_MAP_H_GUARD 1
 
 #ifdef HAVE_CONFIG_H
 # if defined(HAVE_INTTYPES_H)
-#  include <inttypes.h>
-# elif defined(HAVE_STDINT_H)
-#  include <stdint.h>
+#   include <inttypes.h>
 
-# else
-#   ifndef HAVE_INT8_T
-        typedef signed char     int8_t;
-#   endif
-#   ifndef HAVE_UINT8_T
-        typedef unsigned char   uint8_t;
-#   endif
-#   ifndef HAVE_INT16_T
-        typedef signed short    int16_t;
-#   endif
-#   ifndef HAVE_UINT16_T
-        typedef unsigned short  uint16_t;
-#   endif
-#   ifndef HAVE_UINT_T
-        typedef unsigned int    uint_t;
-#   endif
-
-#   ifndef HAVE_INT32_T
-#    if SIZEOF_INT == 4
-        typedef signed int      int32_t;
-#    elif SIZEOF_LONG == 4
-        typedef signed long     int32_t;
-#    endif
-#   endif
+# elif defined(HAVE_STDINT_H)
+#   include <stdint.h>
 
-#   ifndef HAVE_UINT32_T
-#    if SIZEOF_INT == 4
-        typedef unsigned int    uint32_t;
-#    elif SIZEOF_LONG == 4
-        typedef unsigned long   uint32_t;
-#    endif
+# elif !defined(HAVE_UINT32_T)
+#   if SIZEOF_INT == 4
+      typedef unsigned int    uint32_t;
+#   elif SIZEOF_LONG == 4
+      typedef unsigned long   uint32_t;
 #   endif
 # endif /* HAVE_*INT*_H header */
 
 #else /* not HAVE_CONFIG_H -- */
-# ifdef __sun
-#  include <inttypes.h>
-# else
-#  include <stdint.h>
-# endif
+# include <inttypes.h>
 #endif /* HAVE_CONFIG_H */
 
 #if 0 /* mapping specification source (from autogen.map) */
 // 
-// %guard          autoopts_internal
+// %guard
 // %file           ag-char-map.h
-// %table          opt-char-cat
+// %backup
+// %optimize
 // 
-// %comment
-//         This file contains the character classifications
-//         used by AutoGen and AutoOpts for identifying tokens.
+// %comment -- see above
 // %
 // 
-// lower-case      "a-z"
-// upper-case      "A-Z"
-// alphabetic      +lower-case   +upper-case
+// newline         "\n"
+// nul-byte        "\x00"
+// dir-sep         "/\\"
+// percent         "%"
+// comma           ","
+// colon           ":"
+// underscore      "_"
+// plus            "+"
+// dollar          "$"
+// option-marker   "-"
+// 
+// horiz-white     "\t "
+// alt-white       "\v\f\r\b"
+// whitespace      +horiz-white  +newline +alt-white
+// non-nl-white    +horiz-white  +alt-white
+// quote           "'\""
+// parentheses     "()"
+// 
+// graphic         "!-~"
+// inversion       "~-"
 // oct-digit       "0-7"
 // dec-digit       "89"          +oct-digit
 // hex-digit       "a-fA-F"      +dec-digit
+// lower-case      "a-z"
+// upper-case      "A-Z"
+// alphabetic      +lower-case   +upper-case
 // alphanumeric    +alphabetic   +dec-digit
-// var-first       "_"           +alphabetic
+// var-first       +underscore   +alphabetic
 // variable-name   +var-first    +dec-digit
 // option-name     "^-"          +variable-name
-// value-name      ":"           +option-name
-// horiz-white     "\t "
-// compound-name   "[.]"         +value-name   +horiz-white
-// whitespace      "\v\f\r\n\b"  +horiz-white
-// unquotable      "!-~"         -"\"#(),;<=>[\\]`{}?*'"
+// value-name      +colon        +option-name
+// name-sep        "[.]"
+// compound-name   +value-name   +name-sep +horiz-white
+// scheme-note     +parentheses  +quote
+// 
+// unquotable      "!-~"         -"#,;<=>[\\]`{}?*" -quote -parentheses
 // end-xml-token   "/>"          +whitespace
-// graphic         "!-~"
-// plus-n-space    "+"           +whitespace
+// plus-n-space    +plus         +whitespace
 // punctuation     "!-~"         -alphanumeric -"_"
 // suffix          "-._"         +alphanumeric
-// suffix-fmt      "%/"          +suffix     
-// false-type      "nNfF0\x00"
+// suffix-fmt      +percent      +suffix +dir-sep
+// false-type      "nNfF0"       +nul-byte
+// file-name       +dir-sep      +suffix
+// end-token       +nul-byte     +whitespace
+// end-list-entry  +comma        +end-token
+// set-separator   "|+-!"        +end-list-entry
+// signed-number   +inversion    +dec-digit
+// make-script     +dollar       +newline
+// load-line-skip  +horiz-white  +option-marker
 //
 #endif /* 0 -- mapping spec. source */
 
-typedef uint32_t opt_char_cat_mask_t;
-extern opt_char_cat_mask_t const opt_char_cat[128];
 
-static inline int is_opt_char_cat_char(char ch, opt_char_cat_mask_t mask) {
-    unsigned int ix = (unsigned char)ch;
-    return ((ix < 0x7F) && ((opt_char_cat[ix] & mask) != 0)); }
-
-#define IS_LOWER_CASE_CHAR(_c)     is_opt_char_cat_char((_c), 0x00001)
-#define IS_UPPER_CASE_CHAR(_c)     is_opt_char_cat_char((_c), 0x00002)
-#define IS_ALPHABETIC_CHAR(_c)     is_opt_char_cat_char((_c), 0x00003)
-#define IS_OCT_DIGIT_CHAR(_c)      is_opt_char_cat_char((_c), 0x00004)
-#define IS_DEC_DIGIT_CHAR(_c)      is_opt_char_cat_char((_c), 0x0000C)
-#define IS_HEX_DIGIT_CHAR(_c)      is_opt_char_cat_char((_c), 0x0001C)
-#define IS_ALPHANUMERIC_CHAR(_c)   is_opt_char_cat_char((_c), 0x0000F)
-#define IS_VAR_FIRST_CHAR(_c)      is_opt_char_cat_char((_c), 0x00023)
-#define IS_VARIABLE_NAME_CHAR(_c)  is_opt_char_cat_char((_c), 0x0002F)
-#define IS_OPTION_NAME_CHAR(_c)    is_opt_char_cat_char((_c), 0x0006F)
-#define IS_VALUE_NAME_CHAR(_c)     is_opt_char_cat_char((_c), 0x000EF)
-#define IS_HORIZ_WHITE_CHAR(_c)    is_opt_char_cat_char((_c), 0x00100)
-#define IS_COMPOUND_NAME_CHAR(_c)  is_opt_char_cat_char((_c), 0x003EF)
-#define IS_WHITESPACE_CHAR(_c)     is_opt_char_cat_char((_c), 0x00500)
-#define IS_UNQUOTABLE_CHAR(_c)     is_opt_char_cat_char((_c), 0x00800)
-#define IS_END_XML_TOKEN_CHAR(_c)  is_opt_char_cat_char((_c), 0x01500)
-#define IS_GRAPHIC_CHAR(_c)        is_opt_char_cat_char((_c), 0x02000)
-#define IS_PLUS_N_SPACE_CHAR(_c)   is_opt_char_cat_char((_c), 0x04500)
-#define IS_PUNCTUATION_CHAR(_c)    is_opt_char_cat_char((_c), 0x08000)
-#define IS_SUFFIX_CHAR(_c)         is_opt_char_cat_char((_c), 0x1000F)
-#define IS_SUFFIX_FMT_CHAR(_c)     is_opt_char_cat_char((_c), 0x3000F)
-#define IS_FALSE_TYPE_CHAR(_c)     is_opt_char_cat_char((_c), 0x40000)
-
-#ifdef AUTOOPTS_INTERNAL
-opt_char_cat_mask_t const opt_char_cat[128] = {
-  /*x00*/ 0x40000, /*x01*/ 0x00000, /*x02*/ 0x00000, /*x03*/ 0x00000,
-  /*x04*/ 0x00000, /*x05*/ 0x00000, /*x06*/ 0x00000, /*\a */ 0x00000,
-  /*\b */ 0x00400, /*\t */ 0x00100, /*\n */ 0x00400, /*\v */ 0x00400,
-  /*\f */ 0x00400, /*\r */ 0x00400, /*x0E*/ 0x00000, /*x0F*/ 0x00000,
-  /*x10*/ 0x00000, /*x11*/ 0x00000, /*x12*/ 0x00000, /*x13*/ 0x00000,
-  /*x14*/ 0x00000, /*x15*/ 0x00000, /*x16*/ 0x00000, /*x17*/ 0x00000,
-  /*x18*/ 0x00000, /*x19*/ 0x00000, /*x1A*/ 0x00000, /*x1B*/ 0x00000,
-  /*x1C*/ 0x00000, /*x1D*/ 0x00000, /*x1E*/ 0x00000, /*x1F*/ 0x00000,
-  /*   */ 0x00100, /* ! */ 0x0A800, /* " */ 0x0A000, /* # */ 0x0A000,
-  /* $ */ 0x0A800, /* % */ 0x2A800, /* & */ 0x0A800, /* ' */ 0x0A000,
-  /* ( */ 0x0A000, /* ) */ 0x0A000, /* * */ 0x0A000, /* + */ 0x0E800,
-  /* , */ 0x0A000, /* - */ 0x1A840, /* . */ 0x1AA00, /* / */ 0x2B800,
-  /* 0 */ 0x42804, /* 1 */ 0x02804, /* 2 */ 0x02804, /* 3 */ 0x02804,
-  /* 4 */ 0x02804, /* 5 */ 0x02804, /* 6 */ 0x02804, /* 7 */ 0x02804,
-  /* 8 */ 0x02808, /* 9 */ 0x02808, /* : */ 0x0A880, /* ; */ 0x0A000,
-  /* < */ 0x0A000, /* = */ 0x0A000, /* > */ 0x0B000, /* ? */ 0x0A000,
-  /* @ */ 0x0A800, /* A */ 0x02812, /* B */ 0x02812, /* C */ 0x02812,
-  /* D */ 0x02812, /* E */ 0x02812, /* F */ 0x42812, /* G */ 0x02802,
-  /* H */ 0x02802, /* I */ 0x02802, /* J */ 0x02802, /* K */ 0x02802,
-  /* L */ 0x02802, /* M */ 0x02802, /* N */ 0x42802, /* O */ 0x02802,
-  /* P */ 0x02802, /* Q */ 0x02802, /* R */ 0x02802, /* S */ 0x02802,
-  /* T */ 0x02802, /* U */ 0x02802, /* V */ 0x02802, /* W */ 0x02802,
-  /* X */ 0x02802, /* Y */ 0x02802, /* Z */ 0x02802, /* [ */ 0x0A200,
-  /* \ */ 0x0A000, /* ] */ 0x0A200, /* ^ */ 0x0A840, /* _ */ 0x12820,
-  /* ` */ 0x0A000, /* a */ 0x02811, /* b */ 0x02811, /* c */ 0x02811,
-  /* d */ 0x02811, /* e */ 0x02811, /* f */ 0x42811, /* g */ 0x02801,
-  /* h */ 0x02801, /* i */ 0x02801, /* j */ 0x02801, /* k */ 0x02801,
-  /* l */ 0x02801, /* m */ 0x02801, /* n */ 0x42801, /* o */ 0x02801,
-  /* p */ 0x02801, /* q */ 0x02801, /* r */ 0x02801, /* s */ 0x02801,
-  /* t */ 0x02801, /* u */ 0x02801, /* v */ 0x02801, /* w */ 0x02801,
-  /* x */ 0x02801, /* y */ 0x02801, /* z */ 0x02801, /* { */ 0x0A000,
-  /* | */ 0x0A800, /* } */ 0x0A000, /* ~ */ 0x0A800, /*x7F*/ 0x00000
+typedef uint32_t ag_char_map_mask_t;
+
+#define  IS_NEWLINE_CHAR( _c)          is_ag_char_map_char((char)(_c), 0x00000001)
+#define SPN_NEWLINE_CHARS(_s)         spn_ag_char_map_chars(_s, 0)
+#define BRK_NEWLINE_CHARS(_s)         brk_ag_char_map_chars(_s, 0)
+#define SPN_NEWLINE_BACK(s,e)         spn_ag_char_map_back(s, e, 0)
+#define BRK_NEWLINE_BACK(s,e)         brk_ag_char_map_back(s, e, 0)
+#define  IS_NUL_BYTE_CHAR( _c)         is_ag_char_map_char((char)(_c), 0x00000002)
+#define SPN_NUL_BYTE_CHARS(_s)        spn_ag_char_map_chars(_s, 1)
+#define BRK_NUL_BYTE_CHARS(_s)        brk_ag_char_map_chars(_s, 1)
+#define SPN_NUL_BYTE_BACK(s,e)        spn_ag_char_map_back(s, e, 1)
+#define BRK_NUL_BYTE_BACK(s,e)        brk_ag_char_map_back(s, e, 1)
+#define  IS_DIR_SEP_CHAR( _c)          is_ag_char_map_char((char)(_c), 0x00000004)
+#define SPN_DIR_SEP_CHARS(_s)         spn_ag_char_map_chars(_s, 2)
+#define BRK_DIR_SEP_CHARS(_s)         brk_ag_char_map_chars(_s, 2)
+#define SPN_DIR_SEP_BACK(s,e)         spn_ag_char_map_back(s, e, 2)
+#define BRK_DIR_SEP_BACK(s,e)         brk_ag_char_map_back(s, e, 2)
+#define  IS_PERCENT_CHAR( _c)          is_ag_char_map_char((char)(_c), 0x00000008)
+#define SPN_PERCENT_CHARS(_s)         spn_ag_char_map_chars(_s, 3)
+#define BRK_PERCENT_CHARS(_s)         brk_ag_char_map_chars(_s, 3)
+#define SPN_PERCENT_BACK(s,e)         spn_ag_char_map_back(s, e, 3)
+#define BRK_PERCENT_BACK(s,e)         brk_ag_char_map_back(s, e, 3)
+#define  IS_COMMA_CHAR( _c)            is_ag_char_map_char((char)(_c), 0x00000010)
+#define SPN_COMMA_CHARS(_s)           spn_ag_char_map_chars(_s, 4)
+#define BRK_COMMA_CHARS(_s)           brk_ag_char_map_chars(_s, 4)
+#define SPN_COMMA_BACK(s,e)           spn_ag_char_map_back(s, e, 4)
+#define BRK_COMMA_BACK(s,e)           brk_ag_char_map_back(s, e, 4)
+#define  IS_COLON_CHAR( _c)            is_ag_char_map_char((char)(_c), 0x00000020)
+#define SPN_COLON_CHARS(_s)           spn_ag_char_map_chars(_s, 5)
+#define BRK_COLON_CHARS(_s)           brk_ag_char_map_chars(_s, 5)
+#define SPN_COLON_BACK(s,e)           spn_ag_char_map_back(s, e, 5)
+#define BRK_COLON_BACK(s,e)           brk_ag_char_map_back(s, e, 5)
+#define  IS_UNDERSCORE_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x00000040)
+#define SPN_UNDERSCORE_CHARS(_s)      spn_ag_char_map_chars(_s, 6)
+#define BRK_UNDERSCORE_CHARS(_s)      brk_ag_char_map_chars(_s, 6)
+#define SPN_UNDERSCORE_BACK(s,e)      spn_ag_char_map_back(s, e, 6)
+#define BRK_UNDERSCORE_BACK(s,e)      brk_ag_char_map_back(s, e, 6)
+#define  IS_PLUS_CHAR( _c)             is_ag_char_map_char((char)(_c), 0x00000080)
+#define SPN_PLUS_CHARS(_s)            spn_ag_char_map_chars(_s, 7)
+#define BRK_PLUS_CHARS(_s)            brk_ag_char_map_chars(_s, 7)
+#define SPN_PLUS_BACK(s,e)            spn_ag_char_map_back(s, e, 7)
+#define BRK_PLUS_BACK(s,e)            brk_ag_char_map_back(s, e, 7)
+#define  IS_DOLLAR_CHAR( _c)           is_ag_char_map_char((char)(_c), 0x00000100)
+#define SPN_DOLLAR_CHARS(_s)          spn_ag_char_map_chars(_s, 8)
+#define BRK_DOLLAR_CHARS(_s)          brk_ag_char_map_chars(_s, 8)
+#define SPN_DOLLAR_BACK(s,e)          spn_ag_char_map_back(s, e, 8)
+#define BRK_DOLLAR_BACK(s,e)          brk_ag_char_map_back(s, e, 8)
+#define  IS_OPTION_MARKER_CHAR( _c)    is_ag_char_map_char((char)(_c), 0x00000200)
+#define SPN_OPTION_MARKER_CHARS(_s)   spn_ag_char_map_chars(_s, 9)
+#define BRK_OPTION_MARKER_CHARS(_s)   brk_ag_char_map_chars(_s, 9)
+#define SPN_OPTION_MARKER_BACK(s,e)   spn_ag_char_map_back(s, e, 9)
+#define BRK_OPTION_MARKER_BACK(s,e)   brk_ag_char_map_back(s, e, 9)
+#define  IS_HORIZ_WHITE_CHAR( _c)      is_ag_char_map_char((char)(_c), 0x00000400)
+#define SPN_HORIZ_WHITE_CHARS(_s)     spn_ag_char_map_chars(_s, 10)
+#define BRK_HORIZ_WHITE_CHARS(_s)     brk_ag_char_map_chars(_s, 10)
+#define SPN_HORIZ_WHITE_BACK(s,e)     spn_ag_char_map_back(s, e, 10)
+#define BRK_HORIZ_WHITE_BACK(s,e)     brk_ag_char_map_back(s, e, 10)
+#define  IS_ALT_WHITE_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00000800)
+#define SPN_ALT_WHITE_CHARS(_s)       spn_ag_char_map_chars(_s, 11)
+#define BRK_ALT_WHITE_CHARS(_s)       brk_ag_char_map_chars(_s, 11)
+#define SPN_ALT_WHITE_BACK(s,e)       spn_ag_char_map_back(s, e, 11)
+#define BRK_ALT_WHITE_BACK(s,e)       brk_ag_char_map_back(s, e, 11)
+#define  IS_WHITESPACE_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x00000C01)
+#define SPN_WHITESPACE_CHARS(_s)      spn_ag_char_map_chars(_s, 12)
+#define BRK_WHITESPACE_CHARS(_s)      brk_ag_char_map_chars(_s, 12)
+#define SPN_WHITESPACE_BACK(s,e)      spn_ag_char_map_back(s, e, 12)
+#define BRK_WHITESPACE_BACK(s,e)      brk_ag_char_map_back(s, e, 12)
+#define  IS_NON_NL_WHITE_CHAR( _c)     is_ag_char_map_char((char)(_c), 0x00000C00)
+#define SPN_NON_NL_WHITE_CHARS(_s)    spn_ag_char_map_chars(_s, 13)
+#define BRK_NON_NL_WHITE_CHARS(_s)    brk_ag_char_map_chars(_s, 13)
+#define SPN_NON_NL_WHITE_BACK(s,e)    spn_ag_char_map_back(s, e, 13)
+#define BRK_NON_NL_WHITE_BACK(s,e)    brk_ag_char_map_back(s, e, 13)
+#define  IS_QUOTE_CHAR( _c)            is_ag_char_map_char((char)(_c), 0x00001000)
+#define SPN_QUOTE_CHARS(_s)           spn_ag_char_map_chars(_s, 14)
+#define BRK_QUOTE_CHARS(_s)           brk_ag_char_map_chars(_s, 14)
+#define SPN_QUOTE_BACK(s,e)           spn_ag_char_map_back(s, e, 14)
+#define BRK_QUOTE_BACK(s,e)           brk_ag_char_map_back(s, e, 14)
+#define  IS_PARENTHESES_CHAR( _c)      is_ag_char_map_char((char)(_c), 0x00002000)
+#define SPN_PARENTHESES_CHARS(_s)     spn_ag_char_map_chars(_s, 15)
+#define BRK_PARENTHESES_CHARS(_s)     brk_ag_char_map_chars(_s, 15)
+#define SPN_PARENTHESES_BACK(s,e)     spn_ag_char_map_back(s, e, 15)
+#define BRK_PARENTHESES_BACK(s,e)     brk_ag_char_map_back(s, e, 15)
+#define  IS_GRAPHIC_CHAR( _c)          is_ag_char_map_char((char)(_c), 0x00004000)
+#define SPN_GRAPHIC_CHARS(_s)         spn_ag_char_map_chars(_s, 16)
+#define BRK_GRAPHIC_CHARS(_s)         brk_ag_char_map_chars(_s, 16)
+#define SPN_GRAPHIC_BACK(s,e)         spn_ag_char_map_back(s, e, 16)
+#define BRK_GRAPHIC_BACK(s,e)         brk_ag_char_map_back(s, e, 16)
+#define  IS_INVERSION_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00008000)
+#define SPN_INVERSION_CHARS(_s)       spn_ag_char_map_chars(_s, 17)
+#define BRK_INVERSION_CHARS(_s)       brk_ag_char_map_chars(_s, 17)
+#define SPN_INVERSION_BACK(s,e)       spn_ag_char_map_back(s, e, 17)
+#define BRK_INVERSION_BACK(s,e)       brk_ag_char_map_back(s, e, 17)
+#define  IS_OCT_DIGIT_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00010000)
+#define SPN_OCT_DIGIT_CHARS(_s)       spn_ag_char_map_chars(_s, 18)
+#define BRK_OCT_DIGIT_CHARS(_s)       brk_ag_char_map_chars(_s, 18)
+#define SPN_OCT_DIGIT_BACK(s,e)       spn_ag_char_map_back(s, e, 18)
+#define BRK_OCT_DIGIT_BACK(s,e)       brk_ag_char_map_back(s, e, 18)
+#define  IS_DEC_DIGIT_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00030000)
+#define SPN_DEC_DIGIT_CHARS(_s)       spn_ag_char_map_chars(_s, 19)
+#define BRK_DEC_DIGIT_CHARS(_s)       brk_ag_char_map_chars(_s, 19)
+#define SPN_DEC_DIGIT_BACK(s,e)       spn_ag_char_map_back(s, e, 19)
+#define BRK_DEC_DIGIT_BACK(s,e)       brk_ag_char_map_back(s, e, 19)
+#define  IS_HEX_DIGIT_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00070000)
+#define SPN_HEX_DIGIT_CHARS(_s)       spn_ag_char_map_chars(_s, 20)
+#define BRK_HEX_DIGIT_CHARS(_s)       brk_ag_char_map_chars(_s, 20)
+#define SPN_HEX_DIGIT_BACK(s,e)       spn_ag_char_map_back(s, e, 20)
+#define BRK_HEX_DIGIT_BACK(s,e)       brk_ag_char_map_back(s, e, 20)
+#define  IS_LOWER_CASE_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x00080000)
+#define SPN_LOWER_CASE_CHARS(_s)      spn_ag_char_map_chars(_s, 21)
+#define BRK_LOWER_CASE_CHARS(_s)      brk_ag_char_map_chars(_s, 21)
+#define SPN_LOWER_CASE_BACK(s,e)      spn_ag_char_map_back(s, e, 21)
+#define BRK_LOWER_CASE_BACK(s,e)      brk_ag_char_map_back(s, e, 21)
+#define  IS_UPPER_CASE_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x00100000)
+#define SPN_UPPER_CASE_CHARS(_s)      spn_ag_char_map_chars(_s, 22)
+#define BRK_UPPER_CASE_CHARS(_s)      brk_ag_char_map_chars(_s, 22)
+#define SPN_UPPER_CASE_BACK(s,e)      spn_ag_char_map_back(s, e, 22)
+#define BRK_UPPER_CASE_BACK(s,e)      brk_ag_char_map_back(s, e, 22)
+#define  IS_ALPHABETIC_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x00180000)
+#define SPN_ALPHABETIC_CHARS(_s)      spn_ag_char_map_chars(_s, 23)
+#define BRK_ALPHABETIC_CHARS(_s)      brk_ag_char_map_chars(_s, 23)
+#define SPN_ALPHABETIC_BACK(s,e)      spn_ag_char_map_back(s, e, 23)
+#define BRK_ALPHABETIC_BACK(s,e)      brk_ag_char_map_back(s, e, 23)
+#define  IS_ALPHANUMERIC_CHAR( _c)     is_ag_char_map_char((char)(_c), 0x001B0000)
+#define SPN_ALPHANUMERIC_CHARS(_s)    spn_ag_char_map_chars(_s, 24)
+#define BRK_ALPHANUMERIC_CHARS(_s)    brk_ag_char_map_chars(_s, 24)
+#define SPN_ALPHANUMERIC_BACK(s,e)    spn_ag_char_map_back(s, e, 24)
+#define BRK_ALPHANUMERIC_BACK(s,e)    brk_ag_char_map_back(s, e, 24)
+#define  IS_VAR_FIRST_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00180040)
+#define SPN_VAR_FIRST_CHARS(_s)       spn_ag_char_map_chars(_s, 25)
+#define BRK_VAR_FIRST_CHARS(_s)       brk_ag_char_map_chars(_s, 25)
+#define SPN_VAR_FIRST_BACK(s,e)       spn_ag_char_map_back(s, e, 25)
+#define BRK_VAR_FIRST_BACK(s,e)       brk_ag_char_map_back(s, e, 25)
+#define  IS_VARIABLE_NAME_CHAR( _c)    is_ag_char_map_char((char)(_c), 0x001B0040)
+#define SPN_VARIABLE_NAME_CHARS(_s)   spn_ag_char_map_chars(_s, 26)
+#define BRK_VARIABLE_NAME_CHARS(_s)   brk_ag_char_map_chars(_s, 26)
+#define SPN_VARIABLE_NAME_BACK(s,e)   spn_ag_char_map_back(s, e, 26)
+#define BRK_VARIABLE_NAME_BACK(s,e)   brk_ag_char_map_back(s, e, 26)
+#define  IS_OPTION_NAME_CHAR( _c)      is_ag_char_map_char((char)(_c), 0x003B0040)
+#define SPN_OPTION_NAME_CHARS(_s)     spn_ag_char_map_chars(_s, 27)
+#define BRK_OPTION_NAME_CHARS(_s)     brk_ag_char_map_chars(_s, 27)
+#define SPN_OPTION_NAME_BACK(s,e)     spn_ag_char_map_back(s, e, 27)
+#define BRK_OPTION_NAME_BACK(s,e)     brk_ag_char_map_back(s, e, 27)
+#define  IS_VALUE_NAME_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x003B0060)
+#define SPN_VALUE_NAME_CHARS(_s)      spn_ag_char_map_chars(_s, 28)
+#define BRK_VALUE_NAME_CHARS(_s)      brk_ag_char_map_chars(_s, 28)
+#define SPN_VALUE_NAME_BACK(s,e)      spn_ag_char_map_back(s, e, 28)
+#define BRK_VALUE_NAME_BACK(s,e)      brk_ag_char_map_back(s, e, 28)
+#define  IS_NAME_SEP_CHAR( _c)         is_ag_char_map_char((char)(_c), 0x00400000)
+#define SPN_NAME_SEP_CHARS(_s)        spn_ag_char_map_chars(_s, 29)
+#define BRK_NAME_SEP_CHARS(_s)        brk_ag_char_map_chars(_s, 29)
+#define SPN_NAME_SEP_BACK(s,e)        spn_ag_char_map_back(s, e, 29)
+#define BRK_NAME_SEP_BACK(s,e)        brk_ag_char_map_back(s, e, 29)
+#define  IS_COMPOUND_NAME_CHAR( _c)    is_ag_char_map_char((char)(_c), 0x007B0460)
+#define SPN_COMPOUND_NAME_CHARS(_s)   spn_ag_char_map_chars(_s, 30)
+#define BRK_COMPOUND_NAME_CHARS(_s)   brk_ag_char_map_chars(_s, 30)
+#define SPN_COMPOUND_NAME_BACK(s,e)   spn_ag_char_map_back(s, e, 30)
+#define BRK_COMPOUND_NAME_BACK(s,e)   brk_ag_char_map_back(s, e, 30)
+#define  IS_SCHEME_NOTE_CHAR( _c)      is_ag_char_map_char((char)(_c), 0x00003000)
+#define SPN_SCHEME_NOTE_CHARS(_s)     spn_ag_char_map_chars(_s, 31)
+#define BRK_SCHEME_NOTE_CHARS(_s)     brk_ag_char_map_chars(_s, 31)
+#define SPN_SCHEME_NOTE_BACK(s,e)     spn_ag_char_map_back(s, e, 31)
+#define BRK_SCHEME_NOTE_BACK(s,e)     brk_ag_char_map_back(s, e, 31)
+#define  IS_UNQUOTABLE_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x00800000)
+#define SPN_UNQUOTABLE_CHARS(_s)      spn_ag_char_map_chars(_s, 32)
+#define BRK_UNQUOTABLE_CHARS(_s)      brk_ag_char_map_chars(_s, 32)
+#define SPN_UNQUOTABLE_BACK(s,e)      spn_ag_char_map_back(s, e, 32)
+#define BRK_UNQUOTABLE_BACK(s,e)      brk_ag_char_map_back(s, e, 32)
+#define  IS_END_XML_TOKEN_CHAR( _c)    is_ag_char_map_char((char)(_c), 0x01000C01)
+#define SPN_END_XML_TOKEN_CHARS(_s)   spn_ag_char_map_chars(_s, 33)
+#define BRK_END_XML_TOKEN_CHARS(_s)   brk_ag_char_map_chars(_s, 33)
+#define SPN_END_XML_TOKEN_BACK(s,e)   spn_ag_char_map_back(s, e, 33)
+#define BRK_END_XML_TOKEN_BACK(s,e)   brk_ag_char_map_back(s, e, 33)
+#define  IS_PLUS_N_SPACE_CHAR( _c)     is_ag_char_map_char((char)(_c), 0x00000C81)
+#define SPN_PLUS_N_SPACE_CHARS(_s)    spn_ag_char_map_chars(_s, 34)
+#define BRK_PLUS_N_SPACE_CHARS(_s)    brk_ag_char_map_chars(_s, 34)
+#define SPN_PLUS_N_SPACE_BACK(s,e)    spn_ag_char_map_back(s, e, 34)
+#define BRK_PLUS_N_SPACE_BACK(s,e)    brk_ag_char_map_back(s, e, 34)
+#define  IS_PUNCTUATION_CHAR( _c)      is_ag_char_map_char((char)(_c), 0x02000000)
+#define SPN_PUNCTUATION_CHARS(_s)     spn_ag_char_map_chars(_s, 35)
+#define BRK_PUNCTUATION_CHARS(_s)     brk_ag_char_map_chars(_s, 35)
+#define SPN_PUNCTUATION_BACK(s,e)     spn_ag_char_map_back(s, e, 35)
+#define BRK_PUNCTUATION_BACK(s,e)     brk_ag_char_map_back(s, e, 35)
+#define  IS_SUFFIX_CHAR( _c)           is_ag_char_map_char((char)(_c), 0x041B0000)
+#define SPN_SUFFIX_CHARS(_s)          spn_ag_char_map_chars(_s, 36)
+#define BRK_SUFFIX_CHARS(_s)          brk_ag_char_map_chars(_s, 36)
+#define SPN_SUFFIX_BACK(s,e)          spn_ag_char_map_back(s, e, 36)
+#define BRK_SUFFIX_BACK(s,e)          brk_ag_char_map_back(s, e, 36)
+#define  IS_SUFFIX_FMT_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x041B000C)
+#define SPN_SUFFIX_FMT_CHARS(_s)      spn_ag_char_map_chars(_s, 37)
+#define BRK_SUFFIX_FMT_CHARS(_s)      brk_ag_char_map_chars(_s, 37)
+#define SPN_SUFFIX_FMT_BACK(s,e)      spn_ag_char_map_back(s, e, 37)
+#define BRK_SUFFIX_FMT_BACK(s,e)      brk_ag_char_map_back(s, e, 37)
+#define  IS_FALSE_TYPE_CHAR( _c)       is_ag_char_map_char((char)(_c), 0x08000002)
+#define SPN_FALSE_TYPE_CHARS(_s)      spn_ag_char_map_chars(_s, 38)
+#define BRK_FALSE_TYPE_CHARS(_s)      brk_ag_char_map_chars(_s, 38)
+#define SPN_FALSE_TYPE_BACK(s,e)      spn_ag_char_map_back(s, e, 38)
+#define BRK_FALSE_TYPE_BACK(s,e)      brk_ag_char_map_back(s, e, 38)
+#define  IS_FILE_NAME_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x041B0004)
+#define SPN_FILE_NAME_CHARS(_s)       spn_ag_char_map_chars(_s, 39)
+#define BRK_FILE_NAME_CHARS(_s)       brk_ag_char_map_chars(_s, 39)
+#define SPN_FILE_NAME_BACK(s,e)       spn_ag_char_map_back(s, e, 39)
+#define BRK_FILE_NAME_BACK(s,e)       brk_ag_char_map_back(s, e, 39)
+#define  IS_END_TOKEN_CHAR( _c)        is_ag_char_map_char((char)(_c), 0x00000C03)
+#define SPN_END_TOKEN_CHARS(_s)       spn_ag_char_map_chars(_s, 40)
+#define BRK_END_TOKEN_CHARS(_s)       brk_ag_char_map_chars(_s, 40)
+#define SPN_END_TOKEN_BACK(s,e)       spn_ag_char_map_back(s, e, 40)
+#define BRK_END_TOKEN_BACK(s,e)       brk_ag_char_map_back(s, e, 40)
+#define  IS_END_LIST_ENTRY_CHAR( _c)   is_ag_char_map_char((char)(_c), 0x00000C13)
+#define SPN_END_LIST_ENTRY_CHARS(_s)  spn_ag_char_map_chars(_s, 41)
+#define BRK_END_LIST_ENTRY_CHARS(_s)  brk_ag_char_map_chars(_s, 41)
+#define SPN_END_LIST_ENTRY_BACK(s,e)  spn_ag_char_map_back(s, e, 41)
+#define BRK_END_LIST_ENTRY_BACK(s,e)  brk_ag_char_map_back(s, e, 41)
+#define  IS_SET_SEPARATOR_CHAR( _c)    is_ag_char_map_char((char)(_c), 0x10000C13)
+#define SPN_SET_SEPARATOR_CHARS(_s)   spn_ag_char_map_chars(_s, 42)
+#define BRK_SET_SEPARATOR_CHARS(_s)   brk_ag_char_map_chars(_s, 42)
+#define SPN_SET_SEPARATOR_BACK(s,e)   spn_ag_char_map_back(s, e, 42)
+#define BRK_SET_SEPARATOR_BACK(s,e)   brk_ag_char_map_back(s, e, 42)
+#define  IS_SIGNED_NUMBER_CHAR( _c)    is_ag_char_map_char((char)(_c), 0x00038000)
+#define SPN_SIGNED_NUMBER_CHARS(_s)   spn_ag_char_map_chars(_s, 43)
+#define BRK_SIGNED_NUMBER_CHARS(_s)   brk_ag_char_map_chars(_s, 43)
+#define SPN_SIGNED_NUMBER_BACK(s,e)   spn_ag_char_map_back(s, e, 43)
+#define BRK_SIGNED_NUMBER_BACK(s,e)   brk_ag_char_map_back(s, e, 43)
+#define  IS_MAKE_SCRIPT_CHAR( _c)      is_ag_char_map_char((char)(_c), 0x00000101)
+#define SPN_MAKE_SCRIPT_CHARS(_s)     spn_ag_char_map_chars(_s, 44)
+#define BRK_MAKE_SCRIPT_CHARS(_s)     brk_ag_char_map_chars(_s, 44)
+#define SPN_MAKE_SCRIPT_BACK(s,e)     spn_ag_char_map_back(s, e, 44)
+#define BRK_MAKE_SCRIPT_BACK(s,e)     brk_ag_char_map_back(s, e, 44)
+#define  IS_LOAD_LINE_SKIP_CHAR( _c)   is_ag_char_map_char((char)(_c), 0x00000600)
+#define SPN_LOAD_LINE_SKIP_CHARS(_s)  spn_ag_char_map_chars(_s, 45)
+#define BRK_LOAD_LINE_SKIP_CHARS(_s)  brk_ag_char_map_chars(_s, 45)
+#define SPN_LOAD_LINE_SKIP_BACK(s,e)  spn_ag_char_map_back(s, e, 45)
+#define BRK_LOAD_LINE_SKIP_BACK(s,e)  brk_ag_char_map_back(s, e, 45)
+
+static ag_char_map_mask_t const ag_char_map_table[128] = {
+  /*NUL*/ 0x00000002, /*x01*/ 0x00000000, /*x02*/ 0x00000000, /*x03*/ 0x00000000,
+  /*x04*/ 0x00000000, /*x05*/ 0x00000000, /*x06*/ 0x00000000, /*BEL*/ 0x00000000,
+  /* BS*/ 0x00000800, /* HT*/ 0x00000400, /* NL*/ 0x00000001, /* VT*/ 0x00000800,
+  /* FF*/ 0x00000800, /* CR*/ 0x00000800, /*x0E*/ 0x00000000, /*x0F*/ 0x00000000,
+  /*x10*/ 0x00000000, /*x11*/ 0x00000000, /*x12*/ 0x00000000, /*x13*/ 0x00000000,
+  /*x14*/ 0x00000000, /*x15*/ 0x00000000, /*x16*/ 0x00000000, /*x17*/ 0x00000000,
+  /*x18*/ 0x00000000, /*x19*/ 0x00000000, /*x1A*/ 0x00000000, /*ESC*/ 0x00000000,
+  /*x1C*/ 0x00000000, /*x1D*/ 0x00000000, /*x1E*/ 0x00000000, /*x1F*/ 0x00000000,
+  /*   */ 0x00000400, /* ! */ 0x02804000, /* " */ 0x02005000, /* # */ 0x02004000,
+  /* $ */ 0x02804100, /* % */ 0x02804008, /* & */ 0x02804000, /* ' */ 0x02005000,
+  /* ( */ 0x02006000, /* ) */ 0x02006000, /* * */ 0x02004000, /* + */ 0x12804080,
+  /* , */ 0x02004010, /* - */ 0x06A0C200, /* . */ 0x06C04000, /* / */ 0x03804004,
+  /* 0 */ 0x08814000, /* 1 */ 0x00814000, /* 2 */ 0x00814000, /* 3 */ 0x00814000,
+  /* 4 */ 0x00814000, /* 5 */ 0x00814000, /* 6 */ 0x00814000, /* 7 */ 0x00814000,
+  /* 8 */ 0x00824000, /* 9 */ 0x00824000, /* : */ 0x02804020, /* ; */ 0x02004000,
+  /* < */ 0x02004000, /* = */ 0x02004000, /* > */ 0x03004000, /* ? */ 0x02004000,
+  /* @ */ 0x02804000, /* A */ 0x00944000, /* B */ 0x00944000, /* C */ 0x00944000,
+  /* D */ 0x00944000, /* E */ 0x00944000, /* F */ 0x08944000, /* G */ 0x00904000,
+  /* H */ 0x00904000, /* I */ 0x00904000, /* J */ 0x00904000, /* K */ 0x00904000,
+  /* L */ 0x00904000, /* M */ 0x00904000, /* N */ 0x08904000, /* O */ 0x00904000,
+  /* P */ 0x00904000, /* Q */ 0x00904000, /* R */ 0x00904000, /* S */ 0x00904000,
+  /* T */ 0x00904000, /* U */ 0x00904000, /* V */ 0x00904000, /* W */ 0x00904000,
+  /* X */ 0x00904000, /* Y */ 0x00904000, /* Z */ 0x00904000, /* [ */ 0x02404000,
+  /* \ */ 0x02004004, /* ] */ 0x02404000, /* ^ */ 0x02A04000, /* _ */ 0x04804040,
+  /* ` */ 0x02004000, /* a */ 0x008C4000, /* b */ 0x008C4000, /* c */ 0x008C4000,
+  /* d */ 0x008C4000, /* e */ 0x008C4000, /* f */ 0x088C4000, /* g */ 0x00884000,
+  /* h */ 0x00884000, /* i */ 0x00884000, /* j */ 0x00884000, /* k */ 0x00884000,
+  /* l */ 0x00884000, /* m */ 0x00884000, /* n */ 0x08884000, /* o */ 0x00884000,
+  /* p */ 0x00884000, /* q */ 0x00884000, /* r */ 0x00884000, /* s */ 0x00884000,
+  /* t */ 0x00884000, /* u */ 0x00884000, /* v */ 0x00884000, /* w */ 0x00884000,
+  /* x */ 0x00884000, /* y */ 0x00884000, /* z */ 0x00884000, /* { */ 0x02004000,
+  /* | */ 0x12804000, /* } */ 0x02004000, /* ~ */ 0x0280C000, /*x7F*/ 0x00000000
+};
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef _
+# define _(_s) _s
+#endif
+
+static unsigned char const * ag_char_map_spanners[46];
+/**
+ *  Character category masks.  Some categories may have multiple bits,
+ *  if their definition incorporates other character categories.
+ *  This mask array is only used by calc_ag_char_map_spanners().
+ */
+static ag_char_map_mask_t const ag_char_map_masks[46] = {
+    0x00000001, /* NEWLINE         */
+    0x00000002, /* NUL_BYTE        */
+    0x00000004, /* DIR_SEP         */
+    0x00000008, /* PERCENT         */
+    0x00000010, /* COMMA           */
+    0x00000020, /* COLON           */
+    0x00000040, /* UNDERSCORE      */
+    0x00000080, /* PLUS            */
+    0x00000100, /* DOLLAR          */
+    0x00000200, /* OPTION_MARKER   */
+    0x00000400, /* HORIZ_WHITE     */
+    0x00000800, /* ALT_WHITE       */
+    0x00000C01, /* WHITESPACE      */
+    0x00000C00, /* NON_NL_WHITE    */
+    0x00001000, /* QUOTE           */
+    0x00002000, /* PARENTHESES     */
+    0x00004000, /* GRAPHIC         */
+    0x00008000, /* INVERSION       */
+    0x00010000, /* OCT_DIGIT       */
+    0x00030000, /* DEC_DIGIT       */
+    0x00070000, /* HEX_DIGIT       */
+    0x00080000, /* LOWER_CASE      */
+    0x00100000, /* UPPER_CASE      */
+    0x00180000, /* ALPHABETIC      */
+    0x001B0000, /* ALPHANUMERIC    */
+    0x00180040, /* VAR_FIRST       */
+    0x001B0040, /* VARIABLE_NAME   */
+    0x003B0040, /* OPTION_NAME     */
+    0x003B0060, /* VALUE_NAME      */
+    0x00400000, /* NAME_SEP        */
+    0x007B0460, /* COMPOUND_NAME   */
+    0x00003000, /* SCHEME_NOTE     */
+    0x00800000, /* UNQUOTABLE      */
+    0x01000C01, /* END_XML_TOKEN   */
+    0x00000C81, /* PLUS_N_SPACE    */
+    0x02000000, /* PUNCTUATION     */
+    0x041B0000, /* SUFFIX          */
+    0x041B000C, /* SUFFIX_FMT      */
+    0x08000002, /* FALSE_TYPE      */
+    0x041B0004, /* FILE_NAME       */
+    0x00000C03, /* END_TOKEN       */
+    0x00000C13, /* END_LIST_ENTRY  */
+    0x10000C13, /* SET_SEPARATOR   */
+    0x00038000, /* SIGNED_NUMBER   */
+    0x00000101, /* MAKE_SCRIPT     */
+    0x00000600, /* LOAD_LINE_SKIP  */
 };
-#endif /* AUTOOPTS_INTERNAL */
+#undef LOCK_SPANNER_TABLES
+
+static unsigned char const *
+calc_ag_char_map_spanners(unsigned int mask_ix)
+{
+#ifdef LOCK_SPANNER_TABLES
+    if (ag_char_map_spanners[mask_ix] != NULL)
+        return ag_char_map_spanners[mask_ix];
+
+    pthread_mutex_lock(&ag_char_map_mutex);
+    if (ag_char_map_spanners[mask_ix] == NULL)
+#endif
+    {
+        int ix = 1;
+        ag_char_map_mask_t mask = ag_char_map_masks[mask_ix];
+        unsigned char * res = malloc(256 /* 1 << NBBY */);
+        if (res == NULL) {
+            fputs(_("no memory for char-mapper span map\n"), stderr);
+            exit(EXIT_FAILURE);
+        }
+
+        memset(res, 0, 256);
+        for (; ix < 128; ix++)
+            if (ag_char_map_table[ix] & mask)
+                res[ix] = 1;
+        ag_char_map_spanners[mask_ix] = res;
+    }
+#ifdef LOCK_SPANNER_TABLES
+    pthread_mutex_unlock(&ag_char_map_mutex);
+#endif
+    return ag_char_map_spanners[mask_ix];
+}
+#define ag_char_map_masks POISONED_ag_char_map_masks
+
+static inline int
+is_ag_char_map_char(char ch, ag_char_map_mask_t mask)
+{
+    unsigned int ix = (unsigned char)ch;
+    return ((ix < 128) && ((ag_char_map_table[ix] & mask) != 0));
+}
+
+static inline char *
+spn_ag_char_map_chars(char const * p, unsigned int mask_ix)
+{
+    unsigned char const * v = ag_char_map_spanners[mask_ix];
+    if (v == NULL)
+        v = calc_ag_char_map_spanners(mask_ix);
+    while (v[(unsigned char)*p])  p++;
+    return (char *)(uintptr_t)p;
+}
+
+static inline char *
+brk_ag_char_map_chars(char const * p, unsigned int mask_ix)
+{
+    unsigned char const * v = ag_char_map_spanners[mask_ix];
+    if (v == NULL)
+        v = calc_ag_char_map_spanners(mask_ix);
+    while ((*p != '\0') && (! v[(unsigned char)*p]))  p++;
+    return (char *)(uintptr_t)p;
+}
+
+static inline char *
+spn_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix)
+{
+    unsigned char const * v = ag_char_map_spanners[mask_ix];
+    if (v == NULL)
+        v = calc_ag_char_map_spanners(mask_ix);
+    if (s >= e) e = s + strlen(s);
+    while ((e > s) && v[(unsigned char)e[-1]])  e--;
+    return (char *)(uintptr_t)e;
+}
+
+static inline char *
+brk_ag_char_map_back(char const * s, char const * e, unsigned int mask_ix)
+{
+    unsigned char const * v = ag_char_map_spanners[mask_ix];
+    if (v == NULL)
+        v = calc_ag_char_map_spanners(mask_ix);
+    if (s == e) e += strlen(e);
+    while ((e > s) && (! v[(unsigned char)e[-1]]))  e--;
+    return (char *)(uintptr_t)e;
+}
 #endif /* AG_CHAR_MAP_H_GUARD */

+ 116 - 0
libopts/alias.c

@@ -0,0 +1,116 @@
+
+/**
+ * \file alias.c
+ *
+ * Handle options that are aliases for another option.
+ *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
+ *  This routine will forward an option alias to the correct option code.
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+LOCAL tSuccess
+too_many_occurrences(tOptions * opts, tOptDesc * od)
+{
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        char const * eqv = (od->optEquivIndex != NO_EQUIVALENT) ? zequiv : zNil;
+
+        fprintf(stderr, ztoo_often_fmt, opts->pzProgName);
+
+        if (od->optMaxCt > 1)
+            fprintf(stderr, zat_most, od->optMaxCt, od->pz_Name, eqv);
+        else
+            fprintf(stderr, zonly_one, od->pz_Name, eqv);
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+    }
+
+    return FAILURE;
+}
+
+/*=export_func  optionAlias
+ * private:
+ *
+ * what:  relay an option to its alias
+ * arg:   + tOptions *   + opts   + program options descriptor  +
+ * arg:   + tOptDesc *   + old_od + the descriptor for this arg +
+ * arg:   + unsigned int + alias  + the aliased-to option index +
+ * ret-type: int
+ *
+ * doc:
+ *  Handle one option as if it had been specified as another.  Exactly.
+ *  Returns "-1" if the aliased-to option has appeared too many times.
+=*/
+int
+optionAlias(tOptions * opts, tOptDesc * old_od, unsigned int alias)
+{
+    tOptDesc * new_od;
+
+    if (opts <= OPTPROC_EMIT_LIMIT)
+        return 0;
+
+    new_od = opts->pOptDesc + alias;
+    if ((unsigned)opts->optCt <= alias) {
+        fputs(zbad_alias_id, stderr);
+        option_exits(EXIT_FAILURE);
+    }
+
+    /*
+     *  Copy over the option instance flags
+     */
+    new_od->fOptState &= OPTST_PERSISTENT_MASK;
+    new_od->fOptState |= (old_od->fOptState & ~OPTST_PERSISTENT_MASK);
+    new_od->optArg.argString = old_od->optArg.argString;
+
+    /*
+     *  Keep track of count only for DEFINED (command line) options.
+     *  IF we have too many, build up an error message and bail.
+     */
+    if (  (new_od->fOptState & OPTST_DEFINED)
+       && (++new_od->optOccCt > new_od->optMaxCt)  )
+        return too_many_occurrences(opts, new_od);
+
+    /*
+     *  Clear the state bits and counters
+     */
+    old_od->fOptState &= OPTST_PERSISTENT_MASK;
+    old_od->optOccCt   = 0;
+
+    /*
+     *  If there is a procedure to call, call it
+     */
+    if (new_od->pOptProc != NULL)
+        (*new_od->pOptProc)(opts, new_od);
+    return 0;
+}
+
+/** @}
+ *
+ * Local Variables:
+ * mode: C
+ * c-file-style: "stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * end of autoopts/alias.c */

+ 374 - 0
libopts/ao-strs.c

@@ -0,0 +1,374 @@
+/*  -*- buffer-read-only: t -*- vi: set ro:
+ *
+ * DO NOT EDIT THIS FILE   (ao-strs.c)
+ *
+ * It has been AutoGen-ed
+ * From the definitions    ao-strs.def
+ * and the template file   strings
+ *
+ *  Copyright (C) 2011-2014 Bruce Korb, all rights reserved.
+ *  This is free software. It is licensed for use, modification and
+ *  redistribution under the terms of the
+ *  Modified (3 clause) Berkeley Software Distribution License
+ *  <http://www.xfree86.org/3.3.6/COPYRIGHT2.html>
+ *
+ *  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 ``Bruce Korb'' nor the name of any other
+ *     contributor may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ *  strings IS PROVIDED BY Bruce Korb ``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 Bruce Korb OR ANY OTHER 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 "ao-strs.h"
+
+char const ao_strs_strtable[6633] =
+/*     0 */ "-_^\0"
+/*     4 */ "  %s%s\n\0"
+/*    12 */ "auto-options\0"
+/*    25 */ "program\0"
+/*    33 */ "%%-%ds %%s\n\0"
+/*    45 */ "\n"
+            "%s\n\n\0"
+/*    51 */ "=file\0"
+/*    57 */ "=Mbr\0"
+/*    62 */ "=Cplx\0"
+/*    68 */ "[=arg]\0"
+/*    75 */ "--%2$s%1$s\0"
+/*    86 */ "=Tim\0"
+/*    91 */ "none\0"
+/*    96 */ "#  preset/initialization file\n"
+            "#  %s#\n\0"
+/*   134 */ " %3s %-14s %s\0"
+/*   148 */ "%s\0"
+/*   151 */ "T/F\0"
+/*   155 */ "\n"
+            "%s\n\n"
+            "%s\0"
+/*   163 */ "Fil\0"
+/*   167 */ "KWd\0"
+/*   171 */ "Mbr\0"
+/*   175 */ "Cpx\0"
+/*   179 */ "no \0"
+/*   183 */ "Num\0"
+/*   187 */ "opt\0"
+/*   191 */ "YES\0"
+/*   195 */ "Str\0"
+/*   199 */ "Tim\0"
+/*   203 */ "\t\t\t\t- \0"
+/*   210 */ "\t\t\t\t  \0"
+/*   217 */ "\t\t\t\t-- and \0"
+/*   229 */ "\t\t\t\t%s\n\0"
+/*   237 */ "      \0"
+/*   244 */ "     \0"
+/*   250 */ "   \0"
+/*   254 */ "  \0"
+/*   257 */ "all\0"
+/*   261 */ " \t\n"
+            ":=\0"
+/*   267 */ "%s_%s_%d=\0"
+/*   277 */ "''\0"
+/*   280 */ "        ;;\n\n\0"
+/*   293 */ "'\n\n\0"
+/*   297 */ "</%s>\n\0"
+/*   304 */ "  %s\n\0"
+/*   310 */ "%%-%ds\0"
+/*   317 */ "\n"
+            "export %s_%s_%d\n\0"
+/*   335 */ "false\0"
+/*   341 */ "    -* )\n\0"
+/*   351 */ "flag\0"
+/*   356 */ "INVALID-%d\0"
+/*   367 */ "*INVALID*\0"
+/*   377 */ "\\n\\\n\0"
+/*   382 */ "    --* )\n\0"
+/*   393 */ "--\0"
+/*   396 */ "LONGUSAGE\0"
+/*   406 */ "            %s\n\0"
+/*   422 */ "\\%03o\0"
+/*   428 */ "more\0"
+/*   433 */ "<%s type=nested>\n\0"
+/*   451 */ "%s\n\0"
+/*   455 */ "%s\n"
+            "  \0"
+/*   461 */ "OPT_ARG_NEEDED=NO\0"
+/*   479 */ "<%s/>\n\0"
+/*   486 */ "OPT_ARG_NEEDED=OK\0"
+/*   504 */ "\t\0"
+/*   506 */ "<%s>\0"
+/*   511 */ "option\0"
+/*   518 */ "\n"
+            "export %s_%s\n\0"
+/*   533 */ "%s_%s=\0"
+/*   540 */ " | \0"
+/*   544 */ "PAGER\0"
+/*   550 */ " + \0"
+/*   554 */ "  puts(_(%s));\n\0"
+/*   570 */ "\\'\0"
+/*   573 */ "'%s'\0"
+/*   578 */ " -- %s\0"
+/*   585 */ "%s_%s_TEXT='\0"
+/*   598 */ "#! %s\n\0"
+/*   605 */ "\n"
+            "env | grep '^%s_'\n\0"
+/*   625 */ "=%1$lu # 0x%1$lX\n\0"
+/*   643 */ "stdout\0"
+/*   650 */ "%A %B %e, %Y at %r %Z\0"
+/*   672 */ "%s/use-%u.XXXXXX\0"
+/*   689 */ "true\0"
+/*   694 */ "<%s type=%s>\0"
+/*   707 */ "VERSION\0"
+/*   715 */ "#x%02X;\0"
+/*   723 */ "OPT_ARG_NEEDED=YES\0"
+/*   742 */ "'\\''\0"
+/*   747 */ " '%s'\0"
+/*   753 */ "\n"
+            "OPTION_CT=0\n\0"
+/*   767 */ "set --\0"
+/*   774 */ "            ;;\n\n\0"
+/*   791 */ "        '%c' )\n\0"
+/*   807 */ "        '%s' )\n\0"
+/*   823 */ "        '%s' | \\\n\0"
+/*   841 */ "TMPDIR\0"
+/*   848 */ "/tmp\0"
+/*   853 */ "%1$s %2$s ; rm -f %2$s\0"
+/*   876 */ "<%1$s type=boolean>%2$s</%1$s>\n\0"
+/*   908 */ "#  From the %s option definitions\n"
+            "#\n\0"
+/*   945 */ "echo 'Warning:  Cannot load options files' >&2\0"
+/*   992 */ "echo 'Warning:  Cannot save options files' >&2\0"
+/*  1039 */ "echo 'Warning:  Cannot suppress the loading of options files' >&2\0"
+/*  1105 */ "<%1$s type=integer>0x%2$lX</%1$s>\n\0"
+/*  1140 */ "%1$s_%2$s_TEXT='no %2$s text'\n\0"
+/*  1171 */ "%1$s_%2$s_MODE='%3$s'\n"
+            "export %1$s_%2$s_MODE\n\0"
+/*  1216 */ "%1$s_%2$s='%3$s'\n"
+            "export %1$s_%2$s\n\0"
+/*  1251 */ "%1$s_%2$s_CT=%3$d\n"
+            "export %1$s_%2$s_CT\n\0"
+/*  1290 */ "OPTION_CT=%d\n"
+            "export OPTION_CT\n\0"
+/*  1321 */ "%1$s_%2$s=%3$s\n"
+            "export %1$s_%2$s\n\0"
+/*  1354 */ "%1$s_%2$s=%3$d # 0x%3$X\n"
+            "export %1$s_%2$s\n\0"
+/*  1396 */ "        case \"${OPT_CODE}\" in\n\0"
+/*  1427 */ "            if [ $%1$s_%2$s_CT -gt %3$u ] ; then\n"
+            "                echo 'Error:  more than %3$d %2$s options'\n"
+            "                echo \"$%1$s_USAGE_TEXT\"\n"
+            "                exit 1\n"
+            "            fi >&2\n\0"
+/*  1618 */ "test ${%1$s_%2$s_CT-0} -ge %3$u || {\n"
+            "    echo %1$s_%2$s has not been set\n"
+            "    exit 1\n"
+            "} 1>&2\n\0"
+/*  1710 */ "test -n \"$%1$s_%2$s\" || {\n"
+            "    echo %1$s_%2$s has not been set\n"
+            "    exit 1\n"
+            "} 1>&2\n\0"
+/*  1791 */ "            echo \"$%s_%s_TEXT\"\n"
+            "            exit 0\n\0"
+/*  1842 */ "\n"
+            "# # # # # # # # # #\n"
+            "#\n"
+            "#  END OF AUTOMATED OPTION PROCESSING\n"
+            "#\n"
+            "# # # # # # # # # # -- do not modify this marker --\n\0"
+/*  1958 */ "    if [ -n \"${OPT_ARG_VAL}\" ]\n"
+            "    then\n"
+            "        eval %1$s_${OPT_NAME}${OPT_ELEMENT}=\"'${OPT_ARG_VAL}'\"\n"
+            "        export %1$s_${OPT_NAME}${OPT_ELEMENT}\n"
+            "    fi\n"
+            "done\n"
+            "OPTION_COUNT=`expr $ARG_COUNT - $#`\n"
+            "OPERAND_COUNT=$#\n"
+            "unset OPT_PROCESS || :\n"
+            "unset OPT_ELEMENT || :\n"
+            "unset OPT_ARG     || :\n"
+            "unset OPT_ARG_NEEDED || :\n"
+            "unset OPT_NAME    || :\n"
+            "unset OPT_CODE    || :\n"
+            "unset OPT_ARG_VAL || :\n\0"
+/*  2337 */ "        OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n"
+            "        shift\n"
+            "        OPT_ARG=$1\n"
+            "        case \"${OPT_CODE}\" in *=* )\n"
+            "            OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n"
+            "            OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\0"
+/*  2588 */ "        OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n"
+            "        OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\0"
+/*  2705 */ "\n"
+            "ARG_COUNT=$#\n"
+            "OPT_PROCESS=true\n"
+            "OPT_ARG=$1\n"
+            "while ${OPT_PROCESS} && [ $# -gt 0 ]\n"
+            "do\n"
+            "    OPT_ELEMENT=''\n"
+            "    OPT_ARG_VAL=''\n\n"
+            "    case \"${OPT_ARG}\" in\n"
+            "    -- )\n"
+            "        OPT_PROCESS=false\n"
+            "        shift\n"
+            "        ;;\n\0"
+/*  2912 */ "        case \"${OPT_ARG_NEEDED}\" in\n"
+            "        NO )\n"
+            "            OPT_ARG_VAL=''\n"
+            "            ;;\n"
+            "        YES )\n"
+            "            if [ -z \"${OPT_ARG_VAL}\" ]\n"
+            "            then\n"
+            "                if [ $# -eq 0 ]\n"
+            "                then\n"
+            "                    echo No argument provided for ${OPT_NAME} option\n"
+            "                    echo \"$%s_USAGE_TEXT\"\n"
+            "                    exit 1\n"
+            "                fi >&2\n"
+            "                OPT_ARG_VAL=${OPT_ARG}\n"
+            "                shift\n"
+            "                OPT_ARG=$1\n"
+            "            fi\n"
+            "            ;;\n"
+            "        OK )\n"
+            "            if [ -z \"${OPT_ARG_VAL}\" ] && [ $# -gt 0 ]\n"
+            "            then\n"
+            "                case \"${OPT_ARG}\" in -* ) ;; * )\n"
+            "                    OPT_ARG_VAL=${OPT_ARG}\n"
+            "                    shift\n"
+            "                    OPT_ARG=$1 ;; esac\n"
+            "            fi\n"
+            "            ;;\n"
+            "        esac\n\0"
+/*  3691 */ "            %1$s_%2$s_CT=`expr ${%1$s_%2$s_CT} + 1`\n"
+            "            OPT_ELEMENT=\"_${%1$s_%2$s_CT}\"\n"
+            "            OPT_NAME='%2$s'\n\0"
+/*  3815 */ "\n"
+            "if test -z \"${%1$s_%2$s}\"\n"
+            "then\n"
+            "  %1$s_%2$s_CT=0\n"
+            "  export %1$s_%2$s_CT\n"
+            "else\n"
+            "  %1$s_%2$s_CT=1\n"
+            "  %1$s_%2$s_1=${%1$s_%2$s}\n"
+            "  export %1$s_%2$s_CT %1$s_%2$s_1\n"
+            "fi\n\0"
+/*  3973 */ "    * )\n"
+            "         OPT_PROCESS=false\n"
+            "         ;;\n"
+            "    esac\n\0"
+/*  4030 */ "            %1$s_%2$s_CT=0\n"
+            "            OPT_ELEMENT=''\n"
+            "            %1$s_%2$s='%3$s'\n"
+            "            export %1$s_%2$s\n"
+            "            OPT_NAME='%2$s'\n\0"
+/*  4171 */ "            if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
+            "                echo 'Error:  duplicate %2$s option'\n"
+            "                echo \"$%1$s_USAGE_TEXT\"\n"
+            "                exit 1\n"
+            "            fi >&2\n"
+            "            %1$s_%2$s_set=true\n"
+            "            %1$s_%2$s='%3$s'\n"
+            "            export %1$s_%2$s\n"
+            "            OPT_NAME='%2$s'\n\0"
+/*  4488 */ "\n"
+            "ARG_COUNT=$#\n"
+            "OPT_ARG=$1\n"
+            "while [ $# -gt 0 ]\n"
+            "do\n"
+            "    OPT_ELEMENT=''\n"
+            "    OPT_ARG_VAL=''\n"
+            "    OPT_ARG=${1}\n\0"
+/*  4591 */ "        case \"${OPT_ARG_NEEDED}\" in\n"
+            "        NO )\n"
+            "            if [ -n \"${OPT_ARG}\" ]\n"
+            "            then\n"
+            "                OPT_ARG=-${OPT_ARG}\n"
+            "            else\n"
+            "                shift\n"
+            "                OPT_ARG=$1\n"
+            "            fi\n"
+            "            ;;\n"
+            "        YES )\n"
+            "            if [ -n \"${OPT_ARG}\" ]\n"
+            "            then\n"
+            "                OPT_ARG_VAL=${OPT_ARG}\n"
+            "            else\n"
+            "                if [ $# -eq 0 ]\n"
+            "                then\n"
+            "                    echo No argument provided for ${OPT_NAME} option\n"
+            "                    echo \"$%s_USAGE_TEXT\"\n"
+            "                    exit 1\n"
+            "                fi >&2\n"
+            "                shift\n"
+            "                OPT_ARG_VAL=$1\n"
+            "            fi\n"
+            "            shift\n"
+            "            OPT_ARG=$1\n"
+            "            ;;\n"
+            "        OK )\n"
+            "            if [ -n \"${OPT_ARG}\" ]\n"
+            "            then\n"
+            "                OPT_ARG_VAL=${OPT_ARG}\n"
+            "                shift\n"
+            "                OPT_ARG=$1\n"
+            "            else\n"
+            "                shift\n"
+            "                if [ $# -gt 0 ]\n"
+            "                then\n"
+            "                    case \"$1\" in -* ) ;; * )\n"
+            "                        OPT_ARG_VAL=$1\n"
+            "                        shift ;; esac\n"
+            "                    OPT_ARG=$1\n"
+            "                fi\n"
+            "            fi\n"
+            "            ;;\n"
+            "        esac\n\0"
+/*  5745 */ "            echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n"
+            "            exit 0\n\0"
+/*  5819 */ "%s OF %s\n"
+            "#\n"
+            "#  From here to the next `-- do not modify this marker --',\n"
+            "#  the text has been generated %s\n\0"
+/*  5925 */ "            eval %1$s_%2$s${OPT_ELEMENT}=true\n"
+            "            export %1$s_%2$s${OPT_ELEMENT}\n\0"
+/*  6015 */ "            if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
+            "                echo 'Error:  duplicate %2$s option'\n"
+            "                echo \"$%1$s_USAGE_TEXT\"\n"
+            "                exit 1\n"
+            "            fi >&2\n"
+            "            %1$s_%2$s_set=true\n"
+            "            OPT_NAME='%2$s'\n\0"
+/*  6274 */ "\n"
+            "%1$s_%2$s=${%1$s_%2$s-'%3$s'}\n"
+            "%1$s_%2$s_set=false\n"
+            "export %1$s_%2$s\n\0"
+/*  6343 */ "\n"
+            "%1$s_%2$s=${%1$s_%2$s}\n"
+            "%1$s_%2$s_set=false\n"
+            "export %1$s_%2$s\n\0"
+/*  6405 */ "# # # # # # # # # # -- do not modify this marker --\n"
+            "#\n"
+            "#  DO NOT EDIT THIS SECTION\n\0"
+/*  6488 */ "        * )\n"
+            "            echo Unknown %s: \"${OPT_CODE}\" >&2\n"
+            "            echo \"$%s_USAGE_TEXT\" >&2\n"
+            "            exit 1\n"
+            "            ;;\n"
+            "        esac\n";
+
+/* end of ao-strs.c */

+ 330 - 0
libopts/ao-strs.h

@@ -0,0 +1,330 @@
+/*  -*- buffer-read-only: t -*- vi: set ro:
+ *
+ * DO NOT EDIT THIS FILE   (ao-strs.h)
+ *
+ * It has been AutoGen-ed
+ * From the definitions    ao-strs.def
+ * and the template file   strings
+ *
+ *  Copyright (C) 2011-2014 Bruce Korb, all rights reserved.
+ *  This is free software. It is licensed for use, modification and
+ *  redistribution under the terms of the
+ *  Modified (3 clause) Berkeley Software Distribution License
+ *  <http://www.xfree86.org/3.3.6/COPYRIGHT2.html>
+ *
+ *  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 ``Bruce Korb'' nor the name of any other
+ *     contributor may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ *  strings IS PROVIDED BY Bruce Korb ``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 Bruce Korb OR ANY OTHER 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.
+ */
+#ifndef STRINGS_AO_STRS_H_GUARD
+#define STRINGS_AO_STRS_H_GUARD 1
+/*
+ * 142 strings in ao_strs_strtable string table
+ */
+#define ARG_BREAK_STR         (ao_strs_strtable+261)
+#define ARG_BREAK_STR_LEN     5
+#define ARG_BY_NUM_FMT        (ao_strs_strtable+267)
+#define ARG_BY_NUM_FMT_LEN    9
+#define BOOL_ATR_FMT          (ao_strs_strtable+876)
+#define BOOL_ATR_FMT_LEN      31
+#define CHK_MAX_COUNT         (ao_strs_strtable+1427)
+#define CHK_MAX_COUNT_LEN     190
+#define CHK_MIN_COUNT         (ao_strs_strtable+1618)
+#define CHK_MIN_COUNT_LEN     91
+#define CHK_ONE_REQUIRED      (ao_strs_strtable+1710)
+#define CHK_ONE_REQUIRED_LEN  80
+#define ECHO_N_EXIT           (ao_strs_strtable+1791)
+#define ECHO_N_EXIT_LEN       50
+#define EMPTY_ARG             (ao_strs_strtable+277)
+#define EMPTY_ARG_LEN         2
+#define END_MARK              (ao_strs_strtable+1842)
+#define END_MARK_LEN          115
+#define END_OPT_SEL_STR       (ao_strs_strtable+280)
+#define END_OPT_SEL_STR_LEN   12
+#define END_PRE_FMT           (ao_strs_strtable+908)
+#define END_PRE_FMT_LEN       36
+#define END_SET_TEXT          (ao_strs_strtable+293)
+#define END_SET_TEXT_LEN      3
+#define END_XML_FMT           (ao_strs_strtable+297)
+#define END_XML_FMT_LEN       6
+#define ENUM_ERR_LINE         (ao_strs_strtable+304)
+#define ENUM_ERR_LINE_LEN     5
+#define ENUM_ERR_WIDTH        (ao_strs_strtable+310)
+#define ENUM_ERR_WIDTH_LEN    6
+#define EXPORT_ARG_FMT        (ao_strs_strtable+317)
+#define EXPORT_ARG_FMT_LEN    17
+#define FALSE_STR             (ao_strs_strtable+335)
+#define FALSE_STR_LEN         5
+#define FINISH_LOOP           (ao_strs_strtable+1958)
+#define FINISH_LOOP_LEN       378
+#define FLAG_OPT_MARK         (ao_strs_strtable+341)
+#define FLAG_OPT_MARK_LEN     9
+#define FLAG_STR              (ao_strs_strtable+351)
+#define FLAG_STR_LEN          4
+#define INIT_LOPT_STR         (ao_strs_strtable+2337)
+#define INIT_LOPT_STR_LEN     250
+#define INIT_OPT_STR          (ao_strs_strtable+2588)
+#define INIT_OPT_STR_LEN      116
+#define INVALID_FMT           (ao_strs_strtable+356)
+#define INVALID_FMT_LEN       10
+#define INVALID_STR           (ao_strs_strtable+367)
+#define INVALID_STR_LEN       9
+#define LINE_SPLICE           (ao_strs_strtable+377)
+#define LINE_SPLICE_LEN       4
+#define LONG_OPT_MARK         (ao_strs_strtable+382)
+#define LONG_OPT_MARKER       (ao_strs_strtable+393)
+#define LONG_OPT_MARKER_LEN   2
+#define LONG_OPT_MARK_LEN     10
+#define LONG_USE_STR          (ao_strs_strtable+396)
+#define LONG_USE_STR_LEN      9
+#define LOOP_STR              (ao_strs_strtable+2705)
+#define LOOP_STR_LEN          206
+#define LOPT_ARG_FMT          (ao_strs_strtable+2912)
+#define LOPT_ARG_FMT_LEN      778
+#define LVL3_CMD              (ao_strs_strtable+406)
+#define LVL3_CMD_LEN          15
+#define MK_STR_OCT_FMT        (ao_strs_strtable+422)
+#define MK_STR_OCT_FMT_LEN    5
+#define MORE_STR              (ao_strs_strtable+428)
+#define MORE_STR_LEN          4
+#define MULTI_ARG_FMT         (ao_strs_strtable+3691)
+#define MULTI_ARG_FMT_LEN     123
+#define MULTI_DEF_FMT         (ao_strs_strtable+3815)
+#define MULTI_DEF_FMT_LEN     157
+#define NESTED_OPT_FMT        (ao_strs_strtable+433)
+#define NESTED_OPT_FMT_LEN    17
+#define NLSTR_FMT             (ao_strs_strtable+451)
+#define NLSTR_FMT_LEN         3
+#define NLSTR_SPACE_FMT       (ao_strs_strtable+455)
+#define NLSTR_SPACE_FMT_LEN   5
+#define NONE_STR              (ao_strs_strtable+91)
+#define NONE_STR_LEN          4
+#define NOT_FOUND_STR         (ao_strs_strtable+3973)
+#define NOT_FOUND_STR_LEN     56
+#define NO_ARG_NEEDED         (ao_strs_strtable+461)
+#define NO_ARG_NEEDED_LEN     17
+#define NO_LOAD_WARN          (ao_strs_strtable+945)
+#define NO_LOAD_WARN_LEN      46
+#define NO_MULTI_ARG_FMT      (ao_strs_strtable+4030)
+#define NO_MULTI_ARG_FMT_LEN  140
+#define NO_SAVE_OPTS          (ao_strs_strtable+992)
+#define NO_SAVE_OPTS_LEN      46
+#define NO_SGL_ARG_FMT        (ao_strs_strtable+4171)
+#define NO_SGL_ARG_FMT_LEN    316
+#define NO_SUPPRESS_LOAD      (ao_strs_strtable+1039)
+#define NO_SUPPRESS_LOAD_LEN  65
+#define NULL_ATR_FMT          (ao_strs_strtable+479)
+#define NULL_ATR_FMT_LEN      6
+#define NUMB_ATR_FMT          (ao_strs_strtable+1105)
+#define NUMB_ATR_FMT_LEN      34
+#define OK_NEED_OPT_ARG       (ao_strs_strtable+486)
+#define OK_NEED_OPT_ARG_LEN   17
+#define ONE_TAB_STR           (ao_strs_strtable+504)
+#define ONE_TAB_STR_LEN       1
+#define ONLY_OPTS_LOOP        (ao_strs_strtable+4488)
+#define ONLY_OPTS_LOOP_LEN    102
+#define OPEN_CLOSE_FMT        (ao_strs_strtable+479)
+#define OPEN_CLOSE_FMT_LEN    6
+#define OPEN_XML_FMT          (ao_strs_strtable+506)
+#define OPEN_XML_FMT_LEN      4
+#define OPTION_STR            (ao_strs_strtable+511)
+#define OPTION_STR_LEN        6
+#define OPT_ARG_FMT           (ao_strs_strtable+4591)
+#define OPT_ARG_FMT_LEN       1153
+#define OPT_END_FMT           (ao_strs_strtable+518)
+#define OPT_END_FMT_LEN       14
+#define OPT_VAL_FMT           (ao_strs_strtable+533)
+#define OPT_VAL_FMT_LEN       6
+#define OR_STR                (ao_strs_strtable+540)
+#define OR_STR_LEN            3
+#define PAGER_NAME            (ao_strs_strtable+544)
+#define PAGER_NAME_LEN        5
+#define PAGE_USAGE_FMT        (ao_strs_strtable+853)
+#define PAGE_USAGE_FMT_LEN    22
+#define PAGE_USAGE_TEXT       (ao_strs_strtable+5745)
+#define PAGE_USAGE_TEXT_LEN   73
+#define PLUS_STR              (ao_strs_strtable+550)
+#define PLUS_STR_LEN          3
+#define PREAMBLE_FMT          (ao_strs_strtable+5819)
+#define PREAMBLE_FMT_LEN      105
+#define PUTS_FMT              (ao_strs_strtable+554)
+#define PUTS_FMT_LEN          15
+#define QUOT_APOS             (ao_strs_strtable+570)
+#define QUOT_APOS_LEN         2
+#define QUOT_ARG_FMT          (ao_strs_strtable+573)
+#define QUOT_ARG_FMT_LEN      4
+#define SET_MULTI_ARG         (ao_strs_strtable+5925)
+#define SET_MULTI_ARG_LEN     89
+#define SET_NO_TEXT_FMT       (ao_strs_strtable+1140)
+#define SET_NO_TEXT_FMT_LEN   30
+#define SET_OFF_FMT           (ao_strs_strtable+578)
+#define SET_OFF_FMT_LEN       6
+#define SET_TEXT_FMT          (ao_strs_strtable+585)
+#define SET_TEXT_FMT_LEN      12
+#define SGL_ARG_FMT           (ao_strs_strtable+6015)
+#define SGL_ARG_FMT_LEN       258
+#define SGL_DEF_FMT           (ao_strs_strtable+6274)
+#define SGL_DEF_FMT_LEN       68
+#define SGL_NO_DEF_FMT        (ao_strs_strtable+6343)
+#define SGL_NO_DEF_FMT_LEN    61
+#define SHELL_MAGIC           (ao_strs_strtable+598)
+#define SHELL_MAGIC_LEN       6
+#define SHOW_PROG_ENV         (ao_strs_strtable+605)
+#define SHOW_PROG_ENV_LEN     19
+#define SHOW_VAL_FMT          (ao_strs_strtable+625)
+#define SHOW_VAL_FMT_LEN      17
+#define START_MARK            (ao_strs_strtable+6405)
+#define START_MARK_LEN        82
+#define STDOUT                (ao_strs_strtable+643)
+#define STDOUT_LEN            6
+#define TIME_FMT              (ao_strs_strtable+650)
+#define TIME_FMT_LEN          21
+#define TMPDIR                (ao_strs_strtable+841)
+#define TMPDIR_LEN            6
+#define TMP_FILE_FMT          (ao_strs_strtable+672)
+#define TMP_FILE_FMT_LEN      16
+#define TMP_USAGE_FMT         (ao_strs_strtable+672)
+#define TMP_USAGE_FMT_LEN     16
+#define TRUE_STR              (ao_strs_strtable+689)
+#define TRUE_STR_LEN          4
+#define TWO_SPACES_STR        (ao_strs_strtable+254)
+#define TWO_SPACES_STR_LEN    2
+#define TYPE_ATR_FMT          (ao_strs_strtable+694)
+#define TYPE_ATR_FMT_LEN      12
+#define UNK_OPT_FMT           (ao_strs_strtable+6488)
+#define UNK_OPT_FMT_LEN       144
+#define VER_STR               (ao_strs_strtable+707)
+#define VER_STR_LEN           7
+#define XML_HEX_BYTE_FMT      (ao_strs_strtable+715)
+#define XML_HEX_BYTE_FMT_LEN  7
+#define YES_NEED_OPT_ARG      (ao_strs_strtable+723)
+#define YES_NEED_OPT_ARG_LEN  18
+#define apostrophe            (ao_strs_strtable+742)
+#define apostrophe_LEN        4
+#define arg_fmt               (ao_strs_strtable+747)
+#define arg_fmt_LEN           5
+#define init_optct            (ao_strs_strtable+753)
+#define init_optct_LEN        13
+#define set_dash              (ao_strs_strtable+767)
+#define set_dash_LEN          6
+#define tmp_dir               (ao_strs_strtable+848)
+#define tmp_dir_LEN           4
+#define zAll                  (ao_strs_strtable+257)
+#define zAll_LEN              3
+#define zCfgAO_Flags          (ao_strs_strtable+12)
+#define zCfgAO_Flags_LEN      12
+#define zCfgProg              (ao_strs_strtable+25)
+#define zCfgProg_LEN          7
+#define zEquivMode            (ao_strs_strtable+1171)
+#define zEquivMode_LEN        44
+#define zFiveSpaces           (ao_strs_strtable+244)
+#define zFiveSpaces_LEN       5
+#define zFmtFmt               (ao_strs_strtable+33)
+#define zFmtFmt_LEN           11
+#define zFullOptFmt           (ao_strs_strtable+1216)
+#define zFullOptFmt_LEN       34
+#define zGnuBreak             (ao_strs_strtable+45)
+#define zGnuBreak_LEN         5
+#define zGnuFileArg           (ao_strs_strtable+51)
+#define zGnuFileArg_LEN       5
+#define zGnuKeyLArg           (ao_strs_strtable+57)
+#define zGnuKeyLArg_LEN       4
+#define zGnuNestArg           (ao_strs_strtable+62)
+#define zGnuNestArg_LEN       5
+#define zGnuOptArg            (ao_strs_strtable+68)
+#define zGnuOptArg_LEN        6
+#define zGnuOptFmt            (ao_strs_strtable+75)
+#define zGnuOptFmt_LEN        10
+#define zGnuTimeArg           (ao_strs_strtable+86)
+#define zGnuTimeArg_LEN       4
+#define zNone                 (ao_strs_strtable+91)
+#define zNone_LEN             4
+#define zOptCookieCt          (ao_strs_strtable+1251)
+#define zOptCookieCt_LEN      38
+#define zOptCtFmt             (ao_strs_strtable+1290)
+#define zOptCtFmt_LEN         30
+#define zOptDisabl            (ao_strs_strtable+1321)
+#define zOptDisabl_LEN        32
+#define zOptNumFmt            (ao_strs_strtable+1354)
+#define zOptNumFmt_LEN        41
+#define zOptionCase           (ao_strs_strtable+1396)
+#define zOptionCase_LEN       30
+#define zOptionEndSelect      (ao_strs_strtable+774)
+#define zOptionEndSelect_LEN  16
+#define zOptionFlag           (ao_strs_strtable+791)
+#define zOptionFlag_LEN       15
+#define zOptionFullName       (ao_strs_strtable+807)
+#define zOptionFullName_LEN   15
+#define zOptionPartName       (ao_strs_strtable+823)
+#define zOptionPartName_LEN   17
+#define zPresetFile           (ao_strs_strtable+96)
+#define zPresetFile_LEN       37
+#define zReqOptFmt            (ao_strs_strtable+134)
+#define zReqOptFmt_LEN        13
+#define zSepChars             (ao_strs_strtable+0)
+#define zSepChars_LEN         3
+#define zShrtGnuOptFmt        (ao_strs_strtable+148)
+#define zShrtGnuOptFmt_LEN    2
+#define zSixSpaces            (ao_strs_strtable+237)
+#define zSixSpaces_LEN        6
+#define zStdBoolArg           (ao_strs_strtable+151)
+#define zStdBoolArg_LEN       3
+#define zStdBreak             (ao_strs_strtable+155)
+#define zStdBreak_LEN         7
+#define zStdFileArg           (ao_strs_strtable+163)
+#define zStdFileArg_LEN       3
+#define zStdKeyArg            (ao_strs_strtable+167)
+#define zStdKeyArg_LEN        3
+#define zStdKeyLArg           (ao_strs_strtable+171)
+#define zStdKeyLArg_LEN       3
+#define zStdNestArg           (ao_strs_strtable+175)
+#define zStdNestArg_LEN       3
+#define zStdNoArg             (ao_strs_strtable+179)
+#define zStdNoArg_LEN         3
+#define zStdNumArg            (ao_strs_strtable+183)
+#define zStdNumArg_LEN        3
+#define zStdOptArg            (ao_strs_strtable+187)
+#define zStdOptArg_LEN        3
+#define zStdReqArg            (ao_strs_strtable+191)
+#define zStdReqArg_LEN        3
+#define zStdStrArg            (ao_strs_strtable+195)
+#define zStdStrArg_LEN        3
+#define zStdTimeArg           (ao_strs_strtable+199)
+#define zStdTimeArg_LEN       3
+#define zTabHyp               (ao_strs_strtable+203)
+#define zTabHypAnd            (ao_strs_strtable+217)
+#define zTabHypAnd_LEN        11
+#define zTabHyp_LEN           6
+#define zTabSpace             (ao_strs_strtable+210)
+#define zTabSpace_LEN         6
+#define zTabout               (ao_strs_strtable+229)
+#define zTabout_LEN           7
+#define zThreeSpaces          (ao_strs_strtable+250)
+#define zThreeSpaces_LEN      3
+#define zTwoSpaces            (ao_strs_strtable+254)
+#define zTwoSpaces_LEN        2
+#define zambig_file           (ao_strs_strtable+4)
+#define zambig_file_LEN       7
+extern char const ao_strs_strtable[6633];
+
+#endif /* STRINGS_AO_STRS_H_GUARD */

File diff suppressed because it is too large
+ 144 - 911
libopts/autoopts.c


+ 230 - 110
libopts/autoopts.h

@@ -1,15 +1,17 @@
 
 /*
- *  Time-stamp:      "2008-11-01 20:08:06 bkorb"
- *
- *  autoopts.h  $Id: autoopts.h,v 4.42 2009/08/01 17:43:05 bkorb Exp $
+ *  \file autoopts.h
  *
  *  This file defines all the global structures and special values
  *  used in the automated option processing library.
  *
+ * @group autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,18 +23,16 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 #ifndef AUTOGEN_AUTOOPTS_H
 #define AUTOGEN_AUTOOPTS_H
-
-#include "compat/compat.h"
-#include "ag-char-map.h"
+#include <stdnoreturn.h>
 
 #define AO_NAME_LIMIT           127
 #define AO_NAME_SIZE            ((size_t)(AO_NAME_LIMIT + 1))
@@ -41,7 +41,7 @@
 #  ifdef PATH_MAX
 #    define AG_PATH_MAX         ((size_t)PATH_MAX)
 #  else
-#    define AG_PATH_MAX         ((size_t)4096)
+#    define AG_PATH_MAX         4096
 #  endif
 #else
 #  if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
@@ -53,22 +53,72 @@
 #undef  EXPORT
 #define EXPORT
 
+#ifndef NUL
+#define NUL                     '\0'
+#endif
+#define BEL                     '\a'
+#define BS                      '\b'
+#define HT                      '\t'
+#define LF                      '\n'
+#define VT                      '\v'
+#define FF                      '\f'
+#define CR                      '\r'
+
 #if defined(_WIN32) && !defined(__CYGWIN__)
 # define DIRCH                  '\\'
 #else
 # define DIRCH                  '/'
 #endif
 
+#ifndef EX_USAGE
+   /**
+    *  Command line usage problem
+    */
+#  define EX_USAGE              64
+#endif
+#ifndef EX_DATAERR
+   /**
+    *  The input data was incorrect in some way.
+    */
+#  define EX_DATAERR            64
+#endif
 #ifndef EX_NOINPUT
+   /**
+    *  option state was requested from a file that cannot be loaded.
+    */
 #  define EX_NOINPUT            66
 #endif
 #ifndef EX_SOFTWARE
+   /**
+    *  AutoOpts Software failure.
+    */
 #  define EX_SOFTWARE           70
 #endif
-#ifndef EX_CONFIG
-#  define EX_CONFIG             78
+#ifndef EX_OSERR
+   /**
+    *  Command line usage problem
+    */
+#  define EX_OSERR              71
+#endif
+
+#define NL '\n'
+#ifndef C
+/**
+ *  Coercive cast.  Compel an address to be interpreted as the type
+ *  of the first argument.  No complaints, just do it.
+ */
+#define C(_t,_p)  ((_t)(void *)(_p))
 #endif
 
+/* The __attribute__((__warn_unused_result__)) feature
+   is available in gcc versions 3.4 and newer,
+   while the typeof feature has been available since 2.7 at least.  */
+# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
+#  define ignore_val(x) ((void) (x))
+# else
+#  define ignore_val(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
+# endif
+
 /*
  *  Convert the number to a list usable in a printf call
  */
@@ -77,74 +127,59 @@
 #define NAMED_OPTS(po) \
         (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
 
-#define SKIP_OPT(p)  (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
+#define SKIP_OPT(p)  (((p)->fOptState & OPTST_IMMUTABLE_MASK) != 0)
 
 typedef int tDirection;
+/**
+ * handling option presets.  Start with command line and work through
+ * config settings in reverse order.
+ */
 #define DIRECTION_PRESET        -1
+/**
+ * handling normal options.  Start with first config file, then environment
+ * variables and finally the command line.
+ */
 #define DIRECTION_PROCESS       1
+/**
+ * An initialzation phase or an option being loaded from program sources.
+ */
 #define DIRECTION_CALLED        0
 
 #define PROCESSING(d)           ((d)>0)
 #define PRESETTING(d)           ((d)<0)
+#define CALLED(d)               ((d)==0)
 
-/*
- *  Procedure success codes
- *
- *  USAGE:  define procedures to return "tSuccess".  Test their results
- *          with the SUCCEEDED, FAILED and HADGLITCH macros.
- *
- *  Microsoft sticks its nose into user space here, so for Windows' sake,
- *  make sure all of these are undefined.
- */
-#undef  SUCCESS
-#undef  FAILURE
-#undef  PROBLEM
-#undef  SUCCEEDED
-#undef  SUCCESSFUL
-#undef  FAILED
-#undef  HADGLITCH
-
-#define SUCCESS                 ((tSuccess) 0)
-#define FAILURE                 ((tSuccess)-1)
-#define PROBLEM                 ((tSuccess) 1)
-
-typedef int tSuccess;
-
-#define SUCCEEDED( p )          ((p) == SUCCESS)
-#define SUCCESSFUL( p )         SUCCEEDED( p )
-#define FAILED( p )             ((p) <  SUCCESS)
-#define HADGLITCH( p )          ((p) >  SUCCESS)
-
-/*
+/**
  *  When loading a line (or block) of text as an option, the value can
- *  be processed in any of several modes:
- *
- *  @table @samp
- *  @item keep
- *  Every part of the value between the delimiters is saved.
- *
- *  @item uncooked
- *  Even if the value begins with quote characters, do not do quote processing.
- *
- *  @item cooked
- *  If the value looks like a quoted string, then process it.
- *  Double quoted strings are processed the way strings are in "C" programs,
- *  except they are treated as regular characters if the following character
- *  is not a well-established escape sequence.
- *  Single quoted strings (quoted with apostrophies) are handled the way
- *  strings are handled in shell scripts, *except* that backslash escapes
- *  are honored before backslash escapes and apostrophies.
- *  @end table
+ *  be processed in any of several modes.
  */
 typedef enum {
+    /**
+     *  If the value looks like a quoted string, then process it.  Double
+     *  quoted strings are processed the way strings are in "C" programs,
+     *  except they are treated as regular characters if the following
+     *  character is not a well-established escape sequence.  Single quoted
+     *  strings (quoted with apostrophies) are handled the way strings are
+     *  handled in shell scripts, *except* that backslash escapes are
+     *  honored before backslash escapes and apostrophies.
+     */
     OPTION_LOAD_COOKED,
+
+    /**
+     * Even if the value begins with quote characters, do not do quote
+     * processing.  Strip leading and trailing white space.
+     */
     OPTION_LOAD_UNCOOKED,
+
+    /**
+     * Keep every part of the value between the delimiters.
+     */
     OPTION_LOAD_KEEP
 } tOptionLoadMode;
 
-extern tOptionLoadMode option_load_mode;
+static tOptionLoadMode option_load_mode;
 
-/*
+/**
  *  The pager state is used by optionPagedUsage() procedure.
  *  When it runs, it sets itself up to be called again on exit.
  *  If, however, a routine needs a child process to do some work
@@ -153,13 +188,19 @@ extern tOptionLoadMode option_load_mode;
  *  to run the pager program before its time.
  */
 typedef enum {
-    PAGER_STATE_INITIAL,
+    PAGER_STATE_INITIAL, //@< initial option paging state
+
+    /**
+     * temp file created and optionPagedUsage is scheduled to run at exit
+     */
     PAGER_STATE_READY,
+
+    /**
+     *  This is a child process used in creating shell script usage.
+     */
     PAGER_STATE_CHILD
 } tePagerState;
 
-extern tePagerState pagerState;
-
 typedef enum {
     ENV_ALL,
     ENV_IMM,
@@ -174,18 +215,18 @@ typedef enum {
 } teOptType;
 
 typedef struct {
-    tOptDesc*  pOD;
-    tCC*       pzOptArg;
-    tAoUL      flags;
-    teOptType  optType;
+    tOptDesc *          pOD;
+    char const *        pzOptArg;
+    opt_state_mask_t    flags;
+    teOptType           optType;
 } tOptState;
 #define OPTSTATE_INITIALIZER(st) \
     { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
 
 #define TEXTTO_TABLE \
-        _TT_( LONGUSAGE ) \
-        _TT_( USAGE ) \
-        _TT_( VERSION )
+        _TT_(LONGUSAGE) \
+        _TT_(USAGE) \
+        _TT_(VERSION)
 #define _TT_(n) \
         TT_ ## n ,
 
@@ -193,44 +234,45 @@ typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
 
 #undef _TT_
 
+/**
+ * option argument types.  Used to create usage information for
+ * particular options.
+ */
 typedef struct {
-    tCC*    pzStr;
-    tCC*    pzReq;
-    tCC*    pzNum;
-    tCC*    pzFile;
-    tCC*    pzKey;
-    tCC*    pzKeyL;
-    tCC*    pzBool;
-    tCC*    pzNest;
-    tCC*    pzOpt;
-    tCC*    pzNo;
-    tCC*    pzBrk;
-    tCC*    pzNoF;
-    tCC*    pzSpc;
-    tCC*    pzOptFmt;
-    tCC*    pzTime;
+    char const * pzStr;
+    char const * pzReq;
+    char const * pzNum;
+    char const * pzFile;
+    char const * pzKey;
+    char const * pzKeyL;
+    char const * pzBool;
+    char const * pzNest;
+    char const * pzOpt;
+    char const * pzNo;
+    char const * pzBrk;
+    char const * pzNoF;
+    char const * pzSpc;
+    char const * pzOptFmt;
+    char const * pzTime;
 } arg_types_t;
 
-#define AGALOC( c, w )          ao_malloc((size_t)c)
-#define AGREALOC( p, c, w )     ao_realloc((void*)p, (size_t)c)
-#define AGFREE(_p)              do{void*X=(void*)_p;ao_free(X);}while(0)
-#define AGDUPSTR( p, s, w )     (p = ao_strdup(s))
+#define AGALOC(c, w)          ao_malloc((size_t)c)
+#define AGREALOC(p, c, w)     ao_realloc((void*)p, (size_t)c)
+#define AGFREE(_p)            free((void *)_p)
+#define AGDUPSTR(p, s, w)     (p = ao_strdup(s))
 
 static void *
-ao_malloc( size_t sz );
+ao_malloc(size_t sz);
 
 static void *
-ao_realloc( void *p, size_t sz );
+ao_realloc(void *p, size_t sz);
 
-static void
-ao_free( void *p );
+#define ao_free(_p) free((void *)_p)
 
 static char *
-ao_strdup( char const *str );
-
-#define TAGMEM( m, t )
+ao_strdup(char const *str);
 
-/*
+/**
  *  DO option handling?
  *
  *  Options are examined at two times:  at immediate handling time and at
@@ -260,7 +302,8 @@ ao_strdup( char const *str );
     || (   ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM))    \
         == (OPTST_DISABLED|OPTST_DISABLE_IMM)  ))
 
-/*  B) handling at "regular" time because it was not immediate
+/**
+ *  B) handling at "regular" time because it was not immediate
  *
  *  1.  OPTST_DISABLED is not set:
  *      IMM           must *NOT* be set
@@ -281,7 +324,8 @@ ao_strdup( char const *str );
     || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM))    ==     \
                   OPTST_DISABLED)  )
 
-/*  C)  handling at "regular" time because it is to be handled twice.
+/**
+ *  C)  handling at "regular" time because it is to be handled twice.
  *      The immediate bit was already tested and found to be set:
  *
  *  3.  OPTST_DISABLED is not set:
@@ -335,11 +379,21 @@ ao_strdup( char const *str );
 #endif
 
 #ifndef HAVE_STRCHR
-extern char* strchr( char const *s, int c);
-extern char* strrchr( char const *s, int c);
+extern char* strchr(char const *s, int c);
+extern char* strrchr(char const *s, int c);
 #endif
 
-/*
+/**
+ * INQUERY_CALL() tests whether the option handling function has been
+ * called by an inquery (help text needed, or option being reset),
+ * or called by a set-the-option operation.
+ */
+#define INQUERY_CALL(_o, _d) (                  \
+    ((_o) <= OPTPROC_EMIT_LIMIT)                \
+    || ((_d) == NULL)                           \
+    || (((_d)->fOptState & OPTST_RESET) != 0) )
+
+/**
  *  Define and initialize all the user visible strings.
  *  We do not do translations.  If translations are to be done, then
  *  the client will provide a callback for that purpose.
@@ -347,15 +401,81 @@ extern char* strrchr( char const *s, int c);
 #undef DO_TRANSLATIONS
 #include "autoopts/usage-txt.h"
 
-/*
+/**
  *  File pointer for usage output
  */
-extern FILE* option_usage_fp;
-
+FILE * option_usage_fp;
+/**
+ *  If provided in the option structure
+ */
+static char const * program_pkgdatadir;
+/**
+ * privately exported functions
+ */
 extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
 
+#ifdef AUTOOPTS_INTERNAL
+
+#ifndef PKGDATADIR
+#  define PKGDATADIR ""
+#endif
+#define APOSTROPHE '\''
+
+#define OPTPROC_L_N_S  (OPTPROC_LONGOPT | OPTPROC_SHORTOPT)
+#if defined(ENABLE_NLS) && defined(HAVE_LIBINTL_H)
+# include <libintl.h>
+#endif
+
+typedef struct {
+    size_t          fnm_len;
+    uint32_t        fnm_mask;
+    char const *    fnm_name;
+} ao_flag_names_t;
+
+/**
+ * Automated Options Usage Flags.
+ * NB: no entry may be a prefix of another entry
+ */
+#define AOFLAG_TABLE                            \
+    _aof_(gnu,             OPTPROC_GNUUSAGE )   \
+    _aof_(autoopts,        ~OPTPROC_GNUUSAGE)   \
+    _aof_(no_misuse_usage, OPTPROC_MISUSE   )   \
+    _aof_(misuse_usage,    ~OPTPROC_MISUSE  )   \
+    _aof_(compute,         OPTPROC_COMPUTE  )
+
+#define _aof_(_n, _f)   AOUF_ ## _n ## _ID,
+typedef enum { AOFLAG_TABLE AOUF_COUNT } ao_flag_id_t;
+#undef  _aof_
+
+#define _aof_(_n, _f)   AOUF_ ## _n = (1 << AOUF_ ## _n ## _ID),
+typedef enum { AOFLAG_TABLE } ao_flags_t;
+#undef  _aof_
+
+static char const   zNil[] = "";
+static arg_types_t  argTypes             = { NULL };
+static char         line_fmt_buf[32];
+static bool         displayEnum          = false;
+static char const   pkgdatadir_default[] = PKGDATADIR;
+static char const * program_pkgdatadir   = pkgdatadir_default;
+static tOptionLoadMode option_load_mode  = OPTION_LOAD_UNCOOKED;
+static tePagerState pagerState           = PAGER_STATE_INITIAL;
+
+       FILE *       option_usage_fp      = NULL;
+
+static char const * pz_enum_err_fmt;
+
+tOptions * optionParseShellOptions = NULL;
+
+static char const * shell_prog = NULL;
+static char * script_leader    = NULL;
+static char * script_trailer   = NULL;
+static char * script_text      = NULL;
+static bool   print_exit       = false;
+#endif /* AUTOOPTS_INTERNAL */
+
 #endif /* AUTOGEN_AUTOOPTS_H */
-/*
+/**
+ * @}
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

File diff suppressed because it is too large
+ 765 - 561
libopts/autoopts/options.h


+ 77 - 0
libopts/autoopts/project.h

@@ -0,0 +1,77 @@
+
+/**
+ * \file project.h
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+#ifndef AUTOGEN_PROJECT_H
+#define AUTOGEN_PROJECT_H
+
+#include "config.h"
+#include "compat/compat.h"
+#include "ag-char-map.h"
+
+/*
+ *  Procedure success codes
+ *
+ *  USAGE:  define procedures to return "tSuccess".  Test their results
+ *          with the SUCCEEDED, FAILED and HADGLITCH macros.
+ *
+ *  Microsoft sticks its nose into user space here, so for Windows' sake,
+ *  make sure all of these are undefined.
+ */
+#undef  SUCCESS
+#undef  FAILURE
+#undef  PROBLEM
+#undef  SUCCEEDED
+#undef  SUCCESSFUL
+#undef  FAILED
+#undef  HADGLITCH
+
+#define SUCCESS  ((tSuccess) 0)
+#define FAILURE  ((tSuccess)-1)
+#define PROBLEM  ((tSuccess) 1)
+
+typedef int tSuccess;
+
+#define SUCCEEDED(p)    ((p) == SUCCESS)
+#define SUCCESSFUL(p)   SUCCEEDED(p)
+#define FAILED(p)       ((p) <  SUCCESS)
+#define HADGLITCH(p)    ((p) >  SUCCESS)
+
+#ifndef STR
+#  define __STR(s)      #s
+#  define STR(s)        __STR(s)
+#endif
+
+#ifdef DEFINING
+#  define VALUE(s)      = s
+#  define MODE
+#else
+#  define VALUE(s)
+#  define MODE extern
+#endif
+
+#define parse_duration option_parse_duration
+
+#endif /* AUTOGEN_PROJECT_H */
+/* end of project.h */

File diff suppressed because it is too large
+ 627 - 363
libopts/autoopts/usage-txt.h


+ 30 - 26
libopts/boolean.c

@@ -1,16 +1,19 @@
 
-/*
- *  $Id: boolean.c,v 4.16 2009/08/01 17:43:05 bkorb Exp $
- * Time-stamp:      "2008-08-03 13:06:02 bkorb"
+/**
+ * \file boolean.c
  *
- *   Automated Options Paged Usage module.
+ * Handle options with true/false values for arguments.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This routine will run run-on options through a pager so the
  *  user may examine, print or edit them at their leisure.
  *
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -22,19 +25,19 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /*=export_func  optionBooleanVal
  * private:
  *
  * what:  Decipher a boolean value
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od  + the descriptor for this arg +
  *
  * doc:
  *  Decipher a true or false value for a boolean valued option argument.
@@ -42,23 +45,23 @@
  *  it is an empty string or it is a number that evaluates to zero.
 =*/
 void
-optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
+optionBooleanVal(tOptions * opts, tOptDesc * od)
 {
     char* pz;
-    ag_bool  res = AG_TRUE;
+    bool  res = true;
 
-    if ((pOD->fOptState & OPTST_RESET) != 0)
+    if (INQUERY_CALL(opts, od))
         return;
 
-    if (pOD->optArg.argString == NULL) {
-        pOD->optArg.argBool = AG_FALSE;
+    if (od->optArg.argString == NULL) {
+        od->optArg.argBool = false;
         return;
     }
 
-    switch (*(pOD->optArg.argString)) {
+    switch (*(od->optArg.argString)) {
     case '0':
     {
-        long  val = strtol( pOD->optArg.argString, &pz, 0 );
+        long  val = strtol(od->optArg.argString, &pz, 0);
         if ((val != 0) || (*pz != NUL))
             break;
         /* FALLTHROUGH */
@@ -68,21 +71,22 @@ optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
     case 'F':
     case 'f':
     case NUL:
-        res = AG_FALSE;
+        res = false;
         break;
     case '#':
-        if (pOD->optArg.argString[1] != 'f')
+        if (od->optArg.argString[1] != 'f')
             break;
-        res = AG_FALSE;
+        res = false;
     }
 
-    if (pOD->fOptState & OPTST_ALLOC_ARG) {
-        AGFREE(pOD->optArg.argString);
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
+    if (od->fOptState & OPTST_ALLOC_ARG) {
+        AGFREE(od->optArg.argString);
+        od->fOptState &= ~OPTST_ALLOC_ARG;
     }
-    pOD->optArg.argBool = res;
+    od->optArg.argBool = res;
 }
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 177 - 0
libopts/check.c

@@ -0,0 +1,177 @@
+/**
+ * @file check.c
+ *
+ * @brief option consistency checks.
+ *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+/**
+ *  Check for conflicts based on "must" and "cannot" attributes.
+ */
+static bool
+has_conflict(tOptions * pOpts, tOptDesc * od)
+{
+    if (od->pOptMust != NULL) {
+        int const * must = od->pOptMust;
+
+        while (*must != NO_EQUIVALENT) {
+            tOptDesc * p = pOpts->pOptDesc + *(must++);
+            if (UNUSED_OPT(p)) {
+                const tOptDesc * ood = pOpts->pOptDesc + must[-1];
+                fprintf(stderr, zneed_fmt, pOpts->pzProgName,
+                        od->pz_Name, ood->pz_Name);
+                return true;
+            }
+        }
+    }
+
+    if (od->pOptCant != NULL) {
+        int const * cant = od->pOptCant;
+
+        while (*cant != NO_EQUIVALENT) {
+            tOptDesc * p = pOpts->pOptDesc + *(cant++);
+            if (SELECTED_OPT(p)) {
+                const tOptDesc * ood = pOpts->pOptDesc + cant[-1];
+                fprintf(stderr, zconflict_fmt, pOpts->pzProgName,
+                        od->pz_Name, ood->pz_Name);
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+/**
+ *  Check that the option occurs often enough.  Too often is already checked.
+ */
+static bool
+occurs_enough(tOptions * pOpts, tOptDesc * pOD)
+{
+    (void)pOpts;
+
+    /*
+     *  IF the occurrence counts have been satisfied,
+     *  THEN there is no problem.
+     */
+    if (pOD->optOccCt >= pOD->optMinCt)
+        return true;
+
+    /*
+     *  IF MUST_SET means SET and PRESET are okay,
+     *  so min occurrence count doesn't count
+     */
+    if (  (pOD->fOptState & OPTST_MUST_SET)
+       && (pOD->fOptState & (OPTST_PRESET | OPTST_SET)) )
+        return true;
+
+    if (pOD->optMinCt > 1)
+         fprintf(stderr, zneed_more, pOpts->pzProgName, pOD->pz_Name,
+                 pOD->optMinCt);
+    else fprintf(stderr, zneed_one,  pOpts->pzProgName, pOD->pz_Name);
+    return false;
+}
+
+/**
+ *  Verify option consistency.
+ *
+ *  Make sure that the argument list passes our consistency tests.
+ */
+LOCAL bool
+is_consistent(tOptions * pOpts)
+{
+    tOptDesc * pOD   = pOpts->pOptDesc;
+    int        oCt   = pOpts->presetOptCt;
+
+    /*
+     *  FOR each of "oCt" options, ...
+     */
+    for (;;) {
+        /*
+         *  IF the current option was provided on the command line
+         *  THEN ensure that any "MUST" requirements are not
+         *       "DEFAULT" (unspecified) *AND* ensure that any
+         *       "CANT" options have not been SET or DEFINED.
+         */
+        if (SELECTED_OPT(pOD)) {
+            if (has_conflict(pOpts, pOD))
+                return false;
+        }
+
+        /*
+         *  IF       this option is not equivalenced to another,
+         *        OR it is equivalenced to itself (is the equiv. root)
+         *  THEN we need to make sure it occurs often enough.
+         */
+        if (  (pOD->optEquivIndex == NO_EQUIVALENT)
+           || (pOD->optEquivIndex == pOD->optIndex) )
+
+            if (! occurs_enough(pOpts, pOD))
+                return false;
+
+        if (--oCt <= 0)
+            break;
+        pOD++;
+    }
+
+    /*
+     *  IF we are stopping on errors, check to see if any remaining
+     *  arguments are required to be there or prohibited from being there.
+     */
+    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+
+        /*
+         *  Check for prohibition
+         */
+        if ((pOpts->fOptSet & OPTPROC_NO_ARGS) != 0) {
+            if (pOpts->origArgCt > pOpts->curOptIdx) {
+                fprintf(stderr, zNoArgs, pOpts->pzProgName);
+                return false;
+            }
+        }
+
+        /*
+         *  ELSE not prohibited, check for being required
+         */
+        else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) {
+            if (pOpts->origArgCt <= pOpts->curOptIdx) {
+                fprintf(stderr, zargs_must, pOpts->pzProgName);
+                return false;
+            }
+        }
+    }
+
+    return true;
+}
+
+/** @}
+ *
+ * Local Variables:
+ * mode: C
+ * c-file-style: "stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * end of autoopts/check.c */

+ 10 - 0
libopts/compat/_Noreturn.h

@@ -0,0 +1,10 @@
+#if !defined _Noreturn && __STDC_VERSION__ < 201112
+# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
+      || 0x5110 <= __SUNPRO_C)
+#  define _Noreturn __attribute__ ((__noreturn__))
+# elif 1200 <= _MSC_VER
+#  define _Noreturn __declspec (noreturn)
+# else
+#  define _Noreturn
+# endif
+#endif

+ 86 - 69
libopts/compat/compat.h

@@ -1,51 +1,30 @@
-/*  -*- Mode: C -*-  */
-
-/* compat.h --- fake the preprocessor into handlng portability
- *
- *  Time-stamp:      "2008-06-14 09:36:25 bkorb"
- *
- * $Id: compat.h,v 4.22 2009/01/01 16:49:26 bkorb Exp $
+/*  -*- Mode: C -*- 
  *
  *  compat.h is free software.
- *  This file is part of AutoGen.
- *
- *  AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  This file is part of AutoGen and AutoOpts.
  *
- *  AutoGen is free software: you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License as published by the
- *  Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ *  AutoGen Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
- *  AutoGen is distributed in the hope that it will be useful, but
- *  WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *  See the GNU General Public License for more details.
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
  *
- *  As a special exception, Bruce Korb gives permission for additional
- *  uses of the text contained in the release of compat.h.
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
  *
- *  The exception is that, if you link the compat.h library with other
- *  files to produce an executable, this does not by itself cause the
- *  resulting executable to be covered by the GNU General Public License.
- *  Your use of that executable is in no way restricted on account of
- *  linking the compat.h library code into it.
+ *  These files have the following sha256 sums:
  *
- *  This exception does not however invalidate any other reasons why
- *  the executable file might be covered by the GNU General Public License.
- *
- *  This exception applies only to the code released by Bruce Korb under
- *  the name compat.h.  If you copy code from other sources under the
- *  General Public License into a copy of compat.h, as the General Public
- *  License permits, the exception does not apply to the code that you add
- *  in this way.  To avoid misleading anyone as to the status of such
- *  modified files, you must delete this exception notice from them.
- *
- *  If you write modifications of your own for compat.h, it is your choice
- *  whether to permit this exception to apply to your modifications.
- *  If you do not wish that, delete this exception notice.
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+/**
+ * \file compat.h
+ *  fake the preprocessor into handlng stuff portability
  */
 #ifndef COMPAT_H_GUARD
 #define COMPAT_H_GUARD 1
@@ -63,7 +42,9 @@
 
 
 #ifndef HAVE_STRSIGNAL
-   char * strsignal( int signo );
+# ifndef HAVE_RAW_DECL_STRSIGNAL
+   char * strsignal(int signo);
+# endif
 #endif
 
 #define  _GNU_SOURCE    1 /* for strsignal in GNU's libc */
@@ -83,7 +64,9 @@
 #  include <sys/procset.h>
 #endif
 #include <sys/stat.h>
-#include <sys/wait.h>
+#ifdef HAVE_SYS_WAIT_H
+#  include <sys/wait.h>
+#endif
 
 #if defined( HAVE_SOLARIS_SYSINFO )
 #  include <sys/systeminfo.h>
@@ -180,15 +163,15 @@
 #include <setjmp.h>
 #include <signal.h>
 
-#if defined( HAVE_STDINT_H )
+#if defined(HAVE_STDINT_H)
 #  include <stdint.h>
-#elif defined( HAVE_INTTYPES_H )
+
+#elif defined(HAVE_INTTYPES_H)
 #  include <inttypes.h>
 #endif
 
 #include <stdlib.h>
 #include <string.h>
-
 #include <time.h>
 
 #ifdef HAVE_UTIME_H
@@ -199,6 +182,17 @@
 #  include <unistd.h>
 #endif
 
+#ifdef HAVE_STDBOOL_H
+#  include <stdbool.h>
+#else
+   typedef enum { false = 0, true = 1 } _Bool;
+#  define bool _Bool
+
+   /* The other macros must be usable in preprocessor directives.  */
+#  define false 0
+#  define true 1
+#endif
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *  FIXUPS and CONVIENCE STUFF:
@@ -243,7 +237,7 @@
 #endif
 
 #if !defined (MAXPATHLEN)
-#  define MAXPATHLEN ((size_t)4096)
+#  define MAXPATHLEN 4096
 #endif /* MAXPATHLEN */
 
 #define AG_PATH_MAX  ((size_t)MAXPATHLEN)
@@ -259,66 +253,89 @@
 #endif
 
 #ifndef SHORT_MAX
-#  define SHORT_MAX     ~(1 << (8*sizeof(short) -1))
+#  define SHORT_MAX     ~(1 << (8*sizeof(short) - 1))
 #else
 #  define USHORT_MAX    ~(OUS)
 #endif
 
 #ifndef HAVE_INT8_T
-  typedef signed char       int8_t;
+  typedef signed char           int8_t;
+# define  HAVE_INT8_T           1
 #endif
 #ifndef HAVE_UINT8_T
-  typedef unsigned char     uint8_t;
+  typedef unsigned char         uint8_t;
+# define  HAVE_UINT8_T          1
 #endif
 #ifndef HAVE_INT16_T
-  typedef signed short      int16_t;
+  typedef signed short          int16_t;
+# define  HAVE_INT16_T          1
 #endif
 #ifndef HAVE_UINT16_T
-  typedef unsigned short    uint16_t;
-#endif
-#ifndef HAVE_UINT_T
-  typedef unsigned int      uint_t;
+  typedef unsigned short        uint16_t;
+# define  HAVE_UINT16_T         1
 #endif
 
 #ifndef HAVE_INT32_T
-# if SIZEOF_INT == 4
-        typedef signed int      int32_t;
-# elif SIZEOF_LONG == 4
-        typedef signed long     int32_t;
+# if SIZEOF_INT ==              4
+    typedef signed int          int32_t;
+# elif SIZEOF_LONG ==           4
+    typedef signed long         int32_t;
 # endif
+# define  HAVE_INT32_T          1
 #endif
 
 #ifndef HAVE_UINT32_T
-# if SIZEOF_INT == 4
-        typedef unsigned int    uint32_t;
-# elif SIZEOF_LONG == 4
-        typedef unsigned long   uint32_t;
+# if SIZEOF_INT ==              4
+    typedef unsigned int        uint32_t;
+# elif SIZEOF_LONG ==           4
+    typedef unsigned long       uint32_t;
 # else
 #   error Cannot create a uint32_t type.
     Choke Me.
 # endif
+# define  HAVE_UINT32_T         1
 #endif
 
 #ifndef HAVE_INTPTR_T
-  typedef signed long   intptr_t;
+# if SIZEOF_CHARP == SIZEOF_LONG
+    typedef signed long         intptr_t;
+# else
+    typedef signed int          intptr_t;
+# endif
+# define  HAVE_INTPTR_T         1
 #endif
+
 #ifndef HAVE_UINTPTR_T
-  typedef unsigned long uintptr_t;
+# if SIZEOF_CHARP == SIZEOF_LONG
+    typedef unsigned long       intptr_t;
+# else
+    typedef unsigned int        intptr_t;
+# endif
+# define  HAVE_INTPTR_T         1
+#endif
+
+#ifndef HAVE_UINT_T
+  typedef unsigned int          uint_t;
+# define  HAVE_UINT_T           1
 #endif
+
 #ifndef HAVE_SIZE_T
-  typedef unsigned int  size_t;
+  typedef unsigned int          size_t;
+# define  HAVE_SIZE_T           1
 #endif
 #ifndef HAVE_WINT_T
-  typedef unsigned int  wint_t;
+  typedef unsigned int          wint_t;
+# define  HAVE_WINT_T           1
 #endif
 #ifndef HAVE_PID_T
-  typedef signed int    pid_t;
+  typedef signed int            pid_t;
+# define  HAVE_PID_T            1
 #endif
 
 /* redefine these for BSD style string libraries */
 #ifndef HAVE_STRCHR
-#  define strchr        index
-#  define strrchr       rindex
+#  define strchr            index
+#  define strrchr           rindex
 #endif
 
 #ifdef USE_FOPEN_BINARY

+ 39 - 94
libopts/compat/pathfind.c

@@ -2,26 +2,24 @@
 
 /* pathfind.c --- find a FILE  MODE along PATH */
 
-/*
- * Author:           Gary V Vaughan <gvaughan@oranda.demon.co.uk>
- * Time-stamp:       "2006-09-23 19:46:16 bkorb"
- * Last Modified:    $Date: 2007/10/07 16:54:54 $
- *            by: bkorb
- *
- * $Id: pathfind.c,v 4.12 2007/10/07 16:54:54 bkorb Exp $
- */
+/* Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk> */
 
 /* Code: */
 
+static char *
+pathfind( char const * path,
+          char const * fname,
+          char const * mode );
+
 #include "compat.h"
 #ifndef HAVE_PATHFIND
 #if defined(__windows__) && !defined(__CYGWIN__)
-char*
-pathfind( char const*  path,
-          char const*  fileName,
-          char const*  mode )
+static char *
+pathfind( char const * path,
+          char const * fname,
+          char const * mode )
 {
-    return NULL;
+    return strdup(fname);
 }
 #else
 
@@ -29,70 +27,22 @@ static char* make_absolute( char const *string, char const *dot_path );
 static char* canonicalize_pathname( char *path );
 static char* extract_colon_unit( char* dir, char const *string, int *p_index );
 
-
-/*=export_func pathfind
- *
- * what: fild a file in a list of directories
- *
- * ifndef: HAVE_PATHFIND
- *
- * arg:  + char const* + path + colon separated list of search directories +
- * arg:  + char const* + file + the name of the file to look for +
- * arg:  + char const* + mode + the mode bits that must be set to match +
- *
- * ret_type:  char*
- * ret_desc:  the path to the located file
- *
- * doc:
- *
- * pathfind looks for a a file with name "FILE" and "MODE" access
- * along colon delimited "PATH", and returns the full pathname as a
- * string, or NULL if not found.  If "FILE" contains a slash, then
- * it is treated as a relative or absolute path and "PATH" is ignored.
- *
- * @strong{NOTE}: this function is compiled into @file{libopts} only if
- * it is not natively supplied.
- *
- * The "MODE" argument is a string of option letters chosen from the
- * list below:
- * @example
- *          Letter    Meaning
- *          r         readable
- *          w         writable
- *          x         executable
- *          f         normal file       (NOT IMPLEMENTED)
- *          b         block special     (NOT IMPLEMENTED)
- *          c         character special (NOT IMPLEMENTED)
- *          d         directory         (NOT IMPLEMENTED)
- *          p         FIFO (pipe)       (NOT IMPLEMENTED)
- *          u         set user ID bit   (NOT IMPLEMENTED)
- *          g         set group ID bit  (NOT IMPLEMENTED)
- *          k         sticky bit        (NOT IMPLEMENTED)
- *          s         size nonzero      (NOT IMPLEMENTED)
- * @end example
- *
- * example:
- * To find the "ls" command using the "PATH" environment variable:
- * @example
- *    #include <stdlib.h>
- *    char* pz_ls = pathfind( getenv("PATH"), "ls", "rx" );
- *    <<do whatever with pz_ls>>
- *    free( pz_ls );
- * @end example
- * The path is allocated with @code{malloc(3C)}, so you must @code{free(3C)}
- * the result.  Also, do not use unimplemented file modes.  :-)
- *
- * err:  returns NULL if the file is not found.
-=*/
-char*
-pathfind( char const*  path,
-          char const*  fileName,
-          char const*  mode )
+/**
+ * local implementation of pathfind.
+ * @param[in] path  colon separated list of directories
+ * @param[in] fname the name we are hunting for
+ * @param[in] mode  the required file mode
+ * @returns an allocated string with the full path, or NULL
+ */
+static char *
+pathfind( char const * path,
+          char const * fname,
+          char const * mode )
 {
-    int   p_index   = 0;
-    int   mode_bits = 0;
-    char* pathName  = NULL;
-    char  zPath[ AG_PATH_MAX + 1 ];
+    int    p_index   = 0;
+    int    mode_bits = 0;
+    char * res_path  = NULL;
+    char   zPath[ AG_PATH_MAX + 1 ];
 
     if (strchr( mode, 'r' )) mode_bits |= R_OK;
     if (strchr( mode, 'w' )) mode_bits |= W_OK;
@@ -105,9 +55,6 @@ pathfind( char const*  path,
         DIR*  dirP;
         char* colon_unit = extract_colon_unit( zPath, path, &p_index );
 
-        /*
-         *  IF no more entries, THEN quit
-         */
         if (colon_unit == NULL)
             break;
 
@@ -119,9 +66,6 @@ pathfind( char const*  path,
         if (dirP == NULL)
             continue;
 
-        /*
-         *  FOR every entry in the given directory, ...
-         */
         for (;;) {
             struct dirent *entP = readdir( dirP );
 
@@ -131,31 +75,31 @@ pathfind( char const*  path,
             /*
              *  IF the file name matches the one we are looking for, ...
              */
-            if (strcmp( entP->d_name, fileName ) == 0) {
-                char* pzFullName = make_absolute( fileName, colon_unit);
+            if (strcmp(entP->d_name, fname) == 0) {
+                char * abs_name = make_absolute(fname, colon_unit);
 
                 /*
                  *  Make sure we can access it in the way we want
                  */
-                if (access( pzFullName, mode_bits ) >= 0) {
+                if (access(abs_name, mode_bits) >= 0) {
                     /*
                      *  We can, so normalize the name and return it below
                      */
-                    pathName = canonicalize_pathname( pzFullName );
+                    res_path = canonicalize_pathname(abs_name);
                 }
 
-                free( (void*)pzFullName );
+                free(abs_name);
                 break;
             }
         }
 
         closedir( dirP );
 
-        if (pathName != NULL)
+        if (res_path != NULL)
             break;
     }
 
-    return pathName;
+    return res_path;
 }
 
 /*
@@ -175,7 +119,7 @@ make_absolute( char const *string, char const *dot_path )
         if (dot_path && dot_path[0]) {
             result = malloc( 2 + strlen( dot_path ) + strlen( string ) );
             strcpy( result, dot_path );
-            result_len = strlen( result );
+            result_len = (int)strlen(result);
             if (result[result_len - 1] != '/') {
                 result[result_len++] = '/';
                 result[result_len] = '\0';
@@ -290,7 +234,7 @@ canonicalize_pathname( char *path )
 static char*
 extract_colon_unit( char* pzDir, char const *string, int *p_index )
 {
-    char*  pzDest = pzDir;
+    char * pzDest = pzDir;
     int    ix     = *p_index;
 
     if (string == NULL)
@@ -300,7 +244,7 @@ extract_colon_unit( char* pzDir, char const *string, int *p_index )
         return NULL;
 
     {
-        char const* pzSrc = string + ix;
+        char const * pzSrc = string + ix;
 
         while (*pzSrc == ':')  pzSrc++;
 
@@ -309,15 +253,16 @@ extract_colon_unit( char* pzDir, char const *string, int *p_index )
             switch (ch) {
             case ':':
                 pzDest[-1] = NUL;
+                /* FALLTHROUGH */
             case NUL:
                 goto copy_done;
             }
 
-            if ((pzDest - pzDir) >= AG_PATH_MAX)
+            if ((unsigned long)(pzDest - pzDir) >= AG_PATH_MAX)
                 break;
         } copy_done:;
 
-        ix = pzSrc - string;
+        ix = (int)(pzSrc - string);
     }
 
     if (*pzDir == NUL)

+ 2 - 0
libopts/compat/snprintf.c

@@ -1,6 +1,7 @@
 
 #ifndef HAVE_VPRINTF
 #include "choke-me: no vprintf and no snprintf"
+  choke me.
 #endif
 
 #if defined(HAVE_STDARG_H)
@@ -21,6 +22,7 @@
 
 #else
 #  include "must-have-stdarg-or-varargs"
+  choke me.
 #endif
 
 static int

+ 12 - 6
libopts/compat/strchr.c

@@ -24,11 +24,17 @@
        SVID 3, POSIX, BSD 4.3, ISO 9899
 */
 
-char*
-strchr( char const *s, int c)
+static char *
+strchr(char const *s, int c);
+
+static char *
+strrchr(char const *s, int c);
+
+static char *
+strchr(char const *s, int c)
 {
     do {
-        if ((unsigned)*s == (unsigned)c)
+        if ((unsigned char)*s == (unsigned char)c)
             return s;
 
     } while (*(++s) != NUL);
@@ -36,8 +42,8 @@ strchr( char const *s, int c)
     return NULL;
 }
 
-char*
-strrchr( char const *s, int c)
+static char *
+strrchr(char const *s, int c)
 {
     char const *e = s + strlen(s);
 
@@ -45,7 +51,7 @@ strrchr( char const *s, int c)
         if (--e < s)
             break;
 
-        if ((unsigned)*e == (unsigned)c)
+        if ((unsigned char)*e == (unsigned char)c)
             return e;
     }
     return NULL;

+ 3 - 0
libopts/compat/strdup.c

@@ -3,6 +3,9 @@
  */
 
 static char *
+strdup( char const *s );
+
+static char *
 strdup( char const *s )
 {
     char *cp;

+ 58 - 61
libopts/compat/windows-config.h

@@ -1,26 +1,33 @@
 
-/*
- * Time-stamp:        "2009-07-22 18:53:59 bkorb"
- *             by: bkorb
- * Last Committed:    $Date: 2009/07/23 02:05:55 $
+/**
+ * \file windows-config.h
+ *
+ *  This file contains all of the routines that must be linked into
+ *  an executable to use the generated option processing.  The optional
+ *  routines are in separately compiled modules so that they will not
+ *  necessarily be linked in.
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
- *  This file is part of AutoGen.
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
  *
- *  AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
  *
- *  AutoGen is free software: you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License as published by the
- *  Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
  *
- *  AutoGen is distributed in the hope that it will be useful, but
- *  WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *  See the GNU General Public License for more details.
+ *  These files have the following sha256 sums:
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
+
 #ifndef WINDOWS_CONFIG_HACKERY
 #define WINDOWS_CONFIG_HACKERY 1
 
@@ -34,64 +41,25 @@
 #endif
 
 /*
- * Miscellaneous functions that Microsoft maps
- * to other names
- *
- * #define inline __inline
- * #define vsnprintf _vsnprintf
+ * Miscellaneous functions that Microsoft maps to other names
  */
 #define snprintf _snprintf
-/*
- * #define stricmp _stricmp
- * #define strcasecmp _stricmp
- * #define isascii __isascii
- * #define finite _finite
- * #define random      rand
- * #define srandom     srand
- */
 
 #define SIZEOF_INT   4
 #define SIZEOF_CHARP 4
 #define SIZEOF_LONG  4
 #define SIZEOF_SHORT 2
 
-typedef unsigned long uintptr_t;
-
-/*
- * # define HAVE_NET_IF_H
- * # define QSORT_USES_VOID_P
- * # define HAVE_SETVBUF
- * # define HAVE_VSPRINTF
- * # define HAVE_SNPRINTF
- * # define HAVE_VSNPRINTF
- * # define HAVE_PROTOTYPES             /* from ntpq.mak * /
- * # define HAVE_MEMMOVE
- * # define HAVE_TERMIOS_H
- * # define HAVE_ERRNO_H
- * # define HAVE_STDARG_H
- * # define HAVE_NO_NICE
- * # define HAVE_MKTIME
- * # define TIME_WITH_SYS_TIME
- * # define HAVE_IO_COMPLETION_PORT
- * # define ISC_PLATFORM_NEEDNTOP
- * # define ISC_PLATFORM_NEEDPTON
- * # define NEED_S_CHAR_TYPEDEF
- * # define USE_PROTOTYPES              /* for ntp_types.h * /
- *
- * #define ULONG_CONST(a) a ## UL
- */
-
 #define HAVE_LIMITS_H   1
 #define HAVE_STRDUP     1
 #define HAVE_STRCHR     1
 #define HAVE_FCNTL_H    1
 
 /*
- * VS.NET's version of wspiapi.h has a bug in it
- * where it assigns a value to a variable inside
- * an if statement. It should be comparing them.
- * We prevent inclusion since we are not using this
- * code so we don't have to see the warning messages
+ * VS.NET's version of wspiapi.h has a bug in it where it assigns a value
+ * to a variable inside an if statement. It should be comparing them.
+ * We prevent inclusion since we are not using this code so we don't have
+ * to see the warning messages
  */
 #ifndef _WSPIAPI_H_
 #define _WSPIAPI_H_
@@ -118,7 +86,7 @@ typedef unsigned long uintptr_t;
 #define strdup  _strdup
 #define stat    _stat       /* struct stat from <sys/stat.h> */
 #define unlink  _unlink
-#define fchmod( _x, _y );
+#define fchmod( _x, _y )
 #define ssize_t SSIZE_T
 
 #include <io.h>
@@ -144,4 +112,33 @@ typedef unsigned long uintptr_t;
 #  define       S_ISDIR(mode)   (((mode) & S_IFDIR) == S_IFDIR)
 #endif
 
+/* C99 exact size integer support. */
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+# define MISSING_INTTYPES_H 1
+
+#elif ! defined(ADDED_EXACT_SIZE_INTEGERS)
+# define ADDED_EXACT_SIZE_INTEGERS 1
+# define MISSING_INTTYPES_H 1
+
+  typedef __int8 int8_t;
+  typedef unsigned __int8 uint8_t;
+
+  typedef __int16 int16_t;
+  typedef unsigned __int16 uint16_t;
+
+  typedef __int32 int32_t;
+  typedef unsigned __int32 uint32_t;
+
+  typedef __int64 int64_t;
+  typedef unsigned __int64 uint64_t;
+
+  typedef unsigned long uintptr_t;
+  typedef long intptr_t;
+#endif
+
 #endif /* WINDOWS_CONFIG_HACKERY */
+/* windows-config.h ends here */

File diff suppressed because it is too large
+ 718 - 587
libopts/configfile.c


+ 132 - 100
libopts/cook.c

@@ -1,13 +1,16 @@
-/*
- *  $Id: cook.c,v 4.17 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2007-11-16 22:49:11 bkorb"
+/**
+ * \file cook.c
  *
  *  This file contains the routines that deal with processing quoted strings
  *  into an internal format.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -19,15 +22,16 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
+static bool
+contiguous_quote(char ** pps, char * pq, int * lnct_p);
 /* = = = END-STATIC-FORWARD = = = */
 
 /*=export_func  ao_string_cook_escape_char
@@ -57,26 +61,26 @@
  * err:  @code{NULL} is returned if the string is mal-formed.
 =*/
 unsigned int
-ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl )
+ao_string_cook_escape_char(char const * pzIn, char * pRes, uint_t nl)
 {
-    unsigned int  res = 1;
+    unsigned int res = 1;
 
     switch (*pRes = *pzIn++) {
     case NUL:         /* NUL - end of input string */
         return 0;
     case '\r':
-        if (*pzIn != '\n')
+        if (*pzIn != NL)
             return 1;
         res++;
         /* FALLTHROUGH */
-    case '\n':        /* NL  - emit newline        */
+    case NL:        /* NL  - emit newline        */
         *pRes = (char)nl;
         return res;
 
     case 'a': *pRes = '\a'; break;
     case 'b': *pRes = '\b'; break;
     case 'f': *pRes = '\f'; break;
-    case 'n': *pRes = '\n'; break;
+    case 'n': *pRes = NL;   break;
     case 'r': *pRes = '\r'; break;
     case 't': *pRes = '\t'; break;
     case 'v': *pRes = '\v'; break;
@@ -84,13 +88,17 @@ ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl )
     case 'x':
     case 'X':         /* HEX Escape       */
         if (IS_HEX_DIGIT_CHAR(*pzIn))  {
-            char z[4], *pz = z;
+            char z[4];
+            unsigned int ct = 0;
 
-            do *(pz++) = *(pzIn++);
-            while (IS_HEX_DIGIT_CHAR(*pzIn) && (pz < z + 2));
-            *pz = NUL;
-            *pRes = (unsigned char)strtoul(z, NULL, 16);
-            res += pz - z;
+            do  {
+                z[ct] = pzIn[ct];
+                if (++ct >= 2)
+                    break;
+            } while (IS_HEX_DIGIT_CHAR(pzIn[ct]));
+            z[ct] = NUL;
+            *pRes = (char)strtoul(z, NULL, 16);
+            return ct + 1;
         }
         break;
 
@@ -99,24 +107,29 @@ ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl )
     {
         /*
          *  IF the character copied was an octal digit,
-         *  THEN set the output character to an octal value
+         *  THEN set the output character to an octal value.
+         *  The 3 octal digit result might exceed 0xFF, so check it.
          */
-        char z[4], *pz = z + 1;
+        char z[4];
         unsigned long val;
-        z[0] = *pRes;
+        unsigned int  ct = 0;
 
-        while (IS_OCT_DIGIT_CHAR(*pzIn) && (pz < z + 3))
-            *(pz++) = *(pzIn++);
-        *pz = NUL;
+        z[ct++] = *--pzIn;
+        while (IS_OCT_DIGIT_CHAR(pzIn[ct])) {
+            z[ct] = pzIn[ct];
+            if (++ct >= 3)
+                break;
+        }
+
+        z[ct] = NUL;
         val = strtoul(z, NULL, 8);
         if (val > 0xFF)
             val = 0xFF;
-        *pRes = (unsigned char)val;
-        res = pz - z;
-        break;
+        *pRes = (char)val;
+        return ct;
     }
 
-    default: ;
+    default: /* quoted character is result character */;
     }
 
     return res;
@@ -128,12 +141,85 @@ ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl )
  *  A quoted string has been found.
  *  Find the end of it and compress any escape sequences.
  */
+static bool
+contiguous_quote(char ** pps, char * pq, int * lnct_p)
+{
+    char * ps = *pps + 1;
+
+    for (;;) {
+        while (IS_WHITESPACE_CHAR(*ps))
+            if (*(ps++) == NL)
+                (*lnct_p)++;
+
+        /*
+         *  IF the next character is a quote character,
+         *  THEN we will concatenate the strings.
+         */
+        switch (*ps) {
+        case '"':
+        case '\'':
+            *pq  = *(ps++);  /* assign new quote character and return */
+            *pps = ps;
+            return true;
+
+        case '/':
+            /*
+             *  Allow for a comment embedded in the concatenated string.
+             */
+            switch (ps[1]) {
+            default:
+                *pps = NULL;
+                return false;
+
+            case '/':
+                /*
+                 *  Skip to end of line
+                 */
+                ps = strchr(ps, NL);
+                if (ps == NULL) {
+                    *pps = NULL;
+                    return false;
+                }
+                break;
+
+            case '*':
+            {
+                char* p = strstr( ps+2, "*/" );
+                /*
+                 *  Skip to terminating star slash
+                 */
+                if (p == NULL) {
+                    *pps = NULL;
+                    return false;
+                }
+
+                while (ps < p) {
+                    if (*(ps++) == NL)
+                        (*lnct_p)++;
+                }
+
+                ps = p + 2;
+            }
+            }
+            continue;
+
+        default:
+            /*
+             *  The next non-whitespace character is not a quote.
+             *  The series of quoted strings has come to an end.
+             */
+            *pps = ps;
+            return false;
+        }
+    }
+}
+
 /*=export_func  ao_string_cook
  * private:
  *
  * what:  concatenate and escape-process strings
- * arg:   + char* + pzScan     + The *MODIFIABLE* input buffer +
- * arg:   + int*  + pLineCt    + The (possibly NULL) pointer to a line count +
+ * arg:   + char* + pzScan  + The *MODIFIABLE* input buffer +
+ * arg:   + int*  + lnct_p  + The (possibly NULL) pointer to a line count +
  *
  * ret-type: char*
  * ret-desc: The address of the text following the processed strings.
@@ -149,8 +235,8 @@ ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl )
  *
  * err:  @code{NULL} is returned if the string(s) is/are mal-formed.
 =*/
-char*
-ao_string_cook( char* pzScan, int* pLineCt )
+char *
+ao_string_cook(char * pzScan, int * lnct_p)
 {
     int   l = 0;
     char  q = *pzScan;
@@ -162,8 +248,8 @@ ao_string_cook( char* pzScan, int* pLineCt )
     char* pzD = pzScan++;
     char* pzS = pzScan;
 
-    if (pLineCt == NULL)
-        pLineCt = &l;
+    if (lnct_p == NULL)
+        lnct_p = &l;
 
     for (;;) {
         /*
@@ -175,65 +261,8 @@ ao_string_cook( char* pzScan, int* pLineCt )
          */
         while (*pzS == q) {
             *pzD = NUL; /* This is probably the end of the line */
-            pzS++;
-
-        scan_for_quote:
-            while (IS_WHITESPACE_CHAR(*pzS))
-                if (*(pzS++) == '\n')
-                    (*pLineCt)++;
-
-            /*
-             *  IF the next character is a quote character,
-             *  THEN we will concatenate the strings.
-             */
-            switch (*pzS) {
-            case '"':
-            case '\'':
-                break;
-
-            case '/':
-                /*
-                 *  Allow for a comment embedded in the concatenated string.
-                 */
-                switch (pzS[1]) {
-                default:  return NULL;
-                case '/':
-                    /*
-                     *  Skip to end of line
-                     */
-                    pzS = strchr( pzS, '\n' );
-                    if (pzS == NULL)
-                        return NULL;
-                    (*pLineCt)++;
-                    break;
-
-                case '*':
-                {
-                    char* p = strstr( pzS+2, "*/" );
-                    /*
-                     *  Skip to terminating star slash
-                     */
-                    if (p == NULL)
-                        return NULL;
-                    while (pzS < p) {
-                        if (*(pzS++) == '\n')
-                            (*pLineCt)++;
-                    }
-
-                    pzS = p + 2;
-                }
-                }
-                goto scan_for_quote;
-
-            default:
-                /*
-                 *  The next non-whitespace character is not a quote.
-                 *  The series of quoted strings has come to an end.
-                 */
+            if (! contiguous_quote(&pzS, &q, lnct_p))
                 return pzS;
-            }
-
-            q = *(pzS++);  /* assign new quote character and advance scan */
         }
 
         /*
@@ -243,8 +272,8 @@ ao_string_cook( char* pzScan, int* pLineCt )
         case NUL:
             return NULL;
 
-        case '\n':
-            (*pLineCt)++;
+        case NL:
+            (*lnct_p)++;
             break;
 
         case '\\':
@@ -253,10 +282,10 @@ ao_string_cook( char* pzScan, int* pLineCt )
              *  THEN drop both the escape and the newline from
              *       the result string.
              */
-            if (*pzS == '\n') {
+            if (*pzS == NL) {
                 pzS++;
                 pzD--;
-                (*pLineCt)++;
+                (*lnct_p)++;
             }
 
             /*
@@ -264,7 +293,8 @@ ao_string_cook( char* pzScan, int* pLineCt )
              *  THEN we do the full escape character processing
              */
             else if (q != '\'') {
-                int ct = ao_string_cook_escape_char( pzS, pzD-1, (u_int)'\n' );
+                unsigned int ct;
+                ct = ao_string_cook_escape_char(pzS, pzD-1, (uint_t)NL);
                 if (ct == 0)
                     return NULL;
 
@@ -284,7 +314,9 @@ ao_string_cook( char* pzScan, int* pLineCt )
         }     /* switch (*(pzD++) = *(pzS++))    */
     }         /* for (;;)                        */
 }
-/*
+
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 652 - 0
libopts/enum.c

@@ -0,0 +1,652 @@
+
+/**
+ * \file enumeration.c
+ *
+ *  Handle options with enumeration names and bit mask bit names
+ *  for their arguments.
+ *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
+ *  This routine will run run-on options through a pager so the
+ *  user may examine, print or edit them at their leisure.
+ *
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+/* = = = START-STATIC-FORWARD = = = */
+static void
+enum_err(tOptions * pOpts, tOptDesc * pOD,
+         char const * const * paz_names, int name_ct);
+
+static uintptr_t
+find_name(char const * name, tOptions * pOpts, tOptDesc * pOD,
+          char const * const *  paz_names, unsigned int name_ct);
+
+static void
+set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names,
+               unsigned int name_ct);
+
+static void
+set_memb_names(tOptions * opts, tOptDesc * od, char const * const * nm_list,
+               unsigned int nm_ct);
+
+static uintptr_t
+check_membership_start(tOptDesc * od, char const ** argp, bool * invert);
+
+static uintptr_t
+find_member_bit(tOptions * opts, tOptDesc * od, char const * pz, int len,
+                char const * const * nm_list, unsigned int nm_ct);
+/* = = = END-STATIC-FORWARD = = = */
+
+static void
+enum_err(tOptions * pOpts, tOptDesc * pOD,
+         char const * const * paz_names, int name_ct)
+{
+    size_t max_len = 0;
+    size_t ttl_len = 0;
+    int    ct_down = name_ct;
+    int    hidden  = 0;
+
+    /*
+     *  A real "pOpts" pointer means someone messed up.  Give a real error.
+     */
+    if (pOpts > OPTPROC_EMIT_LIMIT)
+        fprintf(option_usage_fp, pz_enum_err_fmt, pOpts->pzProgName,
+                pOD->optArg.argString, pOD->pz_Name);
+
+    fprintf(option_usage_fp, zValidKeys, pOD->pz_Name);
+
+    /*
+     *  If the first name starts with this funny character, then we have
+     *  a first value with an unspellable name.  You cannot specify it.
+     *  So, we don't list it either.
+     */
+    if (**paz_names == 0x7F) {
+        paz_names++;
+        hidden  = 1;
+        ct_down = --name_ct;
+    }
+
+    /*
+     *  Figure out the maximum length of any name, plus the total length
+     *  of all the names.
+     */
+    {
+        char const * const * paz = paz_names;
+
+        do  {
+            size_t len = strlen(*(paz++)) + 1;
+            if (len > max_len)
+                max_len = len;
+            ttl_len += len;
+        } while (--ct_down > 0);
+
+        ct_down = name_ct;
+    }
+
+    /*
+     *  IF any one entry is about 1/2 line or longer, print one per line
+     */
+    if (max_len > 35) {
+        do  {
+            fprintf(option_usage_fp, ENUM_ERR_LINE, *(paz_names++));
+        } while (--ct_down > 0);
+    }
+
+    /*
+     *  ELSE IF they all fit on one line, then do so.
+     */
+    else if (ttl_len < 76) {
+        fputc(' ', option_usage_fp);
+        do  {
+            fputc(' ', option_usage_fp);
+            fputs(*(paz_names++), option_usage_fp);
+        } while (--ct_down > 0);
+        fputc(NL, option_usage_fp);
+    }
+
+    /*
+     *  Otherwise, columnize the output
+     */
+    else {
+        unsigned int ent_no = 0;
+        char  zFmt[16];  /* format for all-but-last entries on a line */
+
+        sprintf(zFmt, ENUM_ERR_WIDTH, (int)max_len);
+        max_len = 78 / max_len; /* max_len is now max entries on a line */
+        fputs(TWO_SPACES_STR, option_usage_fp);
+
+        /*
+         *  Loop through all but the last entry
+         */
+        ct_down = name_ct;
+        while (--ct_down > 0) {
+            if (++ent_no == max_len) {
+                /*
+                 *  Last entry on a line.  Start next line, too.
+                 */
+                fprintf(option_usage_fp, NLSTR_SPACE_FMT, *(paz_names++));
+                ent_no = 0;
+            }
+
+            else
+                fprintf(option_usage_fp, zFmt, *(paz_names++) );
+        }
+        fprintf(option_usage_fp, NLSTR_FMT, *paz_names);
+    }
+
+    if (pOpts > OPTPROC_EMIT_LIMIT) {
+        fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden);
+
+        (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+    }
+
+    if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) {
+        fprintf(option_usage_fp, zLowerBits, name_ct);
+        fputs(zSetMemberSettings, option_usage_fp);
+    } else {
+        fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden);
+    }
+}
+
+/**
+ * Convert a name or number into a binary number.
+ * "~0" and "-1" will be converted to the largest value in the enumeration.
+ *
+ * @param name       the keyword name (number) to convert
+ * @param pOpts      the program's option descriptor
+ * @param pOD        the option descriptor for this option
+ * @param paz_names  the list of keywords for this option
+ * @param name_ct    the count of keywords
+ */
+static uintptr_t
+find_name(char const * name, tOptions * pOpts, tOptDesc * pOD,
+          char const * const *  paz_names, unsigned int name_ct)
+{
+    /*
+     *  Return the matching index as a pointer sized integer.
+     *  The result gets stashed in a char* pointer.
+     */
+    uintptr_t   res = name_ct;
+    size_t      len = strlen((char*)name);
+    uintptr_t   idx;
+
+    if (IS_DEC_DIGIT_CHAR(*name)) {
+        char * pz = (char *)(void *)name;
+        unsigned long val = strtoul(pz, &pz, 0);
+        if ((*pz == NUL) && (val < name_ct))
+            return (uintptr_t)val;
+        pz_enum_err_fmt = znum_too_large;
+        option_usage_fp = stderr;
+        enum_err(pOpts, pOD, paz_names, (int)name_ct);
+        return name_ct;
+    }
+
+    if (IS_INVERSION_CHAR(*name) && (name[2] == NUL)) {
+        if (  ((name[0] == '~') && (name[1] == '0'))
+           || ((name[0] == '-') && (name[1] == '1')))
+        return (uintptr_t)(name_ct - 1);
+        goto oops;
+    }
+
+    /*
+     *  Look for an exact match, but remember any partial matches.
+     *  Multiple partial matches means we have an ambiguous match.
+     */
+    for (idx = 0; idx < name_ct; idx++) {
+        if (strncmp((char*)paz_names[idx], (char*)name, len) == 0) {
+            if (paz_names[idx][len] == NUL)
+                return idx;  /* full match */
+
+            if (res == name_ct)
+                res = idx; /* save partial match */
+            else
+                res = (uintptr_t)~0;  /* may yet find full match */
+        }
+    }
+
+    if (res < name_ct)
+        return res; /* partial match */
+
+ oops:
+
+    pz_enum_err_fmt = (res == name_ct) ? zNoKey : zambiguous_key;
+    option_usage_fp = stderr;
+    enum_err(pOpts, pOD, paz_names, (int)name_ct);
+    return name_ct;
+}
+
+
+/*=export_func  optionKeywordName
+ * what:  Convert between enumeration values and strings
+ * private:
+ *
+ * arg:   tOptDesc*,     pOD,       enumeration option description
+ * arg:   unsigned int,  enum_val,  the enumeration value to map
+ *
+ * ret_type:  char const *
+ * ret_desc:  the enumeration name from const memory
+ *
+ * doc:   This converts an enumeration value into the matching string.
+=*/
+char const *
+optionKeywordName(tOptDesc * pOD, unsigned int enum_val)
+{
+    tOptDesc od = { 0 };
+    od.optArg.argEnum = enum_val;
+
+    (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od );
+    return od.optArg.argString;
+}
+
+
+/*=export_func  optionEnumerationVal
+ * what:  Convert from a string to an enumeration value
+ * private:
+ *
+ * arg:   tOptions*,     pOpts,     the program options descriptor
+ * arg:   tOptDesc*,     pOD,       enumeration option description
+ * arg:   char const * const *,  paz_names, list of enumeration names
+ * arg:   unsigned int,  name_ct,   number of names in list
+ *
+ * ret_type:  uintptr_t
+ * ret_desc:  the enumeration value
+ *
+ * doc:   This converts the optArg.argString string from the option description
+ *        into the index corresponding to an entry in the name list.
+ *        This will match the generated enumeration value.
+ *        Full matches are always accepted.  Partial matches are accepted
+ *        if there is only one partial match.
+=*/
+uintptr_t
+optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD,
+                     char const * const * paz_names, unsigned int name_ct)
+{
+    uintptr_t res = 0UL;
+
+    /*
+     *  IF the program option descriptor pointer is invalid,
+     *  then it is some sort of special request.
+     */
+    switch ((uintptr_t)pOpts) {
+    case (uintptr_t)OPTPROC_EMIT_USAGE:
+        /*
+         *  print the list of enumeration names.
+         */
+        enum_err(pOpts, pOD, paz_names, (int)name_ct);
+        break;
+
+    case (uintptr_t)OPTPROC_EMIT_SHELL:
+    {
+        unsigned int ix = (unsigned int)pOD->optArg.argEnum;
+        /*
+         *  print the name string.
+         */
+        if (ix >= name_ct)
+            printf(INVALID_FMT, ix);
+        else
+            fputs(paz_names[ ix ], stdout);
+
+        break;
+    }
+
+    case (uintptr_t)OPTPROC_RETURN_VALNAME:
+    {
+        unsigned int ix = (unsigned int)pOD->optArg.argEnum;
+        /*
+         *  Replace the enumeration value with the name string.
+         */
+        if (ix >= name_ct)
+            return (uintptr_t)INVALID_STR;
+
+        pOD->optArg.argString = paz_names[ix];
+        break;
+    }
+
+    default:
+        if ((pOD->fOptState & OPTST_RESET) != 0)
+            break;
+
+        res = find_name(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct);
+
+        if (pOD->fOptState & OPTST_ALLOC_ARG) {
+            AGFREE(pOD->optArg.argString);
+            pOD->fOptState &= ~OPTST_ALLOC_ARG;
+            pOD->optArg.argString = NULL;
+        }
+    }
+
+    return res;
+}
+
+static void
+set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names,
+               unsigned int name_ct)
+{
+    /*
+     *  print the name string.
+     */
+    unsigned int ix =  0;
+    uintptr_t  bits = (uintptr_t)pOD->optCookie;
+    size_t     len  = 0;
+
+    (void)pOpts;
+    bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1;
+
+    while (bits != 0) {
+        if (bits & 1) {
+            if (len++ > 0) fputs(OR_STR, stdout);
+            fputs(paz_names[ix], stdout);
+        }
+        if (++ix >= name_ct) break;
+        bits >>= 1;
+    }
+}
+
+static void
+set_memb_names(tOptions * opts, tOptDesc * od, char const * const * nm_list,
+               unsigned int nm_ct)
+{
+    char *     pz;
+    uintptr_t  mask = (1UL << (uintptr_t)nm_ct) - 1UL;
+    uintptr_t  bits = (uintptr_t)od->optCookie & mask;
+    unsigned int ix = 0;
+    size_t     len  = 1;
+
+    /*
+     *  Replace the enumeration value with the name string.
+     *  First, determine the needed length, then allocate and fill in.
+     */
+    while (bits != 0) {
+        if (bits & 1)
+            len += strlen(nm_list[ix]) + PLUS_STR_LEN + 1;
+        if (++ix >= nm_ct) break;
+        bits >>= 1;
+    }
+
+    od->optArg.argString = pz = AGALOC(len, "enum");
+    bits = (uintptr_t)od->optCookie & mask;
+    if (bits == 0) {
+        *pz = NUL;
+        return;
+    }
+
+    for (ix = 0; ; ix++) {
+        size_t nln;
+        int    doit = bits & 1;
+
+        bits >>= 1;
+        if (doit == 0)
+            continue;
+
+        nln = strlen(nm_list[ix]);
+        memcpy(pz, nm_list[ix], nln);
+        pz += nln;
+        if (bits == 0)
+            break;
+        memcpy(pz, PLUS_STR, PLUS_STR_LEN);
+        pz += PLUS_STR_LEN;
+    }
+    *pz = NUL;
+    (void)opts;
+}
+
+/**
+ * Check membership start conditions.  An equal character (@samp{=}) says to
+ * clear the result and not carry over any residual value.  A carat
+ * (@samp{^}), which may follow the equal character, says to invert the
+ * result.  The scanning pointer is advanced past these characters and any
+ * leading white space.  Invalid sequences are indicated by setting the
+ * scanning pointer to NULL.
+ *
+ * @param od      the set membership option description
+ * @param argp    a pointer to the string scanning pointer
+ * @param invert  a pointer to the boolean inversion indicator
+ *
+ * @returns either zero or the original value for the optCookie.
+ */
+static uintptr_t
+check_membership_start(tOptDesc * od, char const ** argp, bool * invert)
+{
+    uintptr_t    res = (uintptr_t)od->optCookie;
+    char const * arg = SPN_WHITESPACE_CHARS(od->optArg.argString);
+    if ((arg == NULL) || (*arg == NUL))
+        goto member_start_fail;
+
+    *invert = false;
+
+    switch (*arg) {
+    case '=':
+        res = 0UL;
+        arg = SPN_WHITESPACE_CHARS(arg + 1);
+        switch (*arg) {
+        case '=': case ',':
+            goto member_start_fail;
+        case '^':
+            goto inversion;
+        default:
+            break;
+        }
+        break;
+
+    case '^':
+    inversion:
+        *invert = true;
+        arg = SPN_WHITESPACE_CHARS(arg + 1);
+        if (*arg != ',')
+            break;
+        /* FALLTHROUGH */
+
+    case ',':
+        goto member_start_fail;
+
+    default:
+        break;
+    }
+
+    *argp = arg;
+    return res;
+
+member_start_fail:
+    *argp = NULL;
+    return 0UL;
+}
+
+/**
+ * convert a name to a bit.  Look up a name string to get a bit number
+ * and shift the value "1" left that number of bits.
+ *
+ * @param opts      program options descriptor
+ * @param od        the set membership option description
+ * @param pz        address of the start of the bit name
+ * @param nm_list   the list of names for this option
+ * @param nm_ct     the number of entries in this list
+ *
+ * @returns 0UL on error, other an unsigned long with the correct bit set.
+ */
+static uintptr_t
+find_member_bit(tOptions * opts, tOptDesc * od, char const * pz, int len,
+                char const * const * nm_list, unsigned int nm_ct)
+{
+    char nm_buf[ AO_NAME_SIZE ];
+
+    memcpy(nm_buf, pz, len);
+    nm_buf[len] = NUL;
+
+    {
+        unsigned int shift_ct = (unsigned int)
+            find_name(nm_buf, opts, od, nm_list, nm_ct);
+        if (shift_ct >= nm_ct)
+            return 0UL;
+
+        return 1UL << shift_ct;
+    }
+}
+
+/*=export_func  optionMemberList
+ * what:  Get the list of members of a bit mask set
+ *
+ * arg:   tOptDesc *,  od,   the set membership option description
+ *
+ * ret_type: char*
+ * ret_desc: the names of the set bits
+ *
+ * doc:   This converts the OPT_VALUE_name mask value to a allocated string.
+ *        It is the caller's responsibility to free the string.
+=*/
+char *
+optionMemberList(tOptDesc * od)
+{
+    uintptr_t    sv = od->optArg.argIntptr;
+    char * res;
+    (*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od);
+    res = (void *)od->optArg.argString;
+    od->optArg.argIntptr = sv;
+    return res;
+}
+
+/*=export_func  optionSetMembers
+ * what:  Convert between bit flag values and strings
+ * private:
+ *
+ * arg:   tOptions*,     opts,     the program options descriptor
+ * arg:   tOptDesc*,     od,       the set membership option description
+ * arg:   char const * const *,
+ *                       nm_list,  list of enumeration names
+ * arg:   unsigned int,  nm_ct,    number of names in list
+ *
+ * doc:   This converts the optArg.argString string from the option description
+ *        into the index corresponding to an entry in the name list.
+ *        This will match the generated enumeration value.
+ *        Full matches are always accepted.  Partial matches are accepted
+ *        if there is only one partial match.
+=*/
+void
+optionSetMembers(tOptions * opts, tOptDesc * od,
+                 char const * const * nm_list, unsigned int nm_ct)
+{
+    /*
+     *  IF the program option descriptor pointer is invalid,
+     *  then it is some sort of special request.
+     */
+    switch ((uintptr_t)opts) {
+    case (uintptr_t)OPTPROC_EMIT_USAGE:
+        enum_err(OPTPROC_EMIT_USAGE, od, nm_list, nm_ct);
+        return;
+
+    case (uintptr_t)OPTPROC_EMIT_SHELL:
+        set_memb_shell(opts, od, nm_list, nm_ct);
+        return;
+
+    case (uintptr_t)OPTPROC_RETURN_VALNAME:
+        set_memb_names(opts, od, nm_list, nm_ct);
+        return;
+
+    default:
+        break;
+    }
+
+    if ((od->fOptState & OPTST_RESET) != 0)
+        return;
+
+    {
+        char const * arg;
+        bool         invert;
+        uintptr_t    res = check_membership_start(od, &arg, &invert);
+        if (arg == NULL)
+            goto fail_return;
+
+        while (*arg != NUL) {
+            bool inv_val = false;
+            int  len;
+
+            switch (*arg) {
+            case ',':
+                arg = SPN_WHITESPACE_CHARS(arg+1);
+                if ((*arg == ',') || (*arg == '|'))
+                    goto fail_return;
+                continue;
+
+            case '-':
+            case '!':
+                inv_val = true;
+                /* FALLTHROUGH */
+
+            case '+':
+            case '|':
+                arg = SPN_WHITESPACE_CHARS(arg+1);
+            }
+
+            len = (int)(BRK_SET_SEPARATOR_CHARS(arg) - arg);
+            if (len == 0)
+                break;
+
+            if ((len == 3) && (strncmp(arg, zAll, 3) == 0)) {
+                if (inv_val)
+                     res = 0;
+                else res = ~0UL;
+            }
+            else if ((len == 4) && (strncmp(arg, zNone, 4) == 0)) {
+                if (! inv_val)
+                    res = 0;
+            }
+            else do {
+                char *    pz;
+                uintptr_t bit = strtoul(arg, &pz, 0);
+
+                if (pz != arg + len) {
+                    bit = find_member_bit(opts, od, pz, len, nm_list, nm_ct);
+                    if (bit == 0UL)
+                        goto fail_return;
+                }
+                if (inv_val)
+                     res &= ~bit;
+                else res |= bit;
+            } while (false);
+
+            arg = SPN_WHITESPACE_CHARS(arg + len);
+        }
+
+        if (invert)
+            res ^= ~0UL;
+
+        if (nm_ct < (8 * sizeof(uintptr_t)))
+            res &= (1UL << nm_ct) - 1UL;
+
+        od->optCookie = (void *)res;
+    }
+    return;
+
+fail_return:
+    od->optCookie = (void *)0;
+}
+
+/** @}
+ *
+ * Local Variables:
+ * mode: C
+ * c-file-style: "stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * end of autoopts/enum.c */

+ 0 - 512
libopts/enumeration.c

@@ -1,512 +0,0 @@
-
-/*
- *  $Id: enumeration.c,v 4.26 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2008-07-27 12:28:01 bkorb"
- *
- *   Automated Options Paged Usage module.
- *
- *  This routine will run run-on options through a pager so the
- *  user may examine, print or edit them at their leisure.
- *
- *  This file is part of AutoOpts, a companion to AutoGen.
- *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
- *
- *  AutoOpts is available under any one of two licenses.  The license
- *  in use must be one of these two and the choice is under the control
- *  of the user of the license.
- *
- *   The GNU Lesser General Public License, version 3 or later
- *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
- *
- *   The Modified Berkeley Software Distribution License
- *      See the file "COPYING.mbsd"
- *
- *  These files have the following md5sums:
- *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
- */
-
-tSCC*  pz_enum_err_fmt;
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-enumError(
-    tOptions*     pOpts,
-    tOptDesc*     pOD,
-    tCC* const *  paz_names,
-    int           name_ct );
-
-static uintptr_t
-findName(
-    tCC*          pzName,
-    tOptions*     pOpts,
-    tOptDesc*     pOD,
-    tCC* const *  paz_names,
-    unsigned int  name_ct );
-/* = = = END-STATIC-FORWARD = = = */
-
-static void
-enumError(
-    tOptions*     pOpts,
-    tOptDesc*     pOD,
-    tCC* const *  paz_names,
-    int           name_ct )
-{
-    size_t max_len = 0;
-    size_t ttl_len = 0;
-    int    ct_down = name_ct;
-    int    hidden  = 0;
-
-    /*
-     *  A real "pOpts" pointer means someone messed up.  Give a real error.
-     */
-    if (pOpts > OPTPROC_EMIT_LIMIT)
-        fprintf(option_usage_fp, pz_enum_err_fmt, pOpts->pzProgName,
-                pOD->optArg.argString, pOD->pz_Name);
-
-    fprintf(option_usage_fp, zValidKeys, pOD->pz_Name);
-
-    /*
-     *  If the first name starts with this funny character, then we have
-     *  a first value with an unspellable name.  You cannot specify it.
-     *  So, we don't list it either.
-     */
-    if (**paz_names == 0x7F) {
-        paz_names++;
-        hidden  = 1;
-        ct_down = --name_ct;
-    }
-
-    /*
-     *  Figure out the maximum length of any name, plus the total length
-     *  of all the names.
-     */
-    {
-        tCC * const * paz = paz_names;
-
-        do  {
-            size_t len = strlen( *(paz++) ) + 1;
-            if (len > max_len)
-                max_len = len;
-            ttl_len += len;
-        } while (--ct_down > 0);
-
-        ct_down = name_ct;
-    }
-
-    /*
-     *  IF any one entry is about 1/2 line or longer, print one per line
-     */
-    if (max_len > 35) {
-        do  {
-            fprintf( option_usage_fp, "  %s\n", *(paz_names++) );
-        } while (--ct_down > 0);
-    }
-
-    /*
-     *  ELSE IF they all fit on one line, then do so.
-     */
-    else if (ttl_len < 76) {
-        fputc( ' ', option_usage_fp );
-        do  {
-            fputc( ' ', option_usage_fp );
-            fputs( *(paz_names++), option_usage_fp );
-        } while (--ct_down > 0);
-        fputc( '\n', option_usage_fp );
-    }
-
-    /*
-     *  Otherwise, columnize the output
-     */
-    else {
-        int   ent_no = 0;
-        char  zFmt[16];  /* format for all-but-last entries on a line */
-
-        sprintf( zFmt, "%%-%ds", (int)max_len );
-        max_len = 78 / max_len; /* max_len is now max entries on a line */
-        fputs( "  ", option_usage_fp );
-
-        /*
-         *  Loop through all but the last entry
-         */
-        ct_down = name_ct;
-        while (--ct_down > 0) {
-            if (++ent_no == max_len) {
-                /*
-                 *  Last entry on a line.  Start next line, too.
-                 */
-                fprintf( option_usage_fp, "%s\n  ", *(paz_names++) );
-                ent_no = 0;
-            }
-
-            else
-                fprintf(option_usage_fp, zFmt, *(paz_names++) );
-        }
-        fprintf(option_usage_fp, "%s\n", *paz_names);
-    }
-
-    if (pOpts > OPTPROC_EMIT_LIMIT) {
-        fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden);
-
-        (*(pOpts->pUsageProc))( pOpts, EXIT_FAILURE );
-        /* NOTREACHED */
-    }
-
-
-    if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) {
-        fprintf(option_usage_fp, zLowerBits, name_ct);
-        fputs(zSetMemberSettings, option_usage_fp);
-    } else {
-        fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden);
-    }
-}
-
-
-static uintptr_t
-findName(
-    tCC*          pzName,
-    tOptions*     pOpts,
-    tOptDesc*     pOD,
-    tCC* const *  paz_names,
-    unsigned int  name_ct )
-{
-    /*
-     *  Return the matching index as a pointer sized integer.
-     *  The result gets stashed in a char* pointer.
-     */
-    uintptr_t     res = name_ct;
-    size_t        len = strlen( (char*)pzName );
-    uintptr_t     idx;
-
-    if (IS_DEC_DIGIT_CHAR(*pzName)) {
-        char * pz = (char *)(void *)pzName;
-        unsigned long val = strtoul(pz, &pz, 0);
-        if ((*pz == NUL) && (val < name_ct))
-            return (uintptr_t)val;
-        enumError(pOpts, pOD, paz_names, (int)name_ct);
-        return name_ct;
-    }
-
-    /*
-     *  Look for an exact match, but remember any partial matches.
-     *  Multiple partial matches means we have an ambiguous match.
-     */
-    for (idx = 0; idx < name_ct; idx++) {
-        if (strncmp( (char*)paz_names[idx], (char*)pzName, len) == 0) {
-            if (paz_names[idx][len] == NUL)
-                return idx;  /* full match */
-
-            res = (res != name_ct) ? ~0 : idx; /* save partial match */
-        }
-    }
-
-    if (res < name_ct)
-        return res; /* partial match */
-
-    pz_enum_err_fmt = (res == name_ct) ? zNoKey : zAmbigKey;
-    option_usage_fp = stderr;
-    enumError(pOpts, pOD, paz_names, (int)name_ct);
-    return name_ct;
-}
-
-
-/*=export_func  optionKeywordName
- * what:  Convert between enumeration values and strings
- * private:
- *
- * arg:   tOptDesc*,     pOD,       enumeration option description
- * arg:   unsigned int,  enum_val,  the enumeration value to map
- *
- * ret_type:  char const*
- * ret_desc:  the enumeration name from const memory
- *
- * doc:   This converts an enumeration value into the matching string.
-=*/
-char const*
-optionKeywordName(
-    tOptDesc*     pOD,
-    unsigned int  enum_val )
-{
-    tOptDesc od;
-
-    od.optArg.argEnum = enum_val;
-    (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od );
-    return od.optArg.argString;
-}
-
-
-/*=export_func  optionEnumerationVal
- * what:  Convert from a string to an enumeration value
- * private:
- *
- * arg:   tOptions*,     pOpts,     the program options descriptor
- * arg:   tOptDesc*,     pOD,       enumeration option description
- * arg:   char const * const *,  paz_names, list of enumeration names
- * arg:   unsigned int,  name_ct,   number of names in list
- *
- * ret_type:  uintptr_t
- * ret_desc:  the enumeration value
- *
- * doc:   This converts the optArg.argString string from the option description
- *        into the index corresponding to an entry in the name list.
- *        This will match the generated enumeration value.
- *        Full matches are always accepted.  Partial matches are accepted
- *        if there is only one partial match.
-=*/
-uintptr_t
-optionEnumerationVal(
-    tOptions*     pOpts,
-    tOptDesc*     pOD,
-    tCC * const * paz_names,
-    unsigned int  name_ct )
-{
-    uintptr_t res = 0UL;
-
-    /*
-     *  IF the program option descriptor pointer is invalid,
-     *  then it is some sort of special request.
-     */
-    switch ((uintptr_t)pOpts) {
-    case (uintptr_t)OPTPROC_EMIT_USAGE:
-        /*
-         *  print the list of enumeration names.
-         */
-        enumError(pOpts, pOD, paz_names, (int)name_ct);
-        break;
-
-    case (uintptr_t)OPTPROC_EMIT_SHELL:
-    {
-        unsigned int ix = pOD->optArg.argEnum;
-        /*
-         *  print the name string.
-         */
-        if (ix >= name_ct)
-            printf( "INVALID-%d", ix );
-        else
-            fputs( paz_names[ ix ], stdout );
-
-        break;
-    }
-
-    case (uintptr_t)OPTPROC_RETURN_VALNAME:
-    {
-        tSCC zInval[] = "*INVALID*";
-        unsigned int ix = pOD->optArg.argEnum;
-        /*
-         *  Replace the enumeration value with the name string.
-         */
-        if (ix >= name_ct)
-            return (uintptr_t)zInval;
-
-        pOD->optArg.argString = paz_names[ix];
-        break;
-    }
-
-    default:
-        res = findName(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct);
-
-        if (pOD->fOptState & OPTST_ALLOC_ARG) {
-            AGFREE(pOD->optArg.argString);
-            pOD->fOptState &= ~OPTST_ALLOC_ARG;
-            pOD->optArg.argString = NULL;
-        }
-    }
-
-    return res;
-}
-
-
-/*=export_func  optionSetMembers
- * what:  Convert between bit flag values and strings
- * private:
- *
- * arg:   tOptions*,     pOpts,     the program options descriptor
- * arg:   tOptDesc*,     pOD,       enumeration option description
- * arg:   char const * const *,
- *                       paz_names, list of enumeration names
- * arg:   unsigned int,  name_ct,   number of names in list
- *
- * doc:   This converts the optArg.argString string from the option description
- *        into the index corresponding to an entry in the name list.
- *        This will match the generated enumeration value.
- *        Full matches are always accepted.  Partial matches are accepted
- *        if there is only one partial match.
-=*/
-void
-optionSetMembers(
-    tOptions*     pOpts,
-    tOptDesc*     pOD,
-    tCC* const *  paz_names,
-    unsigned int  name_ct )
-{
-    /*
-     *  IF the program option descriptor pointer is invalid,
-     *  then it is some sort of special request.
-     */
-    switch ((uintptr_t)pOpts) {
-    case (uintptr_t)OPTPROC_EMIT_USAGE:
-        /*
-         *  print the list of enumeration names.
-         */
-        enumError(OPTPROC_EMIT_USAGE, pOD, paz_names, (int)name_ct );
-        return;
-
-    case (uintptr_t)OPTPROC_EMIT_SHELL:
-    {
-        /*
-         *  print the name string.
-         */
-        int       ix   =  0;
-        uintptr_t bits = (uintptr_t)pOD->optCookie;
-        size_t    len  = 0;
-
-        bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1;
-
-        while (bits != 0) {
-            if (bits & 1) {
-                if (len++ > 0) fputs( " | ", stdout );
-                fputs(paz_names[ix], stdout);
-            }
-            if (++ix >= name_ct) break;
-            bits >>= 1;
-        }
-        return;
-    }
-
-    case (uintptr_t)OPTPROC_RETURN_VALNAME:
-    {
-        char*     pz;
-        uintptr_t bits = (uintptr_t)pOD->optCookie;
-        int       ix   = 0;
-        size_t    len  = 5;
-
-        bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1;
-
-        /*
-         *  Replace the enumeration value with the name string.
-         *  First, determine the needed length, then allocate and fill in.
-         */
-        while (bits != 0) {
-            if (bits & 1)
-                len += strlen( paz_names[ix]) + 8;
-            if (++ix >= name_ct) break;
-            bits >>= 1;
-        }
-
-        pOD->optArg.argString = pz = AGALOC(len, "enum name");
-
-        /*
-         *  Start by clearing all the bits.  We want to turn off any defaults
-         *  because we will be restoring to current state, not adding to
-         *  the default set of bits.
-         */
-        strcpy( pz, "none" );
-        pz += 4;
-        bits = (uintptr_t)pOD->optCookie;
-        bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1;
-        ix = 0;
-
-        while (bits != 0) {
-            if (bits & 1) {
-                strcpy( pz, " + " );
-                strcpy( pz+3, paz_names[ix]);
-                pz += strlen( paz_names[ix]) + 3;
-            }
-            if (++ix >= name_ct) break;
-            bits >>= 1;
-        }
-        return;
-    }
-
-    default:
-        break;
-    }
-
-    if ((pOD->fOptState & OPTST_RESET) != 0)
-        return;
-
-    {
-        tCC*      pzArg = pOD->optArg.argString;
-        uintptr_t res;
-        if ((pzArg == NULL) || (*pzArg == NUL)) {
-            pOD->optCookie = (void*)0;
-            return;
-        }
-
-        res = (uintptr_t)pOD->optCookie;
-        for (;;) {
-            tSCC zSpn[] = " ,|+\t\r\f\n";
-            int  iv, len;
-
-            pzArg += strspn( pzArg, zSpn );
-            iv = (*pzArg == '!');
-            if (iv)
-                pzArg += strspn( pzArg+1, zSpn ) + 1;
-
-            len = strcspn( pzArg, zSpn );
-            if (len == 0)
-                break;
-
-            if ((len == 3) && (strncmp(pzArg, zAll, (size_t)3) == 0)) {
-                if (iv)
-                     res = 0;
-                else res = ~0UL;
-            }
-            else if ((len == 4) && (strncmp(pzArg, zNone, (size_t)4) == 0)) {
-                if (! iv)
-                    res = 0;
-            }
-            else do {
-                char* pz;
-                uintptr_t bit = strtoul( pzArg, &pz, 0 );
-
-                if (pz != pzArg + len) {
-                    char z[ AO_NAME_SIZE ];
-                    tCC* p;
-                    int  shift_ct;
-
-                    if (*pz != NUL) {
-                        if (len >= AO_NAME_LIMIT)
-                            break;
-                        strncpy( z, pzArg, (size_t)len );
-                        z[len] = NUL;
-                        p = z;
-                    } else {
-                        p = pzArg;
-                    }
-
-                    shift_ct = findName(p, pOpts, pOD, paz_names, name_ct);
-                    if (shift_ct >= name_ct) {
-                        pOD->optCookie = (void*)0;
-                        return;
-                    }
-                    bit = 1UL << shift_ct;
-                }
-                if (iv)
-                     res &= ~bit;
-                else res |= bit;
-            } while (0);
-
-            if (pzArg[len] == NUL)
-                break;
-            pzArg += len + 1;
-        }
-        if (name_ct < (8 * sizeof( uintptr_t ))) {
-            res &= (1UL << name_ct) - 1UL;
-        }
-
-        pOD->optCookie = (void*)res;
-    }
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/enumeration.c */

+ 89 - 63
libopts/environment.c

@@ -1,16 +1,19 @@
 
-/*
- *  $Id: environment.c,v 4.21 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2009-07-20 20:12:24 bkorb"
+/**
+ * \file environment.c
  *
  *  This file contains all of the routines that must be linked into
  *  an executable to use the generated option processing.  The optional
  *  routines are in separately compiled modules so that they will not
  *  necessarily be linked in.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -22,53 +25,52 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
 static void
-checkEnvOpt(tOptState * os, char * env_name,
-            tOptions* pOpts, teEnvPresetType type);
+do_env_opt(tOptState * os, char * env_name,
+            tOptions * pOpts, teEnvPresetType type);
 /* = = = END-STATIC-FORWARD = = = */
 
 /*
  *  doPrognameEnv - check for preset values from the ${PROGNAME}
  *  environment variable.  This is accomplished by parsing the text into
  *  tokens, temporarily replacing the arg vector and calling
- *  doImmediateOpts and/or doRegularOpts.
+ *  immediate_opts and/or regular_opts.
  */
 LOCAL void
-doPrognameEnv( tOptions* pOpts, teEnvPresetType type )
+doPrognameEnv(tOptions * pOpts, teEnvPresetType type)
 {
-    char const*   pczOptStr = getenv( pOpts->pzPROGNAME );
-    token_list_t* pTL;
-    int           sv_argc;
-    tAoUI         sv_flag;
-    char**        sv_argv;
+    char const *        env_opts = getenv(pOpts->pzPROGNAME);
+    token_list_t*       pTL;
+    int                 sv_argc;
+    proc_state_mask_t   sv_flag;
+    char **             sv_argv;
 
     /*
      *  No such beast?  Then bail now.
      */
-    if (pczOptStr == NULL)
+    if (env_opts == NULL)
         return;
 
     /*
      *  Tokenize the string.  If there's nothing of interest, we'll bail
      *  here immediately.
      */
-    pTL = ao_string_tokenize( pczOptStr );
+    pTL = ao_string_tokenize(env_opts);
     if (pTL == NULL)
         return;
 
     /*
      *  Substitute our $PROGNAME argument list for the real one
      */
-    sv_argc = pOpts->origArgCt;
+    sv_argc = (int)pOpts->origArgCt;
     sv_argv = pOpts->origArgVect;
     sv_flag = pOpts->fOptSet;
 
@@ -78,8 +80,11 @@ doPrognameEnv( tOptions* pOpts, teEnvPresetType type )
      *  The option scanning code will skip the "program name" at the start
      *  of this list of tokens, so we accommodate this way ....
      */
-    pOpts->origArgVect = (char**)(pTL->tkn_list - 1);
-    pOpts->origArgCt   = pTL->tkn_ct   + 1;
+    {
+        uintptr_t v = (uintptr_t)(pTL->tkn_list);
+        pOpts->origArgVect = (void *)(v - sizeof(char *));
+    }
+    pOpts->origArgCt   = (unsigned int)pTL->tkn_ct   + 1;
     pOpts->fOptSet    &= ~OPTPROC_ERRSTOP;
 
     pOpts->curOptIdx   = 1;
@@ -87,43 +92,45 @@ doPrognameEnv( tOptions* pOpts, teEnvPresetType type )
 
     switch (type) {
     case ENV_IMM:
-        (void)doImmediateOpts( pOpts );
+        (void)immediate_opts(pOpts);
         break;
 
     case ENV_ALL:
-        (void)doImmediateOpts( pOpts );
+        (void)immediate_opts(pOpts);
         pOpts->curOptIdx = 1;
         pOpts->pzCurOpt  = NULL;
         /* FALLTHROUGH */
 
     case ENV_NON_IMM:
-        (void)doRegularOpts( pOpts );
+        (void)regular_opts(pOpts);
     }
 
     /*
      *  Free up the temporary arg vector and restore the original program args.
      */
-    free( pTL );
+    free(pTL);
     pOpts->origArgVect = sv_argv;
-    pOpts->origArgCt   = sv_argc;
+    pOpts->origArgCt   = (unsigned int)sv_argc;
     pOpts->fOptSet     = sv_flag;
 }
 
 static void
-checkEnvOpt(tOptState * os, char * env_name,
-            tOptions* pOpts, teEnvPresetType type)
+do_env_opt(tOptState * os, char * env_name,
+            tOptions * pOpts, teEnvPresetType type)
 {
-    os->pzOptArg = getenv( env_name );
+    os->pzOptArg = getenv(env_name);
     if (os->pzOptArg == NULL)
         return;
 
-    os->flags    = OPTST_PRESET | OPTST_ALLOC_ARG | os->pOD->fOptState;
-    os->optType  = TOPT_UNDEFINED;
+    os->flags   = OPTST_PRESET | OPTST_ALLOC_ARG | os->pOD->fOptState;
+    os->optType = TOPT_UNDEFINED;
 
     if (  (os->pOD->pz_DisablePfx != NULL)
-       && (streqvcmp( os->pzOptArg, os->pOD->pz_DisablePfx ) == 0)) {
+       && (streqvcmp(os->pzOptArg, os->pOD->pz_DisablePfx) == 0)) {
         os->flags |= OPTST_DISABLED;
         os->pzOptArg = NULL;
+        handle_opt(pOpts, os);
+        return;
     }
 
     switch (type) {
@@ -153,29 +160,35 @@ checkEnvOpt(tOptState * os, char * env_name,
      *  The interpretation of the option value depends
      *  on the type of value argument the option takes
      */
-    if (os->pzOptArg != NULL) {
-        if (OPTST_GET_ARGTYPE(os->pOD->fOptState) == OPARG_TYPE_NONE) {
-            os->pzOptArg = NULL;
-        } else if (  (os->pOD->fOptState & OPTST_ARG_OPTIONAL)
-                     && (*os->pzOptArg == NUL)) {
-            os->pzOptArg = NULL;
-        } else if (*os->pzOptArg == NUL) {
-            os->pzOptArg = zNil;
-        } else {
-            AGDUPSTR( os->pzOptArg, os->pzOptArg, "option argument" );
-            os->flags |= OPTST_ALLOC_ARG;
-        }
+    if (OPTST_GET_ARGTYPE(os->pOD->fOptState) == OPARG_TYPE_NONE) {
+        /*
+         *  Ignore any value.
+         */
+        os->pzOptArg = NULL;
+
+    } else if (os->pzOptArg[0] == NUL) {
+        /*
+         * If the argument is the empty string and the argument is
+         * optional, then treat it as if the option was not specified.
+         */
+        if ((os->pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
+            return;
+        os->pzOptArg = NULL;
+
+    } else {
+        AGDUPSTR(os->pzOptArg, os->pzOptArg, "option argument");
+        os->flags |= OPTST_ALLOC_ARG;
     }
 
-    handleOption( pOpts, os );
+    handle_opt(pOpts, os);
 }
 
 /*
- *  doEnvPresets - check for preset values from the envrionment
+ *  env_presets - check for preset values from the envrionment
  *  This routine should process in all, immediate or normal modes....
  */
 LOCAL void
-doEnvPresets( tOptions* pOpts, teEnvPresetType type )
+env_presets(tOptions * pOpts, teEnvPresetType type)
 {
     int        ct;
     tOptState  st;
@@ -190,16 +203,18 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type )
     if ((pOpts->fOptSet & OPTPROC_ENVIRON) == 0)
         return;
 
-    doPrognameEnv( pOpts, type );
+    doPrognameEnv(pOpts, type);
 
     ct  = pOpts->presetOptCt;
     st.pOD = pOpts->pOptDesc;
 
     pzFlagName = zEnvName
-        + snprintf( zEnvName, sizeof( zEnvName ), "%s_", pOpts->pzPROGNAME );
-    spaceLeft = AO_NAME_SIZE - (pzFlagName - zEnvName) - 1;
+        + snprintf(zEnvName, sizeof(zEnvName), "%s_", pOpts->pzPROGNAME);
+    spaceLeft = AO_NAME_SIZE - (unsigned long)(pzFlagName - zEnvName) - 1;
 
     for (;ct-- > 0; st.pOD++) {
+        size_t nln;
+
         /*
          *  If presetting is disallowed, then skip this entry
          */
@@ -211,14 +226,14 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type )
          *  IF there is no such environment variable,
          *  THEN skip this entry, too.
          */
-        if (strlen( st.pOD->pz_NAME ) >= spaceLeft)
-            continue;
-
-        /*
-         *  Set up the option state
-         */
-        strcpy( pzFlagName, st.pOD->pz_NAME );
-        checkEnvOpt(&st, zEnvName, pOpts, type);
+        nln = strlen(st.pOD->pz_NAME) + 1;
+        if (nln <= spaceLeft) {
+            /*
+             *  Set up the option state
+             */
+            memcpy(pzFlagName, st.pOD->pz_NAME, nln);
+            do_env_opt(&st, zEnvName, pOpts, type);
+        }
     }
 
     /*
@@ -226,13 +241,24 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type )
      */
     if (  (pOpts->specOptIdx.save_opts != NO_EQUIVALENT)
        && (pOpts->specOptIdx.save_opts != 0)) {
+        size_t nln;
         st.pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1;
-        strcpy( pzFlagName, st.pOD->pz_NAME );
-        checkEnvOpt(&st, zEnvName, pOpts, type);
+
+        if (st.pOD->pz_NAME == NULL)
+            return;
+
+        nln = strlen(st.pOD->pz_NAME) + 1;
+
+        if (nln > spaceLeft)
+            return;
+
+        memcpy(pzFlagName, st.pOD->pz_NAME, nln);
+        do_env_opt(&st, zEnvName, pOpts, type);
     }
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 133 - 102
libopts/file.c

@@ -1,11 +1,16 @@
 
-/*
- *  $Id: file.c,v 4.9 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2009-07-23 17:23:46 bkorb"
+/**
+ * \file file.c
+ *
+ * Handle options that have file names for arguments.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -17,12 +22,122 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+/**
+ *  Make sure the directory containing the subject file exists and that
+ *  the file exists or does not exist, per the option requirements.
+ *
+ * @param ftype file existence type flags
+ * @param pOpts program option descriptor
+ * @param pOD   the option descriptor
+ */
+static void
+check_existence(teOptFileType ftype, tOptions * pOpts, tOptDesc * pOD)
+{
+    char const * fname = pOD->optArg.argString;
+    struct stat sb;
+
+    errno = 0;
+
+    switch (ftype & FTYPE_MODE_EXIST_MASK) {
+    case FTYPE_MODE_MUST_NOT_EXIST:
+        if ((stat(fname, &sb) == 0) || (errno != ENOENT)) {
+            if (errno == 0)
+                errno = EINVAL;
+            fserr_exit(pOpts->pzProgName, "stat", fname);
+            /* NOTREACHED */
+        }
+        /* FALLTHROUGH */
+
+    default:
+    case FTYPE_MODE_MAY_EXIST:
+    {
+        char * p = strrchr(fname, DIRCH);
+        size_t l;
+
+        if (p == NULL)
+            /*
+             *  The file may or may not exist and its directory is ".".
+             *  Assume that "." exists.
+             */
+            break;
+
+        l = (size_t)(p - fname);
+        p = AGALOC(l + 1, "fname");
+        memcpy(p, fname, l);
+        p[l] = NUL;
+
+        if ((stat(p, &sb) != 0) || (errno = EINVAL, ! S_ISDIR(sb.st_mode)))
+            fserr_exit(pOpts->pzProgName, "stat", p);
+            /* NOTREACHED */
+
+        AGFREE(p);
+        break;
+    }
+
+    case FTYPE_MODE_MUST_EXIST:
+        if (  (stat(fname, &sb) != 0)
+           || (errno = EINVAL, ! S_ISREG(sb.st_mode))  )
+            fserr_exit(pOpts->pzProgName, "stat", fname);
+            /* NOTREACHED */
+
+        break;
+    }
+}
+
+/**
+ *  Open the specified file with open(2) and save the FD.
+ *
+ * @param pOpts program option descriptor
+ * @param pOD   the option descriptor
+ * @param mode  the open mode (uses int flags value)
+ */
+static void
+open_file_fd(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
+{
+    int fd = open(pOD->optArg.argString, mode.file_flags);
+    if (fd < 0)
+        fserr_exit(pOpts->pzProgName, "open", pOD->optArg.argString);
+        /* NOTREACHED */
+
+    if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
+        pOD->optCookie = (void *)pOD->optArg.argString;
+    else
+        AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
+
+    pOD->optArg.argFd = fd;
+    pOD->fOptState &= ~OPTST_ALLOC_ARG;
+}
+
+/**
+ *  Open the specified file with open(2) and save the FD.
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ * @param pOpts program option descriptor
+ * @param pOD   the option descriptor
+ * @param mode  the open mode (uses "char *" mode value)
  */
+static void
+fopen_file_fp(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode)
+{
+    FILE * fp = fopen(pOD->optArg.argString, mode.file_mode);
+    if (fp == NULL)
+        fserr_exit(pOpts->pzProgName, "fopen", pOD->optArg.argString);
+        /* NOTREACHED */
+
+    if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
+        pOD->optCookie = (void *)pOD->optArg.argString;
+    else
+        AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
+
+    pOD->optArg.argFp = fp;
+    pOD->fOptState &= ~OPTST_ALLOC_ARG;
+}
 
 /*=export_func  optionFileCheck
  * private:
@@ -41,7 +156,7 @@
  *   (FILE* pointer).
 =*/
 void
-optionFileCheck(tOptions* pOpts, tOptDesc* pOD,
+optionFileCheck(tOptions * pOpts, tOptDesc * pOD,
                 teOptFileType ftype, tuFileMode mode)
 {
     if (pOpts <= OPTPROC_EMIT_LIMIT) {
@@ -50,11 +165,11 @@ optionFileCheck(tOptions* pOpts, tOptDesc* pOD,
 
         switch (ftype & FTYPE_MODE_EXIST_MASK) {
         case FTYPE_MODE_MUST_NOT_EXIST:
-            fputs(zFileCannotExist, option_usage_fp);
+            fputs(zFileCannotExist + tab_skip_ct, option_usage_fp);
             break;
 
         case FTYPE_MODE_MUST_EXIST:
-            fputs(zFileMustExist, option_usage_fp);
+            fputs(zFileMustExist + tab_skip_ct, option_usage_fp);
             break;
         }
         return;
@@ -66,102 +181,18 @@ optionFileCheck(tOptions* pOpts, tOptDesc* pOD,
         return;
     }
 
-    {
-        struct stat sb;
-
-        errno = 0;
-
-        switch (ftype & FTYPE_MODE_EXIST_MASK) {
-        case FTYPE_MODE_MUST_NOT_EXIST:
-            if (  (stat(pOD->optArg.argString, &sb) == 0)
-               || (errno != ENOENT) ){
-                if (errno == 0)
-                    errno = EINVAL;
-                fprintf(stderr, zFSOptError, errno, strerror(errno),
-                        zFSOptErrNoExist, pOD->optArg.argString, pOD->pz_Name);
-                pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            /* FALLTHROUGH */
-
-        default:
-        case FTYPE_MODE_MAY_EXIST:
-        {
-            char * p = strrchr(pOD->optArg.argString, DIRCH);
-            if (p != NULL)
-                *p = NUL;
-            if (  (stat(pOD->optArg.argString, &sb) != 0)
-               || (errno = EINVAL, ! S_ISDIR(sb.st_mode)) ){
-                fprintf(stderr, zFSOptError, errno, strerror(errno),
-                        zFSOptErrMayExist, pOD->optArg.argString, pOD->pz_Name);
-                pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            if (p != NULL)
-                *p = DIRCH;
-            break;
-        }
-
-        case FTYPE_MODE_MUST_EXIST:
-            if (  (stat(pOD->optArg.argString, &sb) != 0)
-               || (errno = EINVAL, ! S_ISREG(sb.st_mode)) ){
-                fprintf(stderr, zFSOptError, errno, strerror(errno),
-                        zFSOptErrMustExist, pOD->optArg.argString,
-                        pOD->pz_Name);
-                pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-                /* NOTREACHED */
-            }
-            break;
-        }
-    }
+    check_existence(ftype, pOpts, pOD);
 
     switch (ftype & FTYPE_MODE_OPEN_MASK) {
     default:
-    case FTYPE_MODE_NO_OPEN:
-        break;
-
-    case FTYPE_MODE_OPEN_FD:
-    {
-        int fd = open(pOD->optArg.argString, mode.file_flags);
-        if (fd < 0) {
-            fprintf(stderr, zFSOptError, errno, strerror(errno),
-                    zFSOptErrOpen, pOD->optArg.argString, pOD->pz_Name);
-            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-            /* NOTREACHED */
-        }
-
-        if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
-            pOD->optCookie = (void *)pOD->optArg.argString;
-        else
-            AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
-
-        pOD->optArg.argFd = fd;
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
-        break;
-    }
-
-    case FTYPE_MODE_FOPEN_FP:
-    {
-        FILE* fp = fopen(pOD->optArg.argString, mode.file_mode);
-        if (fp == NULL) {
-            fprintf(stderr, zFSOptError, errno, strerror(errno),
-                    zFSOptErrFopen, pOD->optArg.argString, pOD->pz_Name);
-            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
-            /* NOTREACHED */
-        }
-
-        if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0)
-            pOD->optCookie = (void *)pOD->optArg.argString;
-        else
-            AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name");
-
-        pOD->optArg.argFp = fp;
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
-        break;
-    }
+    case FTYPE_MODE_NO_OPEN:  break;
+    case FTYPE_MODE_OPEN_FD:  open_file_fd( pOpts, pOD, mode); break;
+    case FTYPE_MODE_FOPEN_FP: fopen_file_fp(pOpts, pOD, mode); break;
     }
 }
-/*
+
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 780 - 0
libopts/find.c

@@ -0,0 +1,780 @@
+/**
+ * @file check.c
+ *
+ * @brief Hunt for options in the option descriptor list
+ *
+ *  This file contains the routines that deal with processing quoted strings
+ *  into an internal format.
+ *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+/* = = = START-STATIC-FORWARD = = = */
+static int
+parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz);
+
+static void
+opt_ambiguities(tOptions * opts, char const * name, int nm_len);
+
+static int
+opt_match_ct(tOptions * opts, char const * name, int nm_len,
+             int * ixp, bool * disable);
+
+static tSuccess
+opt_set(tOptions * opts, char * arg, int idx, bool disable, tOptState * st);
+
+static tSuccess
+opt_unknown(tOptions * opts, char const * name, char * arg, tOptState * st);
+
+static tSuccess
+opt_ambiguous(tOptions * opts, char const * name, int match_ct);
+
+static tSuccess
+get_opt_arg_must(tOptions * opts, tOptState * o_st);
+
+static tSuccess
+get_opt_arg_may(tOptions * pOpts, tOptState * o_st);
+
+static tSuccess
+get_opt_arg_none(tOptions * pOpts, tOptState* o_st);
+/* = = = END-STATIC-FORWARD = = = */
+
+/**
+ * find the name and name length we are looking for
+ */
+static int
+parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz)
+{
+    int  res = 0;
+    char const * p = *nm_pp;
+    *arg_pp  = NULL;
+
+    for (;;) {
+        switch (*(p++)) {
+        case NUL: return res;
+
+        case '=':
+            memcpy(buf, *nm_pp, (size_t)res);
+
+            buf[res] = NUL;
+            *nm_pp   = buf;
+            *arg_pp  = (char *)p;
+            return res;
+
+        default:
+            if (++res >= (int)bufsz)
+                return -1;
+        }
+    }
+}
+
+/**
+ *  print out the options that match the given name.
+ *
+ * @param pOpts      option data
+ * @param opt_name   name of option to look for
+ */
+static void
+opt_ambiguities(tOptions * opts, char const * name, int nm_len)
+{
+    char const * const hyph =
+        NAMED_OPTS(opts) ? "" : LONG_OPT_MARKER;
+
+    tOptDesc * pOD = opts->pOptDesc;
+    int        idx = 0;
+
+    fputs(zambig_list_msg, stderr);
+    do  {
+        if (pOD->pz_Name == NULL)
+            continue; /* doc option */
+
+        if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0)
+            fprintf(stderr, zambig_file, hyph, pOD->pz_Name);
+
+        else if (  (pOD->pz_DisableName != NULL)
+                && (strneqvcmp(name, pOD->pz_DisableName, nm_len) == 0)
+                )
+            fprintf(stderr, zambig_file, hyph, pOD->pz_DisableName);
+    } while (pOD++, (++idx < opts->optCt));
+}
+
+/**
+ *  Determine the number of options that match the name
+ *
+ * @param pOpts      option data
+ * @param opt_name   name of option to look for
+ * @param nm_len     length of provided name
+ * @param index      pointer to int for option index
+ * @param disable    pointer to bool to mark disabled option
+ * @return count of options that match
+ */
+static int
+opt_match_ct(tOptions * opts, char const * name, int nm_len,
+             int * ixp, bool * disable)
+{
+    int   matchCt  = 0;
+    int   idx      = 0;
+    int   idxLim   = opts->optCt;
+    tOptDesc * pOD = opts->pOptDesc;
+
+    do  {
+        /*
+         *  If option disabled or a doc option, skip to next
+         */
+        if (pOD->pz_Name == NULL)
+            continue;
+
+        if (  SKIP_OPT(pOD)
+           && (pOD->fOptState != (OPTST_OMITTED | OPTST_NO_INIT)))
+            continue;
+
+        if (strneqvcmp(name, pOD->pz_Name, nm_len) == 0) {
+            /*
+             *  IF we have a complete match
+             *  THEN it takes priority over any already located partial
+             */
+            if (pOD->pz_Name[ nm_len ] == NUL) {
+                *ixp = idx;
+                return 1;
+            }
+        }
+
+        /*
+         *  IF       there is a disable name
+         *     *AND* the option name matches the disable name
+         *  THEN ...
+         */
+        else if (  (pOD->pz_DisableName != NULL)
+                && (strneqvcmp(name, pOD->pz_DisableName, nm_len) == 0)
+                )  {
+            *disable = true;
+
+            /*
+             *  IF we have a complete match
+             *  THEN it takes priority over any already located partial
+             */
+            if (pOD->pz_DisableName[ nm_len ] == NUL) {
+                *ixp = idx;
+                return 1;
+            }
+        }
+
+        else
+            continue; /* does not match any option */
+
+        /*
+         *  We found a full or partial match, either regular or disabling.
+         *  Remember the index for later.
+         */
+        *ixp = idx;
+        ++matchCt;
+
+    } while (pOD++, (++idx < idxLim));
+
+    return matchCt;
+}
+
+/**
+ *  Set the option to the indicated option number.
+ *
+ * @param opts      option data
+ * @param arg       option argument (if glued to name)
+ * @param idx       option index
+ * @param disable   mark disabled option
+ * @param st        state about current option
+ */
+static tSuccess
+opt_set(tOptions * opts, char * arg, int idx, bool disable, tOptState * st)
+{
+    tOptDesc * pOD = opts->pOptDesc + idx;
+
+    if (SKIP_OPT(pOD)) {
+        if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0)
+            return FAILURE;
+
+        fprintf(stderr, zDisabledErr, opts->pzProgName, pOD->pz_Name);
+        if (pOD->pzText != NULL)
+            fprintf(stderr, SET_OFF_FMT, pOD->pzText);
+        fputc(NL, stderr);
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    /*
+     *  IF we found a disablement name,
+     *  THEN set the bit in the callers' flag word
+     */
+    if (disable)
+        st->flags |= OPTST_DISABLED;
+
+    st->pOD      = pOD;
+    st->pzOptArg = arg;
+    st->optType  = TOPT_LONG;
+
+    return SUCCESS;
+}
+
+/**
+ *  An option was not found.  Check for default option and set it
+ *  if there is one.  Otherwise, handle the error.
+ *
+ * @param opts   option data
+ * @param name   name of option to look for
+ * @param arg    option argument
+ * @param st     state about current option
+ *
+ * @return success status
+ */
+static tSuccess
+opt_unknown(tOptions * opts, char const * name, char * arg, tOptState * st)
+{
+    /*
+     *  IF there is no equal sign
+     *     *AND* we are using named arguments
+     *     *AND* there is a default named option,
+     *  THEN return that option.
+     */
+    if (  (arg == NULL)
+       && NAMED_OPTS(opts)
+       && (opts->specOptIdx.default_opt != NO_EQUIVALENT)) {
+
+        st->pOD      = opts->pOptDesc + opts->specOptIdx.default_opt;
+        st->pzOptArg = name;
+        st->optType  = TOPT_DEFAULT;
+        return SUCCESS;
+    }
+
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        fprintf(stderr, zIllOptStr, opts->pzProgPath, name);
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    return FAILURE;
+}
+
+/**
+ *  Several options match the provided name.
+ *
+ * @param opts      option data
+ * @param name      name of option to look for
+ * @param match_ct  number of matching options
+ *
+ * @return success status (always FAILURE, if it returns)
+ */
+static tSuccess
+opt_ambiguous(tOptions * opts, char const * name, int match_ct)
+{
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        fprintf(stderr, zambig_opt_fmt, opts->pzProgPath, name, match_ct);
+        if (match_ct <= 4)
+            opt_ambiguities(opts, name, (int)strlen(name));
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+    return FAILURE;
+}
+
+/*=export_func  optionVendorOption
+ * private:
+ *
+ * what:  Process a vendor option
+ * arg:   + tOptions * + pOpts    + program options descriptor +
+ * arg:   + tOptDesc * + pOptDesc + the descriptor for this arg +
+ *
+ * doc:
+ *  For POSIX specified utilities, the options are constrained to the options,
+ *  @xref{config attributes, Program Configuration}.  AutoOpts clients should
+ *  never specify this directly.  It gets referenced when the option
+ *  definitions contain a "vendor-opt" attribute.
+=*/
+void
+optionVendorOption(tOptions * pOpts, tOptDesc * pOD)
+{
+    tOptState     opt_st   = OPTSTATE_INITIALIZER(PRESET);
+    char const *  vopt_str = pOD->optArg.argString;
+
+    if (pOpts <= OPTPROC_EMIT_LIMIT)
+        return;
+
+    if ((pOD->fOptState & OPTST_RESET) != 0)
+        return;
+
+    if ((pOD->fOptState & OPTPROC_IMMEDIATE) == 0)
+        opt_st.flags = OPTST_DEFINED;
+
+    if (  ((pOpts->fOptSet & OPTPROC_VENDOR_OPT) == 0)
+       || ! SUCCESSFUL(opt_find_long(pOpts, vopt_str, &opt_st))
+       || ! SUCCESSFUL(get_opt_arg(pOpts, &opt_st)) )
+    {
+        fprintf(stderr, zIllVendOptStr, pOpts->pzProgName, vopt_str);
+        (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    /*
+     *  See if we are in immediate handling state.
+     */
+    if (pOpts->fOptSet & OPTPROC_IMMEDIATE) {
+        /*
+         *  See if the enclosed option is okay with that state.
+         */
+        if (DO_IMMEDIATELY(opt_st.flags))
+            (void)handle_opt(pOpts, &opt_st);
+
+    } else {
+        /*
+         *  non-immediate direction.
+         *  See if the enclosed option is okay with that state.
+         */
+        if (DO_NORMALLY(opt_st.flags) || DO_SECOND_TIME(opt_st.flags))
+            (void)handle_opt(pOpts, &opt_st);
+    }
+}
+
+/**
+ *  Find the option descriptor by full name.
+ *
+ * @param opts      option data
+ * @param opt_name  name of option to look for
+ * @param state     state about current option
+ *
+ * @return success status
+ */
+LOCAL tSuccess
+opt_find_long(tOptions * opts, char const * opt_name, tOptState * state)
+{
+    char    name_buf[128];
+    char *  opt_arg;
+    int     nm_len = parse_opt(&opt_name, &opt_arg, name_buf, sizeof(name_buf));
+
+    int     idx = 0;
+    bool    disable  = false;
+    int     ct;
+
+    if (nm_len <= 1) {
+        if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0)
+            return FAILURE;
+        
+        fprintf(stderr, zInvalOptName, opts->pzProgName, opt_name);
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    ct = opt_match_ct(opts, opt_name, nm_len, &idx, &disable);
+
+    /*
+     *  See if we found one match, no matches or multiple matches.
+     */
+    switch (ct) {
+    case 1:  return opt_set(opts, opt_arg, idx, disable, state);
+    case 0:  return opt_unknown(opts, opt_name, opt_arg, state);
+    default: return opt_ambiguous(opts, opt_name, ct);
+    }
+}
+
+
+/**
+ *  Find the short option descriptor for the current option
+ *
+ * @param pOpts      option data
+ * @param optValue   option flag character
+ * @param pOptState  state about current option
+ */
+LOCAL tSuccess
+opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState)
+{
+    tOptDesc*  pRes = pOpts->pOptDesc;
+    int        ct   = pOpts->optCt;
+
+    /*
+     *  Search the option list
+     */
+    do  {
+        if (optValue != pRes->optValue)
+            continue;
+
+        if (SKIP_OPT(pRes)) {
+            if (  (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT))
+               && (pRes->pz_Name != NULL)) {
+                if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0)
+                    return FAILURE;
+        
+                fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name);
+                if (pRes->pzText != NULL)
+                    fprintf(stderr, SET_OFF_FMT, pRes->pzText);
+                fputc(NL, stderr);
+                (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
+                /* NOTREACHED */
+                _exit(EXIT_FAILURE); /* to be certain */
+            }
+            goto short_opt_error;
+        }
+
+        pOptState->pOD     = pRes;
+        pOptState->optType = TOPT_SHORT;
+        return SUCCESS;
+
+    } while (pRes++, --ct > 0);
+
+    /*
+     *  IF    the character value is a digit
+     *    AND there is a special number option ("-n")
+     *  THEN the result is the "option" itself and the
+     *       option is the specially marked "number" option.
+     */
+    if (  IS_DEC_DIGIT_CHAR(optValue)
+       && (pOpts->specOptIdx.number_option != NO_EQUIVALENT) ) {
+        pOptState->pOD = \
+        pRes           = pOpts->pOptDesc + pOpts->specOptIdx.number_option;
+        (pOpts->pzCurOpt)--;
+        pOptState->optType = TOPT_SHORT;
+        return SUCCESS;
+    }
+
+ short_opt_error:
+
+    /*
+     *  IF we are to stop on errors (the default, actually)
+     *  THEN call the usage procedure.
+     */
+    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
+        fprintf(stderr, zIllOptChr, pOpts->pzProgPath, optValue);
+        (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE); /* to be certain */
+    }
+
+    return FAILURE;
+}
+
+/**
+ *  Process option with a required argument.  Long options can either have a
+ *  separate command line argument, or an argument attached by the '='
+ *  character.  Figure out which.
+ *
+ *  @param[in,out] opts  the program option descriptor
+ *  @param[in,out] o_st  the option processing state
+ *  @returns SUCCESS or FAILURE
+ */
+static tSuccess
+get_opt_arg_must(tOptions * opts, tOptState * o_st)
+{
+    switch (o_st->optType) {
+    case TOPT_SHORT:
+        /*
+         *  See if an arg string follows the flag character
+         */
+        if (*++(opts->pzCurOpt) == NUL)
+            opts->pzCurOpt = opts->origArgVect[ opts->curOptIdx++ ];
+        o_st->pzOptArg = opts->pzCurOpt;
+        break;
+
+    case TOPT_LONG:
+        /*
+         *  See if an arg string has already been assigned (glued on
+         *  with an `=' character)
+         */
+        if (o_st->pzOptArg == NULL)
+            o_st->pzOptArg = opts->origArgVect[ opts->curOptIdx++ ];
+        break;
+
+    default:
+#ifdef DEBUG
+        fputs("AutoOpts lib error: option type not selected\n", stderr);
+        option_exits(EXIT_FAILURE);
+#endif
+
+    case TOPT_DEFAULT:
+        /*
+         *  The option was selected by default.  The current token is
+         *  the option argument.
+         */
+        break;
+    }
+
+    /*
+     *  Make sure we did not overflow the argument list.
+     */
+    if (opts->curOptIdx > opts->origArgCt) {
+        fprintf(stderr, zMisArg, opts->pzProgPath, o_st->pOD->pz_Name);
+        return FAILURE;
+    }
+
+    opts->pzCurOpt = NULL;  /* next time advance to next arg */
+    return SUCCESS;
+}
+
+/**
+ * Process an option with an optional argument.  For short options, it looks
+ * at the character after the option character, or it consumes the next full
+ * argument.  For long options, it looks for an '=' character attachment to
+ * the long option name before deciding to take the next command line
+ * argument.
+ *
+ * @param pOpts      the option descriptor
+ * @param o_st  a structure for managing the current processing state
+ * @returns SUCCESS or does not return
+ */
+static tSuccess
+get_opt_arg_may(tOptions * pOpts, tOptState * o_st)
+{
+    /*
+     *  An option argument is optional.
+     */
+    switch (o_st->optType) {
+    case TOPT_SHORT:
+        if (*++pOpts->pzCurOpt != NUL)
+            o_st->pzOptArg = pOpts->pzCurOpt;
+        else {
+            char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ];
+
+            /*
+             *  BECAUSE it is optional, we must make sure
+             *  we did not find another flag and that there
+             *  is such an argument.
+             */
+            if ((pzLA == NULL) || (*pzLA == '-'))
+                o_st->pzOptArg = NULL;
+            else {
+                pOpts->curOptIdx++; /* argument found */
+                o_st->pzOptArg = pzLA;
+            }
+        }
+        break;
+
+    case TOPT_LONG:
+        /*
+         *  Look for an argument if we don't already have one (glued on
+         *  with a `=' character) *AND* we are not in named argument mode
+         */
+        if (  (o_st->pzOptArg == NULL)
+           && (! NAMED_OPTS(pOpts))) {
+            char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ];
+
+            /*
+             *  BECAUSE it is optional, we must make sure
+             *  we did not find another flag and that there
+             *  is such an argument.
+             */
+            if ((pzLA == NULL) || (*pzLA == '-'))
+                o_st->pzOptArg = NULL;
+            else {
+                pOpts->curOptIdx++; /* argument found */
+                o_st->pzOptArg = pzLA;
+            }
+        }
+        break;
+
+    default:
+    case TOPT_DEFAULT:
+        ao_bug(zbad_default_msg);
+    }
+
+    /*
+     *  After an option with an optional argument, we will
+     *  *always* start with the next option because if there
+     *  were any characters following the option name/flag,
+     *  they would be interpreted as the argument.
+     */
+    pOpts->pzCurOpt = NULL;
+    return SUCCESS;
+}
+
+/**
+ *  Process option that does not have an argument.
+ *
+ *  @param[in,out] opts  the program option descriptor
+ *  @param[in,out] o_st  the option processing state
+ *  @returns SUCCESS or FAILURE
+ */
+static tSuccess
+get_opt_arg_none(tOptions * pOpts, tOptState* o_st)
+{
+    /*
+     *  No option argument.  Make sure next time around we find
+     *  the correct option flag character for short options
+     */
+    if (o_st->optType == TOPT_SHORT)
+        (pOpts->pzCurOpt)++;
+
+    /*
+     *  It is a long option.  Make sure there was no ``=xxx'' argument
+     */
+    else if (o_st->pzOptArg != NULL) {
+        fprintf(stderr, zNoArg, pOpts->pzProgPath, o_st->pOD->pz_Name);
+        return FAILURE;
+    }
+
+    /*
+     *  It is a long option.  Advance to next command line argument.
+     */
+    else
+        pOpts->pzCurOpt = NULL;
+    return SUCCESS;
+}
+
+/**
+ *  Process option.  Figure out whether or not to look for an option argument.
+ *
+ *  @param[in,out] opts  the program option descriptor
+ *  @param[in,out] o_st  the option processing state
+ *  @returns SUCCESS or FAILURE
+ */
+LOCAL tSuccess
+get_opt_arg(tOptions * opts, tOptState * o_st)
+{
+    o_st->flags |= (o_st->pOD->fOptState & OPTST_PERSISTENT_MASK);
+
+    /*
+     * Disabled options and options specified to not have arguments
+     * are handled with the "none" procedure.  Otherwise, check the
+     * optional flag and call either the "may" or "must" function.
+     */
+    if (  ((o_st->flags & OPTST_DISABLED) != 0)
+       || (OPTST_GET_ARGTYPE(o_st->flags) == OPARG_TYPE_NONE))
+        return get_opt_arg_none(opts, o_st);
+    
+    if (o_st->flags & OPTST_ARG_OPTIONAL)
+        return get_opt_arg_may( opts, o_st);
+    
+    return get_opt_arg_must(opts, o_st);
+}
+
+/**
+ *  Find the option descriptor for the current option.
+ *
+ *  @param[in,out] opts  the program option descriptor
+ *  @param[in,out] o_st  the option processing state
+ *  @returns SUCCESS or FAILURE
+ */
+LOCAL tSuccess
+find_opt(tOptions * opts, tOptState * o_st)
+{
+    /*
+     *  IF we are continuing a short option list (e.g. -xyz...)
+     *  THEN continue a single flag option.
+     *  OTHERWISE see if there is room to advance and then do so.
+     */
+    if ((opts->pzCurOpt != NULL) && (*opts->pzCurOpt != NUL))
+        return opt_find_short(opts, (uint8_t)*(opts->pzCurOpt), o_st);
+
+    if (opts->curOptIdx >= opts->origArgCt)
+        return PROBLEM; /* NORMAL COMPLETION */
+
+    opts->pzCurOpt = opts->origArgVect[ opts->curOptIdx ];
+
+    /*
+     *  IF all arguments must be named options, ...
+     */
+    if (NAMED_OPTS(opts)) {
+        char *      pz  = opts->pzCurOpt;
+        int         def;
+        tSuccess    res;
+        uint16_t *  def_opt;
+
+        opts->curOptIdx++;
+
+        if (*pz != '-')
+            return opt_find_long(opts, pz, o_st);
+
+        /*
+         *  The name is prefixed with one or more hyphens.  Strip them off
+         *  and disable the "default_opt" setting.  Use heavy recasting to
+         *  strip off the "const" quality of the "default_opt" field.
+         */
+        while (*(++pz) == '-')   ;
+        def_opt  = (void *)&(opts->specOptIdx.default_opt);
+        def      = *def_opt;
+        *def_opt = NO_EQUIVALENT;
+        res      = opt_find_long(opts, pz, o_st);
+        *def_opt = (uint16_t)def;
+        return res;
+    }
+
+    /*
+     *  Note the kind of flag/option marker
+     */
+    if (*((opts->pzCurOpt)++) != '-')
+        return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
+
+    /*
+     *  Special hack for a hyphen by itself
+     */
+    if (*(opts->pzCurOpt) == NUL)
+        return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
+
+    /*
+     *  The current argument is to be processed as an option argument
+     */
+    opts->curOptIdx++;
+
+    /*
+     *  We have an option marker.
+     *  Test the next character for long option indication
+     */
+    if (opts->pzCurOpt[0] == '-') {
+        if (*++(opts->pzCurOpt) == NUL)
+            /*
+             *  NORMAL COMPLETION - NOT this arg, but rest are operands
+             */
+            return PROBLEM;
+
+        /*
+         *  We do not allow the hyphen to be used as a flag value.
+         *  Therefore, if long options are not to be accepted, we punt.
+         */
+        if ((opts->fOptSet & OPTPROC_LONGOPT) == 0) {
+            fprintf(stderr, zIllOptStr, opts->pzProgPath, opts->pzCurOpt-2);
+            return FAILURE;
+        }
+
+        return opt_find_long(opts, opts->pzCurOpt, o_st);
+    }
+
+    /*
+     *  If short options are not allowed, then do long
+     *  option processing.  Otherwise the character must be a
+     *  short (i.e. single character) option.
+     */
+    if ((opts->fOptSet & OPTPROC_SHORTOPT) != 0)
+        return opt_find_short(opts, (uint8_t)*(opts->pzCurOpt), o_st);
+
+    return opt_find_long(opts, opts->pzCurOpt, o_st);
+}
+
+/** @}
+ *
+ * Local Variables:
+ * mode: C
+ * c-file-style: "stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * end of autoopts/find.c */

File diff suppressed because it is too large
+ 689 - 200
libopts/genshell.c


+ 127 - 83
libopts/genshell.h

@@ -1,41 +1,44 @@
 /*   -*- buffer-read-only: t -*- vi: set ro:
- *  
+ *
  *  DO NOT EDIT THIS FILE   (genshell.h)
- *  
- *  It has been AutoGen-ed  August  8, 2009 at 10:14:45 AM by AutoGen 5.9.9
+ *
+ *  It has been AutoGen-ed
  *  From the definitions    genshell.def
  *  and the template file   options
  *
- * Generated from AutoOpts @AO_CURRENT@:@AO_REVISION@:@AO_AGE@ templates.
- */
-
-/*
- *  This file was produced by an AutoOpts template.  AutoOpts is a
- *  copyrighted work.  This header file is not encumbered by AutoOpts
- *  licensing, but is provided under the licensing terms chosen by the
- *  genshellopt author or copyright holder.  AutoOpts is licensed under
- *  the terms of the LGPL.  The redistributable library (``libopts'') is
- *  licensed under the terms of either the LGPL or, at the users discretion,
- *  the BSD license.  See the AutoOpts and/or libopts sources for details.
+ * Generated from AutoOpts 41:0:16 templates.
+ *
+ *  AutoOpts is a copyrighted work.  This header file is not encumbered
+ *  by AutoOpts licensing, but is provided under the licensing terms chosen
+ *  by the genshellopt author or copyright holder.  AutoOpts is
+ *  licensed under the terms of the LGPL.  The redistributable library
+ *  (``libopts'') is licensed under the terms of either the LGPL or, at the
+ *  users discretion, the BSD license.  See the AutoOpts and/or libopts sources
+ *  for details.
+ *
+ * The genshellopt program is copyrighted and licensed
+ * under the following terms:
+ *
+ *  Copyright (C) 1999-2014 Bruce Korb, all rights reserved.
+ *  This is free software. It is licensed for use, modification and
+ *  redistribution under the terms of the GNU Lesser General Public License,
+ *  version 2 or later <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
  *
- * This source file is copyrighted and licensed under the following terms:
+ *  The genshellopt library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
  *
- * genshellopt copyright (c) 1999-2009 Bruce Korb - all rights reserved
+ *  This library is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
  *
- * genshellopt is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * genshellopt is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along
- * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, see
+ *  <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>
  */
-/*
+/**
  *  This file contains the programmatic interface to the Automated
  *  Options generated for the genshellopt program.
  *  These macros are documented in the AutoGen info file in the
@@ -45,94 +48,134 @@
 #define AUTOOPTS_GENSHELL_H_GUARD 1
 #include <autoopts/options.h>
 
-/*
+/**
  *  Ensure that the library used for compiling this generated header is at
  *  least as new as the version current when the header template was released
  *  (not counting patch version increments).  Also ensure that the oldest
  *  tolerable version is at least as old as what was current when the header
  *  template was released.
  */
-#define AO_TEMPLATE_VERSION 131074
+#define AO_TEMPLATE_VERSION 167936
 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
  || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
 # error option template version mismatches autoopts/options.h header
   Choke Me.
 #endif
 
-/*
- *  Enumeration of each option:
+/**
+ *  Enumeration of each option type for genshellopt
  */
 typedef enum {
-    INDEX_OPT_SCRIPT      =  0,
-    INDEX_OPT_SHELL       =  1,
-    INDEX_OPT_VERSION     =  2,
-    INDEX_OPT_HELP        =  3,
-    INDEX_OPT_MORE_HELP   =  4
-} teOptIndex;
-
-#define OPTION_CT    5
+    INDEX_GENSHELL_OPT_SCRIPT      =  0,
+    INDEX_GENSHELL_OPT_SHELL       =  1,
+    INDEX_GENSHELL_OPT_VERSION     =  2,
+    INDEX_GENSHELL_OPT_HELP        =  3,
+    INDEX_GENSHELL_OPT_MORE_HELP   =  4
+} teGenshell_OptIndex;
+/** count of all options for genshellopt */
+#define GENSHELL_OPTION_CT    5
+/** genshellopt version */
 #define GENSHELLOPT_VERSION       "1"
-#define GENSHELLOPT_FULL_VERSION  "genshellopt - Generate Shell Option Processing Script - Ver. 1"
+/** Full genshellopt version text */
+#define GENSHELLOPT_FULL_VERSION  "genshellopt 1"
 
-/*
+/**
  *  Interface defines for all options.  Replace "n" with the UPPER_CASED
- *  option name (as in the teOptIndex enumeration above).
- *  e.g. HAVE_OPT( SCRIPT )
+ *  option name (as in the teGenshell_OptIndex enumeration above).
+ *  e.g. HAVE_GENSHELL_OPT(SCRIPT)
  */
-#define         DESC(n) (genshelloptOptions.pOptDesc[INDEX_OPT_## n])
-#define     HAVE_OPT(n) (! UNUSED_OPT(& DESC(n)))
-#define      OPT_ARG(n) (DESC(n).optArg.argString)
-#define    STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK)
-#define    COUNT_OPT(n) (DESC(n).optOccCt)
-#define    ISSEL_OPT(n) (SELECTED_OPT(&DESC(n)))
-#define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n)))
-#define  ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n)))
-#define  STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt)
-#define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs)
-#define    CLEAR_OPT(n) STMTS( \
-                DESC(n).fOptState &= OPTST_PERSISTENT_MASK;   \
-                if ( (DESC(n).fOptState & OPTST_INITENABLED) == 0) \
-                    DESC(n).fOptState |= OPTST_DISABLED; \
-                DESC(n).optCookie = NULL )
-
-/* * * * * *
- *
+#define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n])
+/** 'true' if an option has been specified in any way */
+#define     HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n)))
+/** The string argument to an option. The argument type must be \"string\". */
+#define      GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString)
+/** Mask the option state revealing how an option was specified.
+ *  It will be one and only one of \a OPTST_SET, \a OPTST_PRESET,
+ * \a OPTST_DEFINED, \a OPTST_RESET or zero.
+ */
+#define    STATE_GENSHELL_OPT(n) (GENSHELL_DESC(n).fOptState & OPTST_SET_MASK)
+/** Count of option's occurrances *on the command line*. */
+#define    COUNT_GENSHELL_OPT(n) (GENSHELL_DESC(n).optOccCt)
+/** mask of \a OPTST_SET and \a OPTST_DEFINED. */
+#define    ISSEL_GENSHELL_OPT(n) (SELECTED_OPT(&GENSHELL_DESC(n)))
+/** 'true' if \a HAVE_OPT would yield 'false'. */
+#define ISUNUSED_GENSHELL_OPT(n) (UNUSED_OPT(& GENSHELL_DESC(n)))
+/** 'true' if OPTST_DISABLED bit not set. */
+#define  ENABLED_GENSHELL_OPT(n) (! DISABLED_OPT(& GENSHELL_DESC(n)))
+/** number of stacked option arguments.
+ *  Valid only for stacked option arguments. */
+#define  STACKCT_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->useCt)
+/** stacked argument vector.
+ *  Valid only for stacked option arguments. */
+#define STACKLST_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->apzArgs)
+/** Reset an option. */
+#define    CLEAR_GENSHELL_OPT(n) STMTS( \
+                GENSHELL_DESC(n).fOptState &= OPTST_PERSISTENT_MASK;   \
+                if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \
+                    GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \
+                GENSHELL_DESC(n).optCookie = NULL )
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/**
+ *  Enumeration of genshellopt exit codes
+ */
+typedef enum {
+    GENSHELLOPT_EXIT_SUCCESS         = 0,
+    GENSHELLOPT_EXIT_FAILURE         = 1,
+    GENSHELLOPT_EXIT_USAGE_ERROR     = 64,
+    GENSHELLOPT_EXIT_LIBOPTS_FAILURE = 70
+}   genshellopt_exit_code_t;
+/**
  *  Interface defines for specific options.
+ * @{
  */
-#define VALUE_OPT_SCRIPT         'o'
-#define VALUE_OPT_SHELL          's'
-#define VALUE_OPT_HELP          '?'
-#define VALUE_OPT_MORE_HELP     '!'
-#define VALUE_OPT_VERSION       'v'
+#define VALUE_GENSHELL_OPT_SCRIPT 'o'
+#define VALUE_GENSHELL_OPT_SHELL 's'
+/** option flag (value) for help-value option */
+#define VALUE_GENSHELL_OPT_HELP '?'
+/** option flag (value) for more-help-value option */
+#define VALUE_GENSHELL_OPT_MORE_HELP '!'
+/** option flag (value) for version-value option */
+#define VALUE_GENSHELL_OPT_VERSION 'v'
 /*
  *  Interface defines not associated with particular options
  */
-#define ERRSKIP_OPTERR  STMTS( genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP )
-#define ERRSTOP_OPTERR  STMTS( genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP )
-#define RESTART_OPT(n)  STMTS( \
+#define ERRSKIP_GENSHELL_OPTERR  STMTS(genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP)
+#define ERRSTOP_GENSHELL_OPTERR  STMTS(genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP)
+#define RESTART_GENSHELL_OPT(n)  STMTS( \
                 genshelloptOptions.curOptIdx = (n); \
                 genshelloptOptions.pzCurOpt  = NULL )
-#define START_OPT       RESTART_OPT(1)
-#define USAGE(c)        (*genshelloptOptions.pUsageProc)( &genshelloptOptions, c )
-/* extracted from opthead.tpl near line 409 */
+#define START_GENSHELL_OPT       RESTART_GENSHELL_OPT(1)
+#define GENSHELL_USAGE(c)        (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c)
 
-/* * * * * *
- *
- *  Declare the genshellopt option descriptor.
- */
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
-extern tOptions   genshelloptOptions;
+
+/* * * * * *
+ *
+ *  Declare the genshellopt option descriptor.
+ */
+extern tOptions genshelloptOptions;
 
 #if defined(ENABLE_NLS)
 # ifndef _
 #   include <stdio.h>
-    static inline char* aoGetsText( char const* pz ) {
-        if (pz == NULL) return NULL;
-        return (char*)gettext( pz );
-    }
+#   ifndef HAVE_GETTEXT
+      extern char * gettext(char const *);
+#   else
+#     include <libintl.h>
+#   endif
+
+# ifndef ATTRIBUTE_FORMAT_ARG
+#   define ATTRIBUTE_FORMAT_ARG(_a)
+# endif
+
+static inline char* aoGetsText(char const* pz) ATTRIBUTE_FORMAT_ARG(1);
+static inline char* aoGetsText(char const* pz) {
+    if (pz == NULL) return NULL;
+    return (char*)gettext(pz);
+}
 #   define _(s)  aoGetsText(s)
 # endif /* _() */
 
@@ -162,4 +205,5 @@ extern tOptions   genshelloptOptions;
 }
 #endif
 #endif /* AUTOOPTS_GENSHELL_H_GUARD */
+
 /* genshell.h ends here */

+ 288 - 0
libopts/gettext.h

@@ -0,0 +1,288 @@
+/* Convenience header for conditional use of GNU <libintl.h>.
+   Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2014 Free Software
+   Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License along
+   with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef _LIBGETTEXT_H
+#define _LIBGETTEXT_H 1
+
+/* NLS can be disabled through the configure --disable-nls option.  */
+#if ENABLE_NLS
+
+/* Get declarations of GNU message catalog functions.  */
+# include <libintl.h>
+
+/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
+   the gettext() and ngettext() macros.  This is an alternative to calling
+   textdomain(), and is useful for libraries.  */
+# ifdef DEFAULT_TEXT_DOMAIN
+#  undef gettext
+#  define gettext(Msgid) \
+     dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
+#  undef ngettext
+#  define ngettext(Msgid1, Msgid2, N) \
+     dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
+# endif
+
+#else
+
+/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
+   chokes if dcgettext is defined as a macro.  So include it now, to make
+   later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
+   as well because people using "gettext.h" will not include <libintl.h>,
+   and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
+   is OK.  */
+#if defined(__sun)
+# include <locale.h>
+#endif
+
+/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
+   <libintl.h>, which chokes if dcgettext is defined as a macro.  So include
+   it now, to make later inclusions of <libintl.h> a NOP.  */
+#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
+# include <cstdlib>
+# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
+#  include <libintl.h>
+# endif
+#endif
+
+/* Disabled NLS.
+   The casts to 'const char *' serve the purpose of producing warnings
+   for invalid uses of the value returned from these functions.
+   On pre-ANSI systems without 'const', the config.h file is supposed to
+   contain "#define const".  */
+# undef gettext
+# define gettext(Msgid) ((const char *) (Msgid))
+# undef dgettext
+# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
+# undef dcgettext
+# define dcgettext(Domainname, Msgid, Category) \
+    ((void) (Category), dgettext (Domainname, Msgid))
+# undef ngettext
+# define ngettext(Msgid1, Msgid2, N) \
+    ((N) == 1 \
+     ? ((void) (Msgid2), (const char *) (Msgid1)) \
+     : ((void) (Msgid1), (const char *) (Msgid2)))
+# undef dngettext
+# define dngettext(Domainname, Msgid1, Msgid2, N) \
+    ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
+# undef dcngettext
+# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
+    ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
+# undef textdomain
+# define textdomain(Domainname) ((const char *) (Domainname))
+# undef bindtextdomain
+# define bindtextdomain(Domainname, Dirname) \
+    ((void) (Domainname), (const char *) (Dirname))
+# undef bind_textdomain_codeset
+# define bind_textdomain_codeset(Domainname, Codeset) \
+    ((void) (Domainname), (const char *) (Codeset))
+
+#endif
+
+/* Prefer gnulib's setlocale override over libintl's setlocale override.  */
+#ifdef GNULIB_defined_setlocale
+# undef setlocale
+# define setlocale rpl_setlocale
+#endif
+
+/* A pseudo function call that serves as a marker for the automated
+   extraction of messages, but does not call gettext().  The run-time
+   translation is done at a different place in the code.
+   The argument, String, should be a literal string.  Concatenated strings
+   and other string expressions won't work.
+   The macro's expansion is not parenthesized, so that it is suitable as
+   initializer for static 'char[]' or 'const char[]' variables.  */
+#define gettext_noop(String) String
+
+/* The separator between msgctxt and msgid in a .mo file.  */
+#define GETTEXT_CONTEXT_GLUE "\004"
+
+/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
+   MSGID.  MSGCTXT and MSGID must be string literals.  MSGCTXT should be
+   short and rarely need to change.
+   The letter 'p' stands for 'particular' or 'special'.  */
+#ifdef DEFAULT_TEXT_DOMAIN
+# define pgettext(Msgctxt, Msgid) \
+   pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
+#else
+# define pgettext(Msgctxt, Msgid) \
+   pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
+#endif
+#define dpgettext(Domainname, Msgctxt, Msgid) \
+  pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
+#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
+  pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
+#ifdef DEFAULT_TEXT_DOMAIN
+# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
+   npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
+#else
+# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
+   npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
+#endif
+#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
+  npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
+#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
+  npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+pgettext_aux (const char *domain,
+              const char *msg_ctxt_id, const char *msgid,
+              int category)
+{
+  const char *translation = dcgettext (domain, msg_ctxt_id, category);
+  if (translation == msg_ctxt_id)
+    return msgid;
+  else
+    return translation;
+}
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+npgettext_aux (const char *domain,
+               const char *msg_ctxt_id, const char *msgid,
+               const char *msgid_plural, unsigned long int n,
+               int category)
+{
+  const char *translation =
+    dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
+  if (translation == msg_ctxt_id || translation == msgid_plural)
+    return (n == 1 ? msgid : msgid_plural);
+  else
+    return translation;
+}
+
+/* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
+   can be arbitrary expressions.  But for string literals these macros are
+   less efficient than those above.  */
+
+#include <string.h>
+
+#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
+     /* || __STDC_VERSION__ >= 199901L */ )
+# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
+#else
+# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
+#endif
+
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+#include <stdlib.h>
+#endif
+
+#define pgettext_expr(Msgctxt, Msgid) \
+  dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
+#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
+  dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+dcpgettext_expr (const char *domain,
+                 const char *msgctxt, const char *msgid,
+                 int category)
+{
+  size_t msgctxt_len = strlen (msgctxt) + 1;
+  size_t msgid_len = strlen (msgid) + 1;
+  const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+  char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+  char buf[1024];
+  char *msg_ctxt_id =
+    (msgctxt_len + msgid_len <= sizeof (buf)
+     ? buf
+     : (char *) malloc (msgctxt_len + msgid_len));
+  if (msg_ctxt_id != NULL)
+#endif
+    {
+      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+      msg_ctxt_id[msgctxt_len - 1] = '\004';
+      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+      translation = dcgettext (domain, msg_ctxt_id, category);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+      if (msg_ctxt_id != buf)
+        free (msg_ctxt_id);
+#endif
+      if (translation != msg_ctxt_id)
+        return translation;
+    }
+  return msgid;
+}
+
+#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
+  dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
+#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
+  dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+dcnpgettext_expr (const char *domain,
+                  const char *msgctxt, const char *msgid,
+                  const char *msgid_plural, unsigned long int n,
+                  int category)
+{
+  size_t msgctxt_len = strlen (msgctxt) + 1;
+  size_t msgid_len = strlen (msgid) + 1;
+  const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+  char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+  char buf[1024];
+  char *msg_ctxt_id =
+    (msgctxt_len + msgid_len <= sizeof (buf)
+     ? buf
+     : (char *) malloc (msgctxt_len + msgid_len));
+  if (msg_ctxt_id != NULL)
+#endif
+    {
+      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+      msg_ctxt_id[msgctxt_len - 1] = '\004';
+      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+      translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+      if (msg_ctxt_id != buf)
+        free (msg_ctxt_id);
+#endif
+      if (!(translation == msg_ctxt_id || translation == msgid_plural))
+        return translation;
+    }
+  return (n == 1 ? msgid : msgid_plural);
+}
+
+#endif /* _LIBGETTEXT_H */

+ 298 - 0
libopts/init.c

@@ -0,0 +1,298 @@
+/**
+ * \file initialize.c
+ *
+ *  initialize the libopts data structures.
+ *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
+ *  This file is part of AutoOpts, a companion to AutoGen.
+ *  AutoOpts is free software.
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
+ *
+ *  AutoOpts is available under any one of two licenses.  The license
+ *  in use must be one of these two and the choice is under the control
+ *  of the user of the license.
+ *
+ *   The GNU Lesser General Public License, version 3 or later
+ *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
+ *
+ *   The Modified Berkeley Software Distribution License
+ *      See the file "COPYING.mbsd"
+ *
+ *  These files have the following sha256 sums:
+ *
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
+ */
+
+/* = = = START-STATIC-FORWARD = = = */
+static tSuccess
+do_presets(tOptions * opts);
+/* = = = END-STATIC-FORWARD = = = */
+
+/**
+ *  Make sure the option descriptor is there and that we understand it.
+ *  This should be called from any user entry point where one needs to
+ *  worry about validity.  (Some entry points are free to assume that
+ *  the call is not the first to the library and, thus, that this has
+ *  already been called.)
+ *
+ *  Upon successful completion, pzProgName and pzProgPath are set.
+ *
+ *  @param[in,out] opts   program options descriptor
+ *  @param[in]     pname  name of program, from argv[]
+ *  @returns SUCCESS or FAILURE
+ */
+LOCAL tSuccess
+validate_struct(tOptions * opts, char const * pname)
+{
+    if (opts == NULL) {
+        fputs(zno_opt_arg, stderr);
+        return FAILURE;
+    }
+    print_exit = ((opts->fOptSet & OPTPROC_SHELL_OUTPUT) != 0);
+
+    /*
+     *  IF the client has enabled translation and the translation procedure
+     *  is available, then go do it.
+     */
+    if (  ((opts->fOptSet & OPTPROC_TRANSLATE) != 0)
+       && (opts->pTransProc != NULL)
+       && (option_xlateable_txt.field_ct != 0) ) {
+        /*
+         *  If option names are not to be translated at all, then do not do
+         *  it for configuration parsing either.  (That is the bit that really
+         *  gets tested anyway.)
+         */
+        if ((opts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT)
+            opts->fOptSet |= OPTPROC_NXLAT_OPT_CFG;
+        (*opts->pTransProc)();
+    }
+
+    /*
+     *  IF the struct version is not the current, and also
+     *     either too large (?!) or too small,
+     *  THEN emit error message and fail-exit
+     */
+    if (  ( opts->structVersion  != OPTIONS_STRUCT_VERSION  )
+       && (  (opts->structVersion > OPTIONS_STRUCT_VERSION  )
+          || (opts->structVersion < OPTIONS_MINIMUM_VERSION )
+       )  )  {
+
+        static char const ao_ver_string[] =
+            STR(AO_CURRENT)":"STR(AO_REVISION)":"STR(AO_AGE)"\n";
+
+        fprintf(stderr, zwrong_ver, pname, NUM_TO_VER(opts->structVersion));
+        if (opts->structVersion > OPTIONS_STRUCT_VERSION )
+            fputs(ztoo_new, stderr);
+        else
+            fputs(ztoo_old, stderr);
+
+        fwrite(ao_ver_string, sizeof(ao_ver_string) - 1, 1, stderr);
+        return FAILURE;
+    }
+
+    /*
+     *  If the program name hasn't been set, then set the name and the path
+     *  and the set of equivalent characters.
+     */
+    if (opts->pzProgName == NULL) {
+        char const *  pz = strrchr(pname, DIRCH);
+        char const ** pp =
+            (char const **)(void **)&(opts->pzProgName);
+
+        if (pz != NULL)
+            *pp = pz+1;
+        else
+            *pp = pname;
+
+        pz = pathfind(getenv("PATH"), (char *)pname, "rx");
+        if (pz != NULL)
+            pname = (void *)pz;
+
+        pp  = (char const **)(void **)&(opts->pzProgPath);
+        *pp = pname;
+
+        /*
+         *  when comparing long names, these are equivalent
+         */
+        strequate(zSepChars);
+    }
+
+    return SUCCESS;
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
+ *  DO PRESETS
+ *
+ *  The next several routines do the immediate action pass on the command
+ *  line options, then the environment variables, then the config files in
+ *  reverse order.  Once done with that, the order is reversed and all
+ *  the config files and environment variables are processed again, this
+ *  time only processing the non-immediate action options.  do_presets()
+ *  will then return for optionProcess() to do the final pass on the command
+ *  line arguments.
+ */
+
+/**
+ *  scan the command line for immediate action options.
+ *  This is only called the first time through.
+ *  While this procedure is active, the OPTPROC_IMMEDIATE is true.
+ *
+ *  @param pOpts   program options descriptor
+ *  @returns SUCCESS or FAILURE
+ */
+LOCAL tSuccess
+immediate_opts(tOptions * opts)
+{
+    tSuccess  res;
+
+    opts->fOptSet  |= OPTPROC_IMMEDIATE;
+    opts->curOptIdx = 1;     /* start by skipping program name */
+    opts->pzCurOpt  = NULL;
+
+    /*
+     *  Examine all the options from the start.  We process any options that
+     *  are marked for immediate processing.
+     */
+    for (;;) {
+        tOptState opt_st = OPTSTATE_INITIALIZER(PRESET);
+
+        res = next_opt(opts, &opt_st);
+        switch (res) {
+        case FAILURE: goto   failed_option;
+        case PROBLEM: res = SUCCESS; goto leave;
+        case SUCCESS: break;
+        }
+
+        /*
+         *  IF this is an immediate-attribute option, then do it.
+         */
+        if (! DO_IMMEDIATELY(opt_st.flags))
+            continue;
+
+        if (! SUCCESSFUL(handle_opt(opts, &opt_st)))
+            break;
+    } failed_option:;
+
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
+        (*opts->pUsageProc)(opts, EXIT_FAILURE);
+
+ leave:
+
+    opts->fOptSet &= ~OPTPROC_IMMEDIATE;
+    return res;
+}
+
+/**
+ *  check for preset values from a config files or envrionment variables
+ *
+ * @param[in,out] opts  the structure with the option names to check
+ */
+static tSuccess
+do_presets(tOptions * opts)
+{
+    tOptDesc * od = NULL;
+
+    if (! SUCCESSFUL(immediate_opts(opts)))
+        return FAILURE;
+
+    /*
+     *  IF this option set has a --save-opts option, then it also
+     *  has a --load-opts option.  See if a command line option has disabled
+     *  option presetting.
+     */
+    if (  (opts->specOptIdx.save_opts != NO_EQUIVALENT)
+       && (opts->specOptIdx.save_opts != 0)) {
+        od = opts->pOptDesc + opts->specOptIdx.save_opts + 1;
+        if (DISABLED_OPT(od))
+            return SUCCESS;
+    }
+
+    /*
+     *  Until we return from this procedure, disable non-presettable opts
+     */
+    opts->fOptSet |= OPTPROC_PRESETTING;
+    /*
+     *  IF there are no config files,
+     *  THEN do any environment presets and leave.
+     */
+    if (opts->papzHomeList == NULL) {
+        env_presets(opts, ENV_ALL);
+    }
+    else {
+        env_presets(opts, ENV_IMM);
+
+        /*
+         *  Check to see if environment variables have disabled presetting.
+         */
+        if ((od != NULL) && ! DISABLED_OPT(od))
+            intern_file_load(opts);
+
+        /*
+         *  ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment
+         *  variable options.  Only the loading of .rc files.
+         */
+        env_presets(opts, ENV_NON_IMM);
+    }
+    opts->fOptSet &= ~OPTPROC_PRESETTING;
+
+    return SUCCESS;
+}
+
+/**
+ * AutoOpts initialization
+ *
+ * @param[in,out] opts  the structure to initialize
+ * @param[in]     a_ct  program argument count
+ * @param[in]     a_v   program argument vector
+ */
+LOCAL bool
+ao_initialize(tOptions * opts, int a_ct, char ** a_v)
+{
+    if ((opts->fOptSet & OPTPROC_INITDONE) != 0)
+        return true;
+
+    opts->origArgCt   = (unsigned int)a_ct;
+    opts->origArgVect = a_v;
+    opts->fOptSet    |= OPTPROC_INITDONE;
+
+    if (HAS_pzPkgDataDir(opts))
+        program_pkgdatadir = opts->pzPkgDataDir;
+
+    if (! SUCCESSFUL(do_presets(opts)))
+        return false;
+
+    /*
+     *  IF option name conversion was suppressed but it is not suppressed
+     *  for the command line, then it's time to translate option names.
+     *  Usage text will not get retranslated.
+     */
+    if (  ((opts->fOptSet & OPTPROC_TRANSLATE) != 0)
+       && (opts->pTransProc != NULL)
+       && ((opts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT_CFG)
+       )  {
+        opts->fOptSet &= ~OPTPROC_NXLAT_OPT_CFG;
+        (*opts->pTransProc)();
+    }
+
+    if ((opts->fOptSet & OPTPROC_REORDER) != 0)
+        optionSort(opts);
+
+    opts->curOptIdx   = 1;
+    opts->pzCurOpt    = NULL;
+    return true;
+}
+
+/** @}
+ *
+ * Local Variables:
+ * mode: C
+ * c-file-style: "stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * end of autoopts/initialize.c */

+ 320 - 0
libopts/intprops.h

@@ -0,0 +1,320 @@
+/* intprops.h -- properties of integer types
+
+   Copyright (C) 2001-2005, 2009-2014 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert.  */
+
+#ifndef _GL_INTPROPS_H
+#define _GL_INTPROPS_H
+
+#include <limits.h>
+
+/* Return an integer value, converted to the same type as the integer
+   expression E after integer type promotion.  V is the unconverted value.  */
+#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
+
+/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
+   <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>.  */
+#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))
+
+/* The extra casts in the following macros work around compiler bugs,
+   e.g., in Cray C 5.0.3.0.  */
+
+/* True if the arithmetic type T is an integer type.  bool counts as
+   an integer.  */
+#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
+
+/* True if negative values of the signed integer type T use two's
+   complement, ones' complement, or signed magnitude representation,
+   respectively.  Much GNU code assumes two's complement, but some
+   people like to be portable to all possible C hosts.  */
+#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
+#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
+#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+
+/* True if the signed integer expression E uses two's complement.  */
+#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
+
+/* True if the arithmetic type T is signed.  */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* Return 1 if the integer expression E, after integer promotion, has
+   a signed type.  */
+#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
+
+
+/* Minimum and maximum values for integer types and expressions.  These
+   macros have undefined behavior if T is signed and has padding bits.
+   If this is a problem for you, please let us know how to fix it for
+   your host.  */
+
+/* The maximum and minimum values for the integer type T.  */
+#define TYPE_MINIMUM(t)                                                 \
+  ((t) (! TYPE_SIGNED (t)                                               \
+        ? (t) 0                                                         \
+        : TYPE_SIGNED_MAGNITUDE (t)                                     \
+        ? ~ (t) 0                                                       \
+        : ~ TYPE_MAXIMUM (t)))
+#define TYPE_MAXIMUM(t)                                                 \
+  ((t) (! TYPE_SIGNED (t)                                               \
+        ? (t) -1                                                        \
+        : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+
+/* The maximum and minimum values for the type of the expression E,
+   after integer promotion.  E should not have side effects.  */
+#define _GL_INT_MINIMUM(e)                                              \
+  (_GL_INT_SIGNED (e)                                                   \
+   ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e)         \
+   : _GL_INT_CONVERT (e, 0))
+#define _GL_INT_MAXIMUM(e)                                              \
+  (_GL_INT_SIGNED (e)                                                   \
+   ? _GL_SIGNED_INT_MAXIMUM (e)                                         \
+   : _GL_INT_NEGATE_CONVERT (e, 1))
+#define _GL_SIGNED_INT_MAXIMUM(e)                                       \
+  (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
+
+
+/* Return 1 if the __typeof__ keyword works.  This could be done by
+   'configure', but for now it's easier to do it by hand.  */
+#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \
+     || (0x5110 <= __SUNPRO_C && !__STDC__))
+# define _GL_HAVE___TYPEOF__ 1
+#else
+# define _GL_HAVE___TYPEOF__ 0
+#endif
+
+/* Return 1 if the integer type or expression T might be signed.  Return 0
+   if it is definitely unsigned.  This macro does not evaluate its argument,
+   and expands to an integer constant expression.  */
+#if _GL_HAVE___TYPEOF__
+# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
+#else
+# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
+#endif
+
+/* Bound on length of the string representing an unsigned integer
+   value representable in B bits.  log10 (2.0) < 146/485.  The
+   smallest value of B where this bound is not tight is 2621.  */
+#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
+
+/* Bound on length of the string representing an integer type or expression T.
+   Subtract 1 for the sign bit if T is signed, and then add 1 more for
+   a minus sign if needed.
+
+   Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is
+   signed, this macro may overestimate the true bound by one byte when
+   applied to unsigned types of size 2, 4, 16, ... bytes.  */
+#define INT_STRLEN_BOUND(t)                                     \
+  (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT                 \
+                          - _GL_SIGNED_TYPE_OR_EXPR (t))        \
+   + _GL_SIGNED_TYPE_OR_EXPR (t))
+
+/* Bound on buffer size needed to represent an integer type or expression T,
+   including the terminating null.  */
+#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
+
+
+/* Range overflow checks.
+
+   The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
+   operators might not yield numerically correct answers due to
+   arithmetic overflow.  They do not rely on undefined or
+   implementation-defined behavior.  Their implementations are simple
+   and straightforward, but they are a bit harder to use than the
+   INT_<op>_OVERFLOW macros described below.
+
+   Example usage:
+
+     long int i = ...;
+     long int j = ...;
+     if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX))
+       printf ("multiply would overflow");
+     else
+       printf ("product is %ld", i * j);
+
+   Restrictions on *_RANGE_OVERFLOW macros:
+
+   These macros do not check for all possible numerical problems or
+   undefined or unspecified behavior: they do not check for division
+   by zero, for bad shift counts, or for shifting negative numbers.
+
+   These macros may evaluate their arguments zero or multiple times,
+   so the arguments should not have side effects.  The arithmetic
+   arguments (including the MIN and MAX arguments) must be of the same
+   integer type after the usual arithmetic conversions, and the type
+   must have minimum value MIN and maximum MAX.  Unsigned types should
+   use a zero MIN of the proper type.
+
+   These macros are tuned for constant MIN and MAX.  For commutative
+   operations such as A + B, they are also tuned for constant B.  */
+
+/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  */
+#define INT_ADD_RANGE_OVERFLOW(a, b, min, max)          \
+  ((b) < 0                                              \
+   ? (a) < (min) - (b)                                  \
+   : (max) - (b) < (a))
+
+/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  */
+#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max)     \
+  ((b) < 0                                              \
+   ? (max) + (b) < (a)                                  \
+   : (a) < (min) + (b))
+
+/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  */
+#define INT_NEGATE_RANGE_OVERFLOW(a, min, max)          \
+  ((min) < 0                                            \
+   ? (a) < - (max)                                      \
+   : 0 < (a))
+
+/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Avoid && and || as they tickle
+   bugs in Sun C 5.11 2010/08/13 and other compilers; see
+   <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>.  */
+#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max)     \
+  ((b) < 0                                              \
+   ? ((a) < 0                                           \
+      ? (a) < (max) / (b)                               \
+      : (b) == -1                                       \
+      ? 0                                               \
+      : (min) / (b) < (a))                              \
+   : (b) == 0                                           \
+   ? 0                                                  \
+   : ((a) < 0                                           \
+      ? (a) < (min) / (b)                               \
+      : (max) / (b) < (a)))
+
+/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Do not check for division by zero.  */
+#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max)       \
+  ((min) < 0 && (b) == -1 && (a) < - (max))
+
+/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Do not check for division by zero.
+   Mathematically, % should never overflow, but on x86-like hosts
+   INT_MIN % -1 traps, and the C standard permits this, so treat this
+   as an overflow too.  */
+#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max)    \
+  INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max)
+
+/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic.
+   See above for restrictions.  Here, MIN and MAX are for A only, and B need
+   not be of the same type as the other arguments.  The C standard says that
+   behavior is undefined for shifts unless 0 <= B < wordwidth, and that when
+   A is negative then A << B has undefined behavior and A >> B has
+   implementation-defined behavior, but do not check these other
+   restrictions.  */
+#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max)   \
+  ((a) < 0                                              \
+   ? (a) < (min) >> (b)                                 \
+   : (max) >> (b) < (a))
+
+
+/* The _GL*_OVERFLOW macros have the same restrictions as the
+   *_RANGE_OVERFLOW macros, except that they do not assume that operands
+   (e.g., A and B) have the same type as MIN and MAX.  Instead, they assume
+   that the result (e.g., A + B) has that type.  */
+#define _GL_ADD_OVERFLOW(a, b, min, max)                                \
+  ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max)                  \
+   : (a) < 0 ? (b) <= (a) + (b)                                         \
+   : (b) < 0 ? (a) <= (a) + (b)                                         \
+   : (a) + (b) < (b))
+#define _GL_SUBTRACT_OVERFLOW(a, b, min, max)                           \
+  ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max)             \
+   : (a) < 0 ? 1                                                        \
+   : (b) < 0 ? (a) - (b) <= (a)                                         \
+   : (a) < (b))
+#define _GL_MULTIPLY_OVERFLOW(a, b, min, max)                           \
+  (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a))))       \
+   || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
+#define _GL_DIVIDE_OVERFLOW(a, b, min, max)                             \
+  ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max)  \
+   : (a) < 0 ? (b) <= (a) + (b) - 1                                     \
+   : (b) < 0 && (a) + (b) <= (a))
+#define _GL_REMAINDER_OVERFLOW(a, b, min, max)                          \
+  ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max)  \
+   : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b)                     \
+   : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max))
+
+/* Return a nonzero value if A is a mathematical multiple of B, where
+   A is unsigned, B is negative, and MAX is the maximum value of A's
+   type.  A's type must be the same as (A % B)'s type.  Normally (A %
+   -B == 0) suffices, but things get tricky if -B would overflow.  */
+#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max)                            \
+  (((b) < -_GL_SIGNED_INT_MAXIMUM (b)                                   \
+    ? (_GL_SIGNED_INT_MAXIMUM (b) == (max)                              \
+       ? (a)                                                            \
+       : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1))   \
+    : (a) % - (b))                                                      \
+   == 0)
+
+
+/* Integer overflow checks.
+
+   The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
+   might not yield numerically correct answers due to arithmetic overflow.
+   They work correctly on all known practical hosts, and do not rely
+   on undefined behavior due to signed arithmetic overflow.
+
+   Example usage:
+
+     long int i = ...;
+     long int j = ...;
+     if (INT_MULTIPLY_OVERFLOW (i, j))
+       printf ("multiply would overflow");
+     else
+       printf ("product is %ld", i * j);
+
+   These macros do not check for all possible numerical problems or
+   undefined or unspecified behavior: they do not check for division
+   by zero, for bad shift counts, or for shifting negative numbers.
+
+   These macros may evaluate their arguments zero or multiple times, so the
+   arguments should not have side effects.
+
+   These macros are tuned for their last argument being a constant.
+
+   Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
+   A % B, and A << B would overflow, respectively.  */
+
+#define INT_ADD_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
+#define INT_SUBTRACT_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
+#define INT_NEGATE_OVERFLOW(a) \
+  INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
+#define INT_MULTIPLY_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
+#define INT_DIVIDE_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW)
+#define INT_REMAINDER_OVERFLOW(a, b) \
+  _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW)
+#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
+  INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
+                                 _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
+
+/* Return 1 if the expression A <op> B would overflow,
+   where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
+   assuming MIN and MAX are the minimum and maximum for the result type.
+   Arguments should be free of side effects.  */
+#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow)        \
+  op_result_overflow (a, b,                                     \
+                      _GL_INT_MINIMUM (0 * (b) + (a)),          \
+                      _GL_INT_MAXIMUM (0 * (b) + (a)))
+
+#endif /* _GL_INTPROPS_H */

+ 18 - 10
libopts/libopts.c

@@ -1,23 +1,30 @@
-#define AUTOOPTS_INTERNAL
-#include "compat/compat.h"
-#define LOCAL static
+#define  AUTOOPTS_INTERNAL 1
+#include "autoopts/project.h"
+#define  LOCAL static
+#include "ao-strs.h"
 #include "autoopts/options.h"
 #include "autoopts/usage-txt.h"
 #include "genshell.h"
-#include "xat-attribute.h"
-#include "value-type.h"
+#include "option-xat-attribute.h"
+#include "option-value-type.h"
+#include "ao-strs.h"
 #include "ag-char-map.h"
 #include "autoopts.h"
 #include "proto.h"
-#include "value-type.c"
-#include "xat-attribute.c"
+#include "parse-duration.c"
+#include "ao-strs.c"
+#include "option-value-type.c"
+#include "option-xat-attribute.c"
 #include "autoopts.c"
+#include "alias.c"
 #include "boolean.c"
+#include "check.c"
 #include "configfile.c"
 #include "cook.c"
-#include "enumeration.c"
-#include "environment.c"
+#include "enum.c"
+#include "env.c"
 #include "file.c"
+#include "find.c"
 #include "genshell.c"
 #include "load.c"
 #include "makeshell.c"
@@ -32,7 +39,8 @@
 #include "stack.c"
 #include "streqvcmp.c"
 #include "text_mmap.c"
-#include "tokenize.c"
 #include "time.c"
+#include "tokenize.c"
 #include "usage.c"
 #include "version.c"
+#include "init.c"

+ 283 - 235
libopts/load.c

@@ -1,15 +1,18 @@
 
-/*
- *  $Id: load.c,v 4.38 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2008-12-06 10:16:05 bkorb"
+/**
+ *  \file load.c
  *
  *  This file contains the routines that deal with processing text strings
  *  for options, either from a NUL-terminated string passed in or from an
  *  rc/ini file.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,46 +24,83 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
-tOptionLoadMode option_load_mode = OPTION_LOAD_UNCOOKED;
-
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static ag_bool
-insertProgramPath(
-    char*   pzBuf,
-    int     bufSize,
-    tCC*    pzName,
-    tCC*    pzProgPath );
-
-static ag_bool
-insertEnvVal(
-    char*   pzBuf,
-    int     bufSize,
-    tCC*    pzName,
-    tCC*    pzProgPath );
-
-static char*
-assembleArgValue( char* pzTxt, tOptionLoadMode mode );
+static bool
+get_realpath(char * buf, size_t b_sz);
+
+static bool
+add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path);
+
+static bool
+add_env_val(char * buf, int buf_sz, char const * name);
+
+static char *
+assemble_arg_val(char * txt, tOptionLoadMode mode);
+
+static char *
+trim_quotes(char * arg);
+
+static bool
+direction_ok(opt_state_mask_t f, int dir);
 /* = = = END-STATIC-FORWARD = = = */
 
+static bool
+get_realpath(char * buf, size_t b_sz)
+{
+#if defined(HAVE_CANONICALIZE_FILE_NAME)
+    {
+        size_t name_len;
+
+        char * pz = canonicalize_file_name(buf);
+        if (pz == NULL)
+            return false;
+
+        name_len = strlen(pz);
+        if (name_len >= (size_t)b_sz) {
+            free(pz);
+            return false;
+        }
+
+        memcpy(buf, pz, name_len + 1);
+        free(pz);
+    }
+
+#elif defined(HAVE_REALPATH)
+    {
+        size_t name_len;
+        char z[PATH_MAX+1];
+
+        if (realpath(buf, z) == NULL)
+            return false;
+
+        name_len = strlen(z);
+        if (name_len >= b_sz)
+            return false;
+
+        memcpy(buf, z, name_len + 1);
+    }
+#endif
+    return true;
+}
+
 /*=export_func  optionMakePath
  * private:
  *
  * what:  translate and construct a path
- * arg:   + char*       + pzBuf      + The result buffer +
- * arg:   + int         + bufSize    + The size of this buffer +
- * arg:   + char const* + pzName     + The input name +
- * arg:   + char const* + pzProgPath + The full path of the current program +
+ * arg:   + char*       + p_buf     + The result buffer +
+ * arg:   + int         + b_sz      + The size of this buffer +
+ * arg:   + char const* + fname     + The input name +
+ * arg:   + char const* + prg_path  + The full path of the current program +
  *
- * ret-type: ag_bool
- * ret-desc: AG_TRUE if the name was handled, otherwise AG_FALSE.
+ * ret-type: bool
+ * ret-desc: true if the name was handled, otherwise false.
  *           If the name does not start with ``$'', then it is handled
  *           simply by copying the input name to the output buffer and
  *           resolving the name with either
@@ -68,8 +108,8 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode );
  *
  * doc:
  *
- *  This routine will copy the @code{pzName} input name into the @code{pzBuf}
- *  output buffer, carefully not exceeding @code{bufSize} bytes.  If the
+ *  This routine will copy the @code{pzName} input name into the
+ *  @code{pzBuf} output buffer, not exceeding @code{bufSize} bytes.  If the
  *  first character of the input name is a @code{'$'} character, then there
  *  is special handling:
  *  @*
@@ -86,7 +126,7 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode );
  *     @code{pzName} string and must either be the entire string or be followed
  *     by the @code{'/'} (backslash on windows) character.
  *
- * err:  @code{AG_FALSE} is returned if:
+ * err:  @code{false} is returned if:
  *       @*
  *       @bullet{} The input name exceeds @code{bufSize} bytes.
  *       @*
@@ -101,39 +141,29 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode );
  *       @bullet{} @code{canonicalize_file_name} or @code{realpath} return
  *                 errors (cannot resolve the resulting path).
 =*/
-ag_bool
-optionMakePath(
-    char*   pzBuf,
-    int     bufSize,
-    tCC*    pzName,
-    tCC*    pzProgPath )
+bool
+optionMakePath(char * p_buf, int b_sz, char const * fname, char const * prg_path)
 {
-    size_t  name_len = strlen( pzName );
-
-#   ifndef PKGDATADIR
-#     define PKGDATADIR ""
-#   endif
-
-    tSCC    pkgdatadir[] = PKGDATADIR;
-
-    ag_bool res = AG_TRUE;
+    {
+        size_t len = strlen(fname);
 
-    if (bufSize <= name_len)
-        return AG_FALSE;
+        if (((size_t)b_sz <= len) || (len == 0))
+            return false;
+    }
 
     /*
      *  IF not an environment variable, just copy the data
      */
-    if (*pzName != '$') {
-        tCC*  pzS = pzName;
-        char* pzD = pzBuf;
-        int   ct  = bufSize;
+    if (*fname != '$') {
+        char   const * src = fname;
+        char * dst = p_buf;
+        int    ct  = b_sz;
 
         for (;;) {
-            if ( (*(pzD++) = *(pzS++)) == NUL)
+            if ( (*(dst++) = *(src++)) == NUL)
                 break;
             if (--ct <= 0)
-                return AG_FALSE;
+                return false;
         }
     }
 
@@ -142,76 +172,49 @@ optionMakePath(
      *  it must start with "$$/".  In either event, replace the "$$"
      *  with the path to the executable and append a "/" character.
      */
-    else switch (pzName[1]) {
+    else switch (fname[1]) {
     case NUL:
-        return AG_FALSE;
+        return false;
 
     case '$':
-        res = insertProgramPath( pzBuf, bufSize, pzName, pzProgPath );
+        if (! add_prog_path(p_buf, b_sz, fname, prg_path))
+            return false;
         break;
 
     case '@':
-        if (pkgdatadir[0] == NUL)
-            return AG_FALSE;
-
-        if (name_len + sizeof (pkgdatadir) > bufSize)
-            return AG_FALSE;
+        if (program_pkgdatadir[0] == NUL)
+            return false;
 
-        strcpy(pzBuf, pkgdatadir);
-        strcpy(pzBuf + sizeof(pkgdatadir) - 1, pzName + 2);
+        if (snprintf(p_buf, (size_t)b_sz, "%s%s",
+                     program_pkgdatadir, fname + 2) >= b_sz)
+            return false;
         break;
 
     default:
-        res = insertEnvVal( pzBuf, bufSize, pzName, pzProgPath );
-    }
-
-    if (! res)
-        return AG_FALSE;
-
-#if defined(HAVE_CANONICALIZE_FILE_NAME)
-    {
-        char* pz = canonicalize_file_name(pzBuf);
-        if (pz == NULL)
-            return AG_FALSE;
-        if (strlen(pz) < bufSize)
-            strcpy(pzBuf, pz);
-        free(pz);
+        if (! add_env_val(p_buf, b_sz, fname))
+            return false;
     }
 
-#elif defined(HAVE_REALPATH)
-    {
-        char z[ PATH_MAX+1 ];
-
-        if (realpath( pzBuf, z ) == NULL)
-            return AG_FALSE;
-
-        if (strlen(z) < bufSize)
-            strcpy( pzBuf, z );
-    }
-#endif
-
-    return AG_TRUE;
+    return get_realpath(p_buf, b_sz);
 }
 
-
-static ag_bool
-insertProgramPath(
-    char*   pzBuf,
-    int     bufSize,
-    tCC*    pzName,
-    tCC*    pzProgPath )
+/**
+ * convert a leading "$$" into a path to the executable.
+ */
+static bool
+add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path)
 {
-    tCC*    pzPath;
-    tCC*    pz;
+    char const *   path;
+    char const *   pz;
     int     skip = 2;
 
-    switch (pzName[2]) {
+    switch (fname[2]) {
     case DIRCH:
         skip = 3;
     case NUL:
         break;
     default:
-        return AG_FALSE;
+        return false;
     }
 
     /*
@@ -219,107 +222,112 @@ insertProgramPath(
      *  If it is, we're done.  Otherwise, we have to hunt
      *  for the program using "pathfind".
      */
-    if (strchr( pzProgPath, DIRCH ) != NULL)
-        pzPath = pzProgPath;
+    if (strchr(prg_path, DIRCH) != NULL)
+        path = prg_path;
     else {
-        pzPath = pathfind( getenv( "PATH" ), (char*)pzProgPath, "rx" );
+        path = pathfind(getenv("PATH"), (char*)prg_path, "rx");
 
-        if (pzPath == NULL)
-            return AG_FALSE;
+        if (path == NULL)
+            return false;
     }
 
-    pz = strrchr( pzPath, DIRCH );
+    pz = strrchr(path, DIRCH);
 
     /*
      *  IF we cannot find a directory name separator,
      *  THEN we do not have a path name to our executable file.
      */
     if (pz == NULL)
-        return AG_FALSE;
+        return false;
 
-    pzName += skip;
+    fname += skip;
 
     /*
      *  Concatenate the file name to the end of the executable path.
      *  The result may be either a file or a directory.
      */
-    if ((pz - pzPath)+1 + strlen(pzName) >= bufSize)
-        return AG_FALSE;
+    if ((unsigned)(pz - path) + 1 + strlen(fname) >= (unsigned)b_sz)
+        return false;
 
-    memcpy( pzBuf, pzPath, (size_t)((pz - pzPath)+1) );
-    strcpy( pzBuf + (pz - pzPath) + 1, pzName );
+    memcpy(buf, path, (size_t)((pz - path)+1));
+    strcpy(buf + (pz - path) + 1, fname);
 
     /*
-     *  If the "pzPath" path was gotten from "pathfind()", then it was
+     *  If the "path" path was gotten from "pathfind()", then it was
      *  allocated and we need to deallocate it.
      */
-    if (pzPath != pzProgPath)
-        AGFREE(pzPath);
-    return AG_TRUE;
+    if (path != prg_path)
+        AGFREE(path);
+    return true;
 }
 
-
-static ag_bool
-insertEnvVal(
-    char*   pzBuf,
-    int     bufSize,
-    tCC*    pzName,
-    tCC*    pzProgPath )
+/**
+ * Add an environment variable value.
+ */
+static bool
+add_env_val(char * buf, int buf_sz, char const * name)
 {
-    char* pzDir = pzBuf;
+    char * dir_part = buf;
 
     for (;;) {
-        int ch = (int)*++pzName;
+        int ch = (int)*++name;
         if (! IS_VALUE_NAME_CHAR(ch))
             break;
-        *(pzDir++) = (char)ch;
+        *(dir_part++) = (char)ch;
     }
 
-    if (pzDir == pzBuf)
-        return AG_FALSE;
+    if (dir_part == buf)
+        return false;
 
-    *pzDir = NUL;
+    *dir_part = NUL;
 
-    pzDir = getenv( pzBuf );
+    dir_part = getenv(buf);
 
     /*
      *  Environment value not found -- skip the home list entry
      */
-    if (pzDir == NULL)
-        return AG_FALSE;
+    if (dir_part == NULL)
+        return false;
 
-    if (strlen( pzDir ) + 1 + strlen( pzName ) >= bufSize)
-        return AG_FALSE;
+    if (strlen(dir_part) + 1 + strlen(name) >= (unsigned)buf_sz)
+        return false;
 
-    sprintf( pzBuf, "%s%s", pzDir, pzName );
-    return AG_TRUE;
+    sprintf(buf, "%s%s", dir_part, name);
+    return true;
 }
 
-
+/**
+ * Trim leading and trailing white space.
+ * If we are cooking the text and the text is quoted, then "cook"
+ * the string.  To cook, the string must be quoted.
+ *
+ * @param[in,out] txt  the input and output string
+ * @param[in]     mode the handling mode (cooking method)
+ */
 LOCAL void
-mungeString( char* pzTxt, tOptionLoadMode mode )
+munge_str(char * txt, tOptionLoadMode mode)
 {
-    char* pzE;
+    char * pzE;
 
     if (mode == OPTION_LOAD_KEEP)
         return;
 
-    if (IS_WHITESPACE_CHAR(*pzTxt)) {
-        char* pzS = pzTxt;
-        char* pzD = pzTxt;
-        while (IS_WHITESPACE_CHAR(*++pzS))  ;
-        while ((*(pzD++) = *(pzS++)) != NUL)   ;
-        pzE = pzD-1;
+    if (IS_WHITESPACE_CHAR(*txt)) {
+        char * src = SPN_WHITESPACE_CHARS(txt+1);
+        size_t l   = strlen(src) + 1;
+        memmove(txt, src, l);
+        pzE = txt + l - 1;
+
     } else
-        pzE = pzTxt + strlen( pzTxt );
+        pzE = txt + strlen(txt);
 
-    while ((pzE > pzTxt) && IS_WHITESPACE_CHAR(pzE[-1]))  pzE--;
+    pzE  = SPN_WHITESPACE_BACK(txt, pzE);
     *pzE = NUL;
 
     if (mode == OPTION_LOAD_UNCOOKED)
         return;
 
-    switch (*pzTxt) {
+    switch (*txt) {
     default: return;
     case '"':
     case '\'': break;
@@ -331,22 +339,20 @@ mungeString( char* pzTxt, tOptionLoadMode mode )
     case '\'': break;
     }
 
-    (void)ao_string_cook( pzTxt, NULL );
+    (void)ao_string_cook(txt, NULL);
 }
 
-
-static char*
-assembleArgValue( char* pzTxt, tOptionLoadMode mode )
+static char *
+assemble_arg_val(char * txt, tOptionLoadMode mode)
 {
-    tSCC zBrk[] = " \t\n:=";
-    char* pzEnd = strpbrk( pzTxt, zBrk );
-    int   space_break;
+    char * end = strpbrk(txt, ARG_BREAK_STR);
+    int    space_break;
 
     /*
      *  Not having an argument to a configurable name is okay.
      */
-    if (pzEnd == NULL)
-        return pzTxt + strlen(pzTxt);
+    if (end == NULL)
+        return txt + strlen(txt);
 
     /*
      *  If we are keeping all whitespace, then the  modevalue starts with the
@@ -354,8 +360,8 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode )
      *  of which character caused it.
      */
     if (mode == OPTION_LOAD_KEEP) {
-        *(pzEnd++) = NUL;
-        return pzEnd;
+        *(end++) = NUL;
+        return end;
     }
 
     /*
@@ -363,90 +369,85 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode )
      *  because we'll have to skip over an immediately following ':' or '='
      *  (and the white space following *that*).
      */
-    space_break = IS_WHITESPACE_CHAR(*pzEnd);
-    *(pzEnd++) = NUL;
-    while (IS_WHITESPACE_CHAR(*pzEnd))  pzEnd++;
-    if (space_break && ((*pzEnd == ':') || (*pzEnd == '=')))
-        while (IS_WHITESPACE_CHAR(*++pzEnd))  ;
+    space_break = IS_WHITESPACE_CHAR(*end);
+    *(end++) = NUL;
+
+    end = SPN_WHITESPACE_CHARS(end);
+    if (space_break && ((*end == ':') || (*end == '=')))
+        end = SPN_WHITESPACE_CHARS(end+1);
 
-    return pzEnd;
+    return end;
 }
 
+static char *
+trim_quotes(char * arg)
+{
+    switch (*arg) {
+    case '"':
+    case '\'':
+        ao_string_cook(arg, NULL);
+    }
+    return arg;
+}
 
-/*
- *  Load an option from a block of text.  The text must start with the
- *  configurable/option name and be followed by its associated value.
- *  That value may be processed in any of several ways.  See "tOptionLoadMode"
- *  in autoopts.h.
+/**
+ * See if the option is to be processed in the current scan direction
+ * (-1 or +1).
  */
-LOCAL void
-loadOptionLine(
-    tOptions*   pOpts,
-    tOptState*  pOS,
-    char*       pzLine,
-    tDirection  direction,
-    tOptionLoadMode   load_mode )
+static bool
+direction_ok(opt_state_mask_t f, int dir)
 {
-    while (IS_WHITESPACE_CHAR(*pzLine))  pzLine++;
+    if (dir == 0)
+        return true;
 
-    {
-        char* pzArg = assembleArgValue( pzLine, load_mode );
-
-        if (! SUCCESSFUL( longOptionFind( pOpts, pzLine, pOS )))
-            return;
-        if (pOS->flags & OPTST_NO_INIT)
-            return;
-        pOS->pzOptArg = pzArg;
-    }
-
-    switch (pOS->flags & (OPTST_IMM|OPTST_DISABLE_IMM)) {
+    switch (f & (OPTST_IMM|OPTST_DISABLE_IMM)) {
     case 0:
         /*
          *  The selected option has no immediate action.
          *  THEREFORE, if the direction is PRESETTING
          *  THEN we skip this option.
          */
-        if (PRESETTING(direction))
-            return;
+        if (PRESETTING(dir))
+            return false;
         break;
 
     case OPTST_IMM:
-        if (PRESETTING(direction)) {
+        if (PRESETTING(dir)) {
             /*
              *  We are in the presetting direction with an option we handle
              *  immediately for enablement, but normally for disablement.
              *  Therefore, skip if disabled.
              */
-            if ((pOS->flags & OPTST_DISABLED) == 0)
-                return;
+            if ((f & OPTST_DISABLED) == 0)
+                return false;
         } else {
             /*
              *  We are in the processing direction with an option we handle
              *  immediately for enablement, but normally for disablement.
              *  Therefore, skip if NOT disabled.
              */
-            if ((pOS->flags & OPTST_DISABLED) != 0)
-                return;
+            if ((f & OPTST_DISABLED) != 0)
+                return false;
         }
         break;
 
     case OPTST_DISABLE_IMM:
-        if (PRESETTING(direction)) {
+        if (PRESETTING(dir)) {
             /*
              *  We are in the presetting direction with an option we handle
              *  immediately for disablement, but normally for disablement.
              *  Therefore, skip if NOT disabled.
              */
-            if ((pOS->flags & OPTST_DISABLED) != 0)
-                return;
+            if ((f & OPTST_DISABLED) != 0)
+                return false;
         } else {
             /*
              *  We are in the processing direction with an option we handle
              *  immediately for disablement, but normally for disablement.
              *  Therefore, skip if disabled.
              */
-            if ((pOS->flags & OPTST_DISABLED) == 0)
-                return;
+            if ((f & OPTST_DISABLED) == 0)
+                return false;
         }
         break;
 
@@ -456,51 +457,95 @@ loadOptionLine(
          *  THEREFORE, if the direction is PROCESSING
          *  THEN we skip this option.
          */
-        if (PROCESSING(direction))
-            return;
+        if (PROCESSING(dir))
+            return false;
         break;
     }
+    return true;
+}
+
+/**
+ *  Load an option from a block of text.  The text must start with the
+ *  configurable/option name and be followed by its associated value.
+ *  That value may be processed in any of several ways.  See "tOptionLoadMode"
+ *  in autoopts.h.
+ *
+ * @param[in,out] opts       program options descriptor
+ * @param[in,out] opt_state  option processing state
+ * @param[in,out] line       source line with long option name in it
+ * @param[in]     direction  current processing direction (preset or not)
+ * @param[in]     load_mode  option loading mode (OPTION_LOAD_*)
+ */
+LOCAL void
+load_opt_line(tOptions * opts, tOptState * opt_state, char * line,
+              tDirection direction, tOptionLoadMode load_mode )
+{
+    /*
+     * When parsing a stored line, we only look at the characters after
+     * a hyphen.  Long names must always be at least two characters and
+     * short options are always exactly one character long.
+     */
+    line = SPN_LOAD_LINE_SKIP_CHARS(line);
+
+    {
+        char * arg = assemble_arg_val(line, load_mode);
+
+        if (IS_OPTION_NAME_CHAR(line[1])) {
+
+            if (! SUCCESSFUL(opt_find_long(opts, line, opt_state)))
+                return;
+
+        } else if (! SUCCESSFUL(opt_find_short(opts, *line, opt_state)))
+            return;
+
+        if ((! CALLED(direction)) && (opt_state->flags & OPTST_NO_INIT))
+            return;
+
+        opt_state->pzOptArg = trim_quotes(arg);
+    }
+
+    if (! direction_ok(opt_state->flags, direction))
+        return;
 
     /*
      *  Fix up the args.
      */
-    if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
-        if (*pOS->pzOptArg != NUL)
+    if (OPTST_GET_ARGTYPE(opt_state->pOD->fOptState) == OPARG_TYPE_NONE) {
+        if (*opt_state->pzOptArg != NUL)
             return;
-        pOS->pzOptArg = NULL;
+        opt_state->pzOptArg = NULL;
 
-    } else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
-        if (*pOS->pzOptArg == NUL)
-             pOS->pzOptArg = NULL;
+    } else if (opt_state->pOD->fOptState & OPTST_ARG_OPTIONAL) {
+        if (*opt_state->pzOptArg == NUL)
+             opt_state->pzOptArg = NULL;
         else {
-            AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" );
-            pOS->flags |= OPTST_ALLOC_ARG;
+            AGDUPSTR(opt_state->pzOptArg, opt_state->pzOptArg, "opt arg");
+            opt_state->flags |= OPTST_ALLOC_ARG;
         }
 
     } else {
-        if (*pOS->pzOptArg == NUL)
-             pOS->pzOptArg = zNil;
+        if (*opt_state->pzOptArg == NUL)
+             opt_state->pzOptArg = zNil;
         else {
-            AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" );
-            pOS->flags |= OPTST_ALLOC_ARG;
+            AGDUPSTR(opt_state->pzOptArg, opt_state->pzOptArg, "opt arg");
+            opt_state->flags |= OPTST_ALLOC_ARG;
         }
     }
 
     {
         tOptionLoadMode sv = option_load_mode;
         option_load_mode = load_mode;
-        handleOption( pOpts, pOS );
+        handle_opt(opts, opt_state);
         option_load_mode = sv;
     }
 }
 
-
 /*=export_func  optionLoadLine
  *
  * what:  process a string for an option name and value
  *
- * arg:   tOptions*,   pOpts,  program options descriptor
- * arg:   char const*, pzLine, NUL-terminated text
+ * arg:   tOptions*,   opts,  program options descriptor
+ * arg:   char const*, line,  NUL-terminated text
  *
  * doc:
  *
@@ -511,7 +556,8 @@ loadOptionLine(
  *  When passed a pointer to the option struct and a string, it will find
  *  the option named by the first token on the string and set the option
  *  argument to the remainder of the string.  The caller must NUL terminate
- *  the string.  Any embedded new lines will be included in the option
+ *  the string.  The caller need not skip over any introductory hyphens.
+ *  Any embedded new lines will be included in the option
  *  argument.  If the input looks like one or more quoted strings, then the
  *  input will be "cooked".  The "cooking" is identical to the string
  *  formation used in AutoGen definition files (@pxref{basic expression}),
@@ -521,17 +567,19 @@ loadOptionLine(
  *        will cause a warning to print, but the function should return.
 =*/
 void
-optionLoadLine(
-    tOptions*  pOpts,
-    tCC*       pzLine )
+optionLoadLine(tOptions * opts, char const * line)
 {
     tOptState st = OPTSTATE_INITIALIZER(SET);
-    char* pz;
-    AGDUPSTR( pz, pzLine, "user option line" );
-    loadOptionLine( pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED );
-    AGFREE( pz );
+    char *    pz;
+    proc_state_mask_t sv_flags = opts->fOptSet;
+    opts->fOptSet &= ~OPTPROC_ERRSTOP;
+    AGDUPSTR(pz, line, "opt line");
+    load_opt_line(opts, &st, pz, DIRECTION_CALLED, OPTION_LOAD_COOKED);
+    AGFREE(pz);
+    opts->fOptSet = sv_flags;
 }
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 188 - 144
libopts/m4/libopts.m4

@@ -1,67 +1,45 @@
 dnl  -*- buffer-read-only: t -*- vi: set ro:
-dnl 
+dnl
 dnl DO NOT EDIT THIS FILE   (libopts.m4)
-dnl 
-dnl It has been AutoGen-ed  August  8, 2009 at 10:14:46 AM by AutoGen 5.9.9
+dnl
+dnl It has been AutoGen-ed
 dnl From the definitions    libopts.def
 dnl and the template file   conftest.tpl
 dnl
 dnl do always before generated macros:
 dnl
 AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
-[if test X${INVOKE_LIBOPTS_MACROS_FIRST_done} != Xyes ; then]
-  # =================
-  # AC_HEADER_STDC
-  # =================
-  AC_HEADER_STDC
-  # =================
-  # AC_HEADER_DIRENT
-  # =================
+  AC_REQUIRE([AC_HEADER_STDC])
   AC_HEADER_DIRENT
-  
+
   # =================
   # AC_CHECK_HEADERS
   # =================
-  AC_CHECK_HEADERS(dlfcn.h errno.h fcntl.h libgen.h memory.h netinet/in.h \
-    setjmp.h sys/mman.h sys/param.h sys/poll.h sys/procset.h sys/select.h \
-    sys/socket.h sys/stropts.h sys/time.h sys/un.h sys/wait.h unistd.h    \
-    utime.h sysexits.h)
-  
-  # --------------------------------------------
-  # Verify certain entries from AC_CHECK_HEADERS
-  # --------------------------------------------
-  [for f in sys_types sys_mman sys_param sys_stat sys_wait \
-           string errno stdlib memory setjmp
-  do eval as_ac_var=\${ac_cv_header_${f}_h+set}
-     test "${as_ac_var}" = set] || \
-       AC_MSG_ERROR([You must have ${f}.h on your system])
-  done
-  
-  # ================================================
-  # AC_CHECK_HEADERS: stdarg.h is present define HAVE_STDARG_H, otherwise
-  # if varargs.h is present define HAVE_VARARGS_H.
-  # ================================================
-  AC_CHECK_HEADERS(stdarg.h varargs.h, break)
-  [if test `eval echo '${'$as_ac_Header'}'` != yes; then]
-    AC_MSG_ERROR([You must have stdarg.h or varargs.h on your system])
-  fi
-  
-  # ================================================
-  # Similarly for the string.h and strings.h headers
-  # ================================================
-  AC_CHECK_HEADERS(string.h strings.h, break)
-  [if test `eval echo '${'$as_ac_Header'}'` != yes; then]
-    AC_MSG_ERROR([You must have string.h or strings.h on your system])
-  fi
-  
-  # =====================
-  # ...and limits headers
-  # =====================
-  AC_CHECK_HEADERS(limits.h sys/limits.h values.h, break)
-  [if test `eval echo '${'$as_ac_Header'}'` != yes; then]
-    AC_MSG_ERROR([You must have one of limits.h, sys/limits.h or values.h])
-  fi
-  
+  AC_CHECK_HEADERS([ \
+      sys/mman.h    sys/param.h   sys/poll.h    sys/procset.h \
+      sys/select.h  sys/socket.h  sys/stropts.h sys/time.h \
+      sys/un.h      sys/wait.h    dlfcn.h       errno.h \
+      fcntl.h       libgen.h      libintl.h     memory.h \
+      netinet/in.h  setjmp.h      stdbool.h     sysexits.h \
+      unistd.h      utime.h])
+
+  AC_CHECK_HEADERS([stdarg.h     varargs.h],
+      [lo_have_arg_hdr=true;break],
+      [lo_have_arg_hdr=false])
+
+  AC_CHECK_HEADERS([string.h     strings.h],
+      [lo_have_str_hdr=true;break],
+      [lo_have_str_hdr=false])
+
+  AC_CHECK_HEADERS([limits.h     sys/limits.h  values.h],
+      [lo_have_lim_hdr=true;break],
+      [lo_have_lim_hdr=false])
+
+  AC_CHECK_HEADERS([inttypes.h   stdint.h],
+      [lo_have_typ_hdr=true;break],
+      [lo_have_typ_hdr=false])
+  gl_STDNORETURN_H
+
   # ----------------------------------------------------------------------
   # check for various programs used during the build.
   # On OS/X, "wchar.h" needs "runetype.h" to work properly.
@@ -72,45 +50,87 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[
   # include <runetype.h>
   #endif
   ])
-  
+
+  AC_ARG_ENABLE([nls],
+  AS_HELP_STRING([--disable-nls],[disable nls support in libopts]))
+  AS_IF([test "x$enable_nls" != "xno" && \
+  test "X${ac_cv_header_libintl_h}" = Xyes], [
+  AC_DEFINE([ENABLE_NLS],[1],[nls support in libopts])])
+
+  # --------------------------------------------
+  # Verify certain entries from AC_CHECK_HEADERS
+  # --------------------------------------------
+  [${lo_have_arg_hdr} || \
+    ]AC_MSG_ERROR([you must have stdarg.h or varargs.h on your system])[
+
+  ${lo_have_str_hdr} || \
+    ]AC_MSG_ERROR([you must have string.h or strings.h on your system])[
+
+  ${lo_have_lim_hdr} || \
+    ]AC_MSG_ERROR(
+      [you must have one of limits.h, sys/limits.h or values.h])[
+
+  ${lo_have_typ_hdr} || \
+    ]AC_MSG_ERROR([you must have inttypes.h or stdint.h on your system])[
+
+  for f in sys_types sys_param sys_stat string errno stdlib memory setjmp
+  do eval as_ac_var=\${ac_cv_header_${f}_h}
+     test "X${as_ac_var}" = Xyes || {
+       ]AC_MSG_ERROR([you must have ${f}.h on your system])[
+     }
+  done
+  test "X${ac_cv_header_inttypes_h-no}" = Xyes || \
+    echo '#include <stdint.h>' > inttypes.h]
+
   # ----------------------------------------------------------------------
   # Checks for typedefs
   # ----------------------------------------------------------------------
   AC_CHECK_TYPES(wchar_t)
   AC_CHECK_TYPES(wint_t, [], [], [
-  AC_INCLUDES_DEFAULT
-  #if HAVE_RUNETYPE_H
-  # include <runetype.h>
-  #endif
-  #if HAVE_WCHAR_H
-  # include <wchar.h>
-  #endif
+    AC_INCLUDES_DEFAULT
+    #if HAVE_RUNETYPE_H
+    # include <runetype.h>
+    #endif
+    #if HAVE_WCHAR_H
+    # include <wchar.h>
+    #endif
   ])
-  
-  # ========================
-  # ...and int types headers
-  # ========================
-  AC_CHECK_HEADERS(stdint.h inttypes.h, break)
   AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
-     intptr_t, uintptr_t, uint_t, pid_t, size_t])
-  
-  # =====
-  # sizes
-  # =====
-  AC_CHECK_SIZEOF(char*, 4)
+  intptr_t, uintptr_t, uint_t, pid_t, size_t, ptrdiff_t])
+  AC_CHECK_SIZEOF(char*, 8)
   AC_CHECK_SIZEOF(int,   4)
-  AC_CHECK_SIZEOF(long,  4)
+  AC_CHECK_SIZEOF(long,  8)
   AC_CHECK_SIZEOF(short, 2)
-  
-  # ----------------------------------------------------------------------
-  # AC_CHECK_LIB for SVR4 libgen, and use it if it defines pathfind.
-  # ----------------------------------------------------------------------
+
+  # ------------
+  # AC_CHECK_LIB
+  # ------------
   AC_CHECK_LIB(gen, pathfind)
+  AC_CHECK_LIB(intl,gettext)
   AC_FUNC_VPRINTF
+  AC_FUNC_FORK
   AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr \
-                 strrchr strsignal])
-[  INVOKE_LIBOPTS_MACROS_FIRST_done=yes
-fi]])
+                 strrchr strsignal fchmod fstat chmod])
+  AC_PROG_SED
+  [while :
+  do
+      POSIX_SHELL=`which bash`
+      test -x "$POSIX_SHELL" && break
+      POSIX_SHELL=`which dash`
+      test -x "$POSIX_SHELL" && break
+      POSIX_SHELL=/usr/xpg4/bin/sh
+      test -x "$POSIX_SHELL" && break
+      POSIX_SHELL=`/bin/sh -c '
+          exec 2>/dev/null
+          if ! true ; then exit 1 ; fi
+          echo /bin/sh'`
+      test -x "$POSIX_SHELL" && break
+      ]AC_MSG_ERROR([cannot locate a working POSIX shell])[
+  done]
+  AC_DEFINE_UNQUOTED([POSIX_SHELL], ["${POSIX_SHELL}"],
+           [define to a working POSIX compliant shell])
+  AC_SUBST([POSIX_SHELL])
+])
 
 dnl
 dnl @synopsis  INVOKE_LIBOPTS_MACROS
@@ -120,32 +140,31 @@ dnl  that have not been disabled with "omit-invocation".
 dnl
 AC_DEFUN([LIBOPTS_WITH_REGEX_HEADER],[
   AC_ARG_WITH([regex-header],
-    AC_HELP_STRING([--with-regex-header], [a reg expr header is specified]),
+    AS_HELP_STRING([--with-regex-header], [a reg expr header is specified]),
     [libopts_cv_with_regex_header=${with_regex_header}],
     AC_CACHE_CHECK([whether a reg expr header is specified], libopts_cv_with_regex_header,
       libopts_cv_with_regex_header=no)
   ) # end of AC_ARG_WITH
-
   if test "X${libopts_cv_with_regex_header}" != Xno
   then
     AC_DEFINE_UNQUOTED([REGEX_HEADER],[<${libopts_cv_with_regex_header}>])
   else
     AC_DEFINE([REGEX_HEADER],[<regex.h>],[name of regex header file])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_WITH_REGEX_HEADER
 
 
 AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
   AC_ARG_WITH([libregex],
-    AC_HELP_STRING([--with-libregex], [libregex installation prefix]),
+    AS_HELP_STRING([--with-libregex], [libregex installation prefix]),
     [libopts_cv_with_libregex_root=${with_libregex}],
     AC_CACHE_CHECK([whether with-libregex was specified], libopts_cv_with_libregex_root,
       libopts_cv_with_libregex_root=no)
   ) # end of AC_ARG_WITH libregex
 
-  if test "${with_libguile+set}" = set && \
-     test "${withval}" = no
+  if test "${with_libregex+set}" = set && \
+     test "X${withval}" = Xno
   then ## disabled by request
     libopts_cv_with_libregex_root=no
     libopts_cv_with_libregex_cflags=no
@@ -153,15 +172,15 @@ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
   else
 
   AC_ARG_WITH([libregex-cflags],
-    AC_HELP_STRING([--with-libregex-cflags], [libregex compile flags]),
-    [libopts_cv_with_libregex_cflags=${with_regex_cflags}],
+    AS_HELP_STRING([--with-libregex-cflags], [libregex compile flags]),
+    [libopts_cv_with_libregex_cflags=${with_libregex_cflags}],
     AC_CACHE_CHECK([whether with-libregex-cflags was specified], libopts_cv_with_libregex_cflags,
       libopts_cv_with_libregex_cflags=no)
   ) # end of AC_ARG_WITH libregex-cflags
 
   AC_ARG_WITH([libregex-libs],
-    AC_HELP_STRING([--with-libregex-libs], [libregex link command arguments]),
-    [libopts_cv_with_libregex_libs=${with_regex_libs}],
+    AS_HELP_STRING([--with-libregex-libs], [libregex link command arguments]),
+    [libopts_cv_with_libregex_libs=${with_libregex_libs}],
     AC_CACHE_CHECK([whether with-libregex-libs was specified], libopts_cv_with_libregex_libs,
       libopts_cv_with_libregex_libs=no)
   ) # end of AC_ARG_WITH libregex-libs
@@ -182,8 +201,6 @@ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
   esac
   libopts_save_CPPFLAGS="${CPPFLAGS}"
   libopts_save_LIBS="${LIBS}"
-  fi ## disabled by request
-
   case "X${libopts_cv_with_libregex_cflags}" in
   Xyes|Xno|X )
     libopts_cv_with_libregex_cflags="" ;;
@@ -199,7 +216,7 @@ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[
   LIBREGEX_LIBS=""
   AC_MSG_CHECKING([whether libregex functions properly])
   AC_CACHE_VAL([libopts_cv_with_libregex],[
-  AC_TRY_RUN([@%:@include <stdio.h>
+  AC_RUN_IFELSE([@%:@include <stdio.h>
 @%:@include <stdlib.h>
 @%:@include <sys/types.h>
 @%:@include REGEX_HEADER
@@ -220,10 +237,10 @@ int main() {
   }
   return 0; }],
     [libopts_cv_with_libregex=yes], [libopts_cv_with_libregex=no],
-    [libopts_cv_with_libregex=no]) # end of AC_TRY_RUN 
+    [libopts_cv_with_libregex=no]) # end of AC_RUN_IFELSE 
   ]) # end of AC_CACHE_VAL for libopts_cv_with_libregex
+  fi ## disabled by request
   AC_MSG_RESULT([${libopts_cv_with_libregex}])
-
   if test "X${libopts_cv_with_libregex}" != Xno
   then
     AC_DEFINE([WITH_LIBREGEX],[1],
@@ -231,31 +248,34 @@ int main() {
   else
     CPPFLAGS="${libopts_save_CPPFLAGS}"
     LIBS="${libopts_save_LIBS}"
+    libopts_cv_with_libregex_root=no
+libopts_cv_with_libregex_cflags=no
+libopts_cv_with_libregex_libs=no
+libopts_cv_with_libregex=no
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_WITHLIB_REGEX
 
 
 AC_DEFUN([LIBOPTS_RUN_PATHFIND],[
   AC_MSG_CHECKING([whether pathfind(3) works])
   AC_CACHE_VAL([libopts_cv_run_pathfind],[
-  AC_TRY_RUN([@%:@include <string.h>
+  AC_RUN_IFELSE([@%:@include <string.h>
 @%:@include <stdlib.h>
 int main (int argc, char** argv) {
    char* pz = pathfind( getenv( "PATH" ), "sh", "x" );
    return (pz == 0) ? 1 : 0;
 }],
     [libopts_cv_run_pathfind=yes],[libopts_cv_run_pathfind=no],[libopts_cv_run_pathfind=no]
-  ) # end of TRY_RUN
+  ) # end of RUN_IFELSE
   ]) # end of AC_CACHE_VAL for libopts_cv_run_pathfind
   AC_MSG_RESULT([${libopts_cv_run_pathfind}])
-
   if test "X${libopts_cv_run_pathfind}" != Xno
   then
     AC_DEFINE([HAVE_PATHFIND],[1],
         [Define this if pathfind(3) works])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_RUN_PATHFIND
 
 
@@ -266,27 +286,24 @@ AC_DEFUN([LIBOPTS_TEST_DEV_ZERO],[
 dzero=\`ls -lL /dev/zero | egrep ^c......r\`
 test -z "${dzero}" && exit 1
 echo ${dzero}`
-    if test $? -ne 0
-    then libopts_cv_test_dev_zero=no
-    elif test -z "$libopts_cv_test_dev_zero"
+    if test $? -ne 0 || test -z "$libopts_cv_test_dev_zero"
     then libopts_cv_test_dev_zero=no
     fi
   ]) # end of CACHE_VAL of libopts_cv_test_dev_zero
   AC_MSG_RESULT([${libopts_cv_test_dev_zero}])
-
   if test "X${libopts_cv_test_dev_zero}" != Xno
   then
     AC_DEFINE([HAVE_DEV_ZERO],[1],
         [Define this if /dev/zero is readable device])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_TEST_DEV_ZERO
 
 
 AC_DEFUN([LIBOPTS_RUN_REALPATH],[
   AC_MSG_CHECKING([whether we have a functional realpath(3C)])
   AC_CACHE_VAL([libopts_cv_run_realpath],[
-  AC_TRY_RUN([@%:@include <limits.h>
+  AC_RUN_IFELSE([@%:@include <limits.h>
 @%:@include <stdlib.h>
 int main (int argc, char** argv) {
 @%:@ifndef PATH_MAX
@@ -298,23 +315,22 @@ choke me!!
    return (pz == zPath) ? 0 : 1;
 }],
     [libopts_cv_run_realpath=yes],[libopts_cv_run_realpath=no],[libopts_cv_run_realpath=no]
-  ) # end of TRY_RUN
+  ) # end of RUN_IFELSE
   ]) # end of AC_CACHE_VAL for libopts_cv_run_realpath
   AC_MSG_RESULT([${libopts_cv_run_realpath}])
-
   if test "X${libopts_cv_run_realpath}" != Xno
   then
     AC_DEFINE([HAVE_REALPATH],[1],
         [Define this if we have a functional realpath(3C)])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_RUN_REALPATH
 
 
 AC_DEFUN([LIBOPTS_RUN_STRFTIME],[
   AC_MSG_CHECKING([whether strftime() works])
   AC_CACHE_VAL([libopts_cv_run_strftime],[
-  AC_TRY_RUN([@%:@include <time.h>
+  AC_RUN_IFELSE([@%:@include <time.h>
 @%:@include <string.h>
 char t_buf@<:@ 64 @:>@;
 int main() {
@@ -332,31 +348,29 @@ int main() {
   strftime( t_buf, sizeof( t_buf ), "%A %b %d %j", &tm );
   return (strcmp( t_buf, z ) != 0); }],
     [libopts_cv_run_strftime=yes],[libopts_cv_run_strftime=no],[libopts_cv_run_strftime=no]
-  ) # end of TRY_RUN
+  ) # end of RUN_IFELSE
   ]) # end of AC_CACHE_VAL for libopts_cv_run_strftime
   AC_MSG_RESULT([${libopts_cv_run_strftime}])
-
   if test "X${libopts_cv_run_strftime}" != Xno
   then
     AC_DEFINE([HAVE_STRFTIME],[1],
         [Define this if strftime() works])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_RUN_STRFTIME
 
 
 AC_DEFUN([LIBOPTS_RUN_FOPEN_BINARY],[
   AC_MSG_CHECKING([whether fopen accepts "b" mode])
   AC_CACHE_VAL([libopts_cv_run_fopen_binary],[
-  AC_TRY_RUN([@%:@include <stdio.h>
+  AC_RUN_IFELSE([@%:@include <stdio.h>
 int main (int argc, char** argv) {
 FILE* fp = fopen("conftest.@S|@ac_ext", "rb");
 return (fp == NULL) ? 1 : fclose(fp); }],
     [libopts_cv_run_fopen_binary=yes],[libopts_cv_run_fopen_binary=no],[libopts_cv_run_fopen_binary=no]
-  ) # end of TRY_RUN
+  ) # end of RUN_IFELSE
   ]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_binary
   AC_MSG_RESULT([${libopts_cv_run_fopen_binary}])
-
   if test "X${libopts_cv_run_fopen_binary}" != Xno
   then
     AC_DEFINE([FOPEN_BINARY_FLAG],"b",
@@ -365,22 +379,21 @@ return (fp == NULL) ? 1 : fclose(fp); }],
     AC_DEFINE([FOPEN_BINARY_FLAG],"",
 	[fopen(3) accepts a 'b' in the mode flag])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_RUN_FOPEN_BINARY
 
 
 AC_DEFUN([LIBOPTS_RUN_FOPEN_TEXT],[
   AC_MSG_CHECKING([whether fopen accepts "t" mode])
   AC_CACHE_VAL([libopts_cv_run_fopen_text],[
-  AC_TRY_RUN([@%:@include <stdio.h>
+  AC_RUN_IFELSE([@%:@include <stdio.h>
 int main (int argc, char** argv) {
 FILE* fp = fopen("conftest.@S|@ac_ext", "rt");
 return (fp == NULL) ? 1 : fclose(fp); }],
     [libopts_cv_run_fopen_text=yes],[libopts_cv_run_fopen_text=no],[libopts_cv_run_fopen_text=no]
-  ) # end of TRY_RUN
+  ) # end of RUN_IFELSE
   ]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_text
   AC_MSG_RESULT([${libopts_cv_run_fopen_text}])
-
   if test "X${libopts_cv_run_fopen_text}" != Xno
   then
     AC_DEFINE([FOPEN_TEXT_FLAG],"t",
@@ -389,29 +402,28 @@ return (fp == NULL) ? 1 : fclose(fp); }],
     AC_DEFINE([FOPEN_TEXT_FLAG],"",
 	[fopen(3) accepts a 't' in the mode flag])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_RUN_FOPEN_TEXT
 
 
 AC_DEFUN([LIBOPTS_DISABLE_OPTIONAL_ARGS],[
   AC_ARG_ENABLE([optional-args],
-    AC_HELP_STRING([--disable-optional-args], [not wanting optional option args]),
+    AS_HELP_STRING([--disable-optional-args], [not wanting optional option args]),
     [libopts_cv_enable_optional_args=${enable_optional_args}],
     AC_CACHE_CHECK([whether not wanting optional option args], libopts_cv_enable_optional_args,
       libopts_cv_enable_optional_args=yes)
   ) # end of AC_ARG_ENABLE
-
   if test "X${libopts_cv_enable_optional_args}" = Xno
   then
     AC_DEFINE([NO_OPTIONAL_OPT_ARGS], [1],
           [Define this if optional arguments are disallowed])
   fi
-  
+
 ]) # end of AC_DEFUN of LIBOPTS_DISABLE_OPTIONAL_ARGS
 
 
 AC_DEFUN([INVOKE_LIBOPTS_MACROS],[
-  INVOKE_LIBOPTS_MACROS_FIRST
+  AC_REQUIRE([INVOKE_LIBOPTS_MACROS_FIRST])
   # Check to see if a reg expr header is specified.
   LIBOPTS_WITH_REGEX_HEADER
 
@@ -443,16 +455,13 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS],[
 
 dnl @synopsis  LIBOPTS_CHECK
 dnl
-dnl Time-stamp:        "2009-07-22 18:50:49 bkorb"
-dnl Last Committed:    $Date: 2009/07/23 02:05:55 $
-dnl
 dnl If autoopts-config works, add the linking information to LIBS.
 dnl Otherwise, add ``libopts-${ao_rev}'' to SUBDIRS and run all
 dnl the config tests that the library needs.  Invoke the
 dnl "INVOKE_LIBOPTS_MACROS" macro iff we are building libopts.
 dnl
 dnl  This file is part of AutoGen.
-dnl  AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+dnl  AutoGen Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
 dnl
 dnl  AutoGen is free software: you can redistribute it and/or modify it
 dnl  under the terms of the GNU General Public License as published by the
@@ -469,25 +478,25 @@ dnl  with this program.  If not, see <http://www.gnu.org/licenses/>.
 dnl
 dnl Default to system libopts
 dnl
-AC_DEFUN([LIBOPTS_CHECK],[
+AC_DEFUN([LIBOPTS_CHECK_COMMON],[
+  AC_REQUIRE([INVOKE_LIBOPTS_MACROS_FIRST])
   [NEED_LIBOPTS_DIR='']
   m4_pushdef([AO_Libopts_Dir],
 	    [ifelse($1, , [libopts], [$1])])
-  AC_SUBST(LIBOPTS_DIR, AO_Libopts_Dir)
   AC_ARG_ENABLE([local-libopts],
     AC_HELP_STRING([--enable-local-libopts],
-       [Force using the supplied libopts tearoff code]),[
+       [Use the supplied libopts tearoff code]),[
     if test x$enableval = xyes ; then
        AC_MSG_NOTICE([Using supplied libopts tearoff])
-       LIBOPTS_LDADD='$(top_builddir)/AO_Libopts_Dir/libopts.la'
        LIBOPTS_CFLAGS='-I$(top_srcdir)/AO_Libopts_Dir'
        NEED_LIBOPTS_DIR=true
+       LIBOPTS_LDADD='$(top_builddir)/AO_Libopts_Dir/libopts.la'
     fi])
 
   AC_ARG_ENABLE([libopts-install],
-    AC_HELP_STRING([--disable-libopts-install],
-       [Do not install libopts with client installation]))
-  AM_CONDITIONAL([INSTALL_LIBOPTS],[test "X${enable_libopts_install}" != Xno])
+    AC_HELP_STRING([--enable-libopts-install],
+       [Install libopts with client installation]))
+  AM_CONDITIONAL([INSTALL_LIBOPTS],[test "X${enable_libopts_install}" = Xyes])
 
   [if test -z "${NEED_LIBOPTS_DIR}" ; then]
      AC_MSG_CHECKING([whether autoopts-config can be found])
@@ -530,19 +539,54 @@ AC_DEFUN([LIBOPTS_CHECK],[
         LIBOPTS_CFLAGS='-I$(top_srcdir)/]AO_Libopts_Dir['
         NEED_LIBOPTS_DIR=true
      fi
-  fi # end of if test -z "${NEED_LIBOPTS_DIR}"]
-
+  fi # end of if test -z "${NEED_LIBOPTS_DIR}"
+  if test -n "${LIBOPTS_BUILD_BLOCKED}" ; then
+    NEED_LIBOPTS_DIR=''
+  fi]
   AM_CONDITIONAL([NEED_LIBOPTS], [test -n "${NEED_LIBOPTS_DIR}"])
   AC_SUBST(LIBOPTS_LDADD)
   AC_SUBST(LIBOPTS_CFLAGS)
   AC_SUBST(LIBOPTS_DIR, AO_Libopts_Dir)
-  AC_CONFIG_FILES(AO_Libopts_Dir/Makefile)
   m4_popdef([AO_Libopts_Dir])
-
-  [if test -n "${NEED_LIBOPTS_DIR}" ; then]
+[# end of AC_DEFUN of LIBOPTS_CHECK_COMMON]
+])
+dnl
+dnl AC_CONFIG_FILES conditionalization requires using AM_COND_IF, however
+dnl AM_COND_IF is new to Automake 1.11.  To use it on new Automake without
+dnl requiring same, a fallback implementation for older Automake is provided.
+dnl Note that disabling of AC_CONFIG_FILES requires Automake 1.11, this code
+dnl is correct only in terms of m4sh generated script.
+dnl
+m4_ifndef([AM_COND_IF],
+  [AC_DEFUN([AM_COND_IF], [
+    if test -z "$$1_TRUE"; then :
+      m4_n([$2])[]dnl
+      m4_ifval([$3],[
+    else
+      $3
+    ])dnl
+    fi[]dnl
+  ])dnl
+])
+dnl
+AC_DEFUN([LIBOPTS_CHECK_NOBUILD], [
+  m4_pushdef([AO_Libopts_Dir],
+	      [ifelse($1, , [libopts], [$1])])
+  LIBOPTS_BUILD_BLOCKED=true
+  LIBOPTS_CHECK_COMMON(AO_Libopts_Dir)
+  m4_popdef([AO_Libopts_Dir])dnl
+# end of AC_DEFUN of LIBOPTS_CHECK_NOBUILD
+])
+dnl
+AC_DEFUN([LIBOPTS_CHECK], [
+  m4_pushdef([AO_Libopts_Dir],
+	      [ifelse($1, , [libopts], [$1])])
+  LIBOPTS_BUILD_BLOCKED=''
+  LIBOPTS_CHECK_COMMON(AO_Libopts_Dir)
+  AM_COND_IF([NEED_LIBOPTS], [
     INVOKE_LIBOPTS_MACROS
-  else
-    INVOKE_LIBOPTS_MACROS_FIRST
-  [fi
-# end of AC_DEFUN of LIBOPTS_CHECK]
+  ])
+  AC_CONFIG_FILES(AO_Libopts_Dir/Makefile)
+  m4_popdef([AO_Libopts_Dir])dnl
+# end of AC_DEFUN of LIBOPTS_CHECK
 ])

+ 19 - 35
libopts/m4/liboptschk.m4

@@ -1,43 +1,27 @@
-# liboptschk.m4 serial 1 (autogen - 5.7.3)
-dnl copyright (c) 2005-2009 by Bruce Korb - all rights reserved
+# liboptschk.m4 serial 2 (autogen - 5.11.4)
+dnl Copyright (C) 2005-2014 by Bruce Korb - all rights reserved
 dnl
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
-
-dnl Time-stamp:        "2009-07-22 18:53:27 bkorb"
-dnl Last Committed:    $Date: 2009/07/23 02:05:55 $
-
-dnl This file can can be used in projects which are not available under
-dnl the GNU General Public License or the GNU Library General Public
-dnl License but which still want to provide support for the GNU gettext
-dnl functionality.
-dnl Please note that the actual code of the GNU gettext library is covered
-dnl by the GNU Library General Public License, and the rest of the GNU
-dnl gettext package package is covered by the GNU General Public License.
-dnl They are *not* in the public domain.
-
-dnl Authors:
-dnl   Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
-dnl   Bruno Haible <haible@clisp.cons.org>, 2000-2003.
-
-AC_PREREQ(2.50)
-
+dnl
 AC_DEFUN([ag_FIND_LIBOPTS],
-    [if test "X${ac_cv_header_autoopts_options_h}" == Xno
+  [if test "X${ac_cv_header_autoopts_options_h}" = Xno
+  then :
+  else
+    f=`autoopts-config cflags` 2>/dev/null
+    if test X"${f}" = X
     then
       :
     else
-      f=`autoopts-config cflags` 2>/dev/null
-      test X"${f}" = X && f=`libopts-config cflags` 2>/dev/null
-      if test X"${f}" = X
-      then
-        :
-      else
-        AC_DEFINE([HAVE_LIBOPTS],[1],[define if we can find libopts])
-        CFLAGS="${CFLAGS} ${f}"
-        f=`autoopts-config ldflags` 2>/dev/null
-        test X"${f}" = X && f=`libopts-config ldflags` 2>/dev/null
-        LIBS="${LIBS} ${f}"
-      fi
-    fi])
+      AC_DEFINE([HAVE_LIBOPTS],[1],[define if we can find libopts])
+      CFLAGS="${CFLAGS} ${f}"
+      ao_CFLAGS="${f}"
+      AC_SUBST(ao_CFLAGS)
+
+      f=`autoopts-config ldflags` 2>/dev/null
+      LIBS="${LIBS} ${f}"
+      ao_LIBS="${f}"
+      AC_SUBST(ao_LIBS)
+    fi
+  fi])

+ 41 - 0
libopts/m4/stdnoreturn.m4

@@ -0,0 +1,41 @@
+# Check for stdnoreturn.h that conforms to C11.
+
+dnl Copyright 2012-2014 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Prepare for substituting <stdnoreturn.h> if it is not supported.
+
+AC_DEFUN([gl_STDNORETURN_H],
+[
+  AC_CACHE_CHECK([for working stdnoreturn.h],
+    [gl_cv_header_working_stdnoreturn_h],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <stdlib.h>
+            #include <stdnoreturn.h>
+            /* Do not check for 'noreturn' after the return type.
+               C11 allows it, but it's rarely done that way
+               and circa-2012 bleeding-edge GCC rejects it when given
+               -Werror=old-style-declaration.  */
+            noreturn void foo1 (void) { exit (0); }
+            _Noreturn void foo2 (void) { exit (0); }
+            int testit (int argc, char **argv) {
+              if (argc & 1)
+                return 0;
+              (argv[0][0] ? foo1 : foo2) ();
+            }
+          ]])],
+       [gl_cv_header_working_stdnoreturn_h=yes],
+       [gl_cv_header_working_stdnoreturn_h=no])])
+
+  if test $gl_cv_header_working_stdnoreturn_h = yes; then
+    STDNORETURN_H=''
+  else
+    STDNORETURN_H='stdnoreturn.h'
+  fi
+
+  AC_SUBST([STDNORETURN_H])
+  AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])
+])

File diff suppressed because it is too large
+ 562 - 710
libopts/makeshell.c


File diff suppressed because it is too large
+ 450 - 357
libopts/nested.c


+ 85 - 82
libopts/numeric.c

@@ -1,11 +1,16 @@
 
-/*
- *  $Id: numeric.c,v 4.22 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2009-07-23 17:25:39 bkorb"
+/**
+ * \file numeric.c
+ *
+ * Handle options with numeric (integer) arguments.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -17,17 +22,17 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /*=export_func  optionShowRange
  * private:
  *
- * what:  
+ * what:  Show info about range constraints
  * arg:   + tOptions* + pOpts     + program options descriptor  +
  * arg:   + tOptDesc* + pOptDesc  + the descriptor for this arg +
  * arg:   + void *    + rng_table + the value range tables      +
@@ -37,103 +42,99 @@
  *   Show information about a numeric option with range constraints.
 =*/
 void
-optionShowRange(tOptions* pOpts, tOptDesc* pOD, void * rng_table, int rng_ct)
+optionShowRange(tOptions * pOpts, tOptDesc * pOD, void * rng_table, int rng_ct)
 {
-    static char const bullet[] = "\t\t\t\t- ";
-    static char const deepin[] = "\t\t\t\t  ";
-    static char const onetab[] = "\t";
-
     const struct {long const rmin, rmax;} * rng = rng_table;
 
-    char const * pz_indent =
-        (pOpts != OPTPROC_EMIT_USAGE) ? onetab : bullet;
-
-    if ((pOpts == OPTPROC_EMIT_USAGE) || (pOpts > OPTPROC_EMIT_LIMIT)) {
-        char const * lie_in_range = zRangeLie;
+    char const * pz_indent = zTabHyp + tab_skip_ct;
 
-        if (pOpts > OPTPROC_EMIT_LIMIT) {
-            fprintf(option_usage_fp, zRangeErr,
-                    pOpts->pzProgName, pOD->pz_Name, pOD->optArg.argString);
-            fprintf(option_usage_fp, "The %s option:\n", pOD->pz_Name);
-            lie_in_range = zRangeBadLie;
-            pz_indent = "";
-        }
-
-        if (pOD->fOptState & OPTST_SCALED_NUM)
-            fprintf(option_usage_fp, zRangeScaled, pz_indent);
-
-        if (rng_ct > 1) {
-            fprintf(option_usage_fp, lie_in_range, pz_indent);
-            pz_indent =
-                (pOpts != OPTPROC_EMIT_USAGE) ? onetab : deepin;
-
-        } else {
-            fprintf(option_usage_fp, zRangeOnly, pz_indent);
-            pz_indent = onetab + 1; /* empty string */
-        }
+    /*
+     * The range is shown only for full usage requests and an error
+     * in this particular option.
+     */
+    if (pOpts != OPTPROC_EMIT_USAGE) {
+        if (pOpts <= OPTPROC_EMIT_LIMIT)
+            return;
+        pz_indent = ONE_TAB_STR;
+
+        fprintf(option_usage_fp, zRangeErr, pOpts->pzProgName,
+                pOD->pz_Name, pOD->optArg.argInt);
+        pz_indent = "";
+    }
 
-        for (;;) {
-            if (rng->rmax == LONG_MIN)
-                fprintf(option_usage_fp, zRangeExact, pz_indent, rng->rmin);
-            else if (rng->rmin == LONG_MIN)
-                fprintf(option_usage_fp, zRangeUpto, pz_indent, rng->rmax);
-            else if (rng->rmax == LONG_MAX)
-                fprintf(option_usage_fp, zRangeAbove, pz_indent, rng->rmin);
-            else
-                fprintf(option_usage_fp, zRange, pz_indent, rng->rmin,
-                        rng->rmax);
-
-            if  (--rng_ct <= 0) {
-                fputc('\n', option_usage_fp);
-                break;
-            }
-            fputs(zRangeOr, option_usage_fp);
-            rng++;
-            pz_indent =
-                (pOpts != OPTPROC_EMIT_USAGE) ? onetab : deepin;
+    if (pOD->fOptState & OPTST_SCALED_NUM)
+        fprintf(option_usage_fp, zRangeScaled, pz_indent);
+
+    fprintf(option_usage_fp, (rng_ct > 1) ? zRangeLie : zRangeOnly, pz_indent);
+    pz_indent = (pOpts != OPTPROC_EMIT_USAGE)
+        ? ONE_TAB_STR
+        : (zTabSpace + tab_skip_ct);
+
+    for (;;) {
+        if (rng->rmax == LONG_MIN)
+            fprintf(option_usage_fp, zRangeExact, pz_indent, rng->rmin);
+        else if (rng->rmin == LONG_MIN)
+            fprintf(option_usage_fp, zRangeUpto, pz_indent, rng->rmax);
+        else if (rng->rmax == LONG_MAX)
+            fprintf(option_usage_fp, zRangeAbove, pz_indent, rng->rmin);
+        else
+            fprintf(option_usage_fp, zRange, pz_indent, rng->rmin,
+                    rng->rmax);
+
+        if  (--rng_ct <= 0) {
+            fputc(NL, option_usage_fp);
+            break;
         }
-
-        if (pOpts > OPTPROC_EMIT_LIMIT)
-            pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+        fputs(zRangeOr, option_usage_fp);
+        rng++;
     }
-}
 
+    if (pOpts > OPTPROC_EMIT_LIMIT)
+        pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+}
 
 /*=export_func  optionNumericVal
  * private:
  *
  * what:  process an option with a numeric value.
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
  *
  * doc:
  *  Decipher a numeric value.
 =*/
 void
-optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
+optionNumericVal(tOptions * opts, tOptDesc * od)
 {
     char* pz;
     long  val;
 
     /*
+     *  Guard against all the different ways this procedure might get invoked
+     *  when there is no string argument provided.
+     */
+    if (INQUERY_CALL(opts, od) || (od->optArg.argString == NULL))
+        return;
+
+    /*
      *  Numeric options may have a range associated with it.
      *  If it does, the usage procedure requests that it be
-     *  emitted by passing a NULL pOD pointer.  Also bail out
+     *  emitted by passing a NULL od pointer.  Also bail out
      *  if there is no option argument or if we are being reset.
      */
-    if (  (pOD == NULL)
-       || (pOD->optArg.argString == NULL)
-       || ((pOD->fOptState & OPTST_RESET) != 0))
+    if (  (od == NULL)
+       || (od->optArg.argString == NULL)
+       || ((od->fOptState & OPTST_RESET) != 0))
         return;
 
     errno = 0;
-    val = strtol(pOD->optArg.argString, &pz, 0);
-    if ((pz == pOD->optArg.argString) || (errno != 0))
+    val = strtol(od->optArg.argString, &pz, 0);
+    if ((pz == od->optArg.argString) || (errno != 0))
         goto bad_number;
 
-    if ((pOD->fOptState & OPTST_SCALED_NUM) != 0)
+    if ((od->fOptState & OPTST_SCALED_NUM) != 0)
         switch (*(pz++)) {
-        case '\0': pz--; break;
+        case NUL:  pz--; break;
         case 't':  val *= 1000;
         case 'g':  val *= 1000;
         case 'm':  val *= 1000;
@@ -150,24 +151,26 @@ optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
     if (*pz != NUL)
         goto bad_number;
 
-    if (pOD->fOptState & OPTST_ALLOC_ARG) {
-        AGFREE(pOD->optArg.argString);
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
+    if (od->fOptState & OPTST_ALLOC_ARG) {
+        AGFREE(od->optArg.argString);
+        od->fOptState &= ~OPTST_ALLOC_ARG;
     }
 
-    pOD->optArg.argInt = val;
+    od->optArg.argInt = val;
     return;
 
     bad_number:
 
-    fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
-    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
-        (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
+    fprintf( stderr, zNotNumber, opts->pzProgName, od->optArg.argString );
+    if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
+        (*(opts->pUsageProc))(opts, EXIT_FAILURE);
 
-    pOD->optArg.argInt = ~0;
+    errno = EINVAL;
+    od->optArg.argInt = ~0;
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 156 - 0
libopts/option-value-type.c

@@ -0,0 +1,156 @@
+/*   -*- buffer-read-only: t -*- vi: set ro:
+ *
+ *  DO NOT EDIT THIS FILE   (stdin.c)
+ *
+ *  It has been AutoGen-ed
+ *  From the definitions    stdin
+ *  and the template file   str2enum
+ *
+ * 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 ``Bruce Korb'' nor the name of any other
+ *    contributor may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * str2enum IS PROVIDED BY Bruce Korb ``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 Bruce Korb OR ANY OTHER 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 "option-value-type.h"
+/* ANSI-C code produced by gperf version 3.0.3 */
+/* Command-line: gperf option-value-type.gp  */
+/* Computed positions: -k'1' */
+
+
+
+# if 0 /* gperf build options: */
+// %struct-type
+// %language=ANSI-C
+// %includes
+// %global-table
+// %omit-struct-type
+// %readonly-tables
+// %compare-strncmp
+//
+// %define slot-name               vtp_name
+// %define hash-function-name      option_value_type_hash
+// %define lookup-function-name    find_option_value_type_name
+// %define word-array-name         option_value_type_table
+// %define initializer-suffix      ,VTP_COUNT_CMD
+//
+# endif
+
+#include "option-value-type.h"
+typedef struct {
+    char const *    vtp_name;
+    option_value_type_enum_t vtp_id;
+} option_value_type_map_t;
+#include <string.h>
+
+/* maximum key range = 15, duplicates = 0 */
+
+static unsigned int
+option_value_type_hash (register const char *str, register unsigned int len)
+{
+  static const unsigned char asso_values[] =
+    {
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18,  0, 18,
+      18, 18, 18, 18,  0, 10, 18,  5, 18, 18,
+       5, 18, 18, 18, 18,  0, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
+      18, 18, 18, 18, 18, 18
+    };
+  return len + asso_values[(unsigned char)str[0]];
+}
+
+static const option_value_type_map_t option_value_type_table[] =
+  {
+    {"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
+    {"",VTP_COUNT_CMD},
+    {"set",            VTP_CMD_SET},
+    {"bool",           VTP_CMD_BOOL},
+    {"",VTP_COUNT_CMD},
+    {"string",         VTP_CMD_STRING},
+    {"boolean",        VTP_CMD_BOOLEAN},
+    {"",VTP_COUNT_CMD},
+    {"hierarchy",      VTP_CMD_HIERARCHY},
+    {"",VTP_COUNT_CMD},
+    {"nested",         VTP_CMD_NESTED},
+    {"keyword",        VTP_CMD_KEYWORD},
+    {"",VTP_COUNT_CMD},
+    {"set-membership", VTP_CMD_SET_MEMBERSHIP},
+    {"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
+    {"integer",        VTP_CMD_INTEGER}
+  };
+
+static inline const option_value_type_map_t *
+find_option_value_type_name (register const char *str, register unsigned int len)
+{
+  if (len <= 14 && len >= 3)
+    {
+      register int key = (int)option_value_type_hash (str, len);
+
+      if (key <= 17 && key >= 0)
+        {
+          register const char *s = option_value_type_table[key].vtp_name;
+
+          if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
+            return &option_value_type_table[key];
+        }
+    }
+  return 0;
+}
+
+/**
+ * Convert a command (keyword) to a option_value_type_enum_t enumeration value.
+ *
+ * @param[in] str   a string that should start with a known key word.
+ * @param[in] len   the provided length of the keyword at \a str.
+ * @returns the enumeration value.
+ * If not found, that value is VTP_INVALID_CMD.
+ */
+option_value_type_enum_t
+find_option_value_type_cmd(char const * str, size_t len)
+{
+    option_value_type_map_t const * map;
+
+    map = find_option_value_type_name(str, (unsigned int)len);
+    return (map == NULL) ? VTP_INVALID_CMD : map->vtp_id;
+}
+
+/* end of option-value-type.c */

+ 60 - 0
libopts/option-value-type.h

@@ -0,0 +1,60 @@
+/*   -*- buffer-read-only: t -*- vi: set ro:
+ *
+ *  DO NOT EDIT THIS FILE   (stdin.h)
+ *
+ *  It has been AutoGen-ed
+ *  From the definitions    stdin
+ *  and the template file   str2enum
+ *
+ * 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 ``Bruce Korb'' nor the name of any other
+ *    contributor may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * str2enum IS PROVIDED BY Bruce Korb ``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 Bruce Korb OR ANY OTHER 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.
+ *
+ * Command/Keyword Dispatcher
+ */
+#ifndef STR2ENUM_OPTION_VALUE_TYPE_H_GUARD
+#define STR2ENUM_OPTION_VALUE_TYPE_H_GUARD 1
+#include <sys/types.h>
+#ifndef MISSING_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+typedef enum {
+    VTP_INVALID_CMD = 0,
+    VTP_CMD_STRING         = 1,
+    VTP_CMD_INTEGER        = 2,
+    VTP_CMD_BOOL           = 3,
+    VTP_CMD_BOOLEAN        = 4,
+    VTP_CMD_KEYWORD        = 5,
+    VTP_CMD_SET            = 6,
+    VTP_CMD_SET_MEMBERSHIP = 7,
+    VTP_CMD_NESTED         = 8,
+    VTP_CMD_HIERARCHY      = 9,
+    VTP_COUNT_CMD
+} option_value_type_enum_t;
+
+extern option_value_type_enum_t
+find_option_value_type_cmd(char const * str, size_t len);
+
+#endif /* STR2ENUM_OPTION_VALUE_TYPE_H_GUARD */
+/* end of option-value-type.h */

+ 148 - 0
libopts/option-xat-attribute.c

@@ -0,0 +1,148 @@
+/*   -*- buffer-read-only: t -*- vi: set ro:
+ *
+ *  DO NOT EDIT THIS FILE   (stdin.c)
+ *
+ *  It has been AutoGen-ed
+ *  From the definitions    stdin
+ *  and the template file   str2enum
+ *
+ * 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 ``Bruce Korb'' nor the name of any other
+ *    contributor may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * str2enum IS PROVIDED BY Bruce Korb ``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 Bruce Korb OR ANY OTHER 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 "option-xat-attribute.h"
+/* ANSI-C code produced by gperf version 3.0.3 */
+/* Command-line: gperf option-xat-attribute.gp  */
+/* Computed positions: -k'1' */
+
+
+
+# if 0 /* gperf build options: */
+// %struct-type
+// %language=ANSI-C
+// %includes
+// %global-table
+// %omit-struct-type
+// %readonly-tables
+// %compare-strncmp
+//
+// %define slot-name               xat_name
+// %define hash-function-name      option_xat_attribute_hash
+// %define lookup-function-name    find_option_xat_attribute_name
+// %define word-array-name         option_xat_attribute_table
+// %define initializer-suffix      ,XAT_COUNT_CMD
+//
+# endif
+
+#include "option-xat-attribute.h"
+typedef struct {
+    char const *    xat_name;
+    option_xat_attribute_enum_t xat_id;
+} option_xat_attribute_map_t;
+#include <string.h>
+
+/* maximum key range = 6, duplicates = 0 */
+
+static unsigned int
+option_xat_attribute_hash (register const char *str, register unsigned int len)
+{
+  static const unsigned char asso_values[] =
+    {
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10, 0,
+     10,10,10,10,10,10,10, 5,10, 0,
+     10,10,10,10,10,10, 0, 0,10, 0,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10,10,10,10,10,
+     10,10,10,10,10,10
+    };
+  return len + asso_values[(unsigned char)str[0]];
+}
+
+static const option_xat_attribute_map_t option_xat_attribute_table[] =
+  {
+    {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
+    {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
+    {"type",     XAT_CMD_TYPE},
+    {"words",    XAT_CMD_WORDS},
+    {"cooked",   XAT_CMD_COOKED},
+    {"members",  XAT_CMD_MEMBERS},
+    {"uncooked", XAT_CMD_UNCOOKED},
+    {"keep",     XAT_CMD_KEEP}
+  };
+
+static inline const option_xat_attribute_map_t *
+find_option_xat_attribute_name (register const char *str, register unsigned int len)
+{
+  if (len <= 8 && len >= 4)
+    {
+      register int key = (int)option_xat_attribute_hash (str, len);
+
+      if (key <= 9 && key >= 0)
+        {
+          register const char *s = option_xat_attribute_table[key].xat_name;
+
+          if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
+            return &option_xat_attribute_table[key];
+        }
+    }
+  return 0;
+}
+
+/**
+ * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value.
+ *
+ * @param[in] str   a string that should start with a known key word.
+ * @param[in] len   the provided length of the keyword at \a str.
+ * @returns the enumeration value.
+ * If not found, that value is XAT_INVALID_CMD.
+ */
+option_xat_attribute_enum_t
+find_option_xat_attribute_cmd(char const * str, size_t len)
+{
+    option_xat_attribute_map_t const * map;
+
+    map = find_option_xat_attribute_name(str, (unsigned int)len);
+    return (map == NULL) ? XAT_INVALID_CMD : map->xat_id;
+}
+
+/* end of option-xat-attribute.c */

+ 57 - 0
libopts/option-xat-attribute.h

@@ -0,0 +1,57 @@
+/*   -*- buffer-read-only: t -*- vi: set ro:
+ *
+ *  DO NOT EDIT THIS FILE   (stdin.h)
+ *
+ *  It has been AutoGen-ed
+ *  From the definitions    stdin
+ *  and the template file   str2enum
+ *
+ * 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 ``Bruce Korb'' nor the name of any other
+ *    contributor may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * str2enum IS PROVIDED BY Bruce Korb ``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 Bruce Korb OR ANY OTHER 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.
+ *
+ * Command/Keyword Dispatcher
+ */
+#ifndef STR2ENUM_OPTION_XAT_ATTRIBUTE_H_GUARD
+#define STR2ENUM_OPTION_XAT_ATTRIBUTE_H_GUARD 1
+#include <sys/types.h>
+#ifndef MISSING_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+typedef enum {
+    XAT_INVALID_CMD = 0,
+    XAT_CMD_TYPE     = 1,
+    XAT_CMD_WORDS    = 2,
+    XAT_CMD_MEMBERS  = 3,
+    XAT_CMD_COOKED   = 4,
+    XAT_CMD_UNCOOKED = 5,
+    XAT_CMD_KEEP     = 6,
+    XAT_COUNT_CMD
+} option_xat_attribute_enum_t;
+
+extern option_xat_attribute_enum_t
+find_option_xat_attribute_cmd(char const * str, size_t len);
+
+#endif /* STR2ENUM_OPTION_XAT_ATTRIBUTE_H_GUARD */
+/* end of option-xat-attribute.h */

+ 85 - 63
libopts/parse-duration.c

@@ -1,22 +1,25 @@
 /* Parse a time duration and return a seconds count
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2014 Free Software Foundation, Inc.
    Written by Bruce Korb <bkorb@gnu.org>, 2008.
 
    This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   GNU Lesser General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+/* Specification.  */
+#include "parse-duration.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
@@ -24,11 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "parse-duration.h"
-
-#ifndef _
-#define _(_s)  _s
-#endif
+#include "intprops.h"
 
 #ifndef NUL
 #define NUL '\0'
@@ -54,21 +53,27 @@ typedef enum {
 #define SEC_PER_MONTH   (SEC_PER_DAY * 30)
 #define SEC_PER_YEAR    (SEC_PER_DAY * 365)
 
-#define TIME_MAX        0x7FFFFFFF
+#undef  MAX_DURATION
+#define MAX_DURATION    TYPE_MAXIMUM(time_t)
 
-static unsigned long inline
+/* Wrapper around strtoul that does not require a cast.  */
+static unsigned long
 str_const_to_ul (cch_t * str, cch_t ** ppz, int base)
 {
   return strtoul (str, (char **)ppz, base);
 }
 
-static long inline
+/* Wrapper around strtol that does not require a cast.  */
+static long
 str_const_to_l (cch_t * str, cch_t ** ppz, int base)
 {
   return strtol (str, (char **)ppz, base);
 }
 
-static time_t inline
+/* Returns BASE + VAL * SCALE, interpreting BASE = BAD_TIME
+   with errno set as an error situation, and returning BAD_TIME
+   with errno set in an error situation.  */
+static time_t
 scale_n_add (time_t base, time_t val, int scale)
 {
   if (base == BAD_TIME)
@@ -78,14 +83,14 @@ scale_n_add (time_t base, time_t val, int scale)
       return BAD_TIME;
     }
 
-  if (val > TIME_MAX / scale)
+  if (val >= MAX_DURATION / scale)
     {
       errno = ERANGE;
       return BAD_TIME;
     }
 
   val *= scale;
-  if (base > TIME_MAX - val)
+  if ((base + val) >= MAX_DURATION)
     {
       errno = ERANGE;
       return BAD_TIME;
@@ -94,6 +99,7 @@ scale_n_add (time_t base, time_t val, int scale)
   return base + val;
 }
 
+/* After a number HH has been parsed, parse subsequent :MM or :MM:SS.  */
 static time_t
 parse_hr_min_sec (time_t start, cch_t * pz)
 {
@@ -117,7 +123,8 @@ parse_hr_min_sec (time_t start, cch_t * pz)
     }
 
   /* allow for trailing spaces */
-  while (isspace ((unsigned char)*pz))   pz++;
+  while (isspace ((unsigned char)*pz))
+    pz++;
   if (*pz != NUL)
     {
       errno = EINVAL;
@@ -127,6 +134,9 @@ parse_hr_min_sec (time_t start, cch_t * pz)
   return start;
 }
 
+/* Parses a value and returns BASE + value * SCALE, interpreting
+   BASE = BAD_TIME with errno set as an error situation, and returning
+   BAD_TIME with errno set in an error situation.  */
 static time_t
 parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale)
 {
@@ -140,17 +150,20 @@ parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale)
   val = str_const_to_ul (pz, &pz, 10);
   if (errno != 0)
     return BAD_TIME;
-  while (isspace ((unsigned char)*pz))   pz++;
+  while (isspace ((unsigned char)*pz))
+    pz++;
   if (pz != endp)
     {
       errno = EINVAL;
       return BAD_TIME;
     }
 
-  *ppz =  pz;
+  *ppz = pz;
   return scale_n_add (base, val, scale);
 }
 
+/* Parses the syntax YEAR-MONTH-DAY.
+   PS points into the string, after "YEAR", before "-MONTH-DAY".  */
 static time_t
 parse_year_month_day (cch_t * pz, cch_t * ps)
 {
@@ -158,7 +171,8 @@ parse_year_month_day (cch_t * pz, cch_t * ps)
 
   res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
 
-  ps = strchr (++pz, '-');
+  pz++; /* over the first '-' */
+  ps = strchr (pz, '-');
   if (ps == NULL)
     {
       errno = EINVAL;
@@ -166,11 +180,12 @@ parse_year_month_day (cch_t * pz, cch_t * ps)
     }
   res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);
 
-  pz++;
+  pz++; /* over the second '-' */
   ps = pz + strlen (pz);
   return parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
 }
 
+/* Parses the syntax YYYYMMDD.  */
 static time_t
 parse_yearmonthday (cch_t * in_pz)
 {
@@ -200,6 +215,7 @@ parse_yearmonthday (cch_t * in_pz)
   return parse_scaled_value (res, &pz, buf + 2, SEC_PER_DAY);
 }
 
+/* Parses the syntax yy Y mm M ww W dd D.  */
 static time_t
 parse_YMWD (cch_t * pz)
 {
@@ -232,7 +248,8 @@ parse_YMWD (cch_t * pz)
       pz++;
     }
 
-  while (isspace ((unsigned char)*pz))   pz++;
+  while (isspace ((unsigned char)*pz))
+    pz++;
   if (*pz != NUL)
     {
       errno = EINVAL;
@@ -242,6 +259,8 @@ parse_YMWD (cch_t * pz)
   return res;
 }
 
+/* Parses the syntax HH:MM:SS.
+   PS points into the string, after "HH", before ":MM:SS".  */
 static time_t
 parse_hour_minute_second (cch_t * pz, cch_t * ps)
 {
@@ -249,7 +268,8 @@ parse_hour_minute_second (cch_t * pz, cch_t * ps)
 
   res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
 
-  ps = strchr (++pz, ':');
+  pz++;
+  ps = strchr (pz, ':');
   if (ps == NULL)
     {
       errno = EINVAL;
@@ -263,6 +283,7 @@ parse_hour_minute_second (cch_t * pz, cch_t * ps)
   return parse_scaled_value (res, &pz, ps, 1);
 }
 
+/* Parses the syntax HHMMSS.  */
 static time_t
 parse_hourminutesecond (cch_t * in_pz)
 {
@@ -292,6 +313,7 @@ parse_hourminutesecond (cch_t * in_pz)
   return parse_scaled_value (res, &pz, buf + 2, 1);
 }
 
+/* Parses the syntax hh H mm M ss S.  */
 static time_t
 parse_HMS (cch_t * pz)
 {
@@ -317,7 +339,8 @@ parse_HMS (cch_t * pz)
       pz++;
     }
 
-  while (isspace ((unsigned char)*pz))   pz++;
+  while (isspace ((unsigned char)*pz))
+    pz++;
   if (*pz != NUL)
     {
       errno = EINVAL;
@@ -327,6 +350,7 @@ parse_HMS (cch_t * pz)
   return res;
 }
 
+/* Parses a time (hours, minutes, seconds) specification in either syntax.  */
 static time_t
 parse_time (cch_t * pz)
 {
@@ -358,16 +382,20 @@ parse_time (cch_t * pz)
   return res;
 }
 
+/* Returns a substring of the given string, with spaces at the beginning and at
+   the end destructively removed, per SNOBOL.  */
 static char *
-trim(char * pz)
+trim (char * pz)
 {
   /* trim leading white space */
-  while (isspace ((unsigned char)*pz))  pz++;
+  while (isspace ((unsigned char)*pz))
+    pz++;
 
   /* trim trailing white space */
   {
     char * pe = pz + strlen (pz);
-    while ((pe > pz) && isspace ((unsigned char)pe[-1])) pe--;
+    while ((pe > pz) && isspace ((unsigned char)pe[-1]))
+      pe--;
     *pe = NUL;
   }
 
@@ -380,13 +408,20 @@ trim(char * pz)
 static time_t
 parse_period (cch_t * in_pz)
 {
-  char * pz   = xstrdup (in_pz);
-  char * pT   = strchr (pz, 'T');
+  char * pT;
   char * ps;
+  char * pz   = strdup (in_pz);
   void * fptr = pz;
   time_t res  = 0;
 
-  if (pT != NUL)
+  if (pz == NULL)
+    {
+      errno = ENOMEM;
+      return BAD_TIME;
+    }
+
+  pT = strchr (pz, 'T');
+  if (pT != NULL)
     {
       *(pT++) = NUL;
       pz = trim (pz);
@@ -426,7 +461,7 @@ parse_period (cch_t * in_pz)
 }
 
 static time_t
-parse_non_iso8601(cch_t * pz)
+parse_non_iso8601 (cch_t * pz)
 {
   whats_done_t whatd_we_do = NOTHING_IS_DONE;
 
@@ -461,7 +496,8 @@ parse_non_iso8601(cch_t * pz)
       unsigned int mult;
 
       /*  Skip over white space following the number we just parsed. */
-      while (isspace ((unsigned char)*pz))   pz++;
+      while (isspace ((unsigned char)*pz))
+        pz++;
 
       switch (*pz)
         {
@@ -519,7 +555,9 @@ parse_non_iso8601(cch_t * pz)
 
       res = scale_n_add (res, val, mult);
 
-      while (isspace ((unsigned char)*++pz))   ;
+      pz++;
+      while (isspace ((unsigned char)*pz))
+        pz++;
       if (*pz == NUL)
         return res;
 
@@ -537,40 +575,24 @@ parse_non_iso8601(cch_t * pz)
 time_t
 parse_duration (char const * pz)
 {
-  time_t res = 0;
+  while (isspace ((unsigned char)*pz))
+    pz++;
 
-  while (isspace ((unsigned char)*pz)) pz++;
-
-  do {
-    if (*pz == 'P')
-      {
-        res = parse_period (pz + 1);
-        if ((errno != 0) || (res == BAD_TIME))
-          break;
-        return res;
-      }
-
-    if (*pz == 'T')
-      {
-        res = parse_time (pz + 1);
-        if ((errno != 0) || (res == BAD_TIME))
-          break;
-        return res;
-      }
-
-    if (! isdigit ((unsigned char)*pz))
-      break;
+  switch (*pz)
+    {
+    case 'P':
+      return parse_period (pz + 1);
 
-    res = parse_non_iso8601 (pz);
-    if ((errno == 0) && (res != BAD_TIME))
-      return res;
+    case 'T':
+      return parse_time (pz + 1);
 
-  } while (0);
+    default:
+      if (isdigit ((unsigned char)*pz))
+        return parse_non_iso8601 (pz);
 
-  fprintf (stderr, _("Invalid time duration:  %s\n"), pz);
-  if (errno == 0)
-    errno = EINVAL;
-  return BAD_TIME;
+      errno = EINVAL;
+      return BAD_TIME;
+    }
 }
 
 /*

+ 20 - 12
libopts/parse-duration.h

@@ -1,18 +1,18 @@
 /* Parse a time duration and return a seconds count
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2014 Free Software Foundation, Inc.
    Written by Bruce Korb <bkorb@gnu.org>, 2008.
 
    This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   GNU Lesser General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /*
@@ -28,10 +28,12 @@
 
   ==== if it is a digit
 
-  the string may contain:  NNN d NNN h NNN m NNN s
-  This represents NNN days, NNN hours, NNN minutes and NNN seconds.
-  The embeded white space is optional.
+  the string may contain:  NNN Y NNN M NNN W NNN d NNN h NNN m NNN s
+  This represents NNN years, NNN months, NNN weeks, NNN days, NNN hours,
+    NNN minutes and NNN seconds.
+  The embedded white space is optional.
   These terms must appear in this order.
+  Case is significant:  'M' is months and 'm' is minutes.
   The final "s" is optional.
   All of the terms ("NNN" plus designator) are optional.
   Minutes and seconds may optionally be represented as NNN:NNN.
@@ -47,9 +49,11 @@
     yy Y mm M ww W dd D
 
   or it may be empty and followed by a 'T'.  The "yyyymmdd" must be eight
-  digits long.  Note:  months are always 30 days and years are always 365
-  days long.  5 years is always 1825, not 1826 or 1827 depending on leap
-  year considerations.  3 months is always 90 days.  There is no consideration
+  digits long.
+
+  NOTE!  Months are always 30 days and years are always 365 days long.
+  5 years is always 1825 days, not 1826 or 1827 depending on leap year
+  considerations.  3 months is always 90 days.  There is no consideration
   for how many days are in the current, next or previous months.
 
   For the final format:
@@ -75,8 +79,12 @@
 
 #include <time.h>
 
+/* Return value when a valid duration cannot be parsed.  */
 #define BAD_TIME        ((time_t)~0)
 
-extern time_t parse_duration(char const * in_pz);
+/* Parses the given string.  If it has the syntax of a valid duration,
+   this duration is returned.  Otherwise, the return value is BAD_TIME,
+   and errno is set to either EINVAL (bad syntax) or ERANGE (out of range).  */
+extern time_t parse_duration (char const * in_pz);
 
 #endif /* GNULIB_PARSE_DURATION_H */

+ 107 - 60
libopts/pgusage.c

@@ -1,16 +1,19 @@
 
-/*
- *  $Id: pgusage.c,v 4.18 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2008-07-27 21:08:42 bkorb"
+/**
+ * \file pgusage.c
  *
  *   Automated Options Paged Usage module.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This routine will run run-on options through a pager so the
  *  user may examine, print or edit them at their leisure.
  *
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -22,37 +25,98 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
-tePagerState pagerState = PAGER_STATE_INITIAL;
+#if defined(HAVE_WORKING_FORK)
+static FILE *
+open_tmp_usage(char ** buf)
+{
+    char * bf;
+    size_t bfsz;
+
+    {
+        unsigned int my_pid = (unsigned int)getpid();
+        char const * tmpdir = getenv(TMPDIR);
+        if (tmpdir == NULL)
+            tmpdir = tmp_dir;
+        bfsz = TMP_FILE_FMT_LEN + strlen(tmpdir) + 10;
+        bf   = AGALOC(bfsz, "tmp fil");
+        snprintf(bf, bfsz, TMP_FILE_FMT, tmpdir, my_pid);
+    }
+
+    {
+        static mode_t const cmask = S_IRWXO | S_IRWXG;
+        mode_t svmsk = umask(cmask);
+        int fd = mkstemp(bf);
+        (void)umask(svmsk);
+
+        if (fd < 0) {
+            AGFREE(bf);
+            return NULL;
+        }
+        *buf = bf;
+        return fdopen(fd, "w");
+    }
+}
+
+static char *
+mk_pager_cmd(char const * fname)
+{
+    /*
+     * Page the file and remove it when done.  For shell script processing,
+     * we must redirect the output to the current stderr, otherwise stdout.
+     */
+    fclose(option_usage_fp);
+    option_usage_fp = NULL;
+
+    {
+        char const * pager  = (char const *)getenv(PAGER_NAME);
+        size_t bfsz;
+        char * res;
+
+        /*
+         *  Use the "more(1)" program if "PAGER" has not been defined
+         */
+        if (pager == NULL)
+            pager = MORE_STR;
+
+        bfsz = strlen(fname) + strlen(pager) + PAGE_USAGE_FMT_LEN;
+        res  = AGALOC(bfsz, "more cmd");
+        snprintf(res, bfsz, PAGE_USAGE_FMT, pager, fname);
+        AGFREE((void*)fname);
+        return res;
+    }
+}
+#endif
 
 /*=export_func  optionPagedUsage
  * private:
  *
- * what:  Decipher a boolean value
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * what:  emit help text and pass through a pager program.
+ * arg:   + tOptions * + opts + program options descriptor +
+ * arg:   + tOptDesc * + od   + the descriptor for this arg +
  *
  * doc:
  *  Run the usage output through a pager.
  *  This is very handy if it is very long.
+ *  This is disabled on platforms without a working fork() function.
 =*/
 void
-optionPagedUsage( tOptions* pOptions, tOptDesc* pOD )
+optionPagedUsage(tOptions * opts, tOptDesc * od)
 {
-#if defined(__windows__) && !defined(__CYGWIN__)
-    if ((pOD->fOptState & OPTST_RESET) != 0)
+#if ! defined(HAVE_WORKING_FORK)
+    if ((od->fOptState & OPTST_RESET) != 0)
         return;
 
-    (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS );
+    (*opts->pUsageProc)(opts, EXIT_SUCCESS);
 #else
-    static pid_t     my_pid;
-    char zPageUsage[ 1024 ];
+    static bool sv_print_exit = false;
+    static char * fil_name = NULL;
 
     /*
      *  IF we are being called after the usage proc is done
@@ -62,65 +126,47 @@ optionPagedUsage( tOptions* pOptions, tOptDesc* pOD )
     switch (pagerState) {
     case PAGER_STATE_INITIAL:
     {
-        if ((pOD->fOptState & OPTST_RESET) != 0)
+        if ((od->fOptState & OPTST_RESET) != 0)
             return;
-
-        my_pid  = getpid();
-#ifdef HAVE_SNPRINTF
-        snprintf(zPageUsage, sizeof(zPageUsage), "/tmp/use.%lu", (tAoUL)my_pid);
-#else
-        sprintf( zPageUsage, "/tmp/use.%lu", (tAoUL)my_pid );
-#endif
-        unlink( zPageUsage );
-
-        /*
-         *  Set usage output to this temporary file
-         */
-        option_usage_fp = fopen( zPageUsage, "w" FOPEN_BINARY_FLAG );
+        option_usage_fp = open_tmp_usage(&fil_name);
         if (option_usage_fp == NULL)
-            _exit( EXIT_FAILURE );
+            (*opts->pUsageProc)(opts, EXIT_SUCCESS);
 
-        pagerState = PAGER_STATE_READY;
+        pagerState    = PAGER_STATE_READY;
+        sv_print_exit = print_exit;
 
         /*
          *  Set up so this routine gets called during the exit logic
          */
-        atexit( (void(*)(void))optionPagedUsage );
+        atexit((void(*)(void))optionPagedUsage);
 
         /*
          *  The usage procedure will now put the usage information into
-         *  the temporary file we created above.
+         *  the temporary file we created above.  Keep any shell commands
+         *  out of the result.
          */
-        (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS );
+        print_exit = false;
+        (*opts->pUsageProc)(opts, EXIT_SUCCESS);
 
-        /*NOTREACHED*/
-        _exit( EXIT_FAILURE );
+        /* NOTREACHED */
+        _exit(EXIT_FAILURE);
     }
 
     case PAGER_STATE_READY:
-    {
-        tSCC zPage[]  = "%1$s /tmp/use.%2$lu ; rm -f /tmp/use.%2$lu";
-        tCC* pzPager  = (tCC*)getenv( "PAGER" );
+        fil_name = mk_pager_cmd(fil_name);
 
-        /*
-         *  Use the "more(1)" program if "PAGER" has not been defined
-         */
-        if (pzPager == NULL)
-            pzPager = "more";
+        if (sv_print_exit) {
+            fputs("\nexit 0\n", stdout);
+            fclose(stdout);
+            dup2(STDERR_FILENO, STDOUT_FILENO);
 
-        /*
-         *  Page the file and remove it when done.
-         */
-#ifdef HAVE_SNPRINTF
-        snprintf(zPageUsage, sizeof(zPageUsage), zPage, pzPager, (tAoUL)my_pid);
-#else
-        sprintf( zPageUsage, zPage, pzPager, (tAoUL)my_pid );
-#endif
-        fclose( stderr );
-        dup2( STDOUT_FILENO, STDERR_FILENO );
+        } else {
+            fclose(stderr);
+            dup2(STDOUT_FILENO, STDERR_FILENO);
+        }
 
-        (void)system( zPageUsage );
-    }
+        ignore_val( system( fil_name));
+        AGFREE(fil_name);
 
     case PAGER_STATE_CHILD:
         /*
@@ -131,7 +177,8 @@ optionPagedUsage( tOptions* pOptions, tOptDesc* pOD )
 #endif
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 96 - 62
libopts/proto.h

@@ -1,112 +1,146 @@
 /* -*- buffer-read-only: t -*- vi: set ro:
  *
  * Prototypes for autoopts
- * Generated Sat Aug  8 10:14:45 PDT 2009
+ * Generated Sat Aug 30 10:36:38 PDT 2014
  */
 #ifndef AUTOOPTS_PROTO_H_GUARD
 #define AUTOOPTS_PROTO_H_GUARD 1
 
-#ifndef LOCAL
-#  define LOCAL extern
-#  define REDEF_LOCAL 1
-#else
-#  undef  REDEF_LOCAL
-#endif
+/*
+ *  Extracted from alias.c
+ */
+static tSuccess
+too_many_occurrences(tOptions * opts, tOptDesc * od);
+
 /*
  *  Extracted from autoopts.c
  */
-LOCAL void *
-ao_malloc( size_t sz );
+static void *
+ao_malloc(size_t sz);
 
-LOCAL void *
-ao_realloc( void *p, size_t sz );
+static void *
+ao_realloc(void *p, size_t sz);
 
-LOCAL void
-ao_free( void *p );
+static char *
+ao_strdup(char const *str);
 
-LOCAL char *
-ao_strdup( char const *str );
+static tSuccess
+handle_opt(tOptions * opts, tOptState * o_st);
 
-LOCAL tSuccess
-handleOption( tOptions* pOpts, tOptState* pOptState );
+static tSuccess
+next_opt(tOptions * opts, tOptState * o_st);
 
-LOCAL tSuccess
-longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState );
+static tSuccess
+regular_opts(tOptions * opts);
 
-LOCAL tSuccess
-shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState );
+/*
+ *  Extracted from check.c
+ */
+static bool
+is_consistent(tOptions * pOpts);
 
-LOCAL tSuccess
-doImmediateOpts( tOptions* pOpts );
+/*
+ *  Extracted from configfile.c
+ */
+static void
+intern_file_load(tOptions * opts);
 
-LOCAL tSuccess
-doRegularOpts( tOptions* pOpts );
+static char const *
+parse_attrs(tOptions * opts, char const * txt, tOptionLoadMode * pMode,
+            tOptionValue * pType);
 
 /*
- *  Extracted from configfile.c
+ *  Extracted from env.c
+ */
+static void
+doPrognameEnv(tOptions * pOpts, teEnvPresetType type);
+
+static void
+env_presets(tOptions * pOpts, teEnvPresetType type);
+
+/*
+ *  Extracted from find.c
  */
-LOCAL void
-internalFileLoad( tOptions* pOpts );
+static tSuccess
+opt_find_long(tOptions * opts, char const * opt_name, tOptState * state);
 
-LOCAL char*
-parseAttributes(
-    tOptions*           pOpts,
-    char*               pzText,
-    tOptionLoadMode*    pMode,
-    tOptionValue*       pType );
+static tSuccess
+opt_find_short(tOptions* pOpts, uint_t optValue, tOptState* pOptState);
 
-LOCAL tSuccess
-validateOptionsStruct( tOptions* pOpts, char const* pzProgram );
+static tSuccess
+get_opt_arg(tOptions * opts, tOptState * o_st);
+
+static tSuccess
+find_opt(tOptions * opts, tOptState * o_st);
 
 /*
- *  Extracted from environment.c
+ *  Extracted from init.c
  */
-LOCAL void
-doPrognameEnv( tOptions* pOpts, teEnvPresetType type );
+static tSuccess
+validate_struct(tOptions * opts, char const * pname);
+
+static tSuccess
+immediate_opts(tOptions * opts);
 
-LOCAL void
-doEnvPresets( tOptions* pOpts, teEnvPresetType type );
+static bool
+ao_initialize(tOptions * opts, int a_ct, char ** a_v);
 
 /*
  *  Extracted from load.c
  */
-LOCAL void
-mungeString( char* pzTxt, tOptionLoadMode mode );
+static void
+munge_str(char * txt, tOptionLoadMode mode);
+
+static void
+load_opt_line(tOptions * opts, tOptState * opt_state, char * line,
+              tDirection direction, tOptionLoadMode load_mode );
+
+/*
+ *  Extracted from makeshell.c
+ */
+static noreturn void
+option_exits(int exit_code);
 
-LOCAL void
-loadOptionLine(
-    tOptions*   pOpts,
-    tOptState*  pOS,
-    char*       pzLine,
-    tDirection  direction,
-    tOptionLoadMode   load_mode );
+static noreturn void
+ao_bug(char const * msg);
+
+static void
+fserr_warn(char const * prog, char const * op, char const * fname);
+
+static noreturn void
+fserr_exit(char const * prog, char const * op, char const * fname);
 
 /*
  *  Extracted from nested.c
  */
-LOCAL tOptionValue*
-optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen);
+static void
+unload_arg_list(tArgList * arg_list);
+
+static tOptionValue *
+optionLoadNested(char const * text, char const * name, size_t nm_len);
 
-LOCAL int
+static int
 get_special_char(char const ** ppz, int * ct);
 
-LOCAL void
+static void
 emit_special_char(FILE * fp, int ch);
 
 /*
  *  Extracted from sort.c
  */
-LOCAL void
-optionSort( tOptions* pOpts );
+static void
+optionSort(tOptions * opts);
 
 /*
  *  Extracted from stack.c
  */
-LOCAL void
-addArgListEntry( void** ppAL, void* entry );
+static void
+addArgListEntry(void ** ppAL, void * entry);
+
+/*
+ *  Extracted from usage.c
+ */
+static void
+set_usage_flags(tOptions * opts, char const * flg_txt);
 
-#ifdef REDEF_LOCAL
-#  undef LOCAL
-#  define LOCAL
-#endif
 #endif /* AUTOOPTS_PROTO_H_GUARD */

+ 340 - 149
libopts/putshell.c

@@ -1,15 +1,18 @@
 
-/*
- *  $Id: putshell.c,v 4.27 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2008-07-27 12:14:38 bkorb"
+/**
+ * \file putshell.c
  *
  *  This module will interpret the options set in the tOptions
  *  structure and print them to standard out in a fashion that
  *  will allow them to be interpreted by the Bourne or Korn shells.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,31 +24,207 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
+static size_t
+string_size(char const * scan, size_t nl_len);
+
+static char const *
+print_quoted_apostrophes(char const * str);
+
+static void
+print_quot_str(char const * str);
+
+static void
+print_enumeration(tOptions * pOpts, tOptDesc * pOD);
+
 static void
-putQuotedStr( tCC* pzStr );
+print_membership(tOptions * pOpts, tOptDesc * pOD);
+
+static void
+print_stacked_arg(tOptions * pOpts, tOptDesc * pOD);
+
+static void
+print_reordering(tOptions * opts);
 /* = = = END-STATIC-FORWARD = = = */
 
-/*
- *  Make sure embedded single quotes come out okay.  The initial quote has
- *  been emitted and the closing quote will be upon return.
+/**
+ * Count the number of bytes required to represent a string as a
+ * compilable string.
+ *
+ * @param[in] scan    the text to be rewritten as a C program text string.
+ * @param[in] nl_len  the number of bytes used for each embedded newline.
+ *
+ * @returns the count, including the terminating NUL byte.
+ */
+static size_t
+string_size(char const * scan, size_t nl_len)
+{
+    /*
+     *  Start by counting the start and end quotes, plus the NUL.
+     */
+    size_t res_ln = 3;
+
+    for (;;) {
+        char ch = *(scan++);
+        if ((ch >= ' ') && (ch <= '~')) {
+
+            /*
+             * a backslash allowance for double quotes and baskslashes
+             */
+            res_ln += ((ch == '"') || (ch == '\\')) ? 2 : 1;
+        }
+
+        /*
+         *  When not a normal character, then count the characters
+         *  required to represent whatever it is.
+         */
+        else switch (ch) {
+        case NUL:
+            return res_ln;
+
+        case NL:
+            res_ln += nl_len;
+            break;
+
+        case HT:
+        case BEL:
+        case BS:
+        case FF:
+        case CR:
+        case VT:
+            res_ln += 2;
+            break;
+
+        default:
+            res_ln += 4; /* text len for \xNN */
+        }
+    }
+}
+
+/*=export_func  optionQuoteString
+ * private:
+ *
+ * what:  Print a string as quoted text suitable for a C compiler.
+ * arg:   + char const * + text  + a block of text to quote +
+ * arg:   + char const * + nl    + line splice text         +
+ *
+ * ret_type:  char const *
+ * ret_desc:  the allocated input string as a quoted string
+ *
+ * doc:
+ *  This is for internal use by autogen and autoopts.
+ *  It takes an input string and produces text the C compiler can process
+ *  to produce an exact copy of the original string.
+ *  The caller must deallocate the result.  Standard C strings and
+ *  K&R strings are distinguished by the "nl" string.
+=*/
+char const *
+optionQuoteString(char const * text, char const * nl)
+{
+    size_t   nl_len = strlen(nl);
+    char *   out;
+    char *   res = out = AGALOC(string_size(text, nl_len), "quot str");
+    *(out++) = '"';
+
+    for (;;) {
+        unsigned char ch = (unsigned char)*text;
+        if ((ch >= ' ') && (ch <= '~')) {
+            if ((ch == '"') || (ch == '\\'))
+                /*
+                 *  We must escape these characters in the output string
+                 */
+                *(out++) = '\\';
+            *(out++) = (char)ch;
+
+        } else switch (ch) {
+#       define   add_esc_ch(_ch)  { *(out++) = '\\'; *(out++) = (_ch); }
+        case BEL: add_esc_ch('a'); break;
+        case BS:  add_esc_ch('b'); break;
+        case HT:  add_esc_ch('t'); break;
+        case VT:  add_esc_ch('v'); break;
+        case FF:  add_esc_ch('f'); break;
+        case CR:  add_esc_ch('r'); break;
+
+        case LF:
+            /*
+             *  Place contiguous new-lines on a single line.
+             *  The current character is a NL, check the next one.
+             */
+            while (*++text == NL)
+                add_esc_ch('n');
+
+            /*
+             *  Insert a splice before starting next line
+             */
+            if (*text != NUL) {
+                memcpy(out, nl, nl_len);
+                out += nl_len;
+
+                continue; /* text is already at the next character */
+            }
+
+            add_esc_ch('n');
+            /* FALLTHROUGH */
+
+        case NUL:
+            /*
+             *  End of string.  Terminate the quoted output.  If necessary,
+             *  deallocate the text string.  Return the scan resumption point.
+             */
+            *(out++) = '"';
+            *out = NUL;
+            return res;
+
+        default:
+            /*
+             *  sprintf is safe here, because we already computed
+             *  the amount of space we will be using.
+             */
+            sprintf(out, MK_STR_OCT_FMT, ch);
+            out += 4;
+        }
+
+        text++;
+#       undef add_esc_ch
+    }
+}
+
+/**
+ *  Print out escaped apostorophes.
+ *
+ *  @param[in] str  the apostrophies to print
+ */
+static char const *
+print_quoted_apostrophes(char const * str)
+{
+    while (*str == APOSTROPHE) {
+        fputs(QUOT_APOS, stdout);
+        str++;
+    }
+    return str;
+}
+
+/**
+ *  Print a single quote (apostrophe quoted) string.
+ *  Other than somersaults for apostrophes, nothing else needs quoting.
+ *
+ *  @param[in] str  the string to print
  */
 static void
-putQuotedStr( tCC* pzStr )
+print_quot_str(char const * str)
 {
     /*
      *  Handle empty strings to make the rest of the logic simpler.
      */
-    if ((pzStr == NULL) || (*pzStr == NUL)) {
-        fputs( "''", stdout );
+    if ((str == NULL) || (*str == NUL)) {
+        fputs(EMPTY_ARG, stdout);
         return;
     }
 
@@ -53,48 +232,133 @@ putQuotedStr( tCC* pzStr )
      *  Emit any single quotes/apostrophes at the start of the string and
      *  bail if that is all we need to do.
      */
-    while (*pzStr == '\'') {
-        fputs( "\\'", stdout );
-        pzStr++;
-    }
-    if (*pzStr == NUL)
+    str = print_quoted_apostrophes(str);
+    if (*str == NUL)
         return;
 
     /*
      *  Start the single quote string
      */
-    fputc( '\'', stdout );
+    fputc(APOSTROPHE, stdout);
     for (;;) {
-        tCC* pz = strchr( pzStr, '\'' );
+        char const * pz = strchr(str, APOSTROPHE);
         if (pz == NULL)
             break;
 
         /*
          *  Emit the string up to the single quote (apostrophe) we just found.
          */
-        (void)fwrite( pzStr, (size_t)(pz - pzStr), (size_t)1, stdout );
-        fputc( '\'', stdout );
-        pzStr = pz;
+        (void)fwrite(str, (size_t)(pz - str), (size_t)1, stdout);
 
         /*
-         *  Emit an escaped apostrophe for every one we find.
-         *  If that ends the string, do not re-open the single quotes.
+         * Close the current string, emit the apostrophes and re-open the
+         * string (IFF there is more text to print).
          */
-        while (*++pzStr == '\'')   fputs( "\\'", stdout );
-        if (*pzStr == NUL)
+        fputc(APOSTROPHE, stdout);
+        str = print_quoted_apostrophes(pz);
+        if (*str == NUL)
             return;
 
-        fputc( '\'', stdout );
+        fputc(APOSTROPHE, stdout);
     }
 
     /*
      *  If we broke out of the loop, we must still emit the remaining text
      *  and then close the single quote string.
      */
-    fputs( pzStr, stdout );
-    fputc( '\'', stdout );
+    fputs(str, stdout);
+    fputc(APOSTROPHE, stdout);
 }
 
+static void
+print_enumeration(tOptions * pOpts, tOptDesc * pOD)
+{
+    uintptr_t e_val = pOD->optArg.argEnum;
+    printf(OPT_VAL_FMT, pOpts->pzPROGNAME, pOD->pz_NAME);
+
+    /*
+     *  Convert value to string, print that and restore numeric value.
+     */
+    (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
+    printf(QUOT_ARG_FMT, pOD->optArg.argString);
+    if (pOD->fOptState & OPTST_ALLOC_ARG)
+        AGFREE(pOD->optArg.argString);
+    pOD->optArg.argEnum = e_val;
+
+    printf(OPT_END_FMT, pOpts->pzPROGNAME, pOD->pz_NAME);
+}
+
+static void
+print_membership(tOptions * pOpts, tOptDesc * pOD)
+{
+    char const * svstr = pOD->optArg.argString;
+    char const * pz;
+    uintptr_t val = 1;
+    printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
+           (int)(uintptr_t)(pOD->optCookie));
+    pOD->optCookie = (void*)(uintptr_t)~0UL;
+    (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
+
+    pz = pOD->optArg.argString;
+    while (*pz != NUL) {
+        printf("readonly %s_", pOD->pz_NAME);
+        pz = SPN_PLUS_N_SPACE_CHARS(pz);
+
+        for (;;) {
+            int ch = *(pz++);
+            if (IS_LOWER_CASE_CHAR(ch))   fputc(toupper(ch), stdout);
+            else if (IS_UPPER_CASE_CHAR(ch))   fputc(ch, stdout);
+            else if (IS_PLUS_N_SPACE_CHAR(ch)) goto name_done;
+            else if (ch == NUL)        { pz--; goto name_done; }
+            else fputc('_', stdout);
+        } name_done:;
+        printf(SHOW_VAL_FMT, (unsigned long)val);
+        val <<= 1;
+    }
+
+    AGFREE(pOD->optArg.argString);
+    pOD->optArg.argString = svstr;
+}
+
+static void
+print_stacked_arg(tOptions * pOpts, tOptDesc * pOD)
+{
+    tArgList*       pAL = (tArgList*)pOD->optCookie;
+    char const **   ppz = pAL->apzArgs;
+    int             ct  = pAL->useCt;
+
+    printf(zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct);
+
+    while (--ct >= 0) {
+        printf(ARG_BY_NUM_FMT, pOpts->pzPROGNAME, pOD->pz_NAME,
+               pAL->useCt - ct);
+        print_quot_str(*(ppz++));
+        printf(EXPORT_ARG_FMT, pOpts->pzPROGNAME, pOD->pz_NAME,
+               pAL->useCt - ct);
+    }
+}
+
+/**
+ * emit the arguments as readily parsed text.
+ * The program options are set by emitting the shell "set" command.
+ *
+ * @param[in] opts  the program options structure
+ */
+static void
+print_reordering(tOptions * opts)
+{
+    unsigned int ix;
+
+    fputs(set_dash, stdout);
+
+    for (ix = opts->curOptIdx;
+         ix < opts->origArgCt;
+         ix++) {
+        fputc(' ', stdout);
+        print_quot_str(opts->origArgVect[ ix ]);
+    }
+    fputs(init_optct, stdout);
+}
 
 /*=export_func  optionPutShell
  * what:  write a portable shell script to parse options
@@ -104,23 +368,16 @@ putQuotedStr( tCC* pzStr )
  *        the options described in the option definitions.
 =*/
 void
-optionPutShell( tOptions* pOpts )
+optionPutShell(tOptions* pOpts)
 {
     int  optIx = 0;
-    tSCC zOptCtFmt[]  = "OPTION_CT=%d\nexport OPTION_CT\n";
-    tSCC zOptNumFmt[] = "%1$s_%2$s=%3$d # 0x%3$X\nexport %1$s_%2$s\n";
-    tSCC zOptDisabl[] = "%1$s_%2$s=%3$s\nexport %1$s_%2$s\n";
-    tSCC zOptValFmt[] = "%s_%s=";
-    tSCC zOptEnd[]    = "\nexport %s_%s\n";
-    tSCC zFullOptFmt[]= "%1$s_%2$s='%3$s'\nexport %1$s_%2$s\n";
-    tSCC zEquivMode[] = "%1$s_%2$s_MODE='%3$s'\nexport %1$s_%2$s_MODE\n";
 
-    printf( zOptCtFmt, pOpts->curOptIdx-1 );
+    printf(zOptCtFmt, pOpts->curOptIdx-1);
 
     do  {
         tOptDesc* pOD = pOpts->pOptDesc + optIx;
 
-        if (SKIP_OPT(pOD))
+        if ((pOD->fOptState & OPTST_NO_OUTPUT_MASK) != 0)
             continue;
 
         /*
@@ -143,7 +400,7 @@ optionPutShell( tOptions* pOpts )
             p->optArg     = pOD->optArg;
             p->fOptState &= OPTST_PERSISTENT_MASK;
             p->fOptState |= pOD->fOptState & ~OPTST_PERSISTENT_MASK;
-            printf( zEquivMode, pOpts->pzPROGNAME, pOD->pz_NAME, p->pz_NAME );
+            printf(zEquivMode, pOpts->pzPROGNAME, pOD->pz_NAME, p->pz_NAME);
             pOD = p;
         }
 
@@ -153,37 +410,7 @@ optionPutShell( tOptions* pOpts )
          *  of bitmask value and we need to emit the bit values.
          */
         if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) {
-            char const * pz;
-            uintptr_t val = 1;
-            printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
-                    (int)(uintptr_t)(pOD->optCookie) );
-            pOD->optCookie = (void*)(uintptr_t)~0UL;
-            (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
-
-            /*
-             *  We are building the typeset list.  The list returned starts with
-             *  'none + ' for use by option saving stuff.  We must ignore that.
-             */
-            pz = pOD->optArg.argString + 7;
-            while (*pz != NUL) {
-                printf( "typeset -x -i %s_", pOD->pz_NAME );
-                while (IS_PLUS_N_SPACE_CHAR(*pz))  pz++;
-
-                for (;;) {
-                  int ch = *(pz++);
-                       if (IS_LOWER_CASE_CHAR(ch))   fputc(toupper(ch), stdout);
-                  else if (IS_UPPER_CASE_CHAR(ch))   fputc(ch, stdout);
-                  else if (IS_PLUS_N_SPACE_CHAR(ch)) goto name_done;
-                  else if (ch == NUL)        { pz--; goto name_done; }
-                  else fputc( '_', stdout );
-                } name_done:;
-                printf( "=%1$lu # 0x%1$lX\n", (unsigned long)val );
-                val <<= 1;
-            }
-
-            AGFREE(pOD->optArg.argString);
-            pOD->optArg.argString = NULL;
-            pOD->fOptState &= ~OPTST_ALLOC_ARG;
+            print_membership(pOpts, pOD);
             continue;
         }
 
@@ -193,7 +420,7 @@ optionPutShell( tOptions* pOpts )
          *  The idea is that if someone defines an option to initialize
          *  enabled, we should tell our shell script that it is enabled.
          */
-        if (UNUSED_OPT( pOD ) && DISABLED_OPT( pOD ))
+        if (UNUSED_OPT(pOD) && DISABLED_OPT(pOD))
             continue;
 
         /*
@@ -201,117 +428,81 @@ optionPutShell( tOptions* pOpts )
          */
         if (  (pOD->fOptState & OPTST_STACKED)
            && (pOD->optCookie != NULL) )  {
-            tSCC zOptCookieCt[] = "%1$s_%2$s_CT=%3$d\nexport %1$s_%2$s_CT\n";
-
-            tArgList*    pAL = (tArgList*)pOD->optCookie;
-            tCC**        ppz = pAL->apzArgs;
-            int          ct  = pAL->useCt;
-
-            printf( zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct );
-
-            while (--ct >= 0) {
-                tSCC numarg_z[] = "%s_%s_%d=";
-                tSCC end_z[]    = "\nexport %s_%s_%d\n";
-
-                printf( numarg_z, pOpts->pzPROGNAME, pOD->pz_NAME,
-                        pAL->useCt - ct );
-                putQuotedStr( *(ppz++) );
-                printf( end_z, pOpts->pzPROGNAME, pOD->pz_NAME,
-                        pAL->useCt - ct );
-            }
+            print_stacked_arg(pOpts, pOD);
+            continue;
         }
 
         /*
          *  If the argument has been disabled,
          *  Then set its value to the disablement string
          */
-        else if ((pOD->fOptState & OPTST_DISABLED) != 0)
-            printf( zOptDisabl, pOpts->pzPROGNAME, pOD->pz_NAME,
-                    (pOD->pz_DisablePfx != NULL)
-                    ? pOD->pz_DisablePfx : "false" );
+        if ((pOD->fOptState & OPTST_DISABLED) != 0) {
+            printf(zOptDisabl, pOpts->pzPROGNAME, pOD->pz_NAME,
+                   (pOD->pz_DisablePfx != NULL)
+                   ? pOD->pz_DisablePfx : "false");
+            continue;
+        }
 
         /*
          *  If the argument type is numeric, the last arg pointer
          *  is really the VALUE of the string that was pointed to.
          */
-        else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC)
-            printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
-                    (int)pOD->optArg.argInt );
+        if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC) {
+            printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
+                   (int)pOD->optArg.argInt);
+            continue;
+        }
 
         /*
          *  If the argument type is an enumeration, then it is much
          *  like a text value, except we call the callback function
          *  to emit the value corresponding to the "optArg" number.
          */
-        else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_ENUMERATION) {
-            uintptr_t e_val = pOD->optArg.argEnum;
-            printf( zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME );
-
-            /*
-             *  Convert value to string, print that and restore numeric value.
-             */
-            (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
-            printf("'%s'", pOD->optArg.argString);
-            if (pOD->fOptState & OPTST_ALLOC_ARG)
-                AGFREE(pOD->optArg.argString);
-            pOD->optArg.argEnum = e_val;
-
-            printf(zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME);
+        if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_ENUMERATION) {
+            print_enumeration(pOpts, pOD);
+            continue;
         }
 
         /*
          *  If the argument type is numeric, the last arg pointer
          *  is really the VALUE of the string that was pointed to.
          */
-        else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_BOOLEAN)
-            printf( zFullOptFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
-                    (pOD->optArg.argBool == 0) ? "false" : "true" );
+        if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_BOOLEAN) {
+            printf(zFullOptFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
+                   (pOD->optArg.argBool == 0) ? "false" : "true");
+            continue;
+        }
 
         /*
          *  IF the option has an empty value,
          *  THEN we set the argument to the occurrence count.
          */
-        else if (  (pOD->optArg.argString == NULL)
-                || (pOD->optArg.argString[0] == NUL) )
+        if (  (pOD->optArg.argString == NULL)
+           || (pOD->optArg.argString[0] == NUL) ) {
 
-            printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
-                    pOD->optOccCt );
+            printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
+                   pOD->optOccCt);
+            continue;
+        }
 
         /*
          *  This option has a text value
          */
-        else {
-            printf( zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME );
-            putQuotedStr( pOD->optArg.argString );
-            printf( zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME );
-        }
+        printf(OPT_VAL_FMT, pOpts->pzPROGNAME, pOD->pz_NAME);
+        print_quot_str(pOD->optArg.argString);
+        printf(OPT_END_FMT, pOpts->pzPROGNAME, pOD->pz_NAME);
+
     } while (++optIx < pOpts->presetOptCt );
 
     if (  ((pOpts->fOptSet & OPTPROC_REORDER) != 0)
-       && (pOpts->curOptIdx < pOpts->origArgCt)) {
-        fputs( "set --", stdout );
-        for (optIx = pOpts->curOptIdx; optIx < pOpts->origArgCt; optIx++) {
-            char* pzArg = pOpts->origArgVect[ optIx ];
-            if (strchr( pzArg, '\'' ) == NULL)
-                printf( " '%s'", pzArg );
-            else {
-                fputs( " '", stdout );
-                for (;;) {
-                    char ch = *(pzArg++);
-                    switch (ch) {
-                    case '\'':  fputs( "'\\''", stdout ); break;
-                    case NUL:   goto arg_done;
-                    default:    fputc( ch, stdout ); break;
-                    }
-                } arg_done:;
-                fputc( '\'', stdout );
-            }
-        }
-        fputs( "\nOPTION_CT=0\n", stdout );
-    }
+       && (pOpts->curOptIdx < pOpts->origArgCt))
+        print_reordering(pOpts);
+
+    fflush(stdout);
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 34 - 21
libopts/reset.c

@@ -1,11 +1,16 @@
 
-/*
- *  $Id: reset.c,v 4.7 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2008-08-02 12:25:18 bkorb"
+/**
+ * \file reset.c
+ *
+ *  Reset the option state to the compiled state.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -17,11 +22,11 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 static void
@@ -66,47 +71,54 @@ optionResetEverything(tOptions * pOpts)
  *  For example, --reset=foo will cause the --foo option to be reset.
 =*/
 void
-optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
+optionResetOpt(tOptions * pOpts, tOptDesc * pOD)
 {
-    static ag_bool reset_active = AG_FALSE;
+    static bool reset_active = false;
 
     tOptState opt_state = OPTSTATE_INITIALIZER(DEFINED);
     char const * pzArg = pOD->optArg.argString;
     tSuccess     succ;
 
+    if (pOpts <= OPTPROC_EMIT_LIMIT)
+        return;
+
     if (reset_active)
         return;
 
     if (  (! HAS_originalOptArgArray(pOpts))
-       || (pOpts->originalOptArgCookie == NULL)) {
-        fputs(zResetNotConfig, stderr);
-        _exit(EX_SOFTWARE);
-    }
+       || (pOpts->originalOptArgCookie == NULL))
+        ao_bug(zno_reset);
 
     if ((pzArg == NULL) || (*pzArg == NUL)) {
-        fputs(zNoResetArg, stderr);
+        fprintf(stderr, zreset_arg, pOpts->pzProgName, pOD->pz_Name);
         pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+        /* NOTREACHED */
+        assert(0 == 1);
     }
 
-    reset_active = AG_TRUE;
+    reset_active = true;
 
     if (pzArg[1] == NUL) {
         if (*pzArg == '*') {
             optionResetEverything(pOpts);
-            reset_active = AG_FALSE;
+            reset_active = false;
             return;
         }
 
-        succ = shortOptionFind(pOpts, (tAoUC)*pzArg, &opt_state);
+        succ = opt_find_short(pOpts, (uint8_t)*pzArg, &opt_state);
         if (! SUCCESSFUL(succ)) {
             fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg);
             pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+            /* NOTREACHED */
+            assert(0 == 1);
         }
     } else {
-        succ = longOptionFind(pOpts, (char *)pzArg, &opt_state);
+        succ = opt_find_long(pOpts, (char *)pzArg, &opt_state);
         if (! SUCCESSFUL(succ)) {
             fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg);
             pOpts->pUsageProc(pOpts, EXIT_FAILURE);
+            /* NOTREACHED */
+            assert(0 == 1);
         }
     }
 
@@ -117,9 +129,10 @@ optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
      *  Finally, clear the reset flag, too.
      */
     optionReset(pOpts, opt_state.pOD);
-    reset_active = AG_FALSE;
+    reset_active = false;
 }
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 31 - 35
libopts/restore.c

@@ -1,15 +1,18 @@
 
 /*
- *  restore.c  $Id: restore.c,v 4.14 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2007-07-04 11:34:40 bkorb"
+ * \file restore.c
  *
  *  This module's routines will save the current option state to memory
  *  and restore it.  If saved prior to the initial optionProcess call,
  *  then the initial state will be restored.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,11 +24,11 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /*
@@ -91,29 +94,20 @@ fixupSavedOptionArgs(tOptions* pOpts)
  *        Otherwise, it will always succeed.
 =*/
 void
-optionSaveState(tOptions* pOpts)
+optionSaveState(tOptions * pOpts)
 {
-    tOptions* p = (tOptions*)pOpts->pSavedState;
+    tOptions * p = (tOptions*)pOpts->pSavedState;
 
     if (p == NULL) {
-        size_t sz = sizeof( *pOpts ) + (pOpts->optCt * sizeof( tOptDesc ));
-        p = AGALOC( sz, "saved option state" );
-        if (p == NULL) {
-            tCC* pzName = pOpts->pzProgName;
-            if (pzName == NULL) {
-                pzName = pOpts->pzPROGNAME;
-                if (pzName == NULL)
-                    pzName = zNil;
-            }
-            fprintf( stderr, zCantSave, pzName, sz );
-            exit( EXIT_FAILURE );
-        }
+        size_t sz = sizeof(*pOpts)
+            + ((size_t)pOpts->optCt * sizeof(tOptDesc));
+        p = AGALOC(sz, "saved option state");
 
         pOpts->pSavedState = p;
     }
 
-    memcpy( p, pOpts, sizeof( *p ));
-    memcpy( p + 1, pOpts->pOptDesc, p->optCt * sizeof( tOptDesc ));
+    memcpy(p, pOpts, sizeof(*p));
+    memcpy(p + 1, pOpts->pOptDesc, (size_t)p->optCt * sizeof(tOptDesc));
 
     fixupSavedOptionArgs(pOpts);
 }
@@ -135,26 +129,26 @@ optionSaveState(tOptions* pOpts)
  *       printed to @code{stderr} and exit is called.
 =*/
 void
-optionRestore( tOptions* pOpts )
+optionRestore(tOptions* pOpts)
 {
     tOptions* p = (tOptions*)pOpts->pSavedState;
 
     if (p == NULL) {
-        tCC* pzName = pOpts->pzProgName;
+        char const * pzName = pOpts->pzProgName;
         if (pzName == NULL) {
             pzName = pOpts->pzPROGNAME;
             if (pzName == NULL)
                 pzName = zNil;
         }
-        fprintf( stderr, zNoState, pzName );
-        exit( EXIT_FAILURE );
+        fprintf(stderr, zNoState, pzName);
+        option_exits(EXIT_FAILURE);
     }
 
     pOpts->pSavedState = NULL;
     optionFree(pOpts);
 
-    memcpy( pOpts, p, sizeof( *p ));
-    memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc ));
+    memcpy(pOpts, p, sizeof(*p));
+    memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc));
     pOpts->pSavedState = p;
 
     fixupSavedOptionArgs(pOpts);
@@ -174,7 +168,7 @@ optionRestore( tOptions* pOpts )
  *        this routine is always successful.
 =*/
 void
-optionFree( tOptions* pOpts )
+optionFree(tOptions* pOpts)
 {
  free_saved_state:
     {
@@ -202,7 +196,7 @@ optionFree( tOptions* pOpts )
 
             case OPARG_TYPE_HIERARCHY:
                 if (p->optCookie != NULL)
-                    unloadNestedArglist(p->optCookie);
+                    unload_arg_list(p->optCookie);
                 break;
             }
 
@@ -211,14 +205,16 @@ optionFree( tOptions* pOpts )
     }
     if (pOpts->pSavedState != NULL) {
         tOptions * p = (tOptions*)pOpts->pSavedState;
-        memcpy( pOpts, p, sizeof( *p ));
-        memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc ));
-        AGFREE( pOpts->pSavedState );
+        memcpy(pOpts, p, sizeof(*p));
+        memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc));
+        AGFREE(pOpts->pSavedState);
         pOpts->pSavedState = NULL;
         goto free_saved_state;
     }
 }
-/*
+
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 261 - 243
libopts/save.c

@@ -1,15 +1,18 @@
 
 /*
- *  save.c  $Id: save.c,v 4.36 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2009-07-20 20:40:28 bkorb"
+ * \file save.c
  *
  *  This module's routines will take the currently set options and
  *  store them into an ".rc" file for re-interpretation the next
  *  time the invoking program is run.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,71 +24,66 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
-static char const  zWarn[] = "%s WARNING:  cannot save options - ";
-static char const close_xml[] = "</%s>\n";
-
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static tCC*
-findDirName( tOptions* pOpts, int* p_free );
+static char const *
+find_dir_name(tOptions * opts, int * p_free);
 
-static tCC*
-findFileName( tOptions* pOpts, int* p_free_name );
+static char const *
+find_file_name(tOptions * opts, int * p_free_name);
 
 static void
-printEntry(
-    FILE *     fp,
-    tOptDesc * p,
-    tCC*       pzLA );
+prt_entry(FILE * fp, tOptDesc * od, char const * l_arg);
 
 static void
-print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp);
+prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp);
 
 static void
-print_a_string(FILE * fp, char const * name, char const * pz);
+prt_string(FILE * fp, char const * name, char const * pz);
 
 static void
-printValueList(FILE * fp, char const * name, tArgList * al);
+prt_val_list(FILE * fp, char const * name, tArgList * al);
 
 static void
-printHierarchy(FILE * fp, tOptDesc * p);
+prt_nested(FILE * fp, tOptDesc * p);
 
 static FILE *
-openSaveFile( tOptions* pOpts );
+open_sv_file(tOptions * opts);
 
 static void
-printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD);
+prt_no_arg_opt(FILE * fp, tOptDesc * p, tOptDesc * pOD);
 
 static void
-printStringArg(FILE * fp, tOptDesc * pOD);
+prt_str_arg(FILE * fp, tOptDesc * pOD);
 
 static void
-printEnumArg(FILE * fp, tOptDesc * pOD);
+prt_enum_arg(FILE * fp, tOptDesc * od);
 
 static void
-printSetMemberArg(FILE * fp, tOptDesc * pOD);
+prt_set_arg(FILE * fp, tOptDesc * od);
 
 static void
-printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts);
+prt_file_arg(FILE * fp, tOptDesc * od, tOptions * opts);
 /* = = = END-STATIC-FORWARD = = = */
 
-static tCC*
-findDirName( tOptions* pOpts, int* p_free )
+/**
+ */
+static char const *
+find_dir_name(tOptions * opts, int * p_free)
 {
-    tCC*  pzDir;
+    char const * pzDir;
 
-    if (  (pOpts->specOptIdx.save_opts == NO_EQUIVALENT)
-       || (pOpts->specOptIdx.save_opts == 0))
+    if (  (opts->specOptIdx.save_opts == NO_EQUIVALENT)
+       || (opts->specOptIdx.save_opts == 0))
         return NULL;
 
-    pzDir = pOpts->pOptDesc[ pOpts->specOptIdx.save_opts ].optArg.argString;
+    pzDir = opts->pOptDesc[ opts->specOptIdx.save_opts ].optArg.argString;
     if ((pzDir != NULL) && (*pzDir != NUL))
         return pzDir;
 
@@ -94,7 +92,7 @@ findDirName( tOptions* pOpts, int* p_free )
      *  we can stash the RC (INI) file.
      */
     {
-        tCC* const* papz = pOpts->papzHomeList;
+        char const * const* papz = opts->papzHomeList;
         if (papz == NULL)
             return NULL;
 
@@ -109,29 +107,29 @@ findDirName( tOptions* pOpts, int* p_free )
         return pzDir;
 
     {
-        tCC*  pzEndDir = strchr( ++pzDir, DIRCH );
-        char* pzFileName;
-        char* pzEnv;
+        char const * pzEndDir = strchr(++pzDir, DIRCH);
+        char * pzFileName;
+        char * pzEnv;
 
         if (pzEndDir != NULL) {
             char z[ AO_NAME_SIZE ];
             if ((pzEndDir - pzDir) > AO_NAME_LIMIT )
                 return NULL;
-            strncpy( z, pzDir, (size_t)(pzEndDir - pzDir) );
-            z[ (pzEndDir - pzDir) ] = NUL;
-            pzEnv = getenv( z );
+            memcpy(z, pzDir, (size_t)(pzEndDir - pzDir));
+            z[pzEndDir - pzDir] = NUL;
+            pzEnv = getenv(z);
         } else {
 
             /*
              *  Make sure we can get the env value (after stripping off
              *  any trailing directory or file names)
              */
-            pzEnv = getenv( pzDir );
+            pzEnv = getenv(pzDir);
         }
 
         if (pzEnv == NULL) {
-            fprintf( stderr, zWarn, pOpts->pzProgName );
-            fprintf( stderr, zNotDef, pzDir );
+            fprintf(stderr, zsave_warn, opts->pzProgName);
+            fprintf(stderr, zNotDef, pzDir);
             return NULL;
         }
 
@@ -139,8 +137,8 @@ findDirName( tOptions* pOpts, int* p_free )
             return pzEnv;
 
         {
-            size_t sz = strlen( pzEnv ) + strlen( pzEndDir ) + 2;
-            pzFileName = (char*)AGALOC( sz, "dir name" );
+            size_t sz = strlen(pzEnv) + strlen(pzEndDir) + 2;
+            pzFileName = (char *)AGALOC(sz, "dir name");
         }
 
         if (pzFileName == NULL)
@@ -151,20 +149,20 @@ findDirName( tOptions* pOpts, int* p_free )
          *  Glue together the full name into the allocated memory.
          *  FIXME: We lose track of this memory.
          */
-        sprintf( pzFileName, "%s/%s", pzEnv, pzEndDir );
+        sprintf(pzFileName, "%s/%s", pzEnv, pzEndDir);
         return pzFileName;
     }
 }
 
-
-static tCC*
-findFileName( tOptions* pOpts, int* p_free_name )
+/**
+ */
+static char const *
+find_file_name(tOptions * opts, int * p_free_name)
 {
-    tCC*   pzDir;
     struct stat stBuf;
     int    free_dir_name = 0;
 
-    pzDir = findDirName( pOpts, &free_dir_name );
+    char const * pzDir = find_dir_name(opts, &free_dir_name);
     if (pzDir == NULL)
         return NULL;
 
@@ -172,66 +170,60 @@ findFileName( tOptions* pOpts, int* p_free_name )
      *  See if we can find the specified directory.  We use a once-only loop
      *  structure so we can bail out early.
      */
-    if (stat( pzDir, &stBuf ) != 0) do {
+    if (stat(pzDir, &stBuf) != 0) do {
+        char z[AG_PATH_MAX];
+        char * dirchp;
 
         /*
          *  IF we could not, check to see if we got a full
          *  path to a file name that has not been created yet.
          */
-        if (errno == ENOENT) {
-            char z[AG_PATH_MAX];
-
-            /*
-             *  Strip off the last component, stat the remaining string and
-             *  that string must name a directory
-             */
-            char* pzDirCh = strrchr( pzDir, DIRCH );
-            if (pzDirCh == NULL) {
-                stBuf.st_mode = S_IFREG;
-                continue;  /* bail out of error condition */
-            }
-
-            strncpy( z, pzDir, (size_t)(pzDirCh - pzDir));
-            z[ pzDirCh - pzDir ] = NUL;
-
-            if (  (stat( z, &stBuf ) == 0)
-               && S_ISDIR( stBuf.st_mode )) {
-
-                /*
-                 *  We found the directory.  Restore the file name and
-                 *  mark the full name as a regular file
-                 */
-                stBuf.st_mode = S_IFREG;
-                continue;  /* bail out of error condition */
-            }
+        if (errno != ENOENT) {
+        bogus_name:
+            fprintf(stderr, zsave_warn, opts->pzProgName);
+            fprintf(stderr, zNoStat, errno, strerror(errno), pzDir);
+            if (free_dir_name)
+                AGFREE((void*)pzDir);
+            return NULL;
         }
 
         /*
-         *  We got a bogus name.
+         *  Strip off the last component, stat the remaining string and
+         *  that string must name a directory
          */
-        fprintf( stderr, zWarn, pOpts->pzProgName );
-        fprintf( stderr, zNoStat, errno, strerror( errno ), pzDir );
-        if (free_dir_name)
-            AGFREE( (void*)pzDir );
-        return NULL;
-    } while (0);
+        dirchp = strrchr(pzDir, DIRCH);
+        if (dirchp == NULL) {
+            stBuf.st_mode = S_IFREG;
+            break; /* found directory -- viz.,  "." */
+        }
+
+        if ((size_t)(dirchp - pzDir) >= sizeof(z))
+            goto bogus_name;
+
+        memcpy(z, pzDir, (size_t)(dirchp - pzDir));
+        z[dirchp - pzDir] = NUL;
+
+        if ((stat(z, &stBuf) != 0) || ! S_ISDIR(stBuf.st_mode))
+            goto bogus_name;
+        stBuf.st_mode = S_IFREG; /* file within this directory */
+    } while (false);
 
     /*
      *  IF what we found was a directory,
      *  THEN tack on the config file name
      */
-    if (S_ISDIR( stBuf.st_mode )) {
-        size_t sz = strlen( pzDir ) + strlen( pOpts->pzRcName ) + 2;
+    if (S_ISDIR(stBuf.st_mode)) {
+        size_t sz = strlen(pzDir) + strlen(opts->pzRcName) + 2;
 
         {
-            char*  pzPath = (char*)AGALOC( sz, "file name" );
+            char * pzPath = (char*)AGALOC(sz, "file name");
 #ifdef HAVE_SNPRINTF
-            snprintf( pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName );
+            snprintf(pzPath, sz, "%s/%s", pzDir, opts->pzRcName);
 #else
-            sprintf( pzPath, "%s/%s", pzDir, pOpts->pzRcName );
+            sprintf(pzPath, "%s/%s", pzDir, opts->pzRcName);
 #endif
             if (free_dir_name)
-                AGFREE( (void*)pzDir );
+                AGFREE((void*)pzDir);
             pzDir = pzPath;
             free_dir_name = 1;
         }
@@ -240,12 +232,12 @@ findFileName( tOptions* pOpts, int* p_free_name )
          *  IF we cannot stat the object for any reason other than
          *     it does not exist, then we bail out
          */
-        if (stat( pzDir, &stBuf ) != 0) {
+        if (stat(pzDir, &stBuf) != 0) {
             if (errno != ENOENT) {
-                fprintf( stderr, zWarn, pOpts->pzProgName );
-                fprintf( stderr, zNoStat, errno, strerror( errno ),
-                         pzDir );
-                AGFREE( (void*)pzDir );
+                fprintf(stderr, zsave_warn, opts->pzProgName);
+                fprintf(stderr, zNoStat, errno, strerror(errno),
+                        pzDir);
+                AGFREE((void*)pzDir);
                 return NULL;
             }
 
@@ -260,29 +252,33 @@ findFileName( tOptions* pOpts, int* p_free_name )
      *  Make sure that whatever we ultimately found, that it either is
      *  or will soon be a file.
      */
-    if (! S_ISREG( stBuf.st_mode )) {
-        fprintf( stderr, zWarn, pOpts->pzProgName );
-        fprintf( stderr, zNotFile, pzDir );
+    if (! S_ISREG(stBuf.st_mode)) {
+        fprintf(stderr, zsave_warn, opts->pzProgName, pzDir);
         if (free_dir_name)
-            AGFREE( (void*)pzDir );
+            AGFREE((void*)pzDir);
         return NULL;
     }
 
     /*
      *  Get rid of the old file
      */
-    unlink( pzDir );
+    unlink(pzDir);
     *p_free_name = free_dir_name;
     return pzDir;
 }
 
-
+/**
+ * print one option entry to the save file.
+ *
+ * @param[in] fp    the file pointer for the save file
+ * @param[in] od    the option descriptor to print
+ * @param[in] l_arg the last argument for the option
+ */
 static void
-printEntry(
-    FILE *     fp,
-    tOptDesc * p,
-    tCC*       pzLA )
+prt_entry(FILE * fp, tOptDesc * od, char const * l_arg)
 {
+    int space_ct;
+
     /*
      *  There is an argument.  Pad the name so values line up.
      *  Not disabled *OR* this got equivalenced to another opt,
@@ -290,86 +286,84 @@ printEntry(
      *  Otherwise, there must be a disablement name.
      */
     {
-        char const * pz;
-        if (! DISABLED_OPT(p) || (p->optEquivIndex != NO_EQUIVALENT))
-            pz = p->pz_Name;
-        else
-            pz = p->pz_DisableName;
-
-        fprintf(fp, "%-18s", pz);
+        char const * pz =
+            (! DISABLED_OPT(od) || (od->optEquivIndex != NO_EQUIVALENT))
+            ? od->pz_Name
+            : od->pz_DisableName;
+        space_ct = 17 - strlen(pz);
+        fputs(pz, fp);
     }
+
+    if (  (l_arg == NULL)
+       && (OPTST_GET_ARGTYPE(od->fOptState) != OPARG_TYPE_NUMERIC))
+        goto end_entry;
+
+    fputs(" = ", fp);
+    while (space_ct-- > 0)  fputc(' ', fp);
+
     /*
      *  IF the option is numeric only,
      *  THEN the char pointer is really the number
      */
-    if (OPTST_GET_ARGTYPE(p->fOptState) == OPARG_TYPE_NUMERIC)
-        fprintf( fp, "  %d\n", (int)(t_word)pzLA );
-
-    /*
-     *  OTHERWISE, FOR each line of the value text, ...
-     */
-    else if (pzLA == NULL)
-        fputc( '\n', fp );
+    if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NUMERIC)
+        fprintf(fp, "%d", (int)(t_word)l_arg);
 
     else {
-        fputc( ' ', fp ); fputc( ' ', fp );
         for (;;) {
-            tCC* pzNl = strchr( pzLA, '\n' );
+            char const * eol = strchr(l_arg, NL);
 
             /*
              *  IF this is the last line
              *  THEN bail and print it
              */
-            if (pzNl == NULL)
+            if (eol == NULL)
                 break;
 
             /*
              *  Print the continuation and the text from the current line
              */
-            (void)fwrite( pzLA, (size_t)(pzNl - pzLA), (size_t)1, fp );
-            pzLA = pzNl+1; /* advance the Last Arg pointer */
-            fputs( "\\\n", fp );
+            (void)fwrite(l_arg, (size_t)(eol - l_arg), (size_t)1, fp);
+            l_arg = eol+1; /* advance the Last Arg pointer */
+            fputs("\\\n", fp);
         }
 
         /*
          *  Terminate the entry
          */
-        fputs( pzLA, fp );
-        fputc( '\n', fp );
+        fputs(l_arg, fp);
     }
-}
 
+end_entry:
+    fputc(NL, fp);
+}
 
+/**
+ */
 static void
-print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp)
+prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp)
 {
-    static char const bool_atr[]  = "<%1$s type=boolean>%2$s</%1$s>\n";
-    static char const numb_atr[]  = "<%1$s type=integer>0x%2$lX</%1$s>\n";
-    static char const type_atr[]  = "<%s type=%s>";
-    static char const null_atr[]  = "<%s/>\n";
-
     while (--depth >= 0)
         putc(' ', fp), putc(' ', fp);
 
     switch (ovp->valType) {
     default:
     case OPARG_TYPE_NONE:
-        fprintf(fp, null_atr, ovp->pzName);
+        fprintf(fp, NULL_ATR_FMT, ovp->pzName);
         break;
 
     case OPARG_TYPE_STRING:
-        print_a_string(fp, ovp->pzName, ovp->v.strVal);
+        prt_string(fp, ovp->pzName, ovp->v.strVal);
         break;
 
     case OPARG_TYPE_ENUMERATION:
     case OPARG_TYPE_MEMBERSHIP:
         if (pOD != NULL) {
-            tAoUI     opt_state = pOD->fOptState;
+            uint32_t  opt_state = pOD->fOptState;
             uintptr_t val = pOD->optArg.argEnum;
             char const * typ = (ovp->valType == OPARG_TYPE_ENUMERATION)
                 ? "keyword" : "set-membership";
 
-            fprintf(fp, type_atr, ovp->pzName, typ);
+            fprintf(fp, TYPE_ATR_FMT, ovp->pzName, typ);
 
             /*
              *  This is a magic incantation that will convert the
@@ -383,39 +377,38 @@ print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp)
                     /*
                      *  set membership strings get allocated
                      */
-                    AGFREE( (void*)pOD->optArg.argString );
+                    AGFREE((void*)pOD->optArg.argString);
                 }
             }
 
             pOD->optArg.argEnum = val;
             pOD->fOptState = opt_state;
-            fprintf(fp, close_xml, ovp->pzName);
+            fprintf(fp, END_XML_FMT, ovp->pzName);
             break;
         }
         /* FALLTHROUGH */
 
     case OPARG_TYPE_NUMERIC:
-        fprintf(fp, numb_atr, ovp->pzName, ovp->v.longVal);
+        fprintf(fp, NUMB_ATR_FMT, ovp->pzName, ovp->v.longVal);
         break;
 
     case OPARG_TYPE_BOOLEAN:
-        fprintf(fp, bool_atr, ovp->pzName,
+        fprintf(fp, BOOL_ATR_FMT, ovp->pzName,
                 ovp->v.boolVal ? "true" : "false");
         break;
 
     case OPARG_TYPE_HIERARCHY:
-        printValueList(fp, ovp->pzName, ovp->v.nestVal);
+        prt_val_list(fp, ovp->pzName, ovp->v.nestVal);
         break;
     }
 }
 
-
+/**
+ */
 static void
-print_a_string(FILE * fp, char const * name, char const * pz)
+prt_string(FILE * fp, char const * name, char const * pz)
 {
-    static char const open_atr[]  = "<%s>";
-
-    fprintf(fp, open_atr, name);
+    fprintf(fp, OPEN_XML_FMT, name);
     for (;;) {
         int ch = ((int)*(pz++)) & 0xFF;
 
@@ -443,12 +436,13 @@ print_a_string(FILE * fp, char const * name, char const * pz)
             putc(ch, fp);
         }
     } string_done:;
-    fprintf(fp, close_xml, name);
+    fprintf(fp, END_XML_FMT, name);
 }
 
-
+/**
+ */
 static void
-printValueList(FILE * fp, char const * name, tArgList * al)
+prt_val_list(FILE * fp, char const * name, tArgList * al)
 {
     static int depth = 1;
 
@@ -462,17 +456,17 @@ printValueList(FILE * fp, char const * name, tArgList * al)
     opt_list = (void **)al->apzArgs;
 
     if (opt_ct <= 0) {
-        fprintf(fp, "<%s/>\n", name);
+        fprintf(fp, OPEN_CLOSE_FMT, name);
         return;
     }
 
-    fprintf(fp, "<%s type=nested>\n", name);
+    fprintf(fp, NESTED_OPT_FMT, name);
 
     depth++;
     while (--opt_ct >= 0) {
         tOptionValue const * ovp = *(opt_list++);
 
-        print_a_value(fp, depth, NULL, ovp);
+        prt_value(fp, depth, NULL, ovp);
     }
     depth--;
 
@@ -481,9 +475,10 @@ printValueList(FILE * fp, char const * name, tArgList * al)
     fprintf(fp, "</%s>\n", name);
 }
 
-
+/**
+ */
 static void
-printHierarchy(FILE * fp, tOptDesc * p)
+prt_nested(FILE * fp, tOptDesc * p)
 {
     int opt_ct;
     tArgList * al = p->optCookie;
@@ -505,10 +500,10 @@ printHierarchy(FILE * fp, tOptDesc * p)
         if (ovp == NULL)
             continue;
 
-        fprintf(fp, "<%s type=nested>\n", p->pz_Name);
+        fprintf(fp, NESTED_OPT_FMT, p->pz_Name);
 
         do  {
-            print_a_value(fp, 1, p, ovp);
+            prt_value(fp, 1, p, ovp);
 
         } while (ovp = optionNextValue(base, ovp),
                  ovp != NULL);
@@ -517,57 +512,65 @@ printHierarchy(FILE * fp, tOptDesc * p)
     } while (--opt_ct > 0);
 }
 
-
+/**
+ * open the file for saving option state.
+ *
+ * @param[in] opts  the program options structure
+ * @returns the open file pointer.  It may be NULL.
+ */
 static FILE *
-openSaveFile( tOptions* pOpts )
+open_sv_file(tOptions * opts)
 {
-    FILE*     fp;
+    FILE * fp;
 
     {
         int   free_name = 0;
-        tCC*  pzFName = findFileName( pOpts, &free_name );
+        char const * pzFName = find_file_name(opts, &free_name);
         if (pzFName == NULL)
             return NULL;
 
-        fp = fopen( pzFName, "w" FOPEN_BINARY_FLAG );
+        fp = fopen(pzFName, "w" FOPEN_BINARY_FLAG);
         if (fp == NULL) {
-            fprintf( stderr, zWarn, pOpts->pzProgName );
-            fprintf( stderr, zNoCreat, errno, strerror( errno ), pzFName );
+            fprintf(stderr, zsave_warn, opts->pzProgName);
+            fprintf(stderr, zNoCreat, errno, strerror(errno), pzFName);
             if (free_name)
                 AGFREE((void*) pzFName );
             return fp;
         }
 
         if (free_name)
-            AGFREE( (void*)pzFName );
+            AGFREE((void*)pzFName);
     }
 
+    fputs("#  ", fp);
     {
-        char const*  pz = pOpts->pzUsageTitle;
-        fputs( "#  ", fp );
-        do { fputc( *pz, fp ); } while (*(pz++) != '\n');
+        char const * e = strchr(opts->pzUsageTitle, NL);
+        if (e++ != NULL)
+            fwrite(opts->pzUsageTitle, 1, e - opts->pzUsageTitle, fp);
     }
 
     {
-        time_t  timeVal = time( NULL );
-        char*   pzTime  = ctime( &timeVal );
+        time_t  cur_time = time(NULL);
+        char *  time_str = ctime(&cur_time);
 
-        fprintf( fp, zPresetFile, pzTime );
+        fprintf(fp, zPresetFile, time_str);
 #ifdef HAVE_ALLOCATED_CTIME
         /*
          *  The return values for ctime(), localtime(), and gmtime()
          *  normally point to static data that is overwritten by each call.
          *  The test to detect allocated ctime, so we leak the memory.
          */
-        AGFREE( (void*)pzTime );
+        AGFREE((void*)time_str);
 #endif
     }
 
     return fp;
 }
 
+/**
+ */
 static void
-printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
+prt_no_arg_opt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
 {
     /*
      * The aliased to argument indicates whether or not the option
@@ -575,7 +578,7 @@ printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
      * string, so we get that there, not with "p".
      */
     char const * pznm =
-        (DISABLED_OPT( p )) ? pOD->pz_DisableName : pOD->pz_Name;
+        (DISABLED_OPT(p)) ? pOD->pz_DisableName : pOD->pz_Name;
     /*
      *  If the option was disabled and the disablement name is NULL,
      *  then the disablement was caused by aliasing.
@@ -587,13 +590,15 @@ printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
     fprintf(fp, "%s\n", pznm);
 }
 
+/**
+ */
 static void
-printStringArg(FILE * fp, tOptDesc * pOD)
+prt_str_arg(FILE * fp, tOptDesc * pOD)
 {
     if (pOD->fOptState & OPTST_STACKED) {
-        tArgList*  pAL = (tArgList*)pOD->optCookie;
+        tArgList * pAL = (tArgList*)pOD->optCookie;
         int        uct = pAL->useCt;
-        tCC**      ppz = pAL->apzArgs;
+        char const ** ppz = pAL->apzArgs;
 
         /*
          *  un-disable multiple copies of disabled options.
@@ -602,77 +607,89 @@ printStringArg(FILE * fp, tOptDesc * pOD)
             pOD->fOptState &= ~OPTST_DISABLED;
 
         while (uct-- > 0)
-            printEntry( fp, pOD, *(ppz++) );
+            prt_entry(fp, pOD, *(ppz++));
     } else {
-        printEntry( fp, pOD, pOD->optArg.argString );
+        prt_entry(fp, pOD, pOD->optArg.argString);
     }
 }
 
+/**
+ * print the string value of an enumeration.
+ *
+ * @param[in] fp  the file pointer to write to
+ * @param[in] od  the option descriptor with the enumerated value
+ */
 static void
-printEnumArg(FILE * fp, tOptDesc * pOD)
+prt_enum_arg(FILE * fp, tOptDesc * od)
 {
-    uintptr_t val = pOD->optArg.argEnum;
+    uintptr_t val = od->optArg.argEnum;
 
     /*
      *  This is a magic incantation that will convert the
      *  bit flag values back into a string suitable for printing.
      */
-    (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
-    printEntry( fp, pOD, (void*)(pOD->optArg.argString));
+    (*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od);
+    prt_entry(fp, od, (void*)(od->optArg.argString));
 
-    pOD->optArg.argEnum = val;
+    od->optArg.argEnum = val;
 }
 
+/**
+ * Print the bits set in a bit mask option.
+ * We call the option handling function with a magic value for
+ * the options pointer and it allocates and fills in the string.
+ * We print that with a call to prt_entry().
+ *
+ * @param[in] fp  the file pointer to write to
+ * @param[in] od  the option descriptor with a bit mask value type
+ */
 static void
-printSetMemberArg(FILE * fp, tOptDesc * pOD)
+prt_set_arg(FILE * fp, tOptDesc * od)
 {
-    uintptr_t val = pOD->optArg.argEnum;
-
-    /*
-     *  This is a magic incantation that will convert the
-     *  bit flag values back into a string suitable for printing.
-     */
-    (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD);
-    printEntry( fp, pOD, (void*)(pOD->optArg.argString));
-
-    if (pOD->optArg.argString != NULL) {
-        /*
-         *  set membership strings get allocated
-         */
-        AGFREE( (void*)pOD->optArg.argString );
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
-    }
-
-    pOD->optArg.argEnum = val;
+    char * list = optionMemberList(od);
+    size_t len  = strlen(list);
+    char * buf  = (char *)AGALOC(len + 3, "dir name");
+    *buf= '=';
+    memcpy(buf+1, list, len + 1);
+    prt_entry(fp, od, buf);
+    AGFREE(buf);
+    AGFREE(list);
 }
 
+/**
+ * figure out what the option file name argument is.
+ * If one can be found, call prt_entry() to emit it.
+ *
+ * @param[in] fp   the file pointer to write to.
+ * @param[in] od   the option descriptor with a bit mask value type
+ * @param[in] opts the program options descriptor
+ */
 static void
-printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts)
+prt_file_arg(FILE * fp, tOptDesc * od, tOptions * opts)
 {
     /*
      *  If the cookie is not NULL, then it has the file name, period.
      *  Otherwise, if we have a non-NULL string argument, then....
      */
-    if (pOD->optCookie != NULL)
-        printEntry(fp, pOD, pOD->optCookie);
+    if (od->optCookie != NULL)
+        prt_entry(fp, od, od->optCookie);
 
-    else if (HAS_originalOptArgArray(pOpts)) {
+    else if (HAS_originalOptArgArray(opts)) {
         char const * orig =
-            pOpts->originalOptArgArray[pOD->optIndex].argString;
+            opts->originalOptArgArray[od->optIndex].argString;
 
-        if (pOD->optArg.argString == orig)
+        if (od->optArg.argString == orig)
             return;
 
-        printEntry(fp, pOD, pOD->optArg.argString);
+        prt_entry(fp, od, od->optArg.argString);
     }
 }
 
-
 /*=export_func  optionSaveFile
  *
  * what:  saves the option state to a file
  *
- * arg:   tOptions*,   pOpts,  program options descriptor
+ * arg:   tOptions*,   opts,  program options descriptor
  *
  * doc:
  *
@@ -681,7 +698,7 @@ printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts)
  * option, or by appending the @code{rcfile} attribute to the last
  * @code{homerc} attribute.  If no @code{rcfile} attribute was specified, it
  * will default to @code{.@i{programname}rc}.  If you wish to specify another
- * file, you should invoke the @code{SET_OPT_SAVE_OPTS( @i{filename} )} macro.
+ * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro.
  *
  * The recommend usage is as follows:
  * @example
@@ -698,11 +715,11 @@ printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts)
  * will be printed to @code{stderr} and the routine will return.
 =*/
 void
-optionSaveFile( tOptions* pOpts )
+optionSaveFile(tOptions * opts)
 {
-    tOptDesc* pOD;
-    int       ct;
-    FILE*     fp = openSaveFile(pOpts);
+    tOptDesc *  od;
+    int         ct;
+    FILE *      fp = open_sv_file(opts);
 
     if (fp == NULL)
         return;
@@ -710,10 +727,10 @@ optionSaveFile( tOptions* pOpts )
     /*
      *  FOR each of the defined options, ...
      */
-    ct  = pOpts->presetOptCt;
-    pOD = pOpts->pOptDesc;
+    ct = opts->presetOptCt;
+    od = opts->pOptDesc;
     do  {
-        tOptDesc*  p;
+        tOptDesc * p;
 
         /*
          *  IF    the option has not been defined
@@ -724,14 +741,14 @@ optionSaveFile( tOptions* pOpts )
          *  Equivalenced options get picked up when the equivalenced-to
          *  option is processed.
          */
-        if (UNUSED_OPT( pOD ))
+        if (UNUSED_OPT(od))
             continue;
 
-        if ((pOD->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0)
+        if ((od->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0)
             continue;
 
-        if (  (pOD->optEquivIndex != NO_EQUIVALENT)
-           && (pOD->optEquivIndex != pOD->optIndex))
+        if (  (od->optEquivIndex != NO_EQUIVALENT)
+           && (od->optEquivIndex != od->optIndex))
             continue;
 
         /*
@@ -739,50 +756,51 @@ optionSaveFile( tOptions* pOpts )
          *  but the actual option argument type comes from the original
          *  option descriptor.  Be careful!
          */
-        p = ((pOD->fOptState & OPTST_EQUIVALENCE) != 0)
-            ? (pOpts->pOptDesc + pOD->optActualIndex) : pOD;
+        p = ((od->fOptState & OPTST_EQUIVALENCE) != 0)
+            ? (opts->pOptDesc + od->optActualIndex) : od;
 
-        switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
+        switch (OPTST_GET_ARGTYPE(od->fOptState)) {
         case OPARG_TYPE_NONE:
-            printNoArgOpt(fp, p, pOD);
+            prt_no_arg_opt(fp, p, od);
             break;
 
         case OPARG_TYPE_NUMERIC:
-            printEntry( fp, p, (void*)(p->optArg.argInt));
+            prt_entry(fp, p, (void*)(p->optArg.argInt));
             break;
 
         case OPARG_TYPE_STRING:
-            printStringArg(fp, p);
+            prt_str_arg(fp, p);
             break;
 
         case OPARG_TYPE_ENUMERATION:
-            printEnumArg(fp, p);
+            prt_enum_arg(fp, p);
             break;
 
         case OPARG_TYPE_MEMBERSHIP:
-            printSetMemberArg(fp, p);
+            prt_set_arg(fp, p);
             break;
 
         case OPARG_TYPE_BOOLEAN:
-            printEntry( fp, p, p->optArg.argBool ? "true" : "false" );
+            prt_entry(fp, p, p->optArg.argBool ? "true" : "false");
             break;
 
         case OPARG_TYPE_HIERARCHY:
-            printHierarchy(fp, p);
+            prt_nested(fp, p);
             break;
 
         case OPARG_TYPE_FILE:
-            printFileArg(fp, p, pOpts);
+            prt_file_arg(fp, p, opts);
             break;
 
         default:
             break; /* cannot handle - skip it */
         }
-    } while ( (pOD++), (--ct > 0));
+    } while (od++, (--ct > 0));
 
-    fclose( fp );
+    fclose(fp);
 }
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 86 - 82
libopts/sort.c

@@ -1,13 +1,16 @@
 
 /*
- *  sort.c  $Id: sort.c,v 4.17 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2007-07-04 11:34:52 bkorb"
+ * \file sort.c
  *
  *  This module implements argument sorting.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -19,36 +22,35 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
 static tSuccess
-mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
-               char** ppzOpts, int* pOptsIdx );
+must_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
+         char ** opt_txt, uint32_t * opt_idx);
 
 static tSuccess
-mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
-              char** ppzOpts, int* pOptsIdx );
+maybe_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
+          char ** opt_txt, uint32_t * opt_idx);
 
 static tSuccess
-checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS,
-                char** ppzOpts, int* pOptsIdx );
+short_opt_ck(tOptions * opts, char * arg_txt, tOptState * pOS,
+             char ** opt_txt, uint32_t * opt_idx);
 /* = = = END-STATIC-FORWARD = = = */
 
 /*
- *  "mustHandleArg" and "mayHandleArg" are really similar.  The biggest
+ *  "must_arg" and "maybe_arg" are really similar.  The biggest
  *  difference is that "may" will consume the next argument only if it
  *  does not start with a hyphen and "must" will consume it, hyphen or not.
  */
 static tSuccess
-mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
-               char** ppzOpts, int* pOptsIdx )
+must_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
+         char ** opt_txt, uint32_t * opt_idx)
 {
     /*
      *  An option argument is required.  Long options can either have
@@ -61,7 +63,7 @@ mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
          *  See if an arg string follows the flag character.  If not,
          *  the next arg must be the option argument.
          */
-        if (*pzArg != NUL)
+        if (*arg_txt != NUL)
             return SUCCESS;
         break;
 
@@ -77,16 +79,16 @@ mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
     default:
         return FAILURE;
     }
-    if (pOpts->curOptIdx >= pOpts->origArgCt)
+    if (opts->curOptIdx >= opts->origArgCt)
         return FAILURE;
 
-    ppzOpts[ (*pOptsIdx)++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+    opt_txt[ (*opt_idx)++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
     return SUCCESS;
 }
 
 static tSuccess
-mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
-              char** ppzOpts, int* pOptsIdx )
+maybe_arg(tOptions * opts, char * arg_txt, tOptState * pOS,
+          char ** opt_txt, uint32_t * opt_idx)
 {
     /*
      *  An option argument is optional.
@@ -98,7 +100,7 @@ mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
          *  THEN see if there is another argument.  If so and if it
          *  does *NOT* start with a hyphen, then it is the option arg.
          */
-        if (*pzArg != NUL)
+        if (*arg_txt != NUL)
             return SUCCESS;
         break;
 
@@ -114,12 +116,12 @@ mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
     default:
         return FAILURE;
     }
-    if (pOpts->curOptIdx >= pOpts->origArgCt)
+    if (opts->curOptIdx >= opts->origArgCt)
         return PROBLEM;
 
-    pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
-    if (*pzArg != '-')
-        ppzOpts[ (*pOptsIdx)++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+    arg_txt = opts->origArgVect[ opts->curOptIdx ];
+    if (*arg_txt != '-')
+        opt_txt[ (*opt_idx)++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
     return SUCCESS;
 }
 
@@ -128,31 +130,31 @@ mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
  *  does or may take an argument, the do the argument processing and leave.
  */
 static tSuccess
-checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS,
-                char** ppzOpts, int* pOptsIdx )
+short_opt_ck(tOptions * opts, char * arg_txt, tOptState * pOS,
+             char ** opt_txt, uint32_t * opt_idx)
 {
-    while (*pzArg != NUL) {
-        if (FAILED( shortOptionFind( pOpts, (tAoUC)*pzArg, pOS )))
+    while (*arg_txt != NUL) {
+        if (FAILED(opt_find_short(opts, (uint8_t)*arg_txt, pOS)))
             return FAILURE;
 
         /*
          *  See if we can have an arg.
          */
         if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
-            pzArg++;
+            arg_txt++;
 
         } else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
             /*
              *  Take an argument if it is not attached and it does not
              *  start with a hyphen.
              */
-            if (pzArg[1] != NUL)
+            if (arg_txt[1] != NUL)
                 return SUCCESS;
 
-            pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
-            if (*pzArg != '-')
-                ppzOpts[ (*pOptsIdx)++ ] =
-                    pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+            arg_txt = opts->origArgVect[ opts->curOptIdx ];
+            if (*arg_txt != '-')
+                opt_txt[ (*opt_idx)++ ] =
+                    opts->origArgVect[ (opts->curOptIdx)++ ];
             return SUCCESS;
 
         } else {
@@ -160,11 +162,11 @@ checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS,
              *  IF we need another argument, be sure it is there and
              *  take it.
              */
-            if (pzArg[1] == NUL) {
-                if (pOpts->curOptIdx >= pOpts->origArgCt)
+            if (arg_txt[1] == NUL) {
+                if (opts->curOptIdx >= opts->origArgCt)
                     return FAILURE;
-                ppzOpts[ (*pOptsIdx)++ ] =
-                    pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+                opt_txt[ (*opt_idx)++ ] =
+                    opts->origArgVect[ (opts->curOptIdx)++ ];
             }
             return SUCCESS;
         }
@@ -177,37 +179,37 @@ checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS,
  *  then this routine will to the trick.
  */
 LOCAL void
-optionSort( tOptions* pOpts )
+optionSort(tOptions * opts)
 {
-    char** ppzOpts;
-    char** ppzOpds;
-    int    optsIdx = 0;
-    int    opdsIdx = 0;
+    char **  opt_txt;
+    char **  ppzOpds;
+    uint32_t optsIdx = 0;
+    uint32_t opdsIdx = 0;
 
     tOptState os = OPTSTATE_INITIALIZER(DEFINED);
 
     /*
      *  Disable for POSIX conformance, or if there are no operands.
      */
-    if (  (getenv( "POSIXLY_CORRECT" ) != NULL)
-       || NAMED_OPTS(pOpts))
+    if (  (getenv("POSIXLY_CORRECT") != NULL)
+       || NAMED_OPTS(opts))
         return;
 
     /*
      *  Make sure we can allocate two full-sized arg vectors.
      */
-    ppzOpts = malloc( pOpts->origArgCt * sizeof( char* ));
-    if (ppzOpts == NULL)
+    opt_txt = malloc(opts->origArgCt * sizeof(char*));
+    if (opt_txt == NULL)
         goto exit_no_mem;
 
-    ppzOpds = malloc( pOpts->origArgCt * sizeof( char* ));
+    ppzOpds = malloc(opts->origArgCt * sizeof(char*));
     if (ppzOpds == NULL) {
-        free( ppzOpts );
+        free(opt_txt);
         goto exit_no_mem;
     }
 
-    pOpts->curOptIdx = 1;
-    pOpts->pzCurOpt  = NULL;
+    opts->curOptIdx = 1;
+    opts->pzCurOpt  = NULL;
 
     /*
      *  Now, process all the options from our current position onward.
@@ -215,30 +217,30 @@ optionSort( tOptions* pOpts )
      *  non-standard programs that require it.)
      */
     for (;;) {
-        char* pzArg;
+        char * arg_txt;
         tSuccess res;
 
         /*
          *  If we're out of arguments, we're done.  Join the option and
          *  operand lists into the original argument vector.
          */
-        if (pOpts->curOptIdx >= pOpts->origArgCt) {
+        if (opts->curOptIdx >= opts->origArgCt) {
             errno = 0;
             goto joinLists;
         }
 
-        pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
-        if (*pzArg != '-') {
-            ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+        arg_txt = opts->origArgVect[ opts->curOptIdx ];
+        if (*arg_txt != '-') {
+            ppzOpds[ opdsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
             continue;
         }
 
-        switch (pzArg[1]) {
+        switch (arg_txt[1]) {
         case NUL:
             /*
              *  A single hyphen is an operand.
              */
-            ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+            ppzOpds[ opdsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
             continue;
 
         case '-':
@@ -246,12 +248,12 @@ optionSort( tOptions* pOpts )
              *  Two consecutive hypens.  Put them on the options list and then
              *  _always_ force the remainder of the arguments to be operands.
              */
-            if (pzArg[2] == NUL) {
-                ppzOpts[ optsIdx++ ] =
-                    pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+            if (arg_txt[2] == NUL) {
+                opt_txt[ optsIdx++ ] =
+                    opts->origArgVect[ (opts->curOptIdx)++ ];
                 goto restOperands;
             }
-            res = longOptionFind( pOpts, pzArg+2, &os );
+            res = opt_find_long(opts, arg_txt+2, &os);
             break;
 
         default:
@@ -260,14 +262,14 @@ optionSort( tOptions* pOpts )
              *  option processing.  Otherwise the character must be a
              *  short (i.e. single character) option.
              */
-            if ((pOpts->fOptSet & OPTPROC_SHORTOPT) == 0) {
-                res = longOptionFind( pOpts, pzArg+1, &os );
+            if ((opts->fOptSet & OPTPROC_SHORTOPT) == 0) {
+                res = opt_find_long(opts, arg_txt+1, &os);
             } else {
-                res = shortOptionFind( pOpts, (tAoUC)pzArg[1], &os );
+                res = opt_find_short(opts, (uint8_t)arg_txt[1], &os);
             }
             break;
         }
-        if (FAILED( res )) {
+        if (FAILED(res)) {
             errno = EINVAL;
             goto freeTemps;
         }
@@ -277,7 +279,7 @@ optionSort( tOptions* pOpts )
          *  Next, we have to see if we need to pull another argument to be
          *  used as the option argument.
          */
-        ppzOpts[ optsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+        opt_txt[ optsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
 
         if (OPTST_GET_ARGTYPE(os.pOD->fOptState) == OPARG_TYPE_NONE) {
             /*
@@ -286,20 +288,20 @@ optionSort( tOptions* pOpts )
              *  of the argument string.
              */
             if (  (os.optType == TOPT_SHORT)
-               && FAILED( checkShortOpts( pOpts, pzArg+2, &os,
-                                          ppzOpts, &optsIdx )) )  {
+               && FAILED(short_opt_ck(opts, arg_txt+2, &os, opt_txt,
+                                      &optsIdx)) )  {
                 errno = EINVAL;
                 goto freeTemps;
             }
 
         } else if (os.pOD->fOptState & OPTST_ARG_OPTIONAL) {
-            switch (mayHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) {
+            switch (maybe_arg(opts, arg_txt+2, &os, opt_txt, &optsIdx)) {
             case FAILURE: errno = EIO; goto freeTemps;
             case PROBLEM: errno = 0;   goto joinLists;
             }
 
         } else {
-            switch (mustHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) {
+            switch (must_arg(opts, arg_txt+2, &os, opt_txt, &optsIdx)) {
             case PROBLEM:
             case FAILURE: errno = EIO; goto freeTemps;
             }
@@ -307,19 +309,20 @@ optionSort( tOptions* pOpts )
     } /* for (;;) */
 
  restOperands:
-    while (pOpts->curOptIdx < pOpts->origArgCt)
-        ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
+    while (opts->curOptIdx < opts->origArgCt)
+        ppzOpds[ opdsIdx++ ] = opts->origArgVect[ (opts->curOptIdx)++ ];
 
  joinLists:
     if (optsIdx > 0)
-        memcpy( pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof( char* ));
+        memcpy(opts->origArgVect + 1, opt_txt,
+               (size_t)optsIdx * sizeof(char*));
     if (opdsIdx > 0)
-        memcpy( pOpts->origArgVect + 1 + optsIdx,
-                ppzOpds, opdsIdx * sizeof( char* ));
+        memcpy(opts->origArgVect + 1 + optsIdx, ppzOpds,
+               (size_t)opdsIdx * sizeof(char*));
 
  freeTemps:
-    free( ppzOpts );
-    free( ppzOpds );
+    free(opt_txt);
+    free(ppzOpds);
     return;
 
  exit_no_mem:
@@ -327,7 +330,8 @@ optionSort( tOptions* pOpts )
     return;
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 66 - 63
libopts/stack.c

@@ -1,15 +1,17 @@
 
-/*
- *  stack.c
- *  $Id: stack.c,v 4.19 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2008-07-30 16:56:32 bkorb"
+/**
+ * \file stack.c
  *
  *  This is a special option processing routine that will save the
  *  argument to an option in a FIFO queue.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,11 +23,11 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 #ifdef WITH_LIBREGEX
@@ -36,33 +38,30 @@
  * private:
  *
  * what:  Remove option args from a stack
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
  *
  * doc:
  *  Invoked for options that are equivalenced to stacked options.
 =*/
 void
-optionUnstackArg(
-    tOptions*  pOpts,
-    tOptDesc*  pOptDesc )
+optionUnstackArg(tOptions * opts, tOptDesc * od)
 {
-    int       res;
+    tArgList * arg_list;
 
-    tArgList* pAL;
-
-    if ((pOptDesc->fOptState & OPTST_RESET) != 0)
+    if (INQUERY_CALL(opts, od))
         return;
-    pAL = (tArgList*)pOptDesc->optCookie;
+
+    arg_list = (tArgList*)od->optCookie;
 
     /*
      *  IF we don't have any stacked options,
      *  THEN indicate that we don't have any of these options
      */
-    if (pAL == NULL) {
-        pOptDesc->fOptState &= OPTST_PERSISTENT_MASK;
-        if ( (pOptDesc->fOptState & OPTST_INITENABLED) == 0)
-            pOptDesc->fOptState |= OPTST_DISABLED;
+    if (arg_list == NULL) {
+        od->fOptState &= OPTST_PERSISTENT_MASK;
+        if ((od->fOptState & OPTST_INITENABLED) == 0)
+            od->fOptState |= OPTST_DISABLED;
         return;
     }
 
@@ -71,7 +70,7 @@ optionUnstackArg(
         regex_t   re;
         int       i, ct, dIdx;
 
-        if (regcomp( &re, pOptDesc->optArg.argString, REG_NOSUB ) != 0)
+        if (regcomp(&re, od->optArg.argString, REG_NOSUB) != 0)
             return;
 
         /*
@@ -80,14 +79,16 @@ optionUnstackArg(
          *  index is incremented every time.  The destination only when
          *  we are keeping a define.
          */
-        for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) {
-            tCC*      pzSrc = pAL->apzArgs[ i ];
-            char*     pzEq  = strchr( pzSrc, '=' );
+        for (i = 0, dIdx = 0, ct = arg_list->useCt; --ct >= 0; i++) {
+            char const * pzSrc = arg_list->apzArgs[ i ];
+            char *       pzEq  = strchr(pzSrc, '=');
+            int          res;
+
 
             if (pzEq != NULL)
                 *pzEq = NUL;
 
-            res = regexec( &re, pzSrc, (size_t)0, NULL, 0 );
+            res = regexec(&re, pzSrc, (size_t)0, NULL, 0);
             switch (res) {
             case 0:
                 /*
@@ -96,7 +97,7 @@ optionUnstackArg(
                  *  the list.
                  */
                 AGFREE(pzSrc);
-                pAL->useCt--;
+                arg_list->useCt--;
                 break;
 
             default:
@@ -109,12 +110,12 @@ optionUnstackArg(
                  *  THEN we have to move the current one.
                  */
                 if (dIdx != i)
-                    pAL->apzArgs[ dIdx ] = pzSrc;
+                    arg_list->apzArgs[ dIdx ] = pzSrc;
                 dIdx++;
             }
         }
 
-        regfree( &re );
+        regfree(&re);
     }
 #else  /* not WITH_LIBREGEX */
     {
@@ -126,21 +127,21 @@ optionUnstackArg(
          *  index is incremented every time.  The destination only when
          *  we are keeping a define.
          */
-        for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) {
-            tCC*      pzSrc = pAL->apzArgs[ i ];
-            char*     pzEq  = strchr( pzSrc, '=' );
+        for (i = 0, dIdx = 0, ct = arg_list->useCt; --ct >= 0; i++) {
+            const char * pzSrc = arg_list->apzArgs[ i ];
+            char *       pzEq  = strchr(pzSrc, '=');
 
             if (pzEq != NULL)
                 *pzEq = NUL;
 
-            if (strcmp( pzSrc, pOptDesc->optArg.argString ) == 0) {
+            if (strcmp(pzSrc, od->optArg.argString) == 0) {
                 /*
                  *  Remove this entry by reducing the in-use count
                  *  and *not* putting the string pointer back into
                  *  the list.
                  */
                 AGFREE(pzSrc);
-                pAL->useCt--;
+                arg_list->useCt--;
             } else {
                 if (pzEq != NULL)
                     *pzEq = '=';
@@ -150,7 +151,7 @@ optionUnstackArg(
                  *  THEN we have to move the current one.
                  */
                 if (dIdx != i)
-                    pAL->apzArgs[ dIdx ] = pzSrc;
+                    arg_list->apzArgs[ dIdx ] = pzSrc;
                 dIdx++;
             }
         }
@@ -160,12 +161,12 @@ optionUnstackArg(
      *  IF we have unstacked everything,
      *  THEN indicate that we don't have any of these options
      */
-    if (pAL->useCt == 0) {
-        pOptDesc->fOptState &= OPTST_PERSISTENT_MASK;
-        if ( (pOptDesc->fOptState & OPTST_INITENABLED) == 0)
-            pOptDesc->fOptState |= OPTST_DISABLED;
-        AGFREE( (void*)pAL );
-        pOptDesc->optCookie = NULL;
+    if (arg_list->useCt == 0) {
+        od->fOptState &= OPTST_PERSISTENT_MASK;
+        if ((od->fOptState & OPTST_INITENABLED) == 0)
+            od->fOptState |= OPTST_DISABLED;
+        AGFREE((void *)arg_list);
+        od->optCookie = NULL;
     }
 }
 
@@ -176,7 +177,7 @@ optionUnstackArg(
  *  as an opaque address.
  */
 LOCAL void
-addArgListEntry( void** ppAL, void* entry )
+addArgListEntry(void ** ppAL, void * entry)
 {
     tArgList* pAL = *(void**)ppAL;
 
@@ -185,7 +186,7 @@ addArgListEntry( void** ppAL, void* entry )
      *  THEN allocate one now
      */
     if (pAL == NULL) {
-        pAL = (tArgList*)AGALOC( sizeof( *pAL ), "new option arg stack" );
+        pAL = (tArgList*)AGALOC(sizeof(*pAL), "new option arg stack");
         if (pAL == NULL)
             return;
         pAL->useCt   = 0;
@@ -198,15 +199,15 @@ addArgListEntry( void** ppAL, void* entry )
      *  THEN make it bigger
      */
     else if (pAL->useCt >= pAL->allocCt) {
-        size_t sz = sizeof( *pAL );
+        size_t sz = sizeof(*pAL);
         pAL->allocCt += INCR_ARG_ALLOC_CT;
 
         /*
          *  The base structure contains space for MIN_ARG_ALLOC_CT
          *  pointers.  We subtract it off to find our augment size.
          */
-        sz += sizeof(char*) * (pAL->allocCt - MIN_ARG_ALLOC_CT);
-        pAL = (tArgList*)AGREALOC( (void*)pAL, sz, "expanded opt arg stack" );
+        sz += sizeof(char*) * ((size_t)pAL->allocCt - MIN_ARG_ALLOC_CT);
+        pAL = (tArgList*)AGREALOC((void*)pAL, sz, "expanded opt arg stack");
         if (pAL == NULL)
             return;
         *ppAL = (void*)pAL;
@@ -223,39 +224,41 @@ addArgListEntry( void** ppAL, void* entry )
  * private:
  *
  * what:  put option args on a stack
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
  *
  * doc:
  *  Keep an entry-ordered list of option arguments.
 =*/
 void
-optionStackArg(
-    tOptions*  pOpts,
-    tOptDesc*  pOD )
+optionStackArg(tOptions * opts, tOptDesc * od)
 {
     char * pz;
 
-    if ((pOD->fOptState & OPTST_RESET) != 0) {
-        tArgList* pAL = (void*)pOD->optCookie;
+    if (INQUERY_CALL(opts, od))
+        return;
+
+    if ((od->fOptState & OPTST_RESET) != 0) {
+        tArgList * arg_list = (void*)od->optCookie;
         int ix;
-        if (pAL == NULL)
+        if (arg_list == NULL)
             return;
 
-        ix = pAL->useCt;
+        ix = arg_list->useCt;
         while (--ix >= 0)
-            AGFREE(pAL->apzArgs[ix]);
-        AGFREE(pAL);
+            AGFREE(arg_list->apzArgs[ix]);
+        AGFREE(arg_list);
 
     } else {
-        if (pOD->optArg.argString == NULL)
+        if (od->optArg.argString == NULL)
             return;
 
-        AGDUPSTR(pz, pOD->optArg.argString, "stack arg");
-        addArgListEntry( &(pOD->optCookie), (void*)pz );
+        AGDUPSTR(pz, od->optArg.argString, "stack arg");
+        addArgListEntry(&(od->optCookie), (void*)pz);
     }
 }
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 50 - 0
libopts/stdnoreturn.in.h

@@ -0,0 +1,50 @@
+/* A substitute for ISO C11 <stdnoreturn.h>.
+
+   Copyright 2012-2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert.  */
+
+#ifndef noreturn
+
+/* ISO C11 <stdnoreturn.h> for platforms that lack it.
+
+   References:
+   ISO C11 (latest free draft
+   <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>)
+   section 7.23 */
+
+/* The definition of _Noreturn is copied here.  */
+
+#if 1200 <= _MSC_VER
+/* Standard include files on this platform contain declarations like
+   "__declspec (noreturn) void abort (void);".  "#define noreturn
+   _Noreturn" would cause this declaration to be rewritten to the
+   invalid "__declspec (__declspec (noreturn)) void abort (void);".
+   Instead, define noreturn to empty, so that such declarations are
+   rewritten to "__declspec () void abort (void);", which is
+   equivalent to "void abort (void);"; this gives up on noreturn's
+   advice to the compiler but at least it is valid code.  */
+# define noreturn /*empty*/
+#else
+# define noreturn _Noreturn
+#endif
+
+/* Did he ever return?
+   No he never returned
+   And his fate is still unlearn'd ...
+     -- Steiner J, Hawes BL.  M.T.A. (1949)  */
+
+#endif /* noreturn */

+ 50 - 32
libopts/streqvcmp.c

@@ -1,7 +1,6 @@
 
-/*
- *  $Id: streqvcmp.c,v 4.17 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2008-12-26 10:15:46 bkorb"
+/**
+ * \file streqvcmp.c
  *
  *  String Equivalence Comparison
  *
@@ -10,9 +9,13 @@
  *  the characters "-", "_" and "^" all need to be equivalent
  *  (because they are treated so by different development environments).
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -24,19 +27,19 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  *
  * This array is designed for mapping upper and lower case letter
  * together for a case independent comparison.  The mappings are
  * based upon ascii character sequences.
  */
 static unsigned char charmap[] = {
-    0x00, 0x01, 0x02, 0x03,  0x04, 0x05, 0x06, '\a',
-    '\b', '\t', '\n', '\v',  '\f', '\r', 0x0E, 0x0F,
+    NUL,  0x01, 0x02, 0x03,  0x04, 0x05, 0x06, '\a',
+    '\b', '\t', NL,   '\v',  '\f', '\r', 0x0E, 0x0F,
     0x10, 0x11, 0x12, 0x13,  0x14, 0x15, 0x16, 0x17,
     0x18, 0x19, 0x1A, 0x1B,  0x1C, 0x1D, 0x1E, 0x1F,
 
@@ -97,12 +100,19 @@ static unsigned char charmap[] = {
  * err:  none checked.  Caller responsible for seg faults.
 =*/
 int
-strneqvcmp( tCC* s1, tCC* s2, int ct )
+strneqvcmp(char const * s1, char const * s2, int ct)
 {
     for (; ct > 0; --ct) {
         unsigned char u1 = (unsigned char) *s1++;
         unsigned char u2 = (unsigned char) *s2++;
-        int dif = charmap[ u1 ] - charmap[ u2 ];
+        int dif;
+        if (u1 == u2) {
+            if (u1 == NUL)
+                return 0;
+            continue;
+        }
+
+        dif = charmap[ u1 ] - charmap[ u2 ];
 
         if (dif != 0)
             return dif;
@@ -136,12 +146,19 @@ strneqvcmp( tCC* s1, tCC* s2, int ct )
  * err:  none checked.  Caller responsible for seg faults.
 =*/
 int
-streqvcmp( tCC* s1, tCC* s2 )
+streqvcmp(char const * s1, char const * s2)
 {
     for (;;) {
         unsigned char u1 = (unsigned char) *s1++;
         unsigned char u2 = (unsigned char) *s2++;
-        int dif = charmap[ u1 ] - charmap[ u2 ];
+        int dif;
+        if (u1 == u2) {
+            if (u1 == NUL)
+                return 0;
+            continue;
+        }
+
+        dif = charmap[ u1 ] - charmap[ u2 ];
 
         if (dif != 0)
             return dif;
@@ -156,8 +173,8 @@ streqvcmp( tCC* s1, tCC* s2 )
  *
  * what: Set the character mappings for the streqv functions
  *
- * arg:  + char + From + Input character +
- * arg:  + char + To   + Mapped-to character +
+ * arg:  + char + from + Input character +
+ * arg:  + char + to   + Mapped-to character +
  * arg:  + int  + ct   + compare length +
  *
  * doc:
@@ -169,7 +186,7 @@ streqvcmp( tCC* s1, tCC* s2 )
  * are incremented and the process repeated until @code{ct} entries have been
  * set. For example,
  * @example
- *    streqvmap( 'a', 'A', 26 );
+ *    streqvmap('a', 'A', 26);
  * @end example
  * @noindent
  * will alter the mapping so that all English lower case letters
@@ -181,24 +198,24 @@ streqvcmp( tCC* s1, tCC* s2 )
  * err:  none.
 =*/
 void
-streqvmap( char From, char To, int ct )
+streqvmap(char from, char to, int ct)
 {
     if (ct == 0) {
-        ct = sizeof( charmap ) - 1;
+        ct = sizeof(charmap) - 1;
         do  {
-            charmap[ ct ] = ct;
+            charmap[ct] = (unsigned char)ct;
         } while (--ct >= 0);
     }
 
     else {
-        int  chTo   = (int)To   & 0xFF;
-        int  chFrom = (int)From & 0xFF;
+        unsigned int i_to   = (int)to   & 0xFF;
+        unsigned int i_from = (int)from & 0xFF;
 
         do  {
-            charmap[ chFrom ] = (unsigned)chTo;
-            chFrom++;
-            chTo++;
-            if ((chFrom >= sizeof( charmap )) || (chTo >= sizeof( charmap )))
+            charmap[i_from] = (unsigned char)i_to;
+            i_from++;
+            i_to++;
+            if ((i_from >= sizeof(charmap)) || (i_to >= sizeof(charmap)))
                 break;
         } while (--ct > 0);
     }
@@ -221,12 +238,12 @@ streqvmap( char From, char To, int ct )
  * err:  none.
 =*/
 void
-strequate( char const* s )
+strequate(char const* s)
 {
     if ((s != NULL) && (*s != NUL)) {
-        unsigned char equiv = (unsigned)*s;
+        unsigned char equiv = (unsigned char)*s;
         while (*s != NUL)
-            charmap[ (unsigned)*(s++) ] = equiv;
+            charmap[(unsigned char)*(s++)] = equiv;
     }
 }
 
@@ -250,14 +267,15 @@ strequate( char const* s )
  * err:  none.
 =*/
 void
-strtransform( char* d, char const* s )
+strtransform(char* d, char const* s)
 {
     do  {
-        *(d++) = (char)charmap[ (unsigned)*s ];
+        *(d++) = (char)charmap[(unsigned char)*s];
     } while (*(s++) != NUL);
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 253 - 257
libopts/text_mmap.c

@@ -1,11 +1,15 @@
-/*
- * $Id: text_mmap.c,v 4.21 2009/08/01 17:43:06 bkorb Exp $
+/**
+ * @file text_mmap.c
  *
- * Time-stamp:      "2007-07-04 11:35:49 bkorb"
+ * Map a text file, ensuring the text always has an ending NUL byte.
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -17,16 +21,32 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
+#if defined(HAVE_MMAP)
+#  ifndef      MAP_ANONYMOUS
+#    ifdef     MAP_ANON
+#      define  MAP_ANONYMOUS   MAP_ANON
+#    endif
+#  endif
 
-#ifndef MAP_ANONYMOUS
-#  ifdef   MAP_ANON
-#  define  MAP_ANONYMOUS   MAP_ANON
+#  if ! defined(MAP_ANONYMOUS) && ! defined(HAVE_DEV_ZERO)
+     /*
+      * We must have either /dev/zero or anonymous mapping for
+      * this to work.
+      */
+#    undef HAVE_MMAP
+
+#  else
+#    ifdef _SC_PAGESIZE
+#      define GETPAGESIZE() sysconf(_SC_PAGESIZE)
+#    else
+#      define GETPAGESIZE() getpagesize()
+#    endif
 #  endif
 #endif
 
@@ -43,6 +63,192 @@
          && ((_flg & (MAP_SHARED|MAP_PRIVATE)) == MAP_SHARED))
 #define MAP_FAILED_PTR ((void*)MAP_FAILED)
 
+/**
+ * Load the contents of a text file.  There are two separate implementations,
+ * depending up on whether mmap(3) is available.
+ *
+ *  If not available, malloc the file length plus one byte.  Read it in
+ *  and NUL terminate.
+ *
+ *  If available, first check to see if the text file size is a multiple of a
+ *  page size.  If it is, map the file size plus an extra page from either
+ *  anonymous memory or from /dev/zero.  Then map the file text on top of the
+ *  first pages of the anonymous/zero pages.  Otherwise, just map the file
+ *  because there will be NUL bytes provided at the end.
+ *
+ * @param mapinfo a structure holding everything we need to know
+ *        about the mapping.
+ *
+ * @param pzFile name of the file, for error reporting.
+ */
+static void
+load_text_file(tmap_info_t * mapinfo, char const * pzFile)
+{
+#if ! defined(HAVE_MMAP)
+    mapinfo->txt_data = AGALOC(mapinfo->txt_size+1, "file text");
+    if (mapinfo->txt_data == NULL) {
+        mapinfo->txt_errno = ENOMEM;
+        return;
+    }
+
+    {
+        size_t sz = mapinfo->txt_size;
+        char*  pz = mapinfo->txt_data;
+
+        while (sz > 0) {
+            ssize_t rdct = read(mapinfo->txt_fd, pz, sz);
+            if (rdct <= 0) {
+                mapinfo->txt_errno = errno;
+                fserr_warn("libopts", "read", pzFile);
+                free(mapinfo->txt_data);
+                return;
+            }
+
+            pz += rdct;
+            sz -= rdct;
+        }
+
+        *pz = NUL;
+    }
+
+    mapinfo->txt_errno   = 0;
+
+#else /* HAVE mmap */
+    size_t const pgsz = (size_t)GETPAGESIZE();
+    void * map_addr   = NULL;
+
+    (void)pzFile;
+
+    mapinfo->txt_full_size = (mapinfo->txt_size + pgsz) & ~(pgsz - 1);
+    if (mapinfo->txt_full_size == (mapinfo->txt_size + pgsz)) {
+        /*
+         * The text is a multiple of a page boundary.  We must map an
+         * extra page so the text ends with a NUL.
+         */
+#if defined(MAP_ANONYMOUS)
+        map_addr = mmap(NULL, mapinfo->txt_full_size, PROT_READ|PROT_WRITE,
+                        MAP_ANONYMOUS|MAP_PRIVATE, AO_INVALID_FD, 0);
+#else
+        mapinfo->txt_zero_fd = open("/dev/zero", O_RDONLY);
+
+        if (mapinfo->txt_zero_fd == AO_INVALID_FD) {
+            mapinfo->txt_errno = errno;
+            return;
+        }
+        map_addr = mmap(NULL, mapinfo->txt_full_size, PROT_READ|PROT_WRITE,
+                        MAP_PRIVATE, mapinfo->txt_zero_fd, 0);
+#endif
+        if (map_addr == MAP_FAILED_PTR) {
+            mapinfo->txt_errno = errno;
+            return;
+        }
+        mapinfo->txt_flags |= MAP_FIXED;
+    }
+
+    mapinfo->txt_data =
+        mmap(map_addr, mapinfo->txt_size, mapinfo->txt_prot,
+             mapinfo->txt_flags, mapinfo->txt_fd, 0);
+
+    if (mapinfo->txt_data == MAP_FAILED_PTR)
+        mapinfo->txt_errno = errno;
+#endif /* HAVE_MMAP */
+}
+
+/**
+ * Make sure all the parameters are correct:  we have a file name that
+ * is a text file that we can read.
+ *
+ * @param fname the text file to map
+ * @param prot  the memory protections requested (read/write/etc.)
+ * @param flags mmap flags
+ * @param mapinfo a structure holding everything we need to know
+ *        about the mapping.
+ */
+static void
+validate_mmap(char const * fname, int prot, int flags, tmap_info_t * mapinfo)
+{
+    memset(mapinfo, 0, sizeof(*mapinfo));
+#if defined(HAVE_MMAP) && ! defined(MAP_ANONYMOUS)
+    mapinfo->txt_zero_fd = AO_INVALID_FD;
+#endif
+    mapinfo->txt_fd      = AO_INVALID_FD;
+    mapinfo->txt_prot    = prot;
+    mapinfo->txt_flags   = flags;
+
+    /*
+     *  Map mmap flags and protections into open flags and do the open.
+     */
+    {
+        /*
+         *  See if we will be updating the file.  If we can alter the memory
+         *  and if we share the data and we are *not* copy-on-writing the data,
+         *  then our updates will show in the file, so we must open with
+         *  write access.
+         */
+        int o_flag = FILE_WRITABLE(prot, flags) ? O_RDWR : O_RDONLY;
+
+        /*
+         *  If you're not sharing the file and you are writing to it,
+         *  then don't let anyone else have access to the file.
+         */
+        if (((flags & MAP_SHARED) == 0) && (prot & PROT_WRITE))
+            o_flag |= O_EXCL;
+
+        mapinfo->txt_fd = open(fname, o_flag);
+        if (mapinfo->txt_fd < 0) {
+            mapinfo->txt_errno = errno;
+            mapinfo->txt_fd = AO_INVALID_FD;
+            return;
+        }
+    }
+
+    /*
+     *  Make sure we can stat the regular file.  Save the file size.
+     */
+    {
+        struct stat sb;
+        if (fstat(mapinfo->txt_fd, &sb) != 0) {
+            mapinfo->txt_errno = errno;
+            close(mapinfo->txt_fd);
+            return;
+        }
+
+        if (! S_ISREG(sb.st_mode)) {
+            mapinfo->txt_errno = errno = EINVAL;
+            close(mapinfo->txt_fd);
+            return;
+        }
+
+        mapinfo->txt_size = (size_t)sb.st_size;
+    }
+
+    if (mapinfo->txt_fd == AO_INVALID_FD)
+        mapinfo->txt_errno = errno;
+}
+
+/**
+ * Close any files opened by the mapping.
+ *
+ * @param mi a structure holding everything we need to know about the map.
+ */
+static void
+close_mmap_files(tmap_info_t * mi)
+{
+    if (mi->txt_fd == AO_INVALID_FD)
+        return;
+
+    close(mi->txt_fd);
+    mi->txt_fd = AO_INVALID_FD;
+
+#if defined(HAVE_MMAP) && ! defined(MAP_ANONYMOUS)
+    if (mi->txt_zero_fd == AO_INVALID_FD)
+        return;
+
+    close(mi->txt_zero_fd);
+    mi->txt_zero_fd = AO_INVALID_FD;
+#endif
+}
+
 /*=export_func  text_mmap
  * private:
  *
@@ -61,20 +267,20 @@
  * This routine will mmap a file into memory ensuring that there is at least
  * one @file{NUL} character following the file data.  It will return the
  * address where the file contents have been mapped into memory.  If there is a
- * problem, then it will return @code{MAP_FAILED} and set @file{errno}
+ * problem, then it will return @code{MAP_FAILED} and set @code{errno}
  * appropriately.
  *
- * The named file does not exist, @code{stat(2)} will set @file{errno} as it
- * will.  If the file is not a regular file, @file{errno} will be
+ * The named file does not exist, @code{stat(2)} will set @code{errno} as it
+ * will.  If the file is not a regular file, @code{errno} will be
  * @code{EINVAL}.  At that point, @code{open(2)} is attempted with the access
  * bits set appropriately for the requested @code{mmap(2)} protections and flag
- * bits.  On failure, @file{errno} will be set according to the documentation
- * for @code{open(2)}.  If @code{mmap(2)} fails, @file{errno} will be set as
+ * bits.  On failure, @code{errno} will be set according to the documentation
+ * for @code{open(2)}.  If @code{mmap(2)} fails, @code{errno} will be set as
  * that routine sets it.  If @code{text_mmap} works to this point, a valid
  * address will be returned, but there may still be ``issues''.
  *
  * If the file size is not an even multiple of the system page size, then
- * @code{text_map} will return at this point and @file{errno} will be zero.
+ * @code{text_map} will return at this point and @code{errno} will be zero.
  * Otherwise, an anonymous map is attempted.  If not available, then an attempt
  * is made to @code{mmap(2)} @file{/dev/zero}.  If any of these fail, the
  * address of the file's data is returned, bug @code{no} @file{NUL} characters
@@ -90,203 +296,29 @@
  * #include <mylib.h>
  * tmap_info_t mi;
  * int no_nul;
- * void* data = text_mmap( "file", PROT_WRITE, MAP_PRIVATE, &mi );
+ * void* data = text_mmap("file", PROT_WRITE, MAP_PRIVATE, &mi);
  * if (data == MAP_FAILED) return;
  * no_nul = (mi.txt_size == mi.txt_full_size);
  * << use the data >>
- * text_munmap( &mi );
+ * text_munmap(&mi);
 =*/
-void*
-text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI )
+void *
+text_mmap(char const * pzFile, int prot, int flags, tmap_info_t * mi)
 {
-    memset( pMI, 0, sizeof(*pMI) );
-#ifdef HAVE_MMAP
-    pMI->txt_zero_fd = -1;
-#endif
-    pMI->txt_fd = -1;
-
-    /*
-     *  Make sure we can stat the regular file.  Save the file size.
-     */
-    {
-        struct stat sb;
-        if (stat( pzFile, &sb ) != 0) {
-            pMI->txt_errno = errno;
-            return MAP_FAILED_PTR;
-        }
-
-        if (! S_ISREG( sb.st_mode )) {
-            pMI->txt_errno = errno = EINVAL;
-            return MAP_FAILED_PTR;
-        }
-
-        pMI->txt_size = sb.st_size;
-    }
-
-    /*
-     *  Map mmap flags and protections into open flags and do the open.
-     */
-    {
-        int o_flag;
-        /*
-         *  See if we will be updating the file.  If we can alter the memory
-         *  and if we share the data and we are *not* copy-on-writing the data,
-         *  then our updates will show in the file, so we must open with
-         *  write access.
-         */
-        if (FILE_WRITABLE(prot,flags))
-            o_flag = O_RDWR;
-        else
-            o_flag = O_RDONLY;
-
-        /*
-         *  If you're not sharing the file and you are writing to it,
-         *  then don't let anyone else have access to the file.
-         */
-        if (((flags & MAP_SHARED) == 0) && (prot & PROT_WRITE))
-            o_flag |= O_EXCL;
-
-        pMI->txt_fd = open( pzFile, o_flag );
-    }
-
-    if (pMI->txt_fd == AO_INVALID_FD) {
-        pMI->txt_errno = errno;
+    validate_mmap(pzFile, prot, flags, mi);
+    if (mi->txt_errno != 0)
         return MAP_FAILED_PTR;
-    }
-
-#ifdef HAVE_MMAP /* * * * * WITH MMAP * * * * * */
-    /*
-     *  do the mmap.  If we fail, then preserve errno, close the file and
-     *  return the failure.
-     */
-    pMI->txt_data =
-        mmap(NULL, pMI->txt_size+1, prot, flags, pMI->txt_fd, (size_t)0);
-    if (pMI->txt_data == MAP_FAILED_PTR) {
-        pMI->txt_errno = errno;
-        goto fail_return;
-    }
-
-    /*
-     *  Most likely, everything will turn out fine now.  The only difficult
-     *  part at this point is coping with files with sizes that are a multiple
-     *  of the page size.  Handling that is what this whole thing is about.
-     */
-    pMI->txt_zero_fd = -1;
-    pMI->txt_errno   = 0;
-
-    {
-        void* pNuls;
-#ifdef _SC_PAGESIZE
-        size_t pgsz = sysconf(_SC_PAGESIZE);
-#else
-        size_t pgsz = getpagesize();
-#endif
-        /*
-         *  Compute the pagesize rounded mapped memory size.
-         *  IF this is not the same as the file size, then there are NUL's
-         *  at the end of the file mapping and all is okay.
-         */
-        pMI->txt_full_size = (pMI->txt_size + (pgsz - 1)) & ~(pgsz - 1);
-        if (pMI->txt_size != pMI->txt_full_size)
-            return pMI->txt_data;
-
-        /*
-         *  Still here?  We have to remap the trailing inaccessible page
-         *  either anonymously or to /dev/zero.
-         */
-        pMI->txt_full_size += pgsz;
-#if defined(MAP_ANONYMOUS)
-        pNuls = mmap(
-                (void*)(((char*)pMI->txt_data) + pMI->txt_size),
-                pgsz, PROT_READ|PROT_WRITE,
-                MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE, AO_INVALID_FD, (size_t)0);
-
-        if (pNuls != MAP_FAILED_PTR)
-            return pMI->txt_data;
-
-        pMI->txt_errno = errno;
-
-#elif defined(HAVE_DEV_ZERO)
-        pMI->txt_zero_fd = open( "/dev/zero", O_RDONLY );
 
-        if (pMI->txt_zero_fd == AO_INVALID_FD) {
-            pMI->txt_errno = errno;
+    load_text_file(mi, pzFile);
 
-        } else {
-            pNuls = mmap(
-                    (void*)(((char*)pMI->txt_data) + pMI->txt_size), pgsz,
-                    PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
-                    pMI->txt_zero_fd, 0 );
+    if (mi->txt_errno == 0)
+        return mi->txt_data;
 
-            if (pNuls != MAP_FAILED_PTR)
-                return pMI->txt_data;
+    close_mmap_files(mi);
 
-            pMI->txt_errno = errno;
-            close( pMI->txt_zero_fd );
-            pMI->txt_zero_fd = -1;
-        }
-#endif
-
-        pMI->txt_full_size = pMI->txt_size;
-    }
-
-    {
-        void* p = AGALOC( pMI->txt_size+1, "file text" );
-        memcpy( p, pMI->txt_data, pMI->txt_size );
-        ((char*)p)[pMI->txt_size] = NUL;
-        munmap(pMI->txt_data, pMI->txt_size );
-        pMI->txt_data = p;
-    }
-    pMI->txt_alloc = 1;
-    return pMI->txt_data;
-
-#else /* * * * * * no HAVE_MMAP * * * * * */
-
-    pMI->txt_data = AGALOC( pMI->txt_size+1, "file text" );
-    if (pMI->txt_data == NULL) {
-        pMI->txt_errno = ENOMEM;
-        goto fail_return;
-    }
-
-    {
-        size_t sz = pMI->txt_size;
-        char*  pz = pMI->txt_data;
-
-        while (sz > 0) {
-            ssize_t rdct = read( pMI->txt_fd, pz, sz );
-            if (rdct <= 0) {
-                pMI->txt_errno = errno;
-                fprintf( stderr, zFSErrReadFile,
-                         errno, strerror( errno ), pzFile );
-                free( pMI->txt_data );
-                goto fail_return;
-            }
-
-            pz += rdct;
-            sz -= rdct;
-        }
-
-        *pz = NUL;
-    }
-
-    /*
-     *  We never need a dummy page mapped in
-     */
-    pMI->txt_zero_fd = -1;
-    pMI->txt_errno   = 0;
-
-    return pMI->txt_data;
-
-#endif /* * * * * * no HAVE_MMAP * * * * * */
-
- fail_return:
-    if (pMI->txt_fd >= 0) {
-        close( pMI->txt_fd );
-        pMI->txt_fd = -1;
-    }
-    errno = pMI->txt_errno;
-    pMI->txt_data = MAP_FAILED_PTR;
-    return pMI->txt_data;
+    errno = mi->txt_errno;
+    mi->txt_data = MAP_FAILED_PTR;
+    return mi->txt_data;
 }
 
 
@@ -298,7 +330,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI )
  * arg:   tmap_info_t*, mapinfo, info about the mapping
  *
  * ret-type:   int
- * ret-desc:   -1 or 0.  @file{errno} will have the error code.
+ * ret-desc:   -1 or 0.  @code{errno} will have the error code.
  *
  * doc:
  *
@@ -310,71 +342,35 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI )
  * err: Any error code issued by munmap(2) or close(2) is possible.
 =*/
 int
-text_munmap( tmap_info_t* pMI )
+text_munmap(tmap_info_t * mi)
 {
-#ifdef HAVE_MMAP
-    int res = 0;
-    if (pMI->txt_alloc) {
-        /*
-         *  IF the user has write permission and the text is not mapped private,
-         *  then write back any changes.  Hopefully, nobody else has modified
-         *  the file in the mean time.
-         */
-        if (   ((pMI->txt_prot & PROT_WRITE) != 0)
-            && ((pMI->txt_flags & MAP_PRIVATE) == 0))  {
-
-            if (lseek(pMI->txt_fd, (size_t)0, SEEK_SET) != 0)
-                goto error_return;
-
-            res = (write( pMI->txt_fd, pMI->txt_data, pMI->txt_size ) < 0)
-                ? errno : 0;
-        }
-
-        AGFREE( pMI->txt_data );
-        errno = res;
-    } else {
-        res = munmap( pMI->txt_data, pMI->txt_full_size );
-    }
-    if (res != 0)
-        goto error_return;
-
-    res = close( pMI->txt_fd );
-    if (res != 0)
-        goto error_return;
-
-    pMI->txt_fd = -1;
     errno = 0;
-    if (pMI->txt_zero_fd != -1) {
-        res = close( pMI->txt_zero_fd );
-        pMI->txt_zero_fd = -1;
-    }
 
- error_return:
-    pMI->txt_errno = errno;
-    return res;
-#else  /* HAVE_MMAP */
+#ifdef HAVE_MMAP
+    (void)munmap(mi->txt_data, mi->txt_full_size);
 
-    errno = 0;
+#else  /* don't HAVE_MMAP */
     /*
      *  IF the memory is writable *AND* it is not private (copy-on-write)
      *     *AND* the memory is "sharable" (seen by other processes)
-     *  THEN rewrite the data.
+     *  THEN rewrite the data.  Emulate mmap visibility.
      */
-    if (   FILE_WRITABLE(pMI->txt_prot, pMI->txt_flags)
-        && (lseek( pMI->txt_fd, 0, SEEK_SET ) >= 0) ) {
-        write( pMI->txt_fd, pMI->txt_data, pMI->txt_size );
+    if (   FILE_WRITABLE(mi->txt_prot, mi->txt_flags)
+        && (lseek(mi->txt_fd, 0, SEEK_SET) >= 0) ) {
+        write(mi->txt_fd, mi->txt_data, mi->txt_size);
     }
 
-    close( pMI->txt_fd );
-    pMI->txt_fd = -1;
-    pMI->txt_errno = errno;
-    free( pMI->txt_data );
-
-    return pMI->txt_errno;
+    free(mi->txt_data);
 #endif /* HAVE_MMAP */
+
+    mi->txt_errno = errno;
+    close_mmap_files(mi);
+
+    return mi->txt_errno;
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 99 - 44
libopts/time.c

@@ -1,11 +1,14 @@
 
-/*
- *  $Id: time.c,v 4.5 2009/08/01 17:43:06 bkorb Exp $
- *  Time-stamp:      "2008-11-16 14:51:48 bkorb"
+/**
+ * \file time.c
  *
+ * @addtogroup autoopts
+ * @{
+ */
+/*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -17,72 +20,124 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
-#ifndef HAVE_PARSE_DURATION
-#include <time.h>
-
-static inline char *
-ao_xstrdup(char const * pz)
+/*=export_func  optionTimeVal
+ * private:
+ *
+ * what:  process an option with a time duration.
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
+ *
+ * doc:
+ *  Decipher a time duration value.
+=*/
+void
+optionTimeVal(tOptions * opts, tOptDesc * od)
 {
-    char * str;
-    AGDUPSTR(str, pz, "time val str");
-    return str;
-}
+    time_t val;
 
-#define xstrdup(_s) ao_xstrdup(_s)
+    if (INQUERY_CALL(opts, od))
+        return;
 
-#include "parse-duration.c"
+    val = parse_duration(od->optArg.argString);
+    if (val == BAD_TIME) {
+        fprintf(stderr, zNotDuration, opts->pzProgName, od->optArg.argString);
+        if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
+            (*(opts->pUsageProc))(opts, EXIT_FAILURE);
+    }
 
-#undef xstrdup
-#endif
+    if (od->fOptState & OPTST_ALLOC_ARG) {
+        AGFREE(od->optArg.argString);
+        od->fOptState &= ~OPTST_ALLOC_ARG;
+    }
 
-/*=export_func  optionTimeVal
+    od->optArg.argInt = (long)val;
+}
+
+/*=export_func  optionTimeDate
  * private:
  *
- * what:  process an option with a time value.
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * what:  process an option with a time and date.
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
  *
  * doc:
- *  Decipher a time duration value.
+ *  Decipher a time and date value.
 =*/
 void
-optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
+optionTimeDate(tOptions * opts, tOptDesc * od)
 {
-    long  val;
-
-    if ((pOD->fOptState & OPTST_RESET) != 0)
+#if defined(HAVE_GETDATE_R) && defined(HAVE_PUTENV)
+    if (INQUERY_CALL(opts, od))
         return;
 
-    val = parse_duration(pOD->optArg.argString);
-    if (errno != 0)
-        goto bad_time;
+    if ((! HAS_pzPkgDataDir(opts)) || (opts->pzPkgDataDir == NULL))
+        goto default_action;
+
+    /*
+     *  Export the DATEMSK environment variable.  getdate_r() uses it to
+     *  find the file with the strptime formats.  If we cannot find the file
+     *  we need ($PKGDATADIR/datemsk), then fall back to just a time duration.
+     */
+    {
+        static char * envptr = NULL;
+
+        if (envptr == NULL) {
+            static char const fmt[] = "DATEMSK=%s/datemsk";
+            envptr = AGALOC(sizeof(fmt) + strlen(opts->pzPkgDataDir), fmt);
+            sprintf(envptr, fmt, opts->pzPkgDataDir);
+
+            putenv(envptr);
+        }
 
-    if (pOD->fOptState & OPTST_ALLOC_ARG) {
-        AGFREE(pOD->optArg.argString);
-        pOD->fOptState &= ~OPTST_ALLOC_ARG;
+        if (access(envptr+8, R_OK) != 0)
+            goto default_action;
     }
 
-    pOD->optArg.argInt = val;
+    /*
+     *  Convert the date to a time since the epoch and stash it in a long int.
+     */
+    {
+        struct tm stm;
+        time_t tm;
+
+        if (getdate_r(od->optArg.argString, &stm) != 0) {
+            fprintf(stderr, zNotDate, opts->pzProgName,
+                    od->optArg.argString);
+            if ((opts->fOptSet & OPTPROC_ERRSTOP) != 0)
+                (*(opts->pUsageProc))(opts, EXIT_FAILURE);
+            return;
+        }
+
+        tm = mktime(&stm);
+
+        if (od->fOptState & OPTST_ALLOC_ARG) {
+            AGFREE(od->optArg.argString);
+            od->fOptState &= ~OPTST_ALLOC_ARG;
+        }
+
+        od->optArg.argInt = tm;
+    }
     return;
 
-bad_time:
-    fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
-    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
-        (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
+ default_action:
 
-    pOD->optArg.argInt = ~0;
+#endif
+    optionTimeVal(opts, od);
+    if (od->optArg.argInt != BAD_TIME)
+        od->optArg.argInt += (long)time(NULL);
 }
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"
  * indent-tabs-mode: nil
  * End:
- * end of autoopts/numeric.c */
+ * end of autoopts/time.c */

+ 129 - 113
libopts/tokenize.c

@@ -1,10 +1,15 @@
+/** \file tokenize.c
+ *
+ *  Tokenize a string, accommodating quoted strings.
+ *
+ * @addtogroup autoopts
+ * @{
+ */
 /*
  *  This file defines the string_tokenize interface
- * Time-stamp:      "2007-11-12 20:40:36 bkorb"
- *
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -16,11 +21,11 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
 #include <errno.h>
@@ -30,16 +35,18 @@
 #define ch_t   unsigned char
 
 /* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
 static void
-copy_cooked( ch_t** ppDest, char const ** ppSrc );
+copy_cooked(ch_t** ppDest, char const ** ppSrc);
 
 static void
-copy_raw( ch_t** ppDest, char const ** ppSrc );
+copy_raw(ch_t** ppDest, char const ** ppSrc);
+
+static token_list_t *
+alloc_token_list(char const * str);
 /* = = = END-STATIC-FORWARD = = = */
 
 static void
-copy_cooked( ch_t** ppDest, char const ** ppSrc )
+copy_cooked(ch_t** ppDest, char const ** ppSrc)
 {
     ch_t* pDest = (ch_t*)*ppDest;
     const ch_t* pSrc  = (const ch_t*)(*ppSrc + 1);
@@ -50,7 +57,7 @@ copy_cooked( ch_t** ppDest, char const ** ppSrc )
         case NUL:   *ppSrc = NULL; return;
         case '"':   goto done;
         case '\\':
-            pSrc += ao_string_cook_escape_char( (char*)pSrc, (char*)&ch, 0x7F );
+            pSrc += ao_string_cook_escape_char((char*)pSrc, (char*)&ch, 0x7F);
             if (ch == 0x7F)
                 break;
             /* FALLTHROUGH */
@@ -67,7 +74,7 @@ copy_cooked( ch_t** ppDest, char const ** ppSrc )
 
 
 static void
-copy_raw( ch_t** ppDest, char const ** ppSrc )
+copy_raw(ch_t** ppDest, char const ** ppSrc)
 {
     ch_t* pDest = *ppDest;
     cc_t* pSrc  = (cc_t*) (*ppSrc + 1);
@@ -85,11 +92,11 @@ copy_raw( ch_t** ppDest, char const ** ppSrc )
             switch (*pSrc) {
             case NUL:   *ppSrc = NULL; return;
             case '\r':
-                if (*(++pSrc) == '\n')
+                if (*(++pSrc) == NL)
                     ++pSrc;
                 continue;
 
-            case '\n':
+            case NL:
                 ++pSrc;
                 continue;
 
@@ -113,6 +120,51 @@ copy_raw( ch_t** ppDest, char const ** ppSrc )
     *ppSrc  = (char const *) pSrc;  /* char following closing quote    */
 }
 
+static token_list_t *
+alloc_token_list(char const * str)
+{
+    token_list_t * res;
+
+    int max_token_ct = 2; /* allow for trailing NULL pointer & NUL on string */
+
+    if (str == NULL) goto enoent_res;
+
+    /*
+     *  Trim leading white space.  Use "ENOENT" and a NULL return to indicate
+     *  an empty string was passed.
+     */
+    str = SPN_WHITESPACE_CHARS(str);
+    if (*str == NUL)  goto enoent_res;
+
+    /*
+     *  Take an approximate count of tokens.  If no quoted strings are used,
+     *  it will be accurate.  If quoted strings are used, it will be a little
+     *  high and we'll squander the space for a few extra pointers.
+     */
+    {
+        char const * pz = str;
+
+        do {
+            max_token_ct++;
+            pz = BRK_WHITESPACE_CHARS(pz+1);
+            pz = SPN_WHITESPACE_CHARS(pz);
+        } while (*pz != NUL);
+
+        res = malloc(sizeof(*res) + (size_t)(pz - str)
+                     + ((size_t)max_token_ct * sizeof(ch_t*)));
+    }
+
+    if (res == NULL)
+        errno = ENOMEM;
+    else res->tkn_list[0] = (ch_t*)(res->tkn_list + (max_token_ct - 1));
+
+    return res;
+
+    enoent_res:
+
+    errno = ENOENT;
+    return NULL;
+}
 
 /*=export_func ao_string_tokenize
  *
@@ -161,10 +213,10 @@ copy_raw( ch_t** ppDest, char const ** ppSrc )
  * @example
  *    #include <stdlib.h>
  *    int ix;
- *    token_list_t* ptl = ao_string_tokenize( some_string )
+ *    token_list_t* ptl = ao_string_tokenize(some_string)
  *    for (ix = 0; ix < ptl->tkn_ct; ix++)
- *       do_something_with_tkn( ptl->tkn_list[ix] );
- *    free( ptl );
+ *       do_something_with_tkn(ptl->tkn_list[ix]);
+ *    free(ptl);
  * @end example
  * Note that everything is freed with the one call to @code{free(3C)}.
  *
@@ -180,106 +232,69 @@ copy_raw( ch_t** ppDest, char const ** ppSrc )
  *  @end itemize
 =*/
 token_list_t*
-ao_string_tokenize( char const* str )
+ao_string_tokenize(char const* str)
 {
-    int max_token_ct = 1; /* allow for trailing NUL on string */
-    token_list_t* res;
-
-    if (str == NULL)  goto bogus_str;
+    token_list_t* res = alloc_token_list(str);
+    ch_t* pzDest;
 
     /*
-     *  Trim leading white space.  Use "ENOENT" and a NULL return to indicate
-     *  an empty string was passed.
-     */
-    while (IS_WHITESPACE_CHAR(*str))  str++;
-    if (*str == NUL) {
-    bogus_str:
-        errno = ENOENT;
-        return NULL;
-    }
-
-    /*
-     *  Take an approximate count of tokens.  If no quoted strings are used,
-     *  it will be accurate.  If quoted strings are used, it will be a little
-     *  high and we'll squander the space for a few extra pointers.
+     *  Now copy each token into the output buffer.
      */
-    {
-        cc_t* pz = (cc_t*)str;
+    if (res == NULL)
+        return res;
 
-        do {
-            max_token_ct++;
-            while (! IS_WHITESPACE_CHAR(*++pz))
-                if (*pz == NUL) goto found_nul;
-            while (IS_WHITESPACE_CHAR(*pz))  pz++;
-        } while (*pz != NUL);
+    pzDest = (ch_t*)(res->tkn_list[0]);
+    res->tkn_ct  = 0;
 
-    found_nul:
-        ;
-    }
-
-    res = malloc( sizeof(*res) + strlen(str) + (max_token_ct * sizeof(ch_t*)) );
-    if (res == NULL) {
-        errno = ENOMEM;
-        return res;
-    }
+    do  {
+        res->tkn_list[ res->tkn_ct++ ] = pzDest;
+        for (;;) {
+            int ch = (ch_t)*str;
+            if (IS_WHITESPACE_CHAR(ch)) {
+            found_white_space:
+                str = SPN_WHITESPACE_CHARS(str+1);
+                break;
+            }
 
-    /*
-     *  Now copy each token into the output buffer.
-     */
-    {
-        ch_t* pzDest = (ch_t*)(res->tkn_list + (max_token_ct + 1));
-        res->tkn_ct  = 0;
-
-        do  {
-            res->tkn_list[ res->tkn_ct++ ] = pzDest;
-            for (;;) {
-                int ch = (ch_t)*str;
-                if (IS_WHITESPACE_CHAR(ch)) {
-                found_white_space:
-                    while (IS_WHITESPACE_CHAR(*++str))  ;
-                    break;
+            switch (ch) {
+            case '"':
+                copy_cooked(&pzDest, &str);
+                if (str == NULL) {
+                    free(res);
+                    errno = EINVAL;
+                    return NULL;
                 }
+                if (IS_WHITESPACE_CHAR(*str))
+                    goto found_white_space;
+                break;
 
-                switch (ch) {
-                case '"':
-                    copy_cooked( &pzDest, &str );
-                    if (str == NULL) {
-                        free(res);
-                        errno = EINVAL;
-                        return NULL;
-                    }
-                    if (IS_WHITESPACE_CHAR(*str))
-                        goto found_white_space;
-                    break;
-
-                case '\'':
-                    copy_raw( &pzDest, &str );
-                    if (str == NULL) {
-                        free(res);
-                        errno = EINVAL;
-                        return NULL;
-                    }
-                    if (IS_WHITESPACE_CHAR(*str))
-                        goto found_white_space;
-                    break;
-
-                case NUL:
-                    goto copy_done;
-
-                default:
-                    str++;
-                    *(pzDest++) = ch;
+            case '\'':
+                copy_raw(&pzDest, &str);
+                if (str == NULL) {
+                    free(res);
+                    errno = EINVAL;
+                    return NULL;
                 }
-            } copy_done:;
+                if (IS_WHITESPACE_CHAR(*str))
+                    goto found_white_space;
+                break;
 
-            /*
-             * NUL terminate the last token and see if we have any more tokens.
-             */
-            *(pzDest++) = NUL;
-        } while (*str != NUL);
+            case NUL:
+                goto copy_done;
 
-        res->tkn_list[ res->tkn_ct ] = NULL;
-    }
+            default:
+                str++;
+                *(pzDest++) = (unsigned char)ch;
+            }
+        } copy_done:;
+
+        /*
+         * NUL terminate the last token and see if we have any more tokens.
+         */
+        *(pzDest++) = NUL;
+    } while (*str != NUL);
+
+    res->tkn_list[ res->tkn_ct ] = NULL;
 
     return res;
 }
@@ -289,7 +304,7 @@ ao_string_tokenize( char const* str )
 #include <string.h>
 
 int
-main( int argc, char** argv )
+main(int argc, char** argv)
 {
     if (argc == 1) {
         printf("USAGE:  %s arg [ ... ]\n", *argv);
@@ -297,15 +312,15 @@ main( int argc, char** argv )
     }
     while (--argc > 0) {
         char* arg = *(++argv);
-        token_list_t* p = ao_string_tokenize( arg );
+        token_list_t* p = ao_string_tokenize(arg);
         if (p == NULL) {
-            printf( "Parsing string ``%s'' failed:\n\terrno %d (%s)\n",
-                    arg, errno, strerror( errno ));
+            printf("Parsing string ``%s'' failed:\n\terrno %d (%s)\n",
+                   arg, errno, strerror(errno));
         } else {
             int ix = 0;
-            printf( "Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct );
+            printf("Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct);
             do {
-                printf( " %3d:  ``%s''\n", ix+1, p->tkn_list[ix] );
+                printf(" %3d:  ``%s''\n", ix+1, p->tkn_list[ix]);
             } while (++ix < p->tkn_ct);
             free(p);
         }
@@ -314,7 +329,8 @@ main( int argc, char** argv )
 }
 #endif
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

File diff suppressed because it is too large
+ 891 - 311
libopts/usage.c


+ 0 - 120
libopts/value-type.c

@@ -1,120 +0,0 @@
-/* ANSI-C code produced by gperf version 3.0.2 */
-
-
-#if 0 /* gperf build options: */
-// %struct-type
-// %language=ANSI-C
-// %includes
-// %global-table
-// %omit-struct-type
-// %readonly-tables
-// %compare-strncmp
-// 
-// %define slot-name               vtp_name
-// %define hash-function-name      value_type_hash
-// %define lookup-function-name    find_value_type_name
-// %define word-array-name         value_type_table
-// %define initializer-suffix      ,VTP_COUNT_KWD
-#endif /* gperf build options: */
-
-#include "value-type.h"
-
-typedef struct {
-    char const *    vtp_name;
-    value_type_enum_t   vtp_id;
-} value_type_map_t;
-#include <string.h>
-
-/* maximum key range = 20, duplicates = 0 */
-
-#ifdef __GNUC__
-#else
-#ifdef __cplusplus
-#endif
-#endif
-inline static unsigned int
-value_type_hash (register const char *str, register unsigned int len)
-{
-  static const unsigned char asso_values[] =
-    {
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 10, 23, 23, 23, 23, 23, 23, 23, 23,
-      23,  5, 23, 23,  5,  0,  0, 23, 15, 23,
-      23, 10, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
-      23, 23, 23, 23, 23, 23
-    };
-  return len + asso_values[(unsigned char)str[2]];
-}
-
-static const value_type_map_t value_type_table[] =
-  {
-    {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
-    {"",VTP_COUNT_KWD},
-    {"set",             VTP_KWD_SET},
-    {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
-    {"nested",          VTP_KWD_NESTED},
-    {"integer",         VTP_KWD_INTEGER},
-    {"",VTP_COUNT_KWD},
-    {"bool",            VTP_KWD_BOOL},
-    {"",VTP_COUNT_KWD},
-    {"string",          VTP_KWD_STRING},
-    {"boolean",         VTP_KWD_BOOLEAN},
-    {"",VTP_COUNT_KWD},
-    {"set-membership",  VTP_KWD_SET_MEMBERSHIP},
-    {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
-    {"keyword",         VTP_KWD_KEYWORD},
-    {"",VTP_COUNT_KWD},
-    {"hierarchy",       VTP_KWD_HIERARCHY},
-    {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
-    {"invalid",         VTP_KWD_INVALID}
-  };
-
-#ifdef __GNUC__
-#endif
-static inline const value_type_map_t *
-find_value_type_name (register const char *str, register unsigned int len)
-{
-  if (len <= 14 && len >= 3)
-    {
-      register int key = value_type_hash (str, len);
-
-      if (key <= 22 && key >= 0)
-        {
-          register const char *s = value_type_table[key].vtp_name;
-
-          if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
-            return &value_type_table[key];
-        }
-    }
-  return 0;
-}
-
-
-value_type_enum_t
-find_value_type_id(char const * str, unsigned int len)
-{
-    const value_type_map_t * p =
-        find_value_type_name(str, len);
-    return (p == 0) ? VTP_KWD_INVALID : p->vtp_id;
-}

+ 0 - 25
libopts/value-type.h

@@ -1,25 +0,0 @@
-/*
- *  Generated header for gperf generated source Sat Aug  8 10:14:55 PDT 2009
- *  This file enumerates the list of names and declares the
- *  procedure for mapping string names to the enum value.
- */
-#ifndef AUTOOPTS_VALUE_TYPE_H_GUARD
-#define AUTOOPTS_VALUE_TYPE_H_GUARD 1
-
-typedef enum {
-    VTP_KWD_INVALID,
-    VTP_KWD_STRING,
-    VTP_KWD_INTEGER,
-    VTP_KWD_BOOLEAN,
-    VTP_KWD_BOOL,
-    VTP_KWD_KEYWORD,
-    VTP_KWD_SET,
-    VTP_KWD_SET_MEMBERSHIP,
-    VTP_KWD_NESTED,
-    VTP_KWD_HIERARCHY,
-    VTP_COUNT_KWD
-} value_type_enum_t;
-
-extern value_type_enum_t
-find_value_type_id(char const * str, unsigned int len);
-#endif /* AUTOOPTS_VALUE_TYPE_H_GUARD */

+ 157 - 77
libopts/version.c

@@ -1,15 +1,16 @@
 
-/*  $Id: version.c,v 4.19 2009/08/01 17:43:06 bkorb Exp $
- * Time-stamp:      "2008-07-27 10:11:30 bkorb"
+/** \file version.c
  *
  *  This module implements the default usage procedure for
  *  Automated Options.  It may be overridden, of course.
+ *
+ * @addtogroup autoopts
+ * @{
  */
-
 /*
  *  This file is part of AutoOpts, a companion to AutoGen.
  *  AutoOpts is free software.
- *  AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
+ *  AutoOpts is Copyright (C) 1992-2014 by Bruce Korb - all rights reserved
  *
  *  AutoOpts is available under any one of two licenses.  The license
  *  in use must be one of these two and the choice is under the control
@@ -21,19 +22,13 @@
  *   The Modified Berkeley Software Distribution License
  *      See the file "COPYING.mbsd"
  *
- *  These files have the following md5sums:
+ *  These files have the following sha256 sums:
  *
- *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
- *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
- *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
+ *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
+ *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
+ *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
  */
 
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
-/* = = = END-STATIC-FORWARD = = = */
-
 /*=export_func  optionVersion
  *
  * what:     return the compiled AutoOpts version number
@@ -44,111 +39,196 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
  *  The returned string cannot be modified.
 =*/
 char const*
-optionVersion( void )
+optionVersion(void)
 {
-    static char const zVersion[] =
-        STR( AO_CURRENT.AO_REVISION );
+    static char const ver[] = OPTIONS_DOTTED_VERSION;
+    return ver;
+}
 
-    return zVersion;
+static void
+emit_first_line(
+    FILE * fp, char const * alt1, char const * alt2, char const * alt3)
+{
+    char const * p = (alt1 != NULL) ? alt1 : ((alt2 != NULL) ? alt2 : alt3);
+    char const * e;
+    if (p == NULL)
+        return;
+    e = strchr(p, NL);
+    if (e == NULL)
+        fputs(p, fp);
+    else
+        fwrite(p, 1, (e - p), fp);
+    fputc(NL, fp);
 }
 
+/**
+ * Select among various ways to emit version information.
+ *
+ * @param[in] o   the option descriptor
+ * @param[in] fp  the output stream
+ */
+static void
+emit_simple_ver(tOptions * o, FILE * fp)
+{
+    emit_first_line(fp, o->pzFullVersion, o->pzCopyright, o->pzUsageTitle);
+}
 
+/**
+ * print the version with a copyright notice.
+ *
+ * @param[in] o   the option descriptor
+ * @param[in] fp  the output stream
+ */
 static void
-printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
+emit_copy_full(tOptions * o, FILE * fp)
 {
-    char swCh;
+    if (o->pzCopyright != NULL)
+        fputs(o->pzCopyright, fp);
+
+    else if (o->pzFullVersion != NULL)
+        fputs(o->pzFullVersion, fp);
+
+    else
+        emit_first_line(fp, o->pzUsageTitle, NULL, NULL);
+    
+    if (HAS_pzPkgDataDir(o) && (o->pzPackager != NULL)) {
+        fputc(NL, fp);
+        fputs(o->pzPackager, fp);
+
+    } else if (o->pzBugAddr != NULL) {
+        fputc(NL, fp);
+        fprintf(fp, zPlsSendBugs, o->pzBugAddr);
+    }
+}
+
+/**
+ * print the version and any copyright notice.
+ * The version with a full copyright and additional notes.
+ *
+ * @param[in] opts  the option descriptor
+ * @param[in] fp    the output stream
+ */
+static void
+emit_copy_note(tOptions * opts, FILE * fp)
+{
+    if (opts->pzCopyright != NULL)
+        fputs(opts->pzCopyright, fp);
+
+    if (opts->pzCopyNotice != NULL)
+        fputs(opts->pzCopyNotice, fp);
+
+    fputc(NL, fp);
+    fprintf(fp, zao_ver_fmt, optionVersion());
+    
+    if (HAS_pzPkgDataDir(opts) && (opts->pzPackager != NULL)) {
+        fputc(NL, fp);
+        fputs(opts->pzPackager, fp);
+
+    } else if (opts->pzBugAddr != NULL) {
+        fputc(NL, fp);
+        fprintf(fp, zPlsSendBugs, opts->pzBugAddr);
+    }
+}
+
+/**
+ * Handle the version printing.  We must see how much information
+ * is being requested and select the correct printing routine.
+ */
+static void
+print_ver(tOptions * opts, tOptDesc * od, FILE * fp, bool call_exit)
+{
+    char ch;
+
+    if (opts <= OPTPROC_EMIT_LIMIT)
+        return;
 
     /*
-     *  IF the optional argument flag is off, or the argument is not provided,
-     *  then just print the version.
+     *  IF we have an argument for this option, use it
+     *  Otherwise, default to version only or copyright note,
+     *  depending on whether the layout is GNU standard form or not.
      */
-    if (  ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
-       || (pOD->optArg.argString == NULL))
-         swCh = 'v';
-    else swCh = tolower(pOD->optArg.argString[0]);
-
-    if (pOpts->pzFullVersion != NULL) {
-        fputs( pOpts->pzFullVersion, fp );
-        fputc( '\n', fp );
-
-    } else {
-        char const *pz = pOpts->pzUsageTitle;
-        do { fputc(*pz, fp); } while (*(pz++) != '\n');
+    if (  (od->fOptState & OPTST_ARG_OPTIONAL)
+       && (od->optArg.argString != NULL)
+       && (od->optArg.argString[0] != NUL))
+
+        ch = od->optArg.argString[0];
+
+    else {
+        set_usage_flags(opts, NULL);
+        ch = (opts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
     }
 
-    switch (swCh) {
+    switch (ch) {
     case NUL: /* arg provided, but empty */
-    case 'v':
-        break;
-
-    case 'c':
-        if (pOpts->pzCopyright != NULL) {
-            fputs( pOpts->pzCopyright, fp );
-            fputc( '\n', fp );
-        }
-        fprintf( fp, zAO_Ver, optionVersion() );
-        if (pOpts->pzBugAddr != NULL)
-            fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
-        break;
-
-    case 'n':
-        if (pOpts->pzCopyright != NULL) {
-            fputs( pOpts->pzCopyright, fp );
-            fputc( '\n', fp );
-            fputc( '\n', fp );
-        }
-
-        if (pOpts->pzCopyNotice != NULL) {
-            fputs( pOpts->pzCopyNotice, fp );
-            fputc( '\n', fp );
-        }
-
-        fprintf( fp, zAO_Ver, optionVersion() );
-        if (pOpts->pzBugAddr != NULL)
-            fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
-        break;
+    case 'v': case 'V': emit_simple_ver(opts, fp); break;
+    case 'c': case 'C': emit_copy_full( opts, fp); break;
+    case 'n': case 'N': emit_copy_note( opts, fp); break;
 
     default:
-        fprintf( stderr, zBadVerArg, swCh );
-        exit( EXIT_FAILURE );
+        fprintf(stderr, zBadVerArg, ch);
+        option_exits(EXIT_FAILURE);
     }
 
-    exit( EXIT_SUCCESS );
+    fflush(fp);
+    if (ferror(fp))
+        fserr_exit(opts->pzProgName, zwriting,
+                   (fp == stdout) ? zstdout_name : zstderr_name);
+
+    if (call_exit)
+        option_exits(EXIT_SUCCESS);
 }
 
 /*=export_func  optionPrintVersion
- * private:
  *
  * what:  Print the program version
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
  *
  * doc:
  *  This routine will print the version to stdout.
 =*/
 void
-optionPrintVersion( tOptions*  pOpts, tOptDesc*  pOD )
+optionPrintVersion(tOptions * opts, tOptDesc * od)
 {
-    printVersion( pOpts, pOD, stdout );
+    print_ver(opts, od, print_exit ? stderr : stdout, true);
+}
+
+/*=export_func  optionPrintVersionAndReturn
+ *
+ * what:  Print the program version
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
+ *
+ * doc:
+ *  This routine will print the version to stdout and return
+ *  instead of exiting.  Please see the source for the
+ *  @code{print_ver} funtion for details on selecting how
+ *  verbose to be after this function returns.
+=*/
+void
+optionPrintVersionAndReturn(tOptions * opts, tOptDesc * od)
+{
+    print_ver(opts, od, print_exit ? stderr : stdout, false);
 }
 
 /*=export_func  optionVersionStderr
  * private:
  *
  * what:  Print the program version to stderr
- * arg:   + tOptions* + pOpts    + program options descriptor +
- * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
+ * arg:   + tOptions* + opts + program options descriptor +
+ * arg:   + tOptDesc* + od   + the descriptor for this arg +
  *
  * doc:
  *  This routine will print the version to stderr.
 =*/
 void
-optionVersionStderr( tOptions*  pOpts, tOptDesc*  pOD )
+optionVersionStderr(tOptions * opts, tOptDesc * od)
 {
-    printVersion( pOpts, pOD, stderr );
+    print_ver(opts, od, stderr, true);
 }
 
-/*
+/** @}
+ *
  * Local Variables:
  * mode: C
  * c-file-style: "stroustrup"

+ 0 - 111
libopts/xat-attribute.c

@@ -1,111 +0,0 @@
-/* ANSI-C code produced by gperf version 3.0.2 */
-
-
-#if 0 /* gperf build options: */
-// %struct-type
-// %language=ANSI-C
-// %includes
-// %global-table
-// %omit-struct-type
-// %readonly-tables
-// %compare-strncmp
-// 
-// %define slot-name               xat_name
-// %define hash-function-name      xat_attribute_hash
-// %define lookup-function-name    find_xat_attribute_name
-// %define word-array-name         xat_attribute_table
-// %define initializer-suffix      ,XAT_COUNT_KWD
-#endif /* gperf build options: */
-
-#include "xat-attribute.h"
-
-typedef struct {
-    char const *    xat_name;
-    xat_attribute_enum_t   xat_id;
-} xat_attribute_map_t;
-#include <string.h>
-
-/* maximum key range = 9, duplicates = 0 */
-
-#ifdef __GNUC__
-#else
-#ifdef __cplusplus
-#endif
-#endif
-inline static unsigned int
-xat_attribute_hash (register const char *str, register unsigned int len)
-{
-  static const unsigned char asso_values[] =
-    {
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13,  0,
-      13, 13, 13, 13, 13,  5, 13,  5, 13,  0,
-      13, 13, 13, 13, 13, 13,  0,  0, 13,  0,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-      13, 13, 13, 13, 13, 13
-    };
-  return len + asso_values[(unsigned char)str[0]];
-}
-
-static const xat_attribute_map_t xat_attribute_table[] =
-  {
-    {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD},
-    {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD},
-    {"type",            XAT_KWD_TYPE},
-    {"words",           XAT_KWD_WORDS},
-    {"cooked",          XAT_KWD_COOKED},
-    {"members",         XAT_KWD_MEMBERS},
-    {"uncooked",        XAT_KWD_UNCOOKED},
-    {"keep",            XAT_KWD_KEEP},
-    {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD},
-    {"invalid",         XAT_KWD_INVALID}
-  };
-
-#ifdef __GNUC__
-#endif
-static inline const xat_attribute_map_t *
-find_xat_attribute_name (register const char *str, register unsigned int len)
-{
-  if (len <= 8 && len >= 4)
-    {
-      register int key = xat_attribute_hash (str, len);
-
-      if (key <= 12 && key >= 0)
-        {
-          register const char *s = xat_attribute_table[key].xat_name;
-
-          if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
-            return &xat_attribute_table[key];
-        }
-    }
-  return 0;
-}
-
-
-xat_attribute_enum_t
-find_xat_attribute_id(char const * str, unsigned int len)
-{
-    const xat_attribute_map_t * p =
-        find_xat_attribute_name(str, len);
-    return (p == 0) ? XAT_KWD_INVALID : p->xat_id;
-}

+ 0 - 0
libopts/xat-attribute.h


Some files were not shown because too many files changed in this diff