ChangeLog
-gsoc_sntp/sntp-opts.c
-gsoc_sntp/sntp-opts.h
-gsoc_sntp/sntp-opts.texi
-gsoc_sntp/sntp.1
ntpd/ntpd-opts.c
ntpd/ntpd-opts.h
ntpd/ntpd-opts.texi
+* sntp: out with the old, in with the new.
* [Bug 1281] Build ntpd on Windows without big SDK download, burn,
and install by checking in essentially unchanging messages.mc build
products to avoid requiring mc.exe, which is not included with VC++
adjtimed \
clockstuff \
kernel \
- gsoc_sntp \
sntp \
util \
$(NULL)
adjtimed \
clockstuff \
kernel \
- gsoc_sntp \
sntp \
util \
$(NULL)
touch ntpd/ntp_parser.[ch]
cp bincheck.mf sntp/
-cp bincheck.mf gsoc_sntp/
${AUTORECONF} -i -v
AC_CONFIG_FILES(util/Makefile)
AC_CONFIG_SUBDIRS(sntp)
-AC_CONFIG_SUBDIRS(gsoc_sntp)
AC_OUTPUT
+++ /dev/null
-# Makefile.am for JMK's SNTP, by Harlan Stenn
-
-AUTOMAKE_OPTIONS = foreign
-ACLOCAL_AMFLAGS= -I ../m4 -I libopts/m4
-
-AM_CPPFLAGS= $(LIBOPTS_CFLAGS) -I$(top_srcdir)/../include
-LDADD= $(LIBOPTS_LDADD) -lm ../libntp/libntp.a
-
-NULL=
-
-###
-#bindir= ${exec_prefix}/${BINSUBDIR}
-#bin_PROGRAMS= sntp
-###
-noinst_PROGRAMS= sntp
-###
-run_ag= cd $(srcdir) && autogen -L ../include --writable
-
-SUBDIRS=
-if NEED_LIBOPTS
-SUBDIRS+= libopts
-endif
-SUBDIRS+= .
-
-sntp_SOURCES = \
- crypto.c \
- crypto.h \
- data_formats.h \
- header.h \
- kod_management.c \
- kod_management.h \
- log.c \
- log.h \
- main.c \
- netutils.h \
- networking.c \
- networking.h \
- sntp-opts.c \
- sntp-opts.h \
- utilities.c \
- utilities.h \
- $(NULL)
-
-#dist_man_MANS= sntp.1
-
-EXTRA_DIST= bincheck.mf \
- COPYRIGHT \
- sntp-opts.def sntp.1 sntp-opts.texi sntp-opts.menu \
- $(NULL)
-OLD_EXTRA_DIST= \
- autogen-version.def version.def version.m4
-BUILT_SOURCES= check-autogen-version.def check-version.def check-version.m4 \
- sntp-opts.c sntp-opts.h sntp.1 sntp-opts.texi sntp-opts.menu
-#man_MANS= sntp.1
-noinst_MANS= sntp.1
-
-
-FRC:
-check-autogen-version.def: FRC
-foo1:
- @cd $(srcdir) \
- && test -r ../include/autogen-version.def \
- && ( if cmp -s ../include/autogen-version.def autogen-version.def; \
- then : ; \
- else cp ../include/autogen-version.def autogen-version.def; \
- echo "Installing new sntp/autogen-version.def file"; \
- fi )
-
-check-version.def: FRC
-foo2:
- @cd $(srcdir) \
- && test -r ../include/version.def \
- && ( if cmp -s ../include/version.def version.def; \
- then : ; \
- else cp ../include/version.def version.def; \
- echo "Installing new sntp/version.def file"; \
- fi )
-
-check-version.m4: FRC
-foo3:
- @cd $(srcdir) \
- && test -r ../version.m4 \
- && ( if cmp -s ../version.m4 version.m4; \
- then : ; \
- else cp ../version.m4 version.m4; \
- echo "Installing new sntp/version.m4 file"; \
- fi )
-
-$(srcdir)/sntp-opts.h: $(srcdir)/sntp-opts.c
-$(srcdir)/sntp-opts.c: $(srcdir)/sntp-opts.def $(srcdir)/../include/version.def
- $(run_ag) sntp-opts.def
-
-$(srcdir)/sntp.1: $(srcdir)/sntp-opts.def $(srcdir)/../include/version.def
- $(run_ag) -Tagman1.tpl -bsntp sntp-opts.def
-
-$(srcdir)/sntp-opts.texi $(srcdir)/sntp-opts.menu: $(srcdir)/sntp-opts.def $(srcdir)/../include/version.def
- $(run_ag) -Taginfo.tpl -DLEVEL=section sntp-opts.def
-
-include bincheck.mf
+++ /dev/null
-# -*- Autoconf -*-
-# Process this file with autoconf to produce a configure script.
-m4_include([../version.m4])
-AC_INIT([sntp], [VERSION_NUMBER])
-
-# Increment sntp_configure_cache_version by one for each change to
-# configure.ac or .m4 files which invalidates cached values from
-# previous versions.
-#
-# If the change affects cache variables used only by the main NTP
-# configure.ac, then only its version number should be bumped, while
-# the subdir configure.ac version numbers should be unchanged. The
-# same is true for a test/variable that is used only by one subdir
-# being changed incompatibly; only that subdir's cache version needs
-# bumping.
-#
-# If a change affects variables shared by all NTP configure scripts,
-# please bump the version numbers of all three. If you are not sure,
-# the safe choice is to bump all three on any cache-invalidating change.
-#
-# In order to avoid the risk of version stamp collision between -stable
-# and -dev branches, do not simply increment the version, instead use
-# the date YYYYMMDD optionally with -HHMM if there is more than one
-# bump in a day.
-
-sntp_configure_cache_version=20090503
-
-# When the version of config.cache and configure do not
-# match, NTP_CACHEVERSION will flush the cache.
-
-NTP_CACHEVERSION([sntp], [$sntp_configure_cache_version])
-
-AM_INIT_AUTOMAKE
-AC_CANONICAL_HOST
-dnl the 'build' machine is where we run configure and compile
-dnl the 'host' machine is where the resulting stuff runs.
-AC_DEFINE_UNQUOTED([STR_SYSTEM], "$host", [canonical system (cpu-vendor-os) of where we should run])
-AC_CONFIG_HEADER([config.h])
-dnl AC_ARG_PROGRAM
-AC_PREREQ([2.53])
-
-# Checks for programs.
-AC_PROG_CC
-
-# AC_PROG_CC_STDC has two functions. It attempts to find a compiler
-# capable of C99, or failing that, for C89. CC is set afterward with
-# the selected invocation, such as "gcc --std=gnu99". Also, the
-# ac_cv_prog_cc_stdc variable is no if the compiler selected for CC
-# does not accept C89.
-
-AC_PROG_CC_STDC
-
-case "$ac_cv_prog_cc_stdc" in
- no)
- AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile SNTP ]
- [version 4.2.5 and higher.])
-esac
-
-case "$GCC" in
- yes)
- SAVED_CFLAGS_AC="$CFLAGS"
- CFLAGS="$CFLAGS -Wstrict-overflow"
- AC_CACHE_CHECK(
- [if $CC can handle -Wstrict-overflow],
- ac_cv_gcc_Wstrict_overflow,
- [
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM([], [])],
- [ac_cv_gcc_Wstrict_overflow=yes],
- [ac_cv_gcc_Wstrict_overflow=no]
- )
- ]
- )
- CFLAGS="$SAVED_CFLAGS_AC"
- SAVED_CFLAGS_AC=
-
- CFLAGS="$CFLAGS -Wall"
- # CFLAGS="$CFLAGS -Wcast-align"
- CFLAGS="$CFLAGS -Wcast-qual"
- # CFLAGS="$CFLAGS -Wconversion"
- # CFLAGS="$CFLAGS -Werror"
- # CFLAGS="$CFLAGS -Wextra"
- # CFLAGS="$CFLAGS -Wfloat-equal"
- CFLAGS="$CFLAGS -Wmissing-prototypes"
- CFLAGS="$CFLAGS -Wpointer-arith"
- CFLAGS="$CFLAGS -Wshadow"
- CFLAGS="$CFLAGS -Wstrict-prototypes"
- # CFLAGS="$CFLAGS -Wtraditional"
- # CFLAGS="$CFLAGS -Wwrite-strings"
- case "$ac_cv_gcc_Wstrict_overflow" in
- yes)
- CFLAGS="$CFLAGS -Wstrict-overflow"
- esac
-esac
-
-# HMS: These need to be moved to AM_CPPFLAGS and/or AM_CFLAGS
-case "$host" in
- *-*-solaris*)
- # see "man standards".
- # -D_XOPEN_SOURCE=500 is probably OK for c89 and before
- # -D_XOPEN_SOURCE=600 seems OK for c99
- #CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500 -D__EXTENSIONS__"
- CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
- libxnet=-lxnet
- ;;
-esac
-
-AC_DISABLE_SHARED
-
-# NTP has (so far) been relying on leading-edge autogen.
-# Therefore, by default:
-# - use the version we ship with
-# - do not install it
-# - build a static copy (AC_DISABLE_SHARED - done earlier)
-case "${enable_local_libopts+set}" in
- set) ;;
- *) enable_local_libopts=yes ;;
-esac
-case "${enable_libopts_install+set}" in
- set) ;;
- *) enable_libopts_install=no ;;
-esac
-LIBOPTS_CHECK([libopts])
-
-m4_defun([_LT_AC_LANG_CXX_CONFIG], [:])
-m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
-
-AC_PROG_LIBTOOL
-
-# Checks for libraries.
-
-AC_CHECK_FUNC([gethostent], ,
- [AC_SEARCH_LIBS([gethostent], [nsl], , , [$libxnet -lsocket])])
-AC_CHECK_FUNC([openlog], ,
- [AC_SEARCH_LIBS([openlog], [gen], ,
- [AC_SEARCH_LIBS([openlog], [syslog], , , [$libxnet -lsocket])])])
-
-AC_CHECK_FUNC([setsockopt], ,
- [AC_SEARCH_LIBS([setsockopt], [socket xnet])])
-
-# Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS([netdb.h netinet/in.h stdlib.h string.h strings.h syslog.h])
-AC_CHECK_HEADERS([sys/socket.h sys/time.h])
-AC_HEADER_TIME
-
-# Checks for typedefs, structures, and compiler characteristics.
-AC_HEADER_STDBOOL
-AC_C_CONST
-AC_TYPE_SIZE_T
-
-AC_C_INLINE
-
-case "$ac_cv_c_inline" in
- '')
- ;;
- *)
- AC_DEFINE(HAVE_INLINE,1,[inline keyword or macro available])
- AC_SUBST(HAVE_INLINE)
-esac
-
-AC_C_CHAR_UNSIGNED dnl CROSS_COMPILE?
-AC_CHECK_SIZEOF([signed char])
-AC_CHECK_SIZEOF([int])
-AC_CHECK_SIZEOF([long])
-
-AC_CHECK_TYPES([s_char])
-case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
- *yes)
- # We have a typedef for s_char. Might as well believe it...
- ;;
- no0no)
- # We have signed chars, can't say 'signed char', no s_char typedef.
- AC_DEFINE([NEED_S_CHAR_TYPEDEF], 1, [Do we need an s_char typedef?])
- ;;
- no1no)
- # We have signed chars, can say 'signed char', no s_char typedef.
- AC_DEFINE([NEED_S_CHAR_TYPEDEF])
- ;;
- yes0no)
- # We have unsigned chars, can't say 'signed char', no s_char typedef.
- AC_MSG_ERROR([No way to specify a signed character!])
- ;;
- yes1no)
- # We have unsigned chars, can say 'signed char', no s_char typedef.
- AC_DEFINE([NEED_S_CHAR_TYPEDEF])
- ;;
-esac
-AC_TYPE_UID_T
-
-AC_MSG_CHECKING([type of socklen arg for getsockname()])
-AC_CACHE_VAL(ac_cv_func_getsockname_arg2,dnl
-[AC_CACHE_VAL(ac_cv_func_getsockname_socklen_type,dnl
- [for ac_cv_func_getsockname_arg2 in 'struct sockaddr *' 'void *'; do
- for ac_cv_func_getsockname_socklen_type in 'socklen_t' 'size_t' 'unsigned int' 'int'; do
- AC_TRY_COMPILE(dnl
-[#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-extern getsockname (int, $ac_cv_func_getsockname_arg2, $ac_cv_func_getsockname_socklen_type *);],,dnl
- [ac_not_found=no ; break 2], ac_not_found=yes)
- done
- done
- ])dnl AC_CACHE_VAL
-])dnl AC_CACHE_VAL
-if test "$ac_not_found" = yes; then
- ac_cv_func_getsockname_socklen_type='socklen_t'
-fi
-AC_MSG_RESULT([$ac_cv_func_getsockname_socklen_type])
-AC_DEFINE_UNQUOTED([GETSOCKNAME_SOCKLEN_TYPE],
- $ac_cv_func_getsockname_socklen_type,
- [What is getsockname()'s socklen type?])
-
-AC_CACHE_CHECK(for struct sockaddr_storage, ac_cv_struct_sockaddr_storage,
-[AC_TRY_COMPILE([
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-],[
-struct sockaddr_storage n;],
- ac_cv_struct_sockaddr_storage=yes,
- ac_cv_struct_sockaddr_storage=no)
-])
-if test $ac_cv_struct_sockaddr_storage = yes; then
- AC_DEFINE([HAVE_STRUCT_SOCKADDR_STORAGE], 1, [Does a system header define struct sockaddr_storage?])
-fi
-
-AC_CACHE_CHECK([for ss_family field in struct sockaddr_storage],
- ac_cv_have_ss_family_in_struct_ss, [
- AC_TRY_COMPILE(
- [
-#include <sys/types.h>
-#include <sys/socket.h>
- ],
- [ struct sockaddr_storage s; s.ss_family = 1; ],
- [ ac_cv_have_ss_family_in_struct_ss="yes" ],
- [ ac_cv_have_ss_family_in_struct_ss="no" ],
- )
-])
-if test "x$ac_cv_have_ss_family_in_struct_ss" = "xyes" ; then
- AC_DEFINE(HAVE_SS_FAMILY_IN_SS, 1, [Does struct sockaddr_storage have ss_family?])
-else
- # Hack around a problem...
- # HMS: This is $host because we need the -D if we are building *for* it.
- # HMS: 061029: Now that we separate the ss_* checks this is causing
- # a problem - disable it until we get to the bottom of it.
- case "$host" in
- XXX*-*-hpux11.11) CPPFLAGS="$CPPFLAGS -D_NETINET_IN6_H"
- ;;
- esac
-fi
-
-AC_CACHE_CHECK([for __ss_family field in struct sockaddr_storage],
- ac_cv_have___ss_family_in_struct_ss, [
- AC_TRY_COMPILE(
- [
-#include <sys/types.h>
-#include <sys/socket.h>
- ],
- [ struct sockaddr_storage s; s.__ss_family = 1; ],
- [ ac_cv_have___ss_family_in_struct_ss="yes" ],
- [ ac_cv_have___ss_family_in_struct_ss="no" ]
- )
-])
-if test "x$ac_cv_have___ss_family_in_struct_ss" = "xyes" ; then
- AC_DEFINE(HAVE___SS_FAMILY_IN_SS, 1, [Does struct sockaddr_storage have __ss_family?])
-fi
-
-AH_VERBATIM([X_HAVE_SS_FAMILY_IN_SS],
-[/* Handle ss_family */
-#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
-# define ss_family __ss_family
-#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */])
-
-
-AC_ARG_ENABLE([ipv6], [AC_HELP_STRING([--enable-ipv6], [s use IPv6?])])
-
-case "$enable_ipv6" in
- yes|''|autodetect)
- case "$host" in
- powerpc-ibm-aix4*) ;;
- *)
- AC_DEFINE([WANT_IPV6], ,[ISC: Want IPv6?])
- ;;
- esac
- ;;
- no)
- ;;
-esac
-
-
-AC_CACHE_CHECK(
- [for IPv6 structures],
- ac_cv_isc_found_ipv6,
- [
- AC_COMPILE_IFELSE(
- [
- AC_LANG_PROGRAM(
- [
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- ],
- [
- struct sockaddr_in6 sin6;
- ]
- )
- ],
- [ac_cv_isc_found_ipv6=yes],
- [ac_cv_isc_found_ipv6=no]
- )
- ]
-)
-
-#
-# See whether IPv6 support is provided via a Kame add-on.
-# This is done before other IPv6 linking tests so LIBS is properly set.
-#
-AC_MSG_CHECKING([for Kame IPv6 support])
-AC_ARG_WITH(kame,
- [AC_HELP_STRING([--with-kame], [- =/usr/local/v6])],
- use_kame="$withval", use_kame="no")
-
-case "$use_kame" in
- no)
- ;;
- yes)
- kame_path=/usr/local/v6
- ;;
- *)
- kame_path="$use_kame"
- ;;
-esac
-
-case "$use_kame" in
- no)
- AC_MSG_RESULT(no)
- ;;
- *)
- if test -f $kame_path/lib/libinet6.a; then
- AC_MSG_RESULT($kame_path/lib/libinet6.a)
- LIBS="-L$kame_path/lib -linet6 $LIBS"
- else
- AC_MSG_ERROR([$kame_path/lib/libinet6.a not found.
-
-Please choose the proper path with the following command:
-
- configure --with-kame=PATH
-])
- fi
- ;;
-esac
-
-#
-# Whether netinet6/in6.h is needed has to be defined in isc/platform.h.
-# Including it on Kame-using platforms is very bad, though, because
-# Kame uses #error against direct inclusion. So include it on only
-# the platform that is otherwise broken without it -- BSD/OS 4.0 through 4.1.
-# This is done before the in6_pktinfo check because that's what
-# netinet6/in6.h is needed for.
-#
-case "$host" in
- *-bsdi4.[[01]]*)
- AC_DEFINE(ISC_PLATFORM_NEEDNETINET6IN6H, 1, [Do we need netinet6/in6.h?])
- # does anything use LWRES_PLATFORM_NEEDNETINET6IN6H? Can't it use above?
- AC_DEFINE(LWRES_PLATFORM_NEEDNETINET6IN6H, 1, [Do we need netinet6/in6.h?])
- isc_netinet6in6_hack="#include <netinet6/in6.h>"
- ;;
- *)
- isc_netinet6in6_hack=""
-esac
-
-#
-# This is similar to the netinet6/in6.h issue.
-#
-case "$host" in
- *-sco-sysv*uw*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
- AC_DEFINE(ISC_PLATFORM_FIXIN6ISADDR, 1,[Do we need to fix in6isaddr?])
- isc_netinetin6_hack="#include <netinet/in6.h>"
- ;;
- *)
- isc_netinetin6_hack=""
-esac
-
-
-case "$ac_cv_isc_found_ipv6" in
- yes)
- AC_DEFINE(ISC_PLATFORM_HAVEIPV6, ,[have IPv6?])
-
- AC_CACHE_CHECK(
- [for in6_pktinfo],
- ac_cv_have_in6_pktinfo,
- [
- AC_COMPILE_IFELSE(
- [
- AC_LANG_PROGRAM(
- [
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- $isc_netinetin6_hack
- $isc_netinet6in6_hack
- ],
- [
- struct in6_pktinfo xyzzy;
- ]
- )
- ],
- [ac_cv_have_in6_pktinfo=yes],
- [ac_cv_have_in6_pktinfo=no]
- )
- ]
- )
-
- case "$ac_cv_have_in6_pktinfo" in
- yes)
- AC_DEFINE(ISC_PLATFORM_HAVEIN6PKTINFO, , [have struct in6_pktinfo?])
- esac
-
-
- # HMS: Use HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID instead?
- AC_CACHE_CHECK(
- [for sockaddr_in6.sin6_scope_id],
- ac_cv_have_sin6_scope_id,
- [
- AC_COMPILE_IFELSE(
- [
- AC_LANG_PROGRAM(
- [
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- $isc_netinetin6_hack
- $isc_netinet6in6_hack
- ],
- [
- struct sockaddr_in6 xyzzy;
- xyzzy.sin6_scope_id = 0;
- ]
- )
- ],
- [ac_cv_have_sin6_scope_id=yes],
- [ac_cv_have_sin6_scope_id=no]
- )
- ]
- )
-
- case "$ac_cv_have_sin6_scope_id" in
- yes)
- AC_DEFINE(ISC_PLATFORM_HAVESCOPEID, , [have sin6_scope_id?])
- esac
-esac
-
-
-# We need this check run even without ac_cv_isc_found_ipv6=yes
-
-AC_CACHE_CHECK(
- [for in6addr_any],
- ac_cv_have_in6addr_any,
- [
- AC_COMPILE_IFELSE(
- [
- AC_LANG_PROGRAM(
- [
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- $isc_netinetin6_hack
- $isc_netinet6in6_hack
- ],
- [
- struct in6_addr in6;
- in6 = in6addr_any;
- ]
- )
- ],
- [ac_cv_have_in6addr_any=yes],
- [ac_cv_have_in6addr_any=no]
- )
- ]
-)
-
-case "$ac_cv_have_in6addr_any" in
- no)
- AC_DEFINE(ISC_PLATFORM_NEEDIN6ADDRANY, , [missing in6addr_any?])
-esac
-
-
-AC_CACHE_CHECK(
- [for struct if_laddrconf],
- ac_cv_isc_struct_if_laddrconf,
- [
- AC_COMPILE_IFELSE(
- [
- AC_LANG_PROGRAM(
- [
- #include <sys/types.h>
- #include <net/if6.h>
- ],
- [
- struct if_laddrconf a;
- ]
- )
- ],
- [ac_cv_isc_struct_if_laddrconf=yes],
- [ac_cv_isc_struct_if_laddrconf=no]
- )
- ]
-)
-
-case "$ac_cv_isc_struct_if_laddrconf" in
- yes)
- AC_DEFINE(ISC_PLATFORM_HAVEIF_LADDRCONF, , [have struct if_laddrconf?])
-esac
-
-AC_CACHE_CHECK(
- [for struct if_laddrreq],
- ac_cv_isc_struct_if_laddrreq,
- [
- AC_COMPILE_IFELSE(
- [
- AC_LANG_PROGRAM(
- [
- #include <sys/types.h>
- #include <net/if6.h>
- ],
- [
- struct if_laddrreq a;
- ]
- )
- ],
- [ac_cv_isc_struct_if_laddrreq=yes],
- [ac_cv_isc_struct_if_laddrreq=no]
- )
- ]
-)
-
-case "$ac_cv_isc_struct_if_laddrreq" in
- yes)
- AC_DEFINE(ISC_PLATFORM_HAVEIF_LADDRREQ, , [have struct if_laddrreq?])
-esac
-
-
-###
-
-# Hacks
-AC_DEFINE(HAVE_NO_NICE, 1, [sntp does not care about 'nice'])
-AC_DEFINE(HAVE_TERMIOS, 1, [sntp does not care about TTY stuff])
-
-# Checks for library functions.
-AC_FUNC_MALLOC
-AC_CHECK_FUNCS([atexit memset socket])
-
-AC_MSG_CHECKING(for bin subdirectory)
-AC_ARG_WITH(binsubdir,
- [AC_HELP_STRING([--with-binsubdir], [bin ={bin,sbin}])],
- use_binsubdir="$withval", use_binsubdir="bin")
-
-case "$use_binsubdir" in
- bin)
- ;;
- sbin)
- ;;
- *)
- AC_MSG_ERROR([<$use_binsubdir> is illegal - must be "bin" or "sbin"])
- ;;
-esac
-AC_MSG_RESULT($use_binsubdir)
-BINSUBDIR=$use_binsubdir
-AC_SUBST(BINSUBDIR)
-
-AC_CONFIG_FILES([Makefile])
-AC_OUTPUT
+++ /dev/null
-/* Copyright (C) 1996 N.M. Maclaren
- Copyright (C) 1996 The University of Cambridge
-
-This includes all of the 'safe' headers and definitions used across modules.
-No changes should be needed for any system that is even remotely like Unix. */
-
-
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-
-
-#define MAX_SOCKETS 10 /* Maximum number of addresses */
-
-#ifndef LOCKNAME
-# define LOCKNAME "/etc/sntp.pid" /* Stores the pid */
-#endif
-#ifndef SAVENAME
-# define SAVENAME "/etc/sntp.state" /* Stores the recovery state */
-#endif
-
-#define DEBUG
-
-
-
-/* Defined in main.c */
-
-#define op_client 1 /* Behave as a challenge client */
-#define op_listen 2 /* Behave as a listening client */
-
-/* extern const char *argv0;
-
-extern int verbose, operation;
-
-extern const char *lockname;
-
-extern void fatal (int syserr, const char *message, const char *insert);
-
-
-
- Defined in unix.c */
-
-extern void do_nothing (int seconds);
-
-extern int ftty (FILE *file);
-
-extern void set_lock (int lock);
-
-extern void log_message (const char *message);
-
-
-
-/* Defined in internet.c */
-
-/* extern void find_address (struct in_addr *address, int *port, char *hostname,
- int timespan); */
-
-#define PREF_FAM_INET 1
-#define PREF_FAM_INET6 2
-extern void preferred_family(int);
-
-
-/* Defined in socket.c */
-
-extern void open_socket (int which, char *hostnames, int timespan);
-
-extern void write_socket (int which, void *packet, int length);
-
-extern int read_socket (int which, void *packet, int length, int waiting);
-
-extern int flush_socket (int which);
-
-/* extern void close_socket (int which); */
-
-
-
-/* Defined in timing.c */
-
-extern double current_time (double offset);
-
-extern time_t convert_time (double value, int *millisecs);
-
-extern void adjust_time (double difference, int immediate, double ignore);
+++ /dev/null
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- copyright (c) 2009 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.
-
- 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) 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
- 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) 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.
-
-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>.
+++ /dev/null
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- copyright (c) 2009 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.
-
-
- This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
- 0. Additional Definitions.
-
- As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
- "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
- An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
- A "Combined Work" is a work produced by combining or linking an
-Application with the Library. The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
- The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
- The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
- 1. Exception to Section 3 of the GNU GPL.
-
- You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
- 2. Conveying Modified Versions.
-
- If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
- a) under this License, provided that you make a good faith effort to
- ensure that, in the event an Application does not supply the
- function or data, the facility still operates, and performs
- whatever part of its purpose remains meaningful, or
-
- b) under the GNU GPL, with none of the additional permissions of
- this License applicable to that copy.
-
- 3. Object Code Incorporating Material from Library Header Files.
-
- The object code form of an Application may incorporate material from
-a header file that is part of the Library. You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
- a) Give prominent notice with each copy of the object code that the
- Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the object code with a copy of the GNU GPL and this license
- document.
-
- 4. Combined Works.
-
- You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
- a) Give prominent notice with each copy of the Combined Work that
- the Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
- document.
-
- c) For a Combined Work that displays copyright notices during
- execution, include the copyright notice for the Library among
- these notices, as well as a reference directing the user to the
- copies of the GNU GPL and this license document.
-
- d) Do one of the following:
-
- 0) Convey the Minimal Corresponding Source under the terms of this
- License, and the Corresponding Application Code in a form
- suitable for, and under terms that permit, the user to
- recombine or relink the Application with a modified version of
- the Linked Version to produce a modified Combined Work, in the
- manner specified by section 6 of the GNU GPL for conveying
- Corresponding Source.
-
- 1) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (a) uses at run time
- a copy of the Library already present on the user's computer
- system, and (b) will operate properly with a modified version
- of the Library that is interface-compatible with the Linked
- Version.
-
- e) Provide Installation Information, but only if you would otherwise
- be required to provide such information under section 6 of the
- GNU GPL, and only to the extent that such information is
- necessary to install and execute a modified version of the
- Combined Work produced by recombining or relinking the
- Application with a modified version of the Linked Version. (If
- you use option 4d0, the Installation Information must accompany
- the Minimal Corresponding Source and Corresponding Application
- Code. If you use option 4d1, you must provide the Installation
- Information in the manner specified by section 6 of the GNU GPL
- for conveying Corresponding Source.)
-
- 5. Combined Libraries.
-
- You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
- a) Accompany the combined library with a copy of the same work based
- on the Library, uncombined with any other library facilities,
- conveyed under the terms of this License.
-
- b) Give prominent notice with the combined library that part of it
- is a work based on the Library, and explaining where to find the
- accompanying uncombined form of the same work.
-
- 6. Revised Versions of the GNU Lesser General Public License.
-
- The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser 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
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
- If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
-Library.
+++ /dev/null
-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. The name of the author may not be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+++ /dev/null
-## LIBOPTS Makefile
-MAINTAINERCLEANFILES = Makefile.in
-if INSTALL_LIBOPTS
-lib_LTLIBRARIES = libopts.la
-else
-noinst_LTLIBRARIES = libopts.la
-endif
-libopts_la_SOURCES = libopts.c
-libopts_la_CPPFLAGS = -I$(top_srcdir)
-libopts_la_LDFLAGS = -version-info 32:1: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/windows-config.h \
- compat/compat.h compat/pathfind.c compat/snprintf.c \
- compat/strdup.c compat/strchr.c 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
+++ /dev/null
- 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).
-
-Usage Instructions for autoconf/automake/libtoolized projects:
-
-1. Install the unrolled tarball into your package source tree,
- copying ``libopts.m4'' to your autoconf macro directory.
-
- In your bootstrap (pre-configure) script, you can do this:
-
- rm -rf libopts libopts-*
- gunzip -c `autoopts-config libsrc` | tar -xvf -
- mv -f libopts-*.*.* libopts
- cp -fp libopts/m4/*.m4 m4/.
-
- I tend to put my configure auxiliary files in "m4".
- Whatever directory you choose, if it is not ".", then
- be sure to tell autoconf about it with:
-
- AC_CONFIG_AUX_DIR(m4)
-
- 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''.
-
-3. Add the following to your top level ``Makefile.am'' file:
-
- if NEED_LIBOPTS
- 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.
-
-4. Add ``$(LIBOPTS_CFLAGS)'' to relevant compiler flags and
- ``$(LIBOPTS_LDADD)'' to relevant link options whereever
- you need them in your build tree.
-
-5. Make sure your object files explicitly depend upon the
- generated options header file. e.g.:
-
- $(prog_OBJECTS) : prog-opts.h
- prog-opts.h : prog-opts.c
- prog-opts.c : prog-opts.def
- autogen prog-opts.def
-
-6. *OPTIONAL* --
- If you are creating man pages and texi documentation from
- the program options, you will need these rules somewhere, too:
-
- man_MANS = prog.1
- prog.1 : prog-opts.def
- autogen -Tagman1.tpl -bprog prog-opts.def
-
- prog-invoke.texi : prog-opts.def
- autogen -Taginfo.tpl -bprog-invoke 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.
-
-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.
+++ /dev/null
-/*
- * Character mapping generated 08/01/09 11:21:22
- *
- * This file contains the character classifications
- * used by AutoGen and AutoOpts for identifying tokens.
- */
-#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>
-
-# 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
-
-# ifndef HAVE_UINT32_T
-# if SIZEOF_INT == 4
- typedef unsigned int uint32_t;
-# elif SIZEOF_LONG == 4
- typedef unsigned long uint32_t;
-# endif
-# endif
-# endif /* HAVE_*INT*_H header */
-
-#else /* not HAVE_CONFIG_H -- */
-# ifdef __sun
-# include <inttypes.h>
-# else
-# include <stdint.h>
-# endif
-#endif /* HAVE_CONFIG_H */
-
-#if 0 /* mapping specification source (from autogen.map) */
-//
-// %guard autoopts_internal
-// %file ag-char-map.h
-// %table opt-char-cat
-//
-// %comment
-// This file contains the character classifications
-// used by AutoGen and AutoOpts for identifying tokens.
-// %
-//
-// lower-case "a-z"
-// upper-case "A-Z"
-// alphabetic +lower-case +upper-case
-// oct-digit "0-7"
-// dec-digit "89" +oct-digit
-// hex-digit "a-fA-F" +dec-digit
-// alphanumeric +alphabetic +dec-digit
-// var-first "_" +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 "!-~" -"\"#(),;<=>[\\]`{}?*'"
-// end-xml-token "/>" +whitespace
-// graphic "!-~"
-// plus-n-space "+" +whitespace
-// punctuation "!-~" -alphanumeric -"_"
-// suffix "-._" +alphanumeric
-// suffix-fmt "%/" +suffix
-// false-type "nNfF0\x00"
-//
-#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
-};
-#endif /* AUTOOPTS_INTERNAL */
-#endif /* AG_CHAR_MAP_H_GUARD */
+++ /dev/null
-
-/*
- * $Id: autoopts.c,v 4.40 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2009-01-12 02:49:49 bkorb"
- *
- * 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-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
- */
-
-static char const zNil[] = "";
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static tSuccess
-findOptDesc( tOptions* pOpts, tOptState* pOptState );
-
-static tSuccess
-next_opt_arg_must(tOptions* pOpts, tOptState* pOptState);
-
-static tSuccess
-next_opt_arg_may(tOptions* pOpts, tOptState* pOptState);
-
-static tSuccess
-next_opt_arg_none(tOptions* pOpts, tOptState* pOptState);
-
-static tSuccess
-nextOption(tOptions* pOpts, tOptState* pOptState);
-
-static tSuccess
-doPresets( tOptions* pOpts );
-
-static int
-checkConsistency( tOptions* pOpts );
-/* = = = END-STATIC-FORWARD = = = */
-
-LOCAL void *
-ao_malloc( size_t sz )
-{
- void * res = malloc(sz);
- if (res == NULL) {
- fprintf( stderr, "malloc of %d bytes failed\n", (int)sz );
- exit( EXIT_FAILURE );
- }
- return res;
-}
-#undef malloc
-#define malloc(_s) ao_malloc(_s)
-
-LOCAL void *
-ao_realloc( void *p, size_t sz )
-{
- void * res = realloc(p, sz);
- if (res == NULL) {
- fprintf( stderr, "realloc of %d bytes at 0x%p failed\n", (int)sz, p );
- exit( EXIT_FAILURE );
- }
- return res;
-}
-#undef realloc
-#define realloc(_p,_s) ao_realloc(_p,_s)
-
-
-LOCAL void
-ao_free( void *p )
-{
- if (p != NULL)
- free(p);
-}
-#undef free
-#define free(_p) ao_free(_p)
-
-
-LOCAL char *
-ao_strdup( char const *str )
-{
- char * res = strdup(str);
- if (res == NULL) {
- fprintf(stderr, "strdup of %d byte string failed\n", (int)strlen(str));
- exit( EXIT_FAILURE );
- }
- return res;
-}
-#undef strdup
-#define strdup(_p) ao_strdup(_p)
-
-#ifndef HAVE_PATHFIND
-# include "compat/pathfind.c"
-#endif
-
-#ifndef HAVE_SNPRINTF
-# include "compat/snprintf.c"
-#endif
-
-#ifndef HAVE_STRDUP
-# include "compat/strdup.c"
-#endif
-
-#ifndef HAVE_STRCHR
-# include "compat/strchr.c"
-#endif
-
-/*
- * handleOption
- *
- * This routine handles equivalencing, sets the option state flags and
- * invokes the handler procedure, if any.
- */
-LOCAL tSuccess
-handleOption( tOptions* pOpts, tOptState* pOptState )
-{
- /*
- * Save a copy of the option procedure pointer.
- * If this is an equivalence class option, we still want this proc.
- */
- tOptDesc* pOD = pOptState->pOD;
- tOptProc* pOP = pOD->pOptProc;
- if (pOD->fOptState & OPTST_ALLOC_ARG)
- AGFREE(pOD->optArg.argString);
-
- pOD->optArg.argString = pOptState->pzOptArg;
-
- /*
- * IF we are presetting options, then we will ignore any un-presettable
- * options. They are the ones either marked as such.
- */
- if ( ((pOpts->fOptSet & OPTPROC_PRESETTING) != 0)
- && ((pOD->fOptState & OPTST_NO_INIT) != 0)
- )
- return PROBLEM;
-
- /*
- * IF this is an equivalence class option,
- * THEN
- * Save the option value that got us to this option
- * entry. (It may not be pOD->optChar[0], if this is an
- * equivalence entry.)
- * set the pointer to the equivalence class base
- */
- if (pOD->optEquivIndex != NO_EQUIVALENT) {
- tOptDesc* p = pOpts->pOptDesc + pOD->optEquivIndex;
-
- /*
- * IF the current option state has not been defined (set on the
- * command line), THEN we will allow continued resetting of
- * the value. Once "defined", then it must not change.
- */
- if ((pOD->fOptState & OPTST_DEFINED) != 0) {
- /*
- * The equivalenced-to option has been found on the command
- * line before. Make sure new occurrences are the same type.
- *
- * IF this option has been previously equivalenced and
- * it was not the same equivalenced-to option,
- * THEN we have a usage problem.
- */
- if (p->optActualIndex != pOD->optIndex) {
- fprintf( stderr, (char*)zMultiEquiv, p->pz_Name, pOD->pz_Name,
- (pOpts->pOptDesc + p->optActualIndex)->pz_Name);
- return FAILURE;
- }
- } else {
- /*
- * Set the equivalenced-to actual option index to no-equivalent
- * so that we set all the entries below. This option may either
- * never have been selected before, or else it was selected by
- * some sort of "presetting" mechanism.
- */
- p->optActualIndex = NO_EQUIVALENT;
- }
-
- if (p->optActualIndex != pOD->optIndex) {
- /*
- * First time through, copy over the state
- * and add in the equivalence flag
- */
- p->optActualValue = pOD->optValue;
- p->optActualIndex = pOD->optIndex;
- pOptState->flags |= OPTST_EQUIVALENCE;
- }
-
- /*
- * Copy the most recent option argument. set membership state
- * is kept in ``p->optCookie''. Do not overwrite.
- */
- p->optArg.argString = pOD->optArg.argString;
- pOD = p;
-
- } else {
- pOD->optActualValue = pOD->optValue;
- pOD->optActualIndex = pOD->optIndex;
- }
-
- pOD->fOptState &= OPTST_PERSISTENT_MASK;
- pOD->fOptState |= (pOptState->flags & ~OPTST_PERSISTENT_MASK);
-
- /*
- * Keep track of count only for DEFINED (command line) options.
- * IF we have too many, build up an error message and bail.
- */
- if ( (pOD->fOptState & OPTST_DEFINED)
- && (++pOD->optOccCt > pOD->optMaxCt) ) {
-
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
- char const * pzEqv =
- (pOD->optEquivIndex != NO_EQUIVALENT) ? zEquiv : zNil;
-
- fputs( zErrOnly, stderr );
-
- if (pOD->optMaxCt > 1)
- fprintf(stderr, zAtMost, pOD->optMaxCt, pOD->pz_Name, pzEqv);
- else
- fprintf(stderr, zOnlyOne, pOD->pz_Name, pzEqv);
- }
-
- return FAILURE;
- }
-
- /*
- * If provided a procedure to call, call it
- */
- if (pOP != (tpOptProc)NULL)
- (*pOP)( pOpts, pOD );
-
- return SUCCESS;
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * HUNT FOR OPTIONS IN THE ARGUMENT LIST
- *
- * The next four procedures are "private" to nextOption().
- * nextOption() uses findOptDesc() to find the next descriptor and it, in
- * turn, uses longOptionFind() and shortOptionFind() to actually do the hunt.
- *
- * longOptionFind
- *
- * Find the long option descriptor for the current option
- */
-LOCAL tSuccess
-longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState )
-{
- ag_bool disable = AG_FALSE;
- char* pzEq = strchr( pzOptName, '=' );
- tOptDesc* pOD = pOpts->pOptDesc;
- int idx = 0;
- int idxLim = pOpts->optCt;
- int matchCt = 0;
- int matchIdx = 0;
- int nameLen;
- char opt_name_buf[128];
-
- /*
- * IF the value is attached to the name,
- * copy it off so we can NUL terminate.
- */
- if (pzEq != NULL) {
- nameLen = (int)(pzEq - pzOptName);
- if (nameLen >= sizeof(opt_name_buf))
- return FAILURE;
- memcpy(opt_name_buf, pzOptName, nameLen);
- opt_name_buf[nameLen] = NUL;
- pzOptName = opt_name_buf;
- pzEq++;
-
- } else nameLen = strlen( pzOptName );
-
- do {
- if (SKIP_OPT(pOD))
- continue;
-
- if (strneqvcmp( pzOptName, pOD->pz_Name, nameLen ) == 0) {
- /*
- * IF we have a complete match
- * THEN it takes priority over any already located partial
- */
- if (pOD->pz_Name[ nameLen ] == NUL) {
- matchCt = 1;
- matchIdx = idx;
- break;
- }
- }
-
- /*
- * IF there is a disable name
- * *AND* no argument value has been supplied
- * (disabled options may have no argument)
- * *AND* the option name matches the disable name
- * THEN ...
- */
- else if ( (pOD->pz_DisableName != NULL)
- && (strneqvcmp(pzOptName, pOD->pz_DisableName, nameLen) == 0)
- ) {
- disable = AG_TRUE;
-
- /*
- * IF we have a complete match
- * THEN it takes priority over any already located partial
- */
- if (pOD->pz_DisableName[ nameLen ] == NUL) {
- matchCt = 1;
- matchIdx = idx;
- break;
- }
- }
-
- else
- continue;
-
- /*
- * We found a partial match, either regular or disabling.
- * Remember the index for later.
- */
- matchIdx = idx;
-
- if (++matchCt > 1)
- break;
-
- } while (pOD++, (++idx < idxLim));
-
- /*
- * Make sure we either found an exact match or found only one partial
- */
- if (matchCt == 1) {
- /*
- * IF we found a disablement name,
- * THEN set the bit in the callers' flag word
- */
- if (disable)
- pOptState->flags |= OPTST_DISABLED;
-
- pOptState->pOD = pOpts->pOptDesc + matchIdx;
- pOptState->pzOptArg = pzEq;
- pOptState->optType = TOPT_LONG;
- return SUCCESS;
- }
-
- /*
- * IF there is no equal sign
- * *AND* we are using named arguments
- * *AND* there is a default named option,
- * THEN return that option.
- */
- if ( (pzEq == NULL)
- && NAMED_OPTS(pOpts)
- && (pOpts->specOptIdx.default_opt != NO_EQUIVALENT)) {
- pOptState->pOD = pOpts->pOptDesc + pOpts->specOptIdx.default_opt;
-
- pOptState->pzOptArg = pzOptName;
- pOptState->optType = TOPT_DEFAULT;
- return SUCCESS;
- }
-
- /*
- * IF we are to stop on errors (the default, actually)
- * THEN call the usage procedure.
- */
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
- fprintf(stderr, (matchCt == 0) ? zIllOptStr : zAmbigOptStr,
- pOpts->pzProgPath, pzOptName);
- (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE );
- }
-
- return FAILURE;
-}
-
-
-/*
- * shortOptionFind
- *
- * Find the short option descriptor for the current option
- */
-LOCAL tSuccess
-shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState )
-{
- tOptDesc* pRes = pOpts->pOptDesc;
- int ct = pOpts->optCt;
-
- /*
- * Search the option list
- */
- for (;;) {
- /*
- * IF the values match,
- * THEN we stop here
- */
- if ((! SKIP_OPT(pRes)) && (optValue == pRes->optValue)) {
- pOptState->pOD = pRes;
- pOptState->optType = TOPT_SHORT;
- return SUCCESS;
- }
-
- /*
- * Advance to next option description
- */
- pRes++;
-
- /*
- * IF we have searched everything, ...
- */
- if (--ct <= 0)
- break;
- }
-
- /*
- * 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;
- }
-
- /*
- * 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 );
- }
-
- return FAILURE;
-}
-
-
-/*
- * findOptDesc
- *
- * Find the option descriptor for the current option
- */
-static tSuccess
-findOptDesc( tOptions* pOpts, tOptState* pOptState )
-{
- /*
- * 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 ((pOpts->pzCurOpt != NULL) && (*pOpts->pzCurOpt != NUL))
- return shortOptionFind( pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState );
-
- if (pOpts->curOptIdx >= pOpts->origArgCt)
- return PROBLEM; /* NORMAL COMPLETION */
-
- pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx ];
-
- /*
- * IF all arguments must be named options, ...
- */
- if (NAMED_OPTS(pOpts)) {
- char * pz = pOpts->pzCurOpt;
- int def;
- tSuccess res;
- tAoUS * def_opt;
-
- pOpts->curOptIdx++;
-
- if (*pz != '-')
- return longOptionFind(pOpts, pz, pOptState);
-
- /*
- * 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 *)&(pOpts->specOptIdx.default_opt);
- def = *def_opt;
- *def_opt = NO_EQUIVALENT;
- res = longOptionFind(pOpts, pz, pOptState);
- *def_opt = def;
- return res;
- }
-
- /*
- * Note the kind of flag/option marker
- */
- if (*((pOpts->pzCurOpt)++) != '-')
- return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
-
- /*
- * Special hack for a hyphen by itself
- */
- if (*(pOpts->pzCurOpt) == NUL)
- return PROBLEM; /* NORMAL COMPLETION - this + rest are operands */
-
- /*
- * The current argument is to be processed as an option argument
- */
- pOpts->curOptIdx++;
-
- /*
- * We have an option marker.
- * Test the next character for long option indication
- */
- if (pOpts->pzCurOpt[0] == '-') {
- if (*++(pOpts->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 ((pOpts->fOptSet & OPTPROC_LONGOPT) == 0) {
- fprintf( stderr, zIllOptStr, pOpts->pzProgPath,
- zIllegal, pOpts->pzCurOpt-2 );
- return FAILURE;
- }
-
- return longOptionFind( pOpts, pOpts->pzCurOpt, pOptState );
- }
-
- /*
- * If short options are not allowed, then do long
- * option processing. Otherwise the character must be a
- * short (i.e. single character) option.
- */
- if ((pOpts->fOptSet & OPTPROC_SHORTOPT) != 0)
- return shortOptionFind( pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState );
-
- return longOptionFind( pOpts, pOpts->pzCurOpt, pOptState );
-}
-
-
-static tSuccess
-next_opt_arg_must(tOptions* pOpts, tOptState* pOptState)
-{
- /*
- * An option argument is required. Long options can either have
- * a separate command line argument, or an argument attached by
- * the '=' character. Figure out which.
- */
- switch (pOptState->optType) {
- case TOPT_SHORT:
- /*
- * See if an arg string follows the flag character
- */
- if (*++(pOpts->pzCurOpt) == NUL)
- pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx++ ];
- pOptState->pzOptArg = pOpts->pzCurOpt;
- break;
-
- case TOPT_LONG:
- /*
- * See if an arg string has already been assigned (glued on
- * with an `=' character)
- */
- if (pOptState->pzOptArg == NULL)
- pOptState->pzOptArg = pOpts->origArgVect[ pOpts->curOptIdx++ ];
- break;
-
- default:
-#ifdef DEBUG
- fputs( "AutoOpts lib error: option type not selected\n",
- stderr );
- exit( 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 (pOpts->curOptIdx > pOpts->origArgCt) {
- fprintf( stderr, zMisArg, pOpts->pzProgPath,
- pOptState->pOD->pz_Name );
- return FAILURE;
- }
-
- pOpts->pzCurOpt = NULL; /* next time advance to next arg */
- return SUCCESS;
-}
-
-
-static tSuccess
-next_opt_arg_may(tOptions* pOpts, tOptState* pOptState)
-{
- /*
- * An option argument is optional.
- */
- switch (pOptState->optType) {
- case TOPT_SHORT:
- if (*++pOpts->pzCurOpt != NUL)
- pOptState->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 == '-'))
- pOptState->pzOptArg = NULL;
- else {
- pOpts->curOptIdx++; /* argument found */
- pOptState->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 ( (pOptState->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 == '-'))
- pOptState->pzOptArg = NULL;
- else {
- pOpts->curOptIdx++; /* argument found */
- pOptState->pzOptArg = pzLA;
- }
- }
- break;
-
- default:
- case TOPT_DEFAULT:
- fputs(zAO_Woops, stderr );
- exit( EX_SOFTWARE );
- }
-
- /*
- * 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;
-}
-
-
-static tSuccess
-next_opt_arg_none(tOptions* pOpts, tOptState* pOptState)
-{
- /*
- * No option argument. Make sure next time around we find
- * the correct option flag character for short options
- */
- if (pOptState->optType == TOPT_SHORT)
- (pOpts->pzCurOpt)++;
-
- /*
- * It is a long option. Make sure there was no ``=xxx'' argument
- */
- else if (pOptState->pzOptArg != NULL) {
- fprintf(stderr, zNoArg, pOpts->pzProgPath, pOptState->pOD->pz_Name);
- return FAILURE;
- }
-
- /*
- * It is a long option. Advance to next command line argument.
- */
- else
- pOpts->pzCurOpt = NULL;
- return SUCCESS;
-}
-
-/*
- * nextOption
- *
- * Find the option descriptor and option argument (if any) for the
- * next command line argument. DO NOT modify the descriptor. Put
- * all the state in the state argument so that the option can be skipped
- * without consequence (side effect).
- */
-static tSuccess
-nextOption(tOptions* pOpts, tOptState* pOptState)
-{
- {
- tSuccess res;
- res = findOptDesc( pOpts, pOptState );
- if (! SUCCESSFUL( res ))
- return res;
- }
-
- if ( ((pOptState->flags & OPTST_DEFINED) != 0)
- && ((pOptState->pOD->fOptState & OPTST_NO_COMMAND) != 0)) {
- fprintf(stderr, zNotCmdOpt, pOptState->pOD->pz_Name);
- return FAILURE;
- }
-
- pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK);
-
- /*
- * Figure out what to do about option arguments. An argument may be
- * required, not associated with the option, or be optional. We detect the
- * latter by examining for an option marker on the next possible argument.
- * Disabled mode option selection also disables option arguments.
- */
- {
- enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE;
- tSuccess res;
-
- if ((pOptState->flags & OPTST_DISABLED) != 0)
- arg_type = ARG_NONE;
-
- else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE)
- arg_type = ARG_NONE;
-
- else if (pOptState->flags & OPTST_ARG_OPTIONAL)
- arg_type = ARG_MAY;
-
- else
- arg_type = ARG_MUST;
-
- switch (arg_type) {
- case ARG_MUST: res = next_opt_arg_must(pOpts, pOptState); break;
- case ARG_MAY: res = next_opt_arg_may( pOpts, pOptState); break;
- case ARG_NONE: res = next_opt_arg_none(pOpts, pOptState); break;
- }
-
- return res;
- }
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * 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. doPresets()
- * will then return for optionProcess() to do the final pass on the command
- * line arguments.
- */
-
-/*
- * doImmediateOpts - scan the command line for immediate action options
- */
-LOCAL tSuccess
-doImmediateOpts( tOptions* pOpts )
-{
- pOpts->curOptIdx = 1; /* start by skipping program name */
- pOpts->pzCurOpt = NULL;
-
- /*
- * Examine all the options from the start. We process any options that
- * are marked for immediate processing.
- */
- for (;;) {
- tOptState optState = OPTSTATE_INITIALIZER(PRESET);
-
- switch (nextOption( pOpts, &optState )) {
- case FAILURE: goto optionsDone;
- case PROBLEM: return SUCCESS; /* no more args */
- case SUCCESS: break;
- }
-
- /*
- * IF this *is* an immediate-attribute option, then do it.
- */
- if (! DO_IMMEDIATELY(optState.flags))
- continue;
-
- if (! SUCCESSFUL( handleOption( pOpts, &optState )))
- break;
- } optionsDone:;
-
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
- (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE );
- return FAILURE;
-}
-
-
-LOCAL tSuccess
-doRegularOpts( tOptions* pOpts )
-{
- /*
- * Now, process all the options from our current position onward.
- * (This allows interspersed options and arguments for the few
- * non-standard programs that require it.)
- */
- for (;;) {
- tOptState optState = OPTSTATE_INITIALIZER(DEFINED);
-
- switch (nextOption( pOpts, &optState )) {
- case FAILURE: goto optionsDone;
- case PROBLEM: return SUCCESS; /* no more args */
- case SUCCESS: break;
- }
-
- /*
- * IF this is not being processed normally (i.e. is immediate action)
- * THEN skip it (unless we are supposed to do it a second time).
- */
- if (! DO_NORMALLY(optState.flags)) {
- if (! DO_SECOND_TIME(optState.flags))
- continue;
- optState.pOD->optOccCt--; /* don't count last time */
- }
-
- if (! SUCCESSFUL( handleOption( pOpts, &optState )))
- break;
- } optionsDone:;
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
- (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE );
- return FAILURE;
-}
-
-
-/*
- * doPresets - check for preset values from a config file or the envrionment
- */
-static tSuccess
-doPresets( tOptions* pOpts )
-{
- tOptDesc * pOD = NULL;
-
- if (! SUCCESSFUL( doImmediateOpts( pOpts )))
- 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 ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT)
- && (pOpts->specOptIdx.save_opts != 0)) {
- pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1;
- if (DISABLED_OPT(pOD))
- return SUCCESS;
- }
-
- /*
- * Until we return from this procedure, disable non-presettable opts
- */
- pOpts->fOptSet |= OPTPROC_PRESETTING;
- /*
- * IF there are no config files,
- * THEN do any environment presets and leave.
- */
- if (pOpts->papzHomeList == NULL) {
- doEnvPresets( pOpts, ENV_ALL );
- }
- else {
- doEnvPresets( pOpts, ENV_IMM );
-
- /*
- * Check to see if environment variables have disabled presetting.
- */
- if ((pOD != NULL) && ! DISABLED_OPT(pOD))
- internalFileLoad( pOpts );
-
- /*
- * ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment
- * variable options. Only the loading of .rc files.
- */
- doEnvPresets( pOpts, ENV_NON_IMM );
- }
- pOpts->fOptSet &= ~OPTPROC_PRESETTING;
-
- return SUCCESS;
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * VERIFY OPTION CONSISTENCY
- *
- * Make sure that the argument list passes our consistency tests.
- */
-static int
-checkConsistency( tOptions* pOpts )
-{
- int errCt = 0;
- tOptDesc* pOD = pOpts->pOptDesc;
- int oCt = pOpts->presetOptCt;
-
- /*
- * FOR each of "oCt" options, ...
- */
- for (;;) {
- const int* pMust = pOD->pOptMust;
- const int* pCant = pOD->pOptCant;
-
- /*
- * 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 (pMust != NULL) for (;;) {
- tOptDesc* p = pOpts->pOptDesc + *(pMust++);
- if (UNUSED_OPT(p)) {
- const tOptDesc* pN = pOpts->pOptDesc + pMust[-1];
- errCt++;
- fprintf( stderr, zReqFmt, pOD->pz_Name, pN->pz_Name );
- }
-
- if (*pMust == NO_EQUIVALENT)
- break;
- }
-
- if (pCant != NULL) for (;;) {
- tOptDesc* p = pOpts->pOptDesc + *(pCant++);
- if (SELECTED_OPT(p)) {
- const tOptDesc* pN = pOpts->pOptDesc + pCant[-1];
- errCt++;
- fprintf( stderr, zCantFmt, pOD->pz_Name, pN->pz_Name );
- }
-
- if (*pCant == NO_EQUIVALENT)
- break;
- }
- }
-
- /*
- * 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) ) do {
- /*
- * IF the occurrence counts have been satisfied,
- * THEN there is no problem.
- */
- if (pOD->optOccCt >= pOD->optMinCt)
- break;
-
- /*
- * 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)) )
- break;
-
- errCt++;
- if (pOD->optMinCt > 1)
- fprintf( stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt );
- else fprintf( stderr, zNeedOne, pOD->pz_Name );
- } while (0);
-
- 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 );
- ++errCt;
- }
- }
-
- /*
- * ELSE not prohibited, check for being required
- */
- else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) {
- if (pOpts->origArgCt <= pOpts->curOptIdx) {
- fprintf( stderr, zArgsMust, pOpts->pzProgName );
- ++errCt;
- }
- }
- }
-
- return errCt;
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * THESE ROUTINES ARE CALLABLE FROM THE GENERATED OPTION PROCESSING CODE
- */
-/*=--subblock=arg=arg_type,arg_name,arg_desc =*/
-/*=*
- * library: opts
- * header: your-opts.h
- *
- * lib_description:
- *
- * These are the routines that libopts users may call directly from their
- * code. There are several other routines that can be called by code
- * generated by the libopts option templates, but they are not to be
- * called from any other user code. The @file{options.h} header is
- * fairly clear about this, too.
-=*/
-
-/*=export_func optionProcess
- *
- * what: this is the main option processing routine
- *
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + int + argc + program arg count +
- * arg: + char** + argv + program arg vector +
- *
- * ret_type: int
- * ret_desc: the count of the arguments processed
- *
- * doc:
- *
- * This is the main entry point for processing options. It is intended
- * that this procedure be called once at the beginning of the execution of
- * a program. Depending on options selected earlier, it is sometimes
- * necessary to stop and restart option processing, or to select completely
- * different sets of options. This can be done easily, but you generally
- * do not want to do this.
- *
- * The number of arguments processed always includes the program name.
- * If one of the arguments is "--", then it is counted and the processing
- * stops. If an error was encountered and errors are to be tolerated, then
- * the returned value is the index of the argument causing the error.
- * A hyphen by itself ("-") will also cause processing to stop and will
- * @emph{not} be counted among the processed arguments. A hyphen by itself
- * is treated as an operand. Encountering an operand stops option
- * processing.
- *
- * err: Errors will cause diagnostics to be printed. @code{exit(3)} may
- * or may not be called. It depends upon whether or not the options
- * were generated with the "allow-errors" attribute, or if the
- * ERRSKIP_OPTERR or ERRSTOP_OPTERR macros were invoked.
-=*/
-int
-optionProcess(
- tOptions* pOpts,
- int argCt,
- char** argVect )
-{
- if (! SUCCESSFUL( validateOptionsStruct( pOpts, argVect[0] )))
- exit( EX_SOFTWARE );
-
- /*
- * Establish the real program name, the program full path,
- * and do all the presetting the first time thru only.
- */
- if ((pOpts->fOptSet & OPTPROC_INITDONE) == 0) {
- pOpts->origArgCt = argCt;
- pOpts->origArgVect = argVect;
- pOpts->fOptSet |= OPTPROC_INITDONE;
-
- if (! SUCCESSFUL( doPresets( pOpts )))
- return 0;
-
- /*
- * 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 ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0)
- && (pOpts->pTransProc != NULL)
- && ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK)
- == OPTPROC_NXLAT_OPT_CFG) ) {
-
- pOpts->fOptSet &= ~OPTPROC_NXLAT_OPT_CFG;
- (*pOpts->pTransProc)();
- }
-
- if ((pOpts->fOptSet & OPTPROC_REORDER) != 0)
- optionSort( pOpts );
-
- pOpts->curOptIdx = 1;
- pOpts->pzCurOpt = NULL;
- }
-
- /*
- * IF we are (re)starting,
- * THEN reset option location
- */
- else if (pOpts->curOptIdx <= 0) {
- pOpts->curOptIdx = 1;
- pOpts->pzCurOpt = NULL;
- }
-
- if (! SUCCESSFUL( doRegularOpts( pOpts )))
- return pOpts->origArgCt;
-
- /*
- * IF there were no errors
- * AND we have RC/INI files
- * AND there is a request to save the files
- * THEN do that now before testing for conflicts.
- * (conflicts are ignored in preset options)
- */
- if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT)
- && (pOpts->specOptIdx.save_opts != 0)) {
- tOptDesc* pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts;
-
- if (SELECTED_OPT( pOD )) {
- optionSaveFile( pOpts );
- exit( EXIT_SUCCESS );
- }
- }
-
- /*
- * IF we are checking for errors,
- * THEN look for too few occurrences of required options
- */
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) {
- if (checkConsistency( pOpts ) != 0)
- (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE );
- }
-
- return pOpts->curOptIdx;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/autoopts.c */
+++ /dev/null
-
-/*
- * Time-stamp: "2008-11-01 20:08:06 bkorb"
- *
- * autoopts.h $Id: autoopts.h,v 4.31 2009/08/01 17:44:36 bkorb Exp $
- *
- * This file defines all the global structures and special values
- * used in the automated option processing library.
- *
- * 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
- */
-
-#ifndef AUTOGEN_AUTOOPTS_H
-#define AUTOGEN_AUTOOPTS_H
-
-#include "compat/compat.h"
-#include "ag-char-map.h"
-
-#define AO_NAME_LIMIT 127
-#define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1))
-
-#ifndef AG_PATH_MAX
-# ifdef PATH_MAX
-# define AG_PATH_MAX ((size_t)PATH_MAX)
-# else
-# define AG_PATH_MAX ((size_t)4096)
-# endif
-#else
-# if defined(PATH_MAX) && (PATH_MAX > MAXPATHLEN)
-# undef AG_PATH_MAX
-# define AG_PATH_MAX ((size_t)PATH_MAX)
-# endif
-#endif
-
-#undef EXPORT
-#define EXPORT
-
-#if defined(_WIN32) && !defined(__CYGWIN__)
-# define DIRCH '\\'
-#else
-# define DIRCH '/'
-#endif
-
-#ifndef EX_NOINPUT
-# define EX_NOINPUT 66
-#endif
-#ifndef EX_SOFTWARE
-# define EX_SOFTWARE 70
-#endif
-#ifndef EX_CONFIG
-# define EX_CONFIG 78
-#endif
-
-/*
- * Convert the number to a list usable in a printf call
- */
-#define NUM_TO_VER(n) ((n) >> 12), ((n) >> 7) & 0x001F, (n) & 0x007F
-
-#define NAMED_OPTS(po) \
- (((po)->fOptSet & (OPTPROC_SHORTOPT | OPTPROC_LONGOPT)) == 0)
-
-#define SKIP_OPT(p) (((p)->fOptState & (OPTST_DOCUMENT|OPTST_OMITTED)) != 0)
-
-typedef int tDirection;
-#define DIRECTION_PRESET -1
-#define DIRECTION_PROCESS 1
-#define DIRECTION_CALLED 0
-
-#define PROCESSING(d) ((d)>0)
-#define PRESETTING(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
- */
-typedef enum {
- OPTION_LOAD_COOKED,
- OPTION_LOAD_UNCOOKED,
- OPTION_LOAD_KEEP
-} tOptionLoadMode;
-
-extern 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
- * before it is done, then 'pagerState' must be set to
- * 'PAGER_STATE_CHILD' so that optionPagedUsage() will not try
- * to run the pager program before its time.
- */
-typedef enum {
- PAGER_STATE_INITIAL,
- PAGER_STATE_READY,
- PAGER_STATE_CHILD
-} tePagerState;
-
-extern tePagerState pagerState;
-
-typedef enum {
- ENV_ALL,
- ENV_IMM,
- ENV_NON_IMM
-} teEnvPresetType;
-
-typedef enum {
- TOPT_UNDEFINED = 0,
- TOPT_SHORT,
- TOPT_LONG,
- TOPT_DEFAULT
-} teOptType;
-
-typedef struct {
- tOptDesc* pOD;
- tCC* pzOptArg;
- tAoUL flags;
- teOptType optType;
-} tOptState;
-#define OPTSTATE_INITIALIZER(st) \
- { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED }
-
-#define TEXTTO_TABLE \
- _TT_( LONGUSAGE ) \
- _TT_( USAGE ) \
- _TT_( VERSION )
-#define _TT_(n) \
- TT_ ## n ,
-
-typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo;
-
-#undef _TT_
-
-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;
-} 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))
-
-static void *
-ao_malloc( size_t sz );
-
-static void *
-ao_realloc( void *p, size_t sz );
-
-static void
-ao_free( void *p );
-
-static char *
-ao_strdup( char const *str );
-
-#define TAGMEM( m, t )
-
-/*
- * DO option handling?
- *
- * Options are examined at two times: at immediate handling time and at
- * normal handling time. If an option is disabled, the timing may be
- * different from the handling of the undisabled option. The OPTST_DIABLED
- * bit indicates the state of the currently discovered option.
- * So, here's how it works:
- *
- * A) handling at "immediate" time, either 1 or 2:
- *
- * 1. OPTST_DISABLED is not set:
- * IMM must be set
- * DISABLE_IMM don't care
- * TWICE don't care
- * DISABLE_TWICE don't care
- * 0 -and- 1 x x x
- *
- * 2. OPTST_DISABLED is set:
- * IMM don't care
- * DISABLE_IMM must be set
- * TWICE don't care
- * DISABLE_TWICE don't care
- * 1 -and- x 1 x x
- */
-#define DO_IMMEDIATELY(_flg) \
- ( (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == OPTST_IMM) \
- || ( ((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) \
- == (OPTST_DISABLED|OPTST_DISABLE_IMM) ))
-
-/* B) handling at "regular" time because it was not immediate
- *
- * 1. OPTST_DISABLED is not set:
- * IMM must *NOT* be set
- * DISABLE_IMM don't care
- * TWICE don't care
- * DISABLE_TWICE don't care
- * 0 -and- 0 x x x
- *
- * 2. OPTST_DISABLED is set:
- * IMM don't care
- * DISABLE_IMM don't care
- * TWICE must be set
- * DISABLE_TWICE don't care
- * 1 -and- x x 1 x
- */
-#define DO_NORMALLY(_flg) ( \
- (((_flg) & (OPTST_DISABLED|OPTST_IMM)) == 0) \
- || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_IMM)) == \
- OPTST_DISABLED) )
-
-/* 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:
- * IMM is set (but don't care)
- * DISABLE_IMM don't care
- * TWICE must be set
- * DISABLE_TWICE don't care
- * 0 -and- ? x 1 x
- *
- * 4. OPTST_DISABLED is set:
- * IMM don't care
- * DISABLE_IMM is set (but don't care)
- * TWICE don't care
- * DISABLE_TWICE must be set
- * 1 -and- x ? x 1
- */
-#define DO_SECOND_TIME(_flg) ( \
- (((_flg) & (OPTST_DISABLED|OPTST_TWICE)) == \
- OPTST_TWICE) \
- || (((_flg) & (OPTST_DISABLED|OPTST_DISABLE_TWICE)) == \
- (OPTST_DISABLED|OPTST_DISABLE_TWICE) ))
-
-/*
- * text_mmap structure. Only active on platforms with mmap(2).
- */
-#ifdef HAVE_SYS_MMAN_H
-# include <sys/mman.h>
-#else
-# ifndef PROT_READ
-# define PROT_READ 0x01
-# endif
-# ifndef PROT_WRITE
-# define PROT_WRITE 0x02
-# endif
-# ifndef MAP_SHARED
-# define MAP_SHARED 0x01
-# endif
-# ifndef MAP_PRIVATE
-# define MAP_PRIVATE 0x02
-# endif
-#endif
-
-#ifndef MAP_FAILED
-# define MAP_FAILED ((void*)-1)
-#endif
-
-#ifndef _SC_PAGESIZE
-# ifdef _SC_PAGE_SIZE
-# define _SC_PAGESIZE _SC_PAGE_SIZE
-# endif
-#endif
-
-#ifndef HAVE_STRCHR
-extern char* strchr( char const *s, int c);
-extern char* strrchr( char const *s, int c);
-#endif
-
-/*
- * 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.
- */
-#undef DO_TRANSLATIONS
-#include "autoopts/usage-txt.h"
-
-/*
- * File pointer for usage output
- */
-extern FILE* option_usage_fp;
-
-extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt;
-
-#endif /* AUTOGEN_AUTOOPTS_H */
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/autoopts.h */
+++ /dev/null
-/* -*- buffer-read-only: t -*- vi: set ro:
- *
- * DO NOT EDIT THIS FILE (options.h)
- *
- * It has been AutoGen-ed August 1, 2009 at 11:21:11 AM by AutoGen 5.9.9pre4
- * From the definitions funcs.def
- * and the template file options_h
- *
- * This file defines all the global structures and special values
- * used in the automated option processing library.
- *
- * Automated Options copyright (c) 1992-Y by Bruce Korb
- *
- * AutoOpts 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 3 of the License, or
- * (at your option) any later version.
- *
- * AutoOpts 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 AUTOOPTS_OPTIONS_H_GUARD
-#define AUTOOPTS_OPTIONS_H_GUARD 1
-#include <sys/types.h>
-#include <stdio.h>
-
-#if defined(HAVE_STDINT_H)
-# include <stdint.h>
-#elif defined(HAVE_INTTYPES_H)
-# include <inttypes.h>
-#endif /* HAVE_STDINT/INTTYPES_H */
-
-#if defined(HAVE_LIMITS_H)
-# include <limits.h>
-#elif defined(HAVE_SYS_LIMITS_H)
-# include <sys/limits.h>
-#endif /* HAVE_LIMITS/SYS_LIMITS_H */
-
-#if defined(HAVE_SYSEXITS_H)
-# include <sysexits.h>
-#endif /* HAVE_SYSEXITS_H */
-
-#ifndef EX_USAGE
-# define EX_USAGE 64
-#endif
-
-/*
- * PUBLIC DEFINES
- *
- * The following defines may be used in applications that need to test the
- * state of an option. To test against these masks and values, a pointer
- * to an option descriptor must be obtained. There are two ways:
- *
- * 1. inside an option processing procedure, it is the second argument,
- * conventionally "tOptDesc* pOD".
- *
- * 2. Outside of an option procedure (or to reference a different option
- * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )".
- *
- * See the relevant generated header file to determine which and what
- * values for "opt_name" are available.
- */
-
-#define OPTIONS_STRUCT_VERSION 131073
-#define OPTIONS_VERSION_STRING "32:1:7"
-#define OPTIONS_MINIMUM_VERSION 102400
-#define OPTIONS_MIN_VER_STRING "25:0:0"
-
-typedef enum {
- OPARG_TYPE_NONE = 0,
- OPARG_TYPE_STRING = 1, /* default type/ vanilla string */
- OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */
- OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */
- OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */
- OPARG_TYPE_NUMERIC = 5, /* opt arg has numeric value */
- OPARG_TYPE_HIERARCHY = 6, /* option arg is hierarchical value */
- OPARG_TYPE_FILE = 7, /* option arg names a file */
- OPARG_TYPE_TIME = 8 /* opt arg is a time duration */
-} teOptArgType;
-
-typedef struct optionValue {
- teOptArgType valType;
- char* pzName;
- union {
- char strVal[1]; /* OPARG_TYPE_STRING */
- unsigned int enumVal; /* OPARG_TYPE_ENUMERATION */
- unsigned int boolVal; /* OPARG_TYPE_BOOLEAN */
- unsigned long setVal; /* OPARG_TYPE_MEMBERSHIP */
- long longVal; /* OPARG_TYPE_NUMERIC */
- void* nestVal; /* OPARG_TYPE_HIERARCHY */
- } v;
-} tOptionValue;
-
-typedef enum {
- FTYPE_MODE_MAY_EXIST = 0x00,
- FTYPE_MODE_MUST_EXIST = 0x01,
- FTYPE_MODE_MUST_NOT_EXIST = 0x02,
- FTYPE_MODE_EXIST_MASK = 0x03,
- FTYPE_MODE_NO_OPEN = 0x00,
- FTYPE_MODE_OPEN_FD = 0x10,
- FTYPE_MODE_FOPEN_FP = 0x20,
- FTYPE_MODE_OPEN_MASK = 0x30
-} teOptFileType;
-
-typedef union {
- int file_flags;
- char const * file_mode;
-} tuFileMode;
-
-/*
- * Bits in the fOptState option descriptor field.
- */
-typedef enum {
- OPTST_SET_ID = 0, /* Set via the "SET_OPT()" macro */
- OPTST_PRESET_ID = 1, /* Set via an RC/INI file */
- OPTST_DEFINED_ID = 2, /* Set via a command line option */
- OPTST_RESET_ID = 3, /* Reset via command line option */
- OPTST_EQUIVALENCE_ID = 4, /* selected by equiv'ed option */
- OPTST_DISABLED_ID = 5, /* option is in disabled state */
- OPTST_ALLOC_ARG_ID = 6, /* pzOptArg was allocated */
- OPTST_NO_INIT_ID = 8, /* option cannot be preset */
- OPTST_NUMBER_OPT_ID = 9, /* opt value (flag) is any digit */
- OPTST_STACKED_ID = 10, /* opt uses optionStackArg proc */
- OPTST_INITENABLED_ID = 11, /* option defaults to enabled */
- OPTST_ARG_TYPE_1_ID = 12, /* bit 1 of arg type enum */
- OPTST_ARG_TYPE_2_ID = 13, /* bit 2 of arg type enum */
- OPTST_ARG_TYPE_3_ID = 14, /* bit 3 of arg type enum */
- OPTST_ARG_TYPE_4_ID = 15, /* bit 4 of arg type enum */
- OPTST_ARG_OPTIONAL_ID = 16, /* the option arg not required */
- OPTST_IMM_ID = 17, /* process opt on first pass */
- OPTST_DISABLE_IMM_ID = 18, /* process disablement immed. */
- OPTST_OMITTED_ID = 19, /* compiled out of program */
- OPTST_MUST_SET_ID = 20, /* must be set or pre-set */
- OPTST_DOCUMENT_ID = 21, /* opt is for doc only */
- OPTST_TWICE_ID = 22, /* process opt twice - imm + reg */
- OPTST_DISABLE_TWICE_ID = 23, /* process disabled option twice */
- OPTST_SCALED_NUM_ID = 24, /* scaled integer value */
- OPTST_NO_COMMAND_ID = 25, /* disable from cmd line */
- OPTST_DEPRECATED_ID = 26 /* support is being removed */
-} opt_state_enum_t;
-
-#define OPTST_INIT 0U
-#define OPTST_SET (1U << OPTST_SET_ID)
-#define OPTST_PRESET (1U << OPTST_PRESET_ID)
-#define OPTST_DEFINED (1U << OPTST_DEFINED_ID)
-#define OPTST_RESET (1U << OPTST_RESET_ID)
-#define OPTST_EQUIVALENCE (1U << OPTST_EQUIVALENCE_ID)
-#define OPTST_DISABLED (1U << OPTST_DISABLED_ID)
-#define OPTST_ALLOC_ARG (1U << OPTST_ALLOC_ARG_ID)
-#define OPTST_NO_INIT (1U << OPTST_NO_INIT_ID)
-#define OPTST_NUMBER_OPT (1U << OPTST_NUMBER_OPT_ID)
-#define OPTST_STACKED (1U << OPTST_STACKED_ID)
-#define OPTST_INITENABLED (1U << OPTST_INITENABLED_ID)
-#define OPTST_ARG_TYPE_1 (1U << OPTST_ARG_TYPE_1_ID)
-#define OPTST_ARG_TYPE_2 (1U << OPTST_ARG_TYPE_2_ID)
-#define OPTST_ARG_TYPE_3 (1U << OPTST_ARG_TYPE_3_ID)
-#define OPTST_ARG_TYPE_4 (1U << OPTST_ARG_TYPE_4_ID)
-#define OPTST_ARG_OPTIONAL (1U << OPTST_ARG_OPTIONAL_ID)
-#define OPTST_IMM (1U << OPTST_IMM_ID)
-#define OPTST_DISABLE_IMM (1U << OPTST_DISABLE_IMM_ID)
-#define OPTST_OMITTED (1U << OPTST_OMITTED_ID)
-#define OPTST_MUST_SET (1U << OPTST_MUST_SET_ID)
-#define OPTST_DOCUMENT (1U << OPTST_DOCUMENT_ID)
-#define OPTST_TWICE (1U << OPTST_TWICE_ID)
-#define OPTST_DISABLE_TWICE (1U << OPTST_DISABLE_TWICE_ID)
-#define OPTST_SCALED_NUM (1U << OPTST_SCALED_NUM_ID)
-#define OPTST_NO_COMMAND (1U << OPTST_NO_COMMAND_ID)
-#define OPTST_DEPRECATED (1U << OPTST_DEPRECATED_ID)
-#define OPT_STATE_MASK 0x07FFFF7FU
-
-#define OPTST_SET_MASK ( \
- OPTST_DEFINED | OPTST_PRESET | OPTST_RESET | \
- OPTST_SET \
- /* 0x0000000FU */ )
-
-#define OPTST_MUTABLE_MASK ( \
- OPTST_ALLOC_ARG | OPTST_DEFINED | \
- OPTST_DISABLED | OPTST_EQUIVALENCE | \
- OPTST_PRESET | OPTST_RESET | \
- OPTST_SET \
- /* 0x0000007FU */ )
-
-#define OPTST_SELECTED_MASK ( \
- OPTST_DEFINED | OPTST_SET \
- /* 0x00000005U */ )
-
-#define OPTST_ARG_TYPE_MASK ( \
- OPTST_ARG_TYPE_1 | OPTST_ARG_TYPE_2 | OPTST_ARG_TYPE_3 | \
- OPTST_ARG_TYPE_4 \
- /* 0x0000F000U */ )
-
-#define OPTST_DO_NOT_SAVE_MASK ( \
- OPTST_DOCUMENT | OPTST_NO_INIT | OPTST_OMITTED \
- /* 0x00280100U */ )
-
-#define OPTST_NO_USAGE_MASK ( \
- OPTST_DEPRECATED | OPTST_NO_COMMAND | OPTST_OMITTED \
- /* 0x06080000U */ )
-
-#ifdef NO_OPTIONAL_OPT_ARGS
-# undef OPTST_ARG_OPTIONAL
-# define OPTST_ARG_OPTIONAL 0
-#endif
-
-#define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK)
-
-#define SELECTED_OPT(_od) ((_od)->fOptState & OPTST_SELECTED_MASK)
-#define UNUSED_OPT( _od) (((_od)->fOptState & OPTST_SET_MASK) == 0)
-#define DISABLED_OPT(_od) ((_od)->fOptState & OPTST_DISABLED)
-#define OPTION_STATE(_od) ((_od)->fOptState)
-#define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_1_ID)
-#define OPTST_GET_ARGTYPE(_f) (((_f)&OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID)
-
-/*
- * PRIVATE INTERFACES
- *
- * The following values are used in the generated code to communicate
- * with the option library procedures. They are not for public use
- * and may be subject to change.
- */
-
-/*
- * Define the processing state flags
- */
-typedef enum {
- OPTPROC_LONGOPT_ID = 0, /* Process long style options */
- OPTPROC_SHORTOPT_ID = 1, /* Process short style "flags" */
- OPTPROC_ERRSTOP_ID = 2, /* Stop on argument errors */
- OPTPROC_DISABLEDOPT_ID = 3, /* Current option is disabled */
- OPTPROC_NO_REQ_OPT_ID = 4, /* no options are required */
- OPTPROC_NUM_OPT_ID = 5, /* there is a number option */
- OPTPROC_INITDONE_ID = 6, /* have inits been done? */
- OPTPROC_NEGATIONS_ID = 7, /* any negation options? */
- OPTPROC_ENVIRON_ID = 8, /* check environment? */
- OPTPROC_NO_ARGS_ID = 9, /* Disallow remaining arguments */
- OPTPROC_ARGS_REQ_ID = 10, /* Require args after options */
- OPTPROC_REORDER_ID = 11, /* reorder operands after opts */
- OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */
- OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */
- OPTPROC_NXLAT_OPT_CFG_ID = 16, /* suppress for config only */
- OPTPROC_NXLAT_OPT_ID = 17, /* suppress xlation always */
- OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */
-} optproc_state_enum_t;
-
-#define OPTPROC_NONE 0U
-#define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID)
-#define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID)
-#define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID)
-#define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID)
-#define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID)
-#define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID)
-#define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID)
-#define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID)
-#define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID)
-#define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID)
-#define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID)
-#define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID)
-#define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID)
-#define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID)
-#define OPTPROC_NXLAT_OPT_CFG (1U << OPTPROC_NXLAT_OPT_CFG_ID)
-#define OPTPROC_NXLAT_OPT (1U << OPTPROC_NXLAT_OPT_ID)
-#define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID)
-#define OPTPROC_STATE_MASK 0x000B3FFFU
-
-#define OPTPROC_NO_XLAT_MASK ( \
- OPTPROC_NXLAT_OPT | OPTPROC_NXLAT_OPT_CFG \
- /* 0x00030000U */ )
-
-#define STMTS(s) do { s; } while (0)
-
-/*
- * The following must be #defined instead of typedef-ed
- * because "static const" cannot both be applied to a type,
- * tho each individually can...so they all are
- */
-#define tSCC static char const
-#define tCC char const
-#define tAoSC static char
-#define tAoUC unsigned char
-#define tAoUI unsigned int
-#define tAoUL unsigned long
-#define tAoUS unsigned short
-
-/*
- * It is so disgusting that there must be so many ways
- * of specifying TRUE and FALSE.
- */
-typedef enum { AG_FALSE = 0, AG_TRUE } ag_bool;
-
-/*
- * Define a structure that describes each option and
- * a pointer to the procedure that handles it.
- * The argument is the count of this flag previously seen.
- */
-typedef struct options tOptions;
-typedef struct optDesc tOptDesc;
-typedef struct optNames tOptNames;
-#define OPTPROC_EMIT_USAGE ((tOptions *)0x01UL)
-#define OPTPROC_EMIT_SHELL ((tOptions *)0x02UL)
-#define OPTPROC_RETURN_VALNAME ((tOptions *)0x03UL)
-#define OPTPROC_EMIT_LIMIT ((tOptions *)0x0FUL)
-
-/*
- * The option procedures do the special processing for each
- * option flag that needs it.
- */
-typedef void (tOptProc)(tOptions* pOpts, tOptDesc* pOptDesc);
-typedef tOptProc* tpOptProc;
-
-/*
- * The usage procedure will never return. It calls "exit(2)"
- * with the "exitCode" argument passed to it.
- */
-typedef void (tUsageProc)(tOptions* pOpts, int exitCode);
-typedef tUsageProc* tpUsageProc;
-
-/*
- * Special definitions. "NOLIMIT" is the 'max' value to use when
- * a flag may appear multiple times without limit. "NO_EQUIVALENT"
- * is an illegal value for 'optIndex' (option description index).
- */
-#define NOLIMIT USHRT_MAX
-#define OPTION_LIMIT SHRT_MAX
-#define NO_EQUIVALENT (OPTION_LIMIT+1)
-
-/*
- * Special values for optValue. It must not be generatable from the
- * computation "optIndex +96". Since "optIndex" is limited to 100, ...
- */
-#define NUMBER_OPTION '#'
-
-typedef struct argList tArgList;
-#define MIN_ARG_ALLOC_CT 6
-#define INCR_ARG_ALLOC_CT 8
-struct argList {
- int useCt;
- int allocCt;
- tCC* apzArgs[ MIN_ARG_ALLOC_CT ];
-};
-
-typedef union {
- char const * argString;
- uintptr_t argEnum;
- uintptr_t argIntptr;
- long argInt;
- unsigned long argUint;
- unsigned int argBool;
- FILE* argFp;
- int argFd;
-} optArgBucket_t;
-
-/*
- * Descriptor structure for each option.
- * Only the fields marked "PUBLIC" are for public use.
- */
-struct optDesc {
- tAoUS const optIndex; /* PUBLIC */
- tAoUS const optValue; /* PUBLIC */
- tAoUS optActualIndex; /* PUBLIC */
- tAoUS optActualValue; /* PUBLIC */
-
- tAoUS const optEquivIndex; /* PUBLIC */
- tAoUS const optMinCt;
- tAoUS const optMaxCt;
- tAoUS optOccCt; /* PUBLIC */
-
- tAoUI fOptState; /* PUBLIC */
- tAoUI reserved;
- optArgBucket_t optArg; /* PUBLIC */
-# define pzLastArg optArg.argString
- void* optCookie; /* PUBLIC */
-
- int const * const pOptMust;
- int const * const pOptCant;
- tpOptProc const pOptProc;
- char const* const pzText;
-
- char const* const pz_NAME;
- char const* const pz_Name;
- char const* const pz_DisableName;
- char const* const pz_DisablePfx;
-};
-
-/*
- * Some options need special processing, so we store their
- * indexes in a known place:
- */
-typedef struct optSpecIndex tOptSpecIndex;
-struct optSpecIndex {
- const tAoUS more_help;
- const tAoUS save_opts;
- const tAoUS number_option;
- const tAoUS default_opt;
-};
-
-/*
- * The procedure generated for translating option text
- */
-typedef void (tOptionXlateProc)(void);
-
-struct options {
- int const structVersion;
- int origArgCt;
- char** origArgVect;
- unsigned int fOptSet;
- unsigned int curOptIdx;
- char* pzCurOpt;
-
- char const* pzProgPath; /* PUBLIC */
- char const* pzProgName; /* PUBLIC */
- char const* const pzPROGNAME; /* PUBLIC */
- char const* const pzRcName; /* PUBLIC */
- char const* const pzCopyright; /* PUBLIC */
- char const* const pzCopyNotice; /* PUBLIC */
- char const* const pzFullVersion; /* PUBLIC */
- char const* const* const papzHomeList;
- char const* const pzUsageTitle;
- char const* const pzExplain;
- char const* const pzDetail;
- tOptDesc* const pOptDesc; /* PUBLIC */
- char const* const pzBugAddr; /* PUBLIC */
-
- void* pExtensions;
- void* pSavedState;
-
- tpUsageProc pUsageProc;
- tOptionXlateProc* pTransProc;
-
- tOptSpecIndex specOptIdx;
- int const optCt;
- int const presetOptCt;
- char const * pzFullUsage;
- char const * pzShortUsage;
- /* PUBLIC: */
- optArgBucket_t const * const originalOptArgArray;
- void * const * const originalOptArgCookie;
-};
-
-/*
- * Versions where in various fields first appear:
- * ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero)
- */
-#define originalOptArgArray_STRUCT_VERSION 131072 /* AO_CURRENT = 32 */
-#define HAS_originalOptArgArray(_opt) \
- ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION)
-
-/*
- * "token list" structure returned by "string_tokenize()"
- */
-typedef struct {
- unsigned long tkn_ct;
- unsigned char* tkn_list[1];
-} token_list_t;
-
-/*
- * Hide the interface - it pollutes a POSIX claim, but leave it for
- * anyone #include-ing this header
- */
-#define strneqvcmp option_strneqvcmp
-#define streqvcmp option_streqvcmp
-#define streqvmap option_streqvmap
-#define strequate option_strequate
-#define strtransform option_strtransform
-
-/*
- * This is an output only structure used by text_mmap and text_munmap.
- * Clients must not alter the contents and must provide it to both
- * the text_mmap and text_munmap procedures. BE ADVISED: if you are
- * mapping the file with PROT_WRITE the NUL byte at the end MIGHT NOT
- * BE WRITABLE. In any event, that byte is not be written back
- * to the source file. ALSO: if "txt_data" is valid and "txt_errno"
- * is not zero, then there *may* not be a terminating NUL.
- */
-typedef struct {
- void* txt_data; /* text file data */
- size_t txt_size; /* actual file size */
- size_t txt_full_size; /* mmaped mem size */
- int txt_fd; /* file descriptor */
- int txt_zero_fd; /* fd for /dev/zero */
- int txt_errno; /* warning code */
- int txt_prot; /* "prot" flags */
- int txt_flags; /* mapping type */
- int txt_alloc; /* if we malloced memory */
-} tmap_info_t;
-
-#define TEXT_MMAP_FAILED_ADDR(a) ((void*)(a) == (void*)MAP_FAILED)
-
-#ifdef __cplusplus
-extern "C" {
-#define CPLUSPLUS_CLOSER }
-#else
-#define CPLUSPLUS_CLOSER
-#endif
-
-/*
- * The following routines may be coded into AutoOpts client code:
- */
-
-/* From: tokenize.c line 117
- *
- * ao_string_tokenize - tokenize an input string
- *
- * Arguments:
- * string string to be tokenized
- *
- * Returns: token_list_t* - pointer to a structure that lists each token
- *
- * This function will convert one input string into a list of strings.
- * The list of strings is derived by separating the input based on
- * white space separation. However, if the input contains either single
- * or double quote characters, then the text after that character up to
- * a matching quote will become the string in the list.
- *
- * The returned pointer should be deallocated with @code{free(3C)} when
- * are done using the data. The data are placed in a single block of
- * allocated memory. Do not deallocate individual token/strings.
- *
- * The structure pointed to will contain at least these two fields:
- * @table @samp
- * @item tkn_ct
- * The number of tokens found in the input string.
- * @item tok_list
- * An array of @code{tkn_ct + 1} pointers to substring tokens, with
- * the last pointer set to NULL.
- * @end table
- *
- * There are two types of quoted strings: single quoted (@code{'}) and
- * double quoted (@code{"}). Singly quoted strings are fairly raw in that
- * escape characters (@code{\\}) are simply another character, except when
- * preceding the following characters:
- * @example
- * @code{\\} double backslashes reduce to one
- * @code{'} incorporates the single quote into the string
- * @code{\n} suppresses both the backslash and newline character
- * @end example
- *
- * Double quote strings are formed according to the rules of string
- * constants in ANSI-C programs.
- */
-extern token_list_t* ao_string_tokenize(char const*);
-
-
-/* From: configfile.c line 85
- *
- * configFileLoad - parse a configuration file
- *
- * Arguments:
- * pzFile the file to load
- *
- * Returns: const tOptionValue* - An allocated, compound value structure
- *
- * This routine will load a named configuration file and parse the
- * text as a hierarchically valued option. The option descriptor
- * created from an option definition file is not used via this interface.
- * The returned value is "named" with the input file name and is of
- * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to
- * @code{optionGetValue()}, @code{optionNextValue()} and
- * @code{optionUnloadNested()}.
- */
-extern const tOptionValue* configFileLoad(char const*);
-
-
-/* From: configfile.c line 897
- *
- * optionFileLoad - Load the locatable config files, in order
- *
- * Arguments:
- * pOpts program options descriptor
- * pzProg program name
- *
- * Returns: int - 0 -> SUCCESS, -1 -> FAILURE
- *
- * This function looks in all the specified directories for a configuration
- * file ("rc" file or "ini" file) and processes any found twice. The first
- * time through, they are processed in reverse order (last file first). At
- * that time, only "immediate action" configurables are processed. For
- * example, if the last named file specifies not processing any more
- * configuration files, then no more configuration files will be processed.
- * Such an option in the @strong{first} named directory will have no effect.
- *
- * Once the immediate action configurables have been handled, then the
- * directories are handled in normal, forward order. In that way, later
- * config files can override the settings of earlier config files.
- *
- * See the AutoOpts documentation for a thorough discussion of the
- * config file format.
- *
- * Configuration files not found or not decipherable are simply ignored.
- */
-extern int optionFileLoad(tOptions*, char const*);
-
-
-/* From: configfile.c line 217
- *
- * optionFindNextValue - find a hierarcicaly valued option instance
- *
- * Arguments:
- * pOptDesc an option with a nested arg type
- * pPrevVal the last entry
- * name name of value to find
- * value the matching value
- *
- * Returns: const tOptionValue* - a compound value structure
- *
- * This routine will find the next entry in a nested value option or
- * configurable. It will search through the list and return the next entry
- * that matches the criteria.
- */
-extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionValue*, char const*, char const*);
-
-
-/* From: configfile.c line 143
- *
- * optionFindValue - find a hierarcicaly valued option instance
- *
- * Arguments:
- * pOptDesc an option with a nested arg type
- * name name of value to find
- * value the matching value
- *
- * Returns: const tOptionValue* - a compound value structure
- *
- * This routine will find an entry in a nested value option or configurable.
- * It will search through the list and return a matching entry.
- */
-extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char const*);
-
-
-/* From: restore.c line 165
- *
- * optionFree - free allocated option processing memory
- *
- * Arguments:
- * pOpts program options descriptor
- *
- * AutoOpts sometimes allocates memory and puts pointers to it in the
- * option state structures. This routine deallocates all such memory.
- */
-extern void optionFree(tOptions*);
-
-
-/* From: configfile.c line 286
- *
- * optionGetValue - get a specific value from a hierarcical list
- *
- * Arguments:
- * pOptValue a hierarchcal value
- * valueName name of value to get
- *
- * Returns: const tOptionValue* - a compound value structure
- *
- * This routine will find an entry in a nested value option or configurable.
- * If "valueName" is NULL, then the first entry is returned. Otherwise,
- * the first entry with a name that exactly matches the argument will be
- * returned.
- */
-extern const tOptionValue* optionGetValue(const tOptionValue*, char const*);
-
-
-/* From: load.c line 498
- *
- * optionLoadLine - process a string for an option name and value
- *
- * Arguments:
- * pOpts program options descriptor
- * pzLine NUL-terminated text
- *
- * This is a client program callable routine for setting options from, for
- * example, the contents of a file that they read in. Only one option may
- * appear in the text. It will be treated as a normal (non-preset) option.
- *
- * 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
- * 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}),
- * except that you may not use backquotes.
- */
-extern void optionLoadLine(tOptions*, char const*);
-
-
-/* From: configfile.c line 345
- *
- * optionNextValue - get the next value from a hierarchical list
- *
- * Arguments:
- * pOptValue a hierarchcal list value
- * pOldValue a value from this list
- *
- * Returns: const tOptionValue* - a compound value structure
- *
- * This routine will return the next entry after the entry passed in. At the
- * end of the list, NULL will be returned. If the entry is not found on the
- * list, NULL will be returned and "@var{errno}" will be set to EINVAL.
- * The "@var{pOldValue}" must have been gotten from a prior call to this
- * routine or to "@code{opitonGetValue()}".
- */
-extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionValue*);
-
-
-/* From: usage.c line 107
- *
- * optionOnlyUsage - Print usage text for just the options
- *
- * Arguments:
- * pOpts program options descriptor
- * ex_code exit code for calling exit(3)
- *
- * This routine will print only the usage for each option.
- * This function may be used when the emitted usage must incorporate
- * information not available to AutoOpts.
- */
-extern void optionOnlyUsage(tOptions*, int);
-
-
-/* From: autoopts.c line 1041
- *
- * optionProcess - this is the main option processing routine
- *
- * Arguments:
- * pOpts program options descriptor
- * argc program arg count
- * argv program arg vector
- *
- * Returns: int - the count of the arguments processed
- *
- * This is the main entry point for processing options. It is intended
- * that this procedure be called once at the beginning of the execution of
- * a program. Depending on options selected earlier, it is sometimes
- * necessary to stop and restart option processing, or to select completely
- * different sets of options. This can be done easily, but you generally
- * do not want to do this.
- *
- * The number of arguments processed always includes the program name.
- * If one of the arguments is "--", then it is counted and the processing
- * stops. If an error was encountered and errors are to be tolerated, then
- * the returned value is the index of the argument causing the error.
- * A hyphen by itself ("-") will also cause processing to stop and will
- * @emph{not} be counted among the processed arguments. A hyphen by itself
- * is treated as an operand. Encountering an operand stops option
- * processing.
- */
-extern int optionProcess(tOptions*, int, char**);
-
-
-/* From: restore.c line 122
- *
- * optionRestore - restore option state from memory copy
- *
- * Arguments:
- * pOpts program options descriptor
- *
- * Copy back the option state from saved memory.
- * The allocated memory is left intact, so this routine can be
- * called repeatedly without having to call optionSaveState again.
- * If you are restoring a state that was saved before the first call
- * to optionProcess(3AO), then you may change the contents of the
- * argc/argv parameters to optionProcess.
- */
-extern void optionRestore(tOptions*);
-
-
-/* From: save.c line 671
- *
- * optionSaveFile - saves the option state to a file
- *
- * Arguments:
- * pOpts program options descriptor
- *
- * This routine will save the state of option processing to a file. The name
- * of that file can be specified with the argument to the @code{--save-opts}
- * 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.
- *
- * The recommend usage is as follows:
- * @example
- * optionProcess(&progOptions, argc, argv);
- * if (i_want_a_non_standard_place_for_this)
- * SET_OPT_SAVE_OPTS("myfilename");
- * optionSaveFile(&progOptions);
- * @end example
- */
-extern void optionSaveFile(tOptions*);
-
-
-/* From: restore.c line 70
- *
- * optionSaveState - saves the option state to memory
- *
- * Arguments:
- * pOpts program options descriptor
- *
- * This routine will allocate enough memory to save the current option
- * processing state. If this routine has been called before, that memory
- * will be reused. You may only save one copy of the option state. This
- * routine may be called before optionProcess(3AO). If you do call it
- * before the first call to optionProcess, then you may also change the
- * contents of argc/argv after you call optionRestore(3AO)
- *
- * In fact, more strongly put: it is safest to only use this function
- * before having processed any options. In particular, the saving and
- * restoring of stacked string arguments and hierarchical values is
- * disabled. The values are not saved.
- */
-extern void optionSaveState(tOptions*);
-
-
-/* From: nested.c line 569
- *
- * optionUnloadNested - Deallocate the memory for a nested value
- *
- * Arguments:
- * pOptVal the hierarchical value
- *
- * A nested value needs to be deallocated. The pointer passed in should
- * have been gotten from a call to @code{configFileLoad()} (See
- * @pxref{libopts-configFileLoad}).
- */
-extern void optionUnloadNested(tOptionValue const *);
-
-
-/* From: version.c line 37
- *
- * optionVersion - return the compiled AutoOpts version number
- *
- * Returns: char const* - the version string in constant memory
- *
- * Returns the full version string compiled into the library.
- * The returned string cannot be modified.
- */
-extern char const* optionVersion(void);
-
-
-/* From: ../compat/pathfind.c line 33
- *
- * pathfind - fild a file in a list of directories
- *
- * Arguments:
- * path colon separated list of search directories
- * file the name of the file to look for
- * mode the mode bits that must be set to match
- *
- * Returns: char* - the path to the located file
- *
- * the pathfind function is available only if HAVE_PATHFIND is not defined
- *
- * 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
- */
-#ifndef HAVE_PATHFIND
-extern char* pathfind(char const*, char const*, char const*);
-#endif /* HAVE_PATHFIND */
-
-
-/* From: streqvcmp.c line 208
- *
- * strequate - map a list of characters to the same value
- *
- * Arguments:
- * ch_list characters to equivalence
- *
- * Each character in the input string get mapped to the first character
- * in the string.
- * This function name is mapped to option_strequate so as to not conflict
- * with the POSIX name space.
- */
-extern void strequate(char const*);
-
-
-/* From: streqvcmp.c line 118
- *
- * streqvcmp - compare two strings with an equivalence mapping
- *
- * Arguments:
- * str1 first string
- * str2 second string
- *
- * Returns: int - the difference between two differing characters
- *
- * Using a character mapping, two strings are compared for "equivalence".
- * Each input character is mapped to a comparison character and the
- * mapped-to characters are compared for the two NUL terminated input strings.
- * This function name is mapped to option_streqvcmp so as to not conflict
- * with the POSIX name space.
- */
-extern int streqvcmp(char const*, char const*);
-
-
-/* From: streqvcmp.c line 155
- *
- * streqvmap - Set the character mappings for the streqv functions
- *
- * Arguments:
- * From Input character
- * To Mapped-to character
- * ct compare length
- *
- * Set the character mapping. If the count (@code{ct}) is set to zero, then
- * the map is cleared by setting all entries in the map to their index
- * value. Otherwise, the "@code{From}" character is mapped to the "@code{To}"
- * character. If @code{ct} is greater than 1, then @code{From} and @code{To}
- * are incremented and the process repeated until @code{ct} entries have been
- * set. For example,
- * @example
- * streqvmap( 'a', 'A', 26 );
- * @end example
- * @noindent
- * will alter the mapping so that all English lower case letters
- * will map to upper case.
- *
- * This function name is mapped to option_streqvmap so as to not conflict
- * with the POSIX name space.
- */
-extern void streqvmap(char, char, int);
-
-
-/* From: streqvcmp.c line 77
- *
- * strneqvcmp - compare two strings with an equivalence mapping
- *
- * Arguments:
- * str1 first string
- * str2 second string
- * ct compare length
- *
- * Returns: int - the difference between two differing characters
- *
- * Using a character mapping, two strings are compared for "equivalence".
- * Each input character is mapped to a comparison character and the
- * mapped-to characters are compared for the two NUL terminated input strings.
- * The comparison is limited to @code{ct} bytes.
- * This function name is mapped to option_strneqvcmp so as to not conflict
- * with the POSIX name space.
- */
-extern int strneqvcmp(char const*, char const*, int);
-
-
-/* From: streqvcmp.c line 234
- *
- * strtransform - convert a string into its mapped-to value
- *
- * Arguments:
- * dest output string
- * src input string
- *
- * Each character in the input string is mapped and the mapped-to
- * character is put into the output.
- * This function name is mapped to option_strtransform so as to not conflict
- * with the POSIX name space.
- *
- * The source and destination may be the same.
- */
-extern void strtransform(char*, char const*);
-
-/* AutoOpts PRIVATE FUNCTIONS: */
-tOptProc optionStackArg, optionUnstackArg, optionBooleanVal, optionNumericVal;
-
-extern char* ao_string_cook(char*, int*);
-
-extern unsigned int ao_string_cook_escape_char(char const*, char*, unsigned int);
-
-extern void export_options_to_guile(tOptions*);
-
-extern void genshelloptUsage(tOptions*, int);
-
-extern void optionBooleanVal(tOptions*, tOptDesc*);
-
-extern uintptr_t optionEnumerationVal(tOptions*, tOptDesc*, char const * const *, unsigned int);
-
-extern void optionFileCheck(tOptions*, tOptDesc*, teOptFileType, tuFileMode);
-
-extern char const* optionKeywordName(tOptDesc*, unsigned int);
-
-extern void optionLoadOpt(tOptions*, tOptDesc*);
-
-extern ag_bool optionMakePath(char*, int, char const*, char const*);
-
-extern void optionNestedVal(tOptions*, tOptDesc*);
-
-extern void optionNumericVal(tOptions*, tOptDesc*);
-
-extern void optionPagedUsage(tOptions*, tOptDesc*);
-
-extern void optionParseShell(tOptions*);
-
-extern void optionPrintVersion(tOptions*, tOptDesc*);
-
-extern void optionPutShell(tOptions*);
-
-extern void optionResetOpt(tOptions*, tOptDesc*);
-
-extern void optionSetMembers(tOptions*, tOptDesc*, char const * const *, unsigned int);
-
-extern void optionShowRange(tOptions*, tOptDesc*, void *, int);
-
-extern void optionStackArg(tOptions*, tOptDesc*);
-
-extern void optionTimeVal(tOptions*, tOptDesc*);
-
-extern void optionUnstackArg(tOptions*, tOptDesc*);
-
-extern void optionUsage(tOptions*, int);
-
-extern void optionVersionStderr(tOptions*, tOptDesc*);
-
-extern void* text_mmap(char const*, int, int, tmap_info_t*);
-
-extern int text_munmap(tmap_info_t*);
-
-CPLUSPLUS_CLOSER
-#endif /* AUTOOPTS_OPTIONS_H_GUARD */
-/*
- * Local Variables:
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * options.h ends here */
+++ /dev/null
-/* -*- buffer-read-only: t -*- vi: set ro:
- *
- * DO NOT EDIT THIS FILE (usage-txt.h)
- *
- * It has been AutoGen-ed August 1, 2009 at 11:21:10 AM by AutoGen 5.9.9pre4
- * From the definitions usage-txt.def
- * and the template file usage-txt.tpl
- *
- * This file handles all the bookkeeping required for tracking all the little
- * tiny strings used by the AutoOpts library. There are 130
- * of them. This is not versioned because it is entirely internal to the
- * library and accessed by client code only in a very well-controlled way:
- * they may substitute translated strings using a procedure that steps through
- * all the string pointers.
- *
- * AutoOpts 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 3 of the License, or
- * (at your option) any later version.
- *
- * AutoOpts 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 AUTOOPTS_USAGE_TXT_H_GUARD
-#define AUTOOPTS_USAGE_TXT_H_GUARD 1
-
-#undef cch_t
-#define cch_t char const
-
-/*
- * One structure to hold all the pointers to all the stringlets.
- */
-typedef struct {
- int field_ct;
- char* utpz_GnuBoolArg;
- char* utpz_GnuKeyArg;
- char* utpz_GnuFileArg;
- char* utpz_GnuKeyLArg;
- char* utpz_GnuTimeArg;
- char* utpz_GnuNumArg;
- char* utpz_GnuStrArg;
- cch_t* apz_str[ 123 ];
-} usage_text_t;
-
-/*
- * Declare the global structure with all the pointers to translated
- * strings. This is then used by the usage generation procedure.
- */
-extern usage_text_t option_usage_text;
-
-#if defined(AUTOOPTS_INTERNAL) /* DEFINE ALL THE STRINGS = = = = = */
-/*
- * Provide a mapping from a short name to fields in this structure.
- */
-#define zAO_Bad (option_usage_text.apz_str[ 0])
-#define zAO_Big (option_usage_text.apz_str[ 1])
-#define zAO_Err (option_usage_text.apz_str[ 2])
-#define zAO_Sml (option_usage_text.apz_str[ 3])
-#define zAO_Ver (option_usage_text.apz_str[ 4])
-#define zAO_Woops (option_usage_text.apz_str[ 5])
-#define zAll (option_usage_text.apz_str[ 6])
-#define zAlt (option_usage_text.apz_str[ 7])
-#define zAmbigKey (option_usage_text.apz_str[ 8])
-#define zAmbigOptStr (option_usage_text.apz_str[ 9])
-#define zArgsMust (option_usage_text.apz_str[ 10])
-#define zAtMost (option_usage_text.apz_str[ 11])
-#define zAuto (option_usage_text.apz_str[ 12])
-#define zBadPipe (option_usage_text.apz_str[ 13])
-#define zBadVerArg (option_usage_text.apz_str[ 14])
-#define zCantFmt (option_usage_text.apz_str[ 15])
-#define zCantSave (option_usage_text.apz_str[ 16])
-#define zDefaultOpt (option_usage_text.apz_str[ 17])
-#define zDis (option_usage_text.apz_str[ 18])
-#define zEnab (option_usage_text.apz_str[ 19])
-#define zEquiv (option_usage_text.apz_str[ 20])
-#define zErrOnly (option_usage_text.apz_str[ 21])
-#define zExamineFmt (option_usage_text.apz_str[ 22])
-#define zFiveSpaces (option_usage_text.apz_str[ 23])
-#define zFlagOkay (option_usage_text.apz_str[ 24])
-#define zFmtFmt (option_usage_text.apz_str[ 25])
-#define zForkFail (option_usage_text.apz_str[ 26])
-#define zFSErrOptLoad (option_usage_text.apz_str[ 27])
-#define zFSErrReadFile (option_usage_text.apz_str[ 28])
-#define zFSOptError (option_usage_text.apz_str[ 29])
-#define zFSOptErrMayExist (option_usage_text.apz_str[ 30])
-#define zFSOptErrMustExist (option_usage_text.apz_str[ 31])
-#define zFSOptErrNoExist (option_usage_text.apz_str[ 32])
-#define zFSOptErrOpen (option_usage_text.apz_str[ 33])
-#define zFSOptErrFopen (option_usage_text.apz_str[ 34])
-#define zFileCannotExist (option_usage_text.apz_str[ 35])
-#define zFileMustExist (option_usage_text.apz_str[ 36])
-#define zGenshell (option_usage_text.apz_str[ 37])
-#define zGnuBoolArg (option_usage_text.utpz_GnuBoolArg)
-#define zGnuBreak (option_usage_text.apz_str[ 38])
-#define zGnuKeyArg (option_usage_text.utpz_GnuKeyArg)
-#define zGnuFileArg (option_usage_text.utpz_GnuFileArg)
-#define zGnuKeyLArg (option_usage_text.utpz_GnuKeyLArg)
-#define zGnuTimeArg (option_usage_text.utpz_GnuTimeArg)
-#define zGnuNestArg (option_usage_text.apz_str[ 39])
-#define zGnuNumArg (option_usage_text.utpz_GnuNumArg)
-#define zGnuOptArg (option_usage_text.apz_str[ 40])
-#define zGnuOptFmt (option_usage_text.apz_str[ 41])
-#define zGnuStrArg (option_usage_text.utpz_GnuStrArg)
-#define zIllOptChr (option_usage_text.apz_str[ 42])
-#define zIllOptStr (option_usage_text.apz_str[ 43])
-#define zIllegal (option_usage_text.apz_str[ 44])
-#define zIntRange (option_usage_text.apz_str[ 45])
-#define zInvalOptDesc (option_usage_text.apz_str[ 46])
-#define zLowerBits (option_usage_text.apz_str[ 47])
-#define zMembers (option_usage_text.apz_str[ 48])
-#define zMisArg (option_usage_text.apz_str[ 49])
-#define zMultiEquiv (option_usage_text.apz_str[ 50])
-#define zMust (option_usage_text.apz_str[ 51])
-#define zNeedOne (option_usage_text.apz_str[ 52])
-#define zNoArg (option_usage_text.apz_str[ 53])
-#define zNoArgs (option_usage_text.apz_str[ 54])
-#define zNoCreat (option_usage_text.apz_str[ 55])
-#define zNoFlags (option_usage_text.apz_str[ 56])
-#define zNoKey (option_usage_text.apz_str[ 57])
-#define zNoLim (option_usage_text.apz_str[ 58])
-#define zNoPreset (option_usage_text.apz_str[ 59])
-#define zNoResetArg (option_usage_text.apz_str[ 60])
-#define zNoRq_NoShrtTtl (option_usage_text.apz_str[ 61])
-#define zNoRq_ShrtTtl (option_usage_text.apz_str[ 62])
-#define zNoStat (option_usage_text.apz_str[ 63])
-#define zNoState (option_usage_text.apz_str[ 64])
-#define zNone (option_usage_text.apz_str[ 65])
-#define zNotDef (option_usage_text.apz_str[ 66])
-#define zNotCmdOpt (option_usage_text.apz_str[ 67])
-#define zNotEnough (option_usage_text.apz_str[ 68])
-#define zNotFile (option_usage_text.apz_str[ 69])
-#define zNotNumber (option_usage_text.apz_str[ 70])
-#define zNrmOptFmt (option_usage_text.apz_str[ 71])
-#define zNumberOpt (option_usage_text.apz_str[ 72])
-#define zOneSpace (option_usage_text.apz_str[ 73])
-#define zOnlyOne (option_usage_text.apz_str[ 74])
-#define zOptsOnly (option_usage_text.apz_str[ 75])
-#define zPathFmt (option_usage_text.apz_str[ 76])
-#define zPlsSendBugs (option_usage_text.apz_str[ 77])
-#define zPreset (option_usage_text.apz_str[ 78])
-#define zPresetFile (option_usage_text.apz_str[ 79])
-#define zPresetIntro (option_usage_text.apz_str[ 80])
-#define zProg (option_usage_text.apz_str[ 81])
-#define zProhib (option_usage_text.apz_str[ 82])
-#define zReorder (option_usage_text.apz_str[ 83])
-#define zRange (option_usage_text.apz_str[ 84])
-#define zRangeAbove (option_usage_text.apz_str[ 85])
-#define zRangeLie (option_usage_text.apz_str[ 86])
-#define zRangeBadLie (option_usage_text.apz_str[ 87])
-#define zRangeOnly (option_usage_text.apz_str[ 88])
-#define zRangeOr (option_usage_text.apz_str[ 89])
-#define zRangeErr (option_usage_text.apz_str[ 90])
-#define zRangeExact (option_usage_text.apz_str[ 91])
-#define zRangeScaled (option_usage_text.apz_str[ 92])
-#define zRangeUpto (option_usage_text.apz_str[ 93])
-#define zResetNotConfig (option_usage_text.apz_str[ 94])
-#define zReqFmt (option_usage_text.apz_str[ 95])
-#define zReqOptFmt (option_usage_text.apz_str[ 96])
-#define zReqThese (option_usage_text.apz_str[ 97])
-#define zReq_NoShrtTtl (option_usage_text.apz_str[ 98])
-#define zReq_ShrtTtl (option_usage_text.apz_str[ 99])
-#define zSepChars (option_usage_text.apz_str[100])
-#define zSetMemberSettings (option_usage_text.apz_str[101])
-#define zShrtGnuOptFmt (option_usage_text.apz_str[102])
-#define zSixSpaces (option_usage_text.apz_str[103])
-#define zStdBoolArg (option_usage_text.apz_str[104])
-#define zStdBreak (option_usage_text.apz_str[105])
-#define zStdFileArg (option_usage_text.apz_str[106])
-#define zStdKeyArg (option_usage_text.apz_str[107])
-#define zStdKeyLArg (option_usage_text.apz_str[108])
-#define zStdTimeArg (option_usage_text.apz_str[109])
-#define zStdNestArg (option_usage_text.apz_str[110])
-#define zStdNoArg (option_usage_text.apz_str[111])
-#define zStdNumArg (option_usage_text.apz_str[112])
-#define zStdOptArg (option_usage_text.apz_str[113])
-#define zStdReqArg (option_usage_text.apz_str[114])
-#define zStdStrArg (option_usage_text.apz_str[115])
-#define zTabHyp (option_usage_text.apz_str[116])
-#define zTabHypAnd (option_usage_text.apz_str[117])
-#define zTabout (option_usage_text.apz_str[118])
-#define zThreeSpaces (option_usage_text.apz_str[119])
-#define zTwoSpaces (option_usage_text.apz_str[120])
-#define zUpTo (option_usage_text.apz_str[121])
-#define zValidKeys (option_usage_text.apz_str[122])
-
- /*
- * First, set up the strings. Some of these are writable. These are all in
- * English. This gets compiled into libopts and is distributed here so that
- * xgettext (or equivalents) can extract these strings for translation.
- */
-
- static char eng_zGnuBoolArg[] = "=T/F";
- static char eng_zGnuKeyArg[] = "=KWd";
- static char eng_zGnuFileArg[] = "=file";
- static char eng_zGnuKeyLArg[] = "=Mbr";
- static char eng_zGnuTimeArg[] = "=Tim";
- static char eng_zGnuNumArg[] = "=num";
- static char eng_zGnuStrArg[] = "=str";
-static char const usage_txt[4024] =
- "AutoOpts function called without option descriptor\n\0"
- "\tThis exceeds the compiled library version: \0"
- "Automated Options Processing Error!\n"
- "\t%s called AutoOpts function with structure version %d:%d:%d.\n\0"
- "\tThis is less than the minimum library version: \0"
- "Automated Options version %s\n"
- "\tcopyright (c) 1999-2009 by Bruce Korb - all rights reserved\n\0"
- "AutoOpts lib error: defaulted to option with optional arg\n\0"
- "all\0"
- "\t\t\t\t- an alternate for %s\n\0"
- "%s error: the keyword `%s' is ambiguous for %s\n\0"
- "%s: ambiguous option -- %s\n\0"
- "%s: Command line arguments required\n\0"
- "%d %s%s options allowed\n\0"
- "version and help options:\0"
- "Error %d (%s) from the pipe(2) syscall\n\0"
- "ERROR: version option argument '%c' invalid. Use:\n"
- "\t'v' - version only\n"
- "\t'c' - version and copyright\n"
- "\t'n' - version and copyright notice\n\0"
- "ERROR: %s option conflicts with the %s option\n\0"
- "%s(optionSaveState): error: cannot allocate %d bytes\n\0"
- "\t\t\t\t- default option for unnamed options\n\0"
- "\t\t\t\t- disabled as --%s\n\0"
- "\t\t\t\t- enabled by default\n\0"
- "-equivalence\0"
- "ERROR: only \0"
- " - examining environment variables named %s_*\n\0"
- " \0"
- "Options are specified by doubled hyphens and their name\n"
- "or by a single hyphen and the flag character.\n\0"
- "%%-%ds %%s\n\0"
- "fs error %d (%s) on fork - cannot obtain %s usage\n\0"
- "File error %d (%s) opening %s for loading options\n\0"
- "fs error %d (%s) reading file %s\n\0"
- "fs error %d (%s) on %s %s for option %s\n\0"
- "stat-ing for directory\0"
- "stat-ing for regular file\0"
- "stat-ing for non-existant file\0"
- "open-ing file\0"
- "fopen-ing file\0"
- "\t\t\t\t- file must not pre-exist\n\0"
- "\t\t\t\t- file must pre-exist\n\0"
- "\n"
- "= = = = = = = =\n\n"
- "This incarnation of genshell will produce\n"
- "a shell script to parse the options for %s:\n\n\0"
- "\n"
- "%s\n\n\0"
- "=Cplx\0"
- "[=arg]\0"
- "--%2$s%1$s\0"
- "%s: illegal option -- %c\n\0"
- "%s: illegal option -- %s\n\0"
- "illegal\0"
- " or an integer from %d through %d\n\0"
- "AutoOpts ERROR: invalid option descriptor for %s\n\0"
- " or an integer mask with any of the lower %d bits set\n\0"
- "\t\t\t\t- is a set membership option\n\0"
- "%s: option `%s' requires an argument\n\0"
- "Equivalenced option '%s' was equivalenced to both\n"
- "\t'%s' and '%s'\0"
- "\t\t\t\t- must appear between %d and %d times\n\0"
- "ERROR: The %s option is required\n\0"
- "%s: option `%s' cannot have an argument\n\0"
- "%s: Command line arguments not allowed\n\0"
- "error %d (%s) creating %s\n\0"
- "Options are specified by single or double hyphens and their name.\n\0"
- "%s error: `%s' does not match any %s keywords\n\0"
- "\t\t\t\t- may appear multiple times\n\0"
- "\t\t\t\t- may not be preset\n\0"
- "The 'reset-option' option requires an argument\n\0"
- " Arg Option-Name Description\n\0"
- " Flg Arg Option-Name Description\n\0"
- "error %d (%s) stat-ing %s\n\0"
- "%s(optionRestore): error: no saved option state\n\0"
- "none\0"
- "'%s' not defined\n\0"
- "'%s' is not a command line option\n\0"
- "ERROR: The %s option must appear %d times\n\0"
- "error: cannot load options from non-regular file %s\n\0"
- "%s error: `%s' is not a recognizable number\n\0"
- " %3s %s\0"
- "The '-#<number>' option may omit the hash char\n\0"
- " \0"
- "one %s%s option allowed\n\0"
- "All arguments are named options.\n\0"
- " - reading file %s\0"
- "\n"
- "please send bug reports to: %s\n\0"
- "\t\t\t\t- may NOT appear - preset only\n\0"
- "# preset/initialization file\n"
- "# %s#\n\0"
- "\n"
- "The following option preset mechanisms are supported:\n\0"
- "program\0"
- "prohibits these options:\n\0"
- "Operands and options may be intermixed. They will be reordered.\n\0"
- "%s%ld to %ld\0"
- "%sgreater than or equal to %ld\0"
- "%sIt must lie in one of the ranges:\n\0"
- "%sThis option must lie in one of the ranges:\n\0"
- "%sit must be: \0"
- ", or\n\0"
- "%s error: %s option value ``%s'' is out of range.\n\0"
- "%s%ld exactly\0"
- "%sis scalable with a suffix: k/K/m/M/g/G/t/T\n\0"
- "%sless than or equal to %ld\0"
- "The --reset-option has not been configured.\n\0"
- "ERROR: %s option requires the %s option\n\0"
- " %3s %-14s %s\0"
- "requires these options:\n\0"
- " Arg Option-Name Req? Description\n\0"
- " Flg Arg Option-Name Req? Description\n\0"
- "-_^\0"
- "or you may use a numeric representation. Preceding these with a '!' will\n"
- "clear the bits, specifying 'none' will clear all bits, and 'all' will set them\n"
- "all. Multiple entries may be passed as an option argument list.\n\0"
- "%s\0"
- " \0"
- "T/F\0"
- "\n"
- "%s\n\n"
- "%s\0"
- "Fil\0"
- "KWd\0"
- "Mbr\0"
- "Tim\0"
- "Cpx\0"
- "no \0"
- "Num\0"
- "opt\0"
- "YES\0"
- "Str\0"
- "\t\t\t\t- \0"
- "\t\t\t\t-- and \0"
- "\t\t\t\t%s\n\0"
- " \0"
- " \0"
- "\t\t\t\t- may appear up to %d times\n\0"
- "The valid \"%s\" option keywords are:\n\0";
-
-
- /*
- * Now, define (and initialize) the structure that contains
- * the pointers to all these strings.
- * Aren't you glad you don't maintain this by hand?
- */
- usage_text_t option_usage_text = {
- 130,
- eng_zGnuBoolArg, eng_zGnuKeyArg, eng_zGnuFileArg, eng_zGnuKeyLArg,
- eng_zGnuTimeArg, eng_zGnuNumArg, eng_zGnuStrArg,
- {
- usage_txt + 0, usage_txt + 52, usage_txt + 98, usage_txt + 197,
- usage_txt + 247, usage_txt + 338, usage_txt + 397, usage_txt + 401,
- usage_txt + 428, usage_txt + 477, usage_txt + 505, usage_txt + 542,
- usage_txt + 567, usage_txt + 593, usage_txt + 633, usage_txt + 770,
- usage_txt + 818, usage_txt + 872, usage_txt + 914, usage_txt + 938,
- usage_txt + 964, usage_txt + 977, usage_txt + 991, usage_txt +1038,
- usage_txt +1044, usage_txt +1147, usage_txt +1159, usage_txt +1210,
- usage_txt +1261, usage_txt +1295, usage_txt +1336, usage_txt +1359,
- usage_txt +1385, usage_txt +1416, usage_txt +1430, usage_txt +1445,
- usage_txt +1476, usage_txt +1503, usage_txt +1609, usage_txt +1615,
- usage_txt +1621, usage_txt +1628, usage_txt +1639, usage_txt +1665,
- usage_txt +1691, usage_txt +1699, usage_txt +1735, usage_txt +1786,
- usage_txt +1842, usage_txt +1876, usage_txt +1914, usage_txt +1979,
- usage_txt +2022, usage_txt +2057, usage_txt +2098, usage_txt +2138,
- usage_txt +2165, usage_txt +2232, usage_txt +2280, usage_txt +2313,
- usage_txt +2338, usage_txt +2386, usage_txt +2421, usage_txt +2459,
- usage_txt +2486, usage_txt +2535, usage_txt +2540, usage_txt +2558,
- usage_txt +2593, usage_txt +2637, usage_txt +2691, usage_txt +2737,
- usage_txt +2745, usage_txt +2793, usage_txt +2795, usage_txt +2820,
- usage_txt +2854, usage_txt +2873, usage_txt +2907, usage_txt +2943,
- usage_txt +2981, usage_txt +3037, usage_txt +3045, usage_txt +3071,
- usage_txt +3137, usage_txt +3150, usage_txt +3181, usage_txt +3218,
- usage_txt +3264, usage_txt +3280, usage_txt +3286, usage_txt +3338,
- usage_txt +3352, usage_txt +3398, usage_txt +3426, usage_txt +3471,
- usage_txt +3513, usage_txt +3527, usage_txt +3552, usage_txt +3592,
- usage_txt +3635, usage_txt +3639, usage_txt +3858, usage_txt +3861,
- usage_txt +3868, usage_txt +3872, usage_txt +3880, usage_txt +3884,
- usage_txt +3888, usage_txt +3892, usage_txt +3896, usage_txt +3900,
- usage_txt +3904, usage_txt +3908, usage_txt +3912, usage_txt +3916,
- usage_txt +3920, usage_txt +3927, usage_txt +3939, usage_txt +3947,
- usage_txt +3951, usage_txt +3954, usage_txt +3987
- }
- };
-
-#endif /* DO_TRANSLATIONS */
-#endif /* AUTOOPTS_USAGE_TXT_H_GUARD */
+++ /dev/null
-
-/*
- * $Id: boolean.c,v 4.17 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-08-03 13:06:02 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
- */
-
-/*=export_func optionBooleanVal
- * private:
- *
- * what: Decipher a boolean value
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Decipher a true or false value for a boolean valued option argument.
- * The value is true, unless it starts with 'n' or 'f' or "#f" or
- * it is an empty string or it is a number that evaluates to zero.
-=*/
-void
-optionBooleanVal( tOptions* pOpts, tOptDesc* pOD )
-{
- char* pz;
- ag_bool res = AG_TRUE;
-
- if ((pOD->fOptState & OPTST_RESET) != 0)
- return;
-
- if (pOD->optArg.argString == NULL) {
- pOD->optArg.argBool = AG_FALSE;
- return;
- }
-
- switch (*(pOD->optArg.argString)) {
- case '0':
- {
- long val = strtol( pOD->optArg.argString, &pz, 0 );
- if ((val != 0) || (*pz != NUL))
- break;
- /* FALLTHROUGH */
- }
- case 'N':
- case 'n':
- case 'F':
- case 'f':
- case NUL:
- res = AG_FALSE;
- break;
- case '#':
- if (pOD->optArg.argString[1] != 'f')
- break;
- res = AG_FALSE;
- }
-
- if (pOD->fOptState & OPTST_ALLOC_ARG) {
- AGFREE(pOD->optArg.argString);
- pOD->fOptState &= ~OPTST_ALLOC_ARG;
- }
- pOD->optArg.argBool = res;
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/boolean.c */
+++ /dev/null
-/* -*- Mode: C -*- */
-
-/* compat.h --- fake the preprocessor into handlng portability
- *
- * Time-stamp: "2008-06-14 09:36:25 bkorb"
- *
- * $Id: compat.h,v 4.21 2009/01/01 16:51:52 bkorb Exp $
- *
- * compat.h is free software.
- * This file is part of AutoGen.
- *
- * AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved
- *
- * 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 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/>.
- *
- * As a special exception, Bruce Korb gives permission for additional
- * uses of the text contained in the release of compat.h.
- *
- * 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.
- *
- * 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.
- */
-#ifndef COMPAT_H_GUARD
-#define COMPAT_H_GUARD 1
-
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-
-#elif defined(_WIN32) && !defined(__CYGWIN__)
-# include "windows-config.h"
-
-#else
-# error "compat.h" requires "config.h"
- choke me.
-#endif
-
-
-#ifndef HAVE_STRSIGNAL
- char * strsignal( int signo );
-#endif
-
-#define _GNU_SOURCE 1 /* for strsignal in GNU's libc */
-#define __USE_GNU 1 /* exact same thing as above */
-#define __EXTENSIONS__ 1 /* and another way to call for it */
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * SYSTEM HEADERS:
- */
-#include <sys/types.h>
-#ifdef HAVE_SYS_MMAN_H
-# include <sys/mman.h>
-#endif
-#include <sys/param.h>
-#if HAVE_SYS_PROCSET_H
-# include <sys/procset.h>
-#endif
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#if defined( HAVE_SOLARIS_SYSINFO )
-# include <sys/systeminfo.h>
-#elif defined( HAVE_UNAME_SYSCALL )
-# include <sys/utsname.h>
-#endif
-
-#ifdef DAEMON_ENABLED
-# if HAVE_SYS_STROPTS_H
-# include <sys/stropts.h>
-# endif
-
-# if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-# endif
-
-# if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H)
-# error This system cannot support daemon processing
- Choke Me.
-# endif
-
-# if HAVE_SYS_POLL_H
-# include <sys/poll.h>
-# endif
-
-# if HAVE_SYS_SELECT_H
-# include <sys/select.h>
-# endif
-
-# if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-# endif
-
-# if HAVE_SYS_UN_H
-# include <sys/un.h>
-# endif
-#endif
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * USER HEADERS:
- */
-#include <stdio.h>
-#include <assert.h>
-#include <ctype.h>
-
-/*
- * Directory opening stuff:
- */
-# if defined (_POSIX_SOURCE)
-/* Posix does not require that the d_ino field be present, and some
- systems do not provide it. */
-# define REAL_DIR_ENTRY(dp) 1
-# else /* !_POSIX_SOURCE */
-# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
-# endif /* !_POSIX_SOURCE */
-
-# if defined (HAVE_DIRENT_H)
-# include <dirent.h>
-# define D_NAMLEN(dirent) strlen((dirent)->d_name)
-# else /* !HAVE_DIRENT_H */
-# define dirent direct
-# define D_NAMLEN(dirent) (dirent)->d_namlen
-# if defined (HAVE_SYS_NDIR_H)
-# include <sys/ndir.h>
-# endif /* HAVE_SYS_NDIR_H */
-# if defined (HAVE_SYS_DIR_H)
-# include <sys/dir.h>
-# endif /* HAVE_SYS_DIR_H */
-# if defined (HAVE_NDIR_H)
-# include <ndir.h>
-# endif /* HAVE_NDIR_H */
-# endif /* !HAVE_DIRENT_H */
-
-#include <errno.h>
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-#ifndef O_NONBLOCK
-# define O_NONBLOCK FNDELAY
-#endif
-
-#if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H)
-# include <libgen.h>
-#endif
-
-#if defined(HAVE_LIMITS_H) /* this is also in options.h */
-# include <limits.h>
-#elif defined(HAVE_SYS_LIMITS_H)
-# include <sys/limits.h>
-#endif /* HAVE_LIMITS/SYS_LIMITS_H */
-
-#include <memory.h>
-#include <setjmp.h>
-#include <signal.h>
-
-#if defined( HAVE_STDINT_H )
-# include <stdint.h>
-#elif defined( HAVE_INTTYPES_H )
-# include <inttypes.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <time.h>
-
-#ifdef HAVE_UTIME_H
-# include <utime.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * FIXUPS and CONVIENCE STUFF:
- */
-#ifdef __cplusplus
-# define EXTERN extern "C"
-#else
-# define EXTERN extern
-#endif
-
-/* some systems #def errno! and others do not declare it!! */
-#ifndef errno
- extern int errno;
-#endif
-
-/* Some machines forget this! */
-
-# ifndef EXIT_FAILURE
-# define EXIT_SUCCESS 0
-# define EXIT_FAILURE 1
-# endif
-
-#ifndef NUL
-# define NUL '\0'
-#endif
-
-#ifndef NULL
-# define NULL 0
-#endif
-
-#if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H)
-# include <sys/param.h>
-#endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */
-
-#if !defined (MAXPATHLEN) && defined (PATH_MAX)
-# define MAXPATHLEN PATH_MAX
-#endif /* !MAXPATHLEN && PATH_MAX */
-
-#if !defined (MAXPATHLEN) && defined(_MAX_PATH)
-# define PATH_MAX _MAX_PATH
-# define MAXPATHLEN _MAX_PATH
-#endif
-
-#if !defined (MAXPATHLEN)
-# define MAXPATHLEN ((size_t)4096)
-#endif /* MAXPATHLEN */
-
-#define AG_PATH_MAX ((size_t)MAXPATHLEN)
-
-#ifndef LONG_MAX
-# define LONG_MAX ~(1L << (8*sizeof(long) -1))
-# define INT_MAX ~(1 << (8*sizeof(int) -1))
-#endif
-
-#ifndef ULONG_MAX
-# define ULONG_MAX ~(OUL)
-# define UINT_MAX ~(OU)
-#endif
-
-#ifndef SHORT_MAX
-# define SHORT_MAX ~(1 << (8*sizeof(short) -1))
-#else
-# define USHORT_MAX ~(OUS)
-#endif
-
-#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
-
-#ifndef HAVE_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
-#endif
-
-#ifndef HAVE_INTPTR_T
- typedef signed long intptr_t;
-#endif
-#ifndef HAVE_UINTPTR_T
- typedef unsigned long uintptr_t;
-#endif
-#ifndef HAVE_SIZE_T
- typedef unsigned int size_t;
-#endif
-#ifndef HAVE_WINT_T
- typedef unsigned int wint_t;
-#endif
-#ifndef HAVE_PID_T
- typedef signed int pid_t;
-#endif
-
-/* redefine these for BSD style string libraries */
-#ifndef HAVE_STRCHR
-# define strchr index
-# define strrchr rindex
-#endif
-
-#ifdef USE_FOPEN_BINARY
-# ifndef FOPEN_BINARY_FLAG
-# define FOPEN_BINARY_FLAG "b"
-# endif
-# ifndef FOPEN_TEXT_FLAG
-# define FOPEN_TEXT_FLAG "t"
-# endif
-#else
-# ifndef FOPEN_BINARY_FLAG
-# define FOPEN_BINARY_FLAG
-# endif
-# ifndef FOPEN_TEXT_FLAG
-# define FOPEN_TEXT_FLAG
-# endif
-#endif
-
-#ifndef STR
-# define _STR(s) #s
-# define STR(s) _STR(s)
-#endif
-
-/* ##### Pointer sized word ##### */
-
-/* FIXME: the MAX stuff in here is broken! */
-#if SIZEOF_CHARP > SIZEOF_INT
- typedef long t_word;
- #define WORD_MAX LONG_MAX
- #define WORD_MIN LONG_MIN
-#else /* SIZEOF_CHARP <= SIZEOF_INT */
- typedef int t_word;
- #define WORD_MAX INT_MAX
- #define WORD_MIN INT_MIN
-#endif
-
-#endif /* COMPAT_H_GUARD */
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of compat/compat.h */
+++ /dev/null
-/* -*- Mode: C -*- */
-
-/* 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/07/04 20:51:18 $
- * by: bkorb
- *
- * $Id: pathfind.c,v 4.11 2007/07/04 20:51:18 bkorb Exp $
- */
-
-/* Code: */
-
-#include "compat.h"
-#ifndef HAVE_PATHFIND
-#if defined(__windows__) && !defined(__CYGWIN__)
-char*
-pathfind( char const* path,
- char const* fileName,
- char const* mode )
-{
- return NULL;
-}
-#else
-
-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 )
-{
- int p_index = 0;
- int mode_bits = 0;
- char* pathName = NULL;
- char zPath[ AG_PATH_MAX + 1 ];
-
- if (strchr( mode, 'r' )) mode_bits |= R_OK;
- if (strchr( mode, 'w' )) mode_bits |= W_OK;
- if (strchr( mode, 'x' )) mode_bits |= X_OK;
-
- /*
- * FOR each non-null entry in the colon-separated path, DO ...
- */
- for (;;) {
- DIR* dirP;
- char* colon_unit = extract_colon_unit( zPath, path, &p_index );
-
- /*
- * IF no more entries, THEN quit
- */
- if (colon_unit == NULL)
- break;
-
- dirP = opendir( colon_unit );
-
- /*
- * IF the directory is inaccessable, THEN next directory
- */
- if (dirP == NULL)
- continue;
-
- /*
- * FOR every entry in the given directory, ...
- */
- for (;;) {
- struct dirent *entP = readdir( dirP );
-
- if (entP == (struct dirent*)NULL)
- break;
-
- /*
- * 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);
-
- /*
- * Make sure we can access it in the way we want
- */
- if (access( pzFullName, mode_bits ) >= 0) {
- /*
- * We can, so normalize the name and return it below
- */
- pathName = canonicalize_pathname( pzFullName );
- }
-
- free( (void*)pzFullName );
- break;
- }
- }
-
- closedir( dirP );
-
- if (pathName != NULL)
- break;
- }
-
- return pathName;
-}
-
-/*
- * Turn STRING (a pathname) into an absolute pathname, assuming that
- * DOT_PATH contains the symbolic location of `.'. This always returns
- * a new string, even if STRING was an absolute pathname to begin with.
- */
-static char*
-make_absolute( char const *string, char const *dot_path )
-{
- char *result;
- int result_len;
-
- if (!dot_path || *string == '/') {
- result = strdup( string );
- } else {
- if (dot_path && dot_path[0]) {
- result = malloc( 2 + strlen( dot_path ) + strlen( string ) );
- strcpy( result, dot_path );
- result_len = strlen( result );
- if (result[result_len - 1] != '/') {
- result[result_len++] = '/';
- result[result_len] = '\0';
- }
- } else {
- result = malloc( 3 + strlen( string ) );
- result[0] = '.'; result[1] = '/'; result[2] = '\0';
- result_len = 2;
- }
-
- strcpy( result + result_len, string );
- }
-
- return result;
-}
-
-/*
- * Canonicalize PATH, and return a new path. The new path differs from
- * PATH in that:
- *
- * Multiple `/'s are collapsed to a single `/'.
- * Leading `./'s are removed.
- * Trailing `/.'s are removed.
- * Trailing `/'s are removed.
- * Non-leading `../'s and trailing `..'s are handled by removing
- * portions of the path.
- */
-static char*
-canonicalize_pathname( char *path )
-{
- int i, start;
- char stub_char, *result;
-
- /* The result cannot be larger than the input PATH. */
- result = strdup( path );
-
- stub_char = (*path == '/') ? '/' : '.';
-
- /* Walk along RESULT looking for things to compact. */
- i = 0;
- while (result[i]) {
- while (result[i] != '\0' && result[i] != '/')
- i++;
-
- start = i++;
-
- /* If we didn't find any slashes, then there is nothing left to
- * do.
- */
- if (!result[start])
- break;
-
- /* Handle multiple `/'s in a row. */
- while (result[i] == '/')
- i++;
-
-#if !defined (apollo)
- if ((start + 1) != i)
-#else
- if ((start + 1) != i && (start != 0 || i != 2))
-#endif /* apollo */
- {
- strcpy( result + start + 1, result + i );
- i = start + 1;
- }
-
- /* Handle backquoted `/'. */
- if (start > 0 && result[start - 1] == '\\')
- continue;
-
- /* Check for trailing `/', and `.' by itself. */
- if ((start && !result[i])
- || (result[i] == '.' && !result[i+1])) {
- result[--i] = '\0';
- break;
- }
-
- /* Check for `../', `./' or trailing `.' by itself. */
- if (result[i] == '.') {
- /* Handle `./'. */
- if (result[i + 1] == '/') {
- strcpy( result + i, result + i + 1 );
- i = (start < 0) ? 0 : start;
- continue;
- }
-
- /* Handle `../' or trailing `..' by itself. */
- if (result[i + 1] == '.' &&
- (result[i + 2] == '/' || !result[i + 2])) {
- while (--start > -1 && result[start] != '/')
- ;
- strcpy( result + start + 1, result + i + 2 );
- i = (start < 0) ? 0 : start;
- continue;
- }
- }
- }
-
- if (!*result) {
- *result = stub_char;
- result[1] = '\0';
- }
-
- return result;
-}
-
-/*
- * Given a string containing units of information separated by colons,
- * return the next one pointed to by (P_INDEX), or NULL if there are no
- * more. Advance (P_INDEX) to the character after the colon.
- */
-static char*
-extract_colon_unit( char* pzDir, char const *string, int *p_index )
-{
- char* pzDest = pzDir;
- int ix = *p_index;
-
- if (string == NULL)
- return NULL;
-
- if ((unsigned)ix >= strlen( string ))
- return NULL;
-
- {
- char const* pzSrc = string + ix;
-
- while (*pzSrc == ':') pzSrc++;
-
- for (;;) {
- char ch = (*(pzDest++) = *(pzSrc++));
- switch (ch) {
- case ':':
- pzDest[-1] = NUL;
- case NUL:
- goto copy_done;
- }
-
- if ((pzDest - pzDir) >= AG_PATH_MAX)
- break;
- } copy_done:;
-
- ix = pzSrc - string;
- }
-
- if (*pzDir == NUL)
- return NULL;
-
- *p_index = ix;
- return pzDir;
-}
-#endif /* __windows__ / __CYGWIN__ */
-#endif /* HAVE_PATHFIND */
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of compat/pathfind.c */
+++ /dev/null
-
-#ifndef HAVE_VPRINTF
-#include "choke-me: no vprintf and no snprintf"
-#endif
-
-#if defined(HAVE_STDARG_H)
-# include <stdarg.h>
-# ifndef VA_START
-# define VA_START(a, f) va_start(a, f)
-# define VA_END(a) va_end(a)
-# endif /* VA_START */
-# define SNV_USING_STDARG_H
-
-#elif defined(HAVE_VARARGS_H)
-# include <varargs.h>
-# ifndef VA_START
-# define VA_START(a, f) va_start(a)
-# define VA_END(a) va_end(a)
-# endif /* VA_START */
-# undef SNV_USING_STDARG_H
-
-#else
-# include "must-have-stdarg-or-varargs"
-#endif
-
-static int
-snprintf(char *str, size_t n, char const *fmt, ...)
-{
- va_list ap;
- int rval;
-
-#ifdef VSPRINTF_CHARSTAR
- char *rp;
- VA_START(ap, fmt);
- rp = vsprintf(str, fmt, ap);
- VA_END(ap);
- rval = strlen(rp);
-
-#else
- VA_START(ap, fmt);
- rval = vsprintf(str, fmt, ap);
- VA_END(ap);
-#endif
-
- if (rval > n) {
- fprintf(stderr, "snprintf buffer overrun %d > %d\n", rval, (int)n);
- abort();
- }
- return rval;
-}
-
-static int
-vsnprintf( char *str, size_t n, char const *fmt, va_list ap )
-{
-#ifdef VSPRINTF_CHARSTAR
- return (strlen(vsprintf(str, fmt, ap)));
-#else
- return (vsprintf(str, fmt, ap));
-#endif
-}
+++ /dev/null
-/*
- SYNOPSIS
- #include <string.h>
-
- char *strchr(char const *s, int c);
-
- char *strrchr(char const *s, int c);
-
- DESCRIPTION
- The strchr() function returns a pointer to the first occurrence of the
- character c in the string s.
-
- The strrchr() function returns a pointer to the last occurrence of the
- character c in the string s.
-
- Here "character" means "byte" - these functions do not work with wide
- or multi-byte characters.
-
- RETURN VALUE
- The strchr() and strrchr() functions return a pointer to the matched
- character or NULL if the character is not found.
-
- CONFORMING TO
- SVID 3, POSIX, BSD 4.3, ISO 9899
-*/
-
-char*
-strchr( char const *s, int c)
-{
- do {
- if ((unsigned)*s == (unsigned)c)
- return s;
-
- } while (*(++s) != NUL);
-
- return NULL;
-}
-
-char*
-strrchr( char const *s, int c)
-{
- char const *e = s + strlen(s);
-
- for (;;) {
- if (--e < s)
- break;
-
- if ((unsigned)*e == (unsigned)c)
- return e;
- }
- return NULL;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of compat/strsignal.c */
+++ /dev/null
-/*
- * Platforms without strdup ?!?!?!
- */
-
-static char *
-strdup( char const *s )
-{
- char *cp;
-
- if (s == NULL)
- return NULL;
-
- cp = (char *) AGALOC((unsigned) (strlen(s)+1), "strdup");
-
- if (cp != NULL)
- (void) strcpy(cp, s);
-
- return cp;
-}
+++ /dev/null
-
-/*
- * Time-stamp: "2009-07-22 18:53:59 bkorb"
- * by: bkorb
- * Last Committed: $Date: 2009/07/23 02:07:46 $
- *
- * This file is part of AutoGen.
- *
- * AutoGen copyright (c) 1992-2009 by Bruce Korb - all rights reserved
- *
- * 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 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/>.
- */
-#ifndef WINDOWS_CONFIG_HACKERY
-#define WINDOWS_CONFIG_HACKERY 1
-
-/*
- * The definitions below have been stolen from NTP's config.h for Windows.
- * However, they may be kept here in order to keep libopts independent from
- * the NTP project.
- */
-#ifndef __windows__
-# define __windows__ 4
-#endif
-
-/*
- * Miscellaneous functions that Microsoft maps
- * to other names
- *
- * #define inline __inline
- * #define vsnprintf _vsnprintf
- */
-#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
- */
-#ifndef _WSPIAPI_H_
-#define _WSPIAPI_H_
-#endif
-
-/* Prevent inclusion of winsock.h in windows.h */
-#ifndef _WINSOCKAPI_
-#define _WINSOCKAPI_
-#endif
-
-#ifndef __RPCASYNC_H__
-#define __RPCASYNC_H__
-#endif
-
-/* Include Windows headers */
-#include <windows.h>
-#include <winsock2.h>
-#include <limits.h>
-
-/*
- * Compatibility declarations for Windows, assuming SYS_WINNT
- * has been defined.
- */
-#define strdup _strdup
-#define stat _stat /* struct stat from <sys/stat.h> */
-#define unlink _unlink
-#define fchmod( _x, _y );
-#define ssize_t SSIZE_T
-
-#include <io.h>
-#define open _open
-#define close _close
-#define read _read
-#define write _write
-#define lseek _lseek
-#define pipe _pipe
-#define dup2 _dup2
-
-#define O_RDWR _O_RDWR
-#define O_RDONLY _O_RDONLY
-#define O_EXCL _O_EXCL
-
-#ifndef S_ISREG
-# define S_IFREG _S_IFREG
-# define S_ISREG(mode) (((mode) & S_IFREG) == S_IFREG)
-#endif
-
-#ifndef S_ISDIR
-# define S_IFDIR _S_IFDIR
-# define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR)
-#endif
-
-#endif /* WINDOWS_CONFIG_HACKERY */
+++ /dev/null
-/*
- * $Id: configfile.c,v 1.36 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2009-01-18 10:21:58 bkorb"
- *
- * configuration/rc/ini file handling.
- *
- * 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
- */
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-filePreset(
- tOptions* pOpts,
- char const* pzFileName,
- int direction );
-
-static char*
-handleComment( char* pzText );
-
-static char*
-handleConfig(
- tOptions* pOpts,
- tOptState* pOS,
- char* pzText,
- int direction );
-
-static char*
-handleDirective(
- tOptions* pOpts,
- char* pzText );
-
-static char*
-handleProgramSection(
- tOptions* pOpts,
- char* pzText );
-
-static char*
-handleStructure(
- tOptions* pOpts,
- tOptState* pOS,
- char* pzText,
- int direction );
-
-static char*
-parseKeyWordType(
- tOptions* pOpts,
- char* pzText,
- tOptionValue* pType );
-
-static char*
-parseSetMemType(
- tOptions* pOpts,
- char* pzText,
- tOptionValue* pType );
-
-static char*
-parseValueType(
- char* pzText,
- tOptionValue* pType );
-
-static char*
-skipUnknown( char* pzText );
-/* = = = END-STATIC-FORWARD = = = */
-
-
-/*=export_func configFileLoad
- *
- * what: parse a configuration file
- * arg: + char const* + pzFile + the file to load +
- *
- * ret_type: const tOptionValue*
- * ret_desc: An allocated, compound value structure
- *
- * doc:
- * This routine will load a named configuration file and parse the
- * text as a hierarchically valued option. The option descriptor
- * created from an option definition file is not used via this interface.
- * The returned value is "named" with the input file name and is of
- * type "@code{OPARG_TYPE_HIERARCHY}". It may be used in calls to
- * @code{optionGetValue()}, @code{optionNextValue()} and
- * @code{optionUnloadNested()}.
- *
- * err:
- * If the file cannot be loaded or processed, @code{NULL} is returned and
- * @var{errno} is set. It may be set by a call to either @code{open(2)}
- * @code{mmap(2)} or other file system calls, or it may be:
- * @itemize @bullet
- * @item
- * @code{ENOENT} - the file was empty.
- * @item
- * @code{EINVAL} - the file contents are invalid -- not properly formed.
- * @item
- * @code{ENOMEM} - not enough memory to allocate the needed structures.
- * @end itemize
-=*/
-const tOptionValue*
-configFileLoad( char const* pzFile )
-{
- tmap_info_t cfgfile;
- tOptionValue* pRes = NULL;
- tOptionLoadMode save_mode = option_load_mode;
-
- char* pzText =
- text_mmap( pzFile, PROT_READ, MAP_PRIVATE, &cfgfile );
-
- if (TEXT_MMAP_FAILED_ADDR(pzText))
- return NULL; /* errno is set */
-
- option_load_mode = OPTION_LOAD_COOKED;
- pRes = optionLoadNested(pzText, pzFile, strlen(pzFile));
-
- if (pRes == NULL) {
- int err = errno;
- text_munmap( &cfgfile );
- errno = err;
- } else
- text_munmap( &cfgfile );
-
- option_load_mode = save_mode;
- return pRes;
-}
-
-
-/*=export_func optionFindValue
- *
- * what: find a hierarcicaly valued option instance
- * arg: + const tOptDesc* + pOptDesc + an option with a nested arg type +
- * arg: + char const* + name + name of value to find +
- * arg: + char const* + value + the matching value +
- *
- * ret_type: const tOptionValue*
- * ret_desc: a compound value structure
- *
- * doc:
- * This routine will find an entry in a nested value option or configurable.
- * It will search through the list and return a matching entry.
- *
- * err:
- * The returned result is NULL and errno is set:
- * @itemize @bullet
- * @item
- * @code{EINVAL} - the @code{pOptValue} does not point to a valid
- * hierarchical option value.
- * @item
- * @code{ENOENT} - no entry matched the given name.
- * @end itemize
-=*/
-const tOptionValue*
-optionFindValue( const tOptDesc* pOptDesc,
- char const* pzName, char const* pzVal )
-{
- const tOptionValue* pRes = NULL;
-
- if ( (pOptDesc == NULL)
- || (OPTST_GET_ARGTYPE(pOptDesc->fOptState) != OPARG_TYPE_HIERARCHY)) {
- errno = EINVAL;
- }
-
- else if (pOptDesc->optCookie == NULL) {
- errno = ENOENT;
- }
-
- else do {
- tArgList* pAL = pOptDesc->optCookie;
- int ct = pAL->useCt;
- void** ppOV = (void**)(pAL->apzArgs);
-
- if (ct == 0) {
- errno = ENOENT;
- break;
- }
-
- if (pzName == NULL) {
- pRes = (tOptionValue*)*ppOV;
- break;
- }
-
- while (--ct >= 0) {
- const tOptionValue* pOV = *(ppOV++);
- const tOptionValue* pRV = optionGetValue( pOV, pzName );
-
- if (pRV == NULL)
- continue;
-
- if (pzVal == NULL) {
- pRes = pOV;
- break;
- }
- }
- if (pRes == NULL)
- errno = ENOENT;
- } while (0);
-
- return pRes;
-}
-
-
-/*=export_func optionFindNextValue
- *
- * what: find a hierarcicaly valued option instance
- * arg: + const tOptDesc* + pOptDesc + an option with a nested arg type +
- * arg: + const tOptionValue* + pPrevVal + the last entry +
- * arg: + char const* + name + name of value to find +
- * arg: + char const* + value + the matching value +
- *
- * ret_type: const tOptionValue*
- * ret_desc: a compound value structure
- *
- * doc:
- * This routine will find the next entry in a nested value option or
- * configurable. It will search through the list and return the next entry
- * that matches the criteria.
- *
- * err:
- * The returned result is NULL and errno is set:
- * @itemize @bullet
- * @item
- * @code{EINVAL} - the @code{pOptValue} does not point to a valid
- * hierarchical option value.
- * @item
- * @code{ENOENT} - no entry matched the given name.
- * @end itemize
-=*/
-const tOptionValue*
-optionFindNextValue( const tOptDesc* pOptDesc, const tOptionValue* pPrevVal,
- char const* pzName, char const* pzVal )
-{
- int foundOldVal = 0;
- tOptionValue* pRes = NULL;
-
- if ( (pOptDesc == NULL)
- || (OPTST_GET_ARGTYPE(pOptDesc->fOptState) != OPARG_TYPE_HIERARCHY)) {
- errno = EINVAL;
- }
-
- else if (pOptDesc->optCookie == NULL) {
- errno = ENOENT;
- }
-
- else do {
- tArgList* pAL = pOptDesc->optCookie;
- int ct = pAL->useCt;
- void** ppOV = (void**)pAL->apzArgs;
-
- if (ct == 0) {
- errno = ENOENT;
- break;
- }
-
- while (--ct >= 0) {
- tOptionValue* pOV = *(ppOV++);
- if (foundOldVal) {
- pRes = pOV;
- break;
- }
- if (pOV == pPrevVal)
- foundOldVal = 1;
- }
- if (pRes == NULL)
- errno = ENOENT;
- } while (0);
-
- return pRes;
-}
-
-
-/*=export_func optionGetValue
- *
- * what: get a specific value from a hierarcical list
- * arg: + const tOptionValue* + pOptValue + a hierarchcal value +
- * arg: + char const* + valueName + name of value to get +
- *
- * ret_type: const tOptionValue*
- * ret_desc: a compound value structure
- *
- * doc:
- * This routine will find an entry in a nested value option or configurable.
- * If "valueName" is NULL, then the first entry is returned. Otherwise,
- * the first entry with a name that exactly matches the argument will be
- * returned.
- *
- * err:
- * The returned result is NULL and errno is set:
- * @itemize @bullet
- * @item
- * @code{EINVAL} - the @code{pOptValue} does not point to a valid
- * hierarchical option value.
- * @item
- * @code{ENOENT} - no entry matched the given name.
- * @end itemize
-=*/
-const tOptionValue*
-optionGetValue( const tOptionValue* pOld, char const* pzValName )
-{
- tArgList* pAL;
- tOptionValue* pRes = NULL;
-
- if ((pOld == NULL) || (pOld->valType != OPARG_TYPE_HIERARCHY)) {
- errno = EINVAL;
- return NULL;
- }
- pAL = pOld->v.nestVal;
-
- if (pAL->useCt > 0) {
- int ct = pAL->useCt;
- void** papOV = (void**)(pAL->apzArgs);
-
- if (pzValName == NULL) {
- pRes = (tOptionValue*)*papOV;
- }
-
- else do {
- tOptionValue* pOV = *(papOV++);
- if (strcmp( pOV->pzName, pzValName ) == 0) {
- pRes = pOV;
- break;
- }
- } while (--ct > 0);
- }
- if (pRes == NULL)
- errno = ENOENT;
- return pRes;
-}
-
-
-/*=export_func optionNextValue
- *
- * what: get the next value from a hierarchical list
- * arg: + const tOptionValue* + pOptValue + a hierarchcal list value +
- * arg: + const tOptionValue* + pOldValue + a value from this list +
- *
- * ret_type: const tOptionValue*
- * ret_desc: a compound value structure
- *
- * doc:
- * This routine will return the next entry after the entry passed in. At the
- * end of the list, NULL will be returned. If the entry is not found on the
- * list, NULL will be returned and "@var{errno}" will be set to EINVAL.
- * The "@var{pOldValue}" must have been gotten from a prior call to this
- * routine or to "@code{opitonGetValue()}".
- *
- * err:
- * The returned result is NULL and errno is set:
- * @itemize @bullet
- * @item
- * @code{EINVAL} - the @code{pOptValue} does not point to a valid
- * hierarchical option value or @code{pOldValue} does not point to a
- * member of that option value.
- * @item
- * @code{ENOENT} - the supplied @code{pOldValue} pointed to the last entry.
- * @end itemize
-=*/
-tOptionValue const *
-optionNextValue(tOptionValue const * pOVList,tOptionValue const * pOldOV )
-{
- tArgList* pAL;
- tOptionValue* pRes = NULL;
- int err = EINVAL;
-
- if ((pOVList == NULL) || (pOVList->valType != OPARG_TYPE_HIERARCHY)) {
- errno = EINVAL;
- return NULL;
- }
- pAL = pOVList->v.nestVal;
- {
- int ct = pAL->useCt;
- void** papNV = (void**)(pAL->apzArgs);
-
- while (ct-- > 0) {
- tOptionValue* pNV = *(papNV++);
- if (pNV == pOldOV) {
- if (ct == 0) {
- err = ENOENT;
-
- } else {
- err = 0;
- pRes = (tOptionValue*)*papNV;
- }
- break;
- }
- }
- }
- if (err != 0)
- errno = err;
- return pRes;
-}
-
-
-/* filePreset
- *
- * Load a file containing presetting information (a configuration file).
- */
-static void
-filePreset(
- tOptions* pOpts,
- char const* pzFileName,
- int direction )
-{
- tmap_info_t cfgfile;
- tOptState optst = OPTSTATE_INITIALIZER(PRESET);
- char* pzFileText =
- text_mmap( pzFileName, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile );
-
- if (TEXT_MMAP_FAILED_ADDR(pzFileText))
- return;
-
- if (direction == DIRECTION_CALLED) {
- optst.flags = OPTST_DEFINED;
- direction = DIRECTION_PROCESS;
- }
-
- /*
- * IF this is called via "optionProcess", then we are presetting.
- * This is the default and the PRESETTING bit will be set.
- * If this is called via "optionFileLoad", then the bit is not set
- * and we consider stuff set herein to be "set" by the client program.
- */
- if ((pOpts->fOptSet & OPTPROC_PRESETTING) == 0)
- optst.flags = OPTST_SET;
-
- do {
- while (IS_WHITESPACE_CHAR(*pzFileText)) pzFileText++;
-
- if (IS_VAR_FIRST_CHAR(*pzFileText)) {
- pzFileText = handleConfig(pOpts, &optst, pzFileText, direction);
-
- } else switch (*pzFileText) {
- case '<':
- if (IS_VAR_FIRST_CHAR(pzFileText[1]))
- pzFileText =
- handleStructure(pOpts, &optst, pzFileText, direction);
-
- else switch (pzFileText[1]) {
- case '?':
- pzFileText = handleDirective( pOpts, pzFileText );
- break;
-
- case '!':
- pzFileText = handleComment( pzFileText );
- break;
-
- case '/':
- pzFileText = strchr( pzFileText+2, '>' );
- if (pzFileText++ != NULL)
- break;
-
- default:
- goto all_done;
- }
- break;
-
- case '[':
- pzFileText = handleProgramSection( pOpts, pzFileText );
- break;
-
- case '#':
- pzFileText = strchr( pzFileText+1, '\n' );
- break;
-
- default:
- goto all_done; /* invalid format */
- }
- } while (pzFileText != NULL);
-
- all_done:
- text_munmap( &cfgfile );
-}
-
-
-/* handleComment
- *
- * "pzText" points to a "<!" sequence.
- * Theoretically, we should ensure that it begins with "<!--",
- * but actually I don't care that much. It ends with "-->".
- */
-static char*
-handleComment( char* pzText )
-{
- char* pz = strstr( pzText, "-->" );
- if (pz != NULL)
- pz += 3;
- return pz;
-}
-
-
-/* handleConfig
- *
- * "pzText" points to the start of some value name.
- * The end of the entry is the end of the line that is not preceded by
- * a backslash escape character. The string value is always processed
- * in "cooked" mode.
- */
-static char*
-handleConfig(
- tOptions* pOpts,
- tOptState* pOS,
- char* pzText,
- int direction )
-{
- char* pzName = pzText++;
- char* pzEnd = strchr( pzText, '\n' );
-
- if (pzEnd == NULL)
- return pzText + strlen(pzText);
-
- while (IS_VALUE_NAME_CHAR(*pzText)) pzText++;
- while (IS_WHITESPACE_CHAR(*pzText)) pzText++;
- if (pzText > pzEnd) {
- name_only:
- *pzEnd++ = NUL;
- loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED );
- return pzEnd;
- }
-
- /*
- * Either the first character after the name is a ':' or '=',
- * or else we must have skipped over white space. Anything else
- * is an invalid format and we give up parsing the text.
- */
- if ((*pzText == '=') || (*pzText == ':')) {
- while (IS_WHITESPACE_CHAR(*++pzText)) ;
- if (pzText > pzEnd)
- goto name_only;
- } else if (! IS_WHITESPACE_CHAR(pzText[-1]))
- return NULL;
-
- /*
- * IF the value is continued, remove the backslash escape and push "pzEnd"
- * on to a newline *not* preceded by a backslash.
- */
- if (pzEnd[-1] == '\\') {
- char* pcD = pzEnd-1;
- char* pcS = pzEnd;
-
- for (;;) {
- char ch = *(pcS++);
- switch (ch) {
- case NUL:
- pcS = NULL;
-
- case '\n':
- *pcD = NUL;
- pzEnd = pcS;
- goto copy_done;
-
- case '\\':
- if (*pcS == '\n') {
- ch = *(pcS++);
- }
- /* FALLTHROUGH */
- default:
- *(pcD++) = ch;
- }
- } copy_done:;
-
- } else {
- /*
- * The newline was not preceded by a backslash. NUL it out
- */
- *(pzEnd++) = NUL;
- }
-
- /*
- * "pzName" points to what looks like text for one option/configurable.
- * It is NUL terminated. Process it.
- */
- loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED );
-
- return pzEnd;
-}
-
-
-/* handleDirective
- *
- * "pzText" points to a "<?" sequence.
- * For the moment, we only handle "<?program" directives.
- */
-static char*
-handleDirective(
- tOptions* pOpts,
- char* pzText )
-{
- char ztitle[32] = "<?";
- size_t title_len = strlen( zProg );
- size_t name_len;
-
- if ( (strncmp( pzText+2, zProg, title_len ) != 0)
- || (! IS_WHITESPACE_CHAR(pzText[title_len+2])) ) {
- pzText = strchr( pzText+2, '>' );
- if (pzText != NULL)
- pzText++;
- return pzText;
- }
-
- name_len = strlen( pOpts->pzProgName );
- strcpy( ztitle+2, zProg );
- title_len += 2;
-
- do {
- pzText += title_len;
-
- if (IS_WHITESPACE_CHAR(*pzText)) {
- while (IS_WHITESPACE_CHAR(*++pzText)) ;
- if ( (strneqvcmp( pzText, pOpts->pzProgName, (int)name_len) == 0)
- && (pzText[name_len] == '>')) {
- pzText += name_len + 1;
- break;
- }
- }
-
- pzText = strstr( pzText, ztitle );
- } while (pzText != NULL);
-
- return pzText;
-}
-
-
-/* handleProgramSection
- *
- * "pzText" points to a '[' character.
- * The "traditional" [PROG_NAME] segmentation of the config file.
- * Do not ever mix with the "<?program prog-name>" variation.
- */
-static char*
-handleProgramSection(
- tOptions* pOpts,
- char* pzText )
-{
- size_t len = strlen( pOpts->pzPROGNAME );
- if ( (strncmp( pzText+1, pOpts->pzPROGNAME, len ) == 0)
- && (pzText[len+1] == ']'))
- return strchr( pzText + len + 2, '\n' );
-
- if (len > 16)
- return NULL;
-
- {
- char z[24];
- sprintf( z, "[%s]", pOpts->pzPROGNAME );
- pzText = strstr( pzText, z );
- }
-
- if (pzText != NULL)
- pzText = strchr( pzText, '\n' );
- return pzText;
-}
-
-
-/* handleStructure
- *
- * "pzText" points to a '<' character, followed by an alpha.
- * The end of the entry is either the "/>" following the name, or else a
- * "</name>" string.
- */
-static char*
-handleStructure(
- tOptions* pOpts,
- tOptState* pOS,
- char* pzText,
- int direction )
-{
- tOptionLoadMode mode = option_load_mode;
- tOptionValue valu;
-
- char* pzName = ++pzText;
- char* pzData;
- char* pcNulPoint;
-
- while (IS_VALUE_NAME_CHAR(*pzText)) pzText++;
- pcNulPoint = pzText;
- valu.valType = OPARG_TYPE_STRING;
-
- switch (*pzText) {
- case ' ':
- case '\t':
- pzText = parseAttributes( pOpts, pzText, &mode, &valu );
- if (*pzText == '>')
- break;
- if (*pzText != '/')
- return NULL;
- /* FALLTHROUGH */
-
- case '/':
- if (pzText[1] != '>')
- return NULL;
- *pzText = NUL;
- pzText += 2;
- loadOptionLine( pOpts, pOS, pzName, direction, mode );
- return pzText;
-
- case '>':
- break;
-
- default:
- pzText = strchr( pzText, '>');
- if (pzText != NULL)
- pzText++;
- return pzText;
- }
-
- /*
- * If we are here, we have a value. "pzText" points to a closing angle
- * bracket. Separate the name from the value for a moment.
- */
- *pcNulPoint = NUL;
- pzData = ++pzText;
-
- /*
- * Find the end of the option text and NUL terminate it
- */
- {
- char z[64], *pz = z;
- size_t len = strlen(pzName) + 4;
- if (len > sizeof(z))
- pz = AGALOC(len, "scan name");
-
- sprintf( pz, "</%s>", pzName );
- *pzText = ' ';
- pzText = strstr( pzText, pz );
- if (pz != z) AGFREE(pz);
-
- if (pzText == NULL)
- return pzText;
-
- *pzText = NUL;
-
- pzText += len-1;
- }
-
- /*
- * Rejoin the name and value for parsing by "loadOptionLine()".
- * Erase any attributes parsed by "parseAttributes()".
- */
- memset(pcNulPoint, ' ', pzData - pcNulPoint);
-
- /*
- * If we are getting a "string" value, the process the XML-ish
- * %XX hex characters.
- */
- if (valu.valType == OPARG_TYPE_STRING) {
- char * pzSrc = pzData;
- char * pzDst = pzData;
- char bf[4];
- bf[2] = NUL;
-
- for (;;) {
- int ch = ((int)*(pzSrc++)) & 0xFF;
- switch (ch) {
- case NUL: goto string_fixup_done;
-
- case '%':
- bf[0] = *(pzSrc++);
- bf[1] = *(pzSrc++);
- if ((bf[0] == NUL) || (bf[1] == NUL))
- goto string_fixup_done;
- ch = strtoul(bf, NULL, 16);
- /* FALLTHROUGH */
-
- default:
- *(pzDst++) = ch;
- }
- } string_fixup_done:;
- *pzDst = NUL;
- }
-
- /*
- * "pzName" points to what looks like text for one option/configurable.
- * It is NUL terminated. Process it.
- */
- loadOptionLine( pOpts, pOS, pzName, direction, mode );
-
- return pzText;
-}
-
-
-/* internalFileLoad
- *
- * Load a configuration file. This may be invoked either from
- * scanning the "homerc" list, or from a specific file request.
- * (see "optionFileLoad()", the implementation for --load-opts)
- */
-LOCAL void
-internalFileLoad( tOptions* pOpts )
-{
- uint32_t svfl;
- int idx;
- int inc;
- char zFileName[ AG_PATH_MAX+1 ];
-
- if (pOpts->papzHomeList == NULL)
- return;
-
- svfl = pOpts->fOptSet;
- inc = DIRECTION_PRESET;
-
- /*
- * Never stop on errors in config files.
- */
- pOpts->fOptSet &= ~OPTPROC_ERRSTOP;
-
- /*
- * Find the last RC entry (highest priority entry)
- */
- for (idx = 0; pOpts->papzHomeList[ idx+1 ] != NULL; ++idx) ;
-
- /*
- * For every path in the home list, ... *TWICE* We start at the last
- * (highest priority) entry, work our way down to the lowest priority,
- * handling the immediate options.
- * Then we go back up, doing the normal options.
- */
- for (;;) {
- struct stat StatBuf;
- cch_t* pzPath;
-
- /*
- * IF we've reached the bottom end, change direction
- */
- if (idx < 0) {
- inc = DIRECTION_PROCESS;
- idx = 0;
- }
-
- pzPath = pOpts->papzHomeList[ idx ];
-
- /*
- * IF we've reached the top end, bail out
- */
- if (pzPath == NULL)
- break;
-
- idx += inc;
-
- if (! optionMakePath( zFileName, (int)sizeof(zFileName),
- pzPath, pOpts->pzProgPath ))
- continue;
-
- /*
- * IF the file name we constructed is a directory,
- * THEN append the Resource Configuration file name
- * ELSE we must have the complete file name
- */
- if (stat( zFileName, &StatBuf ) != 0)
- continue; /* bogus name - skip the home list entry */
-
- if (S_ISDIR( StatBuf.st_mode )) {
- size_t len = strlen( zFileName );
- char* pz;
-
- if (len + 1 + strlen( pOpts->pzRcName ) >= sizeof( zFileName ))
- continue;
-
- pz = zFileName + len;
- if (pz[-1] != DIRCH)
- *(pz++) = DIRCH;
- strcpy( pz, pOpts->pzRcName );
- }
-
- filePreset( pOpts, zFileName, inc );
-
- /*
- * IF we are now to skip config files AND we are presetting,
- * THEN change direction. We must go the other way.
- */
- {
- tOptDesc * pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts+1;
- if (DISABLED_OPT(pOD) && PRESETTING(inc)) {
- idx -= inc; /* go back and reprocess current file */
- inc = DIRECTION_PROCESS;
- }
- }
- } /* twice for every path in the home list, ... */
-
- pOpts->fOptSet = svfl;
-}
-
-
-/*=export_func optionFileLoad
- *
- * what: Load the locatable config files, in order
- *
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + char const* + pzProg + program name +
- *
- * ret_type: int
- * ret_desc: 0 -> SUCCESS, -1 -> FAILURE
- *
- * doc:
- *
- * This function looks in all the specified directories for a configuration
- * file ("rc" file or "ini" file) and processes any found twice. The first
- * time through, they are processed in reverse order (last file first). At
- * that time, only "immediate action" configurables are processed. For
- * example, if the last named file specifies not processing any more
- * configuration files, then no more configuration files will be processed.
- * Such an option in the @strong{first} named directory will have no effect.
- *
- * Once the immediate action configurables have been handled, then the
- * directories are handled in normal, forward order. In that way, later
- * config files can override the settings of earlier config files.
- *
- * See the AutoOpts documentation for a thorough discussion of the
- * config file format.
- *
- * Configuration files not found or not decipherable are simply ignored.
- *
- * err: Returns the value, "-1" if the program options descriptor
- * is out of date or indecipherable. Otherwise, the value "0" will
- * always be returned.
-=*/
-int
-optionFileLoad( tOptions* pOpts, char const* pzProgram )
-{
- if (! SUCCESSFUL( validateOptionsStruct( pOpts, pzProgram )))
- return -1;
-
- pOpts->pzProgName = pzProgram;
- internalFileLoad( pOpts );
- return 0;
-}
-
-
-/*=export_func optionLoadOpt
- * private:
- *
- * what: Load an option rc/ini file
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Processes the options found in the file named with
- * pOptDesc->optArg.argString.
-=*/
-void
-optionLoadOpt( tOptions* pOpts, tOptDesc* pOptDesc )
-{
- struct stat sb;
-
- /*
- * IF the option is not being disabled, THEN load the file. There must
- * be a file. (If it is being disabled, then the disablement processing
- * already took place. It must be done to suppress preloading of ini/rc
- * files.)
- */
- if ( DISABLED_OPT(pOptDesc)
- || ((pOptDesc->fOptState & OPTST_RESET) != 0))
- return;
-
- if (stat( pOptDesc->optArg.argString, &sb ) != 0) {
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0)
- return;
-
- fprintf( stderr, zFSErrOptLoad, errno, strerror( errno ),
- pOptDesc->optArg.argString );
- exit(EX_NOINPUT);
- /* NOT REACHED */
- }
-
- if (! S_ISREG( sb.st_mode )) {
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0)
- return;
-
- fprintf( stderr, zNotFile, pOptDesc->optArg.argString );
- exit(EX_NOINPUT);
- /* NOT REACHED */
- }
-
- filePreset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED);
-}
-
-
-/* parseAttributes
- *
- * Parse the various attributes of an XML-styled config file entry
- */
-LOCAL char*
-parseAttributes(
- tOptions* pOpts,
- char* pzText,
- tOptionLoadMode* pMode,
- tOptionValue* pType )
-{
- size_t len;
-
- do {
- if (! IS_WHITESPACE_CHAR(*pzText))
- switch (*pzText) {
- case '/': pType->valType = OPARG_TYPE_NONE;
- case '>': return pzText;
-
- default:
- case NUL: return NULL;
- }
-
- while (IS_WHITESPACE_CHAR(*++pzText)) ;
- len = 0;
- while (IS_LOWER_CASE_CHAR(pzText[len])) len++;
-
- switch (find_xat_attribute_id(pzText, len)) {
- case XAT_KWD_TYPE:
- pzText = parseValueType( pzText+len, pType );
- break;
-
- case XAT_KWD_WORDS:
- pzText = parseKeyWordType( pOpts, pzText+len, pType );
- break;
-
- case XAT_KWD_MEMBERS:
- pzText = parseSetMemType( pOpts, pzText+len, pType );
- break;
-
- case XAT_KWD_COOKED:
- pzText += len;
- if (! IS_END_XML_TOKEN_CHAR(*pzText))
- goto invalid_kwd;
-
- *pMode = OPTION_LOAD_COOKED;
- break;
-
- case XAT_KWD_UNCOOKED:
- pzText += len;
- if (! IS_END_XML_TOKEN_CHAR(*pzText))
- goto invalid_kwd;
-
- *pMode = OPTION_LOAD_UNCOOKED;
- break;
-
- case XAT_KWD_KEEP:
- pzText += len;
- if (! IS_END_XML_TOKEN_CHAR(*pzText))
- goto invalid_kwd;
-
- *pMode = OPTION_LOAD_KEEP;
- break;
-
- default:
- case XAT_KWD_INVALID:
- invalid_kwd:
- pType->valType = OPARG_TYPE_NONE;
- return skipUnknown( pzText );
- }
- } while (pzText != NULL);
-
- return pzText;
-}
-
-
-/* parseKeyWordType
- *
- * "pzText" points to the character after "words=".
- * What should follow is a name of a keyword (enumeration) list.
- */
-static char*
-parseKeyWordType(
- tOptions* pOpts,
- char* pzText,
- tOptionValue* pType )
-{
- return skipUnknown( pzText );
-}
-
-
-/* parseSetMemType
- *
- * "pzText" points to the character after "members="
- * What should follow is a name of a "set membership".
- * A collection of bit flags.
- */
-static char*
-parseSetMemType(
- tOptions* pOpts,
- char* pzText,
- tOptionValue* pType )
-{
- return skipUnknown( pzText );
-}
-
-
-/* parseValueType
- *
- * "pzText" points to the character after "type="
- */
-static char*
-parseValueType(
- char* pzText,
- tOptionValue* pType )
-{
- size_t len = 0;
-
- if (*(pzText++) != '=')
- goto woops;
-
- while (IS_OPTION_NAME_CHAR(pzText[len])) len++;
- pzText += len;
-
- if ((len == 0) || (! IS_END_XML_TOKEN_CHAR(*pzText))) {
- woops:
- pType->valType = OPARG_TYPE_NONE;
- return skipUnknown( pzText );
- }
-
- switch (find_value_type_id(pzText - len, len)) {
- default:
- case VTP_KWD_INVALID: goto woops;
-
- case VTP_KWD_STRING:
- pType->valType = OPARG_TYPE_STRING;
- break;
-
- case VTP_KWD_INTEGER:
- pType->valType = OPARG_TYPE_NUMERIC;
- break;
-
- case VTP_KWD_BOOL:
- case VTP_KWD_BOOLEAN:
- pType->valType = OPARG_TYPE_BOOLEAN;
- break;
-
- case VTP_KWD_KEYWORD:
- pType->valType = OPARG_TYPE_ENUMERATION;
- break;
-
- case VTP_KWD_SET:
- case VTP_KWD_SET_MEMBERSHIP:
- pType->valType = OPARG_TYPE_MEMBERSHIP;
- break;
-
- case VTP_KWD_NESTED:
- case VTP_KWD_HIERARCHY:
- pType->valType = OPARG_TYPE_HIERARCHY;
- }
-
- return pzText;
-}
-
-
-/* skipUnknown
- *
- * Skip over some unknown attribute
- */
-static char*
-skipUnknown( char* pzText )
-{
- for (;; pzText++) {
- if (IS_END_XML_TOKEN_CHAR(*pzText)) return pzText;
- if (*pzText == NUL) return NULL;
- }
-}
-
-
-/* validateOptionsStruct
- *
- * 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.)
- */
-LOCAL tSuccess
-validateOptionsStruct( tOptions* pOpts, char const* pzProgram )
-{
- if (pOpts == NULL) {
- fputs( zAO_Bad, stderr );
- exit( EX_CONFIG );
- }
-
- /*
- * IF the client has enabled translation and the translation procedure
- * is available, then go do it.
- */
- if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0)
- && (pOpts->pTransProc != NULL) ) {
- /*
- * 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 ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT)
- pOpts->fOptSet |= OPTPROC_NXLAT_OPT_CFG;
- (*pOpts->pTransProc)();
- pOpts->fOptSet &= ~OPTPROC_TRANSLATE;
- }
-
- /*
- * IF the struct version is not the current, and also
- * either too large (?!) or too small,
- * THEN emit error message and fail-exit
- */
- if ( ( pOpts->structVersion != OPTIONS_STRUCT_VERSION )
- && ( (pOpts->structVersion > OPTIONS_STRUCT_VERSION )
- || (pOpts->structVersion < OPTIONS_MINIMUM_VERSION )
- ) ) {
-
- fprintf(stderr, zAO_Err, pzProgram, NUM_TO_VER(pOpts->structVersion));
- if (pOpts->structVersion > OPTIONS_STRUCT_VERSION )
- fputs( zAO_Big, stderr );
- else
- fputs( zAO_Sml, 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 (pOpts->pzProgName == NULL) {
- char const* pz = strrchr( pzProgram, DIRCH );
-
- if (pz == NULL)
- pOpts->pzProgName = pzProgram;
- else pOpts->pzProgName = pz+1;
-
- pOpts->pzProgPath = pzProgram;
-
- /*
- * when comparing long names, these are equivalent
- */
- strequate( zSepChars );
- }
-
- return SUCCESS;
-}
-
-
-/**
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/configfile.c */
+++ /dev/null
-/*
- * $Id: cook.c,v 4.18 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2007-11-16 22:49:11 bkorb"
- *
- * This file contains the routines that deal with processing quoted strings
- * into an internal format.
- *
- * 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
- */
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-/* = = = END-STATIC-FORWARD = = = */
-
-/*=export_func ao_string_cook_escape_char
- * private:
- *
- * what: escape-process a string fragment
- * arg: + char const* + pzScan + points to character after the escape +
- * arg: + char* + pRes + Where to put the result byte +
- * arg: + unsigned int + nl_ch + replacement char if scanned char is \n +
- *
- * ret-type: unsigned int
- * ret-desc: The number of bytes consumed processing the escaped character.
- *
- * doc:
- *
- * This function converts "t" into "\t" and all your other favorite
- * escapes, including numeric ones: hex and ocatal, too.
- * The returned result tells the caller how far to advance the
- * scan pointer (passed in). The default is to just pass through the
- * escaped character and advance the scan by one.
- *
- * Some applications need to keep an escaped newline, others need to
- * suppress it. This is accomplished by supplying a '\n' replacement
- * character that is different from \n, if need be. For example, use
- * 0x7F and never emit a 0x7F.
- *
- * 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 )
-{
- unsigned int res = 1;
-
- switch (*pRes = *pzIn++) {
- case NUL: /* NUL - end of input string */
- return 0;
- case '\r':
- if (*pzIn != '\n')
- return 1;
- res++;
- /* FALLTHROUGH */
- case '\n': /* 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 'r': *pRes = '\r'; break;
- case 't': *pRes = '\t'; break;
- case 'v': *pRes = '\v'; break;
-
- case 'x':
- case 'X': /* HEX Escape */
- if (IS_HEX_DIGIT_CHAR(*pzIn)) {
- char z[4], *pz = z;
-
- do *(pz++) = *(pzIn++);
- while (IS_HEX_DIGIT_CHAR(*pzIn) && (pz < z + 2));
- *pz = NUL;
- *pRes = (unsigned char)strtoul(z, NULL, 16);
- res += pz - z;
- }
- break;
-
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- {
- /*
- * IF the character copied was an octal digit,
- * THEN set the output character to an octal value
- */
- char z[4], *pz = z + 1;
- unsigned long val;
- z[0] = *pRes;
-
- while (IS_OCT_DIGIT_CHAR(*pzIn) && (pz < z + 3))
- *(pz++) = *(pzIn++);
- *pz = NUL;
- val = strtoul(z, NULL, 8);
- if (val > 0xFF)
- val = 0xFF;
- *pRes = (unsigned char)val;
- res = pz - z;
- break;
- }
-
- default: ;
- }
-
- return res;
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * A quoted string has been found.
- * Find the end of it and compress any escape sequences.
- */
-/*=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 +
- *
- * ret-type: char*
- * ret-desc: The address of the text following the processed strings.
- * The return value is NULL if the strings are ill-formed.
- *
- * doc:
- *
- * A series of one or more quoted strings are concatenated together.
- * If they are quoted with double quotes (@code{"}), then backslash
- * escapes are processed per the C programming language. If they are
- * single quote strings, then the backslashes are honored only when they
- * precede another backslash or a single quote character.
- *
- * err: @code{NULL} is returned if the string(s) is/are mal-formed.
-=*/
-char*
-ao_string_cook( char* pzScan, int* pLineCt )
-{
- int l = 0;
- char q = *pzScan;
-
- /*
- * It is a quoted string. Process the escape sequence characters
- * (in the set "abfnrtv") and make sure we find a closing quote.
- */
- char* pzD = pzScan++;
- char* pzS = pzScan;
-
- if (pLineCt == NULL)
- pLineCt = &l;
-
- for (;;) {
- /*
- * IF the next character is the quote character, THEN we may end the
- * string. We end it unless the next non-blank character *after* the
- * string happens to also be a quote. If it is, then we will change
- * our quote character to the new quote character and continue
- * condensing text.
- */
- 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.
- */
- return pzS;
- }
-
- q = *(pzS++); /* assign new quote character and advance scan */
- }
-
- /*
- * We are inside a quoted string. Copy text.
- */
- switch (*(pzD++) = *(pzS++)) {
- case NUL:
- return NULL;
-
- case '\n':
- (*pLineCt)++;
- break;
-
- case '\\':
- /*
- * IF we are escaping a new line,
- * THEN drop both the escape and the newline from
- * the result string.
- */
- if (*pzS == '\n') {
- pzS++;
- pzD--;
- (*pLineCt)++;
- }
-
- /*
- * ELSE IF the quote character is '"' or '`',
- * THEN we do the full escape character processing
- */
- else if (q != '\'') {
- int ct = ao_string_cook_escape_char( pzS, pzD-1, (u_int)'\n' );
- if (ct == 0)
- return NULL;
-
- pzS += ct;
- } /* if (q != '\'') */
-
- /*
- * OTHERWISE, we only process "\\", "\'" and "\#" sequences.
- * The latter only to easily hide preprocessing directives.
- */
- else switch (*pzS) {
- case '\\':
- case '\'':
- case '#':
- pzD[-1] = *pzS++;
- }
- } /* switch (*(pzD++) = *(pzS++)) */
- } /* for (;;) */
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/cook.c */
+++ /dev/null
-
-/*
- * $Id: enumeration.c,v 4.26 2009/08/01 17:44:36 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 */
+++ /dev/null
-
-/*
- * $Id: environment.c,v 4.21 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2009-07-20 20:12:24 bkorb"
- *
- * 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-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
- */
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-checkEnvOpt(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.
- */
-LOCAL void
-doPrognameEnv( tOptions* pOpts, teEnvPresetType type )
-{
- char const* pczOptStr = getenv( pOpts->pzPROGNAME );
- token_list_t* pTL;
- int sv_argc;
- tAoUI sv_flag;
- char** sv_argv;
-
- /*
- * No such beast? Then bail now.
- */
- if (pczOptStr == NULL)
- return;
-
- /*
- * Tokenize the string. If there's nothing of interest, we'll bail
- * here immediately.
- */
- pTL = ao_string_tokenize( pczOptStr );
- if (pTL == NULL)
- return;
-
- /*
- * Substitute our $PROGNAME argument list for the real one
- */
- sv_argc = pOpts->origArgCt;
- sv_argv = pOpts->origArgVect;
- sv_flag = pOpts->fOptSet;
-
- /*
- * We add a bogus pointer to the start of the list. The program name
- * has already been pulled from "argv", so it won't get dereferenced.
- * 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;
- pOpts->fOptSet &= ~OPTPROC_ERRSTOP;
-
- pOpts->curOptIdx = 1;
- pOpts->pzCurOpt = NULL;
-
- switch (type) {
- case ENV_IMM:
- (void)doImmediateOpts( pOpts );
- break;
-
- case ENV_ALL:
- (void)doImmediateOpts( pOpts );
- pOpts->curOptIdx = 1;
- pOpts->pzCurOpt = NULL;
- /* FALLTHROUGH */
-
- case ENV_NON_IMM:
- (void)doRegularOpts( pOpts );
- }
-
- /*
- * Free up the temporary arg vector and restore the original program args.
- */
- free( pTL );
- pOpts->origArgVect = sv_argv;
- pOpts->origArgCt = sv_argc;
- pOpts->fOptSet = sv_flag;
-}
-
-static void
-checkEnvOpt(tOptState * os, char * env_name,
- tOptions* pOpts, teEnvPresetType type)
-{
- os->pzOptArg = getenv( env_name );
- if (os->pzOptArg == NULL)
- return;
-
- 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)) {
- os->flags |= OPTST_DISABLED;
- os->pzOptArg = NULL;
- }
-
- switch (type) {
- case ENV_IMM:
- /*
- * Process only immediate actions
- */
- if (DO_IMMEDIATELY(os->flags))
- break;
- return;
-
- case ENV_NON_IMM:
- /*
- * Process only NON immediate actions
- */
- if (DO_NORMALLY(os->flags) || DO_SECOND_TIME(os->flags))
- break;
- return;
-
- default: /* process everything */
- break;
- }
-
- /*
- * Make sure the option value string is persistent and consistent.
- *
- * 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;
- }
- }
-
- handleOption( pOpts, os );
-}
-
-/*
- * doEnvPresets - check for preset values from the envrionment
- * This routine should process in all, immediate or normal modes....
- */
-LOCAL void
-doEnvPresets( tOptions* pOpts, teEnvPresetType type )
-{
- int ct;
- tOptState st;
- char* pzFlagName;
- size_t spaceLeft;
- char zEnvName[ AO_NAME_SIZE ];
-
- /*
- * Finally, see if we are to look at the environment
- * variables for initial values.
- */
- if ((pOpts->fOptSet & OPTPROC_ENVIRON) == 0)
- return;
-
- 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;
-
- for (;ct-- > 0; st.pOD++) {
- /*
- * If presetting is disallowed, then skip this entry
- */
- if ( ((st.pOD->fOptState & OPTST_NO_INIT) != 0)
- || (st.pOD->optEquivIndex != NO_EQUIVALENT) )
- continue;
-
- /*
- * 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);
- }
-
- /*
- * Special handling for ${PROGNAME_LOAD_OPTS}
- */
- if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT)
- && (pOpts->specOptIdx.save_opts != 0)) {
- st.pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1;
- strcpy( pzFlagName, st.pOD->pz_NAME );
- checkEnvOpt(&st, zEnvName, pOpts, type);
- }
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/environment.c */
+++ /dev/null
-
-/*
- * $Id: file.c,v 1.9 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2009-07-23 17:23:46 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 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
- */
-
-/*=export_func optionFileCheck
- * private:
- *
- * what: Decipher a boolean value
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- * arg: + teOptFileType + ftype + File handling type +
- * arg: + tuFileMode + mode + file open mode (if needed) +
- *
- * doc:
- * Make sure the named file conforms with the file type mode.
- * The mode specifies if the file must exist, must not exist or may
- * (or may not) exist. The mode may also specify opening the
- * file: don't, open just the descriptor (fd), or open as a stream
- * (FILE* pointer).
-=*/
-void
-optionFileCheck(tOptions* pOpts, tOptDesc* pOD,
- teOptFileType ftype, tuFileMode mode)
-{
- if (pOpts <= OPTPROC_EMIT_LIMIT) {
- if (pOpts != OPTPROC_EMIT_USAGE)
- return;
-
- switch (ftype & FTYPE_MODE_EXIST_MASK) {
- case FTYPE_MODE_MUST_NOT_EXIST:
- fputs(zFileCannotExist, option_usage_fp);
- break;
-
- case FTYPE_MODE_MUST_EXIST:
- fputs(zFileMustExist, option_usage_fp);
- break;
- }
- return;
- }
-
- if ((pOD->fOptState & OPTST_RESET) != 0) {
- if (pOD->optCookie != NULL)
- AGFREE(pOD->optCookie);
- 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;
- }
- }
-
- 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;
- }
- }
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/file.c */
+++ /dev/null
-/* -*- buffer-read-only: t -*- vi: set ro:
- *
- * DO NOT EDIT THIS FILE (genshell.c)
- *
- * It has been AutoGen-ed August 1, 2009 at 11:21:11 AM by AutoGen 5.9.9pre4
- * 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 source 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.
- *
- * This source file is copyrighted and licensed under the following terms:
- *
- * genshellopt copyright (c) 1999-2009 Bruce Korb - all rights reserved
- *
- * 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/>.
- */
-
-#include <sys/types.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#define OPTION_CODE_COMPILE 1
-#include "genshell.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* TRANSLATORS: choose the translation for option names wisely because you
- cannot ever change your mind. */
-tSCC zCopyright[] =
- "genshellopt copyright (c) 1999-2009 Bruce Korb, all rights reserved";
-tSCC zCopyrightNotice[610] =
-"genshellopt is free software: you can redistribute it and/or modify it under\n\
-the terms of the GNU General Public License as published by the Free Software\n\
-Foundation, either version 3 of the License, or (at your option) any later\n\
-version.\n\n\
-genshellopt is distributed in the hope that it will be useful, but WITHOUT ANY\n\
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\n\
-PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\n\
-You should have received a copy of the GNU General Public License along with\n\
-this program. If not, see <http://www.gnu.org/licenses/>.";
-
-extern tUsageProc genshelloptUsage;
-
-#ifndef NULL
-# define NULL 0
-#endif
-#ifndef EXIT_SUCCESS
-# define EXIT_SUCCESS 0
-#endif
-#ifndef EXIT_FAILURE
-# define EXIT_FAILURE 1
-#endif
-/*
- * Script option description:
- */
-tSCC zScriptText[] =
- "Output Script File";
-tSCC zScript_NAME[] = "SCRIPT";
-tSCC zScript_Name[] = "script";
-#define SCRIPT_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
-
-/*
- * Shell option description:
- */
-tSCC zShellText[] =
- "Shell name (follows \"#!\" magic)";
-tSCC zShell_NAME[] = "SHELL";
-tSCC zNotShell_Name[] = "no-shell";
-tSCC zNotShell_Pfx[] = "no";
-#define zShell_Name (zNotShell_Name + 3)
-#define SHELL_FLAGS (OPTST_INITENABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
-
-/*
- * Help/More_Help/Version option descriptions:
- */
-tSCC zHelpText[] = "Display usage information and exit";
-tSCC zHelp_Name[] = "help";
-tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
-tSCC zMore_Help_Name[] = "more-help";
-tSCC zVersionText[] = "Output version information and exit";
-tSCC zVersion_Name[] = "version";
-/*
- * Declare option callback procedures
- */
-extern tOptProc
- optionPagedUsage, optionPrintVersion;
-static tOptProc
- doUsageOpt;
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Define the Genshellopt Option Descriptions.
- */
-static tOptDesc optDesc[ OPTION_CT ] = {
- { /* entry idx, value */ 0, VALUE_OPT_SCRIPT,
- /* equiv idx, value */ 0, VALUE_OPT_SCRIPT,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ SCRIPT_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 1, VALUE_OPT_SHELL,
- /* equiv idx, value */ 1, VALUE_OPT_SHELL,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ SHELL_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name,
- /* disablement strs */ zNotShell_Name, zNotShell_Pfx },
-
-#ifdef NO_OPTIONAL_OPT_ARGS
-# define VERSION_OPT_FLAGS OPTST_IMM | OPTST_NO_INIT
-#else
-# define VERSION_OPT_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
- OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
-#endif
-
- { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VERSION_OPT_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionPrintVersion,
- /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
- /* disablement strs */ NULL, NULL },
-
-#undef VERSION_OPT_FLAGS
-
-
- { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doUsageOpt,
- /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionPagedUsage,
- /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
- /* disablement strs */ NULL, NULL }
-};
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Define the Genshellopt Option Environment
- */
-tSCC zPROGNAME[] = "GENSHELLOPT";
-tSCC zUsageTitle[] =
-"genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
-USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
-#define zRcName NULL
-#define apzHomeList NULL
-
-tSCC zBugsAddr[] = "autogen-users@lists.sourceforge.net";
-tSCC zExplain[] = "\n\
-Note that `shell' is only useful if the output file does not already\n\
-exist. If it does, then the shell name and optional first argument\n\
-will be extracted from the script file.\n";
-tSCC zDetail[] = "\n\
-If the script file already exists and contains Automated Option Processing\n\
-text, the second line of the file through the ending tag will be replaced\n\
-by the newly generated text. The first `#!' line will be regenerated.\n";
-tSCC zFullVersion[] = GENSHELLOPT_FULL_VERSION;
-/* extracted from optcode.tpl near line 501 */
-
-#if defined(ENABLE_NLS)
-# define OPTPROC_BASE OPTPROC_TRANSLATE
- static tOptionXlateProc translate_option_strings;
-#else
-# define OPTPROC_BASE OPTPROC_NONE
-# define translate_option_strings NULL
-#endif /* ENABLE_NLS */
-
-
-#define genshellopt_full_usage NULL
-#define genshellopt_short_usage NULL
-tOptions genshelloptOptions = {
- OPTIONS_STRUCT_VERSION,
- 0, NULL, /* original argc + argv */
- ( OPTPROC_BASE
- + OPTPROC_ERRSTOP
- + OPTPROC_SHORTOPT
- + OPTPROC_LONGOPT
- + OPTPROC_NO_REQ_OPT
- + OPTPROC_NEGATIONS
- + OPTPROC_NO_ARGS ),
- 0, NULL, /* current option index, current option */
- NULL, NULL, zPROGNAME,
- zRcName, zCopyright, zCopyrightNotice,
- zFullVersion, apzHomeList, zUsageTitle,
- zExplain, zDetail, optDesc,
- zBugsAddr, /* address to send bugs to */
- NULL, NULL, /* extensions/saved state */
- genshelloptUsage, /* usage procedure */
- translate_option_strings, /* translation procedure */
- /*
- * Indexes to special options
- */
- { INDEX_OPT_MORE_HELP, /* more-help option index */
- NO_EQUIVALENT, /* save option index */
- NO_EQUIVALENT, /* '-#' option index */
- NO_EQUIVALENT /* index of default opt */
- },
- 5 /* full option count */, 2 /* user option count */,
- genshellopt_full_usage, genshellopt_short_usage,
- NULL, NULL
-};
-
-/*
- * Create the static procedure(s) declared above.
- */
-static void
-doUsageOpt(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
-{
- (void)pOptions;
- USAGE( EXIT_SUCCESS );
-}
-/* extracted from optcode.tpl near line 633 */
-
-#if ENABLE_NLS
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <autoopts/usage-txt.h>
-
-static char* AO_gettext( char const* pz );
-static void coerce_it(void** s);
-
-static char*
-AO_gettext( char const* pz )
-{
- char* pzRes;
- if (pz == NULL)
- return NULL;
- pzRes = _(pz);
- if (pzRes == pz)
- return pzRes;
- pzRes = strdup( pzRes );
- if (pzRes == NULL) {
- fputs( _("No memory for duping translated strings\n"), stderr );
- exit( EXIT_FAILURE );
- }
- return pzRes;
-}
-
-static void coerce_it(void** s) { *s = AO_gettext(*s); }
-#define COERSION(_f) \
- coerce_it((void*)&(genshelloptOptions._f))
-
-/*
- * This invokes the translation code (e.g. gettext(3)).
- */
-static void
-translate_option_strings( void )
-{
- /*
- * Guard against re-translation. It won't work. The strings will have
- * been changed by the first pass through this code. One shot only.
- */
- if (option_usage_text.field_ct != 0) {
-
- /*
- * Do the translations. The first pointer follows the field count
- * field. The field count field is the size of a pointer.
- */
- tOptDesc* pOD = genshelloptOptions.pOptDesc;
- char** ppz = (char**)(void*)&(option_usage_text);
- int ix = option_usage_text.field_ct;
-
- do {
- ppz++;
- *ppz = AO_gettext(*ppz);
- } while (--ix > 0);
-
- COERSION(pzCopyright);
- COERSION(pzCopyNotice);
- COERSION(pzFullVersion);
- COERSION(pzUsageTitle);
- COERSION(pzExplain);
- COERSION(pzDetail);
- option_usage_text.field_ct = 0;
-
- for (ix = genshelloptOptions.optCt; ix > 0; ix--, pOD++)
- coerce_it((void*)&(pOD->pzText));
- }
-
- if ((genshelloptOptions.fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
- tOptDesc* pOD = genshelloptOptions.pOptDesc;
- int ix;
-
- for (ix = genshelloptOptions.optCt; ix > 0; ix--, pOD++) {
- coerce_it((void*)&(pOD->pz_Name));
- coerce_it((void*)&(pOD->pz_DisableName));
- coerce_it((void*)&(pOD->pz_DisablePfx));
- }
- /* prevent re-translation */
- genshelloptOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
- }
-}
-
-#endif /* ENABLE_NLS */
-
-#ifdef __cplusplus
-}
-#endif
-/* genshell.c ends here */
+++ /dev/null
-/* -*- buffer-read-only: t -*- vi: set ro:
- *
- * DO NOT EDIT THIS FILE (genshell.h)
- *
- * It has been AutoGen-ed August 1, 2009 at 11:21:11 AM by AutoGen 5.9.9pre4
- * 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.
- *
- * This source file is copyrighted and licensed under the following terms:
- *
- * genshellopt copyright (c) 1999-2009 Bruce Korb - all rights reserved
- *
- * 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/>.
- */
-/*
- * 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
- * "AutoOpts" chapter. Please refer to that doc for usage help.
- */
-#ifndef AUTOOPTS_GENSHELL_H_GUARD
-#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 131073
-#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:
- */
-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
-#define GENSHELLOPT_VERSION "1"
-#define GENSHELLOPT_FULL_VERSION "genshellopt - Generate Shell Option Processing Script - Ver. 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 )
- */
-#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 )
-
-/* * * * * *
- *
- * 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'
-/*
- * 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( \
- 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 */
-
-/* * * * * *
- *
- * Declare the genshellopt option descriptor.
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-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 );
- }
-# define _(s) aoGetsText(s)
-# endif /* _() */
-
-# define OPT_NO_XLAT_CFG_NAMES STMTS(genshelloptOptions.fOptSet |= \
- OPTPROC_NXLAT_OPT_CFG;)
-# define OPT_NO_XLAT_OPT_NAMES STMTS(genshelloptOptions.fOptSet |= \
- OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
-
-# define OPT_XLAT_CFG_NAMES STMTS(genshelloptOptions.fOptSet &= \
- ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
-# define OPT_XLAT_OPT_NAMES STMTS(genshelloptOptions.fOptSet &= \
- ~OPTPROC_NXLAT_OPT;)
-
-#else /* ENABLE_NLS */
-# define OPT_NO_XLAT_CFG_NAMES
-# define OPT_NO_XLAT_OPT_NAMES
-
-# define OPT_XLAT_CFG_NAMES
-# define OPT_XLAT_OPT_NAMES
-
-# ifndef _
-# define _(_s) _s
-# endif
-#endif /* ENABLE_NLS */
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* AUTOOPTS_GENSHELL_H_GUARD */
-/* genshell.h ends here */
+++ /dev/null
-#define AUTOOPTS_INTERNAL
-#include "compat/compat.h"
-#define LOCAL static
-#include "autoopts/options.h"
-#include "autoopts/usage-txt.h"
-#include "genshell.h"
-#include "xat-attribute.h"
-#include "value-type.h"
-#include "ag-char-map.h"
-#include "autoopts.h"
-#include "proto.h"
-#include "value-type.c"
-#include "xat-attribute.c"
-#include "autoopts.c"
-#include "boolean.c"
-#include "configfile.c"
-#include "cook.c"
-#include "enumeration.c"
-#include "environment.c"
-#include "file.c"
-#include "genshell.c"
-#include "load.c"
-#include "makeshell.c"
-#include "nested.c"
-#include "numeric.c"
-#include "pgusage.c"
-#include "putshell.c"
-#include "reset.c"
-#include "restore.c"
-#include "save.c"
-#include "sort.c"
-#include "stack.c"
-#include "streqvcmp.c"
-#include "text_mmap.c"
-#include "tokenize.c"
-#include "time.c"
-#include "usage.c"
-#include "version.c"
+++ /dev/null
-
-/*
- * $Id: load.c,v 4.29 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-12-06 10:16:05 bkorb"
- *
- * 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.
- *
- * 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
- */
-
-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 );
-/* = = = END-STATIC-FORWARD = = = */
-
-/*=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 +
- *
- * ret-type: ag_bool
- * ret-desc: AG_TRUE if the name was handled, otherwise AG_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
- * @code{canonicalize_file_name(3GLIBC)} or @code{realpath(3C)}.
- *
- * doc:
- *
- * This routine will copy the @code{pzName} input name into the @code{pzBuf}
- * output buffer, carefully not exceeding @code{bufSize} bytes. If the
- * first character of the input name is a @code{'$'} character, then there
- * is special handling:
- * @*
- * @code{$$} is replaced with the directory name of the @code{pzProgPath},
- * searching @code{$PATH} if necessary.
- * @*
- * @code{$@} is replaced with the AutoGen package data installation directory
- * (aka @code{pkgdatadir}).
- * @*
- * @code{$NAME} is replaced by the contents of the @code{NAME} environment
- * variable. If not found, the search fails.
- *
- * Please note: both @code{$$} and @code{$NAME} must be at the start of the
- * @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:
- * @*
- * @bullet{} The input name exceeds @code{bufSize} bytes.
- * @*
- * @bullet{} @code{$$}, @code{$@@} or @code{$NAME} is not the full string
- * and the next character is not '/'.
- * @*
- * @bullet{} libopts was built without PKGDATADIR defined and @code{$@@}
- * was specified.
- * @*
- * @bullet{} @code{NAME} is not a known environment variable
- * @*
- * @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 )
-{
- size_t name_len = strlen( pzName );
-
-# ifndef PKGDATADIR
-# define PKGDATADIR ""
-# endif
-
- tSCC pkgdatadir[] = PKGDATADIR;
-
- ag_bool res = AG_TRUE;
-
- if (bufSize <= name_len)
- return AG_FALSE;
-
- /*
- * IF not an environment variable, just copy the data
- */
- if (*pzName != '$') {
- tCC* pzS = pzName;
- char* pzD = pzBuf;
- int ct = bufSize;
-
- for (;;) {
- if ( (*(pzD++) = *(pzS++)) == NUL)
- break;
- if (--ct <= 0)
- return AG_FALSE;
- }
- }
-
- /*
- * IF the name starts with "$$", then it must be "$$" or
- * it must start with "$$/". In either event, replace the "$$"
- * with the path to the executable and append a "/" character.
- */
- else switch (pzName[1]) {
- case NUL:
- return AG_FALSE;
-
- case '$':
- res = insertProgramPath( pzBuf, bufSize, pzName, pzProgPath );
- break;
-
- case '@':
- if (pkgdatadir[0] == NUL)
- return AG_FALSE;
-
- if (name_len + sizeof (pkgdatadir) > bufSize)
- return AG_FALSE;
-
- strcpy(pzBuf, pkgdatadir);
- strcpy(pzBuf + sizeof(pkgdatadir) - 1, pzName + 2);
- 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);
- }
-
-#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;
-}
-
-
-static ag_bool
-insertProgramPath(
- char* pzBuf,
- int bufSize,
- tCC* pzName,
- tCC* pzProgPath )
-{
- tCC* pzPath;
- tCC* pz;
- int skip = 2;
-
- switch (pzName[2]) {
- case DIRCH:
- skip = 3;
- case NUL:
- break;
- default:
- return AG_FALSE;
- }
-
- /*
- * See if the path is included in the program name.
- * If it is, we're done. Otherwise, we have to hunt
- * for the program using "pathfind".
- */
- if (strchr( pzProgPath, DIRCH ) != NULL)
- pzPath = pzProgPath;
- else {
- pzPath = pathfind( getenv( "PATH" ), (char*)pzProgPath, "rx" );
-
- if (pzPath == NULL)
- return AG_FALSE;
- }
-
- pz = strrchr( pzPath, 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;
-
- pzName += 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;
-
- memcpy( pzBuf, pzPath, (size_t)((pz - pzPath)+1) );
- strcpy( pzBuf + (pz - pzPath) + 1, pzName );
-
- /*
- * If the "pzPath" path was gotten from "pathfind()", then it was
- * allocated and we need to deallocate it.
- */
- if (pzPath != pzProgPath)
- AGFREE(pzPath);
- return AG_TRUE;
-}
-
-
-static ag_bool
-insertEnvVal(
- char* pzBuf,
- int bufSize,
- tCC* pzName,
- tCC* pzProgPath )
-{
- char* pzDir = pzBuf;
-
- for (;;) {
- int ch = (int)*++pzName;
- if (! IS_VALUE_NAME_CHAR(ch))
- break;
- *(pzDir++) = (char)ch;
- }
-
- if (pzDir == pzBuf)
- return AG_FALSE;
-
- *pzDir = NUL;
-
- pzDir = getenv( pzBuf );
-
- /*
- * Environment value not found -- skip the home list entry
- */
- if (pzDir == NULL)
- return AG_FALSE;
-
- if (strlen( pzDir ) + 1 + strlen( pzName ) >= bufSize)
- return AG_FALSE;
-
- sprintf( pzBuf, "%s%s", pzDir, pzName );
- return AG_TRUE;
-}
-
-
-LOCAL void
-mungeString( char* pzTxt, tOptionLoadMode mode )
-{
- 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;
- } else
- pzE = pzTxt + strlen( pzTxt );
-
- while ((pzE > pzTxt) && IS_WHITESPACE_CHAR(pzE[-1])) pzE--;
- *pzE = NUL;
-
- if (mode == OPTION_LOAD_UNCOOKED)
- return;
-
- switch (*pzTxt) {
- default: return;
- case '"':
- case '\'': break;
- }
-
- switch (pzE[-1]) {
- default: return;
- case '"':
- case '\'': break;
- }
-
- (void)ao_string_cook( pzTxt, NULL );
-}
-
-
-static char*
-assembleArgValue( char* pzTxt, tOptionLoadMode mode )
-{
- tSCC zBrk[] = " \t\n:=";
- char* pzEnd = strpbrk( pzTxt, zBrk );
- int space_break;
-
- /*
- * Not having an argument to a configurable name is okay.
- */
- if (pzEnd == NULL)
- return pzTxt + strlen(pzTxt);
-
- /*
- * If we are keeping all whitespace, then the modevalue starts with the
- * character that follows the end of the configurable name, regardless
- * of which character caused it.
- */
- if (mode == OPTION_LOAD_KEEP) {
- *(pzEnd++) = NUL;
- return pzEnd;
- }
-
- /*
- * If the name ended on a white space character, remember that
- * 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)) ;
-
- return pzEnd;
-}
-
-
-/*
- * 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.
- */
-LOCAL void
-loadOptionLine(
- tOptions* pOpts,
- tOptState* pOS,
- char* pzLine,
- tDirection direction,
- tOptionLoadMode load_mode )
-{
- while (IS_WHITESPACE_CHAR(*pzLine)) pzLine++;
-
- {
- 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)) {
- case 0:
- /*
- * The selected option has no immediate action.
- * THEREFORE, if the direction is PRESETTING
- * THEN we skip this option.
- */
- if (PRESETTING(direction))
- return;
- break;
-
- case OPTST_IMM:
- if (PRESETTING(direction)) {
- /*
- * 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;
- } 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;
- }
- break;
-
- case OPTST_DISABLE_IMM:
- if (PRESETTING(direction)) {
- /*
- * 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;
- } 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;
- }
- break;
-
- case OPTST_IMM|OPTST_DISABLE_IMM:
- /*
- * The selected option is always for immediate action.
- * THEREFORE, if the direction is PROCESSING
- * THEN we skip this option.
- */
- if (PROCESSING(direction))
- return;
- break;
- }
-
- /*
- * Fix up the args.
- */
- if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
- if (*pOS->pzOptArg != NUL)
- return;
- pOS->pzOptArg = NULL;
-
- } else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
- if (*pOS->pzOptArg == NUL)
- pOS->pzOptArg = NULL;
- else {
- AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" );
- pOS->flags |= OPTST_ALLOC_ARG;
- }
-
- } else {
- if (*pOS->pzOptArg == NUL)
- pOS->pzOptArg = zNil;
- else {
- AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" );
- pOS->flags |= OPTST_ALLOC_ARG;
- }
- }
-
- {
- tOptionLoadMode sv = option_load_mode;
- option_load_mode = load_mode;
- handleOption( pOpts, pOS );
- 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
- *
- * doc:
- *
- * This is a client program callable routine for setting options from, for
- * example, the contents of a file that they read in. Only one option may
- * appear in the text. It will be treated as a normal (non-preset) option.
- *
- * 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
- * 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}),
- * except that you may not use backquotes.
- *
- * err: Invalid options are silently ignored. Invalid option arguments
- * will cause a warning to print, but the function should return.
-=*/
-void
-optionLoadLine(
- tOptions* pOpts,
- tCC* pzLine )
-{
- tOptState st = OPTSTATE_INITIALIZER(SET);
- char* pz;
- AGDUPSTR( pz, pzLine, "user option line" );
- loadOptionLine( pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED );
- AGFREE( pz );
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/load.c */
+++ /dev/null
-dnl -*- buffer-read-only: t -*- vi: set ro:
-dnl
-dnl DO NOT EDIT THIS FILE (libopts.m4)
-dnl
-dnl It has been AutoGen-ed August 1, 2009 at 11:21:13 AM by AutoGen 5.9.9pre4
-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_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
-
- # ----------------------------------------------------------------------
- # check for various programs used during the build.
- # On OS/X, "wchar.h" needs "runetype.h" to work properly.
- # ----------------------------------------------------------------------
- AC_CHECK_HEADERS([runetype.h wchar.h], [], [],[
- AC_INCLUDES_DEFAULT
- #if HAVE_RUNETYPE_H
- # include <runetype.h>
- #endif
- ])
-
- # ----------------------------------------------------------------------
- # 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
- ])
-
- # ========================
- # ...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)
- AC_CHECK_SIZEOF(int, 4)
- AC_CHECK_SIZEOF(long, 4)
- AC_CHECK_SIZEOF(short, 2)
-
- # ----------------------------------------------------------------------
- # AC_CHECK_LIB for SVR4 libgen, and use it if it defines pathfind.
- # ----------------------------------------------------------------------
- AC_CHECK_LIB(gen, pathfind)
- AC_FUNC_VPRINTF
- AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr \
- strrchr strsignal])
-[ INVOKE_LIBOPTS_MACROS_FIRST_done=yes
-fi]])
-
-dnl
-dnl @synopsis INVOKE_LIBOPTS_MACROS
-dnl
-dnl This macro will invoke the AutoConf macros specified in libopts.def
-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]),
- [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]),
- [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
- then ## disabled by request
- libopts_cv_with_libregex_root=no
- libopts_cv_with_libregex_cflags=no
- libopts_cv_with_libregex_libs=no
- else
-
- AC_ARG_WITH([libregex-cflags],
- AC_HELP_STRING([--with-libregex-cflags], [libregex compile flags]),
- [libopts_cv_with_libregex_cflags=${with_regex_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}],
- 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
-
- case "X${libopts_cv_with_libregex_cflags}" in
- Xyes|Xno|X )
- case "X${libopts_cv_with_libregex_root}" in
- Xyes|Xno|X ) libopts_cv_with_libregex_cflags=no ;;
- * ) libopts_cv_with_libregex_cflags=-I${libopts_cv_with_libregex_root}/include ;;
- esac
- esac
- case "X${libopts_cv_with_libregex_libs}" in
- Xyes|Xno|X )
- case "X${libopts_cv_with_libregex_root}" in
- Xyes|Xno|X ) libopts_cv_with_libregex_libs=no ;;
- * ) libopts_cv_with_libregex_libs="-L${libopts_cv_with_libregex_root}/lib -lregex";;
- esac
- 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="" ;;
- * ) CPPFLAGS="${CPPFLAGS} ${libopts_cv_with_libregex_cflags}" ;;
- esac
- case "X${libopts_cv_with_libregex_libs}" in
- Xyes|Xno|X )
- libopts_cv_with_libregex_libs="" ;;
- * )
- LIBS="${LIBS} ${libopts_cv_with_libregex_libs}" ;;
- esac
- LIBREGEX_CFLAGS=""
- LIBREGEX_LIBS=""
- AC_MSG_CHECKING([whether libregex functions properly])
- AC_CACHE_VAL([libopts_cv_with_libregex],[
- AC_TRY_RUN([@%:@include <stdio.h>
-@%:@include <stdlib.h>
-@%:@include <sys/types.h>
-@%:@include REGEX_HEADER
-static regex_t re;
-void comp_re( char const* pzPat ) {
- int res = regcomp( &re, pzPat, REG_EXTENDED|REG_ICASE|REG_NEWLINE );
- if (res == 0) return;
- exit( res ); }
-int main() {
- regmatch_t m@<:@2@:>@;
- comp_re( "^.*\@S|@" );
- comp_re( "()|no.*" );
- comp_re( "." );
- if (regexec( &re, "X", 2, m, 0 ) != 0) return 1;
- if ((m@<:@0@:>@.rm_so != 0) || (m@<:@0@:>@.rm_eo != 1)) {
- fputs( "error: regex -->.<-- did not match\n", stderr );
- return 1;
- }
- return 0; }],
- [libopts_cv_with_libregex=yes], [libopts_cv_with_libregex=no],
- [libopts_cv_with_libregex=no]) # end of AC_TRY_RUN
- ]) # end of AC_CACHE_VAL for libopts_cv_with_libregex
- AC_MSG_RESULT([${libopts_cv_with_libregex}])
-
- if test "X${libopts_cv_with_libregex}" != Xno
- then
- AC_DEFINE([WITH_LIBREGEX],[1],
- [Define this if a working libregex can be found])
- else
- CPPFLAGS="${libopts_save_CPPFLAGS}"
- LIBS="${libopts_save_LIBS}"
- 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>
-@%:@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 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
-
-
-AC_DEFUN([LIBOPTS_TEST_DEV_ZERO],[
- AC_MSG_CHECKING([whether /dev/zero is readable device])
- AC_CACHE_VAL([libopts_cv_test_dev_zero],[
- libopts_cv_test_dev_zero=`exec 2> /dev/null
-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"
- 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>
-@%:@include <stdlib.h>
-int main (int argc, char** argv) {
-@%:@ifndef PATH_MAX
-choke me!!
-@%:@else
- char zPath@<:@PATH_MAX+1@:>@;
-@%:@endif
- char *pz = realpath(argv@<:@0@:>@, zPath);
- 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 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>
-@%:@include <string.h>
-char t_buf@<:@ 64 @:>@;
-int main() {
- static char const z@<:@@:>@ = "Thursday Aug 28 240";
- struct tm tm;
- tm.tm_sec = 36; /* seconds after the minute @<:@0, 61@:>@ */
- tm.tm_min = 44; /* minutes after the hour @<:@0, 59@:>@ */
- tm.tm_hour = 12; /* hour since midnight @<:@0, 23@:>@ */
- tm.tm_mday = 28; /* day of the month @<:@1, 31@:>@ */
- tm.tm_mon = 7; /* months since January @<:@0, 11@:>@ */
- tm.tm_year = 86; /* years since 1900 */
- tm.tm_wday = 4; /* days since Sunday @<:@0, 6@:>@ */
- tm.tm_yday = 239; /* days since January 1 @<:@0, 365@:>@ */
- tm.tm_isdst = 1; /* flag for daylight savings time */
- 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 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>
-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 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",
- [fopen(3) accepts a 'b' in the mode flag])
- else
- 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>
-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 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",
- [fopen(3) accepts a 't' in the mode flag])
- else
- 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]),
- [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
- # Check to see if a reg expr header is specified.
- LIBOPTS_WITH_REGEX_HEADER
-
- # Check to see if a working libregex can be found.
- LIBOPTS_WITHLIB_REGEX
-
- # Check to see if pathfind(3) works.
- LIBOPTS_RUN_PATHFIND
-
- # Check to see if /dev/zero is readable device.
- LIBOPTS_TEST_DEV_ZERO
-
- # Check to see if we have a functional realpath(3C).
- LIBOPTS_RUN_REALPATH
-
- # Check to see if strftime() works.
- LIBOPTS_RUN_STRFTIME
-
- # Check to see if fopen accepts "b" mode.
- LIBOPTS_RUN_FOPEN_BINARY
-
- # Check to see if fopen accepts "t" mode.
- LIBOPTS_RUN_FOPEN_TEXT
-
- # Check to see if not wanting optional option args.
- LIBOPTS_DISABLE_OPTIONAL_ARGS
-
-]) # end AC_DEFUN of 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:07:47 $
-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
-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
-dnl Free Software Foundation, either version 3 of the License, or
-dnl (at your option) any later version.
-dnl
-dnl AutoGen is distributed in the hope that it will be useful, but
-dnl WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-dnl See the GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License along
-dnl with this program. If not, see <http://www.gnu.org/licenses/>.
-dnl
-dnl Default to system libopts
-dnl
-AC_DEFUN([LIBOPTS_CHECK],[
- [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]),[
- 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
- 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])
-
- [if test -z "${NEED_LIBOPTS_DIR}" ; then]
- AC_MSG_CHECKING([whether autoopts-config can be found])
- AC_ARG_WITH([autoopts-config],
- AC_HELP_STRING([--with-autoopts-config],
- [specify the config-info script]),
- [lo_cv_with_autoopts_config=${with_autoopts_config}],
- AC_CACHE_CHECK([whether autoopts-config is specified],
- [lo_cv_with_autoopts_config],
- [if autoopts-config --help 2>/dev/null 1>&2
- then lo_cv_with_autoopts_config=autoopts-config
- elif libopts-config --help 2>/dev/null 1>&2
- then lo_cv_with_autoopts_config=libopts-config
- else lo_cv_with_autoopts_config=no ; fi])
- ) # end of AC_ARG_WITH
-
- AC_CACHE_VAL([lo_cv_test_autoopts],[
- if test -z "${lo_cv_with_autoopts_config}" \
- -o X"${lo_cv_with_autoopts_config}" = Xno
- then
- if autoopts-config --help 2>/dev/null 1>&2
- then lo_cv_with_autoopts_config=autoopts-config
- elif libopts-config --help 2>/dev/null 1>&2
- then lo_cv_with_autoopts_config=libopts-config
- else lo_cv_with_autoopts_config=false ; fi
- fi
- lo_cv_test_autoopts=`
- ${lo_cv_with_autoopts_config} --libs` 2> /dev/null
- if test $? -ne 0 -o -z "${lo_cv_test_autoopts}"
- then lo_cv_test_autoopts=no ; fi
- ]) # end of CACHE_VAL
- AC_MSG_RESULT([${lo_cv_test_autoopts}])
-
- [if test "X${lo_cv_test_autoopts}" != Xno
- then
- LIBOPTS_LDADD="${lo_cv_test_autoopts}"
- LIBOPTS_CFLAGS="`${lo_cv_with_autoopts_config} --cflags`"
- else
- LIBOPTS_LDADD='$(top_builddir)/]AO_Libopts_Dir[/libopts.la'
- LIBOPTS_CFLAGS='-I$(top_srcdir)/]AO_Libopts_Dir['
- NEED_LIBOPTS_DIR=true
- fi
- fi # end of if test -z "${NEED_LIBOPTS_DIR}"]
-
- 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]
- INVOKE_LIBOPTS_MACROS
- else
- INVOKE_LIBOPTS_MACROS_FIRST
- [fi
-# end of AC_DEFUN of LIBOPTS_CHECK]
-])
+++ /dev/null
-# liboptschk.m4 serial 1 (autogen - 5.7.3)
-dnl copyright (c) 2005-2009 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:07:46 $
-
-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)
-
-AC_DEFUN([ag_FIND_LIBOPTS],
- [if test "X${ac_cv_header_autoopts_options_h}" == Xno
- 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])
+++ /dev/null
-
-/*
- * $Id: makeshell.c,v 4.29 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-07-26 16:10:51 bkorb"
- *
- * This module will interpret the options set in the tOptions
- * structure and create a Bourne shell script capable of parsing them.
- *
- * 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
- */
-
-tOptions* pShellParseOptions = NULL;
-
-/* * * * * * * * * * * * * * * * * * * * *
- *
- * Setup Format Strings
- */
-tSCC zStartMarker[] =
-"# # # # # # # # # # -- do not modify this marker --\n#\n"
-"# DO NOT EDIT THIS SECTION";
-
-tSCC zPreamble[] =
-"%s OF %s\n#\n"
-"# From here to the next `-- do not modify this marker --',\n"
-"# the text has been generated %s\n";
-
-tSCC zEndPreamble[] =
-"# From the %s option definitions\n#\n";
-
-tSCC zMultiDef[] = "\n"
-"if test -z \"${%1$s_%2$s}\"\n"
-"then\n"
-" %1$s_%2$s_CT=0\n"
-"else\n"
-" %1$s_%2$s_CT=1\n"
-" %1$s_%2$s_1=\"${%1$s_%2$s}\"\n"
-"fi\n"
-"export %1$s_%2$s_CT";
-
-tSCC zSingleDef[] = "\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";
-
-tSCC zSingleNoDef[] = "\n"
-"%1$s_%2$s=\"${%1$s_%2$s}\"\n"
-"%1$s_%2$s_set=false\n"
-"export %1$s_%2$s\n";
-
-/* * * * * * * * * * * * * * * * * * * * *
- *
- * LOOP START
- *
- * The loop may run in either of two modes:
- * all options are named options (loop only)
- * regular, marked option processing.
- */
-tSCC zLoopCase[] = "\n"
-"OPT_PROCESS=true\n"
-"OPT_ARG=\"$1\"\n\n"
-"while ${OPT_PROCESS} && [ $# -gt 0 ]\ndo\n"
-" OPT_ELEMENT=''\n"
-" OPT_ARG_VAL=''\n\n"
- /*
- * 'OPT_ARG' may or may not match the current $1
- */
-" case \"${OPT_ARG}\" in\n"
-" -- )\n"
-" OPT_PROCESS=false\n"
-" shift\n"
-" ;;\n\n";
-
-tSCC zLoopOnly[] = "\n"
-"OPT_ARG=\"$1\"\n\n"
-"while [ $# -gt 0 ]\ndo\n"
-" OPT_ELEMENT=''\n"
-" OPT_ARG_VAL=''\n\n"
-" OPT_ARG=\"${1}\"\n";
-
-/* * * * * * * * * * * * * * * *
- *
- * CASE SELECTORS
- *
- * If the loop runs as a regular option loop,
- * then we must have selectors for each acceptable option
- * type (long option, flag character and non-option)
- */
-tSCC zLongSelection[] =
-" --* )\n";
-
-tSCC zFlagSelection[] =
-" -* )\n";
-
-tSCC zEndSelection[] =
-" ;;\n\n";
-
-tSCC zNoSelection[] =
-" * )\n"
-" OPT_PROCESS=false\n"
-" ;;\n"
-" esac\n\n";
-
-/* * * * * * * * * * * * * * * *
- *
- * LOOP END
- */
-tSCC zLoopEnd[] =
-" 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\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%2$s";
-
-tSCC zTrailerMarker[] = "\n"
-"# # # # # # # # # #\n#\n"
-"# END OF AUTOMATED OPTION PROCESSING\n"
-"#\n# # # # # # # # # # -- do not modify this marker --\n";
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * OPTION SELECTION
- */
-tSCC zOptionCase[] =
-" case \"${OPT_CODE}\" in\n";
-
-tSCC zOptionPartName[] =
-" '%s' | \\\n";
-
-tSCC zOptionFullName[] =
-" '%s' )\n";
-
-tSCC zOptionFlag[] =
-" '%c' )\n";
-
-tSCC zOptionEndSelect[] =
-" ;;\n\n";
-
-tSCC zOptionUnknown[] =
-" * )\n"
-" echo Unknown %s: \"${OPT_CODE}\" >&2\n"
-" echo \"$%s_USAGE_TEXT\"\n"
-" exit 1\n"
-" ;;\n"
-" esac\n\n";
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * OPTION PROCESSING
- *
- * Formats for emitting the text for handling particular options
- */
-tSCC zTextExit[] =
-" echo \"$%s_%s_TEXT\"\n"
-" exit 0\n";
-
-tSCC zPagedUsageExit[] =
-" echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n"
-" exit 0\n";
-
-tSCC zCmdFmt[] =
-" %s\n";
-
-tSCC zCountTest[] =
-" if [ $%1$s_%2$s_CT -ge %3$d ] ; then\n"
-" echo Error: more than %3$d %2$s options >&2\n"
-" echo \"$%1$s_USAGE_TEXT\"\n"
-" exit 1 ; fi\n";
-
-tSCC zMultiArg[] =
-" %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";
-
-tSCC zSingleArg[] =
-" if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
-" echo Error: duplicate %2$s option >&2\n"
-" echo \"$%1$s_USAGE_TEXT\"\n"
-" exit 1 ; fi\n"
-" %1$s_%2$s_set=true\n"
-" OPT_NAME='%2$s'\n";
-
-tSCC zNoMultiArg[] =
-" %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";
-
-tSCC zNoSingleArg[] =
-" if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n"
-" echo Error: duplicate %2$s option >&2\n"
-" echo \"$%1$s_USAGE_TEXT\"\n"
-" exit 1 ; fi\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";
-
-tSCC zMayArg[] =
-" eval %1$s_%2$s${OPT_ELEMENT}=true\n"
-" export %1$s_%2$s${OPT_ELEMENT}\n"
-" OPT_ARG_NEEDED=OK\n";
-
-tSCC zMustArg[] =
-" OPT_ARG_NEEDED=YES\n";
-
-tSCC zCantArg[] =
-" eval %1$s_%2$s${OPT_ELEMENT}=true\n"
-" export %1$s_%2$s${OPT_ELEMENT}\n"
-" OPT_ARG_NEEDED=NO\n";
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * LONG OPTION PROCESSING
- *
- * Formats for emitting the text for handling long option types
- */
-tSCC zLongOptInit[] =
-" OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n"
-" shift\n"
-" OPT_ARG=\"$1\"\n\n"
-" case \"${OPT_CODE}\" in *=* )\n"
-" OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n"
-" OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\n";
-
-tSCC zLongOptArg[] =
-" case \"${OPT_ARG_NEEDED}\" in\n"
-" NO )\n"
-" OPT_ARG_VAL=''\n"
-" ;;\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 >&2\n"
-" echo \"$%s_USAGE_TEXT\"\n"
-" exit 1\n"
-" fi\n\n"
-" OPT_ARG_VAL=\"${OPT_ARG}\"\n"
-" shift\n"
-" OPT_ARG=\"$1\"\n"
-" fi\n"
-" ;;\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";
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * FLAG OPTION PROCESSING
- *
- * Formats for emitting the text for handling flag option types
- */
-tSCC zFlagOptInit[] =
-" OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n"
-" OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\n";
-
-tSCC zFlagOptArg[] =
-" 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\n"
-" YES )\n"
-" if [ -n \"${OPT_ARG}\" ]\n"
-" then\n"
-" OPT_ARG_VAL=\"${OPT_ARG}\"\n\n"
-" else\n"
-" if [ $# -eq 0 ]\n"
-" then\n"
-" echo No argument provided for ${OPT_NAME} option >&2\n"
-" echo \"$%s_USAGE_TEXT\"\n"
-" exit 1\n"
-" fi\n"
-" shift\n"
-" OPT_ARG_VAL=\"$1\"\n"
-" fi\n\n"
-" shift\n"
-" OPT_ARG=\"$1\"\n"
-" ;;\n\n"
-" OK )\n"
-" if [ -n \"${OPT_ARG}\" ]\n"
-" then\n"
-" OPT_ARG_VAL=\"${OPT_ARG}\"\n"
-" shift\n"
-" OPT_ARG=\"$1\"\n\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";
-
-tSCC* pzShell = NULL;
-static char* pzLeader = NULL;
-static char* pzTrailer = NULL;
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD );
-
-static void
-emitUsage( tOptions* pOpts );
-
-static void
-emitSetup( tOptions* pOpts );
-
-static void
-printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc );
-
-static void
-printOptionInaction( tOptions* pOpts, tOptDesc* pOptDesc );
-
-static void
-emitFlag( tOptions* pOpts );
-
-static void
-emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts );
-
-static void
-emitLong( tOptions* pOpts );
-
-static void
-openOutput( char const* pzFile );
-/* = = = END-STATIC-FORWARD = = = */
-
-/*=export_func optionParseShell
- * private:
- *
- * what: Decipher a boolean value
- * arg: + tOptions* + pOpts + program options descriptor +
- *
- * doc:
- * Emit a shell script that will parse the command line options.
-=*/
-void
-optionParseShell( tOptions* pOpts )
-{
- /*
- * Check for our SHELL option now.
- * IF the output file contains the "#!" magic marker,
- * it will override anything we do here.
- */
- if (HAVE_OPT( SHELL ))
- pzShell = OPT_ARG( SHELL );
-
- else if (! ENABLED_OPT( SHELL ))
- pzShell = NULL;
-
- else if ((pzShell = getenv( "SHELL" )),
- pzShell == NULL)
-
- pzShell = "/bin/sh";
-
- /*
- * Check for a specified output file
- */
- if (HAVE_OPT( SCRIPT ))
- openOutput( OPT_ARG( SCRIPT ));
-
- emitUsage( pOpts );
- emitSetup( pOpts );
-
- /*
- * There are four modes of option processing.
- */
- switch (pOpts->fOptSet & (OPTPROC_LONGOPT|OPTPROC_SHORTOPT)) {
- case OPTPROC_LONGOPT:
- fputs( zLoopCase, stdout );
-
- fputs( zLongSelection, stdout );
- fputs( zLongOptInit, stdout );
- emitLong( pOpts );
- printf( zLongOptArg, pOpts->pzPROGNAME );
- fputs( zEndSelection, stdout );
-
- fputs( zNoSelection, stdout );
- break;
-
- case 0:
- fputs( zLoopOnly, stdout );
- fputs( zLongOptInit, stdout );
- emitLong( pOpts );
- printf( zLongOptArg, pOpts->pzPROGNAME );
- break;
-
- case OPTPROC_SHORTOPT:
- fputs( zLoopCase, stdout );
-
- fputs( zFlagSelection, stdout );
- fputs( zFlagOptInit, stdout );
- emitFlag( pOpts );
- printf( zFlagOptArg, pOpts->pzPROGNAME );
- fputs( zEndSelection, stdout );
-
- fputs( zNoSelection, stdout );
- break;
-
- case OPTPROC_LONGOPT|OPTPROC_SHORTOPT:
- fputs( zLoopCase, stdout );
-
- fputs( zLongSelection, stdout );
- fputs( zLongOptInit, stdout );
- emitLong( pOpts );
- printf( zLongOptArg, pOpts->pzPROGNAME );
- fputs( zEndSelection, stdout );
-
- fputs( zFlagSelection, stdout );
- fputs( zFlagOptInit, stdout );
- emitFlag( pOpts );
- printf( zFlagOptArg, pOpts->pzPROGNAME );
- fputs( zEndSelection, stdout );
-
- fputs( zNoSelection, stdout );
- break;
- }
-
- printf( zLoopEnd, pOpts->pzPROGNAME, zTrailerMarker );
- if ((pzTrailer != NULL) && (*pzTrailer != '\0'))
- fputs( pzTrailer, stdout );
- else if (ENABLED_OPT( SHELL ))
- printf( "\nenv | grep '^%s_'\n", pOpts->pzPROGNAME );
-
- fflush( stdout );
- fchmod( STDOUT_FILENO, 0755 );
- fclose( stdout );
-}
-
-
-static void
-textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD )
-{
-# define _TT_(n) tSCC z ## n [] = #n;
- TEXTTO_TABLE
-# undef _TT_
-# define _TT_(n) z ## n ,
- static char const* apzTTNames[] = { TEXTTO_TABLE };
-# undef _TT_
-
-#if defined(__windows__) && !defined(__CYGWIN__)
- printf( "%1$s_%2$s_TEXT='no %2$s text'\n",
- pOpts->pzPROGNAME, apzTTNames[ whichVar ]);
-#else
- int nlHoldCt = 0;
- int pipeFd[2];
- FILE* fp;
-
- printf( "%s_%s_TEXT='", pOpts->pzPROGNAME, apzTTNames[ whichVar ]);
- fflush( stdout );
-
- if (pipe( pipeFd ) != 0) {
- fprintf( stderr, zBadPipe, errno, strerror( errno ));
- exit( EXIT_FAILURE );
- }
-
- switch (fork()) {
- case -1:
- fprintf( stderr, zForkFail, errno, strerror(errno), pOpts->pzProgName);
- exit( EXIT_FAILURE );
- break;
-
- case 0:
- dup2( pipeFd[1], STDERR_FILENO );
- dup2( pipeFd[1], STDOUT_FILENO );
- close( pipeFd[0] );
-
- switch (whichVar) {
- case TT_LONGUSAGE:
- (*(pOpts->pUsageProc))( pOpts, EXIT_SUCCESS );
- /* NOTREACHED */
- exit( EXIT_FAILURE );
-
- case TT_USAGE:
- (*(pOpts->pUsageProc))( pOpts, EXIT_FAILURE );
- /* NOTREACHED */
- exit( EXIT_FAILURE );
-
- case TT_VERSION:
- if (pOD->fOptState & OPTST_ALLOC_ARG) {
- AGFREE(pOD->optArg.argString);
- pOD->fOptState &= ~OPTST_ALLOC_ARG;
- }
- pOD->optArg.argString = "c";
- optionPrintVersion( pOpts, pOD );
- /* NOTREACHED */
-
- default:
- exit( EXIT_FAILURE );
- }
-
- default:
- close( pipeFd[1] );
- fp = fdopen( pipeFd[0], "r" FOPEN_BINARY_FLAG );
- }
-
- for (;;) {
- int ch = fgetc( fp );
- switch (ch) {
-
- case '\n':
- nlHoldCt++;
- break;
-
- case '\'':
- while (nlHoldCt > 0) {
- fputc( '\n', stdout );
- nlHoldCt--;
- }
- fputs( "'\\''", stdout );
- break;
-
- case EOF:
- goto endCharLoop;
-
- default:
- while (nlHoldCt > 0) {
- fputc( '\n', stdout );
- nlHoldCt--;
- }
- fputc( ch, stdout );
- break;
- }
- } endCharLoop:;
-
- fputs( "'\n\n", stdout );
- close( pipeFd[0] );
-#endif
-}
-
-
-static void
-emitUsage( tOptions* pOpts )
-{
- char zTimeBuf[ AO_NAME_SIZE ];
-
- /*
- * First, switch stdout to the output file name.
- * Then, change the program name to the one defined
- * by the definitions (rather than the current
- * executable name). Down case the upper cased name.
- */
- if (pzLeader != NULL)
- fputs( pzLeader, stdout );
-
- {
- tSCC zStdout[] = "stdout";
- tCC* pzOutName;
-
- {
- time_t curTime = time( NULL );
- struct tm* pTime = localtime( &curTime );
- strftime(zTimeBuf, AO_NAME_SIZE, "%A %B %e, %Y at %r %Z", pTime );
- }
-
- if (HAVE_OPT( SCRIPT ))
- pzOutName = OPT_ARG( SCRIPT );
- else pzOutName = zStdout;
-
- if ((pzLeader == NULL) && (pzShell != NULL))
- printf( "#! %s\n", pzShell );
-
- printf( zPreamble, zStartMarker, pzOutName, zTimeBuf );
- }
-
- /*
- * Get a copy of the original program name in lower case
- */
- {
- char* pzPN = zTimeBuf;
- tCC* pz = pOpts->pzPROGNAME;
- for (;;) {
- if ((*pzPN++ = tolower( *pz++ )) == '\0')
- break;
- }
- }
-
- printf( zEndPreamble, pOpts->pzPROGNAME );
-
- pOpts->pzProgPath = pOpts->pzProgName = zTimeBuf;
- textToVariable( pOpts, TT_LONGUSAGE, NULL );
- textToVariable( pOpts, TT_USAGE, NULL );
-
- {
- tOptDesc* pOptDesc = pOpts->pOptDesc;
- int optionCt = pOpts->optCt;
-
- for (;;) {
- if (pOptDesc->pOptProc == optionPrintVersion) {
- textToVariable( pOpts, TT_VERSION, pOptDesc );
- break;
- }
-
- if (--optionCt <= 0)
- break;
- pOptDesc++;
- }
- }
-}
-
-
-static void
-emitSetup( tOptions* pOpts )
-{
- tOptDesc* pOptDesc = pOpts->pOptDesc;
- int optionCt = pOpts->presetOptCt;
- char const* pzFmt;
- char const* pzDefault;
-
- for (;optionCt > 0; pOptDesc++, --optionCt) {
- char zVal[16];
-
- /*
- * Options that are either usage documentation or are compiled out
- * are not to be processed.
- */
- if (SKIP_OPT(pOptDesc) || (pOptDesc->pz_NAME == NULL))
- continue;
-
- if (pOptDesc->optMaxCt > 1)
- pzFmt = zMultiDef;
- else pzFmt = zSingleDef;
-
- /*
- * IF this is an enumeration/bitmask option, then convert the value
- * to a string before printing the default value.
- */
- switch (OPTST_GET_ARGTYPE(pOptDesc->fOptState)) {
- case OPARG_TYPE_ENUMERATION:
- (*(pOptDesc->pOptProc))(OPTPROC_EMIT_SHELL, pOptDesc );
- pzDefault = pOptDesc->optArg.argString;
- break;
-
- /*
- * Numeric and membership bit options are just printed as a number.
- */
- case OPARG_TYPE_NUMERIC:
- snprintf( zVal, sizeof( zVal ), "%d",
- (int)pOptDesc->optArg.argInt );
- pzDefault = zVal;
- break;
-
- case OPARG_TYPE_MEMBERSHIP:
- snprintf( zVal, sizeof( zVal ), "%lu",
- (unsigned long)pOptDesc->optArg.argIntptr );
- pzDefault = zVal;
- break;
-
- case OPARG_TYPE_BOOLEAN:
- pzDefault = (pOptDesc->optArg.argBool) ? "true" : "false";
- break;
-
- default:
- if (pOptDesc->optArg.argString == NULL) {
- if (pzFmt == zSingleDef)
- pzFmt = zSingleNoDef;
- pzDefault = NULL;
- }
- else
- pzDefault = pOptDesc->optArg.argString;
- }
-
- printf( pzFmt, pOpts->pzPROGNAME, pOptDesc->pz_NAME, pzDefault );
- }
-}
-
-
-static void
-printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc )
-{
- if (pOptDesc->pOptProc == optionPrintVersion)
- printf( zTextExit, pOpts->pzPROGNAME, "VERSION" );
-
- else if (pOptDesc->pOptProc == optionPagedUsage)
- printf( zPagedUsageExit, pOpts->pzPROGNAME );
-
- else if (pOptDesc->pOptProc == optionLoadOpt) {
- printf( zCmdFmt, "echo 'Warning: Cannot load options files' >&2" );
- printf( zCmdFmt, "OPT_ARG_NEEDED=YES" );
-
- } else if (pOptDesc->pz_NAME == NULL) {
-
- if (pOptDesc->pOptProc == NULL) {
- printf( zCmdFmt, "echo 'Warning: Cannot save options files' "
- ">&2" );
- printf( zCmdFmt, "OPT_ARG_NEEDED=OK" );
- } else
- printf( zTextExit, pOpts->pzPROGNAME, "LONGUSAGE" );
-
- } else {
- if (pOptDesc->optMaxCt == 1)
- printf( zSingleArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
- else {
- if ((unsigned)pOptDesc->optMaxCt < NOLIMIT)
- printf( zCountTest, pOpts->pzPROGNAME,
- pOptDesc->pz_NAME, pOptDesc->optMaxCt );
-
- printf( zMultiArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
- }
-
- /*
- * Fix up the args.
- */
- if (OPTST_GET_ARGTYPE(pOptDesc->fOptState) == OPARG_TYPE_NONE) {
- printf( zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
-
- } else if (pOptDesc->fOptState & OPTST_ARG_OPTIONAL) {
- printf( zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
-
- } else {
- fputs( zMustArg, stdout );
- }
- }
- fputs( zOptionEndSelect, stdout );
-}
-
-
-static void
-printOptionInaction( tOptions* pOpts, tOptDesc* pOptDesc )
-{
- if (pOptDesc->pOptProc == optionLoadOpt) {
- printf( zCmdFmt, "echo 'Warning: Cannot suppress the loading of "
- "options files' >&2" );
-
- } else if (pOptDesc->optMaxCt == 1)
- printf( zNoSingleArg, pOpts->pzPROGNAME,
- pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx );
- else
- printf( zNoMultiArg, pOpts->pzPROGNAME,
- pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx );
-
- printf( zCmdFmt, "OPT_ARG_NEEDED=NO" );
- fputs( zOptionEndSelect, stdout );
-}
-
-
-static void
-emitFlag( tOptions* pOpts )
-{
- tOptDesc* pOptDesc = pOpts->pOptDesc;
- int optionCt = pOpts->optCt;
-
- fputs( zOptionCase, stdout );
-
- for (;optionCt > 0; pOptDesc++, --optionCt) {
-
- if (SKIP_OPT(pOptDesc))
- continue;
-
- if (IS_GRAPHIC_CHAR(pOptDesc->optValue)) {
- printf( zOptionFlag, pOptDesc->optValue );
- printOptionAction( pOpts, pOptDesc );
- }
- }
- printf( zOptionUnknown, "flag", pOpts->pzPROGNAME );
-}
-
-
-/*
- * Emit the match text for a long option
- */
-static void
-emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts )
-{
- tOptDesc* pOD = pOpts->pOptDesc;
- int oCt = pOpts->optCt;
- int min = 1;
- char zName[ 256 ];
- char* pz = zName;
-
- for (;;) {
- int matchCt = 0;
-
- /*
- * Omit the current option, Documentation opts and compiled out opts.
- */
- if ((pOD == pCurOpt) || SKIP_OPT(pOD)){
- if (--oCt <= 0)
- break;
- pOD++;
- continue;
- }
-
- /*
- * Check each character of the name case insensitively.
- * They must not be the same. They cannot be, because it would
- * not compile correctly if they were.
- */
- while ( toupper( pOD->pz_Name[matchCt] )
- == toupper( pzMatchName[matchCt] ))
- matchCt++;
-
- if (matchCt > min)
- min = matchCt;
-
- /*
- * Check the disablement name, too.
- */
- if (pOD->pz_DisableName != NULL) {
- matchCt = 0;
- while ( toupper( pOD->pz_DisableName[matchCt] )
- == toupper( pzMatchName[matchCt] ))
- matchCt++;
- if (matchCt > min)
- min = matchCt;
- }
- if (--oCt <= 0)
- break;
- pOD++;
- }
-
- /*
- * IF the 'min' is all or one short of the name length,
- * THEN the entire string must be matched.
- */
- if ( (pzMatchName[min ] == NUL)
- || (pzMatchName[min+1] == NUL) )
- printf( zOptionFullName, pzMatchName );
-
- else {
- int matchCt = 0;
- for (; matchCt <= min; matchCt++)
- *pz++ = pzMatchName[matchCt];
-
- for (;;) {
- *pz = NUL;
- printf( zOptionPartName, zName );
- *pz++ = pzMatchName[matchCt++];
- if (pzMatchName[matchCt] == NUL) {
- *pz = NUL;
- printf( zOptionFullName, zName );
- break;
- }
- }
- }
-}
-
-
-/*
- * Emit GNU-standard long option handling code
- */
-static void
-emitLong( tOptions* pOpts )
-{
- tOptDesc* pOD = pOpts->pOptDesc;
- int ct = pOpts->optCt;
-
- fputs( zOptionCase, stdout );
-
- /*
- * do each option, ...
- */
- do {
- /*
- * Documentation & compiled-out options
- */
- if (SKIP_OPT(pOD))
- continue;
-
- emitMatchExpr( pOD->pz_Name, pOD, pOpts );
- printOptionAction( pOpts, pOD );
-
- /*
- * Now, do the same thing for the disablement version of the option.
- */
- if (pOD->pz_DisableName != NULL) {
- emitMatchExpr( pOD->pz_DisableName, pOD, pOpts );
- printOptionInaction( pOpts, pOD );
- }
- } while (pOD++, --ct > 0);
-
- printf( zOptionUnknown, "option", pOpts->pzPROGNAME );
-}
-
-
-static void
-openOutput( char const* pzFile )
-{
- FILE* fp;
- char* pzData = NULL;
- struct stat stbf;
-
- do {
- char* pzScan;
- size_t sizeLeft;
-
- /*
- * IF we cannot stat the file,
- * THEN assume we are creating a new file.
- * Skip the loading of the old data.
- */
- if (stat( pzFile, &stbf ) != 0)
- break;
-
- /*
- * The file must be a regular file
- */
- if (! S_ISREG( stbf.st_mode )) {
- fprintf( stderr, zNotFile, pzFile );
- exit( EXIT_FAILURE );
- }
-
- pzData = AGALOC(stbf.st_size + 1, "file data");
- fp = fopen( pzFile, "r" FOPEN_BINARY_FLAG );
-
- sizeLeft = (unsigned)stbf.st_size;
- pzScan = pzData;
-
- /*
- * Read in all the data as fast as our OS will let us.
- */
- for (;;) {
- int inct = fread( (void*)pzScan, (size_t)1, sizeLeft, fp);
- if (inct == 0)
- break;
-
- pzScan += inct;
- sizeLeft -= inct;
-
- if (sizeLeft == 0)
- break;
- }
-
- /*
- * NUL-terminate the leader and look for the trailer
- */
- *pzScan = '\0';
- fclose( fp );
- pzScan = strstr( pzData, zStartMarker );
- if (pzScan == NULL) {
- pzTrailer = pzData;
- break;
- }
-
- *(pzScan++) = NUL;
- pzScan = strstr( pzScan, zTrailerMarker );
- if (pzScan == NULL) {
- pzTrailer = pzData;
- break;
- }
-
- /*
- * Check to see if the data contains
- * our marker. If it does, then we will skip over it
- */
- pzTrailer = pzScan + sizeof( zTrailerMarker ) - 1;
- pzLeader = pzData;
- } while (AG_FALSE);
-
- freopen( pzFile, "w" FOPEN_BINARY_FLAG, stdout );
-}
-
-
-/*=export_func genshelloptUsage
- * private:
- * what: The usage function for the genshellopt generated program
- *
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + int + exitCode + usage text type to produce +
- *
- * doc:
- * This function is used to create the usage strings for the option
- * processing shell script code. Two child processes are spawned
- * each emitting the usage text in either the short (error exit)
- * style or the long style. The generated program will capture this
- * and create shell script variables containing the two types of text.
-=*/
-void
-genshelloptUsage( tOptions* pOpts, int exitCode )
-{
-#if defined(__windows__) && !defined(__CYGWIN__)
- optionUsage( pOpts, exitCode );
-#else
- /*
- * IF not EXIT_SUCCESS,
- * THEN emit the short form of usage.
- */
- if (exitCode != EXIT_SUCCESS)
- optionUsage( pOpts, exitCode );
- fflush( stderr );
- fflush( stdout );
-
- option_usage_fp = stdout;
-
- /*
- * First, print our usage
- */
- switch (fork()) {
- case -1:
- optionUsage( pOpts, EXIT_FAILURE );
- /*NOTREACHED*/
- _exit( EXIT_FAILURE );
-
- case 0:
- pagerState = PAGER_STATE_CHILD;
- optionUsage( pOpts, EXIT_SUCCESS );
- /*NOTREACHED*/
- _exit( EXIT_FAILURE );
-
- default:
- {
- int sts;
- wait( &sts );
- }
- }
-
- /*
- * Generate the pzProgName, since optionProcess() normally
- * gets it from the command line
- */
- {
- char* pz;
- AGDUPSTR( pz, pShellParseOptions->pzPROGNAME, "program name" );
- pShellParseOptions->pzProgName = pz;
- while (*pz != NUL) {
- *pz = tolower( *pz );
- pz++;
- }
- }
-
- /*
- * Separate the makeshell usage from the client usage
- */
- fprintf( option_usage_fp, zGenshell, pShellParseOptions->pzProgName );
- fflush( option_usage_fp );
-
- /*
- * Now, print the client usage.
- */
- switch (fork()) {
- case 0:
- pagerState = PAGER_STATE_CHILD;
- /*FALLTHROUGH*/
- case -1:
- optionUsage( pShellParseOptions, EXIT_FAILURE );
-
- default:
- {
- int sts;
- wait( &sts );
- }
- }
-
- exit( EXIT_SUCCESS );
-#endif
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/makeshell.c */
+++ /dev/null
-
-/*
- * $Id: nested.c,v 4.28 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-07-28 19:18:28 bkorb"
- *
- * Automated Options Nested Values module.
- *
- * 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
- */
-
-typedef struct {
- int xml_ch;
- int xml_len;
- char xml_txt[8];
-} xml_xlate_t;
-
-static xml_xlate_t const xml_xlate[] = {
- { '&', 4, "amp;" },
- { '<', 3, "lt;" },
- { '>', 3, "gt;" },
- { '"', 5, "quot;" },
- { '\'',5, "apos;" }
-};
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-removeLineContinue( char* pzSrc );
-
-static char const*
-scanQuotedString( char const* pzTxt );
-
-static tOptionValue*
-addStringValue( void** pp, char const* pzName, size_t nameLen,
- char const* pzValue, size_t dataLen );
-
-static tOptionValue*
-addBoolValue( void** pp, char const* pzName, size_t nameLen,
- char const* pzValue, size_t dataLen );
-
-static tOptionValue*
-addNumberValue( void** pp, char const* pzName, size_t nameLen,
- char const* pzValue, size_t dataLen );
-
-static tOptionValue*
-addNestedValue( void** pp, char const* pzName, size_t nameLen,
- char* pzValue, size_t dataLen );
-
-static char const*
-scanNameEntry(char const* pzName, tOptionValue* pRes);
-
-static char const*
-scanXmlEntry( char const* pzName, tOptionValue* pRes );
-
-static void
-unloadNestedArglist( tArgList* pAL );
-
-static void
-sortNestedList( tArgList* pAL );
-/* = = = END-STATIC-FORWARD = = = */
-
-/* removeLineContinue
- *
- * Backslashes are used for line continuations. We keep the newline
- * characters, but trim out the backslash:
- */
-static void
-removeLineContinue( char* pzSrc )
-{
- char* pzD;
-
- do {
- while (*pzSrc == '\n') pzSrc++;
- pzD = strchr(pzSrc, '\n');
- if (pzD == NULL)
- return;
-
- /*
- * pzD has skipped at least one non-newline character and now
- * points to a newline character. It now becomes the source and
- * pzD goes to the previous character.
- */
- pzSrc = pzD--;
- if (*pzD != '\\')
- pzD++;
- } while (pzD == pzSrc);
-
- /*
- * Start shifting text.
- */
- for (;;) {
- char ch = ((*pzD++) = *(pzSrc++));
- switch (ch) {
- case NUL: return;
- case '\\':
- if (*pzSrc == '\n')
- --pzD; /* rewrite on next iteration */
- }
- }
-}
-
-
-/* scanQuotedString
- *
- * Find the end of a quoted string, skipping escaped quote characters.
- */
-static char const*
-scanQuotedString( char const* pzTxt )
-{
- char q = *(pzTxt++); /* remember the type of quote */
-
- for (;;) {
- char ch = *(pzTxt++);
- if (ch == NUL)
- return pzTxt-1;
-
- if (ch == q)
- return pzTxt;
-
- if (ch == '\\') {
- ch = *(pzTxt++);
- /*
- * IF the next character is NUL, drop the backslash, too.
- */
- if (ch == NUL)
- return pzTxt - 2;
-
- /*
- * IF the quote character or the escape character were escaped,
- * then skip both, as long as the string does not end.
- */
- if ((ch == q) || (ch == '\\')) {
- if (*(pzTxt++) == NUL)
- return pzTxt-1;
- }
- }
- }
-}
-
-
-/* addStringValue
- *
- * Associate a name with either a string or no value.
- */
-static tOptionValue*
-addStringValue( void** pp, char const* pzName, size_t nameLen,
- char const* pzValue, size_t dataLen )
-{
- tOptionValue* pNV;
- size_t sz = nameLen + dataLen + sizeof(*pNV);
-
- pNV = AGALOC( sz, "option name/str value pair" );
- if (pNV == NULL)
- return NULL;
-
- if (pzValue == NULL) {
- pNV->valType = OPARG_TYPE_NONE;
- pNV->pzName = pNV->v.strVal;
-
- } else {
- pNV->valType = OPARG_TYPE_STRING;
- if (dataLen > 0) {
- char const * pzSrc = pzValue;
- char * pzDst = pNV->v.strVal;
- int ct = dataLen;
- do {
- int ch = *(pzSrc++) & 0xFF;
- if (ch == NUL) goto data_copy_done;
- if (ch == '&')
- ch = get_special_char(&pzSrc, &ct);
- *(pzDst++) = ch;
- } while (--ct > 0);
- data_copy_done:
- *pzDst = NUL;
-
- } else {
- pNV->v.strVal[0] = NUL;
- }
-
- pNV->pzName = pNV->v.strVal + dataLen + 1;
- }
-
- memcpy( pNV->pzName, pzName, nameLen );
- pNV->pzName[ nameLen ] = NUL;
- addArgListEntry( pp, pNV );
- return pNV;
-}
-
-
-/* addBoolValue
- *
- * Associate a name with either a string or no value.
- */
-static tOptionValue*
-addBoolValue( void** pp, char const* pzName, size_t nameLen,
- char const* pzValue, size_t dataLen )
-{
- tOptionValue* pNV;
- size_t sz = nameLen + sizeof(*pNV) + 1;
-
- pNV = AGALOC( sz, "option name/bool value pair" );
- if (pNV == NULL)
- return NULL;
- while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) {
- dataLen--; pzValue++;
- }
- if (dataLen == 0)
- pNV->v.boolVal = 0;
-
- else if (IS_DEC_DIGIT_CHAR(*pzValue))
- pNV->v.boolVal = atoi(pzValue);
-
- else pNV->v.boolVal = ! IS_FALSE_TYPE_CHAR(*pzValue);
-
- pNV->valType = OPARG_TYPE_BOOLEAN;
- pNV->pzName = (char*)(pNV + 1);
- memcpy( pNV->pzName, pzName, nameLen );
- pNV->pzName[ nameLen ] = NUL;
- addArgListEntry( pp, pNV );
- return pNV;
-}
-
-
-/* addNumberValue
- *
- * Associate a name with either a string or no value.
- */
-static tOptionValue*
-addNumberValue( void** pp, char const* pzName, size_t nameLen,
- char const* pzValue, size_t dataLen )
-{
- tOptionValue* pNV;
- size_t sz = nameLen + sizeof(*pNV) + 1;
-
- pNV = AGALOC( sz, "option name/bool value pair" );
- if (pNV == NULL)
- return NULL;
- while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) {
- dataLen--; pzValue++;
- }
- if (dataLen == 0)
- pNV->v.longVal = 0;
- else
- pNV->v.longVal = strtol(pzValue, 0, 0);
-
- pNV->valType = OPARG_TYPE_NUMERIC;
- pNV->pzName = (char*)(pNV + 1);
- memcpy( pNV->pzName, pzName, nameLen );
- pNV->pzName[ nameLen ] = NUL;
- addArgListEntry( pp, pNV );
- return pNV;
-}
-
-
-/* addNestedValue
- *
- * Associate a name with either a string or no value.
- */
-static tOptionValue*
-addNestedValue( void** pp, char const* pzName, size_t nameLen,
- char* pzValue, size_t dataLen )
-{
- tOptionValue* pNV;
-
- if (dataLen == 0) {
- size_t sz = nameLen + sizeof(*pNV) + 1;
- pNV = AGALOC( sz, "empty nested value pair" );
- if (pNV == NULL)
- return NULL;
- pNV->v.nestVal = NULL;
- pNV->valType = OPARG_TYPE_HIERARCHY;
- pNV->pzName = (char*)(pNV + 1);
- memcpy( pNV->pzName, pzName, nameLen );
- pNV->pzName[ nameLen ] = NUL;
-
- } else {
- pNV = optionLoadNested( pzValue, pzName, nameLen );
- }
-
- if (pNV != NULL)
- addArgListEntry( pp, pNV );
-
- return pNV;
-}
-
-
-/* scanNameEntry
- *
- * We have an entry that starts with a name. Find the end of it, cook it
- * (if called for) and create the name/value association.
- */
-static char const*
-scanNameEntry(char const* pzName, tOptionValue* pRes)
-{
- tOptionValue* pNV;
- char const * pzScan = pzName+1; /* we know first char is a name char */
- char const * pzVal;
- size_t nameLen = 1;
- size_t dataLen = 0;
-
- /*
- * Scan over characters that name a value. These names may not end
- * with a colon, but they may contain colons.
- */
- while (IS_VALUE_NAME_CHAR(*pzScan)) { pzScan++; nameLen++; }
- if (pzScan[-1] == ':') { pzScan--; nameLen--; }
- while (IS_HORIZ_WHITE_CHAR(*pzScan)) pzScan++;
-
-re_switch:
- switch (*pzScan) {
- case '=':
- case ':':
- while (IS_HORIZ_WHITE_CHAR( (int)*++pzScan )) ;
- if ((*pzScan == '=') || (*pzScan == ':'))
- goto default_char;
- goto re_switch;
-
- case '\n':
- case ',':
- pzScan++;
- /* FALLTHROUGH */
-
- case NUL:
- addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0);
- break;
-
- case '"':
- case '\'':
- pzVal = pzScan;
- pzScan = scanQuotedString( pzScan );
- dataLen = pzScan - pzVal;
- pNV = addStringValue( &(pRes->v.nestVal), pzName, nameLen, pzVal,
- dataLen );
- if ((pNV != NULL) && (option_load_mode == OPTION_LOAD_COOKED))
- ao_string_cook( pNV->v.strVal, NULL );
- break;
-
- default:
- default_char:
- /*
- * We have found some strange text value. It ends with a newline
- * or a comma.
- */
- pzVal = pzScan;
- for (;;) {
- char ch = *(pzScan++);
- switch (ch) {
- case NUL:
- pzScan--;
- dataLen = pzScan - pzVal;
- goto string_done;
- /* FALLTHROUGH */
-
- case '\n':
- if ( (pzScan > pzVal + 2)
- && (pzScan[-2] == '\\')
- && (pzScan[ 0] != NUL))
- continue;
- /* FALLTHROUGH */
-
- case ',':
- dataLen = (pzScan - pzVal) - 1;
- string_done:
- pNV = addStringValue( &(pRes->v.nestVal), pzName, nameLen,
- pzVal, dataLen );
- if (pNV != NULL)
- removeLineContinue( pNV->v.strVal );
- goto leave_scan_name;
- }
- }
- break;
- } leave_scan_name:;
-
- return pzScan;
-}
-
-
-/* scanXmlEntry
- *
- * We've found a '<' character. We ignore this if it is a comment or a
- * directive. If it is something else, then whatever it is we are looking
- * at is bogus. Returning NULL stops processing.
- */
-static char const*
-scanXmlEntry( char const* pzName, tOptionValue* pRes )
-{
- size_t nameLen = 1, valLen = 0;
- char const* pzScan = ++pzName;
- char const* pzVal;
- tOptionValue valu;
- tOptionValue* pNewVal;
- tOptionLoadMode save_mode = option_load_mode;
-
- if (! IS_VAR_FIRST_CHAR(*pzName)) {
- switch (*pzName) {
- default:
- pzName = NULL;
- break;
-
- case '!':
- pzName = strstr( pzName, "-->" );
- if (pzName != NULL)
- pzName += 3;
- break;
-
- case '?':
- pzName = strchr( pzName, '>' );
- if (pzName != NULL)
- pzName++;
- break;
- }
- return pzName;
- }
-
- pzScan++;
- while (IS_VALUE_NAME_CHAR( (int)*pzScan )) { pzScan++; nameLen++; }
- if (nameLen > 64)
- return NULL;
- valu.valType = OPARG_TYPE_STRING;
-
- switch (*pzScan) {
- case ' ':
- case '\t':
- pzScan = parseAttributes(
- NULL, (char*)pzScan, &option_load_mode, &valu );
- if (*pzScan == '>') {
- pzScan++;
- break;
- }
-
- if (*pzScan != '/') {
- option_load_mode = save_mode;
- return NULL;
- }
- /* FALLTHROUGH */
-
- case '/':
- if (*++pzScan != '>') {
- option_load_mode = save_mode;
- return NULL;
- }
- addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0);
- option_load_mode = save_mode;
- return pzScan+1;
-
- default:
- option_load_mode = save_mode;
- return NULL;
-
- case '>':
- pzScan++;
- break;
- }
-
- pzVal = pzScan;
-
- {
- char z[68];
- char* pzD = z;
- int ct = nameLen;
- char const* pzS = pzName;
-
- *(pzD++) = '<';
- *(pzD++) = '/';
-
- do {
- *(pzD++) = *(pzS++);
- } while (--ct > 0);
- *(pzD++) = '>';
- *pzD = NUL;
-
- pzScan = strstr( pzScan, z );
- if (pzScan == NULL) {
- option_load_mode = save_mode;
- return NULL;
- }
- valLen = (pzScan - pzVal);
- pzScan += nameLen + 3;
- while (IS_WHITESPACE_CHAR(*pzScan)) pzScan++;
- }
-
- switch (valu.valType) {
- case OPARG_TYPE_NONE:
- addStringValue( &(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0);
- break;
-
- case OPARG_TYPE_STRING:
- pNewVal = addStringValue(
- &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen);
-
- if (option_load_mode == OPTION_LOAD_KEEP)
- break;
- mungeString( pNewVal->v.strVal, option_load_mode );
- break;
-
- case OPARG_TYPE_BOOLEAN:
- addBoolValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen );
- break;
-
- case OPARG_TYPE_NUMERIC:
- addNumberValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen );
- break;
-
- case OPARG_TYPE_HIERARCHY:
- {
- char* pz = AGALOC( valLen+1, "hierarchical scan" );
- if (pz == NULL)
- break;
- memcpy( pz, pzVal, valLen );
- pz[valLen] = NUL;
- addNestedValue( &(pRes->v.nestVal), pzName, nameLen, pz, valLen );
- AGFREE(pz);
- break;
- }
-
- case OPARG_TYPE_ENUMERATION:
- case OPARG_TYPE_MEMBERSHIP:
- default:
- break;
- }
-
- option_load_mode = save_mode;
- return pzScan;
-}
-
-
-/* unloadNestedArglist
- *
- * Deallocate a list of option arguments. This must have been gotten from
- * a hierarchical option argument, not a stacked list of strings. It is
- * an internal call, so it is not validated. The caller is responsible for
- * knowing what they are doing.
- */
-static void
-unloadNestedArglist( tArgList* pAL )
-{
- int ct = pAL->useCt;
- tCC** ppNV = pAL->apzArgs;
-
- while (ct-- > 0) {
- tOptionValue* pNV = (tOptionValue*)(void*)*(ppNV++);
- if (pNV->valType == OPARG_TYPE_HIERARCHY)
- unloadNestedArglist( pNV->v.nestVal );
- AGFREE( pNV );
- }
-
- AGFREE( (void*)pAL );
-}
-
-
-/*=export_func optionUnloadNested
- *
- * what: Deallocate the memory for a nested value
- * arg: + tOptionValue const * + pOptVal + the hierarchical value +
- *
- * doc:
- * A nested value needs to be deallocated. The pointer passed in should
- * have been gotten from a call to @code{configFileLoad()} (See
- * @pxref{libopts-configFileLoad}).
-=*/
-void
-optionUnloadNested( tOptionValue const * pOV )
-{
- if (pOV == NULL) return;
- if (pOV->valType != OPARG_TYPE_HIERARCHY) {
- errno = EINVAL;
- return;
- }
-
- unloadNestedArglist( pOV->v.nestVal );
-
- AGFREE( (void*)pOV );
-}
-
-
-/* sortNestedList
- *
- * This is a _stable_ sort. The entries are sorted alphabetically,
- * but within entries of the same name the ordering is unchanged.
- * Typically, we also hope the input is sorted.
- */
-static void
-sortNestedList( tArgList* pAL )
-{
- int ix;
- int lm = pAL->useCt;
-
- /*
- * This loop iterates "useCt" - 1 times.
- */
- for (ix = 0; ++ix < lm;) {
- int iy = ix-1;
- tOptionValue* pNewNV = (tOptionValue*)(void*)(pAL->apzArgs[ix]);
- tOptionValue* pOldNV = (tOptionValue*)(void*)(pAL->apzArgs[iy]);
-
- /*
- * For as long as the new entry precedes the "old" entry,
- * move the old pointer. Stop before trying to extract the
- * "-1" entry.
- */
- while (strcmp( pOldNV->pzName, pNewNV->pzName ) > 0) {
- pAL->apzArgs[iy+1] = (void*)pOldNV;
- pOldNV = (tOptionValue*)(void*)(pAL->apzArgs[--iy]);
- if (iy < 0)
- break;
- }
-
- /*
- * Always store the pointer. Sometimes it is redundant,
- * but the redundancy is cheaper than a test and branch sequence.
- */
- pAL->apzArgs[iy+1] = (void*)pNewNV;
- }
-}
-
-
-/* optionLoadNested
- * private:
- *
- * what: parse a hierarchical option argument
- * arg: + char const* + pzTxt + the text to scan +
- * arg: + char const* + pzName + the name for the text +
- * arg: + size_t + nameLen + the length of "name" +
- *
- * ret_type: tOptionValue*
- * ret_desc: An allocated, compound value structure
- *
- * doc:
- * A block of text represents a series of values. It may be an
- * entire configuration file, or it may be an argument to an
- * option that takes a hierarchical value.
- */
-LOCAL tOptionValue*
-optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen)
-{
- tOptionValue* pRes;
- tArgList* pAL;
-
- /*
- * Make sure we have some data and we have space to put what we find.
- */
- if (pzTxt == NULL) {
- errno = EINVAL;
- return NULL;
- }
- while (IS_WHITESPACE_CHAR(*pzTxt)) pzTxt++;
- if (*pzTxt == NUL) {
- errno = ENOENT;
- return NULL;
- }
- pRes = AGALOC( sizeof(*pRes) + nameLen + 1, "nested args" );
- if (pRes == NULL) {
- errno = ENOMEM;
- return NULL;
- }
- pRes->valType = OPARG_TYPE_HIERARCHY;
- pRes->pzName = (char*)(pRes + 1);
- memcpy( pRes->pzName, pzName, nameLen );
- pRes->pzName[ nameLen ] = NUL;
-
- pAL = AGALOC( sizeof(*pAL), "nested arg list" );
- if (pAL == NULL) {
- AGFREE( pRes );
- return NULL;
- }
- pRes->v.nestVal = pAL;
- pAL->useCt = 0;
- pAL->allocCt = MIN_ARG_ALLOC_CT;
-
- /*
- * Scan until we hit a NUL.
- */
- do {
- while (IS_WHITESPACE_CHAR( (int)*pzTxt )) pzTxt++;
- if (IS_VAR_FIRST_CHAR( (int)*pzTxt )) {
- pzTxt = scanNameEntry( pzTxt, pRes );
- }
- else switch (*pzTxt) {
- case NUL: goto scan_done;
- case '<': pzTxt = scanXmlEntry( pzTxt, pRes );
- if (pzTxt == NULL) goto woops;
- if (*pzTxt == ',') pzTxt++; break;
- case '#': pzTxt = strchr( pzTxt, '\n' ); break;
- default: goto woops;
- }
- } while (pzTxt != NULL); scan_done:;
-
- pAL = pRes->v.nestVal;
- if (pAL->useCt != 0) {
- sortNestedList( pAL );
- return pRes;
- }
-
- woops:
- AGFREE( pRes->v.nestVal );
- AGFREE( pRes );
- return NULL;
-}
-
-
-/*=export_func optionNestedVal
- * private:
- *
- * what: parse a hierarchical option argument
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Nested value was found on the command line
-=*/
-void
-optionNestedVal(tOptions* pOpts, tOptDesc* pOD)
-{
- if (pOpts < OPTPROC_EMIT_LIMIT)
- return;
-
- if (pOD->fOptState & OPTST_RESET) {
- tArgList* pAL = pOD->optCookie;
- int ct;
- tCC ** av;
-
- if (pAL == NULL)
- return;
- ct = pAL->useCt;
- av = pAL->apzArgs;
-
- while (--ct >= 0) {
- void * p = (void *)*(av++);
- optionUnloadNested((tOptionValue const *)p);
- }
-
- AGFREE(pOD->optCookie);
-
- } else {
- tOptionValue* pOV = optionLoadNested(
- pOD->optArg.argString, pOD->pz_Name, strlen(pOD->pz_Name));
-
- if (pOV != NULL)
- addArgListEntry( &(pOD->optCookie), (void*)pOV );
- }
-}
-
-
-/*
- * get_special_char
- */
-LOCAL int
-get_special_char(char const ** ppz, int * ct)
-{
- char const * pz = *ppz;
-
- if (*ct < 3)
- return '&';
-
- if (*pz == '#') {
- int base = 10;
- int retch;
-
- pz++;
- if (*pz == 'x') {
- base = 16;
- pz++;
- }
- retch = (int)strtoul(pz, (char **)&pz, base);
- if (*pz != ';')
- return '&';
- base = ++pz - *ppz;
- if (base > *ct)
- return '&';
-
- *ct -= base;
- *ppz = pz;
- return retch;
- }
-
- {
- int ctr = sizeof(xml_xlate) / sizeof(xml_xlate[0]);
- xml_xlate_t const * xlatp = xml_xlate;
-
- for (;;) {
- if ( (*ct >= xlatp->xml_len)
- && (strncmp(pz, xlatp->xml_txt, xlatp->xml_len) == 0)) {
- *ppz += xlatp->xml_len;
- *ct -= xlatp->xml_len;
- return xlatp->xml_ch;
- }
-
- if (--ctr <= 0)
- break;
- xlatp++;
- }
- }
- return '&';
-}
-
-
-/*
- * emit_special_char
- */
-LOCAL void
-emit_special_char(FILE * fp, int ch)
-{
- int ctr = sizeof(xml_xlate) / sizeof(xml_xlate[0]);
- xml_xlate_t const * xlatp = xml_xlate;
-
- putc('&', fp);
- for (;;) {
- if (ch == xlatp->xml_ch) {
- fputs(xlatp->xml_txt, fp);
- return;
- }
- if (--ctr <= 0)
- break;
- xlatp++;
- }
- fprintf(fp, "#x%02X;", (ch & 0xFF));
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/nested.c */
+++ /dev/null
-
-/*
- * $Id: numeric.c,v 4.23 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2009-07-23 17:25:39 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 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
- */
-
-/*=export_func optionShowRange
- * private:
- *
- * what:
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- * arg: + void * + rng_table + the value range tables +
- * arg: + int + rng_count + the number of entries +
- *
- * doc:
- * Show information about a numeric option with range constraints.
-=*/
-void
-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;
-
- 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 */
- }
-
- 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 (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 +
- *
- * doc:
- * Decipher a numeric value.
-=*/
-void
-optionNumericVal(tOptions* pOpts, tOptDesc* pOD )
-{
- char* pz;
- long val;
-
- /*
- * 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
- * if there is no option argument or if we are being reset.
- */
- if ( (pOD == NULL)
- || (pOD->optArg.argString == NULL)
- || ((pOD->fOptState & OPTST_RESET) != 0))
- return;
-
- errno = 0;
- val = strtol(pOD->optArg.argString, &pz, 0);
- if ((pz == pOD->optArg.argString) || (errno != 0))
- goto bad_number;
-
- if ((pOD->fOptState & OPTST_SCALED_NUM) != 0)
- switch (*(pz++)) {
- case '\0': pz--; break;
- case 't': val *= 1000;
- case 'g': val *= 1000;
- case 'm': val *= 1000;
- case 'k': val *= 1000; break;
-
- case 'T': val *= 1024;
- case 'G': val *= 1024;
- case 'M': val *= 1024;
- case 'K': val *= 1024; break;
-
- default: goto bad_number;
- }
-
- if (*pz != NUL)
- goto bad_number;
-
- if (pOD->fOptState & OPTST_ALLOC_ARG) {
- AGFREE(pOD->optArg.argString);
- pOD->fOptState &= ~OPTST_ALLOC_ARG;
- }
-
- pOD->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);
-
- pOD->optArg.argInt = ~0;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/numeric.c */
+++ /dev/null
-/* Parse a time duration and return a seconds count
- Copyright (C) 2008 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
- (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/>. */
-
-#include <config.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "parse-duration.h"
-
-#ifndef _
-#define _(_s) _s
-#endif
-
-#ifndef NUL
-#define NUL '\0'
-#endif
-
-#define cch_t char const
-
-typedef enum {
- NOTHING_IS_DONE,
- YEAR_IS_DONE,
- MONTH_IS_DONE,
- WEEK_IS_DONE,
- DAY_IS_DONE,
- HOUR_IS_DONE,
- MINUTE_IS_DONE,
- SECOND_IS_DONE
-} whats_done_t;
-
-#define SEC_PER_MIN 60
-#define SEC_PER_HR (SEC_PER_MIN * 60)
-#define SEC_PER_DAY (SEC_PER_HR * 24)
-#define SEC_PER_WEEK (SEC_PER_DAY * 7)
-#define SEC_PER_MONTH (SEC_PER_DAY * 30)
-#define SEC_PER_YEAR (SEC_PER_DAY * 365)
-
-#define TIME_MAX 0x7FFFFFFF
-
-static unsigned long inline
-str_const_to_ul (cch_t * str, cch_t ** ppz, int base)
-{
- return strtoul (str, (char **)ppz, base);
-}
-
-static long inline
-str_const_to_l (cch_t * str, cch_t ** ppz, int base)
-{
- return strtol (str, (char **)ppz, base);
-}
-
-static time_t inline
-scale_n_add (time_t base, time_t val, int scale)
-{
- if (base == BAD_TIME)
- {
- if (errno == 0)
- errno = EINVAL;
- return BAD_TIME;
- }
-
- if (val > TIME_MAX / scale)
- {
- errno = ERANGE;
- return BAD_TIME;
- }
-
- val *= scale;
- if (base > TIME_MAX - val)
- {
- errno = ERANGE;
- return BAD_TIME;
- }
-
- return base + val;
-}
-
-static time_t
-parse_hr_min_sec (time_t start, cch_t * pz)
-{
- int lpct = 0;
-
- errno = 0;
-
- /* For as long as our scanner pointer points to a colon *AND*
- we've not looped before, then keep looping. (two iterations max) */
- while ((*pz == ':') && (lpct++ <= 1))
- {
- unsigned long v = str_const_to_ul (pz+1, &pz, 10);
-
- if (errno != 0)
- return BAD_TIME;
-
- start = scale_n_add (v, start, 60);
-
- if (errno != 0)
- return BAD_TIME;
- }
-
- /* allow for trailing spaces */
- while (isspace ((unsigned char)*pz)) pz++;
- if (*pz != NUL)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- return start;
-}
-
-static time_t
-parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale)
-{
- cch_t * pz = *ppz;
- time_t val;
-
- if (base == BAD_TIME)
- return base;
-
- errno = 0;
- val = str_const_to_ul (pz, &pz, 10);
- if (errno != 0)
- return BAD_TIME;
- while (isspace ((unsigned char)*pz)) pz++;
- if (pz != endp)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- *ppz = pz;
- return scale_n_add (base, val, scale);
-}
-
-static time_t
-parse_year_month_day (cch_t * pz, cch_t * ps)
-{
- time_t res = 0;
-
- res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
-
- ps = strchr (++pz, '-');
- if (ps == NULL)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
- res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);
-
- pz++;
- ps = pz + strlen (pz);
- return parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
-}
-
-static time_t
-parse_yearmonthday (cch_t * in_pz)
-{
- time_t res = 0;
- char buf[8];
- cch_t * pz;
-
- if (strlen (in_pz) != 8)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- memcpy (buf, in_pz, 4);
- buf[4] = NUL;
- pz = buf;
- res = parse_scaled_value (0, &pz, buf + 4, SEC_PER_YEAR);
-
- memcpy (buf, in_pz + 4, 2);
- buf[2] = NUL;
- pz = buf;
- res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MONTH);
-
- memcpy (buf, in_pz + 6, 2);
- buf[2] = NUL;
- pz = buf;
- return parse_scaled_value (res, &pz, buf + 2, SEC_PER_DAY);
-}
-
-static time_t
-parse_YMWD (cch_t * pz)
-{
- time_t res = 0;
- cch_t * ps = strchr (pz, 'Y');
- if (ps != NULL)
- {
- res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR);
- pz++;
- }
-
- ps = strchr (pz, 'M');
- if (ps != NULL)
- {
- res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH);
- pz++;
- }
-
- ps = strchr (pz, 'W');
- if (ps != NULL)
- {
- res = parse_scaled_value (res, &pz, ps, SEC_PER_WEEK);
- pz++;
- }
-
- ps = strchr (pz, 'D');
- if (ps != NULL)
- {
- res = parse_scaled_value (res, &pz, ps, SEC_PER_DAY);
- pz++;
- }
-
- while (isspace ((unsigned char)*pz)) pz++;
- if (*pz != NUL)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- return res;
-}
-
-static time_t
-parse_hour_minute_second (cch_t * pz, cch_t * ps)
-{
- time_t res = 0;
-
- res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
-
- ps = strchr (++pz, ':');
- if (ps == NULL)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN);
-
- pz++;
- ps = pz + strlen (pz);
- return parse_scaled_value (res, &pz, ps, 1);
-}
-
-static time_t
-parse_hourminutesecond (cch_t * in_pz)
-{
- time_t res = 0;
- char buf[4];
- cch_t * pz;
-
- if (strlen (in_pz) != 6)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- memcpy (buf, in_pz, 2);
- buf[2] = NUL;
- pz = buf;
- res = parse_scaled_value (0, &pz, buf + 2, SEC_PER_HR);
-
- memcpy (buf, in_pz + 2, 2);
- buf[2] = NUL;
- pz = buf;
- res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MIN);
-
- memcpy (buf, in_pz + 4, 2);
- buf[2] = NUL;
- pz = buf;
- return parse_scaled_value (res, &pz, buf + 2, 1);
-}
-
-static time_t
-parse_HMS (cch_t * pz)
-{
- time_t res = 0;
- cch_t * ps = strchr (pz, 'H');
- if (ps != NULL)
- {
- res = parse_scaled_value (0, &pz, ps, SEC_PER_HR);
- pz++;
- }
-
- ps = strchr (pz, 'M');
- if (ps != NULL)
- {
- res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN);
- pz++;
- }
-
- ps = strchr (pz, 'S');
- if (ps != NULL)
- {
- res = parse_scaled_value (res, &pz, ps, 1);
- pz++;
- }
-
- while (isspace ((unsigned char)*pz)) pz++;
- if (*pz != NUL)
- {
- errno = EINVAL;
- return BAD_TIME;
- }
-
- return res;
-}
-
-static time_t
-parse_time (cch_t * pz)
-{
- cch_t * ps;
- time_t res = 0;
-
- /*
- * Scan for a hyphen
- */
- ps = strchr (pz, ':');
- if (ps != NULL)
- {
- res = parse_hour_minute_second (pz, ps);
- }
-
- /*
- * Try for a 'H', 'M' or 'S' suffix
- */
- else if (ps = strpbrk (pz, "HMS"),
- ps == NULL)
- {
- /* Its a YYYYMMDD format: */
- res = parse_hourminutesecond (pz);
- }
-
- else
- res = parse_HMS (pz);
-
- return res;
-}
-
-static char *
-trim(char * pz)
-{
- /* trim leading white space */
- while (isspace ((unsigned char)*pz)) pz++;
-
- /* trim trailing white space */
- {
- char * pe = pz + strlen (pz);
- while ((pe > pz) && isspace ((unsigned char)pe[-1])) pe--;
- *pe = NUL;
- }
-
- return pz;
-}
-
-/*
- * Parse the year/months/days of a time period
- */
-static time_t
-parse_period (cch_t * in_pz)
-{
- char * pz = xstrdup (in_pz);
- char * pT = strchr (pz, 'T');
- char * ps;
- void * fptr = pz;
- time_t res = 0;
-
- if (pT != NUL)
- {
- *(pT++) = NUL;
- pz = trim (pz);
- pT = trim (pT);
- }
-
- /*
- * Scan for a hyphen
- */
- ps = strchr (pz, '-');
- if (ps != NULL)
- {
- res = parse_year_month_day (pz, ps);
- }
-
- /*
- * Try for a 'Y', 'M' or 'D' suffix
- */
- else if (ps = strpbrk (pz, "YMWD"),
- ps == NULL)
- {
- /* Its a YYYYMMDD format: */
- res = parse_yearmonthday (pz);
- }
-
- else
- res = parse_YMWD (pz);
-
- if ((errno == 0) && (pT != NULL))
- {
- time_t val = parse_time (pT);
- res = scale_n_add (res, val, 1);
- }
-
- free (fptr);
- return res;
-}
-
-static time_t
-parse_non_iso8601(cch_t * pz)
-{
- whats_done_t whatd_we_do = NOTHING_IS_DONE;
-
- time_t res = 0;
-
- do {
- time_t val;
-
- errno = 0;
- val = str_const_to_l (pz, &pz, 10);
- if (errno != 0)
- goto bad_time;
-
- /* IF we find a colon, then we're going to have a seconds value.
- We will not loop here any more. We cannot already have parsed
- a minute value and if we've parsed an hour value, then the result
- value has to be less than an hour. */
- if (*pz == ':')
- {
- if (whatd_we_do >= MINUTE_IS_DONE)
- break;
-
- val = parse_hr_min_sec (val, pz);
-
- if ((whatd_we_do == HOUR_IS_DONE) && (val >= SEC_PER_HR))
- break;
-
- return scale_n_add (res, val, 1);
- }
-
- {
- unsigned int mult;
-
- /* Skip over white space following the number we just parsed. */
- while (isspace ((unsigned char)*pz)) pz++;
-
- switch (*pz)
- {
- default: goto bad_time;
- case NUL:
- return scale_n_add (res, val, 1);
-
- case 'y': case 'Y':
- if (whatd_we_do >= YEAR_IS_DONE)
- goto bad_time;
- mult = SEC_PER_YEAR;
- whatd_we_do = YEAR_IS_DONE;
- break;
-
- case 'M':
- if (whatd_we_do >= MONTH_IS_DONE)
- goto bad_time;
- mult = SEC_PER_MONTH;
- whatd_we_do = MONTH_IS_DONE;
- break;
-
- case 'W':
- if (whatd_we_do >= WEEK_IS_DONE)
- goto bad_time;
- mult = SEC_PER_WEEK;
- whatd_we_do = WEEK_IS_DONE;
- break;
-
- case 'd': case 'D':
- if (whatd_we_do >= DAY_IS_DONE)
- goto bad_time;
- mult = SEC_PER_DAY;
- whatd_we_do = DAY_IS_DONE;
- break;
-
- case 'h':
- if (whatd_we_do >= HOUR_IS_DONE)
- goto bad_time;
- mult = SEC_PER_HR;
- whatd_we_do = HOUR_IS_DONE;
- break;
-
- case 'm':
- if (whatd_we_do >= MINUTE_IS_DONE)
- goto bad_time;
- mult = SEC_PER_MIN;
- whatd_we_do = MINUTE_IS_DONE;
- break;
-
- case 's':
- mult = 1;
- whatd_we_do = SECOND_IS_DONE;
- break;
- }
-
- res = scale_n_add (res, val, mult);
-
- while (isspace ((unsigned char)*++pz)) ;
- if (*pz == NUL)
- return res;
-
- if (! isdigit ((unsigned char)*pz))
- break;
- }
-
- } while (whatd_we_do < SECOND_IS_DONE);
-
- bad_time:
- errno = EINVAL;
- return BAD_TIME;
-}
-
-time_t
-parse_duration (char const * pz)
-{
- time_t res = 0;
-
- 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;
-
- res = parse_non_iso8601 (pz);
- if ((errno == 0) && (res != BAD_TIME))
- return res;
-
- } while (0);
-
- fprintf (stderr, _("Invalid time duration: %s\n"), pz);
- if (errno == 0)
- errno = EINVAL;
- return BAD_TIME;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "gnu"
- * indent-tabs-mode: nil
- * End:
- * end of parse-duration.c */
+++ /dev/null
-/* Parse a time duration and return a seconds count
- Copyright (C) 2008 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
- (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/>. */
-
-/*
-
- Readers and users of this function are referred to the ISO-8601
- specification, with particular attention to "Durations".
-
- At the time of writing, this worked:
-
- http://en.wikipedia.org/wiki/ISO_8601#Durations
-
- The string must start with a 'P', 'T' or a digit.
-
- ==== 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.
- These terms must appear in this order.
- The final "s" is optional.
- All of the terms ("NNN" plus designator) are optional.
- Minutes and seconds may optionally be represented as NNN:NNN.
- Also, hours, minute and seconds may be represented as NNN:NNN:NNN.
- There is no limitation on the value of any of the terms, except
- that the final result must fit in a time_t value.
-
- ==== if it is a 'P' or 'T', please see ISO-8601 for a rigorous definition.
-
- The 'P' term may be followed by any of three formats:
- yyyymmdd
- yy-mm-dd
- 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
- for how many days are in the current, next or previous months.
-
- For the final format:
- * Embedded white space is allowed, but it is optional.
- * All of the terms are optional. Any or all-but-one may be omitted.
- * The meanings are yy years, mm months, ww weeks and dd days.
- * The terms must appear in this order.
-
- ==== The 'T' term may be followed by any of these formats:
-
- hhmmss
- hh:mm:ss
- hh H mm M ss S
-
- For the final format:
- * Embedded white space is allowed, but it is optional.
- * All of the terms are optional. Any or all-but-one may be omitted.
- * The terms must appear in this order.
-
- */
-#ifndef GNULIB_PARSE_DURATION_H
-#define GNULIB_PARSE_DURATION_H
-
-#include <time.h>
-
-#define BAD_TIME ((time_t)~0)
-
-extern time_t parse_duration(char const * in_pz);
-
-#endif /* GNULIB_PARSE_DURATION_H */
+++ /dev/null
-
-/*
- * $Id: pgusage.c,v 4.18 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-07-27 21:08:42 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
- */
-
-tePagerState pagerState = PAGER_STATE_INITIAL;
-
-/*=export_func optionPagedUsage
- * private:
- *
- * what: Decipher a boolean value
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Run the usage output through a pager.
- * This is very handy if it is very long.
-=*/
-void
-optionPagedUsage( tOptions* pOptions, tOptDesc* pOD )
-{
-#if defined(__windows__) && !defined(__CYGWIN__)
- if ((pOD->fOptState & OPTST_RESET) != 0)
- return;
-
- (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS );
-#else
- static pid_t my_pid;
- char zPageUsage[ 1024 ];
-
- /*
- * IF we are being called after the usage proc is done
- * (and thus has called "exit(2)")
- * THEN invoke the pager to page through the usage file we created.
- */
- switch (pagerState) {
- case PAGER_STATE_INITIAL:
- {
- if ((pOD->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 );
- if (option_usage_fp == NULL)
- _exit( EXIT_FAILURE );
-
- pagerState = PAGER_STATE_READY;
-
- /*
- * Set up so this routine gets called during the exit logic
- */
- atexit( (void(*)(void))optionPagedUsage );
-
- /*
- * The usage procedure will now put the usage information into
- * the temporary file we created above.
- */
- (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS );
-
- /*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" );
-
- /*
- * Use the "more(1)" program if "PAGER" has not been defined
- */
- if (pzPager == NULL)
- pzPager = "more";
-
- /*
- * 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 );
-
- (void)system( zPageUsage );
- }
-
- case PAGER_STATE_CHILD:
- /*
- * This is a child process used in creating shell script usage.
- */
- break;
- }
-#endif
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/pgusage.c */
+++ /dev/null
-/* -*- buffer-read-only: t -*- vi: set ro:
- *
- * Prototypes for autoopts
- * Generated Sat Aug 1 11:21:12 PDT 2009
- */
-#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 autoopts.c
- */
-LOCAL void *
-ao_malloc( size_t sz );
-
-LOCAL void *
-ao_realloc( void *p, size_t sz );
-
-LOCAL void
-ao_free( void *p );
-
-LOCAL char *
-ao_strdup( char const *str );
-
-LOCAL tSuccess
-handleOption( tOptions* pOpts, tOptState* pOptState );
-
-LOCAL tSuccess
-longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState );
-
-LOCAL tSuccess
-shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState );
-
-LOCAL tSuccess
-doImmediateOpts( tOptions* pOpts );
-
-LOCAL tSuccess
-doRegularOpts( tOptions* pOpts );
-
-/*
- * Extracted from configfile.c
- */
-LOCAL void
-internalFileLoad( tOptions* pOpts );
-
-LOCAL char*
-parseAttributes(
- tOptions* pOpts,
- char* pzText,
- tOptionLoadMode* pMode,
- tOptionValue* pType );
-
-LOCAL tSuccess
-validateOptionsStruct( tOptions* pOpts, char const* pzProgram );
-
-/*
- * Extracted from environment.c
- */
-LOCAL void
-doPrognameEnv( tOptions* pOpts, teEnvPresetType type );
-
-LOCAL void
-doEnvPresets( tOptions* pOpts, teEnvPresetType type );
-
-/*
- * Extracted from load.c
- */
-LOCAL void
-mungeString( char* pzTxt, tOptionLoadMode mode );
-
-LOCAL void
-loadOptionLine(
- tOptions* pOpts,
- tOptState* pOS,
- char* pzLine,
- tDirection direction,
- tOptionLoadMode load_mode );
-
-/*
- * Extracted from nested.c
- */
-LOCAL tOptionValue*
-optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen);
-
-LOCAL int
-get_special_char(char const ** ppz, int * ct);
-
-LOCAL void
-emit_special_char(FILE * fp, int ch);
-
-/*
- * Extracted from sort.c
- */
-LOCAL void
-optionSort( tOptions* pOpts );
-
-/*
- * Extracted from stack.c
- */
-LOCAL void
-addArgListEntry( void** ppAL, void* entry );
-
-#ifdef REDEF_LOCAL
-# undef LOCAL
-# define LOCAL
-#endif
-#endif /* AUTOOPTS_PROTO_H_GUARD */
+++ /dev/null
-
-/*
- * $Id: putshell.c,v 4.27 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-07-27 12:14:38 bkorb"
- *
- * 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.
- *
- * 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
- */
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static void
-putQuotedStr( tCC* pzStr );
-/* = = = 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.
- */
-static void
-putQuotedStr( tCC* pzStr )
-{
- /*
- * Handle empty strings to make the rest of the logic simpler.
- */
- if ((pzStr == NULL) || (*pzStr == NUL)) {
- fputs( "''", stdout );
- return;
- }
-
- /*
- * 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)
- return;
-
- /*
- * Start the single quote string
- */
- fputc( '\'', stdout );
- for (;;) {
- tCC* pz = strchr( pzStr, '\'' );
- 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;
-
- /*
- * Emit an escaped apostrophe for every one we find.
- * If that ends the string, do not re-open the single quotes.
- */
- while (*++pzStr == '\'') fputs( "\\'", stdout );
- if (*pzStr == NUL)
- return;
-
- fputc( '\'', 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 );
-}
-
-
-/*=export_func optionPutShell
- * what: write a portable shell script to parse options
- * private:
- * arg: tOptions*, pOpts, the program options descriptor
- * doc: This routine will emit portable shell script text for parsing
- * the options described in the option definitions.
-=*/
-void
-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 );
-
- do {
- tOptDesc* pOD = pOpts->pOptDesc + optIx;
-
- if (SKIP_OPT(pOD))
- continue;
-
- /*
- * Equivalence classes are hard to deal with. Where the
- * option data wind up kind of squishes around. For the purposes
- * of emitting shell state, they are not recommended, but we'll
- * do something. I guess we'll emit the equivalenced-to option
- * at the point in time when the base option is found.
- */
- if (pOD->optEquivIndex != NO_EQUIVALENT)
- continue; /* equivalence to a different option */
-
- /*
- * Equivalenced to a different option. Process the current option
- * as the equivalenced-to option. Keep the persistent state bits,
- * but copy over the set-state bits.
- */
- if (pOD->optActualIndex != optIx) {
- tOptDesc* p = pOpts->pOptDesc + pOD->optActualIndex;
- 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 );
- pOD = p;
- }
-
- /*
- * If the argument type is a set membership bitmask, then we always
- * emit the thing. We do this because it will always have some sort
- * 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;
- continue;
- }
-
- /*
- * IF the option was either specified or it wakes up enabled,
- * then we will emit information. Otherwise, skip it.
- * 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 ))
- continue;
-
- /*
- * Handle stacked arguments
- */
- 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 );
- }
- }
-
- /*
- * 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 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 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 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 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) )
-
- printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME,
- pOD->optOccCt );
-
- /*
- * 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 );
- }
- } 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 );
- }
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/putshell.c */
+++ /dev/null
-
-/*
- * $Id: reset.c,v 4.4 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-08-02 12:25:18 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 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
- */
-
-static void
-optionReset( tOptions* pOpts, tOptDesc* pOD )
-{
- pOD->fOptState &= OPTST_PERSISTENT_MASK;
- pOD->fOptState |= OPTST_RESET;
- if (pOD->pOptProc != NULL)
- pOD->pOptProc(pOpts, pOD);
- pOD->optArg.argString =
- pOpts->originalOptArgArray[ pOD->optIndex ].argString;
- pOD->optCookie = pOpts->originalOptArgCookie[ pOD->optIndex ];
- pOD->fOptState &= OPTST_PERSISTENT_MASK;
-}
-
-
-static void
-optionResetEverything(tOptions * pOpts)
-{
- tOptDesc * pOD = pOpts->pOptDesc;
- int ct = pOpts->presetOptCt;
-
- for (;;) {
- optionReset(pOpts, pOD);
-
- if (--ct <= 0)
- break;
- pOD++;
- }
-}
-
-
-/*=export_func optionResetOpt
- * private:
- *
- * what: Reset the value of an option
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * This code will cause another option to be reset to its initial state.
- * For example, --reset=foo will cause the --foo option to be reset.
-=*/
-void
-optionResetOpt( tOptions* pOpts, tOptDesc* pOD )
-{
- static ag_bool reset_active = AG_FALSE;
-
- tOptState opt_state = OPTSTATE_INITIALIZER(DEFINED);
- char const * pzArg = pOD->optArg.argString;
- tSuccess succ;
-
- if (reset_active)
- return;
-
- if ( (! HAS_originalOptArgArray(pOpts))
- || (pOpts->originalOptArgCookie == NULL)) {
- fputs(zResetNotConfig, stderr);
- _exit(EX_SOFTWARE);
- }
-
- if ((pzArg == NULL) || (*pzArg == NUL)) {
- fputs(zNoResetArg, stderr);
- pOpts->pUsageProc(pOpts, EXIT_FAILURE);
- }
-
- reset_active = AG_TRUE;
-
- if (pzArg[1] == NUL) {
- if (*pzArg == '*') {
- optionResetEverything(pOpts);
- reset_active = AG_FALSE;
- return;
- }
-
- succ = shortOptionFind(pOpts, (tAoUC)*pzArg, &opt_state);
- if (! SUCCESSFUL(succ)) {
- fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg);
- pOpts->pUsageProc(pOpts, EXIT_FAILURE);
- }
- } else {
- succ = longOptionFind(pOpts, (char *)pzArg, &opt_state);
- if (! SUCCESSFUL(succ)) {
- fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg);
- pOpts->pUsageProc(pOpts, EXIT_FAILURE);
- }
- }
-
- /*
- * We've found the indicated option. Turn off all non-persistent
- * flags because we're forcing the option back to its initialized state.
- * Call any callout procedure to handle whatever it needs to.
- * Finally, clear the reset flag, too.
- */
- optionReset(pOpts, opt_state.pOD);
- reset_active = AG_FALSE;
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/reset.c */
+++ /dev/null
-
-/*
- * restore.c $Id: restore.c,v 4.15 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2007-07-04 11:34:40 bkorb"
- *
- * 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.
- *
- * 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
- */
-
-/*
- * optionFixupSavedOpts Really, it just wipes out option state for
- * options that are troublesome to copy. viz., stacked strings and
- * hierarcicaly valued option args. We do duplicate string args that
- * have been marked as allocated though.
- */
-static void
-fixupSavedOptionArgs(tOptions* pOpts)
-{
- tOptions* p = pOpts->pSavedState;
- tOptDesc* pOD = pOpts->pOptDesc;
- int ct = pOpts->optCt;
-
- /*
- * Make sure that allocated stuff is only referenced in the
- * archived copy of the data.
- */
- for (; ct-- > 0; pOD++) {
- switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
- case OPARG_TYPE_STRING:
- if (pOD->fOptState & OPTST_STACKED) {
- tOptDesc* q = p->pOptDesc + (pOD - pOpts->pOptDesc);
- q->optCookie = NULL;
- }
- if (pOD->fOptState & OPTST_ALLOC_ARG) {
- tOptDesc* q = p->pOptDesc + (pOD - pOpts->pOptDesc);
- AGDUPSTR(q->optArg.argString, pOD->optArg.argString, "arg");
- }
- break;
-
- case OPARG_TYPE_HIERARCHY:
- {
- tOptDesc* q = p->pOptDesc + (pOD - pOpts->pOptDesc);
- q->optCookie = NULL;
- }
- }
- }
-}
-
-/*=export_func optionSaveState
- *
- * what: saves the option state to memory
- * arg: tOptions*, pOpts, program options descriptor
- *
- * doc:
- *
- * This routine will allocate enough memory to save the current option
- * processing state. If this routine has been called before, that memory
- * will be reused. You may only save one copy of the option state. This
- * routine may be called before optionProcess(3AO). If you do call it
- * before the first call to optionProcess, then you may also change the
- * contents of argc/argv after you call optionRestore(3AO)
- *
- * In fact, more strongly put: it is safest to only use this function
- * before having processed any options. In particular, the saving and
- * restoring of stacked string arguments and hierarchical values is
- * disabled. The values are not saved.
- *
- * err: If it fails to allocate the memory,
- * it will print a message to stderr and exit.
- * Otherwise, it will always succeed.
-=*/
-void
-optionSaveState(tOptions* pOpts)
-{
- 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 );
- }
-
- pOpts->pSavedState = p;
- }
-
- memcpy( p, pOpts, sizeof( *p ));
- memcpy( p + 1, pOpts->pOptDesc, p->optCt * sizeof( tOptDesc ));
-
- fixupSavedOptionArgs(pOpts);
-}
-
-
-/*=export_func optionRestore
- *
- * what: restore option state from memory copy
- * arg: tOptions*, pOpts, program options descriptor
- *
- * doc: Copy back the option state from saved memory.
- * The allocated memory is left intact, so this routine can be
- * called repeatedly without having to call optionSaveState again.
- * If you are restoring a state that was saved before the first call
- * to optionProcess(3AO), then you may change the contents of the
- * argc/argv parameters to optionProcess.
- *
- * err: If you have not called @code{optionSaveState} before, a diagnostic is
- * printed to @code{stderr} and exit is called.
-=*/
-void
-optionRestore( tOptions* pOpts )
-{
- tOptions* p = (tOptions*)pOpts->pSavedState;
-
- if (p == NULL) {
- tCC* pzName = pOpts->pzProgName;
- if (pzName == NULL) {
- pzName = pOpts->pzPROGNAME;
- if (pzName == NULL)
- pzName = zNil;
- }
- fprintf( stderr, zNoState, pzName );
- exit( EXIT_FAILURE );
- }
-
- pOpts->pSavedState = NULL;
- optionFree(pOpts);
-
- memcpy( pOpts, p, sizeof( *p ));
- memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc ));
- pOpts->pSavedState = p;
-
- fixupSavedOptionArgs(pOpts);
-}
-
-/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
-
-/*=export_func optionFree
- *
- * what: free allocated option processing memory
- * arg: tOptions*, pOpts, program options descriptor
- *
- * doc: AutoOpts sometimes allocates memory and puts pointers to it in the
- * option state structures. This routine deallocates all such memory.
- *
- * err: As long as memory has not been corrupted,
- * this routine is always successful.
-=*/
-void
-optionFree( tOptions* pOpts )
-{
- free_saved_state:
- {
- tOptDesc* p = pOpts->pOptDesc;
- int ct = pOpts->optCt;
- do {
- if (p->fOptState & OPTST_ALLOC_ARG) {
- AGFREE(p->optArg.argString);
- p->optArg.argString = NULL;
- p->fOptState &= ~OPTST_ALLOC_ARG;
- }
-
- switch (OPTST_GET_ARGTYPE(p->fOptState)) {
- case OPARG_TYPE_STRING:
-#ifdef WITH_LIBREGEX
- if ( (p->fOptState & OPTST_STACKED)
- && (p->optCookie != NULL)) {
- p->optArg.argString = ".*";
- optionUnstackArg(pOpts, p);
- }
-#else
- /* leak memory */;
-#endif
- break;
-
- case OPARG_TYPE_HIERARCHY:
- if (p->optCookie != NULL)
- unloadNestedArglist(p->optCookie);
- break;
- }
-
- p->optCookie = NULL;
- } while (p++, --ct > 0);
- }
- 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 );
- pOpts->pSavedState = NULL;
- goto free_saved_state;
- }
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/restore.c */
+++ /dev/null
-
-/*
- * save.c $Id: save.c,v 4.32 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2009-07-20 20:40:28 bkorb"
- *
- * 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.
- *
- * 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
- */
-
-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 tCC*
-findFileName( tOptions* pOpts, int* p_free_name );
-
-static void
-printEntry(
- FILE * fp,
- tOptDesc * p,
- tCC* pzLA );
-
-static void
-print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp);
-
-static void
-print_a_string(FILE * fp, char const * name, char const * pz);
-
-static void
-printValueList(FILE * fp, char const * name, tArgList * al);
-
-static void
-printHierarchy(FILE * fp, tOptDesc * p);
-
-static FILE *
-openSaveFile( tOptions* pOpts );
-
-static void
-printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD);
-
-static void
-printStringArg(FILE * fp, tOptDesc * pOD);
-
-static void
-printEnumArg(FILE * fp, tOptDesc * pOD);
-
-static void
-printSetMemberArg(FILE * fp, tOptDesc * pOD);
-
-static void
-printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts);
-/* = = = END-STATIC-FORWARD = = = */
-
-static tCC*
-findDirName( tOptions* pOpts, int* p_free )
-{
- tCC* pzDir;
-
- if ( (pOpts->specOptIdx.save_opts == NO_EQUIVALENT)
- || (pOpts->specOptIdx.save_opts == 0))
- return NULL;
-
- pzDir = pOpts->pOptDesc[ pOpts->specOptIdx.save_opts ].optArg.argString;
- if ((pzDir != NULL) && (*pzDir != NUL))
- return pzDir;
-
- /*
- * This function only works if there is a directory where
- * we can stash the RC (INI) file.
- */
- {
- tCC* const* papz = pOpts->papzHomeList;
- if (papz == NULL)
- return NULL;
-
- while (papz[1] != NULL) papz++;
- pzDir = *papz;
- }
-
- /*
- * IF it does not require deciphering an env value, then just copy it
- */
- if (*pzDir != '$')
- return pzDir;
-
- {
- tCC* 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 );
- } else {
-
- /*
- * Make sure we can get the env value (after stripping off
- * any trailing directory or file names)
- */
- pzEnv = getenv( pzDir );
- }
-
- if (pzEnv == NULL) {
- fprintf( stderr, zWarn, pOpts->pzProgName );
- fprintf( stderr, zNotDef, pzDir );
- return NULL;
- }
-
- if (pzEndDir == NULL)
- return pzEnv;
-
- {
- size_t sz = strlen( pzEnv ) + strlen( pzEndDir ) + 2;
- pzFileName = (char*)AGALOC( sz, "dir name" );
- }
-
- if (pzFileName == NULL)
- return NULL;
-
- *p_free = 1;
- /*
- * Glue together the full name into the allocated memory.
- * FIXME: We lose track of this memory.
- */
- sprintf( pzFileName, "%s/%s", pzEnv, pzEndDir );
- return pzFileName;
- }
-}
-
-
-static tCC*
-findFileName( tOptions* pOpts, int* p_free_name )
-{
- tCC* pzDir;
- struct stat stBuf;
- int free_dir_name = 0;
-
- pzDir = findDirName( pOpts, &free_dir_name );
- if (pzDir == NULL)
- return NULL;
-
- /*
- * 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 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 */
- }
- }
-
- /*
- * We got a bogus name.
- */
- fprintf( stderr, zWarn, pOpts->pzProgName );
- fprintf( stderr, zNoStat, errno, strerror( errno ), pzDir );
- if (free_dir_name)
- AGFREE( (void*)pzDir );
- return NULL;
- } while (0);
-
- /*
- * 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;
-
- {
- char* pzPath = (char*)AGALOC( sz, "file name" );
-#ifdef HAVE_SNPRINTF
- snprintf( pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName );
-#else
- sprintf( pzPath, "%s/%s", pzDir, pOpts->pzRcName );
-#endif
- if (free_dir_name)
- AGFREE( (void*)pzDir );
- pzDir = pzPath;
- free_dir_name = 1;
- }
-
- /*
- * 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 (errno != ENOENT) {
- fprintf( stderr, zWarn, pOpts->pzProgName );
- fprintf( stderr, zNoStat, errno, strerror( errno ),
- pzDir );
- AGFREE( (void*)pzDir );
- return NULL;
- }
-
- /*
- * It does not exist yet, but it will be a regular file
- */
- stBuf.st_mode = S_IFREG;
- }
- }
-
- /*
- * 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 (free_dir_name)
- AGFREE( (void*)pzDir );
- return NULL;
- }
-
- /*
- * Get rid of the old file
- */
- unlink( pzDir );
- *p_free_name = free_dir_name;
- return pzDir;
-}
-
-
-static void
-printEntry(
- FILE * fp,
- tOptDesc * p,
- tCC* pzLA )
-{
- /*
- * There is an argument. Pad the name so values line up.
- * Not disabled *OR* this got equivalenced to another opt,
- * then use current option name.
- * 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);
- }
- /*
- * 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 );
-
- else {
- fputc( ' ', fp ); fputc( ' ', fp );
- for (;;) {
- tCC* pzNl = strchr( pzLA, '\n' );
-
- /*
- * IF this is the last line
- * THEN bail and print it
- */
- if (pzNl == 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 );
- }
-
- /*
- * Terminate the entry
- */
- fputs( pzLA, fp );
- fputc( '\n', fp );
- }
-}
-
-
-static void
-print_a_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);
- break;
-
- case OPARG_TYPE_STRING:
- print_a_string(fp, ovp->pzName, ovp->v.strVal);
- break;
-
- case OPARG_TYPE_ENUMERATION:
- case OPARG_TYPE_MEMBERSHIP:
- if (pOD != NULL) {
- tAoUI 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);
-
- /*
- * 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 );
- if (pOD->optArg.argString != NULL) {
- fputs(pOD->optArg.argString, fp);
-
- if (ovp->valType != OPARG_TYPE_ENUMERATION) {
- /*
- * set membership strings get allocated
- */
- AGFREE( (void*)pOD->optArg.argString );
- }
- }
-
- pOD->optArg.argEnum = val;
- pOD->fOptState = opt_state;
- fprintf(fp, close_xml, ovp->pzName);
- break;
- }
- /* FALLTHROUGH */
-
- case OPARG_TYPE_NUMERIC:
- fprintf(fp, numb_atr, ovp->pzName, ovp->v.longVal);
- break;
-
- case OPARG_TYPE_BOOLEAN:
- fprintf(fp, bool_atr, ovp->pzName,
- ovp->v.boolVal ? "true" : "false");
- break;
-
- case OPARG_TYPE_HIERARCHY:
- printValueList(fp, ovp->pzName, ovp->v.nestVal);
- break;
- }
-}
-
-
-static void
-print_a_string(FILE * fp, char const * name, char const * pz)
-{
- static char const open_atr[] = "<%s>";
-
- fprintf(fp, open_atr, name);
- for (;;) {
- int ch = ((int)*(pz++)) & 0xFF;
-
- switch (ch) {
- case NUL: goto string_done;
-
- case '&':
- case '<':
- case '>':
-#if __GNUC__ >= 4
- case 1 ... (' ' - 1):
- case ('~' + 1) ... 0xFF:
-#endif
- emit_special_char(fp, ch);
- break;
-
- default:
-#if __GNUC__ < 4
- if ( ((ch >= 1) && (ch <= (' ' - 1)))
- || ((ch >= ('~' + 1)) && (ch <= 0xFF)) ) {
- emit_special_char(fp, ch);
- break;
- }
-#endif
- putc(ch, fp);
- }
- } string_done:;
- fprintf(fp, close_xml, name);
-}
-
-
-static void
-printValueList(FILE * fp, char const * name, tArgList * al)
-{
- static int depth = 1;
-
- int sp_ct;
- int opt_ct;
- void ** opt_list;
-
- if (al == NULL)
- return;
- opt_ct = al->useCt;
- opt_list = (void **)al->apzArgs;
-
- if (opt_ct <= 0) {
- fprintf(fp, "<%s/>\n", name);
- return;
- }
-
- fprintf(fp, "<%s type=nested>\n", name);
-
- depth++;
- while (--opt_ct >= 0) {
- tOptionValue const * ovp = *(opt_list++);
-
- print_a_value(fp, depth, NULL, ovp);
- }
- depth--;
-
- for (sp_ct = depth; --sp_ct >= 0;)
- putc(' ', fp), putc(' ', fp);
- fprintf(fp, "</%s>\n", name);
-}
-
-
-static void
-printHierarchy(FILE * fp, tOptDesc * p)
-{
- int opt_ct;
- tArgList * al = p->optCookie;
- void ** opt_list;
-
- if (al == NULL)
- return;
-
- opt_ct = al->useCt;
- opt_list = (void **)al->apzArgs;
-
- if (opt_ct <= 0)
- return;
-
- do {
- tOptionValue const * base = *(opt_list++);
- tOptionValue const * ovp = optionGetValue(base, NULL);
-
- if (ovp == NULL)
- continue;
-
- fprintf(fp, "<%s type=nested>\n", p->pz_Name);
-
- do {
- print_a_value(fp, 1, p, ovp);
-
- } while (ovp = optionNextValue(base, ovp),
- ovp != NULL);
-
- fprintf(fp, "</%s>\n", p->pz_Name);
- } while (--opt_ct > 0);
-}
-
-
-static FILE *
-openSaveFile( tOptions* pOpts )
-{
- FILE* fp;
-
- {
- int free_name = 0;
- tCC* pzFName = findFileName( pOpts, &free_name );
- if (pzFName == NULL)
- return NULL;
-
- fp = fopen( pzFName, "w" FOPEN_BINARY_FLAG );
- if (fp == NULL) {
- fprintf( stderr, zWarn, pOpts->pzProgName );
- fprintf( stderr, zNoCreat, errno, strerror( errno ), pzFName );
- if (free_name)
- AGFREE((void*) pzFName );
- return fp;
- }
-
- if (free_name)
- AGFREE( (void*)pzFName );
- }
-
- {
- char const* pz = pOpts->pzUsageTitle;
- fputs( "# ", fp );
- do { fputc( *pz, fp ); } while (*(pz++) != '\n');
- }
-
- {
- time_t timeVal = time( NULL );
- char* pzTime = ctime( &timeVal );
-
- fprintf( fp, zPresetFile, pzTime );
-#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 );
-#endif
- }
-
- return fp;
-}
-
-static void
-printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD)
-{
- /*
- * The aliased to argument indicates whether or not the option
- * is "disabled". However, the original option has the name
- * string, so we get that there, not with "p".
- */
- char const * pznm =
- (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.
- * Use the name as the string to emit.
- */
- if (pznm == NULL)
- pznm = pOD->pz_Name;
-
- fprintf(fp, "%s\n", pznm);
-}
-
-static void
-printStringArg(FILE * fp, tOptDesc * pOD)
-{
- if (pOD->fOptState & OPTST_STACKED) {
- tArgList* pAL = (tArgList*)pOD->optCookie;
- int uct = pAL->useCt;
- tCC** ppz = pAL->apzArgs;
-
- /*
- * un-disable multiple copies of disabled options.
- */
- if (uct > 1)
- pOD->fOptState &= ~OPTST_DISABLED;
-
- while (uct-- > 0)
- printEntry( fp, pOD, *(ppz++) );
- } else {
- printEntry( fp, pOD, pOD->optArg.argString );
- }
-}
-
-static void
-printEnumArg(FILE * fp, tOptDesc * pOD)
-{
- 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));
-
- pOD->optArg.argEnum = val;
-}
-
-static void
-printSetMemberArg(FILE * fp, tOptDesc * pOD)
-{
- 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;
-}
-
-static void
-printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts)
-{
- /*
- * 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);
-
- else if (HAS_originalOptArgArray(pOpts)) {
- char const * orig =
- pOpts->originalOptArgArray[pOD->optIndex].argString;
-
- if (pOD->optArg.argString == orig)
- return;
-
- printEntry(fp, pOD, pOD->optArg.argString);
- }
-}
-
-
-/*=export_func optionSaveFile
- *
- * what: saves the option state to a file
- *
- * arg: tOptions*, pOpts, program options descriptor
- *
- * doc:
- *
- * This routine will save the state of option processing to a file. The name
- * of that file can be specified with the argument to the @code{--save-opts}
- * 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.
- *
- * The recommend usage is as follows:
- * @example
- * optionProcess(&progOptions, argc, argv);
- * if (i_want_a_non_standard_place_for_this)
- * SET_OPT_SAVE_OPTS("myfilename");
- * optionSaveFile(&progOptions);
- * @end example
- *
- * err:
- *
- * If no @code{homerc} file was specified, this routine will silently return
- * and do nothing. If the output file cannot be created or updated, a message
- * will be printed to @code{stderr} and the routine will return.
-=*/
-void
-optionSaveFile( tOptions* pOpts )
-{
- tOptDesc* pOD;
- int ct;
- FILE* fp = openSaveFile(pOpts);
-
- if (fp == NULL)
- return;
-
- /*
- * FOR each of the defined options, ...
- */
- ct = pOpts->presetOptCt;
- pOD = pOpts->pOptDesc;
- do {
- tOptDesc* p;
-
- /*
- * IF the option has not been defined
- * OR it does not take an initialization value
- * OR it is equivalenced to another option
- * THEN continue (ignore it)
- *
- * Equivalenced options get picked up when the equivalenced-to
- * option is processed.
- */
- if (UNUSED_OPT( pOD ))
- continue;
-
- if ((pOD->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0)
- continue;
-
- if ( (pOD->optEquivIndex != NO_EQUIVALENT)
- && (pOD->optEquivIndex != pOD->optIndex))
- continue;
-
- /*
- * The option argument data are found at the equivalenced-to option,
- * 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;
-
- switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
- case OPARG_TYPE_NONE:
- printNoArgOpt(fp, p, pOD);
- break;
-
- case OPARG_TYPE_NUMERIC:
- printEntry( fp, p, (void*)(p->optArg.argInt));
- break;
-
- case OPARG_TYPE_STRING:
- printStringArg(fp, p);
- break;
-
- case OPARG_TYPE_ENUMERATION:
- printEnumArg(fp, p);
- break;
-
- case OPARG_TYPE_MEMBERSHIP:
- printSetMemberArg(fp, p);
- break;
-
- case OPARG_TYPE_BOOLEAN:
- printEntry( fp, p, p->optArg.argBool ? "true" : "false" );
- break;
-
- case OPARG_TYPE_HIERARCHY:
- printHierarchy(fp, p);
- break;
-
- case OPARG_TYPE_FILE:
- printFileArg(fp, p, pOpts);
- break;
-
- default:
- break; /* cannot handle - skip it */
- }
- } while ( (pOD++), (--ct > 0));
-
- fclose( fp );
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/save.c */
+++ /dev/null
-
-/*
- * sort.c $Id: sort.c,v 4.16 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2007-07-04 11:34:52 bkorb"
- *
- * This module implements argument sorting.
- *
- * 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
- */
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static tSuccess
-mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
- char** ppzOpts, int* pOptsIdx );
-
-static tSuccess
-mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
- char** ppzOpts, int* pOptsIdx );
-
-static tSuccess
-checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS,
- char** ppzOpts, int* pOptsIdx );
-/* = = = END-STATIC-FORWARD = = = */
-
-/*
- * "mustHandleArg" and "mayHandleArg" 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 )
-{
- /*
- * An option argument is required. Long options can either have
- * a separate command line argument, or an argument attached by
- * the '=' character. Figure out which.
- */
- switch (pOS->optType) {
- case TOPT_SHORT:
- /*
- * See if an arg string follows the flag character. If not,
- * the next arg must be the option argument.
- */
- if (*pzArg != NUL)
- return SUCCESS;
- break;
-
- case TOPT_LONG:
- /*
- * See if an arg string has already been assigned (glued on
- * with an `=' character). If not, the next is the opt arg.
- */
- if (pOS->pzOptArg != NULL)
- return SUCCESS;
- break;
-
- default:
- return FAILURE;
- }
- if (pOpts->curOptIdx >= pOpts->origArgCt)
- return FAILURE;
-
- ppzOpts[ (*pOptsIdx)++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
- return SUCCESS;
-}
-
-static tSuccess
-mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS,
- char** ppzOpts, int* pOptsIdx )
-{
- /*
- * An option argument is optional.
- */
- switch (pOS->optType) {
- case TOPT_SHORT:
- /*
- * IF nothing is glued on after the current flag character,
- * 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)
- return SUCCESS;
- break;
-
- case TOPT_LONG:
- /*
- * Look for an argument if we don't already have one (glued on
- * with a `=' character)
- */
- if (pOS->pzOptArg != NULL)
- return SUCCESS;
- break;
-
- default:
- return FAILURE;
- }
- if (pOpts->curOptIdx >= pOpts->origArgCt)
- return PROBLEM;
-
- pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
- if (*pzArg != '-')
- ppzOpts[ (*pOptsIdx)++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
- return SUCCESS;
-}
-
-/*
- * Process a string of short options glued together. If the last one
- * 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 )
-{
- while (*pzArg != NUL) {
- if (FAILED( shortOptionFind( pOpts, (tAoUC)*pzArg, pOS )))
- return FAILURE;
-
- /*
- * See if we can have an arg.
- */
- if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
- pzArg++;
-
- } 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)
- return SUCCESS;
-
- pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
- if (*pzArg != '-')
- ppzOpts[ (*pOptsIdx)++ ] =
- pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
- return SUCCESS;
-
- } else {
- /*
- * IF we need another argument, be sure it is there and
- * take it.
- */
- if (pzArg[1] == NUL) {
- if (pOpts->curOptIdx >= pOpts->origArgCt)
- return FAILURE;
- ppzOpts[ (*pOptsIdx)++ ] =
- pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
- }
- return SUCCESS;
- }
- }
- return SUCCESS;
-}
-
-/*
- * If the program wants sorted options (separated operands and options),
- * then this routine will to the trick.
- */
-LOCAL void
-optionSort( tOptions* pOpts )
-{
- char** ppzOpts;
- char** ppzOpds;
- int optsIdx = 0;
- int 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))
- return;
-
- /*
- * Make sure we can allocate two full-sized arg vectors.
- */
- ppzOpts = malloc( pOpts->origArgCt * sizeof( char* ));
- if (ppzOpts == NULL)
- goto exit_no_mem;
-
- ppzOpds = malloc( pOpts->origArgCt * sizeof( char* ));
- if (ppzOpds == NULL) {
- free( ppzOpts );
- goto exit_no_mem;
- }
-
- pOpts->curOptIdx = 1;
- pOpts->pzCurOpt = NULL;
-
- /*
- * Now, process all the options from our current position onward.
- * (This allows interspersed options and arguments for the few
- * non-standard programs that require it.)
- */
- for (;;) {
- char* pzArg;
- 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) {
- errno = 0;
- goto joinLists;
- }
-
- pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
- if (*pzArg != '-') {
- ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
- continue;
- }
-
- switch (pzArg[1]) {
- case NUL:
- /*
- * A single hyphen is an operand.
- */
- ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
- continue;
-
- case '-':
- /*
- * 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)++ ];
- goto restOperands;
- }
- res = longOptionFind( pOpts, pzArg+2, &os );
- break;
-
- default:
- /*
- * If short options are not allowed, then do long
- * 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 );
- } else {
- res = shortOptionFind( pOpts, (tAoUC)pzArg[1], &os );
- }
- break;
- }
- if (FAILED( res )) {
- errno = EINVAL;
- goto freeTemps;
- }
-
- /*
- * We've found an option. Add the argument to the option list.
- * 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)++ ];
-
- if (OPTST_GET_ARGTYPE(os.pOD->fOptState) == OPARG_TYPE_NONE) {
- /*
- * No option argument. If we have a short option here,
- * then scan for short options until we get to the end
- * of the argument string.
- */
- if ( (os.optType == TOPT_SHORT)
- && FAILED( checkShortOpts( pOpts, pzArg+2, &os,
- ppzOpts, &optsIdx )) ) {
- errno = EINVAL;
- goto freeTemps;
- }
-
- } else if (os.pOD->fOptState & OPTST_ARG_OPTIONAL) {
- switch (mayHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) {
- case FAILURE: errno = EIO; goto freeTemps;
- case PROBLEM: errno = 0; goto joinLists;
- }
-
- } else {
- switch (mustHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) {
- case PROBLEM:
- case FAILURE: errno = EIO; goto freeTemps;
- }
- }
- } /* for (;;) */
-
- restOperands:
- while (pOpts->curOptIdx < pOpts->origArgCt)
- ppzOpds[ opdsIdx++ ] = pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
-
- joinLists:
- if (optsIdx > 0)
- memcpy( pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof( char* ));
- if (opdsIdx > 0)
- memcpy( pOpts->origArgVect + 1 + optsIdx,
- ppzOpds, opdsIdx * sizeof( char* ));
-
- freeTemps:
- free( ppzOpts );
- free( ppzOpds );
- return;
-
- exit_no_mem:
- errno = ENOMEM;
- return;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/sort.c */
+++ /dev/null
-
-/*
- * stack.c
- * $Id: stack.c,v 4.19 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-07-30 16:56:32 bkorb"
- *
- * This is a special option processing routine that will save the
- * argument to an option in a FIFO queue.
- *
- * 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
- */
-
-#ifdef WITH_LIBREGEX
-# include REGEX_HEADER
-#endif
-
-/*=export_func optionUnstackArg
- * private:
- *
- * what: Remove option args from a stack
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Invoked for options that are equivalenced to stacked options.
-=*/
-void
-optionUnstackArg(
- tOptions* pOpts,
- tOptDesc* pOptDesc )
-{
- int res;
-
- tArgList* pAL;
-
- if ((pOptDesc->fOptState & OPTST_RESET) != 0)
- return;
- pAL = (tArgList*)pOptDesc->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;
- return;
- }
-
-#ifdef WITH_LIBREGEX
- {
- regex_t re;
- int i, ct, dIdx;
-
- if (regcomp( &re, pOptDesc->optArg.argString, REG_NOSUB ) != 0)
- return;
-
- /*
- * search the list for the entry(s) to remove. Entries that
- * are removed are *not* copied into the result. The source
- * 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, '=' );
-
- if (pzEq != NULL)
- *pzEq = NUL;
-
- res = regexec( &re, pzSrc, (size_t)0, NULL, 0 );
- switch (res) {
- case 0:
- /*
- * Remove this entry by reducing the in-use count
- * and *not* putting the string pointer back into
- * the list.
- */
- AGFREE(pzSrc);
- pAL->useCt--;
- break;
-
- default:
- case REG_NOMATCH:
- if (pzEq != NULL)
- *pzEq = '=';
-
- /*
- * IF we have dropped an entry
- * THEN we have to move the current one.
- */
- if (dIdx != i)
- pAL->apzArgs[ dIdx ] = pzSrc;
- dIdx++;
- }
- }
-
- regfree( &re );
- }
-#else /* not WITH_LIBREGEX */
- {
- int i, ct, dIdx;
-
- /*
- * search the list for the entry(s) to remove. Entries that
- * are removed are *not* copied into the result. The source
- * 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, '=' );
-
- if (pzEq != NULL)
- *pzEq = NUL;
-
- if (strcmp( pzSrc, pOptDesc->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--;
- } else {
- if (pzEq != NULL)
- *pzEq = '=';
-
- /*
- * IF we have dropped an entry
- * THEN we have to move the current one.
- */
- if (dIdx != i)
- pAL->apzArgs[ dIdx ] = pzSrc;
- dIdx++;
- }
- }
- }
-#endif /* WITH_LIBREGEX */
- /*
- * 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;
- }
-}
-
-
-/*
- * Put an entry into an argument list. The first argument points to
- * a pointer to the argument list structure. It gets passed around
- * as an opaque address.
- */
-LOCAL void
-addArgListEntry( void** ppAL, void* entry )
-{
- tArgList* pAL = *(void**)ppAL;
-
- /*
- * IF we have never allocated one of these,
- * THEN allocate one now
- */
- if (pAL == NULL) {
- pAL = (tArgList*)AGALOC( sizeof( *pAL ), "new option arg stack" );
- if (pAL == NULL)
- return;
- pAL->useCt = 0;
- pAL->allocCt = MIN_ARG_ALLOC_CT;
- *ppAL = (void*)pAL;
- }
-
- /*
- * ELSE if we are out of room
- * THEN make it bigger
- */
- else if (pAL->useCt >= pAL->allocCt) {
- 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" );
- if (pAL == NULL)
- return;
- *ppAL = (void*)pAL;
- }
-
- /*
- * Insert the new argument into the list
- */
- pAL->apzArgs[ (pAL->useCt)++ ] = entry;
-}
-
-
-/*=export_func optionStackArg
- * private:
- *
- * what: put option args on a stack
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Keep an entry-ordered list of option arguments.
-=*/
-void
-optionStackArg(
- tOptions* pOpts,
- tOptDesc* pOD )
-{
- char * pz;
-
- if ((pOD->fOptState & OPTST_RESET) != 0) {
- tArgList* pAL = (void*)pOD->optCookie;
- int ix;
- if (pAL == NULL)
- return;
-
- ix = pAL->useCt;
- while (--ix >= 0)
- AGFREE(pAL->apzArgs[ix]);
- AGFREE(pAL);
-
- } else {
- if (pOD->optArg.argString == NULL)
- return;
-
- AGDUPSTR(pz, pOD->optArg.argString, "stack arg");
- addArgListEntry( &(pOD->optCookie), (void*)pz );
- }
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/stack.c */
+++ /dev/null
-
-/*
- * $Id: streqvcmp.c,v 4.16 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-12-26 10:15:46 bkorb"
- *
- * String Equivalence Comparison
- *
- * These routines allow any character to be mapped to any other
- * character before comparison. In processing long option names,
- * the characters "-", "_" and "^" all need to be equivalent
- * (because they are treated so by different development environments).
- *
- * 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
- *
- * 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,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
-
- ' ', '!', '"', '#', '$', '%', '&', '\'',
- '(', ')', '*', '+', ',', '-', '.', '/',
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', ':', ';', '<', '=', '>', '?',
-
- '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', '[', '\\', ']', '^', '_',
- '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', '{', '|', '}', '~', 0x7f,
-
- 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
- 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
- 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
- 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
- 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
- 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
- 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
-
- 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
- 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
- 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
- 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
- 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
- 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
- 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
- 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
-};
-
-
-/*=export_func strneqvcmp
- *
- * what: compare two strings with an equivalence mapping
- *
- * arg: + char const* + str1 + first string +
- * arg: + char const* + str2 + second string +
- * arg: + int + ct + compare length +
- *
- * ret_type: int
- * ret_desc: the difference between two differing characters
- *
- * doc:
- *
- * Using a character mapping, two strings are compared for "equivalence".
- * Each input character is mapped to a comparison character and the
- * mapped-to characters are compared for the two NUL terminated input strings.
- * The comparison is limited to @code{ct} bytes.
- * This function name is mapped to option_strneqvcmp so as to not conflict
- * with the POSIX name space.
- *
- * err: none checked. Caller responsible for seg faults.
-=*/
-int
-strneqvcmp( tCC* s1, tCC* 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 ];
-
- if (dif != 0)
- return dif;
-
- if (u1 == NUL)
- return 0;
- }
-
- return 0;
-}
-
-
-/*=export_func streqvcmp
- *
- * what: compare two strings with an equivalence mapping
- *
- * arg: + char const* + str1 + first string +
- * arg: + char const* + str2 + second string +
- *
- * ret_type: int
- * ret_desc: the difference between two differing characters
- *
- * doc:
- *
- * Using a character mapping, two strings are compared for "equivalence".
- * Each input character is mapped to a comparison character and the
- * mapped-to characters are compared for the two NUL terminated input strings.
- * This function name is mapped to option_streqvcmp so as to not conflict
- * with the POSIX name space.
- *
- * err: none checked. Caller responsible for seg faults.
-=*/
-int
-streqvcmp( tCC* s1, tCC* s2 )
-{
- for (;;) {
- unsigned char u1 = (unsigned char) *s1++;
- unsigned char u2 = (unsigned char) *s2++;
- int dif = charmap[ u1 ] - charmap[ u2 ];
-
- if (dif != 0)
- return dif;
-
- if (u1 == NUL)
- return 0;
- }
-}
-
-
-/*=export_func streqvmap
- *
- * what: Set the character mappings for the streqv functions
- *
- * arg: + char + From + Input character +
- * arg: + char + To + Mapped-to character +
- * arg: + int + ct + compare length +
- *
- * doc:
- *
- * Set the character mapping. If the count (@code{ct}) is set to zero, then
- * the map is cleared by setting all entries in the map to their index
- * value. Otherwise, the "@code{From}" character is mapped to the "@code{To}"
- * character. If @code{ct} is greater than 1, then @code{From} and @code{To}
- * are incremented and the process repeated until @code{ct} entries have been
- * set. For example,
- * @example
- * streqvmap( 'a', 'A', 26 );
- * @end example
- * @noindent
- * will alter the mapping so that all English lower case letters
- * will map to upper case.
- *
- * This function name is mapped to option_streqvmap so as to not conflict
- * with the POSIX name space.
- *
- * err: none.
-=*/
-void
-streqvmap( char From, char To, int ct )
-{
- if (ct == 0) {
- ct = sizeof( charmap ) - 1;
- do {
- charmap[ ct ] = ct;
- } while (--ct >= 0);
- }
-
- else {
- int chTo = (int)To & 0xFF;
- int chFrom = (int)From & 0xFF;
-
- do {
- charmap[ chFrom ] = (unsigned)chTo;
- chFrom++;
- chTo++;
- if ((chFrom >= sizeof( charmap )) || (chTo >= sizeof( charmap )))
- break;
- } while (--ct > 0);
- }
-}
-
-
-/*=export_func strequate
- *
- * what: map a list of characters to the same value
- *
- * arg: + char const* + ch_list + characters to equivalence +
- *
- * doc:
- *
- * Each character in the input string get mapped to the first character
- * in the string.
- * This function name is mapped to option_strequate so as to not conflict
- * with the POSIX name space.
- *
- * err: none.
-=*/
-void
-strequate( char const* s )
-{
- if ((s != NULL) && (*s != NUL)) {
- unsigned char equiv = (unsigned)*s;
- while (*s != NUL)
- charmap[ (unsigned)*(s++) ] = equiv;
- }
-}
-
-
-/*=export_func strtransform
- *
- * what: convert a string into its mapped-to value
- *
- * arg: + char* + dest + output string +
- * arg: + char const* + src + input string +
- *
- * doc:
- *
- * Each character in the input string is mapped and the mapped-to
- * character is put into the output.
- * This function name is mapped to option_strtransform so as to not conflict
- * with the POSIX name space.
- *
- * The source and destination may be the same.
- *
- * err: none.
-=*/
-void
-strtransform( char* d, char const* s )
-{
- do {
- *(d++) = (char)charmap[ (unsigned)*s ];
- } while (*(s++) != NUL);
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/streqvcmp.c */
+++ /dev/null
-/*
- * $Id: text_mmap.c,v 4.20 2009/08/01 17:44:36 bkorb Exp $
- *
- * Time-stamp: "2007-07-04 11:35:49 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 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
- */
-
-#ifndef MAP_ANONYMOUS
-# ifdef MAP_ANON
-# define MAP_ANONYMOUS MAP_ANON
-# endif
-#endif
-
-/*
- * Some weird systems require that a specifically invalid FD number
- * get passed in as an argument value. Which value is that? Well,
- * as everybody knows, if open(2) fails, it returns -1, so that must
- * be the value. :)
- */
-#define AO_INVALID_FD -1
-
-#define FILE_WRITABLE(_prt,_flg) \
- ( (_prt & PROT_WRITE) \
- && ((_flg & (MAP_SHARED|MAP_PRIVATE)) == MAP_SHARED))
-#define MAP_FAILED_PTR ((void*)MAP_FAILED)
-
-/*=export_func text_mmap
- * private:
- *
- * what: map a text file with terminating NUL
- *
- * arg: char const*, pzFile, name of the file to map
- * arg: int, prot, mmap protections (see mmap(2))
- * arg: int, flags, mmap flags (see mmap(2))
- * arg: tmap_info_t*, mapinfo, returned info about the mapping
- *
- * ret-type: void*
- * ret-desc: The mmaped data address
- *
- * doc:
- *
- * 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}
- * 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
- * @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
- * 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.
- * 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
- * are mapped after the end of the data.
- *
- * see: mmap(2), open(2), stat(2)
- *
- * err: Any error code issued by mmap(2), open(2), stat(2) is possible.
- * Additionally, if the specified file is not a regular file, then
- * errno will be set to @code{EINVAL}.
- *
- * example:
- * #include <mylib.h>
- * tmap_info_t mi;
- * int no_nul;
- * 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 );
-=*/
-void*
-text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI )
-{
- 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;
- 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;
-
- } 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 (pNuls != MAP_FAILED_PTR)
- return pMI->txt_data;
-
- 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;
-}
-
-
-/*=export_func text_munmap
- * private:
- *
- * what: unmap the data mapped in by text_mmap
- *
- * arg: tmap_info_t*, mapinfo, info about the mapping
- *
- * ret-type: int
- * ret-desc: -1 or 0. @file{errno} will have the error code.
- *
- * doc:
- *
- * This routine will unmap the data mapped in with @code{text_mmap} and close
- * the associated file descriptors opened by that function.
- *
- * see: munmap(2), close(2)
- *
- * err: Any error code issued by munmap(2) or close(2) is possible.
-=*/
-int
-text_munmap( tmap_info_t* pMI )
-{
-#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 */
-
- errno = 0;
- /*
- * 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.
- */
- 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 );
- }
-
- close( pMI->txt_fd );
- pMI->txt_fd = -1;
- pMI->txt_errno = errno;
- free( pMI->txt_data );
-
- return pMI->txt_errno;
-#endif /* HAVE_MMAP */
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/text_mmap.c */
+++ /dev/null
-
-/*
- * $Id: time.c,v 4.4 2009/08/01 17:44:36 bkorb Exp $
- * Time-stamp: "2008-11-16 14:51:48 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 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
- */
-
-#ifndef HAVE_PARSE_DURATION
-#include <time.h>
-
-static inline char *
-ao_xstrdup(char const * pz)
-{
- char * str;
- AGDUPSTR(str, pz, "time val str");
- return str;
-}
-
-#define xstrdup(_s) ao_xstrdup(_s)
-
-#include "parse-duration.c"
-
-#undef xstrdup
-#endif
-
-/*=export_func optionTimeVal
- * private:
- *
- * what: process an option with a time value.
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
- *
- * doc:
- * Decipher a time duration value.
-=*/
-void
-optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
-{
- long val;
-
- if ((pOD->fOptState & OPTST_RESET) != 0)
- return;
-
- val = parse_duration(pOD->optArg.argString);
- if (errno != 0)
- goto bad_time;
-
- if (pOD->fOptState & OPTST_ALLOC_ARG) {
- AGFREE(pOD->optArg.argString);
- pOD->fOptState &= ~OPTST_ALLOC_ARG;
- }
-
- pOD->optArg.argInt = val;
- return;
-
-bad_time:
- fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString );
- if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
- (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
-
- pOD->optArg.argInt = ~0;
-}
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/numeric.c */
+++ /dev/null
-/*
- * 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 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
- */
-
-#include <errno.h>
-#include <stdlib.h>
-
-#define cc_t const unsigned char
-#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 );
-
-static void
-copy_raw( ch_t** ppDest, char const ** ppSrc );
-/* = = = END-STATIC-FORWARD = = = */
-
-static void
-copy_cooked( ch_t** ppDest, char const ** ppSrc )
-{
- ch_t* pDest = (ch_t*)*ppDest;
- const ch_t* pSrc = (const ch_t*)(*ppSrc + 1);
-
- for (;;) {
- ch_t ch = *(pSrc++);
- switch (ch) {
- case NUL: *ppSrc = NULL; return;
- case '"': goto done;
- case '\\':
- pSrc += ao_string_cook_escape_char( (char*)pSrc, (char*)&ch, 0x7F );
- if (ch == 0x7F)
- break;
- /* FALLTHROUGH */
-
- default:
- *(pDest++) = ch;
- }
- }
-
- done:
- *ppDest = (ch_t*)pDest; /* next spot for storing character */
- *ppSrc = (char const *)pSrc; /* char following closing quote */
-}
-
-
-static void
-copy_raw( ch_t** ppDest, char const ** ppSrc )
-{
- ch_t* pDest = *ppDest;
- cc_t* pSrc = (cc_t*) (*ppSrc + 1);
-
- for (;;) {
- ch_t ch = *(pSrc++);
- switch (ch) {
- case NUL: *ppSrc = NULL; return;
- case '\'': goto done;
- case '\\':
- /*
- * *Four* escapes are handled: newline removal, escape char
- * quoting and apostrophe quoting
- */
- switch (*pSrc) {
- case NUL: *ppSrc = NULL; return;
- case '\r':
- if (*(++pSrc) == '\n')
- ++pSrc;
- continue;
-
- case '\n':
- ++pSrc;
- continue;
-
- case '\'':
- ch = '\'';
- /* FALLTHROUGH */
-
- case '\\':
- ++pSrc;
- break;
- }
- /* FALLTHROUGH */
-
- default:
- *(pDest++) = ch;
- }
- }
-
- done:
- *ppDest = pDest; /* next spot for storing character */
- *ppSrc = (char const *) pSrc; /* char following closing quote */
-}
-
-
-/*=export_func ao_string_tokenize
- *
- * what: tokenize an input string
- *
- * arg: + char const* + string + string to be tokenized +
- *
- * ret_type: token_list_t*
- * ret_desc: pointer to a structure that lists each token
- *
- * doc:
- *
- * This function will convert one input string into a list of strings.
- * The list of strings is derived by separating the input based on
- * white space separation. However, if the input contains either single
- * or double quote characters, then the text after that character up to
- * a matching quote will become the string in the list.
- *
- * The returned pointer should be deallocated with @code{free(3C)} when
- * are done using the data. The data are placed in a single block of
- * allocated memory. Do not deallocate individual token/strings.
- *
- * The structure pointed to will contain at least these two fields:
- * @table @samp
- * @item tkn_ct
- * The number of tokens found in the input string.
- * @item tok_list
- * An array of @code{tkn_ct + 1} pointers to substring tokens, with
- * the last pointer set to NULL.
- * @end table
- *
- * There are two types of quoted strings: single quoted (@code{'}) and
- * double quoted (@code{"}). Singly quoted strings are fairly raw in that
- * escape characters (@code{\\}) are simply another character, except when
- * preceding the following characters:
- * @example
- * @code{\\} double backslashes reduce to one
- * @code{'} incorporates the single quote into the string
- * @code{\n} suppresses both the backslash and newline character
- * @end example
- *
- * Double quote strings are formed according to the rules of string
- * constants in ANSI-C programs.
- *
- * example:
- * @example
- * #include <stdlib.h>
- * int ix;
- * 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 );
- * @end example
- * Note that everything is freed with the one call to @code{free(3C)}.
- *
- * err:
- * NULL is returned and @code{errno} will be set to indicate the problem:
- * @itemize @bullet
- * @item
- * @code{EINVAL} - There was an unterminated quoted string.
- * @item
- * @code{ENOENT} - The input string was empty.
- * @item
- * @code{ENOMEM} - There is not enough memory.
- * @end itemize
-=*/
-token_list_t*
-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;
-
- /*
- * 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.
- */
- {
- cc_t* pz = (cc_t*)str;
-
- do {
- max_token_ct++;
- while (! IS_WHITESPACE_CHAR(*++pz))
- if (*pz == NUL) goto found_nul;
- while (IS_WHITESPACE_CHAR(*pz)) pz++;
- } while (*pz != NUL);
-
- found_nul:
- ;
- }
-
- res = malloc( sizeof(*res) + strlen(str) + (max_token_ct * sizeof(ch_t*)) );
- if (res == NULL) {
- errno = ENOMEM;
- return res;
- }
-
- /*
- * 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;
-
- 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;
- }
- } 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;
-}
-
-#ifdef TEST
-#include <stdio.h>
-#include <string.h>
-
-int
-main( int argc, char** argv )
-{
- if (argc == 1) {
- printf("USAGE: %s arg [ ... ]\n", *argv);
- return 1;
- }
- while (--argc > 0) {
- char* arg = *(++argv);
- 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 ));
- } else {
- int ix = 0;
- printf( "Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct );
- do {
- printf( " %3d: ``%s''\n", ix+1, p->tkn_list[ix] );
- } while (++ix < p->tkn_ct);
- free(p);
- }
- }
- return 0;
-}
-#endif
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/tokenize.c */
+++ /dev/null
-
-/*
- * usage.c $Id: usage.c,v 4.31 2009/08/01 17:44:37 bkorb Exp $
- * Time-stamp: "2009-01-17 13:18:23 bkorb"
- *
- * This module implements the default usage procedure for
- * Automated Options. It may be overridden, of course.
- *
- * Sort options:
- --start=END-[S]TATIC-FORWARD --patt='^/\*($|[^:])' \
- --out=xx.c key='^[a-zA-Z0-9_]+\(' --trail='^/\*:' \
- --spac=2 --input=usage.c
- */
-
-/*
- * 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
- */
-
-#define OPTPROC_L_N_S (OPTPROC_LONGOPT | OPTPROC_SHORTOPT)
-
-static arg_types_t argTypes;
-
-FILE* option_usage_fp = NULL;
-static char zOptFmtLine[ 16 ];
-static ag_bool displayEnum;
-
-/* = = = START-STATIC-FORWARD = = = */
-/* static forward declarations maintained by mk-fwd */
-static ag_bool
-checkGNUUsage( tOptions* pOpts );
-
-static void
-printExtendedUsage(
- tOptions* pOptions,
- tOptDesc* pOD,
- arg_types_t* pAT );
-
-static void
-printInitList(
- tCC* const* papz,
- ag_bool* pInitIntro,
- tCC* pzRc,
- tCC* pzPN );
-
-static void
-printOneUsage(
- tOptions* pOptions,
- tOptDesc* pOD,
- arg_types_t* pAT );
-
-static void
-printOptionUsage(
- tOptions* pOpts,
- int ex_code,
- tCC* pOptTitle );
-
-static void
-printProgramDetails( tOptions* pOptions );
-
-static int
-setGnuOptFmts( tOptions* pOpts, tCC** ppT );
-
-static int
-setStdOptFmts( tOptions* pOpts, tCC** ppT );
-/* = = = END-STATIC-FORWARD = = = */
-
-
-/*
- * Figure out if we should try to format usage text sort-of like
- * the way many GNU programs do.
- */
-static ag_bool
-checkGNUUsage( tOptions* pOpts )
-{
- char* pz = getenv( "AUTOOPTS_USAGE" );
- if (pz == NULL)
- ;
-
- else if (streqvcmp( pz, "gnu" ) == 0)
- pOpts->fOptSet |= OPTPROC_GNUUSAGE;
-
- else if (streqvcmp( pz, "autoopts" ) == 0)
- pOpts->fOptSet &= ~OPTPROC_GNUUSAGE;
-
- return (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? AG_TRUE : AG_FALSE;
-}
-
-
-/*=export_func optionOnlyUsage
- *
- * what: Print usage text for just the options
- * arg: + tOptions* + pOpts + program options descriptor +
- * arg: + int + ex_code + exit code for calling exit(3) +
- *
- * doc:
- * This routine will print only the usage for each option.
- * This function may be used when the emitted usage must incorporate
- * information not available to AutoOpts.
-=*/
-void
-optionOnlyUsage(
- tOptions* pOpts,
- int ex_code )
-{
- tCC* pOptTitle = NULL;
-
- /*
- * Determine which header and which option formatting strings to use
- */
- if (checkGNUUsage(pOpts)) {
- (void)setGnuOptFmts( pOpts, &pOptTitle );
- }
- else {
- (void)setStdOptFmts( pOpts, &pOptTitle );
- }
-
- printOptionUsage( pOpts, ex_code, pOptTitle );
-}
-
-
-/*=export_func optionUsage
- * private:
- *
- * what: Print usage text
- * arg: + tOptions* + pOptions + program options descriptor +
- * arg: + int + exitCode + exit code for calling exit(3) +
- *
- * doc:
- * This routine will print usage in both GNU-standard and AutoOpts-expanded
- * formats. The descriptor specifies the default, but AUTOOPTS_USAGE will
- * over-ride this, providing the value of it is set to either "gnu" or
- * "autoopts". This routine will @strong{not} return.
- *
- * If "exitCode" is "EX_USAGE" (normally 64), then output will to to stdout
- * and the actual exit code will be "EXIT_SUCCESS".
-=*/
-void
-optionUsage(
- tOptions* pOptions,
- int usage_exit_code )
-{
- int actual_exit_code =
- (usage_exit_code == EX_USAGE) ? EXIT_SUCCESS : usage_exit_code;
-
- displayEnum = AG_FALSE;
-
- /*
- * Paged usage will preset option_usage_fp to an output file.
- * If it hasn't already been set, then set it to standard output
- * on successful exit (help was requested), otherwise error out.
- *
- * Test the version before obtaining pzFullUsage or pzShortUsage.
- * These fields do not exist before revision 30.
- */
- {
- char const * pz;
-
- if (actual_exit_code == EXIT_SUCCESS) {
- pz = (pOptions->structVersion >= 30 * 4096)
- ? pOptions->pzFullUsage : NULL;
-
- if (option_usage_fp == NULL)
- option_usage_fp = stdout;
- } else {
- pz = (pOptions->structVersion >= 30 * 4096)
- ? pOptions->pzShortUsage : NULL;
-
- if (option_usage_fp == NULL)
- option_usage_fp = stderr;
- }
-
- if (pz != NULL) {
- fputs(pz, option_usage_fp);
- exit(actual_exit_code);
- }
- }
-
- fprintf( option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName );
-
- {
- tCC* pOptTitle = NULL;
-
- /*
- * Determine which header and which option formatting strings to use
- */
- if (checkGNUUsage(pOptions)) {
- int flen = setGnuOptFmts( pOptions, &pOptTitle );
- sprintf( zOptFmtLine, zFmtFmt, flen );
- fputc( '\n', option_usage_fp );
- }
- else {
- int flen = setStdOptFmts( pOptions, &pOptTitle );
- sprintf( zOptFmtLine, zFmtFmt, flen );
-
- /*
- * When we exit with EXIT_SUCCESS and the first option is a doc
- * option, we do *NOT* want to emit the column headers.
- * Otherwise, we do.
- */
- if ( (usage_exit_code != EXIT_SUCCESS)
- || ((pOptions->pOptDesc->fOptState & OPTST_DOCUMENT) == 0) )
-
- fputs( pOptTitle, option_usage_fp );
- }
-
- printOptionUsage( pOptions, usage_exit_code, pOptTitle );
- }
-
- /*
- * Describe the mechanics of denoting the options
- */
- switch (pOptions->fOptSet & OPTPROC_L_N_S) {
- case OPTPROC_L_N_S: fputs( zFlagOkay, option_usage_fp ); break;
- case OPTPROC_SHORTOPT: break;
- case OPTPROC_LONGOPT: fputs( zNoFlags, option_usage_fp ); break;
- case 0: fputs( zOptsOnly, option_usage_fp ); break;
- }
-
- if ((pOptions->fOptSet & OPTPROC_NUM_OPT) != 0) {
- fputs( zNumberOpt, option_usage_fp );
- }
-
- if ((pOptions->fOptSet & OPTPROC_REORDER) != 0) {
- fputs( zReorder, option_usage_fp );
- }
-
- if (pOptions->pzExplain != NULL)
- fputs( pOptions->pzExplain, option_usage_fp );
-
- /*
- * IF the user is asking for help (thus exiting with SUCCESS),
- * THEN see what additional information we can provide.
- */
- if (usage_exit_code == EXIT_SUCCESS)
- printProgramDetails( pOptions );
-
- if (pOptions->pzBugAddr != NULL)
- fprintf( option_usage_fp, zPlsSendBugs, pOptions->pzBugAddr );
- fflush( option_usage_fp );
-
- exit( actual_exit_code );
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PER OPTION TYPE USAGE INFORMATION
- */
-static void
-printExtendedUsage(
- tOptions* pOptions,
- tOptDesc* pOD,
- arg_types_t* pAT )
-{
- /*
- * IF there are option conflicts or dependencies,
- * THEN print them here.
- */
- if ( (pOD->pOptMust != NULL)
- || (pOD->pOptCant != NULL) ) {
-
- fputs( zTabHyp, option_usage_fp );
-
- /*
- * DEPENDENCIES:
- */
- if (pOD->pOptMust != NULL) {
- const int* pOptNo = pOD->pOptMust;
-
- fputs( zReqThese, option_usage_fp );
- for (;;) {
- fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[
- *pOptNo ].pz_Name );
- if (*++pOptNo == NO_EQUIVALENT)
- break;
- }
-
- if (pOD->pOptCant != NULL)
- fputs( zTabHypAnd, option_usage_fp );
- }
-
- /*
- * CONFLICTS:
- */
- if (pOD->pOptCant != NULL) {
- const int* pOptNo = pOD->pOptCant;
-
- fputs( zProhib, option_usage_fp );
- for (;;) {
- fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[
- *pOptNo ].pz_Name );
- if (*++pOptNo == NO_EQUIVALENT)
- break;
- }
- }
- }
-
- /*
- * IF there is a disablement string
- * THEN print the disablement info
- */
- if (pOD->pz_DisableName != NULL )
- fprintf( option_usage_fp, zDis, pOD->pz_DisableName );
-
- /*
- * Check for argument types that have callbacks with magical properties
- */
- switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
- case OPARG_TYPE_NUMERIC:
- /*
- * IF the numeric option has a special callback,
- * THEN call it, requesting the range or other special info
- */
- if ( (pOD->pOptProc != NULL)
- && (pOD->pOptProc != optionNumericVal) ) {
- (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
- }
- break;
-
- case OPARG_TYPE_FILE:
- (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
- break;
- }
-
- /*
- * IF the option defaults to being enabled,
- * THEN print that out
- */
- if (pOD->fOptState & OPTST_INITENABLED)
- fputs( zEnab, option_usage_fp );
-
- /*
- * IF the option is in an equivalence class
- * AND not the designated lead
- * THEN print equivalence and leave it at that.
- */
- if ( (pOD->optEquivIndex != NO_EQUIVALENT)
- && (pOD->optEquivIndex != pOD->optActualIndex ) ) {
- fprintf( option_usage_fp, zAlt,
- pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name );
- return;
- }
-
- /*
- * IF this particular option can NOT be preset
- * AND some form of presetting IS allowed,
- * AND it is not an auto-managed option (e.g. --help, et al.)
- * THEN advise that this option may not be preset.
- */
- if ( ((pOD->fOptState & OPTST_NO_INIT) != 0)
- && ( (pOptions->papzHomeList != NULL)
- || (pOptions->pzPROGNAME != NULL)
- )
- && (pOD->optIndex < pOptions->presetOptCt)
- )
-
- fputs( zNoPreset, option_usage_fp );
-
- /*
- * Print the appearance requirements.
- */
- if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP)
- fputs( zMembers, option_usage_fp );
-
- else switch (pOD->optMinCt) {
- case 1:
- case 0:
- switch (pOD->optMaxCt) {
- case 0: fputs( zPreset, option_usage_fp ); break;
- case NOLIMIT: fputs( zNoLim, option_usage_fp ); break;
- case 1: break;
- /*
- * IF the max is more than one but limited, print "UP TO" message
- */
- default: fprintf( option_usage_fp, zUpTo, pOD->optMaxCt ); break;
- }
- break;
-
- default:
- /*
- * More than one is required. Print the range.
- */
- fprintf( option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt );
- }
-
- if ( NAMED_OPTS( pOptions )
- && (pOptions->specOptIdx.default_opt == pOD->optIndex))
- fputs( zDefaultOpt, option_usage_fp );
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Figure out where all the initialization files might live.
- * This requires translating some environment variables and
- * testing to see if a name is a directory or a file. It's
- * squishy, but important to tell users how to find these files.
- */
-static void
-printInitList(
- tCC* const* papz,
- ag_bool* pInitIntro,
- tCC* pzRc,
- tCC* pzPN )
-{
- char zPath[ AG_PATH_MAX+1 ];
-
- if (papz == NULL)
- return;
-
- fputs( zPresetIntro, option_usage_fp );
- *pInitIntro = AG_FALSE;
-
- for (;;) {
- char const* pzPath = *(papz++);
-
- if (pzPath == NULL)
- break;
-
- if (optionMakePath(zPath, (int)sizeof( zPath ), pzPath, pzPN))
- pzPath = zPath;
-
- /*
- * Print the name of the "homerc" file. If the "rcfile" name is
- * not empty, we may or may not print that, too...
- */
- fprintf( option_usage_fp, zPathFmt, pzPath );
- if (*pzRc != NUL) {
- struct stat sb;
-
- /*
- * IF the "homerc" file is a directory,
- * then append the "rcfile" name.
- */
- if ( (stat( pzPath, &sb ) == 0)
- && S_ISDIR( sb.st_mode ) ) {
- fputc( DIRCH, option_usage_fp );
- fputs( pzRc, option_usage_fp );
- }
- }
-
- fputc( '\n', option_usage_fp );
- }
-}
-
-
-/*
- * Print the usage information for a single option.
- */
-static void
-printOneUsage(
- tOptions* pOptions,
- tOptDesc* pOD,
- arg_types_t* pAT )
-{
- /*
- * Flag prefix: IF no flags at all, then omit it. If not printable
- * (not allowed for this option), then blank, else print it.
- * Follow it with a comma if we are doing GNU usage and long
- * opts are to be printed too.
- */
- if ((pOptions->fOptSet & OPTPROC_SHORTOPT) == 0)
- fputs( pAT->pzSpc, option_usage_fp );
- else if (! IS_GRAPHIC_CHAR(pOD->optValue)) {
- if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
- == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
- fputc( ' ', option_usage_fp );
- fputs( pAT->pzNoF, option_usage_fp );
- } else {
- fprintf( option_usage_fp, " -%c", pOD->optValue );
- if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
- == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
- fputs( ", ", option_usage_fp );
- }
-
- {
- char z[ 80 ];
- tCC* pzArgType;
- /*
- * Determine the argument type string first on its usage, then,
- * when the option argument is required, base the type string on the
- * argument type.
- */
- if (pOD->fOptState & OPTST_ARG_OPTIONAL) {
- pzArgType = pAT->pzOpt;
-
- } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
- case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break;
- case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break;
- case OPARG_TYPE_FILE : pzArgType = pAT->pzFile; break;
- case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break;
- case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break;
- case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break;
- case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break;
- case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break;
- case OPARG_TYPE_TIME: pzArgType = pAT->pzTime; break;
- default: goto bogus_desc;
- }
-
- snprintf( z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name,
- (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt );
-
- fprintf( option_usage_fp, zOptFmtLine, z, pOD->pzText );
-
- switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
- case OPARG_TYPE_ENUMERATION:
- case OPARG_TYPE_MEMBERSHIP:
- displayEnum = (pOD->pOptProc != NULL) ? AG_TRUE : displayEnum;
- }
- }
- return;
-
- bogus_desc:
- fprintf( stderr, zInvalOptDesc, pOD->pz_Name );
- exit( EX_SOFTWARE );
-}
-
-
-/*
- * Print out the usage information for just the options.
- */
-static void
-printOptionUsage(
- tOptions* pOpts,
- int ex_code,
- tCC* pOptTitle )
-{
- int ct = pOpts->optCt;
- int optNo = 0;
- tOptDesc* pOD = pOpts->pOptDesc;
- int docCt = 0;
-
- do {
- if ((pOD->fOptState & OPTST_NO_USAGE_MASK) != 0)
- continue;
-
- if ((pOD->fOptState & OPTST_DOCUMENT) != 0) {
- if (ex_code == EXIT_SUCCESS) {
- fprintf(option_usage_fp, argTypes.pzBrk, pOD->pzText,
- pOptTitle);
- docCt++;
- }
-
- continue;
- }
-
- /*
- * IF this is the first auto-opt maintained option
- * *AND* we are doing a full help
- * *AND* there are documentation options
- * *AND* the last one was not a doc option,
- * THEN document that the remaining options are not user opts
- */
- if ( (pOpts->presetOptCt == optNo)
- && (ex_code == EXIT_SUCCESS)
- && (docCt > 0)
- && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) )
- fprintf( option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle );
-
- printOneUsage( pOpts, pOD, &argTypes );
-
- /*
- * IF we were invoked because of the --help option,
- * THEN print all the extra info
- */
- if (ex_code == EXIT_SUCCESS)
- printExtendedUsage( pOpts, pOD, &argTypes );
-
- } while (pOD++, optNo++, (--ct > 0));
-
- fputc( '\n', option_usage_fp );
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PROGRAM DETAILS
- */
-static void
-printProgramDetails( tOptions* pOptions )
-{
- ag_bool initIntro = AG_TRUE;
-
- /*
- * Display all the places we look for config files
- */
- printInitList( pOptions->papzHomeList, &initIntro,
- pOptions->pzRcName, pOptions->pzProgPath );
-
- /*
- * Let the user know about environment variable settings
- */
- if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) {
- if (initIntro)
- fputs( zPresetIntro, option_usage_fp );
-
- fprintf( option_usage_fp, zExamineFmt, pOptions->pzPROGNAME );
- }
-
- /*
- * IF we found an enumeration,
- * THEN hunt for it again. Call the handler proc with a NULL
- * option struct pointer. That tells it to display the keywords.
- */
- if (displayEnum) {
- int ct = pOptions->optCt;
- int optNo = 0;
- tOptDesc* pOD = pOptions->pOptDesc;
-
- fputc( '\n', option_usage_fp );
- fflush( option_usage_fp );
- do {
- switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
- case OPARG_TYPE_ENUMERATION:
- case OPARG_TYPE_MEMBERSHIP:
- (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
- }
- } while (pOD++, optNo++, (--ct > 0));
- }
-
- /*
- * If there is a detail string, now is the time for that.
- */
- if (pOptions->pzDetail != NULL)
- fputs( pOptions->pzDetail, option_usage_fp );
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * OPTION LINE FORMATTING SETUP
- *
- * The "OptFmt" formats receive three arguments:
- * 1. the type of the option's argument
- * 2. the long name of the option
- * 3. "YES" or "no ", depending on whether or not the option must appear
- * on the command line.
- * These formats are used immediately after the option flag (if used) has
- * been printed.
- *
- * Set up the formatting for GNU-style output
- */
-static int
-setGnuOptFmts( tOptions* pOpts, tCC** ppT )
-{
- int flen = 22;
- *ppT = zNoRq_ShrtTtl;
-
- argTypes.pzStr = zGnuStrArg;
- argTypes.pzReq = zOneSpace;
- argTypes.pzNum = zGnuNumArg;
- argTypes.pzKey = zGnuKeyArg;
- argTypes.pzKeyL = zGnuKeyLArg;
- argTypes.pzTime = zGnuTimeArg;
- argTypes.pzFile = zGnuFileArg;
- argTypes.pzBool = zGnuBoolArg;
- argTypes.pzNest = zGnuNestArg;
- argTypes.pzOpt = zGnuOptArg;
- argTypes.pzNo = zOneSpace;
- argTypes.pzBrk = zGnuBreak;
- argTypes.pzNoF = zSixSpaces;
- argTypes.pzSpc = zThreeSpaces;
-
- switch (pOpts->fOptSet & OPTPROC_L_N_S) {
- case OPTPROC_L_N_S: argTypes.pzOptFmt = zGnuOptFmt; break;
- case OPTPROC_LONGOPT: argTypes.pzOptFmt = zGnuOptFmt; break;
- case 0: argTypes.pzOptFmt = zGnuOptFmt + 2; break;
- case OPTPROC_SHORTOPT:
- argTypes.pzOptFmt = zShrtGnuOptFmt;
- zGnuStrArg[0] = zGnuNumArg[0] = zGnuKeyArg[0] = zGnuBoolArg[0] = ' ';
- argTypes.pzOpt = " [arg]";
- flen = 8;
- break;
- }
-
- return flen;
-}
-
-
-/*
- * Standard (AutoOpts normal) option line formatting
- */
-static int
-setStdOptFmts( tOptions* pOpts, tCC** ppT )
-{
- int flen = 0;
-
- argTypes.pzStr = zStdStrArg;
- argTypes.pzReq = zStdReqArg;
- argTypes.pzNum = zStdNumArg;
- argTypes.pzKey = zStdKeyArg;
- argTypes.pzKeyL = zStdKeyLArg;
- argTypes.pzTime = zStdTimeArg;
- argTypes.pzFile = zStdFileArg;
- argTypes.pzBool = zStdBoolArg;
- argTypes.pzNest = zStdNestArg;
- argTypes.pzOpt = zStdOptArg;
- argTypes.pzNo = zStdNoArg;
- argTypes.pzBrk = zStdBreak;
- argTypes.pzNoF = zFiveSpaces;
- argTypes.pzSpc = zTwoSpaces;
-
- switch (pOpts->fOptSet & (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT)) {
- case (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT):
- *ppT = zNoRq_ShrtTtl;
- argTypes.pzOptFmt = zNrmOptFmt;
- flen = 19;
- break;
-
- case OPTPROC_NO_REQ_OPT:
- *ppT = zNoRq_NoShrtTtl;
- argTypes.pzOptFmt = zNrmOptFmt;
- flen = 19;
- break;
-
- case OPTPROC_SHORTOPT:
- *ppT = zReq_ShrtTtl;
- argTypes.pzOptFmt = zReqOptFmt;
- flen = 24;
- break;
-
- case 0:
- *ppT = zReq_NoShrtTtl;
- argTypes.pzOptFmt = zReqOptFmt;
- flen = 24;
- }
-
- return flen;
-}
-
-
-/*:
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/usage.c */
+++ /dev/null
-/* 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;
-}
+++ /dev/null
-/*
- * Generated header for gperf generated source Sat Aug 1 11:21:22 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 */
+++ /dev/null
-
-/* $Id: version.c,v 4.17 2009/08/01 17:44:37 bkorb Exp $
- * Time-stamp: "2008-07-27 10:11:30 bkorb"
- *
- * This module implements the default usage procedure for
- * Automated Options. It may be overridden, of course.
- */
-
-/*
- * 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
- */
-
-/* = = = 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
- * ret_type: char const*
- * ret_desc: the version string in constant memory
- * doc:
- * Returns the full version string compiled into the library.
- * The returned string cannot be modified.
-=*/
-char const*
-optionVersion( void )
-{
- static char const zVersion[] =
- STR( AO_CURRENT.AO_REVISION );
-
- return zVersion;
-}
-
-
-static void
-printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
-{
- char swCh;
-
- /*
- * IF the optional argument flag is off, or the argument is not provided,
- * then just print the version.
- */
- 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');
- }
-
- switch (swCh) {
- 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;
-
- default:
- fprintf( stderr, zBadVerArg, swCh );
- exit( EXIT_FAILURE );
- }
-
- exit( 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 +
- *
- * doc:
- * This routine will print the version to stdout.
-=*/
-void
-optionPrintVersion( tOptions* pOpts, tOptDesc* pOD )
-{
- printVersion( pOpts, pOD, stdout );
-}
-
-/*=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 +
- *
- * doc:
- * This routine will print the version to stderr.
-=*/
-void
-optionVersionStderr( tOptions* pOpts, tOptDesc* pOD )
-{
- printVersion( pOpts, pOD, stderr );
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-file-style: "stroustrup"
- * indent-tabs-mode: nil
- * End:
- * end of autoopts/version.c */
+++ /dev/null
-/* 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;
-}
+++ /dev/null
-/*
- * Generated header for gperf generated source Sat Aug 1 11:21:22 PDT 2009
- * This file enumerates the list of names and declares the
- * procedure for mapping string names to the enum value.
- */
-#ifndef AUTOOPTS_XAT_ATTRIBUTE_H_GUARD
-#define AUTOOPTS_XAT_ATTRIBUTE_H_GUARD 1
-
-typedef enum {
- XAT_KWD_INVALID,
- XAT_KWD_TYPE,
- XAT_KWD_WORDS,
- XAT_KWD_MEMBERS,
- XAT_KWD_COOKED,
- XAT_KWD_UNCOOKED,
- XAT_KWD_KEEP,
- XAT_COUNT_KWD
-} xat_attribute_enum_t;
-
-extern xat_attribute_enum_t
-find_xat_attribute_id(char const * str, unsigned int len);
-#endif /* AUTOOPTS_XAT_ATTRIBUTE_H_GUARD */
+++ /dev/null
-# ltmain.sh - Provide generalized library-building support services.
-# NOTE: Changing this file will not affect anything until you rerun configure.
-#
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
-# Free Software Foundation, Inc.
-# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 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
-# the Free Software Foundation; either version 2 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, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# 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.
-
-basename="s,^.*/,,g"
-
-# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
-# is ksh but when the shell is invoked as "sh" and the current value of
-# the _XPG environment variable is not equal to 1 (one), the special
-# positional parameter $0, within a function call, is the name of the
-# function.
-progpath="$0"
-
-# The name of this program:
-progname=`echo "$progpath" | $SED $basename`
-modename="$progname"
-
-# Global variables:
-EXIT_SUCCESS=0
-EXIT_FAILURE=1
-
-PROGRAM=ltmain.sh
-PACKAGE=libtool
-VERSION=1.5.22
-TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)"
-
-# See if we are running on zsh, and set the options which allow our
-# commands through without removal of \ escapes.
-if test -n "${ZSH_VERSION+set}" ; then
- setopt NO_GLOB_SUBST
-fi
-
-# Check that we have a working $echo.
-if test "X$1" = X--no-reexec; then
- # Discard the --no-reexec flag, and continue.
- shift
-elif test "X$1" = X--fallback-echo; then
- # Avoid inline document here, it may be left over
- :
-elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then
- # Yippee, $echo works!
- :
-else
- # Restart under the correct shell, and then maybe $echo will work.
- exec $SHELL "$progpath" --no-reexec ${1+"$@"}
-fi
-
-if test "X$1" = X--fallback-echo; then
- # used as fallback echo
- shift
- cat <<EOF
-$*
-EOF
- exit $EXIT_SUCCESS
-fi
-
-default_mode=
-help="Try \`$progname --help' for more information."
-magic="%%%MAGIC variable%%%"
-mkdir="mkdir"
-mv="mv -f"
-rm="rm -f"
-
-# Sed substitution that helps us do robust quoting. It backslashifies
-# metacharacters that are still active within double-quoted strings.
-Xsed="${SED}"' -e 1s/^X//'
-sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
-# test EBCDIC or ASCII
-case `echo X|tr X '\101'` in
- A) # ASCII based system
- # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
- SP2NL='tr \040 \012'
- NL2SP='tr \015\012 \040\040'
- ;;
- *) # EBCDIC based system
- SP2NL='tr \100 \n'
- NL2SP='tr \r\n \100\100'
- ;;
-esac
-
-# NLS nuisances.
-# Only set LANG and LC_ALL to C if already set.
-# These must not be set unconditionally because not all systems understand
-# e.g. LANG=C (notably SCO).
-# We save the old values to restore during execute mode.
-if test "${LC_ALL+set}" = set; then
- save_LC_ALL="$LC_ALL"; LC_ALL=C; export LC_ALL
-fi
-if test "${LANG+set}" = set; then
- save_LANG="$LANG"; LANG=C; export LANG
-fi
-
-# Make sure IFS has a sensible default
-lt_nl='
-'
-IFS=" $lt_nl"
-
-if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
- $echo "$modename: not configured to build any kind of library" 1>&2
- $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2
- exit $EXIT_FAILURE
-fi
-
-# Global variables.
-mode=$default_mode
-nonopt=
-prev=
-prevopt=
-run=
-show="$echo"
-show_help=
-execute_dlfiles=
-duplicate_deps=no
-preserve_args=
-lo2o="s/\\.lo\$/.${objext}/"
-o2lo="s/\\.${objext}\$/.lo/"
-
-#####################################
-# Shell function definitions:
-# This seems to be the best place for them
-
-# func_mktempdir [string]
-# Make a temporary directory that won't clash with other running
-# libtool processes, and avoids race conditions if possible. If
-# given, STRING is the basename for that directory.
-func_mktempdir ()
-{
- my_template="${TMPDIR-/tmp}/${1-$progname}"
-
- if test "$run" = ":"; then
- # Return a directory name, but don't create it in dry-run mode
- my_tmpdir="${my_template}-$$"
- else
-
- # If mktemp works, use that first and foremost
- my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
-
- if test ! -d "$my_tmpdir"; then
- # Failing that, at least try and use $RANDOM to avoid a race
- my_tmpdir="${my_template}-${RANDOM-0}$$"
-
- save_mktempdir_umask=`umask`
- umask 0077
- $mkdir "$my_tmpdir"
- umask $save_mktempdir_umask
- fi
-
- # If we're not in dry-run mode, bomb out on failure
- test -d "$my_tmpdir" || {
- $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2
- exit $EXIT_FAILURE
- }
- fi
-
- $echo "X$my_tmpdir" | $Xsed
-}
-
-
-# func_win32_libid arg
-# return the library type of file 'arg'
-#
-# Need a lot of goo to handle *both* DLLs and import libs
-# Has to be a shell function in order to 'eat' the argument
-# that is supplied when $file_magic_command is called.
-func_win32_libid ()
-{
- win32_libid_type="unknown"
- win32_fileres=`file -L $1 2>/dev/null`
- case $win32_fileres in
- *ar\ archive\ import\ library*) # definitely import
- win32_libid_type="x86 archive import"
- ;;
- *ar\ archive*) # could be an import, or static
- if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \
- $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
- win32_nmres=`eval $NM -f posix -A $1 | \
- $SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'`
- case $win32_nmres in
- import*) win32_libid_type="x86 archive import";;
- *) win32_libid_type="x86 archive static";;
- esac
- fi
- ;;
- *DLL*)
- win32_libid_type="x86 DLL"
- ;;
- *executable*) # but shell scripts are "executable" too...
- case $win32_fileres in
- *MS\ Windows\ PE\ Intel*)
- win32_libid_type="x86 DLL"
- ;;
- esac
- ;;
- esac
- $echo $win32_libid_type
-}
-
-
-# func_infer_tag arg
-# Infer tagged configuration to use if any are available and
-# if one wasn't chosen via the "--tag" command line option.
-# Only attempt this if the compiler in the base compile
-# command doesn't match the default compiler.
-# arg is usually of the form 'gcc ...'
-func_infer_tag ()
-{
- if test -n "$available_tags" && test -z "$tagname"; then
- CC_quoted=
- for arg in $CC; do
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- CC_quoted="$CC_quoted $arg"
- done
- case $@ in
- # Blanks in the command may have been stripped by the calling shell,
- # but not from the CC environment variable when configure was run.
- " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;;
- # Blanks at the start of $base_compile will cause this to fail
- # if we don't check for them as well.
- *)
- for z in $available_tags; do
- if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
- # Evaluate the configuration.
- eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
- CC_quoted=
- for arg in $CC; do
- # Double-quote args containing other shell metacharacters.
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- CC_quoted="$CC_quoted $arg"
- done
- case "$@ " in
- " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*)
- # The compiler in the base compile command matches
- # the one in the tagged configuration.
- # Assume this is the tagged configuration we want.
- tagname=$z
- break
- ;;
- esac
- fi
- done
- # If $tagname still isn't set, then no tagged configuration
- # was found and let the user know that the "--tag" command
- # line option must be used.
- if test -z "$tagname"; then
- $echo "$modename: unable to infer tagged configuration"
- $echo "$modename: specify a tag with \`--tag'" 1>&2
- exit $EXIT_FAILURE
-# else
-# $echo "$modename: using $tagname tagged configuration"
- fi
- ;;
- esac
- fi
-}
-
-
-# func_extract_an_archive dir oldlib
-func_extract_an_archive ()
-{
- f_ex_an_ar_dir="$1"; shift
- f_ex_an_ar_oldlib="$1"
-
- $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)"
- $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $?
- if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
- :
- else
- $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2
- exit $EXIT_FAILURE
- fi
-}
-
-# func_extract_archives gentop oldlib ...
-func_extract_archives ()
-{
- my_gentop="$1"; shift
- my_oldlibs=${1+"$@"}
- my_oldobjs=""
- my_xlib=""
- my_xabs=""
- my_xdir=""
- my_status=""
-
- $show "${rm}r $my_gentop"
- $run ${rm}r "$my_gentop"
- $show "$mkdir $my_gentop"
- $run $mkdir "$my_gentop"
- my_status=$?
- if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then
- exit $my_status
- fi
-
- for my_xlib in $my_oldlibs; do
- # Extract the objects.
- case $my_xlib in
- [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
- *) my_xabs=`pwd`"/$my_xlib" ;;
- esac
- my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'`
- my_xdir="$my_gentop/$my_xlib"
-
- $show "${rm}r $my_xdir"
- $run ${rm}r "$my_xdir"
- $show "$mkdir $my_xdir"
- $run $mkdir "$my_xdir"
- exit_status=$?
- if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then
- exit $exit_status
- fi
- case $host in
- *-darwin*)
- $show "Extracting $my_xabs"
- # Do not bother doing anything if just a dry run
- if test -z "$run"; then
- darwin_orig_dir=`pwd`
- cd $my_xdir || exit $?
- darwin_archive=$my_xabs
- darwin_curdir=`pwd`
- darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'`
- darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null`
- if test -n "$darwin_arches"; then
- darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'`
- darwin_arch=
- $show "$darwin_base_archive has multiple architectures $darwin_arches"
- for darwin_arch in $darwin_arches ; do
- mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
- lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
- cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
- func_extract_an_archive "`pwd`" "${darwin_base_archive}"
- cd "$darwin_curdir"
- $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
- done # $darwin_arches
- ## Okay now we have a bunch of thin objects, gotta fatten them up :)
- darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP`
- darwin_file=
- darwin_files=
- for darwin_file in $darwin_filelist; do
- darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
- lipo -create -output "$darwin_file" $darwin_files
- done # $darwin_filelist
- ${rm}r unfat-$$
- cd "$darwin_orig_dir"
- else
- cd "$darwin_orig_dir"
- func_extract_an_archive "$my_xdir" "$my_xabs"
- fi # $darwin_arches
- fi # $run
- ;;
- *)
- func_extract_an_archive "$my_xdir" "$my_xabs"
- ;;
- esac
- my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
- done
- func_extract_archives_result="$my_oldobjs"
-}
-# End of Shell function definitions
-#####################################
-
-# Darwin sucks
-eval std_shrext=\"$shrext_cmds\"
-
-disable_libs=no
-
-# Parse our command line options once, thoroughly.
-while test "$#" -gt 0
-do
- arg="$1"
- shift
-
- case $arg in
- -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;;
- *) optarg= ;;
- esac
-
- # If the previous option needs an argument, assign it.
- if test -n "$prev"; then
- case $prev in
- execute_dlfiles)
- execute_dlfiles="$execute_dlfiles $arg"
- ;;
- tag)
- tagname="$arg"
- preserve_args="${preserve_args}=$arg"
-
- # Check whether tagname contains only valid characters
- case $tagname in
- *[!-_A-Za-z0-9,/]*)
- $echo "$progname: invalid tag name: $tagname" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- case $tagname in
- CC)
- # Don't test for the "default" C tag, as we know, it's there, but
- # not specially marked.
- ;;
- *)
- if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then
- taglist="$taglist $tagname"
- # Evaluate the configuration.
- eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`"
- else
- $echo "$progname: ignoring unknown tag $tagname" 1>&2
- fi
- ;;
- esac
- ;;
- *)
- eval "$prev=\$arg"
- ;;
- esac
-
- prev=
- prevopt=
- continue
- fi
-
- # Have we seen a non-optional argument yet?
- case $arg in
- --help)
- show_help=yes
- ;;
-
- --version)
- $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP"
- $echo
- $echo "Copyright (C) 2005 Free Software Foundation, Inc."
- $echo "This is free software; see the source for copying conditions. There is NO"
- $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
- exit $?
- ;;
-
- --config)
- ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath
- # Now print the configurations for the tags.
- for tagname in $taglist; do
- ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath"
- done
- exit $?
- ;;
-
- --debug)
- $echo "$progname: enabling shell trace mode"
- set -x
- preserve_args="$preserve_args $arg"
- ;;
-
- --dry-run | -n)
- run=:
- ;;
-
- --features)
- $echo "host: $host"
- if test "$build_libtool_libs" = yes; then
- $echo "enable shared libraries"
- else
- $echo "disable shared libraries"
- fi
- if test "$build_old_libs" = yes; then
- $echo "enable static libraries"
- else
- $echo "disable static libraries"
- fi
- exit $?
- ;;
-
- --finish) mode="finish" ;;
-
- --mode) prevopt="--mode" prev=mode ;;
- --mode=*) mode="$optarg" ;;
-
- --preserve-dup-deps) duplicate_deps="yes" ;;
-
- --quiet | --silent)
- show=:
- preserve_args="$preserve_args $arg"
- ;;
-
- --tag)
- prevopt="--tag"
- prev=tag
- preserve_args="$preserve_args --tag"
- ;;
- --tag=*)
- set tag "$optarg" ${1+"$@"}
- shift
- prev=tag
- preserve_args="$preserve_args --tag"
- ;;
-
- -dlopen)
- prevopt="-dlopen"
- prev=execute_dlfiles
- ;;
-
- -*)
- $echo "$modename: unrecognized option \`$arg'" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- ;;
-
- *)
- nonopt="$arg"
- break
- ;;
- esac
-done
-
-if test -n "$prevopt"; then
- $echo "$modename: option \`$prevopt' requires an argument" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
-fi
-
-case $disable_libs in
-no)
- ;;
-shared)
- build_libtool_libs=no
- build_old_libs=yes
- ;;
-static)
- build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
- ;;
-esac
-
-# If this variable is set in any of the actions, the command in it
-# will be execed at the end. This prevents here-documents from being
-# left over by shells.
-exec_cmd=
-
-if test -z "$show_help"; then
-
- # Infer the operation mode.
- if test -z "$mode"; then
- $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2
- $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2
- case $nonopt in
- *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*)
- mode=link
- for arg
- do
- case $arg in
- -c)
- mode=compile
- break
- ;;
- esac
- done
- ;;
- *db | *dbx | *strace | *truss)
- mode=execute
- ;;
- *install*|cp|mv)
- mode=install
- ;;
- *rm)
- mode=uninstall
- ;;
- *)
- # If we have no mode, but dlfiles were specified, then do execute mode.
- test -n "$execute_dlfiles" && mode=execute
-
- # Just use the default operation mode.
- if test -z "$mode"; then
- if test -n "$nonopt"; then
- $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2
- else
- $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2
- fi
- fi
- ;;
- esac
- fi
-
- # Only execute mode is allowed to have -dlopen flags.
- if test -n "$execute_dlfiles" && test "$mode" != execute; then
- $echo "$modename: unrecognized option \`-dlopen'" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Change the help message to a mode-specific one.
- generic_help="$help"
- help="Try \`$modename --help --mode=$mode' for more information."
-
- # These modes are in order of execution frequency so that they run quickly.
- case $mode in
- # libtool compile mode
- compile)
- modename="$modename: compile"
- # Get the compilation command and the source file.
- base_compile=
- srcfile="$nonopt" # always keep a non-empty value in "srcfile"
- suppress_opt=yes
- suppress_output=
- arg_mode=normal
- libobj=
- later=
-
- for arg
- do
- case $arg_mode in
- arg )
- # do not "continue". Instead, add this to base_compile
- lastarg="$arg"
- arg_mode=normal
- ;;
-
- target )
- libobj="$arg"
- arg_mode=normal
- continue
- ;;
-
- normal )
- # Accept any command-line options.
- case $arg in
- -o)
- if test -n "$libobj" ; then
- $echo "$modename: you cannot specify \`-o' more than once" 1>&2
- exit $EXIT_FAILURE
- fi
- arg_mode=target
- continue
- ;;
-
- -static | -prefer-pic | -prefer-non-pic)
- later="$later $arg"
- continue
- ;;
-
- -no-suppress)
- suppress_opt=no
- continue
- ;;
-
- -Xcompiler)
- arg_mode=arg # the next one goes into the "base_compile" arg list
- continue # The current "srcfile" will either be retained or
- ;; # replaced later. I would guess that would be a bug.
-
- -Wc,*)
- args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"`
- lastarg=
- save_ifs="$IFS"; IFS=','
- for arg in $args; do
- IFS="$save_ifs"
-
- # Double-quote args containing other shell metacharacters.
- # Many Bourne shells cannot handle close brackets correctly
- # in scan sets, so we specify it separately.
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- lastarg="$lastarg $arg"
- done
- IFS="$save_ifs"
- lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"`
-
- # Add the arguments to base_compile.
- base_compile="$base_compile $lastarg"
- continue
- ;;
-
- * )
- # Accept the current argument as the source file.
- # The previous "srcfile" becomes the current argument.
- #
- lastarg="$srcfile"
- srcfile="$arg"
- ;;
- esac # case $arg
- ;;
- esac # case $arg_mode
-
- # Aesthetically quote the previous argument.
- lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"`
-
- case $lastarg in
- # Double-quote args containing other shell metacharacters.
- # Many Bourne shells cannot handle close brackets correctly
- # in scan sets, and some SunOS ksh mistreat backslash-escaping
- # in scan sets (worked around with variable expansion),
- # and furthermore cannot handle '|' '&' '(' ')' in scan sets
- # at all, so we specify them separately.
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- lastarg="\"$lastarg\""
- ;;
- esac
-
- base_compile="$base_compile $lastarg"
- done # for arg
-
- case $arg_mode in
- arg)
- $echo "$modename: you must specify an argument for -Xcompile"
- exit $EXIT_FAILURE
- ;;
- target)
- $echo "$modename: you must specify a target with \`-o'" 1>&2
- exit $EXIT_FAILURE
- ;;
- *)
- # Get the name of the library object.
- [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'`
- ;;
- esac
-
- # Recognize several different file suffixes.
- # If the user specifies -o file.o, it is replaced with file.lo
- xform='[cCFSifmso]'
- case $libobj in
- *.ada) xform=ada ;;
- *.adb) xform=adb ;;
- *.ads) xform=ads ;;
- *.asm) xform=asm ;;
- *.c++) xform=c++ ;;
- *.cc) xform=cc ;;
- *.ii) xform=ii ;;
- *.class) xform=class ;;
- *.cpp) xform=cpp ;;
- *.cxx) xform=cxx ;;
- *.f90) xform=f90 ;;
- *.for) xform=for ;;
- *.java) xform=java ;;
- esac
-
- libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"`
-
- case $libobj in
- *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;;
- *)
- $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- func_infer_tag $base_compile
-
- for arg in $later; do
- case $arg in
- -static)
- build_old_libs=yes
- continue
- ;;
-
- -prefer-pic)
- pic_mode=yes
- continue
- ;;
-
- -prefer-non-pic)
- pic_mode=no
- continue
- ;;
- esac
- done
-
- qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"`
- case $qlibobj in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- qlibobj="\"$qlibobj\"" ;;
- esac
- test "X$libobj" != "X$qlibobj" \
- && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' &()|`$[]' \
- && $echo "$modename: libobj name \`$libobj' may not contain shell special characters."
- objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
- xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$xdir" = "X$obj"; then
- xdir=
- else
- xdir=$xdir/
- fi
- lobj=${xdir}$objdir/$objname
-
- if test -z "$base_compile"; then
- $echo "$modename: you must specify a compilation command" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Delete any leftover library objects.
- if test "$build_old_libs" = yes; then
- removelist="$obj $lobj $libobj ${libobj}T"
- else
- removelist="$lobj $libobj ${libobj}T"
- fi
-
- $run $rm $removelist
- trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15
-
- # On Cygwin there's no "real" PIC flag so we must build both object types
- case $host_os in
- cygwin* | mingw* | pw32* | os2*)
- pic_mode=default
- ;;
- esac
- if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
- # non-PIC code in shared libraries is not supported
- pic_mode=default
- fi
-
- # Calculate the filename of the output object if compiler does
- # not support -o with -c
- if test "$compiler_c_o" = no; then
- output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
- lockfile="$output_obj.lock"
- removelist="$removelist $output_obj $lockfile"
- trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15
- else
- output_obj=
- need_locks=no
- lockfile=
- fi
-
- # Lock this critical section if it is needed
- # We use this script file to make the link, it avoids creating a new file
- if test "$need_locks" = yes; then
- until $run ln "$progpath" "$lockfile" 2>/dev/null; do
- $show "Waiting for $lockfile to be removed"
- sleep 2
- done
- elif test "$need_locks" = warn; then
- if test -f "$lockfile"; then
- $echo "\
-*** ERROR, $lockfile exists and contains:
-`cat $lockfile 2>/dev/null`
-
-This indicates that another process is trying to use the same
-temporary object file, and libtool could not work around it because
-your compiler does not support \`-c' and \`-o' together. If you
-repeat this compilation, it may succeed, by chance, but you had better
-avoid parallel builds (make -j) in this platform, or get a better
-compiler."
-
- $run $rm $removelist
- exit $EXIT_FAILURE
- fi
- $echo "$srcfile" > "$lockfile"
- fi
-
- if test -n "$fix_srcfile_path"; then
- eval srcfile=\"$fix_srcfile_path\"
- fi
- qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"`
- case $qsrcfile in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- qsrcfile="\"$qsrcfile\"" ;;
- esac
-
- $run $rm "$libobj" "${libobj}T"
-
- # Create a libtool object file (analogous to a ".la" file),
- # but don't create it if we're doing a dry run.
- test -z "$run" && cat > ${libobj}T <<EOF
-# $libobj - a libtool object file
-# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# Name of the PIC object.
-EOF
-
- # Only build a PIC object if we are building libtool libraries.
- if test "$build_libtool_libs" = yes; then
- # Without this assignment, base_compile gets emptied.
- fbsd_hideous_sh_bug=$base_compile
-
- if test "$pic_mode" != no; then
- command="$base_compile $qsrcfile $pic_flag"
- else
- # Don't build PIC code
- command="$base_compile $qsrcfile"
- fi
-
- if test ! -d "${xdir}$objdir"; then
- $show "$mkdir ${xdir}$objdir"
- $run $mkdir ${xdir}$objdir
- exit_status=$?
- if test "$exit_status" -ne 0 && test ! -d "${xdir}$objdir"; then
- exit $exit_status
- fi
- fi
-
- if test -z "$output_obj"; then
- # Place PIC objects in $objdir
- command="$command -o $lobj"
- fi
-
- $run $rm "$lobj" "$output_obj"
-
- $show "$command"
- if $run eval "$command"; then :
- else
- test -n "$output_obj" && $run $rm $removelist
- exit $EXIT_FAILURE
- fi
-
- if test "$need_locks" = warn &&
- test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
- $echo "\
-*** ERROR, $lockfile contains:
-`cat $lockfile 2>/dev/null`
-
-but it should contain:
-$srcfile
-
-This indicates that another process is trying to use the same
-temporary object file, and libtool could not work around it because
-your compiler does not support \`-c' and \`-o' together. If you
-repeat this compilation, it may succeed, by chance, but you had better
-avoid parallel builds (make -j) in this platform, or get a better
-compiler."
-
- $run $rm $removelist
- exit $EXIT_FAILURE
- fi
-
- # Just move the object if needed, then go on to compile the next one
- if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
- $show "$mv $output_obj $lobj"
- if $run $mv $output_obj $lobj; then :
- else
- error=$?
- $run $rm $removelist
- exit $error
- fi
- fi
-
- # Append the name of the PIC object to the libtool object file.
- test -z "$run" && cat >> ${libobj}T <<EOF
-pic_object='$objdir/$objname'
-
-EOF
-
- # Allow error messages only from the first compilation.
- if test "$suppress_opt" = yes; then
- suppress_output=' >/dev/null 2>&1'
- fi
- else
- # No PIC object so indicate it doesn't exist in the libtool
- # object file.
- test -z "$run" && cat >> ${libobj}T <<EOF
-pic_object=none
-
-EOF
- fi
-
- # Only build a position-dependent object if we build old libraries.
- if test "$build_old_libs" = yes; then
- if test "$pic_mode" != yes; then
- # Don't build PIC code
- command="$base_compile $qsrcfile"
- else
- command="$base_compile $qsrcfile $pic_flag"
- fi
- if test "$compiler_c_o" = yes; then
- command="$command -o $obj"
- fi
-
- # Suppress compiler output if we already did a PIC compilation.
- command="$command$suppress_output"
- $run $rm "$obj" "$output_obj"
- $show "$command"
- if $run eval "$command"; then :
- else
- $run $rm $removelist
- exit $EXIT_FAILURE
- fi
-
- if test "$need_locks" = warn &&
- test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
- $echo "\
-*** ERROR, $lockfile contains:
-`cat $lockfile 2>/dev/null`
-
-but it should contain:
-$srcfile
-
-This indicates that another process is trying to use the same
-temporary object file, and libtool could not work around it because
-your compiler does not support \`-c' and \`-o' together. If you
-repeat this compilation, it may succeed, by chance, but you had better
-avoid parallel builds (make -j) in this platform, or get a better
-compiler."
-
- $run $rm $removelist
- exit $EXIT_FAILURE
- fi
-
- # Just move the object if needed
- if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
- $show "$mv $output_obj $obj"
- if $run $mv $output_obj $obj; then :
- else
- error=$?
- $run $rm $removelist
- exit $error
- fi
- fi
-
- # Append the name of the non-PIC object the libtool object file.
- # Only append if the libtool object file exists.
- test -z "$run" && cat >> ${libobj}T <<EOF
-# Name of the non-PIC object.
-non_pic_object='$objname'
-
-EOF
- else
- # Append the name of the non-PIC object the libtool object file.
- # Only append if the libtool object file exists.
- test -z "$run" && cat >> ${libobj}T <<EOF
-# Name of the non-PIC object.
-non_pic_object=none
-
-EOF
- fi
-
- $run $mv "${libobj}T" "${libobj}"
-
- # Unlock the critical section if it was locked
- if test "$need_locks" != no; then
- $run $rm "$lockfile"
- fi
-
- exit $EXIT_SUCCESS
- ;;
-
- # libtool link mode
- link | relink)
- modename="$modename: link"
- case $host in
- *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
- # It is impossible to link a dll without this setting, and
- # we shouldn't force the makefile maintainer to figure out
- # which system we are compiling for in order to pass an extra
- # flag for every libtool invocation.
- # allow_undefined=no
-
- # FIXME: Unfortunately, there are problems with the above when trying
- # to make a dll which has undefined symbols, in which case not
- # even a static library is built. For now, we need to specify
- # -no-undefined on the libtool link line when we can be certain
- # that all symbols are satisfied, otherwise we get a static library.
- allow_undefined=yes
- ;;
- *)
- allow_undefined=yes
- ;;
- esac
- libtool_args="$nonopt"
- base_compile="$nonopt $@"
- compile_command="$nonopt"
- finalize_command="$nonopt"
-
- compile_rpath=
- finalize_rpath=
- compile_shlibpath=
- finalize_shlibpath=
- convenience=
- old_convenience=
- deplibs=
- old_deplibs=
- compiler_flags=
- linker_flags=
- dllsearchpath=
- lib_search_path=`pwd`
- inst_prefix_dir=
-
- avoid_version=no
- dlfiles=
- dlprefiles=
- dlself=no
- export_dynamic=no
- export_symbols=
- export_symbols_regex=
- generated=
- libobjs=
- ltlibs=
- module=no
- no_install=no
- objs=
- non_pic_objects=
- notinst_path= # paths that contain not-installed libtool libraries
- precious_files_regex=
- prefer_static_libs=no
- preload=no
- prev=
- prevarg=
- release=
- rpath=
- xrpath=
- perm_rpath=
- temp_rpath=
- thread_safe=no
- vinfo=
- vinfo_number=no
-
- func_infer_tag $base_compile
-
- # We need to know -static, to get the right output filenames.
- for arg
- do
- case $arg in
- -all-static | -static)
- if test "X$arg" = "X-all-static"; then
- if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
- $echo "$modename: warning: complete static linking is impossible in this configuration" 1>&2
- fi
- if test -n "$link_static_flag"; then
- dlopen_self=$dlopen_self_static
- fi
- prefer_static_libs=yes
- else
- if test -z "$pic_flag" && test -n "$link_static_flag"; then
- dlopen_self=$dlopen_self_static
- fi
- prefer_static_libs=built
- fi
- build_libtool_libs=no
- build_old_libs=yes
- break
- ;;
- esac
- done
-
- # See if our shared archives depend on static archives.
- test -n "$old_archive_from_new_cmds" && build_old_libs=yes
-
- # Go through the arguments, transforming them on the way.
- while test "$#" -gt 0; do
- arg="$1"
- shift
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test
- ;;
- *) qarg=$arg ;;
- esac
- libtool_args="$libtool_args $qarg"
-
- # If the previous option needs an argument, assign it.
- if test -n "$prev"; then
- case $prev in
- output)
- compile_command="$compile_command @OUTPUT@"
- finalize_command="$finalize_command @OUTPUT@"
- ;;
- esac
-
- case $prev in
- dlfiles|dlprefiles)
- if test "$preload" = no; then
- # Add the symbol object into the linking commands.
- compile_command="$compile_command @SYMFILE@"
- finalize_command="$finalize_command @SYMFILE@"
- preload=yes
- fi
- case $arg in
- *.la | *.lo) ;; # We handle these cases below.
- force)
- if test "$dlself" = no; then
- dlself=needless
- export_dynamic=yes
- fi
- prev=
- continue
- ;;
- self)
- if test "$prev" = dlprefiles; then
- dlself=yes
- elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
- dlself=yes
- else
- dlself=needless
- export_dynamic=yes
- fi
- prev=
- continue
- ;;
- *)
- if test "$prev" = dlfiles; then
- dlfiles="$dlfiles $arg"
- else
- dlprefiles="$dlprefiles $arg"
- fi
- prev=
- continue
- ;;
- esac
- ;;
- expsyms)
- export_symbols="$arg"
- if test ! -f "$arg"; then
- $echo "$modename: symbol file \`$arg' does not exist"
- exit $EXIT_FAILURE
- fi
- prev=
- continue
- ;;
- expsyms_regex)
- export_symbols_regex="$arg"
- prev=
- continue
- ;;
- inst_prefix)
- inst_prefix_dir="$arg"
- prev=
- continue
- ;;
- precious_regex)
- precious_files_regex="$arg"
- prev=
- continue
- ;;
- release)
- release="-$arg"
- prev=
- continue
- ;;
- objectlist)
- if test -f "$arg"; then
- save_arg=$arg
- moreargs=
- for fil in `cat $save_arg`
- do
-# moreargs="$moreargs $fil"
- arg=$fil
- # A libtool-controlled object.
-
- # Check to see that this really is a libtool object.
- if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
- pic_object=
- non_pic_object=
-
- # Read the .lo file
- # If there is no directory component, then add one.
- case $arg in
- */* | *\\*) . $arg ;;
- *) . ./$arg ;;
- esac
-
- if test -z "$pic_object" || \
- test -z "$non_pic_object" ||
- test "$pic_object" = none && \
- test "$non_pic_object" = none; then
- $echo "$modename: cannot find name of object for \`$arg'" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Extract subdirectory from the argument.
- xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$xdir" = "X$arg"; then
- xdir=
- else
- xdir="$xdir/"
- fi
-
- if test "$pic_object" != none; then
- # Prepend the subdirectory the object is found in.
- pic_object="$xdir$pic_object"
-
- if test "$prev" = dlfiles; then
- if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
- dlfiles="$dlfiles $pic_object"
- prev=
- continue
- else
- # If libtool objects are unsupported, then we need to preload.
- prev=dlprefiles
- fi
- fi
-
- # CHECK ME: I think I busted this. -Ossama
- if test "$prev" = dlprefiles; then
- # Preload the old-style object.
- dlprefiles="$dlprefiles $pic_object"
- prev=
- fi
-
- # A PIC object.
- libobjs="$libobjs $pic_object"
- arg="$pic_object"
- fi
-
- # Non-PIC object.
- if test "$non_pic_object" != none; then
- # Prepend the subdirectory the object is found in.
- non_pic_object="$xdir$non_pic_object"
-
- # A standard non-PIC object
- non_pic_objects="$non_pic_objects $non_pic_object"
- if test -z "$pic_object" || test "$pic_object" = none ; then
- arg="$non_pic_object"
- fi
- else
- # If the PIC object exists, use it instead.
- # $xdir was prepended to $pic_object above.
- non_pic_object="$pic_object"
- non_pic_objects="$non_pic_objects $non_pic_object"
- fi
- else
- # Only an error if not doing a dry-run.
- if test -z "$run"; then
- $echo "$modename: \`$arg' is not a valid libtool object" 1>&2
- exit $EXIT_FAILURE
- else
- # Dry-run case.
-
- # Extract subdirectory from the argument.
- xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$xdir" = "X$arg"; then
- xdir=
- else
- xdir="$xdir/"
- fi
-
- pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
- non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"`
- libobjs="$libobjs $pic_object"
- non_pic_objects="$non_pic_objects $non_pic_object"
- fi
- fi
- done
- else
- $echo "$modename: link input file \`$save_arg' does not exist"
- exit $EXIT_FAILURE
- fi
- arg=$save_arg
- prev=
- continue
- ;;
- rpath | xrpath)
- # We need an absolute path.
- case $arg in
- [\\/]* | [A-Za-z]:[\\/]*) ;;
- *)
- $echo "$modename: only absolute run-paths are allowed" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
- if test "$prev" = rpath; then
- case "$rpath " in
- *" $arg "*) ;;
- *) rpath="$rpath $arg" ;;
- esac
- else
- case "$xrpath " in
- *" $arg "*) ;;
- *) xrpath="$xrpath $arg" ;;
- esac
- fi
- prev=
- continue
- ;;
- xcompiler)
- compiler_flags="$compiler_flags $qarg"
- prev=
- compile_command="$compile_command $qarg"
- finalize_command="$finalize_command $qarg"
- continue
- ;;
- xlinker)
- linker_flags="$linker_flags $qarg"
- compiler_flags="$compiler_flags $wl$qarg"
- prev=
- compile_command="$compile_command $wl$qarg"
- finalize_command="$finalize_command $wl$qarg"
- continue
- ;;
- xcclinker)
- linker_flags="$linker_flags $qarg"
- compiler_flags="$compiler_flags $qarg"
- prev=
- compile_command="$compile_command $qarg"
- finalize_command="$finalize_command $qarg"
- continue
- ;;
- shrext)
- shrext_cmds="$arg"
- prev=
- continue
- ;;
- darwin_framework|darwin_framework_skip)
- test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg"
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- prev=
- continue
- ;;
- *)
- eval "$prev=\"\$arg\""
- prev=
- continue
- ;;
- esac
- fi # test -n "$prev"
-
- prevarg="$arg"
-
- case $arg in
- -all-static)
- if test -n "$link_static_flag"; then
- compile_command="$compile_command $link_static_flag"
- finalize_command="$finalize_command $link_static_flag"
- fi
- continue
- ;;
-
- -allow-undefined)
- # FIXME: remove this flag sometime in the future.
- $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2
- continue
- ;;
-
- -avoid-version)
- avoid_version=yes
- continue
- ;;
-
- -dlopen)
- prev=dlfiles
- continue
- ;;
-
- -dlpreopen)
- prev=dlprefiles
- continue
- ;;
-
- -export-dynamic)
- export_dynamic=yes
- continue
- ;;
-
- -export-symbols | -export-symbols-regex)
- if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
- $echo "$modename: more than one -exported-symbols argument is not allowed"
- exit $EXIT_FAILURE
- fi
- if test "X$arg" = "X-export-symbols"; then
- prev=expsyms
- else
- prev=expsyms_regex
- fi
- continue
- ;;
-
- -framework|-arch|-isysroot)
- case " $CC " in
- *" ${arg} ${1} "* | *" ${arg} ${1} "*)
- prev=darwin_framework_skip ;;
- *) compiler_flags="$compiler_flags $arg"
- prev=darwin_framework ;;
- esac
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- continue
- ;;
-
- -inst-prefix-dir)
- prev=inst_prefix
- continue
- ;;
-
- # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
- # so, if we see these flags be careful not to treat them like -L
- -L[A-Z][A-Z]*:*)
- case $with_gcc/$host in
- no/*-*-irix* | /*-*-irix*)
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- ;;
- esac
- continue
- ;;
-
- -L*)
- dir=`$echo "X$arg" | $Xsed -e 's/^-L//'`
- # We need an absolute path.
- case $dir in
- [\\/]* | [A-Za-z]:[\\/]*) ;;
- *)
- absdir=`cd "$dir" && pwd`
- if test -z "$absdir"; then
- $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2
- absdir="$dir"
- notinst_path="$notinst_path $dir"
- fi
- dir="$absdir"
- ;;
- esac
- case "$deplibs " in
- *" -L$dir "*) ;;
- *)
- deplibs="$deplibs -L$dir"
- lib_search_path="$lib_search_path $dir"
- ;;
- esac
- case $host in
- *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
- testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'`
- case :$dllsearchpath: in
- *":$dir:"*) ;;
- *) dllsearchpath="$dllsearchpath:$dir";;
- esac
- case :$dllsearchpath: in
- *":$testbindir:"*) ;;
- *) dllsearchpath="$dllsearchpath:$testbindir";;
- esac
- ;;
- esac
- continue
- ;;
-
- -l*)
- if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
- case $host in
- *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*)
- # These systems don't actually have a C or math library (as such)
- continue
- ;;
- *-*-os2*)
- # These systems don't actually have a C library (as such)
- test "X$arg" = "X-lc" && continue
- ;;
- *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
- # Do not include libc due to us having libc/libc_r.
- test "X$arg" = "X-lc" && continue
- ;;
- *-*-rhapsody* | *-*-darwin1.[012])
- # Rhapsody C and math libraries are in the System framework
- deplibs="$deplibs -framework System"
- continue
- ;;
- *-*-sco3.2v5* | *-*-sco5v6*)
- # Causes problems with __ctype
- test "X$arg" = "X-lc" && continue
- ;;
- *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
- # Compiler inserts libc in the correct place for threads to work
- test "X$arg" = "X-lc" && continue
- ;;
- esac
- elif test "X$arg" = "X-lc_r"; then
- case $host in
- *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
- # Do not include libc_r directly, use -pthread flag.
- continue
- ;;
- esac
- fi
- deplibs="$deplibs $arg"
- continue
- ;;
-
- # Tru64 UNIX uses -model [arg] to determine the layout of C++
- # classes, name mangling, and exception handling.
- -model)
- compile_command="$compile_command $arg"
- compiler_flags="$compiler_flags $arg"
- finalize_command="$finalize_command $arg"
- prev=xcompiler
- continue
- ;;
-
- -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe)
- compiler_flags="$compiler_flags $arg"
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- continue
- ;;
-
- -module)
- module=yes
- continue
- ;;
-
- # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
- # -r[0-9][0-9]* specifies the processor on the SGI compiler
- # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
- # +DA*, +DD* enable 64-bit mode on the HP compiler
- # -q* pass through compiler args for the IBM compiler
- # -m* pass through architecture-specific compiler args for GCC
- # -m*, -t[45]*, -txscale* pass through architecture-specific
- # compiler args for GCC
- # -pg pass through profiling flag for GCC
- # @file GCC response files
- -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \
- -t[45]*|-txscale*|@*)
-
- # Unknown arguments in both finalize_command and compile_command need
- # to be aesthetically quoted because they are evaled later.
- arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- compiler_flags="$compiler_flags $arg"
- continue
- ;;
-
- -shrext)
- prev=shrext
- continue
- ;;
-
- -no-fast-install)
- fast_install=no
- continue
- ;;
-
- -no-install)
- case $host in
- *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
- # The PATH hackery in wrapper scripts is required on Windows
- # in order for the loader to find any dlls it needs.
- $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2
- $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2
- fast_install=no
- ;;
- *) no_install=yes ;;
- esac
- continue
- ;;
-
- -no-undefined)
- allow_undefined=no
- continue
- ;;
-
- -objectlist)
- prev=objectlist
- continue
- ;;
-
- -o) prev=output ;;
-
- -precious-files-regex)
- prev=precious_regex
- continue
- ;;
-
- -release)
- prev=release
- continue
- ;;
-
- -rpath)
- prev=rpath
- continue
- ;;
-
- -R)
- prev=xrpath
- continue
- ;;
-
- -R*)
- dir=`$echo "X$arg" | $Xsed -e 's/^-R//'`
- # We need an absolute path.
- case $dir in
- [\\/]* | [A-Za-z]:[\\/]*) ;;
- *)
- $echo "$modename: only absolute run-paths are allowed" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
- case "$xrpath " in
- *" $dir "*) ;;
- *) xrpath="$xrpath $dir" ;;
- esac
- continue
- ;;
-
- -static)
- # The effects of -static are defined in a previous loop.
- # We used to do the same as -all-static on platforms that
- # didn't have a PIC flag, but the assumption that the effects
- # would be equivalent was wrong. It would break on at least
- # Digital Unix and AIX.
- continue
- ;;
-
- -thread-safe)
- thread_safe=yes
- continue
- ;;
-
- -version-info)
- prev=vinfo
- continue
- ;;
- -version-number)
- prev=vinfo
- vinfo_number=yes
- continue
- ;;
-
- -Wc,*)
- args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'`
- arg=
- save_ifs="$IFS"; IFS=','
- for flag in $args; do
- IFS="$save_ifs"
- case $flag in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- flag="\"$flag\""
- ;;
- esac
- arg="$arg $wl$flag"
- compiler_flags="$compiler_flags $flag"
- done
- IFS="$save_ifs"
- arg=`$echo "X$arg" | $Xsed -e "s/^ //"`
- ;;
-
- -Wl,*)
- args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'`
- arg=
- save_ifs="$IFS"; IFS=','
- for flag in $args; do
- IFS="$save_ifs"
- case $flag in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- flag="\"$flag\""
- ;;
- esac
- arg="$arg $wl$flag"
- compiler_flags="$compiler_flags $wl$flag"
- linker_flags="$linker_flags $flag"
- done
- IFS="$save_ifs"
- arg=`$echo "X$arg" | $Xsed -e "s/^ //"`
- ;;
-
- -Xcompiler)
- prev=xcompiler
- continue
- ;;
-
- -Xlinker)
- prev=xlinker
- continue
- ;;
-
- -XCClinker)
- prev=xcclinker
- continue
- ;;
-
- # Some other compiler flag.
- -* | +*)
- # Unknown arguments in both finalize_command and compile_command need
- # to be aesthetically quoted because they are evaled later.
- arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- ;;
-
- *.$objext)
- # A standard object.
- objs="$objs $arg"
- ;;
-
- *.lo)
- # A libtool-controlled object.
-
- # Check to see that this really is a libtool object.
- if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
- pic_object=
- non_pic_object=
-
- # Read the .lo file
- # If there is no directory component, then add one.
- case $arg in
- */* | *\\*) . $arg ;;
- *) . ./$arg ;;
- esac
-
- if test -z "$pic_object" || \
- test -z "$non_pic_object" ||
- test "$pic_object" = none && \
- test "$non_pic_object" = none; then
- $echo "$modename: cannot find name of object for \`$arg'" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Extract subdirectory from the argument.
- xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$xdir" = "X$arg"; then
- xdir=
- else
- xdir="$xdir/"
- fi
-
- if test "$pic_object" != none; then
- # Prepend the subdirectory the object is found in.
- pic_object="$xdir$pic_object"
-
- if test "$prev" = dlfiles; then
- if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
- dlfiles="$dlfiles $pic_object"
- prev=
- continue
- else
- # If libtool objects are unsupported, then we need to preload.
- prev=dlprefiles
- fi
- fi
-
- # CHECK ME: I think I busted this. -Ossama
- if test "$prev" = dlprefiles; then
- # Preload the old-style object.
- dlprefiles="$dlprefiles $pic_object"
- prev=
- fi
-
- # A PIC object.
- libobjs="$libobjs $pic_object"
- arg="$pic_object"
- fi
-
- # Non-PIC object.
- if test "$non_pic_object" != none; then
- # Prepend the subdirectory the object is found in.
- non_pic_object="$xdir$non_pic_object"
-
- # A standard non-PIC object
- non_pic_objects="$non_pic_objects $non_pic_object"
- if test -z "$pic_object" || test "$pic_object" = none ; then
- arg="$non_pic_object"
- fi
- else
- # If the PIC object exists, use it instead.
- # $xdir was prepended to $pic_object above.
- non_pic_object="$pic_object"
- non_pic_objects="$non_pic_objects $non_pic_object"
- fi
- else
- # Only an error if not doing a dry-run.
- if test -z "$run"; then
- $echo "$modename: \`$arg' is not a valid libtool object" 1>&2
- exit $EXIT_FAILURE
- else
- # Dry-run case.
-
- # Extract subdirectory from the argument.
- xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$xdir" = "X$arg"; then
- xdir=
- else
- xdir="$xdir/"
- fi
-
- pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
- non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"`
- libobjs="$libobjs $pic_object"
- non_pic_objects="$non_pic_objects $non_pic_object"
- fi
- fi
- ;;
-
- *.$libext)
- # An archive.
- deplibs="$deplibs $arg"
- old_deplibs="$old_deplibs $arg"
- continue
- ;;
-
- *.la)
- # A libtool-controlled library.
-
- if test "$prev" = dlfiles; then
- # This library was specified with -dlopen.
- dlfiles="$dlfiles $arg"
- prev=
- elif test "$prev" = dlprefiles; then
- # The library was specified with -dlpreopen.
- dlprefiles="$dlprefiles $arg"
- prev=
- else
- deplibs="$deplibs $arg"
- fi
- continue
- ;;
-
- # Some other compiler argument.
- *)
- # Unknown arguments in both finalize_command and compile_command need
- # to be aesthetically quoted because they are evaled later.
- arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- ;;
- esac # arg
-
- # Now actually substitute the argument into the commands.
- if test -n "$arg"; then
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- fi
- done # argument parsing loop
-
- if test -n "$prev"; then
- $echo "$modename: the \`$prevarg' option requires an argument" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
- eval arg=\"$export_dynamic_flag_spec\"
- compile_command="$compile_command $arg"
- finalize_command="$finalize_command $arg"
- fi
-
- oldlibs=
- # calculate the name of the file, without its directory
- outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'`
- libobjs_save="$libobjs"
-
- if test -n "$shlibpath_var"; then
- # get the directories listed in $shlibpath_var
- eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
- else
- shlib_search_path=
- fi
- eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
- eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
-
- output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$output_objdir" = "X$output"; then
- output_objdir="$objdir"
- else
- output_objdir="$output_objdir/$objdir"
- fi
- # Create the object directory.
- if test ! -d "$output_objdir"; then
- $show "$mkdir $output_objdir"
- $run $mkdir $output_objdir
- exit_status=$?
- if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then
- exit $exit_status
- fi
- fi
-
- # Determine the type of output
- case $output in
- "")
- $echo "$modename: you must specify an output file" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- ;;
- *.$libext) linkmode=oldlib ;;
- *.lo | *.$objext) linkmode=obj ;;
- *.la) linkmode=lib ;;
- *) linkmode=prog ;; # Anything else should be a program.
- esac
-
- case $host in
- *cygwin* | *mingw* | *pw32*)
- # don't eliminate duplications in $postdeps and $predeps
- duplicate_compiler_generated_deps=yes
- ;;
- *)
- duplicate_compiler_generated_deps=$duplicate_deps
- ;;
- esac
- specialdeplibs=
-
- libs=
- # Find all interdependent deplibs by searching for libraries
- # that are linked more than once (e.g. -la -lb -la)
- for deplib in $deplibs; do
- if test "X$duplicate_deps" = "Xyes" ; then
- case "$libs " in
- *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
- esac
- fi
- libs="$libs $deplib"
- done
-
- if test "$linkmode" = lib; then
- libs="$predeps $libs $compiler_lib_search_path $postdeps"
-
- # Compute libraries that are listed more than once in $predeps
- # $postdeps and mark them as special (i.e., whose duplicates are
- # not to be eliminated).
- pre_post_deps=
- if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then
- for pre_post_dep in $predeps $postdeps; do
- case "$pre_post_deps " in
- *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
- esac
- pre_post_deps="$pre_post_deps $pre_post_dep"
- done
- fi
- pre_post_deps=
- fi
-
- deplibs=
- newdependency_libs=
- newlib_search_path=
- need_relink=no # whether we're linking any uninstalled libtool libraries
- notinst_deplibs= # not-installed libtool libraries
- case $linkmode in
- lib)
- passes="conv link"
- for file in $dlfiles $dlprefiles; do
- case $file in
- *.la) ;;
- *)
- $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
- done
- ;;
- prog)
- compile_deplibs=
- finalize_deplibs=
- alldeplibs=no
- newdlfiles=
- newdlprefiles=
- passes="conv scan dlopen dlpreopen link"
- ;;
- *) passes="conv"
- ;;
- esac
- for pass in $passes; do
- if test "$linkmode,$pass" = "lib,link" ||
- test "$linkmode,$pass" = "prog,scan"; then
- libs="$deplibs"
- deplibs=
- fi
- if test "$linkmode" = prog; then
- case $pass in
- dlopen) libs="$dlfiles" ;;
- dlpreopen) libs="$dlprefiles" ;;
- link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
- esac
- fi
- if test "$pass" = dlopen; then
- # Collect dlpreopened libraries
- save_deplibs="$deplibs"
- deplibs=
- fi
- for deplib in $libs; do
- lib=
- found=no
- case $deplib in
- -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe)
- if test "$linkmode,$pass" = "prog,link"; then
- compile_deplibs="$deplib $compile_deplibs"
- finalize_deplibs="$deplib $finalize_deplibs"
- else
- compiler_flags="$compiler_flags $deplib"
- fi
- continue
- ;;
- -l*)
- if test "$linkmode" != lib && test "$linkmode" != prog; then
- $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2
- continue
- fi
- name=`$echo "X$deplib" | $Xsed -e 's/^-l//'`
- for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do
- for search_ext in .la $std_shrext .so .a; do
- # Search the libtool library
- lib="$searchdir/lib${name}${search_ext}"
- if test -f "$lib"; then
- if test "$search_ext" = ".la"; then
- found=yes
- else
- found=no
- fi
- break 2
- fi
- done
- done
- if test "$found" != yes; then
- # deplib doesn't seem to be a libtool library
- if test "$linkmode,$pass" = "prog,link"; then
- compile_deplibs="$deplib $compile_deplibs"
- finalize_deplibs="$deplib $finalize_deplibs"
- else
- deplibs="$deplib $deplibs"
- test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
- fi
- continue
- else # deplib is a libtool library
- # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
- # We need to do some special things here, and not later.
- if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
- case " $predeps $postdeps " in
- *" $deplib "*)
- if (${SED} -e '2q' $lib |
- grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
- library_names=
- old_library=
- case $lib in
- */* | *\\*) . $lib ;;
- *) . ./$lib ;;
- esac
- for l in $old_library $library_names; do
- ll="$l"
- done
- if test "X$ll" = "X$old_library" ; then # only static version available
- found=no
- ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'`
- test "X$ladir" = "X$lib" && ladir="."
- lib=$ladir/$old_library
- if test "$linkmode,$pass" = "prog,link"; then
- compile_deplibs="$deplib $compile_deplibs"
- finalize_deplibs="$deplib $finalize_deplibs"
- else
- deplibs="$deplib $deplibs"
- test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
- fi
- continue
- fi
- fi
- ;;
- *) ;;
- esac
- fi
- fi
- ;; # -l
- -L*)
- case $linkmode in
- lib)
- deplibs="$deplib $deplibs"
- test "$pass" = conv && continue
- newdependency_libs="$deplib $newdependency_libs"
- newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`
- ;;
- prog)
- if test "$pass" = conv; then
- deplibs="$deplib $deplibs"
- continue
- fi
- if test "$pass" = scan; then
- deplibs="$deplib $deplibs"
- else
- compile_deplibs="$deplib $compile_deplibs"
- finalize_deplibs="$deplib $finalize_deplibs"
- fi
- newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`
- ;;
- *)
- $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2
- ;;
- esac # linkmode
- continue
- ;; # -L
- -R*)
- if test "$pass" = link; then
- dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'`
- # Make sure the xrpath contains only unique directories.
- case "$xrpath " in
- *" $dir "*) ;;
- *) xrpath="$xrpath $dir" ;;
- esac
- fi
- deplibs="$deplib $deplibs"
- continue
- ;;
- *.la) lib="$deplib" ;;
- *.$libext)
- if test "$pass" = conv; then
- deplibs="$deplib $deplibs"
- continue
- fi
- case $linkmode in
- lib)
- valid_a_lib=no
- case $deplibs_check_method in
- match_pattern*)
- set dummy $deplibs_check_method
- match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"`
- if eval $echo \"$deplib\" 2>/dev/null \
- | $SED 10q \
- | $EGREP "$match_pattern_regex" > /dev/null; then
- valid_a_lib=yes
- fi
- ;;
- pass_all)
- valid_a_lib=yes
- ;;
- esac
- if test "$valid_a_lib" != yes; then
- $echo
- $echo "*** Warning: Trying to link with static lib archive $deplib."
- $echo "*** I have the capability to make that library automatically link in when"
- $echo "*** you link to this library. But I can only do this if you have a"
- $echo "*** shared version of the library, which you do not appear to have"
- $echo "*** because the file extensions .$libext of this argument makes me believe"
- $echo "*** that it is just a static archive that I should not used here."
- else
- $echo
- $echo "*** Warning: Linking the shared library $output against the"
- $echo "*** static library $deplib is not portable!"
- deplibs="$deplib $deplibs"
- fi
- continue
- ;;
- prog)
- if test "$pass" != link; then
- deplibs="$deplib $deplibs"
- else
- compile_deplibs="$deplib $compile_deplibs"
- finalize_deplibs="$deplib $finalize_deplibs"
- fi
- continue
- ;;
- esac # linkmode
- ;; # *.$libext
- *.lo | *.$objext)
- if test "$pass" = conv; then
- deplibs="$deplib $deplibs"
- elif test "$linkmode" = prog; then
- if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
- # If there is no dlopen support or we're linking statically,
- # we need to preload.
- newdlprefiles="$newdlprefiles $deplib"
- compile_deplibs="$deplib $compile_deplibs"
- finalize_deplibs="$deplib $finalize_deplibs"
- else
- newdlfiles="$newdlfiles $deplib"
- fi
- fi
- continue
- ;;
- %DEPLIBS%)
- alldeplibs=yes
- continue
- ;;
- esac # case $deplib
- if test "$found" = yes || test -f "$lib"; then :
- else
- $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Check to see that this really is a libtool archive.
- if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
- else
- $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
- exit $EXIT_FAILURE
- fi
-
- ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'`
- test "X$ladir" = "X$lib" && ladir="."
-
- dlname=
- dlopen=
- dlpreopen=
- libdir=
- library_names=
- old_library=
- # If the library was installed with an old release of libtool,
- # it will not redefine variables installed, or shouldnotlink
- installed=yes
- shouldnotlink=no
- avoidtemprpath=
-
-
- # Read the .la file
- case $lib in
- */* | *\\*) . $lib ;;
- *) . ./$lib ;;
- esac
-
- if test "$linkmode,$pass" = "lib,link" ||
- test "$linkmode,$pass" = "prog,scan" ||
- { test "$linkmode" != prog && test "$linkmode" != lib; }; then
- test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
- test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
- fi
-
- if test "$pass" = conv; then
- # Only check for convenience libraries
- deplibs="$lib $deplibs"
- if test -z "$libdir"; then
- if test -z "$old_library"; then
- $echo "$modename: cannot find name of link library for \`$lib'" 1>&2
- exit $EXIT_FAILURE
- fi
- # It is a libtool convenience library, so add in its objects.
- convenience="$convenience $ladir/$objdir/$old_library"
- old_convenience="$old_convenience $ladir/$objdir/$old_library"
- tmp_libs=
- for deplib in $dependency_libs; do
- deplibs="$deplib $deplibs"
- if test "X$duplicate_deps" = "Xyes" ; then
- case "$tmp_libs " in
- *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
- esac
- fi
- tmp_libs="$tmp_libs $deplib"
- done
- elif test "$linkmode" != prog && test "$linkmode" != lib; then
- $echo "$modename: \`$lib' is not a convenience library" 1>&2
- exit $EXIT_FAILURE
- fi
- continue
- fi # $pass = conv
-
-
- # Get the name of the library we link against.
- linklib=
- for l in $old_library $library_names; do
- linklib="$l"
- done
- if test -z "$linklib"; then
- $echo "$modename: cannot find name of link library for \`$lib'" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # This library was specified with -dlopen.
- if test "$pass" = dlopen; then
- if test -z "$libdir"; then
- $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2
- exit $EXIT_FAILURE
- fi
- if test -z "$dlname" ||
- test "$dlopen_support" != yes ||
- test "$build_libtool_libs" = no; then
- # If there is no dlname, no dlopen support or we're linking
- # statically, we need to preload. We also need to preload any
- # dependent libraries so libltdl's deplib preloader doesn't
- # bomb out in the load deplibs phase.
- dlprefiles="$dlprefiles $lib $dependency_libs"
- else
- newdlfiles="$newdlfiles $lib"
- fi
- continue
- fi # $pass = dlopen
-
- # We need an absolute path.
- case $ladir in
- [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;;
- *)
- abs_ladir=`cd "$ladir" && pwd`
- if test -z "$abs_ladir"; then
- $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2
- $echo "$modename: passing it literally to the linker, although it might fail" 1>&2
- abs_ladir="$ladir"
- fi
- ;;
- esac
- laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
-
- # Find the relevant object directory and library name.
- if test "X$installed" = Xyes; then
- if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
- $echo "$modename: warning: library \`$lib' was moved." 1>&2
- dir="$ladir"
- absdir="$abs_ladir"
- libdir="$abs_ladir"
- else
- dir="$libdir"
- absdir="$libdir"
- fi
- test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
- else
- if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
- dir="$ladir"
- absdir="$abs_ladir"
- # Remove this search path later
- notinst_path="$notinst_path $abs_ladir"
- else
- dir="$ladir/$objdir"
- absdir="$abs_ladir/$objdir"
- # Remove this search path later
- notinst_path="$notinst_path $abs_ladir"
- fi
- fi # $installed = yes
- name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
-
- # This library was specified with -dlpreopen.
- if test "$pass" = dlpreopen; then
- if test -z "$libdir"; then
- $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2
- exit $EXIT_FAILURE
- fi
- # Prefer using a static library (so that no silly _DYNAMIC symbols
- # are required to link).
- if test -n "$old_library"; then
- newdlprefiles="$newdlprefiles $dir/$old_library"
- # Otherwise, use the dlname, so that lt_dlopen finds it.
- elif test -n "$dlname"; then
- newdlprefiles="$newdlprefiles $dir/$dlname"
- else
- newdlprefiles="$newdlprefiles $dir/$linklib"
- fi
- fi # $pass = dlpreopen
-
- if test -z "$libdir"; then
- # Link the convenience library
- if test "$linkmode" = lib; then
- deplibs="$dir/$old_library $deplibs"
- elif test "$linkmode,$pass" = "prog,link"; then
- compile_deplibs="$dir/$old_library $compile_deplibs"
- finalize_deplibs="$dir/$old_library $finalize_deplibs"
- else
- deplibs="$lib $deplibs" # used for prog,scan pass
- fi
- continue
- fi
-
-
- if test "$linkmode" = prog && test "$pass" != link; then
- newlib_search_path="$newlib_search_path $ladir"
- deplibs="$lib $deplibs"
-
- linkalldeplibs=no
- if test "$link_all_deplibs" != no || test -z "$library_names" ||
- test "$build_libtool_libs" = no; then
- linkalldeplibs=yes
- fi
-
- tmp_libs=
- for deplib in $dependency_libs; do
- case $deplib in
- -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test
- esac
- # Need to link against all dependency_libs?
- if test "$linkalldeplibs" = yes; then
- deplibs="$deplib $deplibs"
- else
- # Need to hardcode shared library paths
- # or/and link against static libraries
- newdependency_libs="$deplib $newdependency_libs"
- fi
- if test "X$duplicate_deps" = "Xyes" ; then
- case "$tmp_libs " in
- *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
- esac
- fi
- tmp_libs="$tmp_libs $deplib"
- done # for deplib
- continue
- fi # $linkmode = prog...
-
- if test "$linkmode,$pass" = "prog,link"; then
- if test -n "$library_names" &&
- { test "$prefer_static_libs" = no || test -z "$old_library"; }; then
- # We need to hardcode the library path
- if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
- # Make sure the rpath contains only unique directories.
- case "$temp_rpath " in
- *" $dir "*) ;;
- *" $absdir "*) ;;
- *) temp_rpath="$temp_rpath $absdir" ;;
- esac
- fi
-
- # Hardcode the library path.
- # Skip directories that are in the system default run-time
- # search path.
- case " $sys_lib_dlsearch_path " in
- *" $absdir "*) ;;
- *)
- case "$compile_rpath " in
- *" $absdir "*) ;;
- *) compile_rpath="$compile_rpath $absdir"
- esac
- ;;
- esac
- case " $sys_lib_dlsearch_path " in
- *" $libdir "*) ;;
- *)
- case "$finalize_rpath " in
- *" $libdir "*) ;;
- *) finalize_rpath="$finalize_rpath $libdir"
- esac
- ;;
- esac
- fi # $linkmode,$pass = prog,link...
-
- if test "$alldeplibs" = yes &&
- { test "$deplibs_check_method" = pass_all ||
- { test "$build_libtool_libs" = yes &&
- test -n "$library_names"; }; }; then
- # We only need to search for static libraries
- continue
- fi
- fi
-
- link_static=no # Whether the deplib will be linked statically
- use_static_libs=$prefer_static_libs
- if test "$use_static_libs" = built && test "$installed" = yes ; then
- use_static_libs=no
- fi
- if test -n "$library_names" &&
- { test "$use_static_libs" = no || test -z "$old_library"; }; then
- if test "$installed" = no; then
- notinst_deplibs="$notinst_deplibs $lib"
- need_relink=yes
- fi
- # This is a shared library
-
- # Warn about portability, can't link against -module's on
- # some systems (darwin)
- if test "$shouldnotlink" = yes && test "$pass" = link ; then
- $echo
- if test "$linkmode" = prog; then
- $echo "*** Warning: Linking the executable $output against the loadable module"
- else
- $echo "*** Warning: Linking the shared library $output against the loadable module"
- fi
- $echo "*** $linklib is not portable!"
- fi
- if test "$linkmode" = lib &&
- test "$hardcode_into_libs" = yes; then
- # Hardcode the library path.
- # Skip directories that are in the system default run-time
- # search path.
- case " $sys_lib_dlsearch_path " in
- *" $absdir "*) ;;
- *)
- case "$compile_rpath " in
- *" $absdir "*) ;;
- *) compile_rpath="$compile_rpath $absdir"
- esac
- ;;
- esac
- case " $sys_lib_dlsearch_path " in
- *" $libdir "*) ;;
- *)
- case "$finalize_rpath " in
- *" $libdir "*) ;;
- *) finalize_rpath="$finalize_rpath $libdir"
- esac
- ;;
- esac
- fi
-
- if test -n "$old_archive_from_expsyms_cmds"; then
- # figure out the soname
- set dummy $library_names
- realname="$2"
- shift; shift
- libname=`eval \\$echo \"$libname_spec\"`
- # use dlname if we got it. it's perfectly good, no?
- if test -n "$dlname"; then
- soname="$dlname"
- elif test -n "$soname_spec"; then
- # bleh windows
- case $host in
- *cygwin* | mingw*)
- major=`expr $current - $age`
- versuffix="-$major"
- ;;
- esac
- eval soname=\"$soname_spec\"
- else
- soname="$realname"
- fi
-
- # Make a new name for the extract_expsyms_cmds to use
- soroot="$soname"
- soname=`$echo $soroot | ${SED} -e 's/^.*\///'`
- newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a"
-
- # If the library has no export list, then create one now
- if test -f "$output_objdir/$soname-def"; then :
- else
- $show "extracting exported symbol list from \`$soname'"
- save_ifs="$IFS"; IFS='~'
- cmds=$extract_expsyms_cmds
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
- fi
-
- # Create $newlib
- if test -f "$output_objdir/$newlib"; then :; else
- $show "generating import library for \`$soname'"
- save_ifs="$IFS"; IFS='~'
- cmds=$old_archive_from_expsyms_cmds
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
- fi
- # make sure the library variables are pointing to the new library
- dir=$output_objdir
- linklib=$newlib
- fi # test -n "$old_archive_from_expsyms_cmds"
-
- if test "$linkmode" = prog || test "$mode" != relink; then
- add_shlibpath=
- add_dir=
- add=
- lib_linked=yes
- case $hardcode_action in
- immediate | unsupported)
- if test "$hardcode_direct" = no; then
- add="$dir/$linklib"
- case $host in
- *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
- *-*-sysv4*uw2*) add_dir="-L$dir" ;;
- *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
- *-*-unixware7*) add_dir="-L$dir" ;;
- *-*-darwin* )
- # if the lib is a module then we can not link against
- # it, someone is ignoring the new warnings I added
- if /usr/bin/file -L $add 2> /dev/null |
- $EGREP ": [^:]* bundle" >/dev/null ; then
- $echo "** Warning, lib $linklib is a module, not a shared library"
- if test -z "$old_library" ; then
- $echo
- $echo "** And there doesn't seem to be a static archive available"
- $echo "** The link will probably fail, sorry"
- else
- add="$dir/$old_library"
- fi
- fi
- esac
- elif test "$hardcode_minus_L" = no; then
- case $host in
- *-*-sunos*) add_shlibpath="$dir" ;;
- esac
- add_dir="-L$dir"
- add="-l$name"
- elif test "$hardcode_shlibpath_var" = no; then
- add_shlibpath="$dir"
- add="-l$name"
- else
- lib_linked=no
- fi
- ;;
- relink)
- if test "$hardcode_direct" = yes; then
- add="$dir/$linklib"
- elif test "$hardcode_minus_L" = yes; then
- add_dir="-L$dir"
- # Try looking first in the location we're being installed to.
- if test -n "$inst_prefix_dir"; then
- case $libdir in
- [\\/]*)
- add_dir="$add_dir -L$inst_prefix_dir$libdir"
- ;;
- esac
- fi
- add="-l$name"
- elif test "$hardcode_shlibpath_var" = yes; then
- add_shlibpath="$dir"
- add="-l$name"
- else
- lib_linked=no
- fi
- ;;
- *) lib_linked=no ;;
- esac
-
- if test "$lib_linked" != yes; then
- $echo "$modename: configuration error: unsupported hardcode properties"
- exit $EXIT_FAILURE
- fi
-
- if test -n "$add_shlibpath"; then
- case :$compile_shlibpath: in
- *":$add_shlibpath:"*) ;;
- *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
- esac
- fi
- if test "$linkmode" = prog; then
- test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
- test -n "$add" && compile_deplibs="$add $compile_deplibs"
- else
- test -n "$add_dir" && deplibs="$add_dir $deplibs"
- test -n "$add" && deplibs="$add $deplibs"
- if test "$hardcode_direct" != yes && \
- test "$hardcode_minus_L" != yes && \
- test "$hardcode_shlibpath_var" = yes; then
- case :$finalize_shlibpath: in
- *":$libdir:"*) ;;
- *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
- esac
- fi
- fi
- fi
-
- if test "$linkmode" = prog || test "$mode" = relink; then
- add_shlibpath=
- add_dir=
- add=
- # Finalize command for both is simple: just hardcode it.
- if test "$hardcode_direct" = yes; then
- add="$libdir/$linklib"
- elif test "$hardcode_minus_L" = yes; then
- add_dir="-L$libdir"
- add="-l$name"
- elif test "$hardcode_shlibpath_var" = yes; then
- case :$finalize_shlibpath: in
- *":$libdir:"*) ;;
- *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
- esac
- add="-l$name"
- elif test "$hardcode_automatic" = yes; then
- if test -n "$inst_prefix_dir" &&
- test -f "$inst_prefix_dir$libdir/$linklib" ; then
- add="$inst_prefix_dir$libdir/$linklib"
- else
- add="$libdir/$linklib"
- fi
- else
- # We cannot seem to hardcode it, guess we'll fake it.
- add_dir="-L$libdir"
- # Try looking first in the location we're being installed to.
- if test -n "$inst_prefix_dir"; then
- case $libdir in
- [\\/]*)
- add_dir="$add_dir -L$inst_prefix_dir$libdir"
- ;;
- esac
- fi
- add="-l$name"
- fi
-
- if test "$linkmode" = prog; then
- test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
- test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
- else
- test -n "$add_dir" && deplibs="$add_dir $deplibs"
- test -n "$add" && deplibs="$add $deplibs"
- fi
- fi
- elif test "$linkmode" = prog; then
- # Here we assume that one of hardcode_direct or hardcode_minus_L
- # is not unsupported. This is valid on all known static and
- # shared platforms.
- if test "$hardcode_direct" != unsupported; then
- test -n "$old_library" && linklib="$old_library"
- compile_deplibs="$dir/$linklib $compile_deplibs"
- finalize_deplibs="$dir/$linklib $finalize_deplibs"
- else
- compile_deplibs="-l$name -L$dir $compile_deplibs"
- finalize_deplibs="-l$name -L$dir $finalize_deplibs"
- fi
- elif test "$build_libtool_libs" = yes; then
- # Not a shared library
- if test "$deplibs_check_method" != pass_all; then
- # We're trying link a shared library against a static one
- # but the system doesn't support it.
-
- # Just print a warning and add the library to dependency_libs so
- # that the program can be linked against the static library.
- $echo
- $echo "*** Warning: This system can not link to static lib archive $lib."
- $echo "*** I have the capability to make that library automatically link in when"
- $echo "*** you link to this library. But I can only do this if you have a"
- $echo "*** shared version of the library, which you do not appear to have."
- if test "$module" = yes; then
- $echo "*** But as you try to build a module library, libtool will still create "
- $echo "*** a static module, that should work as long as the dlopening application"
- $echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
- if test -z "$global_symbol_pipe"; then
- $echo
- $echo "*** However, this would only work if libtool was able to extract symbol"
- $echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
- $echo "*** not find such a program. So, this module is probably useless."
- $echo "*** \`nm' from GNU binutils and a full rebuild may help."
- fi
- if test "$build_old_libs" = no; then
- build_libtool_libs=module
- build_old_libs=yes
- else
- build_libtool_libs=no
- fi
- fi
- else
- deplibs="$dir/$old_library $deplibs"
- link_static=yes
- fi
- fi # link shared/static library?
-
- if test "$linkmode" = lib; then
- if test -n "$dependency_libs" &&
- { test "$hardcode_into_libs" != yes ||
- test "$build_old_libs" = yes ||
- test "$link_static" = yes; }; then
- # Extract -R from dependency_libs
- temp_deplibs=
- for libdir in $dependency_libs; do
- case $libdir in
- -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'`
- case " $xrpath " in
- *" $temp_xrpath "*) ;;
- *) xrpath="$xrpath $temp_xrpath";;
- esac;;
- *) temp_deplibs="$temp_deplibs $libdir";;
- esac
- done
- dependency_libs="$temp_deplibs"
- fi
-
- newlib_search_path="$newlib_search_path $absdir"
- # Link against this library
- test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
- # ... and its dependency_libs
- tmp_libs=
- for deplib in $dependency_libs; do
- newdependency_libs="$deplib $newdependency_libs"
- if test "X$duplicate_deps" = "Xyes" ; then
- case "$tmp_libs " in
- *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
- esac
- fi
- tmp_libs="$tmp_libs $deplib"
- done
-
- if test "$link_all_deplibs" != no; then
- # Add the search paths of all dependency libraries
- for deplib in $dependency_libs; do
- case $deplib in
- -L*) path="$deplib" ;;
- *.la)
- dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'`
- test "X$dir" = "X$deplib" && dir="."
- # We need an absolute path.
- case $dir in
- [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
- *)
- absdir=`cd "$dir" && pwd`
- if test -z "$absdir"; then
- $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2
- absdir="$dir"
- fi
- ;;
- esac
- if grep "^installed=no" $deplib > /dev/null; then
- path="$absdir/$objdir"
- else
- eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
- if test -z "$libdir"; then
- $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2
- exit $EXIT_FAILURE
- fi
- if test "$absdir" != "$libdir"; then
- $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2
- fi
- path="$absdir"
- fi
- depdepl=
- case $host in
- *-*-darwin*)
- # we do not want to link against static libs,
- # but need to link against shared
- eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
- if test -n "$deplibrary_names" ; then
- for tmp in $deplibrary_names ; do
- depdepl=$tmp
- done
- if test -f "$path/$depdepl" ; then
- depdepl="$path/$depdepl"
- fi
- # do not add paths which are already there
- case " $newlib_search_path " in
- *" $path "*) ;;
- *) newlib_search_path="$newlib_search_path $path";;
- esac
- fi
- path=""
- ;;
- *)
- path="-L$path"
- ;;
- esac
- ;;
- -l*)
- case $host in
- *-*-darwin*)
- # Again, we only want to link against shared libraries
- eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"`
- for tmp in $newlib_search_path ; do
- if test -f "$tmp/lib$tmp_libs.dylib" ; then
- eval depdepl="$tmp/lib$tmp_libs.dylib"
- break
- fi
- done
- path=""
- ;;
- *) continue ;;
- esac
- ;;
- *) continue ;;
- esac
- case " $deplibs " in
- *" $path "*) ;;
- *) deplibs="$path $deplibs" ;;
- esac
- case " $deplibs " in
- *" $depdepl "*) ;;
- *) deplibs="$depdepl $deplibs" ;;
- esac
- done
- fi # link_all_deplibs != no
- fi # linkmode = lib
- done # for deplib in $libs
- dependency_libs="$newdependency_libs"
- if test "$pass" = dlpreopen; then
- # Link the dlpreopened libraries before other libraries
- for deplib in $save_deplibs; do
- deplibs="$deplib $deplibs"
- done
- fi
- if test "$pass" != dlopen; then
- if test "$pass" != conv; then
- # Make sure lib_search_path contains only unique directories.
- lib_search_path=
- for dir in $newlib_search_path; do
- case "$lib_search_path " in
- *" $dir "*) ;;
- *) lib_search_path="$lib_search_path $dir" ;;
- esac
- done
- newlib_search_path=
- fi
-
- if test "$linkmode,$pass" != "prog,link"; then
- vars="deplibs"
- else
- vars="compile_deplibs finalize_deplibs"
- fi
- for var in $vars dependency_libs; do
- # Add libraries to $var in reverse order
- eval tmp_libs=\"\$$var\"
- new_libs=
- for deplib in $tmp_libs; do
- # FIXME: Pedantically, this is the right thing to do, so
- # that some nasty dependency loop isn't accidentally
- # broken:
- #new_libs="$deplib $new_libs"
- # Pragmatically, this seems to cause very few problems in
- # practice:
- case $deplib in
- -L*) new_libs="$deplib $new_libs" ;;
- -R*) ;;
- *)
- # And here is the reason: when a library appears more
- # than once as an explicit dependence of a library, or
- # is implicitly linked in more than once by the
- # compiler, it is considered special, and multiple
- # occurrences thereof are not removed. Compare this
- # with having the same library being listed as a
- # dependency of multiple other libraries: in this case,
- # we know (pedantically, we assume) the library does not
- # need to be listed more than once, so we keep only the
- # last copy. This is not always right, but it is rare
- # enough that we require users that really mean to play
- # such unportable linking tricks to link the library
- # using -Wl,-lname, so that libtool does not consider it
- # for duplicate removal.
- case " $specialdeplibs " in
- *" $deplib "*) new_libs="$deplib $new_libs" ;;
- *)
- case " $new_libs " in
- *" $deplib "*) ;;
- *) new_libs="$deplib $new_libs" ;;
- esac
- ;;
- esac
- ;;
- esac
- done
- tmp_libs=
- for deplib in $new_libs; do
- case $deplib in
- -L*)
- case " $tmp_libs " in
- *" $deplib "*) ;;
- *) tmp_libs="$tmp_libs $deplib" ;;
- esac
- ;;
- *) tmp_libs="$tmp_libs $deplib" ;;
- esac
- done
- eval $var=\"$tmp_libs\"
- done # for var
- fi
- # Last step: remove runtime libs from dependency_libs
- # (they stay in deplibs)
- tmp_libs=
- for i in $dependency_libs ; do
- case " $predeps $postdeps $compiler_lib_search_path " in
- *" $i "*)
- i=""
- ;;
- esac
- if test -n "$i" ; then
- tmp_libs="$tmp_libs $i"
- fi
- done
- dependency_libs=$tmp_libs
- done # for pass
- if test "$linkmode" = prog; then
- dlfiles="$newdlfiles"
- dlprefiles="$newdlprefiles"
- fi
-
- case $linkmode in
- oldlib)
- if test -n "$deplibs"; then
- $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2
- fi
-
- if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
- $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2
- fi
-
- if test -n "$rpath"; then
- $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2
- fi
-
- if test -n "$xrpath"; then
- $echo "$modename: warning: \`-R' is ignored for archives" 1>&2
- fi
-
- if test -n "$vinfo"; then
- $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2
- fi
-
- if test -n "$release"; then
- $echo "$modename: warning: \`-release' is ignored for archives" 1>&2
- fi
-
- if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
- $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2
- fi
-
- # Now set the variables for building old libraries.
- build_libtool_libs=no
- oldlibs="$output"
- objs="$objs$old_deplibs"
- ;;
-
- lib)
- # Make sure we only generate libraries of the form `libNAME.la'.
- case $outputname in
- lib*)
- name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
- eval shared_ext=\"$shrext_cmds\"
- eval libname=\"$libname_spec\"
- ;;
- *)
- if test "$module" = no; then
- $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
- if test "$need_lib_prefix" != no; then
- # Add the "lib" prefix for modules if required
- name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'`
- eval shared_ext=\"$shrext_cmds\"
- eval libname=\"$libname_spec\"
- else
- libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'`
- fi
- ;;
- esac
-
- if test -n "$objs"; then
- if test "$deplibs_check_method" != pass_all; then
- $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1
- exit $EXIT_FAILURE
- else
- $echo
- $echo "*** Warning: Linking the shared library $output against the non-libtool"
- $echo "*** objects $objs is not portable!"
- libobjs="$libobjs $objs"
- fi
- fi
-
- if test "$dlself" != no; then
- $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2
- fi
-
- set dummy $rpath
- if test "$#" -gt 2; then
- $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2
- fi
- install_libdir="$2"
-
- oldlibs=
- if test -z "$rpath"; then
- if test "$build_libtool_libs" = yes; then
- # Building a libtool convenience library.
- # Some compilers have problems with a `.al' extension so
- # convenience libraries should have the same extension an
- # archive normally would.
- oldlibs="$output_objdir/$libname.$libext $oldlibs"
- build_libtool_libs=convenience
- build_old_libs=yes
- fi
-
- if test -n "$vinfo"; then
- $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2
- fi
-
- if test -n "$release"; then
- $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2
- fi
- else
-
- # Parse the version information argument.
- save_ifs="$IFS"; IFS=':'
- set dummy $vinfo 0 0 0
- IFS="$save_ifs"
-
- if test -n "$8"; then
- $echo "$modename: too many parameters to \`-version-info'" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # convert absolute version numbers to libtool ages
- # this retains compatibility with .la files and attempts
- # to make the code below a bit more comprehensible
-
- case $vinfo_number in
- yes)
- number_major="$2"
- number_minor="$3"
- number_revision="$4"
- #
- # There are really only two kinds -- those that
- # use the current revision as the major version
- # and those that subtract age and use age as
- # a minor version. But, then there is irix
- # which has an extra 1 added just for fun
- #
- case $version_type in
- darwin|linux|osf|windows)
- current=`expr $number_major + $number_minor`
- age="$number_minor"
- revision="$number_revision"
- ;;
- freebsd-aout|freebsd-elf|sunos)
- current="$number_major"
- revision="$number_minor"
- age="0"
- ;;
- irix|nonstopux)
- current=`expr $number_major + $number_minor - 1`
- age="$number_minor"
- revision="$number_minor"
- ;;
- esac
- ;;
- no)
- current="$2"
- revision="$3"
- age="$4"
- ;;
- esac
-
- # Check that each of the things are valid numbers.
- case $current in
- 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
- *)
- $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2
- $echo "$modename: \`$vinfo' is not valid version information" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- case $revision in
- 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
- *)
- $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2
- $echo "$modename: \`$vinfo' is not valid version information" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- case $age in
- 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
- *)
- $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2
- $echo "$modename: \`$vinfo' is not valid version information" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- if test "$age" -gt "$current"; then
- $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2
- $echo "$modename: \`$vinfo' is not valid version information" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Calculate the version variables.
- major=
- versuffix=
- verstring=
- case $version_type in
- none) ;;
-
- darwin)
- # Like Linux, but with the current version available in
- # verstring for coding it into the library header
- major=.`expr $current - $age`
- versuffix="$major.$age.$revision"
- # Darwin ld doesn't like 0 for these options...
- minor_current=`expr $current + 1`
- verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
- ;;
-
- freebsd-aout)
- major=".$current"
- versuffix=".$current.$revision";
- ;;
-
- freebsd-elf)
- major=".$current"
- versuffix=".$current";
- ;;
-
- irix | nonstopux)
- major=`expr $current - $age + 1`
-
- case $version_type in
- nonstopux) verstring_prefix=nonstopux ;;
- *) verstring_prefix=sgi ;;
- esac
- verstring="$verstring_prefix$major.$revision"
-
- # Add in all the interfaces that we are compatible with.
- loop=$revision
- while test "$loop" -ne 0; do
- iface=`expr $revision - $loop`
- loop=`expr $loop - 1`
- verstring="$verstring_prefix$major.$iface:$verstring"
- done
-
- # Before this point, $major must not contain `.'.
- major=.$major
- versuffix="$major.$revision"
- ;;
-
- linux)
- major=.`expr $current - $age`
- versuffix="$major.$age.$revision"
- ;;
-
- osf)
- major=.`expr $current - $age`
- versuffix=".$current.$age.$revision"
- verstring="$current.$age.$revision"
-
- # Add in all the interfaces that we are compatible with.
- loop=$age
- while test "$loop" -ne 0; do
- iface=`expr $current - $loop`
- loop=`expr $loop - 1`
- verstring="$verstring:${iface}.0"
- done
-
- # Make executables depend on our current version.
- verstring="$verstring:${current}.0"
- ;;
-
- sunos)
- major=".$current"
- versuffix=".$current.$revision"
- ;;
-
- windows)
- # Use '-' rather than '.', since we only want one
- # extension on DOS 8.3 filesystems.
- major=`expr $current - $age`
- versuffix="-$major"
- ;;
-
- *)
- $echo "$modename: unknown library version type \`$version_type'" 1>&2
- $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- # Clear the version info if we defaulted, and they specified a release.
- if test -z "$vinfo" && test -n "$release"; then
- major=
- case $version_type in
- darwin)
- # we can't check for "0.0" in archive_cmds due to quoting
- # problems, so we reset it completely
- verstring=
- ;;
- *)
- verstring="0.0"
- ;;
- esac
- if test "$need_version" = no; then
- versuffix=
- else
- versuffix=".0.0"
- fi
- fi
-
- # Remove version info from name if versioning should be avoided
- if test "$avoid_version" = yes && test "$need_version" = no; then
- major=
- versuffix=
- verstring=""
- fi
-
- # Check to see if the archive will have undefined symbols.
- if test "$allow_undefined" = yes; then
- if test "$allow_undefined_flag" = unsupported; then
- $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2
- build_libtool_libs=no
- build_old_libs=yes
- fi
- else
- # Don't allow undefined symbols.
- allow_undefined_flag="$no_undefined_flag"
- fi
- fi
-
- if test "$mode" != relink; then
- # Remove our outputs, but don't remove object files since they
- # may have been created when compiling PIC objects.
- removelist=
- tempremovelist=`$echo "$output_objdir/*"`
- for p in $tempremovelist; do
- case $p in
- *.$objext)
- ;;
- $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
- if test "X$precious_files_regex" != "X"; then
- if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
- then
- continue
- fi
- fi
- removelist="$removelist $p"
- ;;
- *) ;;
- esac
- done
- if test -n "$removelist"; then
- $show "${rm}r $removelist"
- $run ${rm}r $removelist
- fi
- fi
-
- # Now set the variables for building old libraries.
- if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
- oldlibs="$oldlibs $output_objdir/$libname.$libext"
-
- # Transform .lo files to .o files.
- oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
- fi
-
- # Eliminate all temporary directories.
- for path in $notinst_path; do
- lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"`
- deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"`
- dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"`
- done
-
- if test -n "$xrpath"; then
- # If the user specified any rpath flags, then add them.
- temp_xrpath=
- for libdir in $xrpath; do
- temp_xrpath="$temp_xrpath -R$libdir"
- case "$finalize_rpath " in
- *" $libdir "*) ;;
- *) finalize_rpath="$finalize_rpath $libdir" ;;
- esac
- done
- if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
- dependency_libs="$temp_xrpath $dependency_libs"
- fi
- fi
-
- # Make sure dlfiles contains only unique files that won't be dlpreopened
- old_dlfiles="$dlfiles"
- dlfiles=
- for lib in $old_dlfiles; do
- case " $dlprefiles $dlfiles " in
- *" $lib "*) ;;
- *) dlfiles="$dlfiles $lib" ;;
- esac
- done
-
- # Make sure dlprefiles contains only unique files
- old_dlprefiles="$dlprefiles"
- dlprefiles=
- for lib in $old_dlprefiles; do
- case "$dlprefiles " in
- *" $lib "*) ;;
- *) dlprefiles="$dlprefiles $lib" ;;
- esac
- done
-
- if test "$build_libtool_libs" = yes; then
- if test -n "$rpath"; then
- case $host in
- *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*)
- # these systems don't actually have a c library (as such)!
- ;;
- *-*-rhapsody* | *-*-darwin1.[012])
- # Rhapsody C library is in the System framework
- deplibs="$deplibs -framework System"
- ;;
- *-*-netbsd*)
- # Don't link with libc until the a.out ld.so is fixed.
- ;;
- *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
- # Do not include libc due to us having libc/libc_r.
- ;;
- *-*-sco3.2v5* | *-*-sco5v6*)
- # Causes problems with __ctype
- ;;
- *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
- # Compiler inserts libc in the correct place for threads to work
- ;;
- *)
- # Add libc to deplibs on all other systems if necessary.
- if test "$build_libtool_need_lc" = "yes"; then
- deplibs="$deplibs -lc"
- fi
- ;;
- esac
- fi
-
- # Transform deplibs into only deplibs that can be linked in shared.
- name_save=$name
- libname_save=$libname
- release_save=$release
- versuffix_save=$versuffix
- major_save=$major
- # I'm not sure if I'm treating the release correctly. I think
- # release should show up in the -l (ie -lgmp5) so we don't want to
- # add it in twice. Is that correct?
- release=""
- versuffix=""
- major=""
- newdeplibs=
- droppeddeps=no
- case $deplibs_check_method in
- pass_all)
- # Don't check for shared/static. Everything works.
- # This might be a little naive. We might want to check
- # whether the library exists or not. But this is on
- # osf3 & osf4 and I'm not really sure... Just
- # implementing what was already the behavior.
- newdeplibs=$deplibs
- ;;
- test_compile)
- # This code stresses the "libraries are programs" paradigm to its
- # limits. Maybe even breaks it. We compile a program, linking it
- # against the deplibs as a proxy for the library. Then we can check
- # whether they linked in statically or dynamically with ldd.
- $rm conftest.c
- cat > conftest.c <<EOF
- int main() { return 0; }
-EOF
- $rm conftest
- $LTCC $LTCFLAGS -o conftest conftest.c $deplibs
- if test "$?" -eq 0 ; then
- ldd_output=`ldd conftest`
- for i in $deplibs; do
- name=`expr $i : '-l\(.*\)'`
- # If $name is empty we are operating on a -L argument.
- if test "$name" != "" && test "$name" -ne "0"; then
- if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
- case " $predeps $postdeps " in
- *" $i "*)
- newdeplibs="$newdeplibs $i"
- i=""
- ;;
- esac
- fi
- if test -n "$i" ; then
- libname=`eval \\$echo \"$libname_spec\"`
- deplib_matches=`eval \\$echo \"$library_names_spec\"`
- set dummy $deplib_matches
- deplib_match=$2
- if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
- newdeplibs="$newdeplibs $i"
- else
- droppeddeps=yes
- $echo
- $echo "*** Warning: dynamic linker does not accept needed library $i."
- $echo "*** I have the capability to make that library automatically link in when"
- $echo "*** you link to this library. But I can only do this if you have a"
- $echo "*** shared version of the library, which I believe you do not have"
- $echo "*** because a test_compile did reveal that the linker did not use it for"
- $echo "*** its dynamic dependency list that programs get resolved with at runtime."
- fi
- fi
- else
- newdeplibs="$newdeplibs $i"
- fi
- done
- else
- # Error occurred in the first compile. Let's try to salvage
- # the situation: Compile a separate program for each library.
- for i in $deplibs; do
- name=`expr $i : '-l\(.*\)'`
- # If $name is empty we are operating on a -L argument.
- if test "$name" != "" && test "$name" != "0"; then
- $rm conftest
- $LTCC $LTCFLAGS -o conftest conftest.c $i
- # Did it work?
- if test "$?" -eq 0 ; then
- ldd_output=`ldd conftest`
- if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
- case " $predeps $postdeps " in
- *" $i "*)
- newdeplibs="$newdeplibs $i"
- i=""
- ;;
- esac
- fi
- if test -n "$i" ; then
- libname=`eval \\$echo \"$libname_spec\"`
- deplib_matches=`eval \\$echo \"$library_names_spec\"`
- set dummy $deplib_matches
- deplib_match=$2
- if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
- newdeplibs="$newdeplibs $i"
- else
- droppeddeps=yes
- $echo
- $echo "*** Warning: dynamic linker does not accept needed library $i."
- $echo "*** I have the capability to make that library automatically link in when"
- $echo "*** you link to this library. But I can only do this if you have a"
- $echo "*** shared version of the library, which you do not appear to have"
- $echo "*** because a test_compile did reveal that the linker did not use this one"
- $echo "*** as a dynamic dependency that programs can get resolved with at runtime."
- fi
- fi
- else
- droppeddeps=yes
- $echo
- $echo "*** Warning! Library $i is needed by this library but I was not able to"
- $echo "*** make it link in! You will probably need to install it or some"
- $echo "*** library that it depends on before this library will be fully"
- $echo "*** functional. Installing it before continuing would be even better."
- fi
- else
- newdeplibs="$newdeplibs $i"
- fi
- done
- fi
- ;;
- file_magic*)
- set dummy $deplibs_check_method
- file_magic_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"`
- for a_deplib in $deplibs; do
- name=`expr $a_deplib : '-l\(.*\)'`
- # If $name is empty we are operating on a -L argument.
- if test "$name" != "" && test "$name" != "0"; then
- if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
- case " $predeps $postdeps " in
- *" $a_deplib "*)
- newdeplibs="$newdeplibs $a_deplib"
- a_deplib=""
- ;;
- esac
- fi
- if test -n "$a_deplib" ; then
- libname=`eval \\$echo \"$libname_spec\"`
- for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
- potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
- for potent_lib in $potential_libs; do
- # Follow soft links.
- if ls -lLd "$potent_lib" 2>/dev/null \
- | grep " -> " >/dev/null; then
- continue
- fi
- # The statement above tries to avoid entering an
- # endless loop below, in case of cyclic links.
- # We might still enter an endless loop, since a link
- # loop can be closed while we follow links,
- # but so what?
- potlib="$potent_lib"
- while test -h "$potlib" 2>/dev/null; do
- potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
- case $potliblink in
- [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
- *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
- esac
- done
- if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \
- | ${SED} 10q \
- | $EGREP "$file_magic_regex" > /dev/null; then
- newdeplibs="$newdeplibs $a_deplib"
- a_deplib=""
- break 2
- fi
- done
- done
- fi
- if test -n "$a_deplib" ; then
- droppeddeps=yes
- $echo
- $echo "*** Warning: linker path does not have real file for library $a_deplib."
- $echo "*** I have the capability to make that library automatically link in when"
- $echo "*** you link to this library. But I can only do this if you have a"
- $echo "*** shared version of the library, which you do not appear to have"
- $echo "*** because I did check the linker path looking for a file starting"
- if test -z "$potlib" ; then
- $echo "*** with $libname but no candidates were found. (...for file magic test)"
- else
- $echo "*** with $libname and none of the candidates passed a file format test"
- $echo "*** using a file magic. Last file checked: $potlib"
- fi
- fi
- else
- # Add a -L argument.
- newdeplibs="$newdeplibs $a_deplib"
- fi
- done # Gone through all deplibs.
- ;;
- match_pattern*)
- set dummy $deplibs_check_method
- match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"`
- for a_deplib in $deplibs; do
- name=`expr $a_deplib : '-l\(.*\)'`
- # If $name is empty we are operating on a -L argument.
- if test -n "$name" && test "$name" != "0"; then
- if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
- case " $predeps $postdeps " in
- *" $a_deplib "*)
- newdeplibs="$newdeplibs $a_deplib"
- a_deplib=""
- ;;
- esac
- fi
- if test -n "$a_deplib" ; then
- libname=`eval \\$echo \"$libname_spec\"`
- for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
- potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
- for potent_lib in $potential_libs; do
- potlib="$potent_lib" # see symlink-check above in file_magic test
- if eval $echo \"$potent_lib\" 2>/dev/null \
- | ${SED} 10q \
- | $EGREP "$match_pattern_regex" > /dev/null; then
- newdeplibs="$newdeplibs $a_deplib"
- a_deplib=""
- break 2
- fi
- done
- done
- fi
- if test -n "$a_deplib" ; then
- droppeddeps=yes
- $echo
- $echo "*** Warning: linker path does not have real file for library $a_deplib."
- $echo "*** I have the capability to make that library automatically link in when"
- $echo "*** you link to this library. But I can only do this if you have a"
- $echo "*** shared version of the library, which you do not appear to have"
- $echo "*** because I did check the linker path looking for a file starting"
- if test -z "$potlib" ; then
- $echo "*** with $libname but no candidates were found. (...for regex pattern test)"
- else
- $echo "*** with $libname and none of the candidates passed a file format test"
- $echo "*** using a regex pattern. Last file checked: $potlib"
- fi
- fi
- else
- # Add a -L argument.
- newdeplibs="$newdeplibs $a_deplib"
- fi
- done # Gone through all deplibs.
- ;;
- none | unknown | *)
- newdeplibs=""
- tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \
- -e 's/ -[LR][^ ]*//g'`
- if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
- for i in $predeps $postdeps ; do
- # can't use Xsed below, because $i might contain '/'
- tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"`
- done
- fi
- if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \
- | grep . >/dev/null; then
- $echo
- if test "X$deplibs_check_method" = "Xnone"; then
- $echo "*** Warning: inter-library dependencies are not supported in this platform."
- else
- $echo "*** Warning: inter-library dependencies are not known to be supported."
- fi
- $echo "*** All declared inter-library dependencies are being dropped."
- droppeddeps=yes
- fi
- ;;
- esac
- versuffix=$versuffix_save
- major=$major_save
- release=$release_save
- libname=$libname_save
- name=$name_save
-
- case $host in
- *-*-rhapsody* | *-*-darwin1.[012])
- # On Rhapsody replace the C library is the System framework
- newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'`
- ;;
- esac
-
- if test "$droppeddeps" = yes; then
- if test "$module" = yes; then
- $echo
- $echo "*** Warning: libtool could not satisfy all declared inter-library"
- $echo "*** dependencies of module $libname. Therefore, libtool will create"
- $echo "*** a static module, that should work as long as the dlopening"
- $echo "*** application is linked with the -dlopen flag."
- if test -z "$global_symbol_pipe"; then
- $echo
- $echo "*** However, this would only work if libtool was able to extract symbol"
- $echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
- $echo "*** not find such a program. So, this module is probably useless."
- $echo "*** \`nm' from GNU binutils and a full rebuild may help."
- fi
- if test "$build_old_libs" = no; then
- oldlibs="$output_objdir/$libname.$libext"
- build_libtool_libs=module
- build_old_libs=yes
- else
- build_libtool_libs=no
- fi
- else
- $echo "*** The inter-library dependencies that have been dropped here will be"
- $echo "*** automatically added whenever a program is linked with this library"
- $echo "*** or is declared to -dlopen it."
-
- if test "$allow_undefined" = no; then
- $echo
- $echo "*** Since this library must not contain undefined symbols,"
- $echo "*** because either the platform does not support them or"
- $echo "*** it was explicitly requested with -no-undefined,"
- $echo "*** libtool will only create a static version of it."
- if test "$build_old_libs" = no; then
- oldlibs="$output_objdir/$libname.$libext"
- build_libtool_libs=module
- build_old_libs=yes
- else
- build_libtool_libs=no
- fi
- fi
- fi
- fi
- # Done checking deplibs!
- deplibs=$newdeplibs
- fi
-
-
- # move library search paths that coincide with paths to not yet
- # installed libraries to the beginning of the library search list
- new_libs=
- for path in $notinst_path; do
- case " $new_libs " in
- *" -L$path/$objdir "*) ;;
- *)
- case " $deplibs " in
- *" -L$path/$objdir "*)
- new_libs="$new_libs -L$path/$objdir" ;;
- esac
- ;;
- esac
- done
- for deplib in $deplibs; do
- case $deplib in
- -L*)
- case " $new_libs " in
- *" $deplib "*) ;;
- *) new_libs="$new_libs $deplib" ;;
- esac
- ;;
- *) new_libs="$new_libs $deplib" ;;
- esac
- done
- deplibs="$new_libs"
-
-
- # All the library-specific variables (install_libdir is set above).
- library_names=
- old_library=
- dlname=
-
- # Test again, we may have decided not to build it any more
- if test "$build_libtool_libs" = yes; then
- if test "$hardcode_into_libs" = yes; then
- # Hardcode the library paths
- hardcode_libdirs=
- dep_rpath=
- rpath="$finalize_rpath"
- test "$mode" != relink && rpath="$compile_rpath$rpath"
- for libdir in $rpath; do
- if test -n "$hardcode_libdir_flag_spec"; then
- if test -n "$hardcode_libdir_separator"; then
- if test -z "$hardcode_libdirs"; then
- hardcode_libdirs="$libdir"
- else
- # Just accumulate the unique libdirs.
- case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
- *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
- ;;
- *)
- hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
- ;;
- esac
- fi
- else
- eval flag=\"$hardcode_libdir_flag_spec\"
- dep_rpath="$dep_rpath $flag"
- fi
- elif test -n "$runpath_var"; then
- case "$perm_rpath " in
- *" $libdir "*) ;;
- *) perm_rpath="$perm_rpath $libdir" ;;
- esac
- fi
- done
- # Substitute the hardcoded libdirs into the rpath.
- if test -n "$hardcode_libdir_separator" &&
- test -n "$hardcode_libdirs"; then
- libdir="$hardcode_libdirs"
- if test -n "$hardcode_libdir_flag_spec_ld"; then
- eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
- else
- eval dep_rpath=\"$hardcode_libdir_flag_spec\"
- fi
- fi
- if test -n "$runpath_var" && test -n "$perm_rpath"; then
- # We should set the runpath_var.
- rpath=
- for dir in $perm_rpath; do
- rpath="$rpath$dir:"
- done
- eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
- fi
- test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
- fi
-
- shlibpath="$finalize_shlibpath"
- test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
- if test -n "$shlibpath"; then
- eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
- fi
-
- # Get the real and link names of the library.
- eval shared_ext=\"$shrext_cmds\"
- eval library_names=\"$library_names_spec\"
- set dummy $library_names
- realname="$2"
- shift; shift
-
- if test -n "$soname_spec"; then
- eval soname=\"$soname_spec\"
- else
- soname="$realname"
- fi
- if test -z "$dlname"; then
- dlname=$soname
- fi
-
- lib="$output_objdir/$realname"
- linknames=
- for link
- do
- linknames="$linknames $link"
- done
-
- # Use standard objects if they are pic
- test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
-
- # Prepare the list of exported symbols
- if test -z "$export_symbols"; then
- if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then
- $show "generating symbol list for \`$libname.la'"
- export_symbols="$output_objdir/$libname.exp"
- $run $rm $export_symbols
- cmds=$export_symbols_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- if len=`expr "X$cmd" : ".*"` &&
- test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
- $show "$cmd"
- $run eval "$cmd" || exit $?
- skipped_export=false
- else
- # The command line is too long to execute in one step.
- $show "using reloadable object file for export list..."
- skipped_export=:
- # Break out early, otherwise skipped_export may be
- # set to false by a later but shorter cmd.
- break
- fi
- done
- IFS="$save_ifs"
- if test -n "$export_symbols_regex"; then
- $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\""
- $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
- $show "$mv \"${export_symbols}T\" \"$export_symbols\""
- $run eval '$mv "${export_symbols}T" "$export_symbols"'
- fi
- fi
- fi
-
- if test -n "$export_symbols" && test -n "$include_expsyms"; then
- $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"'
- fi
-
- tmp_deplibs=
- for test_deplib in $deplibs; do
- case " $convenience " in
- *" $test_deplib "*) ;;
- *)
- tmp_deplibs="$tmp_deplibs $test_deplib"
- ;;
- esac
- done
- deplibs="$tmp_deplibs"
-
- if test -n "$convenience"; then
- if test -n "$whole_archive_flag_spec"; then
- save_libobjs=$libobjs
- eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
- else
- gentop="$output_objdir/${outputname}x"
- generated="$generated $gentop"
-
- func_extract_archives $gentop $convenience
- libobjs="$libobjs $func_extract_archives_result"
- fi
- fi
-
- if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
- eval flag=\"$thread_safe_flag_spec\"
- linker_flags="$linker_flags $flag"
- fi
-
- # Make a backup of the uninstalled library when relinking
- if test "$mode" = relink; then
- $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $?
- fi
-
- # Do each of the archive commands.
- if test "$module" = yes && test -n "$module_cmds" ; then
- if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
- eval test_cmds=\"$module_expsym_cmds\"
- cmds=$module_expsym_cmds
- else
- eval test_cmds=\"$module_cmds\"
- cmds=$module_cmds
- fi
- else
- if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
- eval test_cmds=\"$archive_expsym_cmds\"
- cmds=$archive_expsym_cmds
- else
- eval test_cmds=\"$archive_cmds\"
- cmds=$archive_cmds
- fi
- fi
-
- if test "X$skipped_export" != "X:" &&
- len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
- test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
- :
- else
- # The command line is too long to link in one step, link piecewise.
- $echo "creating reloadable object files..."
-
- # Save the value of $output and $libobjs because we want to
- # use them later. If we have whole_archive_flag_spec, we
- # want to use save_libobjs as it was before
- # whole_archive_flag_spec was expanded, because we can't
- # assume the linker understands whole_archive_flag_spec.
- # This may have to be revisited, in case too many
- # convenience libraries get linked in and end up exceeding
- # the spec.
- if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
- save_libobjs=$libobjs
- fi
- save_output=$output
- output_la=`$echo "X$output" | $Xsed -e "$basename"`
-
- # Clear the reloadable object creation command queue and
- # initialize k to one.
- test_cmds=
- concat_cmds=
- objlist=
- delfiles=
- last_robj=
- k=1
- output=$output_objdir/$output_la-${k}.$objext
- # Loop over the list of objects to be linked.
- for obj in $save_libobjs
- do
- eval test_cmds=\"$reload_cmds $objlist $last_robj\"
- if test "X$objlist" = X ||
- { len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
- test "$len" -le "$max_cmd_len"; }; then
- objlist="$objlist $obj"
- else
- # The command $test_cmds is almost too long, add a
- # command to the queue.
- if test "$k" -eq 1 ; then
- # The first file doesn't have a previous command to add.
- eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
- else
- # All subsequent reloadable object files will link in
- # the last one created.
- eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\"
- fi
- last_robj=$output_objdir/$output_la-${k}.$objext
- k=`expr $k + 1`
- output=$output_objdir/$output_la-${k}.$objext
- objlist=$obj
- len=1
- fi
- done
- # Handle the remaining objects by creating one last
- # reloadable object file. All subsequent reloadable object
- # files will link in the last one created.
- test -z "$concat_cmds" || concat_cmds=$concat_cmds~
- eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
-
- if ${skipped_export-false}; then
- $show "generating symbol list for \`$libname.la'"
- export_symbols="$output_objdir/$libname.exp"
- $run $rm $export_symbols
- libobjs=$output
- # Append the command to create the export file.
- eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\"
- fi
-
- # Set up a command to remove the reloadable object files
- # after they are used.
- i=0
- while test "$i" -lt "$k"
- do
- i=`expr $i + 1`
- delfiles="$delfiles $output_objdir/$output_la-${i}.$objext"
- done
-
- $echo "creating a temporary reloadable object file: $output"
-
- # Loop through the commands generated above and execute them.
- save_ifs="$IFS"; IFS='~'
- for cmd in $concat_cmds; do
- IFS="$save_ifs"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
-
- libobjs=$output
- # Restore the value of output.
- output=$save_output
-
- if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
- eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
- fi
- # Expand the library linking commands again to reset the
- # value of $libobjs for piecewise linking.
-
- # Do each of the archive commands.
- if test "$module" = yes && test -n "$module_cmds" ; then
- if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
- cmds=$module_expsym_cmds
- else
- cmds=$module_cmds
- fi
- else
- if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
- cmds=$archive_expsym_cmds
- else
- cmds=$archive_cmds
- fi
- fi
-
- # Append the command to remove the reloadable object files
- # to the just-reset $cmds.
- eval cmds=\"\$cmds~\$rm $delfiles\"
- fi
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || {
- lt_exit=$?
-
- # Restore the uninstalled library and exit
- if test "$mode" = relink; then
- $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)'
- fi
-
- exit $lt_exit
- }
- done
- IFS="$save_ifs"
-
- # Restore the uninstalled library and exit
- if test "$mode" = relink; then
- $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $?
-
- if test -n "$convenience"; then
- if test -z "$whole_archive_flag_spec"; then
- $show "${rm}r $gentop"
- $run ${rm}r "$gentop"
- fi
- fi
-
- exit $EXIT_SUCCESS
- fi
-
- # Create links to the real library.
- for linkname in $linknames; do
- if test "$realname" != "$linkname"; then
- $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)"
- $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $?
- fi
- done
-
- # If -module or -export-dynamic was specified, set the dlname.
- if test "$module" = yes || test "$export_dynamic" = yes; then
- # On all known operating systems, these are identical.
- dlname="$soname"
- fi
- fi
- ;;
-
- obj)
- if test -n "$deplibs"; then
- $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2
- fi
-
- if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
- $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2
- fi
-
- if test -n "$rpath"; then
- $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2
- fi
-
- if test -n "$xrpath"; then
- $echo "$modename: warning: \`-R' is ignored for objects" 1>&2
- fi
-
- if test -n "$vinfo"; then
- $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2
- fi
-
- if test -n "$release"; then
- $echo "$modename: warning: \`-release' is ignored for objects" 1>&2
- fi
-
- case $output in
- *.lo)
- if test -n "$objs$old_deplibs"; then
- $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2
- exit $EXIT_FAILURE
- fi
- libobj="$output"
- obj=`$echo "X$output" | $Xsed -e "$lo2o"`
- ;;
- *)
- libobj=
- obj="$output"
- ;;
- esac
-
- # Delete the old objects.
- $run $rm $obj $libobj
-
- # Objects from convenience libraries. This assumes
- # single-version convenience libraries. Whenever we create
- # different ones for PIC/non-PIC, this we'll have to duplicate
- # the extraction.
- reload_conv_objs=
- gentop=
- # reload_cmds runs $LD directly, so let us get rid of
- # -Wl from whole_archive_flag_spec
- wl=
-
- if test -n "$convenience"; then
- if test -n "$whole_archive_flag_spec"; then
- eval reload_conv_objs=\"\$reload_objs $whole_archive_flag_spec\"
- else
- gentop="$output_objdir/${obj}x"
- generated="$generated $gentop"
-
- func_extract_archives $gentop $convenience
- reload_conv_objs="$reload_objs $func_extract_archives_result"
- fi
- fi
-
- # Create the old-style object.
- reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
-
- output="$obj"
- cmds=$reload_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
-
- # Exit if we aren't doing a library object file.
- if test -z "$libobj"; then
- if test -n "$gentop"; then
- $show "${rm}r $gentop"
- $run ${rm}r $gentop
- fi
-
- exit $EXIT_SUCCESS
- fi
-
- if test "$build_libtool_libs" != yes; then
- if test -n "$gentop"; then
- $show "${rm}r $gentop"
- $run ${rm}r $gentop
- fi
-
- # Create an invalid libtool object if no PIC, so that we don't
- # accidentally link it into a program.
- # $show "echo timestamp > $libobj"
- # $run eval "echo timestamp > $libobj" || exit $?
- exit $EXIT_SUCCESS
- fi
-
- if test -n "$pic_flag" || test "$pic_mode" != default; then
- # Only do commands if we really have different PIC objects.
- reload_objs="$libobjs $reload_conv_objs"
- output="$libobj"
- cmds=$reload_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
- fi
-
- if test -n "$gentop"; then
- $show "${rm}r $gentop"
- $run ${rm}r $gentop
- fi
-
- exit $EXIT_SUCCESS
- ;;
-
- prog)
- case $host in
- *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;;
- esac
- if test -n "$vinfo"; then
- $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2
- fi
-
- if test -n "$release"; then
- $echo "$modename: warning: \`-release' is ignored for programs" 1>&2
- fi
-
- if test "$preload" = yes; then
- if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown &&
- test "$dlopen_self_static" = unknown; then
- $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support."
- fi
- fi
-
- case $host in
- *-*-rhapsody* | *-*-darwin1.[012])
- # On Rhapsody replace the C library is the System framework
- compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'`
- finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'`
- ;;
- esac
-
- case $host in
- *darwin*)
- # Don't allow lazy linking, it breaks C++ global constructors
- if test "$tagname" = CXX ; then
- compile_command="$compile_command ${wl}-bind_at_load"
- finalize_command="$finalize_command ${wl}-bind_at_load"
- fi
- ;;
- esac
-
-
- # move library search paths that coincide with paths to not yet
- # installed libraries to the beginning of the library search list
- new_libs=
- for path in $notinst_path; do
- case " $new_libs " in
- *" -L$path/$objdir "*) ;;
- *)
- case " $compile_deplibs " in
- *" -L$path/$objdir "*)
- new_libs="$new_libs -L$path/$objdir" ;;
- esac
- ;;
- esac
- done
- for deplib in $compile_deplibs; do
- case $deplib in
- -L*)
- case " $new_libs " in
- *" $deplib "*) ;;
- *) new_libs="$new_libs $deplib" ;;
- esac
- ;;
- *) new_libs="$new_libs $deplib" ;;
- esac
- done
- compile_deplibs="$new_libs"
-
-
- compile_command="$compile_command $compile_deplibs"
- finalize_command="$finalize_command $finalize_deplibs"
-
- if test -n "$rpath$xrpath"; then
- # If the user specified any rpath flags, then add them.
- for libdir in $rpath $xrpath; do
- # This is the magic to use -rpath.
- case "$finalize_rpath " in
- *" $libdir "*) ;;
- *) finalize_rpath="$finalize_rpath $libdir" ;;
- esac
- done
- fi
-
- # Now hardcode the library paths
- rpath=
- hardcode_libdirs=
- for libdir in $compile_rpath $finalize_rpath; do
- if test -n "$hardcode_libdir_flag_spec"; then
- if test -n "$hardcode_libdir_separator"; then
- if test -z "$hardcode_libdirs"; then
- hardcode_libdirs="$libdir"
- else
- # Just accumulate the unique libdirs.
- case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
- *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
- ;;
- *)
- hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
- ;;
- esac
- fi
- else
- eval flag=\"$hardcode_libdir_flag_spec\"
- rpath="$rpath $flag"
- fi
- elif test -n "$runpath_var"; then
- case "$perm_rpath " in
- *" $libdir "*) ;;
- *) perm_rpath="$perm_rpath $libdir" ;;
- esac
- fi
- case $host in
- *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
- testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'`
- case :$dllsearchpath: in
- *":$libdir:"*) ;;
- *) dllsearchpath="$dllsearchpath:$libdir";;
- esac
- case :$dllsearchpath: in
- *":$testbindir:"*) ;;
- *) dllsearchpath="$dllsearchpath:$testbindir";;
- esac
- ;;
- esac
- done
- # Substitute the hardcoded libdirs into the rpath.
- if test -n "$hardcode_libdir_separator" &&
- test -n "$hardcode_libdirs"; then
- libdir="$hardcode_libdirs"
- eval rpath=\" $hardcode_libdir_flag_spec\"
- fi
- compile_rpath="$rpath"
-
- rpath=
- hardcode_libdirs=
- for libdir in $finalize_rpath; do
- if test -n "$hardcode_libdir_flag_spec"; then
- if test -n "$hardcode_libdir_separator"; then
- if test -z "$hardcode_libdirs"; then
- hardcode_libdirs="$libdir"
- else
- # Just accumulate the unique libdirs.
- case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
- *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
- ;;
- *)
- hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
- ;;
- esac
- fi
- else
- eval flag=\"$hardcode_libdir_flag_spec\"
- rpath="$rpath $flag"
- fi
- elif test -n "$runpath_var"; then
- case "$finalize_perm_rpath " in
- *" $libdir "*) ;;
- *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;;
- esac
- fi
- done
- # Substitute the hardcoded libdirs into the rpath.
- if test -n "$hardcode_libdir_separator" &&
- test -n "$hardcode_libdirs"; then
- libdir="$hardcode_libdirs"
- eval rpath=\" $hardcode_libdir_flag_spec\"
- fi
- finalize_rpath="$rpath"
-
- if test -n "$libobjs" && test "$build_old_libs" = yes; then
- # Transform all the library objects into standard objects.
- compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
- finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
- fi
-
- dlsyms=
- if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
- if test -n "$NM" && test -n "$global_symbol_pipe"; then
- dlsyms="${outputname}S.c"
- else
- $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2
- fi
- fi
-
- if test -n "$dlsyms"; then
- case $dlsyms in
- "") ;;
- *.c)
- # Discover the nlist of each of the dlfiles.
- nlist="$output_objdir/${outputname}.nm"
-
- $show "$rm $nlist ${nlist}S ${nlist}T"
- $run $rm "$nlist" "${nlist}S" "${nlist}T"
-
- # Parse the name list into a source file.
- $show "creating $output_objdir/$dlsyms"
-
- test -z "$run" && $echo > "$output_objdir/$dlsyms" "\
-/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */
-/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */
-
-#ifdef __cplusplus
-extern \"C\" {
-#endif
-
-/* Prevent the only kind of declaration conflicts we can make. */
-#define lt_preloaded_symbols some_other_symbol
-
-/* External symbol declarations for the compiler. */\
-"
-
- if test "$dlself" = yes; then
- $show "generating symbol list for \`$output'"
-
- test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist"
-
- # Add our own program objects to the symbol list.
- progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
- for arg in $progfiles; do
- $show "extracting global C symbols from \`$arg'"
- $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'"
- done
-
- if test -n "$exclude_expsyms"; then
- $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
- $run eval '$mv "$nlist"T "$nlist"'
- fi
-
- if test -n "$export_symbols_regex"; then
- $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
- $run eval '$mv "$nlist"T "$nlist"'
- fi
-
- # Prepare the list of exported symbols
- if test -z "$export_symbols"; then
- export_symbols="$output_objdir/$outputname.exp"
- $run $rm $export_symbols
- $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
- case $host in
- *cygwin* | *mingw* )
- $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
- $run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
- ;;
- esac
- else
- $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
- $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
- $run eval 'mv "$nlist"T "$nlist"'
- case $host in
- *cygwin* | *mingw* )
- $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
- $run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
- ;;
- esac
- fi
- fi
-
- for arg in $dlprefiles; do
- $show "extracting global C symbols from \`$arg'"
- name=`$echo "$arg" | ${SED} -e 's%^.*/%%'`
- $run eval '$echo ": $name " >> "$nlist"'
- $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'"
- done
-
- if test -z "$run"; then
- # Make sure we have at least an empty file.
- test -f "$nlist" || : > "$nlist"
-
- if test -n "$exclude_expsyms"; then
- $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
- $mv "$nlist"T "$nlist"
- fi
-
- # Try sorting and uniquifying the output.
- if grep -v "^: " < "$nlist" |
- if sort -k 3 </dev/null >/dev/null 2>&1; then
- sort -k 3
- else
- sort +2
- fi |
- uniq > "$nlist"S; then
- :
- else
- grep -v "^: " < "$nlist" > "$nlist"S
- fi
-
- if test -f "$nlist"S; then
- eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"'
- else
- $echo '/* NONE */' >> "$output_objdir/$dlsyms"
- fi
-
- $echo >> "$output_objdir/$dlsyms" "\
-
-#undef lt_preloaded_symbols
-
-#if defined (__STDC__) && __STDC__
-# define lt_ptr void *
-#else
-# define lt_ptr char *
-# define const
-#endif
-
-/* The mapping between symbol names and symbols. */
-"
-
- case $host in
- *cygwin* | *mingw* )
- $echo >> "$output_objdir/$dlsyms" "\
-/* DATA imports from DLLs on WIN32 can't be const, because
- runtime relocations are performed -- see ld's documentation
- on pseudo-relocs */
-struct {
-"
- ;;
- * )
- $echo >> "$output_objdir/$dlsyms" "\
-const struct {
-"
- ;;
- esac
-
-
- $echo >> "$output_objdir/$dlsyms" "\
- const char *name;
- lt_ptr address;
-}
-lt_preloaded_symbols[] =
-{\
-"
-
- eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms"
-
- $echo >> "$output_objdir/$dlsyms" "\
- {0, (lt_ptr) 0}
-};
-
-/* This works around a problem in FreeBSD linker */
-#ifdef FREEBSD_WORKAROUND
-static const void *lt_preloaded_setup() {
- return lt_preloaded_symbols;
-}
-#endif
-
-#ifdef __cplusplus
-}
-#endif\
-"
- fi
-
- pic_flag_for_symtable=
- case $host in
- # compiling the symbol table file with pic_flag works around
- # a FreeBSD bug that causes programs to crash when -lm is
- # linked before any other PIC object. But we must not use
- # pic_flag when linking with -static. The problem exists in
- # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
- *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
- case "$compile_command " in
- *" -static "*) ;;
- *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";;
- esac;;
- *-*-hpux*)
- case "$compile_command " in
- *" -static "*) ;;
- *) pic_flag_for_symtable=" $pic_flag";;
- esac
- esac
-
- # Now compile the dynamic symbol file.
- $show "(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")"
- $run eval '(cd $output_objdir && $LTCC $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $?
-
- # Clean up the generated files.
- $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T"
- $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T"
-
- # Transform the symbol file into the correct name.
- case $host in
- *cygwin* | *mingw* )
- if test -f "$output_objdir/${outputname}.def" ; then
- compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%"`
- finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%"`
- else
- compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
- finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
- fi
- ;;
- * )
- compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
- finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
- ;;
- esac
- ;;
- *)
- $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
- else
- # We keep going just in case the user didn't refer to
- # lt_preloaded_symbols. The linker will fail if global_symbol_pipe
- # really was required.
-
- # Nullify the symbol file.
- compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
- finalize_command=`$echo "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
- fi
-
- if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
- # Replace the output file specification.
- compile_command=`$echo "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
- link_command="$compile_command$compile_rpath"
-
- # We have no uninstalled library dependencies, so finalize right now.
- $show "$link_command"
- $run eval "$link_command"
- exit_status=$?
-
- # Delete the generated files.
- if test -n "$dlsyms"; then
- $show "$rm $output_objdir/${outputname}S.${objext}"
- $run $rm "$output_objdir/${outputname}S.${objext}"
- fi
-
- exit $exit_status
- fi
-
- if test -n "$shlibpath_var"; then
- # We should set the shlibpath_var
- rpath=
- for dir in $temp_rpath; do
- case $dir in
- [\\/]* | [A-Za-z]:[\\/]*)
- # Absolute path.
- rpath="$rpath$dir:"
- ;;
- *)
- # Relative path: add a thisdir entry.
- rpath="$rpath\$thisdir/$dir:"
- ;;
- esac
- done
- temp_rpath="$rpath"
- fi
-
- if test -n "$compile_shlibpath$finalize_shlibpath"; then
- compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
- fi
- if test -n "$finalize_shlibpath"; then
- finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
- fi
-
- compile_var=
- finalize_var=
- if test -n "$runpath_var"; then
- if test -n "$perm_rpath"; then
- # We should set the runpath_var.
- rpath=
- for dir in $perm_rpath; do
- rpath="$rpath$dir:"
- done
- compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
- fi
- if test -n "$finalize_perm_rpath"; then
- # We should set the runpath_var.
- rpath=
- for dir in $finalize_perm_rpath; do
- rpath="$rpath$dir:"
- done
- finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
- fi
- fi
-
- if test "$no_install" = yes; then
- # We don't need to create a wrapper script.
- link_command="$compile_var$compile_command$compile_rpath"
- # Replace the output file specification.
- link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
- # Delete the old output file.
- $run $rm $output
- # Link the executable and exit
- $show "$link_command"
- $run eval "$link_command" || exit $?
- exit $EXIT_SUCCESS
- fi
-
- if test "$hardcode_action" = relink; then
- # Fast installation is not supported
- link_command="$compile_var$compile_command$compile_rpath"
- relink_command="$finalize_var$finalize_command$finalize_rpath"
-
- $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2
- $echo "$modename: \`$output' will be relinked during installation" 1>&2
- else
- if test "$fast_install" != no; then
- link_command="$finalize_var$compile_command$finalize_rpath"
- if test "$fast_install" = yes; then
- relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'`
- else
- # fast_install is set to needless
- relink_command=
- fi
- else
- link_command="$compile_var$compile_command$compile_rpath"
- relink_command="$finalize_var$finalize_command$finalize_rpath"
- fi
- fi
-
- # Replace the output file specification.
- link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
-
- # Delete the old output files.
- $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname
-
- $show "$link_command"
- $run eval "$link_command" || exit $?
-
- # Now create the wrapper script.
- $show "creating $output"
-
- # Quote the relink command for shipping.
- if test -n "$relink_command"; then
- # Preserve any variables that may affect compiler behavior
- for var in $variables_saved_for_relink; do
- if eval test -z \"\${$var+set}\"; then
- relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command"
- elif eval var_value=\$$var; test -z "$var_value"; then
- relink_command="$var=; export $var; $relink_command"
- else
- var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"`
- relink_command="$var=\"$var_value\"; export $var; $relink_command"
- fi
- done
- relink_command="(cd `pwd`; $relink_command)"
- relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"`
- fi
-
- # Quote $echo for shipping.
- if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then
- case $progpath in
- [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
- *) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
- esac
- qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"`
- else
- qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"`
- fi
-
- # Only actually do things if our run command is non-null.
- if test -z "$run"; then
- # win32 will think the script is a binary if it has
- # a .exe suffix, so we strip it off here.
- case $output in
- *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;;
- esac
- # test for cygwin because mv fails w/o .exe extensions
- case $host in
- *cygwin*)
- exeext=.exe
- outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;;
- *) exeext= ;;
- esac
- case $host in
- *cygwin* | *mingw* )
- output_name=`basename $output`
- output_path=`dirname $output`
- cwrappersource="$output_path/$objdir/lt-$output_name.c"
- cwrapper="$output_path/$output_name.exe"
- $rm $cwrappersource $cwrapper
- trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
-
- cat > $cwrappersource <<EOF
-
-/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
- Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
-
- The $output program cannot be directly executed until all the libtool
- libraries that it depends on are installed.
-
- This wrapper executable should never be moved out of the build directory.
- If it is, it will not operate correctly.
-
- Currently, it simply execs the wrapper *script* "/bin/sh $output",
- but could eventually absorb all of the scripts functionality and
- exec $objdir/$outputname directly.
-*/
-EOF
- cat >> $cwrappersource<<"EOF"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/stat.h>
-
-#if defined(PATH_MAX)
-# define LT_PATHMAX PATH_MAX
-#elif defined(MAXPATHLEN)
-# define LT_PATHMAX MAXPATHLEN
-#else
-# define LT_PATHMAX 1024
-#endif
-
-#ifndef DIR_SEPARATOR
-# define DIR_SEPARATOR '/'
-# define PATH_SEPARATOR ':'
-#endif
-
-#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
- defined (__OS2__)
-# define HAVE_DOS_BASED_FILE_SYSTEM
-# ifndef DIR_SEPARATOR_2
-# define DIR_SEPARATOR_2 '\\'
-# endif
-# ifndef PATH_SEPARATOR_2
-# define PATH_SEPARATOR_2 ';'
-# endif
-#endif
-
-#ifndef DIR_SEPARATOR_2
-# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
-#else /* DIR_SEPARATOR_2 */
-# define IS_DIR_SEPARATOR(ch) \
- (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
-#endif /* DIR_SEPARATOR_2 */
-
-#ifndef PATH_SEPARATOR_2
-# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
-#else /* PATH_SEPARATOR_2 */
-# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
-#endif /* PATH_SEPARATOR_2 */
-
-#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type)))
-#define XFREE(stale) do { \
- if (stale) { free ((void *) stale); stale = 0; } \
-} while (0)
-
-/* -DDEBUG is fairly common in CFLAGS. */
-#undef DEBUG
-#if defined DEBUGWRAPPER
-# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__)
-#else
-# define DEBUG(format, ...)
-#endif
-
-const char *program_name = NULL;
-
-void * xmalloc (size_t num);
-char * xstrdup (const char *string);
-const char * base_name (const char *name);
-char * find_executable(const char *wrapper);
-int check_executable(const char *path);
-char * strendzap(char *str, const char *pat);
-void lt_fatal (const char *message, ...);
-
-int
-main (int argc, char *argv[])
-{
- char **newargz;
- int i;
-
- program_name = (char *) xstrdup (base_name (argv[0]));
- DEBUG("(main) argv[0] : %s\n",argv[0]);
- DEBUG("(main) program_name : %s\n",program_name);
- newargz = XMALLOC(char *, argc+2);
-EOF
-
- cat >> $cwrappersource <<EOF
- newargz[0] = (char *) xstrdup("$SHELL");
-EOF
-
- cat >> $cwrappersource <<"EOF"
- newargz[1] = find_executable(argv[0]);
- if (newargz[1] == NULL)
- lt_fatal("Couldn't find %s", argv[0]);
- DEBUG("(main) found exe at : %s\n",newargz[1]);
- /* we know the script has the same name, without the .exe */
- /* so make sure newargz[1] doesn't end in .exe */
- strendzap(newargz[1],".exe");
- for (i = 1; i < argc; i++)
- newargz[i+1] = xstrdup(argv[i]);
- newargz[argc+1] = NULL;
-
- for (i=0; i<argc+1; i++)
- {
- DEBUG("(main) newargz[%d] : %s\n",i,newargz[i]);
- ;
- }
-
-EOF
-
- case $host_os in
- mingw*)
- cat >> $cwrappersource <<EOF
- execv("$SHELL",(char const **)newargz);
-EOF
- ;;
- *)
- cat >> $cwrappersource <<EOF
- execv("$SHELL",newargz);
-EOF
- ;;
- esac
-
- cat >> $cwrappersource <<"EOF"
- return 127;
-}
-
-void *
-xmalloc (size_t num)
-{
- void * p = (void *) malloc (num);
- if (!p)
- lt_fatal ("Memory exhausted");
-
- return p;
-}
-
-char *
-xstrdup (const char *string)
-{
- return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL
-;
-}
-
-const char *
-base_name (const char *name)
-{
- const char *base;
-
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
- /* Skip over the disk name in MSDOS pathnames. */
- if (isalpha ((unsigned char)name[0]) && name[1] == ':')
- name += 2;
-#endif
-
- for (base = name; *name; name++)
- if (IS_DIR_SEPARATOR (*name))
- base = name + 1;
- return base;
-}
-
-int
-check_executable(const char * path)
-{
- struct stat st;
-
- DEBUG("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!");
- if ((!path) || (!*path))
- return 0;
-
- if ((stat (path, &st) >= 0) &&
- (
- /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */
-#if defined (S_IXOTH)
- ((st.st_mode & S_IXOTH) == S_IXOTH) ||
-#endif
-#if defined (S_IXGRP)
- ((st.st_mode & S_IXGRP) == S_IXGRP) ||
-#endif
- ((st.st_mode & S_IXUSR) == S_IXUSR))
- )
- return 1;
- else
- return 0;
-}
-
-/* Searches for the full path of the wrapper. Returns
- newly allocated full path name if found, NULL otherwise */
-char *
-find_executable (const char* wrapper)
-{
- int has_slash = 0;
- const char* p;
- const char* p_next;
- /* static buffer for getcwd */
- char tmp[LT_PATHMAX + 1];
- int tmp_len;
- char* concat_name;
-
- DEBUG("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!");
-
- if ((wrapper == NULL) || (*wrapper == '\0'))
- return NULL;
-
- /* Absolute path? */
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
- if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':')
- {
- concat_name = xstrdup (wrapper);
- if (check_executable(concat_name))
- return concat_name;
- XFREE(concat_name);
- }
- else
- {
-#endif
- if (IS_DIR_SEPARATOR (wrapper[0]))
- {
- concat_name = xstrdup (wrapper);
- if (check_executable(concat_name))
- return concat_name;
- XFREE(concat_name);
- }
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
- }
-#endif
-
- for (p = wrapper; *p; p++)
- if (*p == '/')
- {
- has_slash = 1;
- break;
- }
- if (!has_slash)
- {
- /* no slashes; search PATH */
- const char* path = getenv ("PATH");
- if (path != NULL)
- {
- for (p = path; *p; p = p_next)
- {
- const char* q;
- size_t p_len;
- for (q = p; *q; q++)
- if (IS_PATH_SEPARATOR(*q))
- break;
- p_len = q - p;
- p_next = (*q == '\0' ? q : q + 1);
- if (p_len == 0)
- {
- /* empty path: current directory */
- if (getcwd (tmp, LT_PATHMAX) == NULL)
- lt_fatal ("getcwd failed");
- tmp_len = strlen(tmp);
- concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
- memcpy (concat_name, tmp, tmp_len);
- concat_name[tmp_len] = '/';
- strcpy (concat_name + tmp_len + 1, wrapper);
- }
- else
- {
- concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1);
- memcpy (concat_name, p, p_len);
- concat_name[p_len] = '/';
- strcpy (concat_name + p_len + 1, wrapper);
- }
- if (check_executable(concat_name))
- return concat_name;
- XFREE(concat_name);
- }
- }
- /* not found in PATH; assume curdir */
- }
- /* Relative path | not found in path: prepend cwd */
- if (getcwd (tmp, LT_PATHMAX) == NULL)
- lt_fatal ("getcwd failed");
- tmp_len = strlen(tmp);
- concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
- memcpy (concat_name, tmp, tmp_len);
- concat_name[tmp_len] = '/';
- strcpy (concat_name + tmp_len + 1, wrapper);
-
- if (check_executable(concat_name))
- return concat_name;
- XFREE(concat_name);
- return NULL;
-}
-
-char *
-strendzap(char *str, const char *pat)
-{
- size_t len, patlen;
-
- assert(str != NULL);
- assert(pat != NULL);
-
- len = strlen(str);
- patlen = strlen(pat);
-
- if (patlen <= len)
- {
- str += len - patlen;
- if (strcmp(str, pat) == 0)
- *str = '\0';
- }
- return str;
-}
-
-static void
-lt_error_core (int exit_status, const char * mode,
- const char * message, va_list ap)
-{
- fprintf (stderr, "%s: %s: ", program_name, mode);
- vfprintf (stderr, message, ap);
- fprintf (stderr, ".\n");
-
- if (exit_status >= 0)
- exit (exit_status);
-}
-
-void
-lt_fatal (const char *message, ...)
-{
- va_list ap;
- va_start (ap, message);
- lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
- va_end (ap);
-}
-EOF
- # we should really use a build-platform specific compiler
- # here, but OTOH, the wrappers (shell script and this C one)
- # are only useful if you want to execute the "real" binary.
- # Since the "real" binary is built for $host, then this
- # wrapper might as well be built for $host, too.
- $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource
- ;;
- esac
- $rm $output
- trap "$rm $output; exit $EXIT_FAILURE" 1 2 15
-
- $echo > $output "\
-#! $SHELL
-
-# $output - temporary wrapper script for $objdir/$outputname
-# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
-#
-# The $output program cannot be directly executed until all the libtool
-# libraries that it depends on are installed.
-#
-# This wrapper script should never be moved out of the build directory.
-# If it is, it will not operate correctly.
-
-# Sed substitution that helps us do robust quoting. It backslashifies
-# metacharacters that are still active within double-quoted strings.
-Xsed='${SED} -e 1s/^X//'
-sed_quote_subst='$sed_quote_subst'
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-relink_command=\"$relink_command\"
-
-# This environment variable determines our operation mode.
-if test \"\$libtool_install_magic\" = \"$magic\"; then
- # install mode needs the following variable:
- notinst_deplibs='$notinst_deplibs'
-else
- # When we are sourced in execute mode, \$file and \$echo are already set.
- if test \"\$libtool_execute_magic\" != \"$magic\"; then
- echo=\"$qecho\"
- file=\"\$0\"
- # Make sure echo works.
- if test \"X\$1\" = X--no-reexec; then
- # Discard the --no-reexec flag, and continue.
- shift
- elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then
- # Yippee, \$echo works!
- :
- else
- # Restart under the correct shell, and then maybe \$echo will work.
- exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
- fi
- fi\
-"
- $echo >> $output "\
-
- # Find the directory that this script lives in.
- thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
- test \"x\$thisdir\" = \"x\$file\" && thisdir=.
-
- # Follow symbolic links until we get to the real thisdir.
- file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
- while test -n \"\$file\"; do
- destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
-
- # If there was a directory component, then change thisdir.
- if test \"x\$destdir\" != \"x\$file\"; then
- case \"\$destdir\" in
- [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
- *) thisdir=\"\$thisdir/\$destdir\" ;;
- esac
- fi
-
- file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
- file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
- done
-
- # Try to get the absolute directory name.
- absdir=\`cd \"\$thisdir\" && pwd\`
- test -n \"\$absdir\" && thisdir=\"\$absdir\"
-"
-
- if test "$fast_install" = yes; then
- $echo >> $output "\
- program=lt-'$outputname'$exeext
- progdir=\"\$thisdir/$objdir\"
-
- if test ! -f \"\$progdir/\$program\" || \\
- { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
- test \"X\$file\" != \"X\$progdir/\$program\"; }; then
-
- file=\"\$\$-\$program\"
-
- if test ! -d \"\$progdir\"; then
- $mkdir \"\$progdir\"
- else
- $rm \"\$progdir/\$file\"
- fi"
-
- $echo >> $output "\
-
- # relink executable if necessary
- if test -n \"\$relink_command\"; then
- if relink_command_output=\`eval \$relink_command 2>&1\`; then :
- else
- $echo \"\$relink_command_output\" >&2
- $rm \"\$progdir/\$file\"
- exit $EXIT_FAILURE
- fi
- fi
-
- $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
- { $rm \"\$progdir/\$program\";
- $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; }
- $rm \"\$progdir/\$file\"
- fi"
- else
- $echo >> $output "\
- program='$outputname'
- progdir=\"\$thisdir/$objdir\"
-"
- fi
-
- $echo >> $output "\
-
- if test -f \"\$progdir/\$program\"; then"
-
- # Export our shlibpath_var if we have one.
- if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
- $echo >> $output "\
- # Add our own library path to $shlibpath_var
- $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
-
- # Some systems cannot cope with colon-terminated $shlibpath_var
- # The second colon is a workaround for a bug in BeOS R4 sed
- $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`
-
- export $shlibpath_var
-"
- fi
-
- # fixup the dll searchpath if we need to.
- if test -n "$dllsearchpath"; then
- $echo >> $output "\
- # Add the dll search path components to the executable PATH
- PATH=$dllsearchpath:\$PATH
-"
- fi
-
- $echo >> $output "\
- if test \"\$libtool_execute_magic\" != \"$magic\"; then
- # Run the actual program with our arguments.
-"
- case $host in
- # Backslashes separate directories on plain windows
- *-*-mingw | *-*-os2*)
- $echo >> $output "\
- exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
-"
- ;;
-
- *)
- $echo >> $output "\
- exec \"\$progdir/\$program\" \${1+\"\$@\"}
-"
- ;;
- esac
- $echo >> $output "\
- \$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\"
- exit $EXIT_FAILURE
- fi
- else
- # The program doesn't exist.
- \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
- \$echo \"This script is just a wrapper for \$program.\" 1>&2
- $echo \"See the $PACKAGE documentation for more information.\" 1>&2
- exit $EXIT_FAILURE
- fi
-fi\
-"
- chmod +x $output
- fi
- exit $EXIT_SUCCESS
- ;;
- esac
-
- # See if we need to build an old-fashioned archive.
- for oldlib in $oldlibs; do
-
- if test "$build_libtool_libs" = convenience; then
- oldobjs="$libobjs_save"
- addlibs="$convenience"
- build_libtool_libs=no
- else
- if test "$build_libtool_libs" = module; then
- oldobjs="$libobjs_save"
- build_libtool_libs=no
- else
- oldobjs="$old_deplibs $non_pic_objects"
- fi
- addlibs="$old_convenience"
- fi
-
- if test -n "$addlibs"; then
- gentop="$output_objdir/${outputname}x"
- generated="$generated $gentop"
-
- func_extract_archives $gentop $addlibs
- oldobjs="$oldobjs $func_extract_archives_result"
- fi
-
- # Do each command in the archive commands.
- if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
- cmds=$old_archive_from_new_cmds
- else
- # POSIX demands no paths to be encoded in archives. We have
- # to avoid creating archives with duplicate basenames if we
- # might have to extract them afterwards, e.g., when creating a
- # static archive out of a convenience library, or when linking
- # the entirety of a libtool archive into another (currently
- # not supported by libtool).
- if (for obj in $oldobjs
- do
- $echo "X$obj" | $Xsed -e 's%^.*/%%'
- done | sort | sort -uc >/dev/null 2>&1); then
- :
- else
- $echo "copying selected object files to avoid basename conflicts..."
-
- if test -z "$gentop"; then
- gentop="$output_objdir/${outputname}x"
- generated="$generated $gentop"
-
- $show "${rm}r $gentop"
- $run ${rm}r "$gentop"
- $show "$mkdir $gentop"
- $run $mkdir "$gentop"
- exit_status=$?
- if test "$exit_status" -ne 0 && test ! -d "$gentop"; then
- exit $exit_status
- fi
- fi
-
- save_oldobjs=$oldobjs
- oldobjs=
- counter=1
- for obj in $save_oldobjs
- do
- objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
- case " $oldobjs " in
- " ") oldobjs=$obj ;;
- *[\ /]"$objbase "*)
- while :; do
- # Make sure we don't pick an alternate name that also
- # overlaps.
- newobj=lt$counter-$objbase
- counter=`expr $counter + 1`
- case " $oldobjs " in
- *[\ /]"$newobj "*) ;;
- *) if test ! -f "$gentop/$newobj"; then break; fi ;;
- esac
- done
- $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
- $run ln "$obj" "$gentop/$newobj" ||
- $run cp "$obj" "$gentop/$newobj"
- oldobjs="$oldobjs $gentop/$newobj"
- ;;
- *) oldobjs="$oldobjs $obj" ;;
- esac
- done
- fi
-
- eval cmds=\"$old_archive_cmds\"
-
- if len=`expr "X$cmds" : ".*"` &&
- test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
- cmds=$old_archive_cmds
- else
- # the command line is too long to link in one step, link in parts
- $echo "using piecewise archive linking..."
- save_RANLIB=$RANLIB
- RANLIB=:
- objlist=
- concat_cmds=
- save_oldobjs=$oldobjs
-
- # Is there a better way of finding the last object in the list?
- for obj in $save_oldobjs
- do
- last_oldobj=$obj
- done
- for obj in $save_oldobjs
- do
- oldobjs="$objlist $obj"
- objlist="$objlist $obj"
- eval test_cmds=\"$old_archive_cmds\"
- if len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
- test "$len" -le "$max_cmd_len"; then
- :
- else
- # the above command should be used before it gets too long
- oldobjs=$objlist
- if test "$obj" = "$last_oldobj" ; then
- RANLIB=$save_RANLIB
- fi
- test -z "$concat_cmds" || concat_cmds=$concat_cmds~
- eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
- objlist=
- fi
- done
- RANLIB=$save_RANLIB
- oldobjs=$objlist
- if test "X$oldobjs" = "X" ; then
- eval cmds=\"\$concat_cmds\"
- else
- eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
- fi
- fi
- fi
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- eval cmd=\"$cmd\"
- IFS="$save_ifs"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
- done
-
- if test -n "$generated"; then
- $show "${rm}r$generated"
- $run ${rm}r$generated
- fi
-
- # Now create the libtool archive.
- case $output in
- *.la)
- old_library=
- test "$build_old_libs" = yes && old_library="$libname.$libext"
- $show "creating $output"
-
- # Preserve any variables that may affect compiler behavior
- for var in $variables_saved_for_relink; do
- if eval test -z \"\${$var+set}\"; then
- relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command"
- elif eval var_value=\$$var; test -z "$var_value"; then
- relink_command="$var=; export $var; $relink_command"
- else
- var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"`
- relink_command="$var=\"$var_value\"; export $var; $relink_command"
- fi
- done
- # Quote the link command for shipping.
- relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
- relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"`
- if test "$hardcode_automatic" = yes ; then
- relink_command=
- fi
-
-
- # Only create the output if not a dry run.
- if test -z "$run"; then
- for installed in no yes; do
- if test "$installed" = yes; then
- if test -z "$install_libdir"; then
- break
- fi
- output="$output_objdir/$outputname"i
- # Replace all uninstalled libtool libraries with the installed ones
- newdependency_libs=
- for deplib in $dependency_libs; do
- case $deplib in
- *.la)
- name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'`
- eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
- if test -z "$libdir"; then
- $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2
- exit $EXIT_FAILURE
- fi
- newdependency_libs="$newdependency_libs $libdir/$name"
- ;;
- *) newdependency_libs="$newdependency_libs $deplib" ;;
- esac
- done
- dependency_libs="$newdependency_libs"
- newdlfiles=
- for lib in $dlfiles; do
- name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
- eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
- if test -z "$libdir"; then
- $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
- exit $EXIT_FAILURE
- fi
- newdlfiles="$newdlfiles $libdir/$name"
- done
- dlfiles="$newdlfiles"
- newdlprefiles=
- for lib in $dlprefiles; do
- name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
- eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
- if test -z "$libdir"; then
- $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
- exit $EXIT_FAILURE
- fi
- newdlprefiles="$newdlprefiles $libdir/$name"
- done
- dlprefiles="$newdlprefiles"
- else
- newdlfiles=
- for lib in $dlfiles; do
- case $lib in
- [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
- *) abs=`pwd`"/$lib" ;;
- esac
- newdlfiles="$newdlfiles $abs"
- done
- dlfiles="$newdlfiles"
- newdlprefiles=
- for lib in $dlprefiles; do
- case $lib in
- [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
- *) abs=`pwd`"/$lib" ;;
- esac
- newdlprefiles="$newdlprefiles $abs"
- done
- dlprefiles="$newdlprefiles"
- fi
- $rm $output
- # place dlname in correct position for cygwin
- tdlname=$dlname
- case $host,$output,$installed,$module,$dlname in
- *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
- esac
- $echo > $output "\
-# $outputname - a libtool library file
-# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# The name that we can dlopen(3).
-dlname='$tdlname'
-
-# Names of this library.
-library_names='$library_names'
-
-# The name of the static archive.
-old_library='$old_library'
-
-# Libraries that this one depends upon.
-dependency_libs='$dependency_libs'
-
-# Version information for $libname.
-current=$current
-age=$age
-revision=$revision
-
-# Is this an already installed library?
-installed=$installed
-
-# Should we warn about portability when linking against -modules?
-shouldnotlink=$module
-
-# Files to dlopen/dlpreopen
-dlopen='$dlfiles'
-dlpreopen='$dlprefiles'
-
-# Directory that this library needs to be installed in:
-libdir='$install_libdir'"
- if test "$installed" = no && test "$need_relink" = yes; then
- $echo >> $output "\
-relink_command=\"$relink_command\""
- fi
- done
- fi
-
- # Do a symbolic link so that the libtool archive can be found in
- # LD_LIBRARY_PATH before the program is installed.
- $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)"
- $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $?
- ;;
- esac
- exit $EXIT_SUCCESS
- ;;
-
- # libtool install mode
- install)
- modename="$modename: install"
-
- # There may be an optional sh(1) argument at the beginning of
- # install_prog (especially on Windows NT).
- if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
- # Allow the use of GNU shtool's install command.
- $echo "X$nonopt" | grep shtool > /dev/null; then
- # Aesthetically quote it.
- arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"`
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- install_prog="$arg "
- arg="$1"
- shift
- else
- install_prog=
- arg=$nonopt
- fi
-
- # The real first argument should be the name of the installation program.
- # Aesthetically quote it.
- arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- install_prog="$install_prog$arg"
-
- # We need to accept at least all the BSD install flags.
- dest=
- files=
- opts=
- prev=
- install_type=
- isdir=no
- stripme=
- for arg
- do
- if test -n "$dest"; then
- files="$files $dest"
- dest=$arg
- continue
- fi
-
- case $arg in
- -d) isdir=yes ;;
- -f)
- case " $install_prog " in
- *[\\\ /]cp\ *) ;;
- *) prev=$arg ;;
- esac
- ;;
- -g | -m | -o) prev=$arg ;;
- -s)
- stripme=" -s"
- continue
- ;;
- -*)
- ;;
- *)
- # If the previous option needed an argument, then skip it.
- if test -n "$prev"; then
- prev=
- else
- dest=$arg
- continue
- fi
- ;;
- esac
-
- # Aesthetically quote the argument.
- arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
- case $arg in
- *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
- arg="\"$arg\""
- ;;
- esac
- install_prog="$install_prog $arg"
- done
-
- if test -z "$install_prog"; then
- $echo "$modename: you must specify an install program" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- if test -n "$prev"; then
- $echo "$modename: the \`$prev' option requires an argument" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- if test -z "$files"; then
- if test -z "$dest"; then
- $echo "$modename: no file or destination specified" 1>&2
- else
- $echo "$modename: you must specify a destination" 1>&2
- fi
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Strip any trailing slash from the destination.
- dest=`$echo "X$dest" | $Xsed -e 's%/$%%'`
-
- # Check to see that the destination is a directory.
- test -d "$dest" && isdir=yes
- if test "$isdir" = yes; then
- destdir="$dest"
- destname=
- else
- destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'`
- test "X$destdir" = "X$dest" && destdir=.
- destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'`
-
- # Not a directory, so check to see that there is only one file specified.
- set dummy $files
- if test "$#" -gt 2; then
- $echo "$modename: \`$dest' is not a directory" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
- fi
- case $destdir in
- [\\/]* | [A-Za-z]:[\\/]*) ;;
- *)
- for file in $files; do
- case $file in
- *.lo) ;;
- *)
- $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
- done
- ;;
- esac
-
- # This variable tells wrapper scripts just to set variables rather
- # than running their programs.
- libtool_install_magic="$magic"
-
- staticlibs=
- future_libdirs=
- current_libdirs=
- for file in $files; do
-
- # Do each installation.
- case $file in
- *.$libext)
- # Do the static libraries later.
- staticlibs="$staticlibs $file"
- ;;
-
- *.la)
- # Check to see that this really is a libtool archive.
- if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
- else
- $echo "$modename: \`$file' is not a valid libtool archive" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- library_names=
- old_library=
- relink_command=
- # If there is no directory component, then add one.
- case $file in
- */* | *\\*) . $file ;;
- *) . ./$file ;;
- esac
-
- # Add the libdir to current_libdirs if it is the destination.
- if test "X$destdir" = "X$libdir"; then
- case "$current_libdirs " in
- *" $libdir "*) ;;
- *) current_libdirs="$current_libdirs $libdir" ;;
- esac
- else
- # Note the libdir as a future libdir.
- case "$future_libdirs " in
- *" $libdir "*) ;;
- *) future_libdirs="$future_libdirs $libdir" ;;
- esac
- fi
-
- dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/
- test "X$dir" = "X$file/" && dir=
- dir="$dir$objdir"
-
- if test -n "$relink_command"; then
- # Determine the prefix the user has applied to our future dir.
- inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"`
-
- # Don't allow the user to place us outside of our expected
- # location b/c this prevents finding dependent libraries that
- # are installed to the same prefix.
- # At present, this check doesn't affect windows .dll's that
- # are installed into $libdir/../bin (currently, that works fine)
- # but it's something to keep an eye on.
- if test "$inst_prefix_dir" = "$destdir"; then
- $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2
- exit $EXIT_FAILURE
- fi
-
- if test -n "$inst_prefix_dir"; then
- # Stick the inst_prefix_dir data into the link command.
- relink_command=`$echo "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
- else
- relink_command=`$echo "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
- fi
-
- $echo "$modename: warning: relinking \`$file'" 1>&2
- $show "$relink_command"
- if $run eval "$relink_command"; then :
- else
- $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2
- exit $EXIT_FAILURE
- fi
- fi
-
- # See the names of the shared library.
- set dummy $library_names
- if test -n "$2"; then
- realname="$2"
- shift
- shift
-
- srcname="$realname"
- test -n "$relink_command" && srcname="$realname"T
-
- # Install the shared library and build the symlinks.
- $show "$install_prog $dir/$srcname $destdir/$realname"
- $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $?
- if test -n "$stripme" && test -n "$striplib"; then
- $show "$striplib $destdir/$realname"
- $run eval "$striplib $destdir/$realname" || exit $?
- fi
-
- if test "$#" -gt 0; then
- # Delete the old symlinks, and create new ones.
- # Try `ln -sf' first, because the `ln' binary might depend on
- # the symlink we replace! Solaris /bin/ln does not understand -f,
- # so we also need to try rm && ln -s.
- for linkname
- do
- if test "$linkname" != "$realname"; then
- $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })"
- $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })"
- fi
- done
- fi
-
- # Do each command in the postinstall commands.
- lib="$destdir/$realname"
- cmds=$postinstall_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || {
- lt_exit=$?
-
- # Restore the uninstalled library and exit
- if test "$mode" = relink; then
- $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)'
- fi
-
- exit $lt_exit
- }
- done
- IFS="$save_ifs"
- fi
-
- # Install the pseudo-library for information purposes.
- name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
- instname="$dir/$name"i
- $show "$install_prog $instname $destdir/$name"
- $run eval "$install_prog $instname $destdir/$name" || exit $?
-
- # Maybe install the static library, too.
- test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
- ;;
-
- *.lo)
- # Install (i.e. copy) a libtool object.
-
- # Figure out destination file name, if it wasn't already specified.
- if test -n "$destname"; then
- destfile="$destdir/$destname"
- else
- destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
- destfile="$destdir/$destfile"
- fi
-
- # Deduce the name of the destination old-style object file.
- case $destfile in
- *.lo)
- staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"`
- ;;
- *.$objext)
- staticdest="$destfile"
- destfile=
- ;;
- *)
- $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- # Install the libtool object if requested.
- if test -n "$destfile"; then
- $show "$install_prog $file $destfile"
- $run eval "$install_prog $file $destfile" || exit $?
- fi
-
- # Install the old object if enabled.
- if test "$build_old_libs" = yes; then
- # Deduce the name of the old-style object file.
- staticobj=`$echo "X$file" | $Xsed -e "$lo2o"`
-
- $show "$install_prog $staticobj $staticdest"
- $run eval "$install_prog \$staticobj \$staticdest" || exit $?
- fi
- exit $EXIT_SUCCESS
- ;;
-
- *)
- # Figure out destination file name, if it wasn't already specified.
- if test -n "$destname"; then
- destfile="$destdir/$destname"
- else
- destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
- destfile="$destdir/$destfile"
- fi
-
- # If the file is missing, and there is a .exe on the end, strip it
- # because it is most likely a libtool script we actually want to
- # install
- stripped_ext=""
- case $file in
- *.exe)
- if test ! -f "$file"; then
- file=`$echo $file|${SED} 's,.exe$,,'`
- stripped_ext=".exe"
- fi
- ;;
- esac
-
- # Do a test to see if this is really a libtool program.
- case $host in
- *cygwin*|*mingw*)
- wrapper=`$echo $file | ${SED} -e 's,.exe$,,'`
- ;;
- *)
- wrapper=$file
- ;;
- esac
- if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then
- notinst_deplibs=
- relink_command=
-
- # Note that it is not necessary on cygwin/mingw to append a dot to
- # foo even if both foo and FILE.exe exist: automatic-append-.exe
- # behavior happens only for exec(3), not for open(2)! Also, sourcing
- # `FILE.' does not work on cygwin managed mounts.
- #
- # If there is no directory component, then add one.
- case $wrapper in
- */* | *\\*) . ${wrapper} ;;
- *) . ./${wrapper} ;;
- esac
-
- # Check the variables that should have been set.
- if test -z "$notinst_deplibs"; then
- $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2
- exit $EXIT_FAILURE
- fi
-
- finalize=yes
- for lib in $notinst_deplibs; do
- # Check to see that each library is installed.
- libdir=
- if test -f "$lib"; then
- # If there is no directory component, then add one.
- case $lib in
- */* | *\\*) . $lib ;;
- *) . ./$lib ;;
- esac
- fi
- libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test
- if test -n "$libdir" && test ! -f "$libfile"; then
- $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2
- finalize=no
- fi
- done
-
- relink_command=
- # Note that it is not necessary on cygwin/mingw to append a dot to
- # foo even if both foo and FILE.exe exist: automatic-append-.exe
- # behavior happens only for exec(3), not for open(2)! Also, sourcing
- # `FILE.' does not work on cygwin managed mounts.
- #
- # If there is no directory component, then add one.
- case $wrapper in
- */* | *\\*) . ${wrapper} ;;
- *) . ./${wrapper} ;;
- esac
-
- outputname=
- if test "$fast_install" = no && test -n "$relink_command"; then
- if test "$finalize" = yes && test -z "$run"; then
- tmpdir=`func_mktempdir`
- file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'`
- outputname="$tmpdir/$file"
- # Replace the output file specification.
- relink_command=`$echo "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
-
- $show "$relink_command"
- if $run eval "$relink_command"; then :
- else
- $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2
- ${rm}r "$tmpdir"
- continue
- fi
- file="$outputname"
- else
- $echo "$modename: warning: cannot relink \`$file'" 1>&2
- fi
- else
- # Install the binary that we compiled earlier.
- file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
- fi
- fi
-
- # remove .exe since cygwin /usr/bin/install will append another
- # one anyway
- case $install_prog,$host in
- */usr/bin/install*,*cygwin*)
- case $file:$destfile in
- *.exe:*.exe)
- # this is ok
- ;;
- *.exe:*)
- destfile=$destfile.exe
- ;;
- *:*.exe)
- destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'`
- ;;
- esac
- ;;
- esac
- $show "$install_prog$stripme $file $destfile"
- $run eval "$install_prog\$stripme \$file \$destfile" || exit $?
- test -n "$outputname" && ${rm}r "$tmpdir"
- ;;
- esac
- done
-
- for file in $staticlibs; do
- name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
-
- # Set up the ranlib parameters.
- oldlib="$destdir/$name"
-
- $show "$install_prog $file $oldlib"
- $run eval "$install_prog \$file \$oldlib" || exit $?
-
- if test -n "$stripme" && test -n "$old_striplib"; then
- $show "$old_striplib $oldlib"
- $run eval "$old_striplib $oldlib" || exit $?
- fi
-
- # Do each command in the postinstall commands.
- cmds=$old_postinstall_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || exit $?
- done
- IFS="$save_ifs"
- done
-
- if test -n "$future_libdirs"; then
- $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2
- fi
-
- if test -n "$current_libdirs"; then
- # Maybe just do a dry run.
- test -n "$run" && current_libdirs=" -n$current_libdirs"
- exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
- else
- exit $EXIT_SUCCESS
- fi
- ;;
-
- # libtool finish mode
- finish)
- modename="$modename: finish"
- libdirs="$nonopt"
- admincmds=
-
- if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
- for dir
- do
- libdirs="$libdirs $dir"
- done
-
- for libdir in $libdirs; do
- if test -n "$finish_cmds"; then
- # Do each command in the finish commands.
- cmds=$finish_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd" || admincmds="$admincmds
- $cmd"
- done
- IFS="$save_ifs"
- fi
- if test -n "$finish_eval"; then
- # Do the single finish_eval.
- eval cmds=\"$finish_eval\"
- $run eval "$cmds" || admincmds="$admincmds
- $cmds"
- fi
- done
- fi
-
- # Exit here if they wanted silent mode.
- test "$show" = : && exit $EXIT_SUCCESS
-
- $echo "X----------------------------------------------------------------------" | $Xsed
- $echo "Libraries have been installed in:"
- for libdir in $libdirs; do
- $echo " $libdir"
- done
- $echo
- $echo "If you ever happen to want to link against installed libraries"
- $echo "in a given directory, LIBDIR, you must either use libtool, and"
- $echo "specify the full pathname of the library, or use the \`-LLIBDIR'"
- $echo "flag during linking and do at least one of the following:"
- if test -n "$shlibpath_var"; then
- $echo " - add LIBDIR to the \`$shlibpath_var' environment variable"
- $echo " during execution"
- fi
- if test -n "$runpath_var"; then
- $echo " - add LIBDIR to the \`$runpath_var' environment variable"
- $echo " during linking"
- fi
- if test -n "$hardcode_libdir_flag_spec"; then
- libdir=LIBDIR
- eval flag=\"$hardcode_libdir_flag_spec\"
-
- $echo " - use the \`$flag' linker flag"
- fi
- if test -n "$admincmds"; then
- $echo " - have your system administrator run these commands:$admincmds"
- fi
- if test -f /etc/ld.so.conf; then
- $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
- fi
- $echo
- $echo "See any operating system documentation about shared libraries for"
- $echo "more information, such as the ld(1) and ld.so(8) manual pages."
- $echo "X----------------------------------------------------------------------" | $Xsed
- exit $EXIT_SUCCESS
- ;;
-
- # libtool execute mode
- execute)
- modename="$modename: execute"
-
- # The first argument is the command name.
- cmd="$nonopt"
- if test -z "$cmd"; then
- $echo "$modename: you must specify a COMMAND" 1>&2
- $echo "$help"
- exit $EXIT_FAILURE
- fi
-
- # Handle -dlopen flags immediately.
- for file in $execute_dlfiles; do
- if test ! -f "$file"; then
- $echo "$modename: \`$file' is not a file" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- dir=
- case $file in
- *.la)
- # Check to see that this really is a libtool archive.
- if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
- else
- $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- # Read the libtool library.
- dlname=
- library_names=
-
- # If there is no directory component, then add one.
- case $file in
- */* | *\\*) . $file ;;
- *) . ./$file ;;
- esac
-
- # Skip this library if it cannot be dlopened.
- if test -z "$dlname"; then
- # Warn if it was a shared library.
- test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'"
- continue
- fi
-
- dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
- test "X$dir" = "X$file" && dir=.
-
- if test -f "$dir/$objdir/$dlname"; then
- dir="$dir/$objdir"
- else
- $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2
- exit $EXIT_FAILURE
- fi
- ;;
-
- *.lo)
- # Just add the directory containing the .lo file.
- dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
- test "X$dir" = "X$file" && dir=.
- ;;
-
- *)
- $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2
- continue
- ;;
- esac
-
- # Get the absolute pathname.
- absdir=`cd "$dir" && pwd`
- test -n "$absdir" && dir="$absdir"
-
- # Now add the directory to shlibpath_var.
- if eval "test -z \"\$$shlibpath_var\""; then
- eval "$shlibpath_var=\"\$dir\""
- else
- eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
- fi
- done
-
- # This variable tells wrapper scripts just to set shlibpath_var
- # rather than running their programs.
- libtool_execute_magic="$magic"
-
- # Check if any of the arguments is a wrapper script.
- args=
- for file
- do
- case $file in
- -*) ;;
- *)
- # Do a test to see if this is really a libtool program.
- if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
- # If there is no directory component, then add one.
- case $file in
- */* | *\\*) . $file ;;
- *) . ./$file ;;
- esac
-
- # Transform arg to wrapped name.
- file="$progdir/$program"
- fi
- ;;
- esac
- # Quote arguments (to preserve shell metacharacters).
- file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"`
- args="$args \"$file\""
- done
-
- if test -z "$run"; then
- if test -n "$shlibpath_var"; then
- # Export the shlibpath_var.
- eval "export $shlibpath_var"
- fi
-
- # Restore saved environment variables
- if test "${save_LC_ALL+set}" = set; then
- LC_ALL="$save_LC_ALL"; export LC_ALL
- fi
- if test "${save_LANG+set}" = set; then
- LANG="$save_LANG"; export LANG
- fi
-
- # Now prepare to actually exec the command.
- exec_cmd="\$cmd$args"
- else
- # Display what would be done.
- if test -n "$shlibpath_var"; then
- eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\""
- $echo "export $shlibpath_var"
- fi
- $echo "$cmd$args"
- exit $EXIT_SUCCESS
- fi
- ;;
-
- # libtool clean and uninstall mode
- clean | uninstall)
- modename="$modename: $mode"
- rm="$nonopt"
- files=
- rmforce=
- exit_status=0
-
- # This variable tells wrapper scripts just to set variables rather
- # than running their programs.
- libtool_install_magic="$magic"
-
- for arg
- do
- case $arg in
- -f) rm="$rm $arg"; rmforce=yes ;;
- -*) rm="$rm $arg" ;;
- *) files="$files $arg" ;;
- esac
- done
-
- if test -z "$rm"; then
- $echo "$modename: you must specify an RM program" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- fi
-
- rmdirs=
-
- origobjdir="$objdir"
- for file in $files; do
- dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
- if test "X$dir" = "X$file"; then
- dir=.
- objdir="$origobjdir"
- else
- objdir="$dir/$origobjdir"
- fi
- name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
- test "$mode" = uninstall && objdir="$dir"
-
- # Remember objdir for removal later, being careful to avoid duplicates
- if test "$mode" = clean; then
- case " $rmdirs " in
- *" $objdir "*) ;;
- *) rmdirs="$rmdirs $objdir" ;;
- esac
- fi
-
- # Don't error if the file doesn't exist and rm -f was used.
- if (test -L "$file") >/dev/null 2>&1 \
- || (test -h "$file") >/dev/null 2>&1 \
- || test -f "$file"; then
- :
- elif test -d "$file"; then
- exit_status=1
- continue
- elif test "$rmforce" = yes; then
- continue
- fi
-
- rmfiles="$file"
-
- case $name in
- *.la)
- # Possibly a libtool archive, so verify it.
- if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
- . $dir/$name
-
- # Delete the libtool libraries and symlinks.
- for n in $library_names; do
- rmfiles="$rmfiles $objdir/$n"
- done
- test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
-
- case "$mode" in
- clean)
- case " $library_names " in
- # " " in the beginning catches empty $dlname
- *" $dlname "*) ;;
- *) rmfiles="$rmfiles $objdir/$dlname" ;;
- esac
- test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
- ;;
- uninstall)
- if test -n "$library_names"; then
- # Do each command in the postuninstall commands.
- cmds=$postuninstall_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd"
- if test "$?" -ne 0 && test "$rmforce" != yes; then
- exit_status=1
- fi
- done
- IFS="$save_ifs"
- fi
-
- if test -n "$old_library"; then
- # Do each command in the old_postuninstall commands.
- cmds=$old_postuninstall_cmds
- save_ifs="$IFS"; IFS='~'
- for cmd in $cmds; do
- IFS="$save_ifs"
- eval cmd=\"$cmd\"
- $show "$cmd"
- $run eval "$cmd"
- if test "$?" -ne 0 && test "$rmforce" != yes; then
- exit_status=1
- fi
- done
- IFS="$save_ifs"
- fi
- # FIXME: should reinstall the best remaining shared library.
- ;;
- esac
- fi
- ;;
-
- *.lo)
- # Possibly a libtool object, so verify it.
- if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
-
- # Read the .lo file
- . $dir/$name
-
- # Add PIC object to the list of files to remove.
- if test -n "$pic_object" \
- && test "$pic_object" != none; then
- rmfiles="$rmfiles $dir/$pic_object"
- fi
-
- # Add non-PIC object to the list of files to remove.
- if test -n "$non_pic_object" \
- && test "$non_pic_object" != none; then
- rmfiles="$rmfiles $dir/$non_pic_object"
- fi
- fi
- ;;
-
- *)
- if test "$mode" = clean ; then
- noexename=$name
- case $file in
- *.exe)
- file=`$echo $file|${SED} 's,.exe$,,'`
- noexename=`$echo $name|${SED} 's,.exe$,,'`
- # $file with .exe has already been added to rmfiles,
- # add $file without .exe
- rmfiles="$rmfiles $file"
- ;;
- esac
- # Do a test to see if this is a libtool program.
- if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
- relink_command=
- . $dir/$noexename
-
- # note $name still contains .exe if it was in $file originally
- # as does the version of $file that was added into $rmfiles
- rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
- if test "$fast_install" = yes && test -n "$relink_command"; then
- rmfiles="$rmfiles $objdir/lt-$name"
- fi
- if test "X$noexename" != "X$name" ; then
- rmfiles="$rmfiles $objdir/lt-${noexename}.c"
- fi
- fi
- fi
- ;;
- esac
- $show "$rm $rmfiles"
- $run $rm $rmfiles || exit_status=1
- done
- objdir="$origobjdir"
-
- # Try to remove the ${objdir}s in the directories where we deleted files
- for dir in $rmdirs; do
- if test -d "$dir"; then
- $show "rmdir $dir"
- $run rmdir $dir >/dev/null 2>&1
- fi
- done
-
- exit $exit_status
- ;;
-
- "")
- $echo "$modename: you must specify a MODE" 1>&2
- $echo "$generic_help" 1>&2
- exit $EXIT_FAILURE
- ;;
- esac
-
- if test -z "$exec_cmd"; then
- $echo "$modename: invalid operation mode \`$mode'" 1>&2
- $echo "$generic_help" 1>&2
- exit $EXIT_FAILURE
- fi
-fi # test -z "$show_help"
-
-if test -n "$exec_cmd"; then
- eval exec $exec_cmd
- exit $EXIT_FAILURE
-fi
-
-# We need to display help for each of the modes.
-case $mode in
-"") $echo \
-"Usage: $modename [OPTION]... [MODE-ARG]...
-
-Provide generalized library-building support services.
-
- --config show all configuration variables
- --debug enable verbose shell tracing
--n, --dry-run display commands without modifying any files
- --features display basic configuration information and exit
- --finish same as \`--mode=finish'
- --help display this help message and exit
- --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS]
- --quiet same as \`--silent'
- --silent don't print informational messages
- --tag=TAG use configuration variables from tag TAG
- --version print version information
-
-MODE must be one of the following:
-
- clean remove files from the build directory
- compile compile a source file into a libtool object
- execute automatically set library path, then run a program
- finish complete the installation of libtool libraries
- install install libraries or executables
- link create a library or an executable
- uninstall remove libraries from an installed directory
-
-MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for
-a more detailed description of MODE.
-
-Report bugs to <bug-libtool@gnu.org>."
- exit $EXIT_SUCCESS
- ;;
-
-clean)
- $echo \
-"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
-
-Remove files from the build directory.
-
-RM is the name of the program to use to delete files associated with each FILE
-(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed
-to RM.
-
-If FILE is a libtool library, object or program, all the files associated
-with it are deleted. Otherwise, only FILE itself is deleted using RM."
- ;;
-
-compile)
- $echo \
-"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
-
-Compile a source file into a libtool library object.
-
-This mode accepts the following additional options:
-
- -o OUTPUT-FILE set the output file name to OUTPUT-FILE
- -prefer-pic try to building PIC objects only
- -prefer-non-pic try to building non-PIC objects only
- -static always build a \`.o' file suitable for static linking
-
-COMPILE-COMMAND is a command to be used in creating a \`standard' object file
-from the given SOURCEFILE.
-
-The output file name is determined by removing the directory component from
-SOURCEFILE, then substituting the C source code suffix \`.c' with the
-library object suffix, \`.lo'."
- ;;
-
-execute)
- $echo \
-"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]...
-
-Automatically set library path, then run a program.
-
-This mode accepts the following additional options:
-
- -dlopen FILE add the directory containing FILE to the library path
-
-This mode sets the library path environment variable according to \`-dlopen'
-flags.
-
-If any of the ARGS are libtool executable wrappers, then they are translated
-into their corresponding uninstalled binary, and any of their required library
-directories are added to the library path.
-
-Then, COMMAND is executed, with ARGS as arguments."
- ;;
-
-finish)
- $echo \
-"Usage: $modename [OPTION]... --mode=finish [LIBDIR]...
-
-Complete the installation of libtool libraries.
-
-Each LIBDIR is a directory that contains libtool libraries.
-
-The commands that this mode executes may require superuser privileges. Use
-the \`--dry-run' option if you just want to see what would be executed."
- ;;
-
-install)
- $echo \
-"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND...
-
-Install executables or libraries.
-
-INSTALL-COMMAND is the installation command. The first component should be
-either the \`install' or \`cp' program.
-
-The rest of the components are interpreted as arguments to that command (only
-BSD-compatible install options are recognized)."
- ;;
-
-link)
- $echo \
-"Usage: $modename [OPTION]... --mode=link LINK-COMMAND...
-
-Link object files or libraries together to form another library, or to
-create an executable program.
-
-LINK-COMMAND is a command using the C compiler that you would use to create
-a program from several object files.
-
-The following components of LINK-COMMAND are treated specially:
-
- -all-static do not do any dynamic linking at all
- -avoid-version do not add a version suffix if possible
- -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime
- -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols
- -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
- -export-symbols SYMFILE
- try to export only the symbols listed in SYMFILE
- -export-symbols-regex REGEX
- try to export only the symbols matching REGEX
- -LLIBDIR search LIBDIR for required installed libraries
- -lNAME OUTPUT-FILE requires the installed library libNAME
- -module build a library that can dlopened
- -no-fast-install disable the fast-install mode
- -no-install link a not-installable executable
- -no-undefined declare that a library does not refer to external symbols
- -o OUTPUT-FILE create OUTPUT-FILE from the specified objects
- -objectlist FILE Use a list of object files found in FILE to specify objects
- -precious-files-regex REGEX
- don't remove output files matching REGEX
- -release RELEASE specify package release information
- -rpath LIBDIR the created library will eventually be installed in LIBDIR
- -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries
- -static do not do any dynamic linking of libtool libraries
- -version-info CURRENT[:REVISION[:AGE]]
- specify library version info [each variable defaults to 0]
-
-All other options (arguments beginning with \`-') are ignored.
-
-Every other argument is treated as a filename. Files ending in \`.la' are
-treated as uninstalled libtool libraries, other files are standard or library
-object files.
-
-If the OUTPUT-FILE ends in \`.la', then a libtool library is created,
-only library objects (\`.lo' files) may be specified, and \`-rpath' is
-required, except when creating a convenience library.
-
-If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created
-using \`ar' and \`ranlib', or on Windows using \`lib'.
-
-If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file
-is created, otherwise an executable program is created."
- ;;
-
-uninstall)
- $echo \
-"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
-
-Remove libraries from an installation directory.
-
-RM is the name of the program to use to delete files associated with each FILE
-(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed
-to RM.
-
-If FILE is a libtool library, all the files associated with it are deleted.
-Otherwise, only FILE itself is deleted using RM."
- ;;
-
-*)
- $echo "$modename: invalid operation mode \`$mode'" 1>&2
- $echo "$help" 1>&2
- exit $EXIT_FAILURE
- ;;
-esac
-
-$echo
-$echo "Try \`$modename --help' for more information about other modes."
-
-exit $?
-
-# The TAGs below are defined such that we never get into a situation
-# in which we disable both kinds of libraries. Given conflicting
-# choices, we go for a static library, that is the most portable,
-# since we can't tell whether shared libraries were disabled because
-# the user asked for that or because the platform doesn't support
-# them. This is particularly important on AIX, because we don't
-# support having both static and shared libraries enabled at the same
-# time on that platform, so we default to a shared-only configuration.
-# If a disable-shared tag is given, we'll fallback to a static-only
-# configuration. But we'll never go from static-only to shared-only.
-
-# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
-disable_libs=shared
-# ### END LIBTOOL TAG CONFIG: disable-shared
-
-# ### BEGIN LIBTOOL TAG CONFIG: disable-static
-disable_libs=static
-# ### END LIBTOOL TAG CONFIG: disable-static
-
-# Local Variables:
-# mode:shell-script
-# sh-indentation:2
-# End:
+++ /dev/null
-#include <isc/result.h>
-#include <isc/net.h>
-#include <l_stdlib.h>
-#include <ntp_fp.h>
-#include <ntp.h>
-#include <ntp_stdlib.h>
-#include <ntp_unixtime.h>
-#include <stdio.h>
-
-#include <sntp-opts.h>
-
-#include "crypto.h"
-#include "kod_management.h"
-#include "networking.h"
-#include "utilities.h"
-#include "log.h"
-
-
-int ai_fam_pref;
-volatile int debug;
-char adr_buf[INET6_ADDRSTRLEN];
-
-struct key *keys = NULL;
-
-void set_li_vn_mode (struct pkt *spkt, char leap, char version, char mode);
-int sntp_main (int argc, char **argv);
-int on_wire (struct addrinfo *host);
-int set_time (double offset);
-
-
-#if !HAVE_MALLOC
-void *
-rpl_malloc (size_t n)
-{
- if (n == 0)
- n = 1;
- return malloc (n);
-}
-#endif /* !HAVE_MALLOC */
-
-int
-main (
- int argc,
- char **argv
- )
-{
- return sntp_main(argc, argv);
-}
-
-/*
- * The actual main function.
- */
-int
-sntp_main (
- int argc,
- char **argv
- )
-{
- register int c;
- struct kod_entry *reason = NULL;
- int optct;
- int sync_data_suc = 0;
- struct addrinfo **resh = NULL;
- int resc;
-
- /* IPv6 available? */
- if (isc_net_probeipv6() != ISC_R_SUCCESS) {
- ai_fam_pref = AF_INET;
-#ifdef DEBUG
- printf("No ipv6 support available, forcing ipv4\n");
-#endif
- }
- else {
- /* Check for options -4 and -6 */
- if(ENABLED_OPT(IPV4))
- ai_fam_pref = AF_INET;
- else if(ENABLED_OPT(IPV6))
- ai_fam_pref = AF_INET6;
- else
- ai_fam_pref = 0;
- }
-
- log_msg("Started sntp", 0);
-
- optct = optionProcess(&sntpOptions, argc, argv);
- argc -= optct;
- argv += optct;
-
- /* Parse config file if declared TODO */
-
- /* Initialize logging system */
- if (HAVE_OPT(FILELOG))
- init_log(OPT_ARG(FILELOG));
-
- /* If there's a specified KOD file init KOD system.
- * If not and system may save to HD use default file.
- */
- if (HAVE_OPT(KOD))
- kod_init_kod_db(OPT_ARG(KOD));
-
- if (HAVE_OPT(KEYFILE))
- auth_init(OPT_ARG(KEYFILE), &keys);
-
-
- /* Considering employing a variable that prevents functions of doing anything until
- * everything is initialized properly
- */
- resc = resolve_hosts(argv, argc, &resh, ai_fam_pref);
-
- if (resc < 1) {
- printf("Unable to resolve hostname(s)\n");
- return -1;
- }
-
- /* Select a certain ntp server according to simple criteria? For now
- * let's just pay attention to previous KoDs.
- */
- for (c = 0; c < resc && !sync_data_suc; c++) {
- getnameinfo(resh[c]->ai_addr, resh[c]->ai_addrlen, adr_buf,
- sizeof(adr_buf), NULL, 0, NI_NUMERICHOST);
-
- int kodc;
- char *hostname = addrinfo_to_str(resh[c]);
-
- if ((kodc = search_entry(hostname, &reason)) == 0) {
- if (is_reachable(resh[c])) {
- int ow_ret = on_wire(resh[c]);
-
- if (ow_ret < 0)
- printf("on_wire failed for server %s!\n", hostname);
- else
- sync_data_suc = 1;
- }
- } else {
- printf("KoD %i packages exists for %s, stopping any further communication.\n",
- kodc, adr_buf);
- free(reason);
- }
-
- freeaddrinfo(resh[c]);
- free(hostname);
- }
- free(resh);
-
- return 0;
-}
-
-/* The heart of (S)NTP, exchange NTP packets and compute values to correct the local clock */
-int
-on_wire (
- struct addrinfo *host
- )
-{
- register int try;
- SOCKET sock;
- struct pkt *x_pkt = (struct pkt *) alloca(sizeof(struct pkt));
- struct pkt *r_pkt = (struct pkt *) alloca(sizeof(struct pkt));
-
- for(try=0; try<5; try++) {
- struct timeval tv_xmt, tv_dst;
- double t21, t34, delta, offset;
- int error, rpktl, sw_case;
- char *hostname = NULL, *ts_str = NULL;
- l_fp p_rec, p_xmt, p_ref, p_org, xmt, tmp, dst;
-
- memset(r_pkt, 0, sizeof(*r_pkt));
- memset(x_pkt, 0, sizeof(*x_pkt));
-
- error = GETTIMEOFDAY(&tv_xmt, (struct timezone *)NULL);
-
- tv_xmt.tv_sec += JAN_1970;
-
-#ifdef DEBUG
- printf("sntp on_wire: Current time sec: %i msec: %i\n", (unsigned int) tv_xmt.tv_sec,
- (unsigned int) tv_xmt.tv_usec);
-#endif
-
- TVTOTS(&tv_xmt, &xmt);
- HTONL_FP(&xmt, &(x_pkt->xmt));
-
- x_pkt->stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
- x_pkt->ppoll = 8;
- /* FIXME! Modus broadcast + adr. check -> bdr. pkt */
- set_li_vn_mode(x_pkt, LEAP_NOTINSYNC, 4, 3);
-
- create_socket(&sock, (sockaddr_u *)host->ai_addr);
-
- sendpkt(sock, (sockaddr_u *)host->ai_addr, x_pkt, LEN_PKT_NOMAC);
- rpktl = recvpkt(sock, r_pkt, x_pkt);
-
- closesocket(sock);
-
- if(rpktl > 0)
- sw_case = 1;
- else
- sw_case = rpktl;
-
- switch(sw_case) {
- case SERVER_UNUSEABLE:
- return -1;
- break;
-
- case PACKET_UNUSEABLE:
- break;
-
- case SERVER_AUTH_FAIL:
- break;
-
- case KOD_DEMOBILIZE:
- /* Received a DENY or RESTR KOD packet */
- hostname = addrinfo_to_str(host);
- add_entry(hostname, (char *) &r_pkt->refid);
-
- if(ENABLED_OPT(NORMALVERBOSE))
- printf("sntp on_wire: Received KOD packet with code: %s from %s, demobilizing all connections\n",
- (char *) r_pkt->refid, hostname);
-
- char *log_str = (char *) malloc(sizeof(char) * (INET6_ADDRSTRLEN + 72));
- snprintf(log_str, sizeof(log_str),
- "Received a KOD packet with code %s from %s, demobilizing all connections",
- (char *) &r_pkt->refid, hostname);
-
- log_msg(log_str, 2);
-
- free(log_str);
- break;
-
- case KOD_RATE:
- /* Hmm... probably we should sleep a bit here */
- break;
-
- case 1:
-
- /* Convert timestamps from network to host byte order */
- NTOHL_FP(&r_pkt->reftime, &p_ref);
- NTOHL_FP(&r_pkt->org, &p_org);
- NTOHL_FP(&r_pkt->rec, &p_rec);
- NTOHL_FP(&r_pkt->xmt, &p_xmt);
-
- if(ENABLED_OPT(NORMALVERBOSE)) {
- getnameinfo(host->ai_addr, host->ai_addrlen, adr_buf,
- sizeof(adr_buf), NULL, 0, NI_NUMERICHOST);
-
- printf("sntp on_wire: Received %i bytes from %s\n", rpktl, adr_buf);
- }
-
-#ifdef DEBUG
- pkt_output(r_pkt, rpktl, stdout);
-
- printf("sntp on_wire: rpkt->reftime:\n");
- l_fp_output(&(r_pkt->reftime), stdout);
- printf("sntp on_wire: rpkt->org:\n");
- l_fp_output(&(r_pkt->org), stdout);
- printf("sntp on_wire: rpkt->rec:\n");
- l_fp_output(&(r_pkt->rec), stdout);
- printf("sntp on_wire: rpkt->rec:\n");
- l_fp_output_bin(&(r_pkt->rec), stdout);
- printf("sntp on_wire: rpkt->rec:\n");
- l_fp_output_dec(&(r_pkt->rec), stdout);
- printf("sntp on_wire: rpkt->xmt:\n");
- l_fp_output(&(r_pkt->xmt), stdout);
-#endif
-
- /* Compute offset etc. */
- GETTIMEOFDAY(&tv_dst, (struct timezone *)NULL);
-
- tv_dst.tv_sec += JAN_1970;
-
- tmp = p_rec;
- L_SUB(&tmp, &p_org);
-
- LFPTOD(&tmp, t21);
-
- TVTOTS(&tv_dst, &dst);
-
- tmp = dst;
- L_SUB(&tmp, &p_xmt);
-
- LFPTOD(&tmp, t34);
-
- offset = (t21 + t34) / 2.;
- delta = t21 - t34;
-
- if(ENABLED_OPT(NORMALVERBOSE))
- printf("sntp on_wire:\tt21: %.6f\t\t t34: %.6f\n\t\tdelta: %.6f\t offset: %.6f\n",
- t21, t34, delta, offset);
-
- ts_str = tv_to_str(&tv_dst);
-
- printf("%s ", ts_str);
-
- if(offset > 0)
- printf("+");
-
- printf("%.3f\n", offset);
- free(ts_str);
-
- if(ENABLED_OPT(SETTOD) || ENABLED_OPT(ADJTIME))
- return set_time(offset);
-
- return 0;
- }
- }
-
- char logmsg[32 + INET6_ADDRSTRLEN];
- getnameinfo(host->ai_addr, host->ai_addrlen, adr_buf, sizeof(adr_buf), NULL, 0, NI_NUMERICHOST);
-
- snprintf(logmsg, sizeof(logmsg), "Received no useable packet from %s!", adr_buf);
-
- if(ENABLED_OPT(NORMALVERBOSE))
- printf("sntp on_wire: Received no useable packet from %s!\n", adr_buf);
-
-
- log_msg(logmsg, 1);
-
- return -1;
-}
-
-/* Compute the 8 bits for li_vn_mode */
-void
-set_li_vn_mode (
- struct pkt *spkt,
- char leap,
- char version,
- char mode
- )
-{
-
- if(leap > 3) {
- debug_msg("set_li_vn_mode: leap > 3 using max. 3");
- leap = 3;
- }
-
- if(mode > 7) {
- debug_msg("set_li_vn_mode: mode > 7, using client mode 3");
- mode = 3;
- }
-
- spkt->li_vn_mode = leap << 6;
- spkt->li_vn_mode |= version << 3;
- spkt->li_vn_mode |= mode;
-}
-
-/* set_time corrects the local clock by offset with either settimeofday() or by default
- * with adjtime()/adjusttimeofday().
- */
-int
-set_time (
- double offset
- )
-{
- struct timeval tp;
-
- if(ENABLED_OPT(SETTOD)) {
- GETTIMEOFDAY(&tp, (struct timezone *)NULL);
-
- tp.tv_sec += (int) offset;
- tp.tv_usec += offset - (double)((int)offset);
-
- if(SETTIMEOFDAY(&tp, (struct timezone *)NULL) < 0) {
- if(errno == EPERM)
- printf("set_time: You don't have enough priviledges to call settimeofday(), cannot set time!\n");
-
- else
- printf("set_time: settimeofday() returned with an error, couldn't set time!\n");
-
- return -1;
- }
- else {
- return 0;
- }
- }
- else {
- tp.tv_sec = (int) offset;
- tp.tv_usec = offset - (double)((int)offset);
-
- if(ADJTIMEOFDAY(&tp, NULL) < 0) {
- if(errno == EPERM)
- printf("set_time: You don't have enough priviledges to call adjtime(), cannot set time!\n");
- else
- printf("set_time: adjtime() returned with an error, couldn't set time!\n");
-
- return -1;
- }
- else {
- return 0;
- }
- }
-}
+++ /dev/null
-/*
- * EDIT THIS FILE WITH CAUTION (sntp-opts.c)
- *
- * It has been AutoGen-ed August 9, 2009 at 07:52:56 AM by AutoGen 5.9.9pre5
- * From the definitions sntp-opts.def
- * and the template file options
- *
- * Generated from AutoOpts 32:1:7 templates.
- */
-
-/*
- * This file was produced by an AutoOpts template. AutoOpts is a
- * copyrighted work. This source file is not encumbered by AutoOpts
- * licensing, but is provided under the licensing terms chosen by the
- * sntp 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.
- *
- * This source file is copyrighted and licensed under the following terms:
- *
- * sntp copyright (c) 2008 ntp.org - all rights reserved
- *
- *
- */
-
-#include <sys/types.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#define OPTION_CODE_COMPILE 1
-#include "sntp-opts.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* TRANSLATORS: choose the translation for option names wisely because you
- cannot ever change your mind. */
-tSCC zCopyright[] =
- "sntp copyright (c) 2008 ntp.org, all rights reserved"
-/* extracted from sntp-opts.def near line 17 */
-;
-tSCC zCopyrightNotice[1] =
-"";
-
-extern tUsageProc optionUsage;
-
-#ifndef NULL
-# define NULL 0
-#endif
-#ifndef EXIT_SUCCESS
-# define EXIT_SUCCESS 0
-#endif
-#ifndef EXIT_FAILURE
-# define EXIT_FAILURE 1
-#endif
-/*
- * Ipv4 option description:
- */
-tSCC zIpv4Text[] =
- "Force IPv4 DNS name resolution";
-tSCC zIpv4_NAME[] = "IPV4";
-tSCC zIpv4_Name[] = "ipv4";
-#define IPV4_FLAGS (OPTST_DISABLED)
-
-/*
- * Ipv6 option description:
- */
-tSCC zIpv6Text[] =
- "Force IPv6 DNS name resolution";
-tSCC zIpv6_NAME[] = "IPV6";
-tSCC zIpv6_Name[] = "ipv6";
-#define IPV6_FLAGS (OPTST_DISABLED)
-
-/*
- * Normalverbose option description:
- */
-tSCC zNormalverboseText[] =
- "Normal verbose";
-tSCC zNormalverbose_NAME[] = "NORMALVERBOSE";
-tSCC zNormalverbose_Name[] = "normalverbose";
-#define NORMALVERBOSE_FLAGS (OPTST_DISABLED)
-
-/*
- * Kod option description:
- */
-tSCC zKodText[] =
- "Specify a file for the KOD packet storage";
-tSCC zKod_NAME[] = "KOD";
-tSCC zKod_Name[] = "kod";
-#define KOD_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
-
-/*
- * Syslog option description with
- * "Must also have options" and "Incompatible options":
- */
-tSCC zSyslogText[] =
- "Logging with syslog";
-tSCC zSyslog_NAME[] = "SYSLOG";
-tSCC zSyslog_Name[] = "syslog";
-static const int
- aSyslogCantList[] = {
- INDEX_OPT_FILELOG, NO_EQUIVALENT };
-#define SYSLOG_FLAGS (OPTST_DISABLED)
-
-/*
- * Filelog option description with
- * "Must also have options" and "Incompatible options":
- */
-tSCC zFilelogText[] =
- "Logging to specified logfile";
-tSCC zFilelog_NAME[] = "FILELOG";
-tSCC zFilelog_Name[] = "filelog";
-static const int
- aFilelogCantList[] = {
- INDEX_OPT_SYSLOG, NO_EQUIVALENT };
-#define FILELOG_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
-
-/*
- * Settod option description with
- * "Must also have options" and "Incompatible options":
- */
-tSCC zSettodText[] =
- "Set (step) the time with settimeofday()";
-tSCC zSettod_NAME[] = "SETTOD";
-tSCC zSettod_Name[] = "settod";
-static const int
- aSettodCantList[] = {
- INDEX_OPT_ADJTIME, NO_EQUIVALENT };
-#define SETTOD_FLAGS (OPTST_DISABLED)
-
-/*
- * Adjtime option description with
- * "Must also have options" and "Incompatible options":
- */
-tSCC zAdjtimeText[] =
- "Set (slew) the time with adjtime()";
-tSCC zAdjtime_NAME[] = "ADJTIME";
-tSCC zAdjtime_Name[] = "adjtime";
-static const int
- aAdjtimeCantList[] = {
- INDEX_OPT_SETTOD, NO_EQUIVALENT };
-#define ADJTIME_FLAGS (OPTST_DISABLED)
-
-/*
- * Broadcast option description:
- */
-tSCC zBroadcastText[] =
- "Use broadcast packages from the broadcast address specified for synchronisation";
-tSCC zBroadcast_NAME[] = "BROADCAST";
-tSCC zBroadcast_Name[] = "broadcast";
-#define BROADCAST_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
-
-/*
- * Timeout option description:
- */
-tSCC zTimeoutText[] =
- "Specify the number of seconds until SNTP times out when waiting for broadcast packets";
-tSCC zTimeout_NAME[] = "TIMEOUT";
-tSCC zTimeout_Name[] = "timeout";
-#define TIMEOUT_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
-
-/*
- * Authentication option description:
- */
-tSCC zAuthenticationText[] =
- "Enable authentication with the key keyno. This option is used as -a keyno";
-tSCC zAuthentication_NAME[] = "AUTHENTICATION";
-tSCC zAuthentication_Name[] = "authentication";
-#define AUTHENTICATION_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
-
-/*
- * Keyfile option description:
- */
-tSCC zKeyfileText[] =
- "Specify a keyfile. SNTP will look in this file for the key specified with -a";
-tSCC zKeyfile_NAME[] = "KEYFILE";
-tSCC zKeyfile_Name[] = "keyfile";
-#define KEYFILE_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
-
-/*
- * Help/More_Help/Version option descriptions:
- */
-tSCC zHelpText[] = "Display usage information and exit";
-tSCC zHelp_Name[] = "help";
-tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
-tSCC zMore_Help_Name[] = "more-help";
-tSCC zVersionText[] = "Output version information and exit";
-tSCC zVersion_Name[] = "version";
-tSCC zSave_OptsText[] = "Save the option state to a config file";
-tSCC zSave_Opts_Name[] = "save-opts";
-tSCC zLoad_OptsText[] = "Load options from a config file";
-tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
-tSCC zNotLoad_Opts_Name[] = "no-load-opts";
-tSCC zNotLoad_Opts_Pfx[] = "no";
-#define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
-/*
- * Declare option callback procedures
- */
-#if defined(TEST_SNTP_OPTS)
-/*
- * Under test, omit argument processing, or call optionStackArg,
- * if multiple copies are allowed.
- */
-extern tOptProc
- optionNumericVal, optionPagedUsage, optionVersionStderr;
-static tOptProc
- doUsageOpt;
-
-#else /* NOT defined TEST_SNTP_OPTS */
-/*
- * When not under test, there are different procs to use
- */
-extern tOptProc
- optionNumericVal, optionPagedUsage, optionPrintVersion;
-static tOptProc
- doUsageOpt;
-#endif /* defined(TEST_SNTP_OPTS) */
-#ifdef TEST_SNTP_OPTS
-# define DOVERPROC optionVersionStderr
-#else
-# define DOVERPROC optionPrintVersion
-#endif /* TEST_SNTP_OPTS */
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Define the Sntp Option Descriptions.
- */
-static tOptDesc optDesc[ OPTION_CT ] = {
- { /* entry idx, value */ 0, VALUE_OPT_IPV4,
- /* equiv idx, value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ IPV4_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zIpv4Text, zIpv4_NAME, zIpv4_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 1, VALUE_OPT_IPV6,
- /* equiv idx, value */ NOLIMIT, NOLIMIT,
- /* equivalenced to */ INDEX_OPT_IPV4,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ IPV6_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 2, VALUE_OPT_NORMALVERBOSE,
- /* equiv idx, value */ 2, VALUE_OPT_NORMALVERBOSE,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ NORMALVERBOSE_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zNormalverboseText, zNormalverbose_NAME, zNormalverbose_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 3, VALUE_OPT_KOD,
- /* equiv idx, value */ 3, VALUE_OPT_KOD,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ KOD_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zKodText, zKod_NAME, zKod_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 4, VALUE_OPT_SYSLOG,
- /* equiv idx, value */ 4, VALUE_OPT_SYSLOG,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ SYSLOG_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aSyslogCantList,
- /* option proc */ NULL,
- /* desc, NAME, name */ zSyslogText, zSyslog_NAME, zSyslog_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 5, VALUE_OPT_FILELOG,
- /* equiv idx, value */ 5, VALUE_OPT_FILELOG,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ FILELOG_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aFilelogCantList,
- /* option proc */ NULL,
- /* desc, NAME, name */ zFilelogText, zFilelog_NAME, zFilelog_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 6, VALUE_OPT_SETTOD,
- /* equiv idx, value */ 6, VALUE_OPT_SETTOD,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ SETTOD_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aSettodCantList,
- /* option proc */ NULL,
- /* desc, NAME, name */ zSettodText, zSettod_NAME, zSettod_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 7, VALUE_OPT_ADJTIME,
- /* equiv idx, value */ 7, VALUE_OPT_ADJTIME,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ ADJTIME_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aAdjtimeCantList,
- /* option proc */ NULL,
- /* desc, NAME, name */ zAdjtimeText, zAdjtime_NAME, zAdjtime_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 8, VALUE_OPT_BROADCAST,
- /* equiv idx, value */ 8, VALUE_OPT_BROADCAST,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ BROADCAST_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zBroadcastText, zBroadcast_NAME, zBroadcast_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 9, VALUE_OPT_TIMEOUT,
- /* equiv idx, value */ 9, VALUE_OPT_TIMEOUT,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ TIMEOUT_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionNumericVal,
- /* desc, NAME, name */ zTimeoutText, zTimeout_NAME, zTimeout_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 10, VALUE_OPT_AUTHENTICATION,
- /* equiv idx, value */ 10, VALUE_OPT_AUTHENTICATION,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ AUTHENTICATION_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionNumericVal,
- /* desc, NAME, name */ zAuthenticationText, zAuthentication_NAME, zAuthentication_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ 11, VALUE_OPT_KEYFILE,
- /* equiv idx, value */ 11, VALUE_OPT_KEYFILE,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ KEYFILE_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zKeyfileText, zKeyfile_NAME, zKeyfile_Name,
- /* disablement strs */ NULL, NULL },
-
-#ifdef NO_OPTIONAL_OPT_ARGS
-# define VERSION_OPT_FLAGS OPTST_IMM | OPTST_NO_INIT
-#else
-# define VERSION_OPT_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
- OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
-#endif
-
- { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VERSION_OPT_FLAGS, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ DOVERPROC,
- /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
- /* disablement strs */ NULL, NULL },
-
-#undef VERSION_OPT_FLAGS
-
-
- { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doUsageOpt,
- /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionPagedUsage,
- /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
- | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
- /* disablement strs */ NULL, NULL },
-
- { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, NOLIMIT, 0,
- /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
- | OPTST_DISABLE_IMM, 0,
- /* last opt argumnt */ { NULL },
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionLoadOpt,
- /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
- /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
-};
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Define the Sntp Option Environment
- */
-tSCC zPROGNAME[] = "SNTP";
-tSCC zUsageTitle[] =
-"sntp - standard SNTP program - Ver. 4.2.5p199\n\
-USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... ...\n";
-tSCC zRcName[] = ".ntprc";
-tSCC* apzHomeList[] = {
- "$HOME",
- ".",
- NULL };
-
-tSCC zBugsAddr[] = "http://bugs.ntp.org, bugs@ntp.org";
-#define zExplain NULL
-tSCC zDetail[] = "\n\
-.I sntp\n\
-can be used as a SNTP client to query a NTP or SNTP server and either display\n\
-the time or set the local system's time (given suitable privilege). It can be\n\
-run as an interactive command or in a\n\
-.I cron\n\
-job.\n\
-NTP is the Network Time Protocol (RFC 1305) and SNTP is the\n\
-Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).\n";
-tSCC zFullVersion[] = SNTP_FULL_VERSION;
-/* extracted from /usr/local/gnu/share/autogen/optcode.tpl near line 501 */
-
-#if defined(ENABLE_NLS)
-# define OPTPROC_BASE OPTPROC_TRANSLATE
- static tOptionXlateProc translate_option_strings;
-#else
-# define OPTPROC_BASE OPTPROC_NONE
-# define translate_option_strings NULL
-#endif /* ENABLE_NLS */
-
-
-#define sntp_full_usage NULL
-#define sntp_short_usage NULL
-tOptions sntpOptions = {
- OPTIONS_STRUCT_VERSION,
- 0, NULL, /* original argc + argv */
- ( OPTPROC_BASE
- + OPTPROC_ERRSTOP
- + OPTPROC_SHORTOPT
- + OPTPROC_LONGOPT
- + OPTPROC_NO_REQ_OPT
- + OPTPROC_ENVIRON
- + OPTPROC_ARGS_REQ ),
- 0, NULL, /* current option index, current option */
- NULL, NULL, zPROGNAME,
- zRcName, zCopyright, zCopyrightNotice,
- zFullVersion, apzHomeList, zUsageTitle,
- zExplain, zDetail, optDesc,
- zBugsAddr, /* address to send bugs to */
- NULL, NULL, /* extensions/saved state */
- optionUsage, /* usage procedure */
- translate_option_strings, /* translation procedure */
- /*
- * Indexes to special options
- */
- { INDEX_OPT_MORE_HELP, /* more-help option index */
- INDEX_OPT_SAVE_OPTS, /* save option index */
- NO_EQUIVALENT, /* '-#' option index */
- NO_EQUIVALENT /* index of default opt */
- },
- 17 /* full option count */, 12 /* user option count */,
- sntp_full_usage, sntp_short_usage,
- NULL, NULL
-};
-
-/*
- * Create the static procedure(s) declared above.
- */
-static void
-doUsageOpt(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
-{
- (void)pOptions;
- USAGE( EXIT_SUCCESS );
-}
-/* extracted from /usr/local/gnu/share/autogen/optmain.tpl near line 109 */
-
-#if defined(TEST_SNTP_OPTS) /* TEST MAIN PROCEDURE: */
-
-extern void optionPutShell( tOptions* );
-
-int
-main(int argc, char** argv)
-{
- int res = EXIT_SUCCESS;
- (void)optionProcess( &sntpOptions, argc, argv );
- optionPutShell( &sntpOptions );
- return res;
-}
-#endif /* defined TEST_SNTP_OPTS */
-/* extracted from /usr/local/gnu/share/autogen/optcode.tpl near line 633 */
-
-#if ENABLE_NLS
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <autoopts/usage-txt.h>
-
-static char* AO_gettext( char const* pz );
-static void coerce_it(void** s);
-
-static char*
-AO_gettext( char const* pz )
-{
- char* pzRes;
- if (pz == NULL)
- return NULL;
- pzRes = _(pz);
- if (pzRes == pz)
- return pzRes;
- pzRes = strdup( pzRes );
- if (pzRes == NULL) {
- fputs( _("No memory for duping translated strings\n"), stderr );
- exit( EXIT_FAILURE );
- }
- return pzRes;
-}
-
-static void coerce_it(void** s) { *s = AO_gettext(*s); }
-#define COERSION(_f) \
- coerce_it((void*)&(sntpOptions._f))
-
-/*
- * This invokes the translation code (e.g. gettext(3)).
- */
-static void
-translate_option_strings( void )
-{
- /*
- * Guard against re-translation. It won't work. The strings will have
- * been changed by the first pass through this code. One shot only.
- */
- if (option_usage_text.field_ct != 0) {
-
- /*
- * Do the translations. The first pointer follows the field count
- * field. The field count field is the size of a pointer.
- */
- tOptDesc* pOD = sntpOptions.pOptDesc;
- char** ppz = (char**)(void*)&(option_usage_text);
- int ix = option_usage_text.field_ct;
-
- do {
- ppz++;
- *ppz = AO_gettext(*ppz);
- } while (--ix > 0);
-
- COERSION(pzCopyright);
- COERSION(pzCopyNotice);
- COERSION(pzFullVersion);
- COERSION(pzUsageTitle);
- COERSION(pzExplain);
- COERSION(pzDetail);
- option_usage_text.field_ct = 0;
-
- for (ix = sntpOptions.optCt; ix > 0; ix--, pOD++)
- coerce_it((void*)&(pOD->pzText));
- }
-
- if ((sntpOptions.fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
- tOptDesc* pOD = sntpOptions.pOptDesc;
- int ix;
-
- for (ix = sntpOptions.optCt; ix > 0; ix--, pOD++) {
- coerce_it((void*)&(pOD->pz_Name));
- coerce_it((void*)&(pOD->pz_DisableName));
- coerce_it((void*)&(pOD->pz_DisablePfx));
- }
- /* prevent re-translation */
- sntpOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
- }
-}
-
-#endif /* ENABLE_NLS */
-
-#ifdef __cplusplus
-}
-#endif
-/* sntp-opts.c ends here */
+++ /dev/null
-/* -*- Mode: Text -*- */
-
-autogen definitions options;
-
-#include autogen-version.def
-
-prog-name = "sntp";
-prog-title = "standard SNTP program";
-homerc = $HOME, ".";
-argument = '...';
-
-copyright = {
- date = "2008";
- owner = "ntp.org";
- eaddr = "http://bugs.ntp.org, bugs@ntp.org";
- type = note;
- text = `cat COPYRIGHT`;
-};
-
-
-long-opts;
-
-config-header = "config.h";
-
-#ifndef __windows__
-rcfile = ".ntprc";
-#else
-rcfile = "ntp.ini";
-#endif
-
-environrc;
-
-#include version.def
-
-test-main;
-
-flag = {
- name = ipv4;
- value = 4;
- equivalence = ipv4;
- descrip = "Force IPv4 DNS name resolution";
- doc = <<- _EndOfDoc_
- Force DNS resolution of following host names on the command line
- to the IPv4 namespace.
- _EndOfDoc_;
-};
-
-flag = {
- name = ipv6;
- value = 6;
- equivalence = ipv4;
- descrip = "Force IPv6 DNS name resolution";
- doc = <<- _EndOfDoc_
- Force DNS resolution of following host names on the command line
- to the IPv6 namespace.
- _EndOfDoc_;
-};
-
-flag = {
- name = normalverbose;
- value = d;
- descrip = "Normal verbose";
- doc = <<- _EndOfDoc_
- Diagnostic messages for non-fatal errors and a limited amount of
- tracing should be written to standard error. Fatal ones always
- produce a diagnostic. This option should be set when there is a
- suspected problem with the server, network or the source.
- _EndOfDoc_;
-};
-
-flag = {
- name = kod;
- value = K;
- arg-type = string;
- descrip = "Specify a file for the KOD packet storage";
- doc = <<- _EndOfDoc_
- Specifies the file to be used to store KOD packaet information.
- _EndOfDoc_;
-};
-
-
-flag = {
- name = syslog;
- value = p;
- flags-cant = filelog;
- descrip = "Logging with syslog";
- doc = <<- _EndOfDoc_
- When this option is set all logging will be done using syslog.
- _EndOfDoc_;
-};
-
-flag = {
- name = filelog;
- value = l;
- arg-type = string;
- flags-cant = syslog;
- descrip = "Logging to specified logfile";
- doc = <<- _EndOfDoc_
- This option causes the client to write log messages to the specified
- logfile.
- _EndOfDoc_;
-};
-
-flag = {
- name = settod;
- value = s;
- flags-cant = adjtime;
- descrip = "Set (step) the time with settimeofday()";
- doc = <<- _EndOfDoc_
- _EndOfDoc_;
-};
-
-flag = {
- name = adjtime;
- value = j;
- flags-cant = settod;
- descrip = "Set (slew) the time with adjtime()";
- doc = <<- _EndOfDoc_
- _EndOfDoc_;
-};
-
-flag = {
- name = broadcast;
- value = b;
- descrip = "Use broadcast packages from the broadcast address specified for synchronisation";
- arg-type = string;
- doc = <<- _EndOfDoc_
- If specified SNTP will wait 1 minute for broadcast packets
- from the broadcast address specified for synchronisation.
- The amount of time SNTP waits can be specified with -t.
- _EndOfDoc_;
-};
-
-flag = {
- name = timeout;
- value = t;
- descrip = "Specify the number of seconds until SNTP times out when waiting for broadcast packets";
- arg-type = number;
- doc = <<- _EndOfDoc_
- When waiting for a broadcast packet SNTP will wait the number
- of seconds specified and times out.
- _EndOfDoc_;
-};
-
-flag = {
- name = authentication;
- value = a;
- descrip = "Enable authentication with the key keyno. This option is used as -a keyno";
- arg-type = number;
- doc = <<- _EndOfDoc_
- This option enables authentication using the key specified in this option\'s argument.
- The argument of this option is the keyid, a number specified in the keyfile as this
- key\'s identifier. See the keyfile option -k for more details.
- _EndOfDoc_;
-};
-
-flag = {
- name = keyfile;
- value = k;
- descrip = "Specify a keyfile. SNTP will look in this file for the key specified with -a";
- arg-type = string;
- doc = <<- _EndOfDoc_
- This option specifies the keyfile. SNTP will search for the key specified with -a keyno in this
- file. Key files follow the following format:
-
- keyid keytype key
-
- Where keyid is a number identifying this key
- keytype is one of the follow:
- S Key in 64 Bit hexadecimal number as specified in in the DES specification.
- N Key in 64 Bit hexadecimal number as specified in the NTP standard.
- A Key in a 1-to-8 character ASCII string.
- M Key in a 1-to-8 character ASCII string using the MD5 authentication scheme.
-
- See more information see ntp.keys(5).
- _EndOfDoc_;
-};
-
-
-
-
-detail = <<- _END_DETAIL
-.I sntp
-can be used as a SNTP client to query a NTP or SNTP server and either display
-the time or set the local system's time (given suitable privilege). It can be
-run as an interactive command or in a
-.I cron
-job.
-NTP is the Network Time Protocol (RFC 1305) and SNTP is the
-Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).
- _END_DETAIL;
-
-prog-man-descrip = <<- _END_PROG_MAN_DESCRIP
-.I sntp
-can be used as a SNTP client to query a NTP or SNTP server and either display
-the time or set the local system's time (given suitable privilege). It can be
-run as an interactive command or in a
-.I cron
-job.
-NTP is the Network Time Protocol (RFC 1305) and SNTP is the
-Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).
-.SS Options
-.PP
-.I sntp
-recognizes the following options:
-.TP
-.B \-v
-indicates that diagnostic messages for non-fatal errors and a limited amount of
-tracing should be written to standard error. Fatal ones always produce a
-diagnostic. This option should be set when there is a suspected problem with
-the server, network or the source.
-.TP
-.B \-V
-requests more and less comprehensible output, mainly for investigating problems
-with apparently inconsistent timestamps. This option should be set when the
-program fails with a message indicating that is the trouble.
-.TP
-.B \-W
-requests very verbose debugging output, and will interfere with the timing
-when writing to the terminal (because of line buffered output from C). Note
-that the times produced by this are the corrections needed, and not the error
-in the local clock. This option should be set only when debugging the source.
-.TP
-.B \-r
-indicates that the system clock should be reset by
-.IR settod .
-Naturally, this will work only if the user has enough privilege.
-.TP
-.B \-a
-indicates that the system clock should be reset by
-.IR adjtime .
-Naturally, this will work only if the user has enough privilege.
-.PP
-The default is to write the estimated correct local date and time (i.e. not
-UTC) to the standard output in a format like
-.BR "'1996 Oct 15 20:17:25.123 + 4.567 +/- 0.089 secs'" ,
-where the
-.B "'+ 4.567 +/- 0.089 secs'"
-indicates the estimated error in the time on the local system.
-.TP
-.BI \-l " lockfile"
-sets the name of the lock file to ensure that there is only
-one copy of
-.I sntp
-running at once. The default is installation-dependent, but will usually be
-.IR /etc/sntp.pid .
-.TP
-.BI \-c " count"
-sets the maximum number of NTP packets required to
-.IR count .
-Acceptable values are from 1 to 25 if a NTP host is specified and from 5 to 25
-otherwise, and the default is 5. If the maximum isn't enough, the system needs
-a better consistency algorithm than this program uses.
-.TP
-.B -4
-force IPv4 DNS resolution.
-.TP
-.B -6
-force IPv6 DNS resolution.
-.PP
-.B address(es)
-are the DNS names or IP numbers of hosts to use for the challenge and response
-protocol; if no names are given, the program waits for broadcasts. Polling a
-server is vastly more reliable than listening to broadcasts. Note that a
-single component numeric address is not allowed, to avoid ambiguities. If
-more than one name is give, they will be used in a round-robin fashion.
-.PP
-Constraints:
-.IP
-.BR delay / count "),"
-and
-.B count
-must be less than half of
-.BR delay .
-.IP
-In update mode,
-.B maxerr
-must be less than
-.SH USAGE
-The simplest use of this program is as an unprivileged command to check the
-current time and error in the local clock. For example:
-.IP
-.B sntp ntpserver.somewhere
-.PP
-With suitable privilege, it can be run as a command or in a
-.I cron
-job to reset the local clock from a reliable server, like the
-.I ntpdate
-and
-.I rdate
-commands. For example:
-.IP
-.B sntp -a ntpserver.somewhere
-.PP
-More information on how to use this utility is given in the
-.I README
-file in the distribution. In particular, this
-.I man
-page does not describe how to set it up as a server, which needs special care
-to avoid propagating misinformation.
-.SH RETURN VALUE
-When used as a client in non-daemon mode, the program returns a zero exit
-status for success, and a non-zero one otherwise. When used as a daemon
-(either client or server), it does not return except after a serious error.
-.SH BUGS
-The program implements the SNTP protocol, and does not provide all NTP
-facilities. In particular, it contains no checks against any form of spoofing.
-If this is a serious concern, some network security mechanism (like a firewall
-or even just
-.IR tcpwrappers )
-should be installed.
-.PP
-There are some errors, ambiguities and inconsistencies in the RFCs, and this
-code may not interwork with all other NTP implementations. Any unreasonable
-restrictions should be reported as bugs to whoever is responsible. It may
-be difficult to find out who that is.
-.PP
-The program will stop as soon as it feels that things have got out of control.
-In client daemon mode, it will usually fail during an extended period of
-network or server inaccessibility or excessively slow performance, or when the
-local clock is reset by another process. It will then need restarting
-manually. Experienced system administrators can write a shell script, a
-.I cron
-job or put it in
-.IR inittab ,
-to do this automatically.
-.PP
-.SH AUTHOR
-.I sntp
- _END_PROG_MAN_DESCRIP;
+++ /dev/null
-/*
- * EDIT THIS FILE WITH CAUTION (sntp-opts.h)
- *
- * It has been AutoGen-ed August 9, 2009 at 07:52:55 AM by AutoGen 5.9.9pre5
- * From the definitions sntp-opts.def
- * and the template file options
- *
- * Generated from AutoOpts 32:1:7 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
- * sntp 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.
- *
- * This source file is copyrighted and licensed under the following terms:
- *
- * sntp copyright (c) 2008 ntp.org - all rights reserved
- *
- *
- */
-/*
- * This file contains the programmatic interface to the Automated
- * Options generated for the sntp program.
- * These macros are documented in the AutoGen info file in the
- * "AutoOpts" chapter. Please refer to that doc for usage help.
- */
-#ifndef AUTOOPTS_SNTP_OPTS_H_GUARD
-#define AUTOOPTS_SNTP_OPTS_H_GUARD 1
-#include "config.h"
-#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 131073
-#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:
- */
-typedef enum {
- INDEX_OPT_IPV4 = 0,
- INDEX_OPT_IPV6 = 1,
- INDEX_OPT_NORMALVERBOSE = 2,
- INDEX_OPT_KOD = 3,
- INDEX_OPT_SYSLOG = 4,
- INDEX_OPT_FILELOG = 5,
- INDEX_OPT_SETTOD = 6,
- INDEX_OPT_ADJTIME = 7,
- INDEX_OPT_BROADCAST = 8,
- INDEX_OPT_TIMEOUT = 9,
- INDEX_OPT_AUTHENTICATION = 10,
- INDEX_OPT_KEYFILE = 11,
- INDEX_OPT_VERSION = 12,
- INDEX_OPT_HELP = 13,
- INDEX_OPT_MORE_HELP = 14,
- INDEX_OPT_SAVE_OPTS = 15,
- INDEX_OPT_LOAD_OPTS = 16
-} teOptIndex;
-
-#define OPTION_CT 17
-#define SNTP_VERSION "4.2.5p199"
-#define SNTP_FULL_VERSION "sntp - standard SNTP program - Ver. 4.2.5p199"
-
-/*
- * Interface defines for all options. Replace "n" with the UPPER_CASED
- * option name (as in the teOptIndex enumeration above).
- * e.g. HAVE_OPT( IPV4 )
- */
-#define DESC(n) (sntpOptions.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 )
-
-/*
- * Make sure there are no #define name conflicts with the option names
- */
-#ifndef NO_OPTION_NAME_WARNINGS
-# ifdef IPV4
-# warning undefining IPV4 due to option name conflict
-# undef IPV4
-# endif
-# ifdef IPV6
-# warning undefining IPV6 due to option name conflict
-# undef IPV6
-# endif
-# ifdef NORMALVERBOSE
-# warning undefining NORMALVERBOSE due to option name conflict
-# undef NORMALVERBOSE
-# endif
-# ifdef KOD
-# warning undefining KOD due to option name conflict
-# undef KOD
-# endif
-# ifdef SYSLOG
-# warning undefining SYSLOG due to option name conflict
-# undef SYSLOG
-# endif
-# ifdef FILELOG
-# warning undefining FILELOG due to option name conflict
-# undef FILELOG
-# endif
-# ifdef SETTOD
-# warning undefining SETTOD due to option name conflict
-# undef SETTOD
-# endif
-# ifdef ADJTIME
-# warning undefining ADJTIME due to option name conflict
-# undef ADJTIME
-# endif
-# ifdef BROADCAST
-# warning undefining BROADCAST due to option name conflict
-# undef BROADCAST
-# endif
-# ifdef TIMEOUT
-# warning undefining TIMEOUT due to option name conflict
-# undef TIMEOUT
-# endif
-# ifdef AUTHENTICATION
-# warning undefining AUTHENTICATION due to option name conflict
-# undef AUTHENTICATION
-# endif
-# ifdef KEYFILE
-# warning undefining KEYFILE due to option name conflict
-# undef KEYFILE
-# endif
-#else /* NO_OPTION_NAME_WARNINGS */
-# undef IPV4
-# undef IPV6
-# undef NORMALVERBOSE
-# undef KOD
-# undef SYSLOG
-# undef FILELOG
-# undef SETTOD
-# undef ADJTIME
-# undef BROADCAST
-# undef TIMEOUT
-# undef AUTHENTICATION
-# undef KEYFILE
-#endif /* NO_OPTION_NAME_WARNINGS */
-
-/* * * * * *
- *
- * Interface defines for specific options.
- */
-#define VALUE_OPT_IPV4 '4'
-#define WHICH_OPT_IPV4 (DESC(IPV4).optActualValue)
-#define WHICH_IDX_IPV4 (DESC(IPV4).optActualIndex)
-#define VALUE_OPT_IPV6 '6'
-#define VALUE_OPT_NORMALVERBOSE 'd'
-#define VALUE_OPT_KOD 'K'
-#define VALUE_OPT_SYSLOG 'p'
-#define VALUE_OPT_FILELOG 'l'
-#define VALUE_OPT_SETTOD 's'
-#define VALUE_OPT_ADJTIME 'j'
-#define VALUE_OPT_BROADCAST 'b'
-#define VALUE_OPT_TIMEOUT 't'
-#define OPT_VALUE_TIMEOUT (DESC(TIMEOUT).optArg.argInt)
-#define VALUE_OPT_AUTHENTICATION 'a'
-#define OPT_VALUE_AUTHENTICATION (DESC(AUTHENTICATION).optArg.argInt)
-#define VALUE_OPT_KEYFILE 'k'
-#define VALUE_OPT_HELP '?'
-#define VALUE_OPT_MORE_HELP '!'
-#define VALUE_OPT_VERSION 'v'
-#define VALUE_OPT_SAVE_OPTS '>'
-#define VALUE_OPT_LOAD_OPTS '<'
-#define SET_OPT_SAVE_OPTS(a) STMTS( \
- DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \
- DESC(SAVE_OPTS).fOptState |= OPTST_SET; \
- DESC(SAVE_OPTS).optArg.argString = (char const*)(a) )
-/*
- * Interface defines not associated with particular options
- */
-#define ERRSKIP_OPTERR STMTS( sntpOptions.fOptSet &= ~OPTPROC_ERRSTOP )
-#define ERRSTOP_OPTERR STMTS( sntpOptions.fOptSet |= OPTPROC_ERRSTOP )
-#define RESTART_OPT(n) STMTS( \
- sntpOptions.curOptIdx = (n); \
- sntpOptions.pzCurOpt = NULL )
-#define START_OPT RESTART_OPT(1)
-#define USAGE(c) (*sntpOptions.pUsageProc)( &sntpOptions, c )
-/* extracted from /usr/local/gnu/share/autogen/opthead.tpl near line 409 */
-
-/* * * * * *
- *
- * Declare the sntp option descriptor.
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern tOptions sntpOptions;
-
-#if defined(ENABLE_NLS)
-# ifndef _
-# include <stdio.h>
- static inline char* aoGetsText( char const* pz ) {
- if (pz == NULL) return NULL;
- return (char*)gettext( pz );
- }
-# define _(s) aoGetsText(s)
-# endif /* _() */
-
-# define OPT_NO_XLAT_CFG_NAMES STMTS(sntpOptions.fOptSet |= \
- OPTPROC_NXLAT_OPT_CFG;)
-# define OPT_NO_XLAT_OPT_NAMES STMTS(sntpOptions.fOptSet |= \
- OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
-
-# define OPT_XLAT_CFG_NAMES STMTS(sntpOptions.fOptSet &= \
- ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
-# define OPT_XLAT_OPT_NAMES STMTS(sntpOptions.fOptSet &= \
- ~OPTPROC_NXLAT_OPT;)
-
-#else /* ENABLE_NLS */
-# define OPT_NO_XLAT_CFG_NAMES
-# define OPT_NO_XLAT_OPT_NAMES
-
-# define OPT_XLAT_CFG_NAMES
-# define OPT_XLAT_OPT_NAMES
-
-# ifndef _
-# define _(_s) _s
-# endif
-#endif /* ENABLE_NLS */
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* AUTOOPTS_SNTP_OPTS_H_GUARD */
-/* sntp-opts.h ends here */
+++ /dev/null
-* sntp Invocation:: Invoking sntp
+++ /dev/null
-@node sntp Invocation
-@section Invoking sntp
-@pindex sntp
-@cindex standard SNTP program
-@ignore
-#
-# EDIT THIS FILE WITH CAUTION (sntp-opts.texi)
-#
-# It has been AutoGen-ed August 9, 2009 at 07:52:59 AM by AutoGen 5.9.9pre5
-# From the definitions sntp-opts.def
-# and the template file aginfo.tpl
-@end ignore
-This program has no explanation.
-
-.I sntp
-can be used as a SNTP client to query a NTP or SNTP server and either display
-the time or set the local system's time (given suitable privilege). It can be
-run as an interactive command or in a
-.I cron
-job.
-NTP is the Network Time Protocol (RFC 1305) and SNTP is the
-Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).
-
-This section was generated by @strong{AutoGen},
-the aginfo template and the option descriptions for the @command{sntp} program. It documents the sntp usage text and option meanings.
-
-This software is released under a specialized copyright license.
-
-@menu
-* sntp usage:: sntp usage help (-?)
-* sntp adjtime:: adjtime option (-j)
-* sntp authentication:: authentication option (-a)
-* sntp broadcast:: broadcast option (-b)
-* sntp filelog:: filelog option (-l)
-* sntp ipv4:: ipv4 option (-4)
-* sntp ipv6:: ipv6 option (-6)
-* sntp keyfile:: keyfile option (-k)
-* sntp kod:: kod option (-K)
-* sntp normalverbose:: normalverbose option (-d)
-* sntp settod:: settod option (-s)
-* sntp syslog:: syslog option (-p)
-* sntp timeout:: timeout option (-t)
-@end menu
-
-@node sntp usage
-@subsection sntp usage help (-?)
-@cindex sntp usage
-
-This is the automatically generated usage text for sntp:
-
-@exampleindent 0
-@example
-sntp is unavailable - no --help
-@end example
-@exampleindent 4
-
-@node sntp ipv4
-@subsection ipv4 option (-4)
-@cindex sntp-ipv4
-
-This is the ``force ipv4 dns name resolution'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-is a member of the ipv4 class of options.
-@end itemize
-
-Force DNS resolution of following host names on the command line
-to the IPv4 namespace.
-
-@node sntp ipv6
-@subsection ipv6 option (-6)
-@cindex sntp-ipv6
-
-This is the ``force ipv6 dns name resolution'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-is a member of the ipv4 class of options.
-@end itemize
-
-Force DNS resolution of following host names on the command line
-to the IPv6 namespace.
-
-@node sntp normalverbose
-@subsection normalverbose option (-d)
-@cindex sntp-normalverbose
-
-This is the ``normal verbose'' option.
-Diagnostic messages for non-fatal errors and a limited amount of
-tracing should be written to standard error. Fatal ones always
-produce a diagnostic. This option should be set when there is a
-suspected problem with the server, network or the source.
-
-@node sntp kod
-@subsection kod option (-K)
-@cindex sntp-kod
-
-This is the ``specify a file for the kod packet storage'' option.
-Specifies the file to be used to store KOD packaet information.
-
-@node sntp syslog
-@subsection syslog option (-p)
-@cindex sntp-syslog
-
-This is the ``logging with syslog'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-must not appear in combination with any of the following options:
-filelog.
-@end itemize
-
-When this option is set all logging will be done using syslog.
-
-@node sntp filelog
-@subsection filelog option (-l)
-@cindex sntp-filelog
-
-This is the ``logging to specified logfile'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-must not appear in combination with any of the following options:
-syslog.
-@end itemize
-
-This option causes the client to write log messages to the specified
-logfile.
-
-@node sntp settod
-@subsection settod option (-s)
-@cindex sntp-settod
-
-This is the ``set (step) the time with settimeofday()'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-must not appear in combination with any of the following options:
-adjtime.
-@end itemize
-
-
-
-@node sntp adjtime
-@subsection adjtime option (-j)
-@cindex sntp-adjtime
-
-This is the ``set (slew) the time with adjtime()'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-must not appear in combination with any of the following options:
-settod.
-@end itemize
-
-
-
-@node sntp broadcast
-@subsection broadcast option (-b)
-@cindex sntp-broadcast
-
-This is the ``use broadcast packages from the broadcast address specified for synchronisation'' option.
-If specified SNTP will wait 1 minute for broadcast packets
-from the broadcast address specified for synchronisation.
-The amount of time SNTP waits can be specified with -t.
-
-@node sntp timeout
-@subsection timeout option (-t)
-@cindex sntp-timeout
-
-This is the ``specify the number of seconds until sntp times out when waiting for broadcast packets'' option.
-When waiting for a broadcast packet SNTP will wait the number
-of seconds specified and times out.
-
-@node sntp authentication
-@subsection authentication option (-a)
-@cindex sntp-authentication
-
-This is the ``enable authentication with the key keyno. this option is used as -a keyno'' option.
-This option enables authentication using the key specified in this option\'s argument.
-The argument of this option is the keyid, a number specified in the keyfile as this
-key\'s identifier. See the keyfile option -k for more details.
-
-@node sntp keyfile
-@subsection keyfile option (-k)
-@cindex sntp-keyfile
-
-This is the ``specify a keyfile. sntp will look in this file for the key specified with -a'' option.
-This option specifies the keyfile. SNTP will search for the key specified with -a keyno in this
-file. Key files follow the following format:
-
-keyid keytype key
-
-Where keyid is a number identifying this key
-keytype is one of the follow:
-S Key in 64 Bit hexadecimal number as specified in in the DES specification.
-N Key in 64 Bit hexadecimal number as specified in the NTP standard.
-A Key in a 1-to-8 character ASCII string.
-M Key in a 1-to-8 character ASCII string using the MD5 authentication scheme.
-
-See more information see ntp.keys(5).
+++ /dev/null
-.TH SNTP 1 2009-08-09 "( 4.2.5p199)" "Programmer's Manual"
-.\" EDIT THIS FILE WITH CAUTION (sntp.1)
-.\"
-.\" It has been AutoGen-ed August 9, 2009 at 07:52:57 AM by AutoGen 5.9.9pre5
-.\" From the definitions sntp-opts.def
-.\" and the template file agman1.tpl
-.\"
-.SH NAME
-sntp \- standard SNTP program
-.SH SYNOPSIS
-.B sntp
-.\" Mixture of short (flag) options and long options
-.RB [ \-\fIflag\fP " [\fIvalue\fP]]... [" \--\fIopt-name\fP " [[=| ]\fIvalue\fP]]..."
-.br
-.in +8
-...
-.SH "DESCRIPTION"
-This manual page briefly documents the \fBsntp\fP command.
-.I sntp
-can be used as a SNTP client to query a NTP or SNTP server and either display
-the time or set the local system's time (given suitable privilege). It can be
-run as an interactive command or in a
-.I cron
-job.
-NTP is the Network Time Protocol (RFC 1305) and SNTP is the
-Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).
-.SS Options
-.PP
-.I sntp
-recognizes the following options:
-.TP
-.B \-v
-indicates that diagnostic messages for non-fatal errors and a limited amount of
-tracing should be written to standard error. Fatal ones always produce a
-diagnostic. This option should be set when there is a suspected problem with
-the server, network or the source.
-.TP
-.B \-V
-requests more and less comprehensible output, mainly for investigating problems
-with apparently inconsistent timestamps. This option should be set when the
-program fails with a message indicating that is the trouble.
-.TP
-.B \-W
-requests very verbose debugging output, and will interfere with the timing
-when writing to the terminal (because of line buffered output from C). Note
-that the times produced by this are the corrections needed, and not the error
-in the local clock. This option should be set only when debugging the source.
-.TP
-.B \-r
-indicates that the system clock should be reset by
-.IR settod .
-Naturally, this will work only if the user has enough privilege.
-.TP
-.B \-a
-indicates that the system clock should be reset by
-.IR adjtime .
-Naturally, this will work only if the user has enough privilege.
-.PP
-The default is to write the estimated correct local date and time (i.e. not
-UTC) to the standard output in a format like
-.BR "'1996 Oct 15 20:17:25.123 + 4.567 +/- 0.089 secs'" ,
-where the
-.B "'+ 4.567 +/- 0.089 secs'"
-indicates the estimated error in the time on the local system.
-.TP
-.BI \-l " lockfile"
-sets the name of the lock file to ensure that there is only
-one copy of
-.I sntp
-running at once. The default is installation-dependent, but will usually be
-.IR /etc/sntp.pid .
-.TP
-.BI \-c " count"
-sets the maximum number of NTP packets required to
-.IR count .
-Acceptable values are from 1 to 25 if a NTP host is specified and from 5 to 25
-otherwise, and the default is 5. If the maximum isn't enough, the system needs
-a better consistency algorithm than this program uses.
-.TP
-.B \-4
-force IPv4 DNS resolution.
-.TP
-.B \-6
-force IPv6 DNS resolution.
-.PP
-.B address(es)
-are the DNS names or IP numbers of hosts to use for the challenge and response
-protocol; if no names are given, the program waits for broadcasts. Polling a
-server is vastly more reliable than listening to broadcasts. Note that a
-single component numeric address is not allowed, to avoid ambiguities. If
-more than one name is give, they will be used in a round-robin fashion.
-.PP
-Constraints:
-.IP
-.BR delay / count "),"
-and
-.B count
-must be less than half of
-.BR delay .
-.IP
-In update mode,
-.B maxerr
-must be less than
-.SH USAGE
-The simplest use of this program is as an unprivileged command to check the
-current time and error in the local clock. For example:
-.IP
-.B sntp ntpserver.somewhere
-.PP
-With suitable privilege, it can be run as a command or in a
-.I cron
-job to reset the local clock from a reliable server, like the
-.I ntpdate
-and
-.I rdate
-commands. For example:
-.IP
-.B sntp \-a ntpserver.somewhere
-.PP
-More information on how to use this utility is given in the
-.I README
-file in the distribution. In particular, this
-.I man
-page does not describe how to set it up as a server, which needs special care
-to avoid propagating misinformation.
-.SH RETURN VALUE
-When used as a client in non-daemon mode, the program returns a zero exit
-status for success, and a non-zero one otherwise. When used as a daemon
-(either client or server), it does not return except after a serious error.
-.SH BUGS
-The program implements the SNTP protocol, and does not provide all NTP
-facilities. In particular, it contains no checks against any form of spoofing.
-If this is a serious concern, some network security mechanism (like a firewall
-or even just
-.IR tcpwrappers )
-should be installed.
-.PP
-There are some errors, ambiguities and inconsistencies in the RFCs, and this
-code may not interwork with all other NTP implementations. Any unreasonable
-restrictions should be reported as bugs to whoever is responsible. It may
-be difficult to find out who that is.
-.PP
-The program will stop as soon as it feels that things have got out of control.
-In client daemon mode, it will usually fail during an extended period of
-network or server inaccessibility or excessively slow performance, or when the
-local clock is reset by another process. It will then need restarting
-manually. Experienced system administrators can write a shell script, a
-.I cron
-job or put it in
-.IR inittab ,
-to do this automatically.
-.PP
-.SH AUTHOR
-.I sntp
-.SH OPTIONS
-.TP
-.BR \-4 ", " \--ipv4
-Force IPv4 DNS name resolution.
-This option is a member of the ipv4 class of options.
-.sp
-Force DNS resolution of following host names on the command line
-to the IPv4 namespace.
-.TP
-.BR \-6 ", " \--ipv6
-Force IPv6 DNS name resolution.
-This option is a member of the ipv4 class of options.
-.sp
-Force DNS resolution of following host names on the command line
-to the IPv6 namespace.
-.TP
-.BR \-d ", " \--normalverbose
-Normal verbose.
-.sp
-Diagnostic messages for non-fatal errors and a limited amount of
-tracing should be written to standard error. Fatal ones always
-produce a diagnostic. This option should be set when there is a
-suspected problem with the server, network or the source.
-.TP
-.BR \-K " \fIstring\fP, " \--kod "=" \fIstring\fP
-Specify a file for the KOD packet storage.
-.sp
-Specifies the file to be used to store KOD packaet information.
-.TP
-.BR \-p ", " \--syslog
-Logging with syslog.
-This option must not appear in combination with any of the following options:
-filelog.
-.sp
-When this option is set all logging will be done using syslog.
-.TP
-.BR \-l " \fIstring\fP, " \--filelog "=" \fIstring\fP
-Logging to specified logfile.
-This option must not appear in combination with any of the following options:
-syslog.
-.sp
-This option causes the client to write log messages to the specified
-logfile.
-.TP
-.BR \-s ", " \--settod
-Set (step) the time with settimeofday().
-This option must not appear in combination with any of the following options:
-adjtime.
-.sp
-
-.TP
-.BR \-j ", " \--adjtime
-Set (slew) the time with adjtime().
-This option must not appear in combination with any of the following options:
-settod.
-.sp
-
-.TP
-.BR \-b " \fIstring\fP, " \--broadcast "=" \fIstring\fP
-Use broadcast packages from the broadcast address specified for synchronisation.
-.sp
-If specified SNTP will wait 1 minute for broadcast packets
-from the broadcast address specified for synchronisation.
-The amount of time SNTP waits can be specified with \-t.
-.TP
-.BR \-t " \fInumber\fP, " \--timeout "=" \fInumber\fP
-Specify the number of seconds until SNTP times out when waiting for broadcast packets.
-This option takes an integer number as its argument.
-.sp
-When waiting for a broadcast packet SNTP will wait the number
-of seconds specified and times out.
-.TP
-.BR \-a " \fInumber\fP, " \--authentication "=" \fInumber\fP
-Enable authentication with the key keyno. This option is used as \-a keyno.
-This option takes an integer number as its argument.
-.sp
-This option enables authentication using the key specified in this option\\'s argument.
-The argument of this option is the keyid, a number specified in the keyfile as this
-key\\'s identifier. See the keyfile option \-k for more details.
-.TP
-.BR \-k " \fIstring\fP, " \--keyfile "=" \fIstring\fP
-Specify a keyfile. SNTP will look in this file for the key specified with \-a.
-.sp
-This option specifies the keyfile. SNTP will search for the key specified with \-a keyno in this
-file. Key files follow the following format:
-
-keyid keytype key
-
-Where keyid is a number identifying this key
-keytype is one of the follow:
-S Key in 64 Bit hexadecimal number as specified in in the DES specification.
-N Key in 64 Bit hexadecimal number as specified in the NTP standard.
-A Key in a 1-to-8 character ASCII string.
-M Key in a 1-to-8 character ASCII string using the MD5 authentication scheme.
-
-See more information see ntp.keys(5).
-.TP
-.BR \-? , " \--help"
-Display usage information and exit.
-.TP
-.BR \-! , " \--more-help"
-Extended usage information passed thru pager.
-.TP
-.BR \-> " [\fIrcfile\fP]," " \--save-opts" "[=\fIrcfile\fP]"
-Save the option state to \fIrcfile\fP. The default is the \fIlast\fP
-configuration file listed in the \fBOPTION PRESETS\fP section, below.
-.TP
-.BR \-< " \fIrcfile\fP," " \--load-opts" "=\fIrcfile\fP," " \--no-load-opts"
-Load options from \fIrcfile\fP.
-The \fIno-load-opts\fP form will disable the loading
-of earlier RC/INI files. \fI--no-load-opts\fP is handled early,
-out of order.
-.TP
-.BR \-v " [{\fIv|c|n\fP}]," " \--version" "[=\fI{v|c|n}\fP]"
-Output version of program and exit. The default mode is `v', a simple
-version. The `c' mode will print copyright information and `n' will
-print the full copyright notice.
-.SH OPTION PRESETS
-Any option that is not marked as \fInot presettable\fP may be preset
-by loading values from configuration ("RC" or ".INI") file(s) and values from
-environment variables named:
-.nf
- \fBSNTP_<option-name>\fP or \fBSNTP\fP
-.fi
-.ad
-The environmental presets take precedence (are processed later than)
-the configuration files.
-The \fIhomerc\fP files are "\fI$HOME\fP", and "\fI.\fP".
-If any of these are directories, then the file \fI.ntprc\fP
-is searched for within those directories.
-.SH AUTHOR
-ntp.org
-.br
-Please send bug reports to: http://bugs.ntp.org, bugs@ntp.org
-
-.PP
-.nf
-.na
-
-.fi
-.ad
-.PP
-This manual page was \fIAutoGen\fP-erated from the \fBsntp\fP
-option definitions.
- General Public Licence for the software known as MSNTP
- ------------------------------------------------------
-
- (c) Copyright, N.M. Maclaren, 1996, 1997, 2000
- (c) Copyright, University of Cambridge, 1996, 1997, 2000
-
-
-
-Free use of MSNTP in source and binary forms is permitted, provided that this
-entire licence is duplicated in all copies, and that any documentation,
-announcements, and other materials related to use acknowledge that the software
-was developed by N.M. Maclaren (hereafter refered to as the Author) at the
-University of Cambridge. Neither the name of the Author nor the University of
-Cambridge may be used to endorse or promote products derived from this material
-without specific prior written permission.
-
-The Author and the University of Cambridge retain the copyright and all other
-legal rights to the software and make it available non-exclusively. All users
-must ensure that the software in all its derivations carries a copyright notice
-in the form:
- (c) Copyright N.M. Maclaren,
- (c) Copyright University of Cambridge.
-
-
-
- NO WARRANTY
-
-Because the MSNTP software is licensed free of charge, the Author and the
-University of Cambridge provide absolutely no warranty, 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 MSNTP software is with you. Should MSNTP
-prove defective, you assume the cost of all necessary servicing or repair.
-
-In no event, unless required by law, will the Author or the University of
-Cambridge, or any other party who may modify and redistribute this software as
-permitted in accordance with the provisions below, be liable for damages for
-any losses whatsoever, including but not limited to lost profits, lost monies,
-lost or corrupted data, or other special, incidental or consequential losses
-that may arise out of the use or inability to use the MSNTP software.
-
-
-
- COPYING POLICY
-
-Permission is hereby granted for copying and distribution of copies of the
-MSNTP source and binary files, and of any part thereof, subject to the
-following licence conditions:
-
-1. You may distribute MSNTP or components of MSNTP, with or without additions
-developed by you or by others. No charge, other than an "at-cost" distribution
-fee, may be charged for copies, derivations, or distributions of this material
-without the express written consent of the copyright holders.
-
-2. You may also distribute MSNTP along with any other product for sale,
-provided that the cost of the bundled package is the same regardless of whether
-MSNTP is included or not, and provided that those interested only in MSNTP must
-be notified that it is a product freely available from the University of
-Cambridge.
-
-3. If you distribute MSNTP software or parts of MSNTP, with or without
-additions developed by you or others, then you must either make available the
-source to all portions of the MSNTP system (exclusive of any additions made by
-you or by others) upon request, or instead you may notify anyone requesting
-source that it is freely available from the University of Cambridge.
-
-4. You may not omit any of the copyright notices on either the source files,
-the executable files, or the documentation.
-
-5. You may not omit transmission of this License agreement with whatever
-portions of MSNTP that are distributed.
-
-6. Any users of this software must be notified that it is without warranty or
-guarantee of any nature, express or implied, nor is there any fitness for use
-represented.
-
-
-October 1996
-April 1997
-October 2000
-# Makefile.am, by Harlan Stenn, from:
-# Makefile for sntp
-# N.M. Maclaren, October 2000.
+# Makefile.am for JMK's SNTP, by Harlan Stenn
AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS= -I ../m4 -I libopts/m4
-AM_CPPFLAGS= $(LIBOPTS_CFLAGS)
-LDADD= $(LIBOPTS_LDADD)
+AM_CPPFLAGS= $(LIBOPTS_CFLAGS) -I$(top_srcdir)/../include
+LDADD= $(LIBOPTS_LDADD) -lm ../libntp/libntp.a
NULL=
-bindir= ${exec_prefix}/${BINSUBDIR}
-bin_PROGRAMS= sntp
-#run_ag= cd $(srcdir) && autogen --writable -L $(top_srcdir)/include
-run_ag= cd $(srcdir) && autogen --writable
+###
+#bindir= ${exec_prefix}/${BINSUBDIR}
+#bin_PROGRAMS= sntp
+###
+noinst_PROGRAMS= sntp
+###
+run_ag= cd $(srcdir) && autogen -L ../include --writable
SUBDIRS=
if NEED_LIBOPTS
endif
SUBDIRS+= .
-sntp_SOURCES = \
- header.h \
- internet.c \
- internet.h \
- kludges.h \
- main.c \
- sntp-opts.c \
- sntp-opts.h \
- socket.c \
- timing.c \
- unix.c \
+sntp_SOURCES = \
+ crypto.c \
+ crypto.h \
+ data_formats.h \
+ header.h \
+ kod_management.c \
+ kod_management.h \
+ log.c \
+ log.h \
+ main.c \
+ netutils.h \
+ networking.c \
+ networking.h \
+ sntp-opts.c \
+ sntp-opts.h \
+ utilities.c \
+ utilities.h \
$(NULL)
-dist_man_MANS= sntp.1
+#dist_man_MANS= sntp.1
EXTRA_DIST= bincheck.mf \
COPYRIGHT \
sntp-opts.def sntp.1 sntp-opts.texi sntp-opts.menu \
- autogen-version.def version.def
-BUILT_SOURCES= check-autogen-version.def check-version.def \
+ $(NULL)
+OLD_EXTRA_DIST= \
+ autogen-version.def version.def version.m4
+BUILT_SOURCES= check-autogen-version.def check-version.def check-version.m4 \
sntp-opts.c sntp-opts.h sntp.1 sntp-opts.texi sntp-opts.menu
-man_MANS= sntp.1
+#man_MANS= sntp.1
+noinst_MANS= sntp.1
FRC:
check-autogen-version.def: FRC
+foo1:
@cd $(srcdir) \
&& test -r ../include/autogen-version.def \
&& ( if cmp -s ../include/autogen-version.def autogen-version.def; \
fi )
check-version.def: FRC
+foo2:
@cd $(srcdir) \
&& test -r ../include/version.def \
&& ( if cmp -s ../include/version.def version.def; \
echo "Installing new sntp/version.def file"; \
fi )
+check-version.m4: FRC
+foo3:
+ @cd $(srcdir) \
+ && test -r ../version.m4 \
+ && ( if cmp -s ../version.m4 version.m4; \
+ then : ; \
+ else cp ../version.m4 version.m4; \
+ echo "Installing new sntp/version.m4 file"; \
+ fi )
+
$(srcdir)/sntp-opts.h: $(srcdir)/sntp-opts.c
-$(srcdir)/sntp-opts.c: $(srcdir)/sntp-opts.def $(srcdir)/version.def
+$(srcdir)/sntp-opts.c: $(srcdir)/sntp-opts.def $(srcdir)/../include/version.def
$(run_ag) sntp-opts.def
-$(srcdir)/sntp.1: $(srcdir)/sntp-opts.def $(srcdir)/version.def
+$(srcdir)/sntp.1: $(srcdir)/sntp-opts.def $(srcdir)/../include/version.def
$(run_ag) -Tagman1.tpl -bsntp sntp-opts.def
-$(srcdir)/sntp-opts.texi $(srcdir)/sntp-opts.menu: $(srcdir)/sntp-opts.def $(srcdir)/version.def
+$(srcdir)/sntp-opts.texi $(srcdir)/sntp-opts.menu: $(srcdir)/sntp-opts.def $(srcdir)/../include/version.def
$(run_ag) -Taginfo.tpl -DLEVEL=section sntp-opts.def
include bincheck.mf
+++ /dev/null
-# Makefile for msntp
-# N.M. Maclaren, October 2000.
-
-# Take a look at README for the various preprocessor symbols, but they are
-# extremely unlikely to be needed on newer systems. You may prefer to change
-# LOCKNAME and SAVENAME to use /var/run (or even /tmp) rather than /etc. Note
-# that not all of the following system settings have been tested recently.
-
-# These options will work on most modern systems. Start with them, and add
-# any necessary options.
- CC = cc -D_ALL_SOURCE
- CFLAGS = -D_ALL_SOURCE
- LDFLAGS =
- LIBS = -lm
-
-# Compiling this sort of ANSI C under SunOS 4.1 is a mug's game, because Sun's
-# Unix headers make GNU C vomit even in compatibility mode, but the following
-# will compile main.c and unix.c. At least two people have got it to work.
-# CC = gcc -ansi
-# CFLAGS = -O -DNONBLOCK_BROKEN
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under SOME versions of Solaris 2, but
-# -D_XOPEN_SOURCE should probably be added on versions where setting that
-# does not cause it to reject its own headers! They can also be used under
-# UnixWare, probably with similar constraints.
-# CC = cc -Xc
-# CFLAGS = -O -v
-# LDFLAGS =
-# LIBS = -lm -lsocket -lnsl
-
-# The following settings can be used under HP-UX 10.0 and later on PA-RISC and
-# HP-UX 9.03 and later on 68000.
-# CC = cc -Aa -D_HPUX_SOURCE
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under HP-UX before 10.0 on PA-RISC.
-# CC = cc -Aa -D_HPUX_SOURCE
-# CFLAGS = -O -DADJTIME_MISSING
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under Digital Unix (aka DEC OSF/1).
-# CC = cc -std1
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under DEC Ultrix 4.3 on a MIPS.
-# CC = gcc -ansi
-# CFLAGS = -O -DNONBLOCK_BROKEN
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under SGI Irix.
-# CC = cc -ansi
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under Hitachi HI-UX/WE2.
-# CC = cc -Aa -D_HIUX_SOURCE
-# CFLAGS = -O
-# DFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under Hitachi HI-OSF/1-MJ and HI-UX/MPP.
-# CC = cc
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under at least NextStep 3. cc is a
-# wrapper for gcc.
-# CC = cc -D_POSIX_SOURCE
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under Unicos.
-# CC = cc -DNONBLOCK_BROKEN
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# The following settings can be used under Linux. While adjtime is present,
-# it is completely broken (i.e. it will work only if xntp is running), so it
-# is a good idea to add -DADJTIME_MISSING.
-# CC = cc -DADJTIME_MISSING
-# CFLAGS = -O
-# LDFLAGS =
-# LIBS = -lm
-
-# It has been compiled with the following options, though with quite a lot of
-# warnings (many due to system header bugs!) All functions defined without a
-# previous declaration should be internal to that file - static is not used
-# because it often interferes with debugging.
-# CC = gcc -ansi
-# CFLAGS = -O -pedantic -Wall -Wtraditional -Wshadow -Wpointer-arith \
-# -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Waggregate-return \
-# -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
-# -Wredundant-decls -Wnested-externs
-# LDFLAGS =
-# LIBS = -lm
-
-all: msntp
-
-clean:
- rm -f msntp msntp-1.5.tar.gz *~ *.o core
-
-archive:
- (cd ..; tar -cvf - msntp-1.6/README msntp-1.6/Copyright \
-msntp-1.6/Makefile msntp-1.6/msntp.1 msntp-1.6/RFC2030.TXT \
-msntp-1.6/header.h msntp-1.6/internet.h msntp-1.6/kludges.h \
-msntp-1.6/main.c msntp-1.6/unix.c msntp-1.6/internet.c msntp-1.6/socket.c \
-msntp-1.6/timing.c) | \
-gzip > msntp-1.6.tar.gz
-
-install:
- @echo "This does not actually install anything; do something like:"
- @echo ""
- @echo "cp msntp /usr/local/bin"
- @echo "cp msntp.1 /usr/local/man/man1"
-
-msntp: main.o unix.o internet.o socket.o timing.o
- $(CC) $(LDFLAGS) -o msntp main.o unix.o internet.o socket.o timing.o \
-$(LIBS)
-
-main.o: main.c header.h kludges.h
-
-unix.o: unix.c header.h kludges.h
-
-internet.o: internet.c header.h internet.h kludges.h
-
-socket.o: socket.c header.h internet.h kludges.h
-
-timing.o: timing.c header.h kludges.h
-
+++ /dev/null
-SNTP (Simple Network Time Protocol Utility) - Version 1.6
-----------------------------------------------------------
-
-Please read the file Copyright first. Also note that the file RFC2030.TXT is
-David Mills's copyright and not the author's - it is just a copy of the RFC
-that is available from so many Internet archives.
-
-RFC 1305 (Network Time Protocol - NTP) is an attempt to provide globally
-consistent timestamps in an extremely hostile environment; it is fiendishly
-complicated and an impressive piece of virtuosity. RFC 2030 (Simple Network
-Time Protocol - SNTP) which supersedes RFC 1769 describes a subset of this that
-will give excellent accuracy in most environments encountered in practice; it
-uses only the obvious algorithms that have been used since time immemorial.
-
-WARNING: the text version of RFC 1305 is incomplete, and omits the tables that
-are in the Postscript version. Unfortunately, these contain the only copy of
-some critical information.
-
-draft-mills-sntp-v4-00.txt is the next proposed revision of RFC 2030,
-and the current goal is to have this code implement that specification.
-
-SNTP Servers - Some Little-Known Facts
---------------------------------------
-
-RFC 2030 states that SNTP clients should be used only at the lowest level,
-which is good practice. It then states that SNTP servers should be used only
-at stratum 1 (i.e. top level), which is bizarre! A far saner use of them would
-be for the very lowest level of server, exporting solely to local clients that
-do not themselves act as servers to ANY system (e.g. on a Netware server,
-exporting only to the PCs that it manages).
-
-[There is missing language in the previous paragraph. SNTP is designed
-to be used in 2 cases: as a client at the lowest levels of the timing
-hierarchy, or as a server of last resort at stratum 1 when connected to
-a modem or radio clock.]
-
-[This is as far as I have updated this file as part of the upgrade.]
-
-If the NTP network were being run as a directed acyclic graph (i.e. using SNTP
-rather than full NTP), with a diameter of D links and a maximum error per link
-of E, the maximum synchronisation error would be D*E. Reasonable figures for D
-and E are 5 and 0.1 seconds, so this would be adequate for most uses. Note
-that the fact that the graph is acyclic is critical, which is one reason why
-SNTP client/servers must NEVER be embedded WITHIN an NTP network.
-
-The other reason is that inserting SNTP client/servers at a low stratum (but
-not the root) of an NTP network could easily break NTP! See RFC 1305 for why,
-but don't expect the answer to stand out at you. It would be easy to extend
-SNTP to a full-function client/server application, thus making it into a true
-alternative to ntp, but this incompatibility is why it MUST NOT be done.
-
-The above does not mean that the SNTP approach is unsatisfactory, but only that
-it is incompatible with full NTP. The author would favour a complete SNTP
-network using the SNTP approach, and the statistical error reduction used in
-SNTP, but it actually addresses a slightly different problem from that
-addressed by NTP. TANSTAAFL.
-
-FINAL WARNING: do NOT use this program to serve NTP requests from outside the
-systems that you manage. If you do this, and manage to break the time
-synchronisation on other people's systems, you will be regarded very
-unfavourably. Actually, this should be possible only if their NTP client is
-completely broken, because SNTP does its damnedest to declare its packets as
-the lowest form of NTP timestamp.
-
-
-
-SNTP and its Assumptions
--------------------------
-
-SNTP is intended to be a straightforward SNTP daemon/utility that is easy to
-build on any reasonable Unix platform (and most near-Unix ones), whether or not
-it has ever been ported to them before. It is intended to answer the following
-requirements, either by challenge and response or the less reliable broadcast
-method:
-
- A simple command to run on Unix systems that will check the time
- and optionally drift compared with a known, local and reliable NTP
- time server. No privilege is required just to read the time and
- estimate the drift.
-
- A client for Unix systems that will synchronise the time from a known,
- local and reliable NTP time server. This is probably the most common
- one, and the need that caused the program to be written.
-
- A server for Unix systems that are synchronised other than by NTP
- methods and that need to synchronise other systems by NTP. This is
- the classroom of PCs with a central server scenario. It is NOT
- intended to work as a peer with true NTP servers, and won't.
-
- A simple method by which two or more Unix systems can keep themselves
- synchronised using what is becoming a standard protocol. Yes, I know
- that there are half-a-dozen other such methods.
-
- A base for building non-Unix SNTP clients. Some 3/4 of the code
- (including all of the complicated algorithms and NTP packet handling)
- should work, unchanged, on any system with an ANSI/ISO C compiler.
-
-There are full tracing facilities and a lot of paranoia in the code to check
-for bad packets (more than in ntp) which may need relaxing in the light of
-experience. Unfortunately, RFC 1305 does not include a precise description of
-the data protocol, despite its length, and there are some internal
-inconsistencies and differences between it and RFC 2030 and ntp's behaviour.
-
-WARNING: SNTP has not been tested in conjunction with ntp broadcasts or ntp
-clients, as the ability to do so was not available to the author. It is very
-unlikely that it won't work, but you should check. Much of the paranoid code
-is only partially tested, too, because it is dealing with cases that are very
-hard to provoke.
-
-It assumes that the local network is tolerably secure and that any accessible
-NTP or SNTP servers are trustworthy. It also makes no attempt to check that
-it has been installed and is being used correctly (e.g. at an appropriate
-priority) or that the changes it makes have the desired effect. When you first
-use it, you should both run it in display mode and use the date command as a
-cross-check.
-
-Furthermore, it does not attempt to solve all of the problems addressed by the
-NTP protocol and you should NOT use it if any of those problems are likely to
-cause you serious trouble. If they are, bite the bullet and implement ntp, or
-buy a fancy time-server.
-
-
-Building SNTP
--------------
-
-The contents of the distribution are:
-
-README - this file
-Copyright - the copyright notice and conditions of use
-Makefile - the makefile, with comments for several systems
-header.h - the main header (almost entirely portable)
-kludges.h - dirty kludges for difficult systems
-internet.h - a very small header for internet.c and socket.c
-main.c - most of the source (almost entirely portable)
-unix.c - just for isatty, sleep and locking
-internet.c - Internet host and service name lookup
-socket.c - the Berkeley socket code
-sntp.1 - the man page
-RFC2030.TXT - the SNTPv4 specification
-
-All you SHOULD need to do is to uncomment the settings in file Makefile for
-your system or to add new ones. But real life is not always so simple. As
-POSIX does not yet define sub-second timers, Internet addressing facilities,
-sockets etc., the code has to rely on the facilities described in the
-ill-defined and non-standard 'X/Open' documents and the almost totally
-unspecified 'BSD' extensions.
-
-Most hacks should be limited to the compiler options (e.g. setting flags like
-_XOPEN_SOURCE), but perverse systems may need additions to kludges.h - please
-report them to the author. See Makefile and kludges.h for documentation on
-the standard hacks - there only 6, and most are only for obsolete systems.
-But, generally, using the generic set of C options usually works with no
-further ado.
-
-
-Sick, Bizarre or non-Unix Systems
----------------------------------
-
-A very few Unix systems and almost all non-Unix systems may need changes to the
-code, such as:
-
- If the system doesn't have Berkeley sockets, you will need to replace
- socket.c and possibly modify internet.h and internet.c. All of the
- systems for which the author needs this have Berkeley sockets.
-
- NTP is supposedly an Internet protocol, but is not Internet specific.
- For other types of network, you will need to replace internet.c and
- probably modify internet.h.
-
- If the system doesn't have gettimeofday or settimeofday, you will
- need to modify timing.c. If it doesn't have adjtime (e.g. HP-UX
- on PA-RISC before 10.0), you can set -DADJTIME_MISSING and the code
- will compile but the -a option will always give an error.
-
- If the system has totally broken signal handling, the program will
- hang or crash if it can't reach its name server or responses time
- out. You may be able to improve matters by hacking internet.c and
- socket.c, but don't bet on it.
-
- If the the program won't be able to create files in /etc when
- updating the clock, you can use another lock file or even set
- -DLOCKFILE=NULL, which will disable the locking code entirely. On
- systems that have it, using /var/run would be better than /etc.
-
- If the the program hangs when flushing outstanding packets (which
- you can tell by setting -W), it may help to set -DNONBLOCK_BROKEN.
- This seems needed only for obsolete systems, like Ultrix.
-
- If the system isn't Unix, even vaguely, you will probably need to
- modify all of the above, and unix.c as well.
-
- Note that adjtime is commonly sick, but you don't need to change the
- code - just use the -r option whan making large corrections (see below
- for more details).
-
-Any changes needed to header.h or main.c are bugs. They may be bugs in the
-code or in the compiler or libraries, but they are bugs. Please prod the
-people responsible and tell the author, who may be able to bypass them cleanly
-even if they aren't bugs in his code. The code also makes the following
-assumptions, which would be quite hard to remove:
-
- 8-bit bytes. Strictly, neither ANSI/ISO C nor POSIX require these,
- and there were some very early versions of Unix on systems with other
- byte sizes. But, without a defined sub-byte facility in C, ....
-
- At least 32-bit ints. Well, actually, this wouldn't be too hard to
- remove. But most Unix programs make this assumption, and I have very
- little interest in the more rudimentary versions of MS-DOS etc.
-
- An ANSI/ISO C compiler. It didn't seem worth writing dual-language
- code in 1996. Tough luck if you haven't got one.
-
- Tolerably efficient floating-point arithmetic, with at least 13 digits
- (decimal), preferably 15, in the mantissa of doubles. Ditto. If you
- want to port this to a toaster, please accept my insincerest sympathies
- and don't bother me.
-
- A trustworthy local network. It does not check for DNS, Ethernet,
- packet or other spoofing, and assumes that any accessible NTP or SNTP
- servers are properly synchronised.
-
-
-Warnings about Installation and Use
------------------------------------
-
-Anyone attempting to fiddle with the clock on their system should already know
-how to write system administration scripts, install daemons and so on. There
-are a few warnings:
-
- Don't use the broadcast modes unless you really have to, as the
- client-server modes are far more reliable. The broadcast modes were
- implemented more for virtuosity (a.k.a. SNTP conformance) than use.
- In particular, the error estimates are mere guesses, and may be low
- or even very low. And even reading broadcasts needs privilege.
-
- The program is not intended to be installed setuid or setgid, and
- doing so is asking for trouble. Its ownerships and access modes are
- not important. It need not be run by root for merely displaying the
- time (even in daemon mode).
-
- The program does not need to run at a high priority (low in Unix
- terms!) even when being used to set the clock or as a server, except
- when the '-r' option is used. However, doing so may improve its
- accuracy.
-
- Unlike NTP, the SNTP protocol contains no protection against
- client-server loops. If you set one up, your systems will spin
- themselves off into a disconnected vortex of unreality!
-
- It will get very confused if another process changes the local time
- while it is running. There is some locking code in unix.c to prevent
- this program doing this to itself, but it will protect only against
- some errors. However, the remaining failures should be harmless.
-
- Don't run it as a server unless you REALLY know what you are doing.
- It should be used as a server only on a system that is properly
- synchronised, by fair means or foul. If it isn't, you will simply
- perpetrate misinformation. And remember that broadcasts are most
- unpopular with overloaded administrators of overloaded networks.
-
- Watch out for multi-server broadcasts and systems with multiple ports
- onto the same Ethernet; there is some code to protect against this,
- but it is still easy to get confused.
-
- Don't put the lock file onto an automounted partition or delete it by
- hand, unless you really want to start two daemons at the same time.
- Both will probably fail horribly if you do this.
-
- The daemon save file is checked fairly carefully, but should be in a
- reasonably safe directory, unless you want hackers to cause trouble.
- /tmp is safe enough on most systems, but not all - /etc is better.
-
-
-Installing and Using the Program
---------------------------------
-
-Start by copying the executable and man page to where you want them. If you
-want only to display the time and as a replacement for the rdate or date
-commands, the installation is finished!
-
-You can use it as a simple unprivileged command to check the time, quite
-independently of whether it is running as a time-updating daemon or server, or
-whether you are running ntp. You can run it in daemon mode without updating
-the clock, to check for drift, but it may fail if the clock is changed under
-its feet. Unfortunately, you cannot listen to broadcasts without privilege.
-
-If it is used with the -a option to keep the time synchronised, it is best to
-run it as one of root's cron jobs - for many systems, running it once a day
-should be adequate, but it will depend on the reliability of the local clock.
-The author runs it this way with -a and -x - see below.
-
-If it is used with the -r option to set the time (instead of the rdate or date
-commands), it should be used interactively and either on a lightly loaded
-system or at a high priority. You should then check the result by running it
-in display mode.
-
-You are advised NOT to run it with the -r option in a cron job, though this is
-not locked out. If you have to (for example under HP-UX before 10.0), be sure
-to run it as the highest priority that will not cause other system problems and
-set the maximum automatic change to as low a value as you can get away with.
-
-WARNING: adjtime is more than a bit sick on many systems, and will ignore large
-corrections, usually without any form of hint that it has done so. It is often
-(even usually) necessary to reset the clock to approximately the right time
-using the -r option before using the -a and -x options to keep it correct.
-
-It can be started as a time-updating daemon with the -a and -x options (or -r
-and -x if you must), and will perform some limited drift correction. In this
-case, start it from any suitable system initialisation script and leave it
-running. Note that it will stop if it thinks that the time difference or drift
-has got out of control, and you will need to reset the time and restart it by
-hand.
-
-In daemon mode, it will survive its time server or network disappearing for a
-while, but will eventually fail, and will fail immediately if the network call
-returns an unexpected error. If this is a problem, you can start it (say,
-hourly or nightly) from cron, and it will fail if it is already running
-(provided that you haven't disabled or deleted the lock file).
-
-If it is used as a server, it should be started from any suitable system
-initialisation script, just like any other daemon. It must be started after
-the networking, of course. To run it in both server modes, start one copy with
-the -B option and one with the -S option.
-
-
-Simple Examples of Use
-----------------------
-
-Many people use it solely to check the time of their system, especially as a
-cross-check on ntpd. You do not need privilege and it will not cause trouble
-to the local network, so you can use it on someone else's system! You can
-specify one server or several. For example:
-
- msntp ntp.server.local ntp.server.neighbour
-
-You can use it to check how your system is drifting, but it isn't very good at
-this if the system is drifting very badly (in which case use the previous
-technique and dc) or if you are running ntp. You do not need privilege and it
-will not cause trouble to the local network. For example:
-
- sntp -x 120 -f /tmp/msntp.state ntp.server.local
-
-More generally, it is used to synchronise the clock, in which case you DO need
-root privilege. It can be used in many ways, but the author favours running it
-in daemon mode, started from a cron job, which will restart after power cuts
-with no attention, and send a mail message (if cron is configured to do that)
-when it fails badly. For example, the author uses a root crontab entry on one
-system of:
-
- 15 0 * * * /bin/nice --10 /usr/local/bin/sntp -a -x 480 ntp.server.local
-
-If you have a home computer, it can be set up to resynchronise each time you
-dial up. For example, the author uses a /etc/ppp/ip-up.d/sntp file on his
-home Linux system of:
-
- #!/bin/sh
- sleep 60
- /bin/nice --10 /usr/local/sbin/sntp -r -P 60 ntp.server.local
-
--a would be better, but adjtime is broken in Linux.
-
-
-Debugging or Hacking the Program
---------------------------------
-
-Almost everybody who does this is likely to need to modify only the system
-interfaces. While they are messy, they are pretty simple and have a simple
-specification. This is documented in comments in the source. This is
-described above.
-
-The main program SHOULD need no attention, though it may need the odd tweak to
-bypass compiler problems - please report these, if you encounter any. If
-something looks odd while it is running, start by setting the -v option (lower
-case), as for investigating network problems, and checking any diagnostics that
-appear. Note that most of it can be checked in display mode without harming
-your system.
-
-The client will sometimes give up, complaining about inconsistent timestamps or
-similar. This can be caused by the server being rebooted and similar glitches
-to the time - unfortunately, there is no reliable way to tell an ignorable
-fluctuation from a server up the spout. If this happens annoyingly often,
-the -V option may help tie down the problem. In actual use, it is simplest
-just to restart the client in a cron job!
-
-If it needs more than this, then you will need to debug the source seriously.
-Start by putting an icepack on your head and pouring yourself a large whisky!
-While it is commented, it is not well commented, and much of the code interacts
-in complex and horrible ways. This isn't so much because it lacks 'structure'
-as because one part needs to make assumptions about the numerical properties of
-another.
-
-The -W option (upper case) will print out a complete trace of everything it
-does, and this should be enough to tie down the problem. It does distort the
-timing a bit, but not usually too badly. However, wading through that amount
-of gibberish (let alone looking at the source) is not a pleasant task. If you
-are pretty sure that you have a bug, you may tell the author, and he may ask
-for a copy of the output - but he will reply rudely if you send thousands of
-lines of tracing to him by Email!
-
-Note that there are a fair number of circumstances where its error recovery
-could be better, but is left as it is to keep the code simple. Most of these
-should be pretty rare.
-
-
-Changes in Version 1.2
-----------------------
-
-The main change was the addition of the daemon mode for drift correction (i.e.
-the -x option). The daemon code is complex and has a lot of special-casing for
-strange circumstances, not all of which are testable in practice.
-
-A lot of the code was reordered while doing this. The output was slightly
-different - considerably different with -V.
-
-The error estimation for broadcasts was modified, and should bear more relation
-to reality. It remains a guess, as there is no way to get decent error error
-estimates under such circumstances.
-
-The -B option is now in minutes, and has a different permissible range and
-default value.
-
-The argument consistency checking for broadcasts was tightened up a bit, and a
-few other internal checks added. These should not affect any reasonable
-requirement.
-
-A couple of new functions were added to the portability base, but they don't
-use any non-standard new facilities. However, the specification of the
-functions has changed slightly.
-
-
-Changes in Version 1.3
-----------------------
-
-The main change was the addition of the restarting facility for daemon mode
-(i.e. the -f option), which is pretty straightforward.
-
-There were also a lot of minor changes to the paranoia code in daemon mode, to
-try to separate out the case of a demented server from network and other
-'ignorable' problems. These are not entirely successful.
-
-
-Changes in Version 1.4 and 1.5
-------------------------------
-
-There turned out to be a couple of places where the author misunderstood the
-specification of NTP, which affect only its use in server mode. The main
-change is to use stratum 15 instead of stratum 0.
-
-And there were some more relaxations of the paranoia code, to allow for more
-erratic servers, plus a kludge to improve restarting in daemon mode after a
-period of down time has unsynchronised the clock. There is also an
-incompatible change to the debugging options to add a new level - the old -V
-option is now -W, and -V is an intermediate one for debugging daemon mode - but
-they are both hacker's facilities, and not for normal use.
-
-Version 1.5 adds some very minor fixes.
-
-
-Changes in Version 1.6
-----------------------
-
-The first change is support for multiple server addresses - it uses these in a
-round-robin fashion. This may be useful when you have access to several
-servers, all of which are a bit iffy. This means that the restart file format
-is incompatible with msntp 1.5.
-
-It has also been modified to reset itself automatically after detecting an
-inconsistency in its server's timestamps, because the author got sick of the
-failures. It writes a comment to syslog (uniquely) in such cases.
-
-The ability to query a daemon save file was added.
-
-Related to the above, the -E argument has been redefined to mean an error bound
-on various internal times (which is what it had become, anyway) and a -P option
-introduced to be what the -E argument was documented to be.
-
-The lock and save file handling have been changed to allow defaults to be set
-at installation time, and to be overridable at run-time. To disable these
-at either stage, simply set the file names to the null string.
-
-And there have been the usual changes for portability, as standards have been
-modified and/or introduced.
-
-
-Future Versions
----------------
-
-There are unlikely to be any, except probably one to fix bugs in version 1.6.
-
-I attempted to put support for intermittent connexions (e.g. dial-up) into the
-daemon mode, but doing so needs so much code reorganisation that it isn't worth
-it. What needs doing for that is to separate the socket handling from the
-timekeeping, so that they can be run asynchronously (either in separate
-processes or threads), and to look up a network name and open a socket only
-when prodded (and to close it immediately thereafter). So just running it
-with the -r option is the current best solution.
-
-I also attempted to put support for the "Unix 2000" interfaces into the code.
-Ha, ha. Not merely do very few systems define socklen_t (needed for IPv6
-support), but "Unix 2000" neither addresses the leap second problem nor even
-provides an adjtime replacement! Some function like the latter is critical,
-not so much because of the gradual change, but because of its atomicity;
-without it, msntp really needs to be made non-interruptible, and that brings in
-a ghastly number of system-dependencies.
-
-Realistically, it needs a complete rewrite before adding any more function.
-And, worse, the Unix 'standards' need fixing, too.
-
-
-
-Miscellaneous
--------------
-
-Thanks are due to Douglas M. Wells of Connection Technologies for helping the
-author with several IP-related conventions, to Sam Nelson of Stirling
-University for testing it on some very strange systems, and to David Mills for
-clarifying what the NTP specification really is.
-
-Thanks are also due to several other people with locating bugs, finding
-appropriate options for the Makefile and passing on extension code and
-suggestions. As I am sure to leave someone out, I shall not name anyone else.
-
-Version 1.0 - October 1996.
-Version 1.1 - November 1996 - mainly portability improvements.
-Version 1.2 - January 1997 - mainly drift handling, but much reorganisation.
-Version 1.3 - February 1997 - daemon save file, and some robustness changes.
-Version 1.4 - May 1997 - relatively minor fixes, more diagnostic levels etc.
-Version 1.5 - December 1997 - some very minor fixes
-Version 1.6 - October 2000 - quite a few miscellaneous changes
-
-
-Nick Maclaren,
-University of Cambridge Computer Laboratory,
-New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
-Email: nmm1@cam.ac.uk
-Tel.: +44 1223 334761 Fax: +44 1223 334679
+++ /dev/null
-
-
-
-
-
-
-Network Working Group D. Mills
-Request for Comments: 2030 University of Delaware
-Obsoletes: 1769 October 1996
-Category: Informational
-
-
- Simple Network Time Protocol (SNTP) Version 4
- for IPv4, IPv6 and OSI
-
-Status of this Memo
-
- This memo provides information for the Internet community. This memo
- does not specify an Internet standard of any kind. Distribution of
- this memo is unlimited.
-
-Abstract
-
- This memorandum describes the Simple Network Time Protocol (SNTP)
- Version 4, which is an adaptation of the Network Time Protocol (NTP)
- used to synchronize computer clocks in the Internet. SNTP can be used
- when the ultimate performance of the full NTP implementation
- described in RFC-1305 is not needed or justified. When operating with
- current and previous NTP and SNTP versions, SNTP Version 4 involves
- no changes to the NTP specification or known implementations, but
- rather a clarification of certain design features of NTP which allow
- operation in a simple, stateless remote-procedure call (RPC) mode
- with accuracy and reliability expectations similar to the UDP/TIME
- protocol described in RFC-868.
-
- The only significant protocol change in SNTP Version 4 over previous
- versions of NTP and SNTP is a modified header interpretation to
- accommodate Internet Protocol Version 6 (IPv6) [DEE96] and OSI
- [COL94] addressing. However, SNTP Version 4 includes certain optional
- extensions to the basic Version 3 model, including an anycast mode
- and an authentication scheme designed specifically for multicast and
- anycast modes. While the anycast mode extension is described in this
- document, the authentication scheme extension will be described in
- another document to be published later. Until such time that a
- definitive specification is published, these extensions should be
- considered provisional.
-
- This memorandum obsoletes RFC-1769, which describes SNTP Version 3.
- Its purpose is to correct certain inconsistencies in the previous
- document and to clarify header formats and protocol operations for
- current NTP Version 3 (IPv4) and proposed NTP Version 4 (IPv6 and
- OSI), which are also used for SNTP. A working knowledge of the NTP
- Version 3 specification RFC-1305 is not required for an
- implementation of SNTP.
-
-
-
-Mills Informational [Page 1]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
-1. Introduction
-
- The Network Time Protocol (NTP) Version 3 specified in RFC-1305
- [MIL92] is widely used to synchronize computer clocks in the global
- Internet. It provides comprehensive mechanisms to access national
- time and frequency dissemination services, organize the time-
- synchronization subnet and adjust the local clock in each
- participating subnet peer. In most places of the Internet of today,
- NTP provides accuracies of 1-50 ms, depending on the characteristics
- of the synchronization source and network paths.
-
- RFC-1305 specifies the NTP Version 3 protocol machine in terms of
- events, states, transition functions and actions and, in addition,
- engineered algorithms to improve the timekeeping quality and mitigate
- among several synchronization sources, some of which may be faulty.
- To achieve accuracies in the low milliseconds over paths spanning
- major portions of the Internet of today, these intricate algorithms,
- or their functional equivalents, are necessary. However, in many
- cases accuracies in the order of significant fractions of a second
- are acceptable. In such cases, simpler protocols such as the Time
- Protocol [POS83], have been used for this purpose. These protocols
- usually involve an RPC exchange where the client requests the time of
- day and the server returns it in seconds past some known reference
- epoch.
-
- NTP is designed for use by clients and servers with a wide range of
- capabilities and over a wide range of network delays and jitter
- characteristics. Most users of the Internet NTP synchronization
- subnet of today use a software package including the full suite of
- NTP options and algorithms, which are relatively complex, real-time
- applications (see http://www.eecis.udel.edu/~ntp). While the software
- has been ported to a wide variety of hardware platforms ranging from
- personal computers to supercomputers, its sheer size and complexity
- is not appropriate for many applications. Accordingly, it is useful
- to explore alternative access strategies using simpler software
- appropriate for less stringent accuracy expectations.
-
- This document describes the Simple Network Time Protocol (SNTP)
- Version 4, which is a simplified access strategy for servers and
- clients using NTP Version 3 as now specified and deployed in the
- Internet, as well as NTP Version 4 now under development. The access
- paradigm is identical to the UDP/TIME Protocol and, in fact, it
- should be easily possible to adapt a UDP/TIME client implementation,
- say for a personal computer, to operate using SNTP. Moreover, SNTP is
- also designed to operate in a dedicated server configuration
- including an integrated radio clock. With careful design and control
- of the various latencies in the system, which is practical in a
- dedicated design, it is possible to deliver time accurate to the
-
-
-
-Mills Informational [Page 2]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- order of microseconds.
-
- SNTP Version 4 is designed to coexist with existing NTP and SNTP
- Version 3 clients and servers, as well as proposed Version 4 clients
- and servers. When operating with current and previous versions of NTP
- and SNTP, SNTP Version 4 requires no changes to the protocol or
- implementations now running or likely to be implemented specifically
- for NTP ir SNTP Version 4. To a NTP or SNTP server, NTP and SNTP
- clients are undistinguishable; to a NTP or SNTP client, NTP and SNTP
- servers are undistinguishable. Like NTP servers operating in non-
- symmetric modes, SNTP servers are stateless and can support large
- numbers of clients; however, unlike most NTP clients, SNTP clients
- normally operate with only a single server. NTP and SNTP Version 3
- servers can operate in unicast and multicast modes. In addition, SNTP
- Version 4 clients and servers can implement extensions to operate in
- anycast mode.
-
- It is strongly recommended that SNTP be used only at the extremities
- of the synchronization subnet. SNTP clients should operate only at
- the leaves (highest stratum) of the subnet and in configurations
- where no NTP or SNTP client is dependent on another SNTP client for
- synchronization. SNTP servers should operate only at the root
- (stratum 1) of the subnet and then only in configurations where no
- other source of synchronization other than a reliable radio or modem
- time service is available. The full degree of reliability ordinarily
- expected of primary servers is possible only using the redundant
- sources, diverse subnet paths and crafted algorithms of a full NTP
- implementation. This extends to the primary source of synchronization
- itself in the form of multiple radio or modem sources and backup
- paths to other primary servers should all sources fail or the
- majority deliver incorrect time. Therefore, the use of SNTP rather
- than NTP in primary servers should be carefully considered.
-
- An important provision in this document is the reinterpretation of
- certain NTP Versino 4 header fields which provide for IPv6 and OSI
- addressing and optional anycast extensions designed specifically for
- multicast service. These additions are in conjunction with the
- proposed NTP Version 4 specification, which will appear as a separate
- document. The only difference between the current NTP Version 3 and
- proposed NTP Version 4 header formats is the interpretation of the
- four-octet Reference Identifier field, which is used primarily to
- detect and avoid synchronization loops. In Version 3 and Version 4
- primary (stratum-1) servers, this field contains the four-character
- ASCII reference identifier defined later in this document. In Version
- 3 secondary servers and clients, it contains the 32-bit IPv4 address
- of the synchronization source. In Version 4 secondary servers and
- clients, it contains the low order 32 bits of the last transmit
- timestamp received from the synchronization source.
-
-
-
-Mills Informational [Page 3]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- In the case of OSI, the Connectionless Transport Service (CLTS) is
- used [ISO86]. Each SNTP packet is transmitted as tht TS-Userdata
- parameter of a T-UNITDATA Request primitive. Alternately, the header
- can be encapsulated in a TPDU which itself is transported using UDP
- [DOB91]. It is not advised that NTP be operated at the upper layers
- of the OSI stack, such as might be inferred from [FUR94], as this
- could seriously degrade accuracy. With the header formats defined in
- this document, it is in principle possible to interwork between
- servers and clients of one protocol family and another, although the
- practical difficulties may make this inadvisable.
-
- In the following, indented paragraphs such as this one contain
- information not required by the formal protocol specification, but
- considered good practice in protocol implementations.
-
-2. Operating Modes and Addressing
-
- SNTP Version 4 can operate in either unicast (point to point),
- multicast (point to multipoint) or anycast (multipoint to point)
- modes. A unicast client sends a request to a designated server at its
- unicast address and expects a reply from which it can determine the
- time and, optionally, the roundtrip delay and local clock offset
- relative to the server. A multicast server periodically sends a
- unsolicited message to a designated IPv4 or IPv6 local broadcast
- address or multicast group address and ordinarily expects no requests
- from clients. A multicast client listens on this address and
- ordinarily sends no requests. An anycast client sends a request to a
- designated IPv4 or IPv6 local broadcast address or multicast group
- address. One or more anycast servers reply with their individual
- unicast addresses. The client binds to the first one received, then
- continues operation in unicast mode.
-
- Multicast servers should respond to client unicast requests, as
- well as send unsolicited multicast messages. Multicast clients may
- send unicast requests in order to determine the network
- propagation delay between the server and client and then continue
- operation in multicast mode.
-
- In unicast mode, the client and server end-system addresses are
- assigned following the usual IPv4, IPv6 or OSI conventions. In
- multicast mode, the server uses a designated local broadcast address
- or multicast group address. An IP local broadcast address has scope
- limited to a single IP subnet, since routers do not propagate IP
- broadcast datagrams. On the other hand, an IP multicast group address
- has scope extending to potentially the entire Internet. The scoping,
- routing and group membership procedures are determined by
- considerations beyond the scope of this document. For IPv4, the IANA
- has assigned the multicast group address 224.0.1.1 for NTP, which is
-
-
-
-Mills Informational [Page 4]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- used both by multicast servers and anycast clients. NTP multicast
- addresses for IPv6 and OSI have yet to be determined.
-
- Multicast clients listen on the designated local broadcast address or
- multicast group address. In the case of local broadcast addresses, no
- further provisions are necessary. In the case of IP multicast
- addresses, the multicast client and anycast server must implement the
- Internet Group Management Protocol (IGMP) [DEE89], in order that the
- local router joins the multicast group and relays messages to the
- IPv4 or IPv6 multicast group addresses assigned by the IANA. Other
- than the IP addressing conventions and IGMP, there is no difference
- in server or client operations with either the local broadcast
- address or multicast group address.
-
- It is important to adjust the time-to-live (TTL) field in the IP
- header of multicast messages to a reasonable value, in order to
- limit the network resources used by this (and any other) multicast
- service. Only multicast clients in scope will receive multicast
- server messages. Only cooperating anycast servers in scope will
- reply to a client request. The engineering principles which
- determine the proper value to be used are beyond the scope of this
- document.
-
- Anycast mode is designed for use with a set of cooperating servers
- whose addresses are not known beforehand by the client. An anycast
- client sends a request to the designated local broadcast or multicast
- group address as described below. For this purpose, the NTP multicast
- group address assigned by the IANA is used. One or more anycast
- servers listen on the designated local broadcast address or multicast
- group address. Each anycast server, upon receiving a request, sends a
- unicast reply message to the originating client. The client then
- binds to the first such message received and continues operation in
- unicast mode. Subsequent replies from other anycast servers are
- ignored.
-
- In the case of SNTP as specified herein, there is a very real
- vulnerability that SNTP multicast clients can be disrupted by
- misbehaving or hostile SNTP or NTP multicast servers elsewhere in
- the Internet, since at present all such servers use the same IPv4
- multicast group address assigned by the IANA. Where necessary,
- access control based on the server source address can be used to
- select only the designated server known to and trusted by the
- client. The use of cryptographic authentication scheme defined in
- RFC-1305 is optional; however, implementors should be advised that
- extensions to this scheme are planned specifically for NTP
- multicast and anycast modes.
-
-
-
-
-
-Mills Informational [Page 5]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- While not integral to the SNTP specification, it is intended that
- IP broadcast addresses will be used primarily in IP subnets and
- LAN segments including a fully functional NTP server with a number
- of dependent SNTP multicast clients on the same subnet, while IP
- multicast group addresses will be used only in cases where the TTL
- is engineered specifically for each service domain.
-
- In NTP Version 3, the reference identifier was often used to
- walk-back the synchronization subnet to the root (primary server)
- for management purposes. In NTP Version 4, this feature is not
- available, since the addresses are longer than 32 bits. However,
- the intent in the protocol design was to provide a way to detect
- and avoid loops. A peer could determine that a loop was possible
- by comparing the contents of this field with the IPv4 destination
- address in the same packet. A NTP Version 4 server can accomplish
- the same thing by comparing the contents of this field with the
- low order 32 bits of the originate timestamp in the same packet.
- There is a small possibility of false alarm in this scheme, but
- the false alarm rate can be minimized by randomizing the low order
- unused bits of the transmit timestamp.
-
-3. NTP Timestamp Format
-
- SNTP uses the standard NTP timestamp format described in RFC-1305 and
- previous versions of that document. In conformance with standard
- Internet practice, NTP data are specified as integer or fixed-point
- quantities, with bits numbered in big-endian fashion from 0 starting
- at the left, or high-order, position. Unless specified otherwise, all
- quantities are unsigned and may occupy the full field width with an
- implied 0 preceding bit 0.
-
- Since NTP timestamps are cherished data and, in fact, represent the
- main product of the protocol, a special timestamp format has been
- established. NTP timestamps are represented as a 64-bit unsigned
- fixed-point number, in seconds relative to 0h on 1 January 1900. The
- integer part is in the first 32 bits and the fraction part in the
- last 32 bits. In the fraction part, the non-significant low order can
- be set to 0.
-
- It is advisable to fill the non-significant low order bits of the
- timestamp with a random, unbiased bitstring, both to avoid
- systematic roundoff errors and as a means of loop detection and
- replay detection (see below). One way of doing this is to generate
- a random bitstring in a 64-bit word, then perform an arithmetic
- right shift a number of bits equal to the number of significant
- bits of the timestamp, then add the result to the original
- timestamp.
-
-
-
-
-Mills Informational [Page 6]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- This format allows convenient multiple-precision arithmetic and
- conversion to UDP/TIME representation (seconds), but does complicate
- the conversion to ICMP Timestamp message representation, which is in
- milliseconds. The maximum number that can be represented is
- 4,294,967,295 seconds with a precision of about 200 picoseconds,
- which should be adequate for even the most exotic requirements.
-
- 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Seconds |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Seconds Fraction (0-padded) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- Note that, since some time in 1968 (second 2,147,483,648) the most
- significant bit (bit 0 of the integer part) has been set and that the
- 64-bit field will overflow some time in 2036 (second 4,294,967,296).
- Should NTP or SNTP be in use in 2036, some external means will be
- necessary to qualify time relative to 1900 and time relative to 2036
- (and other multiples of 136 years). There will exist a 200-picosecond
- interval, henceforth ignored, every 136 years when the 64-bit field
- will be 0, which by convention is interpreted as an invalid or
- unavailable timestamp.
-
- As the NTP timestamp format has been in use for the last 17 years,
- it remains a possibility that it will be in use 40 years from now
- when the seconds field overflows. As it is probably inappropriate
- to archive NTP timestamps before bit 0 was set in 1968, a
- convenient way to extend the useful life of NTP timestamps is the
- following convention: If bit 0 is set, the UTC time is in the
- range 1968-2036 and UTC time is reckoned from 0h 0m 0s UTC on 1
- January 1900. If bit 0 is not set, the time is in the range 2036-
- 2104 and UTC time is reckoned from 6h 28m 16s UTC on 7 February
- 2036. Note that when calculating the correspondence, 2000 is not a
- leap year. Note also that leap seconds are not counted in the
- reckoning.
-
-4. NTP Message Format
-
- Both NTP and SNTP are clients of the User Datagram Protocol (UDP)
- [POS80], which itself is a client of the Internet Protocol (IP)
- [DAR81]. The structure of the IP and UDP headers is described in the
- cited specification documents and will not be detailed further here.
- The UDP port number assigned to NTP is 123, which should be used in
- both the Source Port and Destination Port fields in the UDP header.
- The remaining UDP header fields should be set as described in the
- specification.
-
-
-
-Mills Informational [Page 7]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- Below is a description of the NTP/SNTP Version 4 message format,
- which follows the IP and UDP headers. This format is identical to
- that described in RFC-1305, with the exception of the contents of the
- reference identifier field. The header fields are defined as follows:
-
- 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |LI | VN |Mode | Stratum | Poll | Precision |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Root Delay |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Root Dispersion |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Reference Identifier |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Reference Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Originate Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Receive Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Transmit Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Key Identifier (optional) (32) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | |
- | Message Digest (optional) (128) |
- | |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- As described in the next section, in SNTP most of these fields are
- initialized with pre-specified data. For completeness, the function
- of each field is briefly summarized below.
-
-
-
-
-
-
-
-Mills Informational [Page 8]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- Leap Indicator (LI): This is a two-bit code warning of an impending
- leap second to be inserted/deleted in the last minute of the current
- day, with bit 0 and bit 1, respectively, coded as follows:
-
- LI Value Meaning
- -------------------------------------------------------
- 00 0 no warning
- 01 1 last minute has 61 seconds
- 10 2 last minute has 59 seconds)
- 11 3 alarm condition (clock not synchronized)
-
- Version Number (VN): This is a three-bit integer indicating the
- NTP/SNTP version number. The version number is 3 for Version 3 (IPv4
- only) and 4 for Version 4 (IPv4, IPv6 and OSI). If necessary to
- distinguish between IPv4, IPv6 and OSI, the encapsulating context
- must be inspected.
-
- Mode: This is a three-bit integer indicating the mode, with values
- defined as follows:
-
- Mode Meaning
- ------------------------------------
- 0 reserved
- 1 symmetric active
- 2 symmetric passive
- 3 client
- 4 server
- 5 broadcast
- 6 reserved for NTP control message
- 7 reserved for private use
-
- In unicast and anycast modes, the client sets this field to 3
- (client) in the request and the server sets it to 4 (server) in the
- reply. In multicast mode, the server sets this field to 5
- (broadcast).
-
- Stratum: This is a eight-bit unsigned integer indicating the stratum
- level of the local clock, with values defined as follows:
-
- Stratum Meaning
- ----------------------------------------------
- 0 unspecified or unavailable
- 1 primary reference (e.g., radio clock)
- 2-15 secondary reference (via NTP or SNTP)
- 16-255 reserved
-
-
-
-
-
-
-Mills Informational [Page 9]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- Poll Interval: This is an eight-bit signed integer indicating the
- maximum interval between successive messages, in seconds to the
- nearest power of two. The values that can appear in this field
- presently range from 4 (16 s) to 14 (16284 s); however, most
- applications use only the sub-range 6 (64 s) to 10 (1024 s).
-
- Precision: This is an eight-bit signed integer indicating the
- precision of the local clock, in seconds to the nearest power of two.
- The values that normally appear in this field range from -6 for
- mains-frequency clocks to -20 for microsecond clocks found in some
- workstations.
-
- Root Delay: This is a 32-bit signed fixed-point number indicating the
- total roundtrip delay to the primary reference source, in seconds
- with fraction point between bits 15 and 16. Note that this variable
- can take on both positive and negative values, depending on the
- relative time and frequency offsets. The values that normally appear
- in this field range from negative values of a few milliseconds to
- positive values of several hundred milliseconds.
-
- Root Dispersion: This is a 32-bit unsigned fixed-point number
- indicating the nominal error relative to the primary reference
- source, in seconds with fraction point between bits 15 and 16. The
- values that normally appear in this field range from 0 to several
- hundred milliseconds.
-
- Reference Identifier: This is a 32-bit bitstring identifying the
- particular reference source. In the case of NTP Version 3 or Version
- 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a
- four-character ASCII string, left justified and zero padded to 32
- bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4
- address of the reference source. In NTP Version 4 secondary servers,
- this is the low order 32 bits of the latest transmit timestamp of the
- reference source. NTP primary (stratum 1) servers should set this
- field to a code identifying the external reference source according
- to the following list. If the external reference is one of those
- listed, the associated code should be used. Codes for sources not
- listed can be contrived as appropriate.
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 10]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- Code External Reference Source
- ----------------------------------------------------------------
- LOCL uncalibrated local clock used as a primary reference for
- a subnet without external means of synchronization
- PPS atomic clock or other pulse-per-second source
- individually calibrated to national standards
- ACTS NIST dialup modem service
- USNO USNO modem service
- PTB PTB (Germany) modem service
- TDF Allouis (France) Radio 164 kHz
- DCF Mainflingen (Germany) Radio 77.5 kHz
- MSF Rugby (UK) Radio 60 kHz
- WWV Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz
- WWVB Boulder (US) Radio 60 kHz
- WWVH Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz
- CHU Ottawa (Canada) Radio 3330, 7335, 14670 kHz
- LORC LORAN-C radionavigation system
- OMEG OMEGA radionavigation system
- GPS Global Positioning Service
- GOES Geostationary Orbit Environment Satellite
-
- Reference Timestamp: This is the time at which the local clock was
- last set or corrected, in 64-bit timestamp format.
-
- Originate Timestamp: This is the time at which the request departed
- the client for the server, in 64-bit timestamp format.
-
- Receive Timestamp: This is the time at which the request arrived at
- the server, in 64-bit timestamp format.
-
- Transmit Timestamp: This is the time at which the reply departed the
- server for the client, in 64-bit timestamp format.
-
- Authenticator (optional): When the NTP authentication scheme is
- implemented, the Key Identifier and Message Digest fields contain the
- message authentication code (MAC) information defined in Appendix C
- of RFC-1305.
-
-5. SNTP Client Operations
-
- A SNTP client can operate in multicast mode, unicast mode or anycast
- mode. In multicast mode, the client sends no request and waits for a
- broadcast (mode 5) from a designated multicast server. In unicast
- mode, the client sends a request (mode 3) to a designated unicast
- server and expects a reply (mode 4) from that server. In anycast
- mode, the client sends a request (mode 3) to a designated local
- broadcast or multicast group address and expects a reply (mode 4)
- from one or more anycast servers. The client uses the first reply
-
-
-
-Mills Informational [Page 11]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- received to establish the particular server for subsequent unicast
- operations. Later replies from this server (duplicates) or any other
- server are ignored. Other than the selection of address in the
- request, the operations of anycast and unicast clients are identical.
- Requests are normally sent at intervals from 64 s to 1024 s,
- depending on the frequency tolerance of the client clock and the
- required accuracy.
-
- A unicast or anycast client initializes the NTP message header, sends
- the request to the server and strips the time of day from the
- Transmit Timestamp field of the reply. For this purpose, all of the
- NTP header fields shown above can be set to 0, except the first octet
- and (optional) Transmit Timestamp fields. In the first octet, the LI
- field is set to 0 (no warning) and the Mode field is set to 3
- (client). The VN field must agree with the version number of the
- NTP/SNTP server; however, Version 4 servers will also accept previous
- versions. Version 3 (RFC-1305) and Version 2 (RFC-1119) servers
- already accept all previous versions, including Version 1 (RFC-1059).
- Note that Version 0 (RFC-959) is no longer supported by any other
- version.
-
- Since there will probably continue to be NTP and SNTP servers of all
- four versions interoperating in the Internet, careful consideration
- should be given to the version used by SNTP Version 4 clients. It is
- recommended that clients use the latest version known to be supported
- by the selected server in the interest of the highest accuracy and
- reliability. SNTP Version 4 clients can interoperate with all
- previous version NTP and SNTP servers, since the header fields used
- by SNTP clients are unchanged. Version 4 servers are required to
- reply in the same version as the request, so the VN field of the
- request also specifies the version of the reply.
-
- While not necessary in a conforming client implementation, in unicast
- and anycast modes it highly recommended that the transmit timestamp
- in the request is set to the time of day according to the client
- clock in NTP timestamp format. This allows a simple calculation to
- determine the propagation delay between the server and client and to
- align the local clock generally within a few tens of milliseconds
- relative to the server. In addition, this provides a simple method to
- verify that the server reply is in fact a legitimate response to the
- specific client request and avoid replays. In multicast mode, the
- client has no information to calculate the propagation delay or
- determine the validity of the server, unless the NTP authentication
- scheme is used.
-
- To calculate the roundtrip delay d and local clock offset t relative
- to the server, the client sets the transmit timestamp in the request
- to the time of day according to the client clock in NTP timestamp
-
-
-
-Mills Informational [Page 12]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- format. The server copies this field to the originate timestamp in
- the reply and sets the receive timestamp and transmit timestamp to
- the time of day according to the server clock in NTP timestamp
- format.
-
- When the server reply is received, the client determines a
- Destination Timestamp variable as the time of arrival according to
- its clock in NTP timestamp format. The following table summarizes the
- four timestamps.
-
- Timestamp Name ID When Generated
- ------------------------------------------------------------
- Originate Timestamp T1 time request sent by client
- Receive Timestamp T2 time request received by server
- Transmit Timestamp T3 time reply sent by server
- Destination Timestamp T4 time reply received by client
-
- The roundtrip delay d and local clock offset t are defined as
-
- d = (T4 - T1) - (T2 - T3) t = ((T2 - T1) + (T3 - T4)) / 2.
-
- The following table summarizes the SNTP client operations in unicast,
- anycast and multicast modes. The recommended error checks are shown
- in the Reply and Multicast columns in the table. The message should
- be considered valid only if all the fields shown contain values in
- the respective ranges. Whether to believe the message if one or more
- of the fields marked "ignore" contain invalid values is at the
- discretion of the implementation.
-
- Field Name Unicast/Anycast Multicast
- Request Reply
- ----------------------------------------------------------
- LI 0 0-2 0-2
- VN 1-4 copied from 1-4
- request
- Mode 3 4 5
- Stratum 0 1-14 1-14
- Poll 0 ignore ignore
- Precision 0 ignore ignore
- Root Delay 0 ignore ignore
- Root Dispersion 0 ignore ignore
- Reference Identifier 0 ignore ignore
- Reference Timestamp 0 ignore ignore
- Originate Timestamp 0 (see text) ignore
- Receive Timestamp 0 (see text) ignore
- Transmit Timestamp (see text) nonzero nonzero
- Authenticator optional optional optional
-
-
-
-
-Mills Informational [Page 13]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
-6. SNTP Server Operations
-
- A SNTP Version 4 server operating with either a NTP or SNTP client of
- the same or previous versions retains no persistent state. Since a
- SNTP server ordinarily does not implement the full set of NTP
- algorithms intended to support redundant peers and diverse network
- paths, a SNTP server should be operated only in conjunction with a
- source of external synchronization, such as a reliable radio clock or
- telephone modem. In this case it always operates as a primary
- (stratum 1) server.
-
- A SNTP server can operate in unicast mode, anycast mode, multicast
- mode or any combination of these modes. In unicast and anycast modes,
- the server receives a request (mode 3), modifies certain fields in
- the NTP header, and sends a reply (mode 4), possibly using the same
- message buffer as the request. In anycast mode, the server listens on
- the designated local broadcast or multicast group address assigned by
- the IANA, but uses its own unicast address in the source address
- field of the reply. Other than the selection of address in the reply,
- the operations of anycast and unicast servers are identical.
- Multicast messages are normally sent at poll intervals from 64 s to
- 1024 s, depending on the expected frequency tolerance of the client
- clocks and the required accuracy.
-
- In unicast and anycast modes, the VN and Poll fields of the request
- are copied intact to the reply. If the Mode field of the request is 3
- (client), it is set to 4 (server) in the reply; otherwise, this field
- is set to 2 (symmetric passive) in order to conform to the NTP
- specification. This allows clients configured in symmetric active
- (mode 1) to interoperate successfully, even if configured in possibly
- suboptimal ways. In multicast (unsolicited) mode, the VN field is set
- to 4, the Mode field is set to 5 (broadcast), and the Poll field set
- to the nearest integer base-2 logarithm of the poll interval.
-
- Note that it is highly desirable that, if a server supports
- multicast mode, it also supports unicast mode. This is so a
- potential multicast client can calculate the propagation delay
- using a client/server exchange prior to regular operation using
- only multicast mode. If the server supports anycast mode, then it
- must support unicast mode. There does not seem to be a great
- advantage to operate both multicast and anycast modes at the same
- time, although the protocol specification does not forbid it.
-
- In unicast and anycast modes, the server may or may not respond if
- not synchronized to a correctly operating radio clock, but the
- preferred option is to respond, since this allows reachability to be
- determined regardless of synchronization state. In multicast mode,
- the server sends broadcasts only if synchronized to a correctly
-
-
-
-Mills Informational [Page 14]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- operating reference clock.
-
- The remaining fields of the NTP header are set in the following way.
- Assuming the server is synchronized to a radio clock or other primary
- reference source and operating correctly, the LI field is set to 0
- and the Stratum field is set to 1 (primary server); if not, the
- Stratum field is set to 0 and the LI field is set to 3. The Precision
- field is set to reflect the maximum reading error of the local clock.
- For all practical cases it is computed as the negative of the number
- of significant bits to the right of the decimal point in the NTP
- timestamp format. The Root Delay and Root Dispersion fields are set
- to 0 for a primary server; optionally, the Root Dispersion field can
- be set to a value corresponding to the maximum expected error of the
- radio clock itself. The Reference Identifier is set to designate the
- primary reference source, as indicated in the table of Section 5 of
- this document.
-
- The timestamp fields are set as follows. If the server is
- unsynchronized or first coming up, all timestamp fields are set to
- zero. If synchronized, the Reference Timestamp is set to the time the
- last update was received from the radio clock or modem. In unicast
- and anycast modes, the Receive Timestamp and Transmit Timestamp
- fields are set to the time of day when the message is sent and the
- Originate Timestamp field is copied unchanged from the Transmit
- Timestamp field of the request. It is important that this field be
- copied intact, as a NTP client uses it to avoid replays. In multicast
- mode, the Originate Timestamp and Receive Timestamp fields are set to
- 0 and the Transmit Timestamp field is set to the time of day when the
- message is sent. The following table summarizes these actions.
-
- Field Name Unicast/Anycast Multicast
- Request Reply
- ----------------------------------------------------------
- LI ignore 0 or 3 0 or 3
- VN 1-4 copied from 4
- request
- Mode 3 2 or 4 5
- Stratum ignore 1 1
- Poll ignore copied from log2 poll
- request interval
- Precision ignore -log2 server -log2 server
- significant significant
- bits bits
- Root Delay ignore 0 0
- Root Dispersion ignore 0 0
- Reference Identifier ignore source ident source ident
- Reference Timestamp ignore time of last time of last
- radio update radio update
-
-
-
-Mills Informational [Page 15]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- Originate Timestamp ignore copied from 0
- transmit
- timestamp
- Receive Timestamp ignore time of day 0
- Transmit Timestamp (see text) time of day time of day
- Authenticator optional optional optional
-
- There is some latitude on the part of most clients to forgive invalid
- timestamps, such as might occur when first coming up or during
- periods when the primary reference source is inoperative. The most
- important indicator of an unhealthy server is the LI field, in which
- a value of 3 indicates an unsynchronized condition. When this value
- is displayed, clients should discard the server message, regardless
- of the contents of other fields.
-
-7. Configuration and Management
-
- Initial setup for SNTP servers and clients can be done using a
- configuration file if a file system is available, or a serial port if
- not. It is intended that in-service management of NTP and SNTP
- Version 4 servers and clients be performed using SNMP and a suitable
- MIB to be published later. Ordinarily, SNTP servers and clients are
- expected to operate with little or no site-specific configuration,
- other than specifying the IP address and subnet mask or OSI NSAP
- address.
-
- Unicast clients must be provided with the designated server name or
- address. If a server name is used, the address of one of more DNS
- servers must be provided. Multicast servers and anycast clients must
- be provided with the TTL and local broadcast or multicast group
- address. Anycast servers and multicast clients may be configured with
- a list of address-mask pairs for access control, so that only those
- clients or servers known to be trusted will be used. These servers
- and clients must implement the IGMP protocol and be provided with the
- local broadcast or multicast group address as well. The configuration
- data for cryptographic authentication is beyond the scope of this
- document.
-
- There are several scenarios which provide automatic server discovery
- and selection for SNTP clients with no pre-specified configuration,
- other than the IP address and subnet mask or OSI NSAP address. For a
- IP subnet or LAN segment including a fully functional NTP server, the
- clients can be configured for multicast mode using the local
- broadcast address. The same approach can be used with other servers
- using the multicast group address. In both cases, provision of an
- access control list is a good way to insure only trusted sources can
- be used to set the local clock.
-
-
-
-
-Mills Informational [Page 16]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- In another scenario suitable for an extended network with significant
- network propagation delays, clients can be configured for anycast
- mode, both upon initial startup and after some period when the
- currently selected unicast source has not been heard. Following the
- defined protocol, the client binds to the first reply heard and
- continues operation in unicast mode. In this mode the local clock can
- be automatically adjusted to compensate for the propagation delay.
-
- In still another scenario suitable for any network and where
- multicast service is not available, the DNS can be set up with a
- common CNAME, like time.domain.net, and a list of address records for
- NTP servers in the same domain. Upon resolving time.domain.net and
- obtaining the list, the client selects a server at random and begins
- operation in unicast mode with that server. Many variations on this
- theme are possible.
-
-8. Acknowledgements
-
- Jeff Learman was helpful in developing the OSI model for this
- protocol. Ajit Thyagarajan provided valuable suggestions and
- corrections.
-
-9. References
-
- [COL94] Colella, R., R. Callon, E. Gardner, Y. Rekhter, "Guidelines
- for OSI NSAP allocation in the Internet", RFC 1629, NIST, May 1994.
-
- [DAR81] Postel, J., "Internet Protocol", STD 5, RFC 791,
- USC Information Sciences Institute, September 1981.
-
- [DEE89] Deering, S., "Host extensions for IP multicasting", STD 5,
- RFC 1112, Stanford University, August 1989.
-
- [DEE96] Deering, S., R. Hinden, "Internet Protocol, Version 6 (IPv6)
- Specification", RFC 1883, Xerox and Ipsilon, January 1996.
-
- [DOB91] Dobbins, K, W. Haggerty, C. Shue, "OSI connectionless
- transport services on top of UDP - Version: 1", RFC 1240, Open
- Software Foundation, June 1991.
-
- [EAS95] Eastlake, D., 3rd., and C. Kaufman, "Domain Name System
- Security Extensions", Work in Progress.
-
- [FUR94] Furniss, P., "Octet sequences for upper-layer OSI to support
- basic communications applications", RFC 1698, Consultant,
- October 1994.
-
-
-
-
-
-Mills Informational [Page 17]
-
-RFC 2030 SNTPv4 for IPv4, IPv6 and OSI October 1996
-
-
- [HIN96] Hinden, R., and S. Deering, "IP Version 6 addressing
- Architecture", RFC 1884, Ipsilon and Xerox, January 1996.
-
- [ISO86] International Standards 8602 - Information Processing Systems
- - OSI: Connectionless Transport Protocol Specification. International
- Standards Organization, December 1986.
-
- [MIL92] Mills, D., "Network Time Protocol (Version 3) specification,
- implementation and analysis", RFC 1305, University of Delaware,
- March 1992.
-
- [PAR93] Partridge, C., T. Mendez and W. Milliken, "Host anycasting
- service", RFC 1546, Bolt Beranek Newman, November 1993.
-
- [POS80] Postel, J., "User Datagram Protocol", STD 6, RFC 768,
- USC Information Sciences Institute, August 1980.
-
- [POS83] Postel, J., "Time Protocol", STD 26, RFC 868,
- USC Information Sciences Institute, May 1983.
-
-Security Considerations
-
- Security issues are not discussed in this memo.
-
-Author's Address
-
- David L. Mills
- Electrical Engineering Department
- University of Delaware
- Newark, DE 19716
-
- Phone: (302) 831-8247
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 18]
-
+++ /dev/null
-
-
-
-
-
-
-Network Working Group D. Mills
-Request for Comments: 4330 University of Delaware
-Obsoletes: 2030, 1769 January 2006
-Category: Informational
-
-
- Simple Network Time Protocol (SNTP) Version 4
- for IPv4, IPv6 and OSI
-
-Status of This Memo
-
- This memo provides information for the Internet community. It does
- not specify an Internet standard of any kind. Distribution of this
- memo is unlimited.
-
-Copyright Notice
-
- Copyright (C) The Internet Society (2006).
-
-Abstract
-
- This memorandum describes the Simple Network Time Protocol Version 4
- (SNTPv4), which is a subset of the Network Time Protocol (NTP) used
- to synchronize computer clocks in the Internet. SNTPv4 can be used
- when the ultimate performance of a full NTP implementation based on
- RFC 1305 is neither needed nor justified. When operating with
- current and previous NTP and SNTP versions, SNTPv4 requires no
- changes to the specifications or known implementations, but rather
- clarifies certain design features that allow operation in a simple,
- stateless remote-procedure call (RPC) mode with accuracy and
- reliability expectations similar to the UDP/TIME protocol described
- in RFC 868.
-
- This memorandum obsoletes RFC 1769, which describes SNTP Version 3
- (SNTPv3), and RFC 2030, which describes SNTPv4. Its purpose is to
- correct certain inconsistencies in the previous documents and to
- clarify header formats and protocol operations for NTPv3 (IPv4) and
- SNTPv4 (IPv4, IPv6, and OSI), which are also used for SNTP. A
- further purpose is to provide guidance for home and business client
- implementations for routers and other consumer devices to protect the
- server population from abuse. A working knowledge of the NTPv3
- specification, RFC 1305, is not required for an implementation of
- SNTP.
-
-
-
-
-
-
-
-
-Mills Informational [Page 1]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
-Table of Contents
-
- 1. Introduction ....................................................2
- 1.1. Specification of Requirements ..............................5
- 2. Operating Modes and Addressing ..................................5
- 3. NTP Timestamp Format ............................................6
- 4. Message Format ..................................................8
- 5. SNTP Client Operations .........................................13
- 6. SNTP Server Operations .........................................16
- 7. Configuration and Management ...................................19
- 8. The Kiss-o'-Death Packet .......................................20
- 9. On Being a Good Network Citizen ................................21
- 10. Best Practices ................................................21
- 11. Security Considerations .......................................24
- 12. Acknowledgements ..............................................24
- 13. Contributors ..................................................24
- 14. Informative References ........................................25
-
-1. Introduction
-
- The Network Time Protocol Version 3 (NTPv3), specified in RFC 1305
- [MIL92], is widely used to synchronize computer clocks in the global
- Internet. It provides comprehensive mechanisms to access national
- time and frequency dissemination services, organize the NTP subnet of
- servers and clients, and adjust the system clock in each participant.
- In most places of the Internet of today, NTP provides accuracies of
- 1-50 ms, depending on the characteristics of the synchronization
- source and network paths.
-
- RFC 1305 specifies the NTP protocol machine in terms of events,
- states, transition functions and actions, and engineered algorithms
- to improve the timekeeping quality and to mitigate several
- synchronization sources, some of which may be faulty. To achieve
- accuracies in the low milliseconds over paths spanning major portions
- of the Internet, these intricate algorithms, or their functional
- equivalents, are necessary. In many applications, accuracies on the
- order of significant fractions of a second are acceptable. In simple
- home router applications, accuracies of up to a minute may suffice.
- In such cases, simpler protocols, such as the Time Protocol specified
- in RFC 868 [POS83], have been used for this purpose. These protocols
- involve an RPC exchange where the client requests the time of day and
- the server returns it in seconds past a known reference epoch.
-
- NTP is designed for use by clients and servers with a wide range of
- capabilities and over a wide range of network jitter and clock
- frequency wander characteristics. Many users of NTP in the Internet
- of today use a software distribution available from www.ntp.org. The
- distribution, which includes the full suite of NTP options,
-
-
-
-Mills Informational [Page 2]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- mitigation algorithms, and security schemes, is a relatively complex,
- real-time application. Although the software has been ported to a
- wide variety of hardware platforms ranging from personal computers to
- supercomputers, its sheer size and complexity is not appropriate for
- many applications. Accordingly, it is useful to explore alternative
- strategies using simpler software appropriate for less stringent
- accuracy expectations.
-
- This memo describes the Simple Network Time Protocol Version 4
- (SNTPv4), which is a simplified access paradigm for servers and
- clients using current and previous versions of NTP and SNTP. The
- access paradigm is identical to the UDP/TIME Protocol, and, in fact,
- it should be easy to adapt a UDP/TIME client implementation, say for
- a personal computer, to operate using SNTP. Moreover, SNTP is also
- designed to operate in a dedicated server configuration including an
- integrated radio clock. With careful design and control of the
- various latencies in the system, which is practical in a dedicated
- design, it is possible to deliver time accurate on the order of
- microseconds.
-
- The only significant protocol change in SNTPv4 from previous SNTP
- versions is a modified header interpretation to accommodate Internet
- Protocol Version 6 (IPv6) (RFC 2460) and OSI (RFC 1629) addressing.
- However, SNTPv4 includes certain optional extensions to the basic NTP
- Version 3 (NTPv3) model, including a manycast mode and a public-key-
- based authentication scheme designed specifically for broadcast and
- manycast applications. Although the manycast mode is described in
- this memo, the authentication scheme is described in another RFC to
- be submitted later. Until such time that a definitive NTPv4
- specification is published, the manycast and authentication features
- should be considered provisional. In addition, this memo introduces
- the kiss-o'-death message, which can be used by servers to suppress
- client requests as circumstances require.
-
- When operating with current and previous versions of NTP and SNTP,
- SNTPv4 requires no changes to the protocol or implementations now
- running or likely to be implemented specifically for future NTP or
- SNTP versions. The NTP and SNTP packet formats are the same, and the
- arithmetic operations to calculate the client time, clock offset, and
- roundtrip delay are the same. To an NTP or SNTP server, NTP and SNTP
- clients are indistinguishable; to an NTP or SNTP client, NTP and SNTP
- servers are indistinguishable. Like NTP servers operating in non-
- symmetric modes, SNTP servers are stateless and can support large
- numbers of clients; however, unlike most NTP clients, SNTP clients
- normally operate with only a single server at a time.
-
- The full degree of reliability ordinarily expected of NTP servers is
- possible only using redundant sources, diverse paths, and the crafted
-
-
-
-Mills Informational [Page 3]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- algorithms of a full NTP implementation. It is strongly recommended
- that SNTP clients be used only at the extremities of the
- synchronization subnet. SNTP clients should operate only at the
- leaves (highest stratum) of the subnet and in configurations where no
- NTP or SNTP client is dependent on another SNTP client for
- synchronization. SNTP servers should operate only at the root
- (stratum 1) of the subnet, and then only in configurations where no
- other source of synchronization other than a reliable radio clock or
- telephone modem is available.
-
- An important provision in this memo is the interpretation of certain
- NTP header fields that provide for IPv6 [DEE98] and OSI [COL94]
- addressing. The only significant difference between the NTP and
- SNTPv4 header formats is the four-octet Reference Identifier field,
- which is used primarily to detect and avoid synchronization loops.
- In all NTP and SNTP versions providing IPv4 addressing, primary
- servers use a four-character ASCII reference clock identifier in this
- field, whereas secondary servers use the 32-bit IPv4 address of the
- synchronization source. In SNTPv4 providing IPv6 and OSI addressing,
- primary servers use the same clock identifier, but secondary servers
- use the first 32 bits of the MD5 hash of the IPv6 or NSAP address of
- the synchronization source. A further use of this field is when the
- server sends a kiss-o'-death message, documented later in this memo.
-
- NTP Version 4 (NTPv4), now in deployment, but not yet the subject
- of a standards document, uses the same Reference Identifier field
- as SNTPv4.
-
- In the case of OSI, the Connectionless Transport Service (CLTS) is
- used as in [ISO86]. Each SNTP packet is transmitted as the TS-
- Userdata parameter of a T-UNITDATA Request primitive. Alternately,
- the header can be encapsulated in a Transport Protocol Data Unit
- (TPDU), which itself is transported using UDP, as described in RFC
- 1240 [DOB91]. It is not advised that NTP be operated at the upper
- layers of the OSI stack, such as might be inferred from RFC 1698
- [FUR94], as this could seriously degrade accuracy. With the header
- formats defined in this memo, it is in principle possible to
- interwork between servers and clients of one protocol family and
- another, although the practical difficulties may make this
- inadvisable.
-
- In the following, indented paragraphs such as this one contain
- information not required by the formal protocol specification, but
- considered good practice in protocol implementations.
-
- This memo is organized as follows. Section 2 describes how the
- protocol works, the various modes, and how IP addresses and UDP ports
- are used. Section 3 describes the NTP timestamp format, and Section
-
-
-
-Mills Informational [Page 4]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- 4 the NTP message format. Section 5 summarizes SNTP client
- operations, and Section 6 summarizes SNTP server operations. Section
- 7 summarizes operation and management issues. Section 8 describes
- the kiss-o'-death message, newly minted with functions similar to the
- ICMP Source Quench and ICMP Destination Unreachable messages.
- Section 9 summarizes design issues important for good network
- citizenry and presents an example algorithm designed to give good
- reliability while minimizing network and server resource demands.
-
-1.1. Specification of Requirements
-
- The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
- "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
- document are to be interpreted as described in RFC 2119 [BRA97].
-
-2. Operating Modes and Addressing
-
- Unless excepted in context, a reference to broadcast address means
- IPv4 broadcast address, IPv4 multicast group address, or IPv6 address
- of appropriate scope. Further information on the broadcast/multicast
- model is in RFC 1112 [DEE89]. Details of address format, scoping
- rules, etc., are beyond the scope of this memo. SNTPv4 can operate
- with either unicast (point to point), broadcast (point to
- multipoint), or manycast (multipoint to point) addressing modes. A
- unicast client sends a request to a designated server at its unicast
- address and expects a reply from which it can determine the time and,
- optionally, the roundtrip delay and clock offset relative to the
- server. A broadcast server periodically sends an unsolicited message
- to a designated broadcast address. A broadcast client listens on
- this address and ordinarily sends no requests.
-
- Manycast is an extension of the anycast paradigm described in RFC
- 1546 [PAR93]. It is designed for use with a set of cooperating
- servers whose addresses are not known beforehand. The manycast
- client sends an ordinary NTP client request to a designated broadcast
- address. One or more manycast servers listen on that address. Upon
- receiving a request, a manycast server sends an ordinary NTP server
- reply to the client. The client then mobilizes an association for
- each server found and continues operation with all of them.
- Subsequently, the NTP mitigation algorithms operate to cast out all
- except the best three.
-
- Broadcast servers should respond to client unicast requests, as
- well as send unsolicited broadcast messages. Broadcast clients
- may send unicast requests in order to measure the network
- propagation delay between the server and client and then continue
- operation in listen-only mode. However, broadcast servers may
-
-
-
-
-Mills Informational [Page 5]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- choose not to respond to unicast requests, so unicast clients
- should be prepared to abandon the measurement and assume a default
- value for the delay.
-
- The client and server addresses are assigned following the usual
- IPv4, IPv6 or OSI conventions. For NTP multicast, the IANA has
- reserved the IPv4 group address 224.0.1.1 and the IPv6 address ending
- :101 with appropriate scope. The NTP broadcast address for OSI has
- yet to be determined. Notwithstanding the IANA reserved addresses,
- other multicast addresses can be used that do not conflict with
- others assigned in scope. The scoping, routing, and group membership
- procedures are determined by considerations beyond the scope of this
- memo.
-
- It is important to adjust the time-to-live (TTL) field in the IP
- header of multicast messages to a reasonable value in order to
- limit the network resources used by this (and any other) multicast
- service. Only multicast clients in scope will receive multicast
- server messages. Only cooperating manycast servers in scope will
- reply to a client request. The engineering principles that
- determine the proper values to be used are beyond the scope of
- this memo.
-
- In the case of SNTP as specified herein, there is a very real
- vulnerability that SNTP broadcast clients can be disrupted by
- misbehaving or hostile SNTP or NTP broadcast servers elsewhere in
- the Internet. It is strongly recommended that access controls
- and/or cryptographic authentication means be provided for
- additional security in such cases.
-
- It is intended that IP broadcast addresses will be used primarily
- in IP subnets and LAN segments including a fully functional NTP
- server with a number of dependent SNTP broadcast clients on the
- same subnet, and that IP multicast group addresses will be used
- only in cases where the TTL is engineered specifically for each
- service domain. However, these uses are not integral to the SNTP
- specification.
-
-3. NTP Timestamp Format
-
- SNTP uses the standard NTP timestamp format described in RFC 1305 and
- previous versions of that document. In conformance with standard
- Internet practice, NTP data are specified as integer or fixed-point
- quantities, with bits numbered in big-endian fashion from 0 starting
- at the left or most significant end. Unless specified otherwise, all
- quantities are unsigned and may occupy the full field width with an
- implied 0 preceding bit 0.
-
-
-
-
-Mills Informational [Page 6]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- Because NTP timestamps are cherished data and, in fact, represent the
- main product of the protocol, a special timestamp format has been
- established. NTP timestamps are represented as a 64-bit unsigned
- fixed-point number, in seconds relative to 0h on 1 January 1900. The
- integer part is in the first 32 bits, and the fraction part in the
- last 32 bits. In the fraction part, the non-significant low-order
- bits are not specified and are ordinarily set to 0.
-
- It is advisable to fill the non-significant low-order bits of the
- timestamp with a random, unbiased bitstring, both to avoid
- systematic roundoff errors and to provide loop detection and
- replay detection (see below). It is important that the bitstring
- be unpredictable by an intruder. One way of doing this is to
- generate a random 128-bit bitstring at startup. After that, each
- time the system clock is read, the string consisting of the
- timestamp and bitstring is hashed with the MD5 algorithm, then the
- non-significant bits of the timestamp are copied from the result.
-
- The NTP format allows convenient multiple-precision arithmetic and
- conversion to UDP/TIME message (seconds), but does complicate the
- conversion to ICMP Timestamp message (milliseconds) and Unix time
- values (seconds and microseconds or seconds and nanoseconds). The
- maximum number that can be represented is 4,294,967,295 seconds with
- a precision of about 232 picoseconds, which should be adequate for
- even the most exotic requirements.
-
- 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Seconds |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Seconds Fraction (0-padded) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- Note that since some time in 1968 (second 2,147,483,648), the most
- significant bit (bit 0 of the integer part) has been set and that the
- 64-bit field will overflow some time in 2036 (second 4,294,967,296).
- There will exist a 232-picosecond interval, henceforth ignored, every
- 136 years when the 64-bit field will be 0, which by convention is
- interpreted as an invalid or unavailable timestamp.
-
- As the NTP timestamp format has been in use for over 20 years, it
- is possible that it will be in use 32 years from now, when the
- seconds field overflows. As it is probably inappropriate to
- archive NTP timestamps before bit 0 was set in 1968, a convenient
- way to extend the useful life of NTP timestamps is the following
- convention: If bit 0 is set, the UTC time is in the range 1968-
- 2036, and UTC time is reckoned from 0h 0m 0s UTC on 1 January
-
-
-
-Mills Informational [Page 7]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- 1900. If bit 0 is not set, the time is in the range 2036-2104 and
- UTC time is reckoned from 6h 28m 16s UTC on 7 February 2036. Note
- that when calculating the correspondence, 2000 is a leap year, and
- leap seconds are not included in the reckoning.
-
- The arithmetic calculations used by NTP to determine the clock
- offset and roundtrip delay require the client time to be within 34
- years of the server time before the client is launched. As the
- time since the Unix base 1970 is now more than 34 years, means
- must be available to initialize the clock at a date closer to the
- present, either with a time-of-year (TOY) chip or from firmware.
-
-4. Message Format
-
- Both NTP and SNTP are clients of the User Datagram Protocol (UDP)
- specified in RFC 768 [POS80]. The structures of the IP and UDP
- headers are described in the cited specification documents and will
- not be detailed further here. The UDP port number assigned by the
- IANA to NTP is 123. The SNTP client should use this value in the UDP
- Destination Port field for client request messages. The Source Port
- field of these messages can be any nonzero value chosen for
- identification or multiplexing purposes. The server interchanges
- these fields for the corresponding reply messages.
-
- This differs from the RFC 2030 specifications, which required both
- the source and destination ports to be 123. The intent of this
- change is to allow the identification of particular client
- implementations (which are now allowed to use unreserved port
- numbers, including ones of their choosing) and to attain
- compatibility with Network Address Port Translation (NAPT)
- described in RFC 2663 [SRI99] and RFC 3022 [SRI01].
-
- Figure 1 is a description of the NTP and SNTP message format, which
- follows the IP and UDP headers in the message. This format is
- identical to the NTP message format described in RFC 1305, with the
- exception of the Reference Identifier field described below. For
- SNTP client messages, most of these fields are zero or initialized
- with pre-specified data. For completeness, the function of each
- field is briefly summarized below.
-
-
-
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 8]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |LI | VN |Mode | Stratum | Poll | Precision |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Root Delay |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Root Dispersion |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Reference Identifier |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Reference Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Originate Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Receive Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Transmit Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Key Identifier (optional) (32) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | |
- | Message Digest (optional) (128) |
- | |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- Figure 1. NTP Packet Header
-
- Leap Indicator (LI): This is a two-bit code warning of an impending
- leap second to be inserted/deleted in the last minute of the current
- day. This field is significant only in server messages, where the
- values are defined as follows:
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 9]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- LI Meaning
- ---------------------------------------------
- 0 no warning
- 1 last minute has 61 seconds
- 2 last minute has 59 seconds
- 3 alarm condition (clock not synchronized)
-
- On startup, servers set this field to 3 (clock not synchronized), and
- set this field to some other value when synchronized to the primary
- reference clock. Once set to a value other than 3, the field is
- never set to that value again, even if all synchronization sources
- become unreachable or defective.
-
- Version Number (VN): This is a three-bit integer indicating the
- NTP/SNTP version number, currently 4. If necessary to distinguish
- between IPv4, IPv6, and OSI, the encapsulating context must be
- inspected.
-
- Mode: This is a three-bit number indicating the protocol mode. The
- values are defined as follows:
-
- Mode Meaning
- ------------------------------------
- 0 reserved
- 1 symmetric active
- 2 symmetric passive
- 3 client
- 4 server
- 5 broadcast
- 6 reserved for NTP control message
- 7 reserved for private use
-
- In unicast and manycast modes, the client sets this field to 3
- (client) in the request, and the server sets it to 4 (server) in the
- reply. In broadcast mode, the server sets this field to 5
- (broadcast). The other modes are not used by SNTP servers and
- clients.
-
- Stratum: This is an eight-bit unsigned integer indicating the
- stratum. This field is significant only in SNTP server messages,
- where the values are defined as follows:
-
- Stratum Meaning
- ----------------------------------------------
- 0 kiss-o'-death message (see below)
- 1 primary reference (e.g., synchronized by radio clock)
- 2-15 secondary reference (synchronized by NTP or SNTP)
- 16-255 reserved
-
-
-
-Mills Informational [Page 10]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- Poll Interval: This is an eight-bit unsigned integer used as an
- exponent of two, where the resulting value is the maximum interval
- between successive messages in seconds. This field is significant
- only in SNTP server messages, where the values range from 4 (16 s) to
- 17 (131,072 s -- about 36 h).
-
- Precision: This is an eight-bit signed integer used as an exponent of
- two, where the resulting value is the precision of the system clock
- in seconds. This field is significant only in server messages, where
- the values range from -6 for mains-frequency clocks to -20 for
- microsecond clocks found in some workstations.
-
- Root Delay: This is a 32-bit signed fixed-point number indicating the
- total roundtrip delay to the primary reference source, in seconds
- with the fraction point between bits 15 and 16. Note that this
- variable can take on both positive and negative values, depending on
- the relative time and frequency offsets. This field is significant
- only in server messages, where the values range from negative values
- of a few milliseconds to positive values of several hundred
- milliseconds.
-
- Code External Reference Source
- ------------------------------------------------------------------
- LOCL uncalibrated local clock
- CESM calibrated Cesium clock
- RBDM calibrated Rubidium clock
- PPS calibrated quartz clock or other pulse-per-second
- source
- IRIG Inter-Range Instrumentation Group
- ACTS NIST telephone modem service
- USNO USNO telephone modem service
- PTB PTB (Germany) telephone modem service
- TDF Allouis (France) Radio 164 kHz
- DCF Mainflingen (Germany) Radio 77.5 kHz
- MSF Rugby (UK) Radio 60 kHz
- WWV Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz
- WWVB Boulder (US) Radio 60 kHz
- WWVH Kauai Hawaii (US) Radio 2.5, 5, 10, 15 MHz
- CHU Ottawa (Canada) Radio 3330, 7335, 14670 kHz
- LORC LORAN-C radionavigation system
- OMEG OMEGA radionavigation system
- GPS Global Positioning Service
-
- Figure 2. Reference Identifier Codes
-
-
-
-
-
-
-
-Mills Informational [Page 11]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- Root Dispersion: This is a 32-bit unsigned fixed-point number
- indicating the maximum error due to the clock frequency tolerance, in
- seconds with the fraction point between bits 15 and 16. This field
- is significant only in server messages, where the values range from
- zero to several hundred milliseconds.
-
- Reference Identifier: This is a 32-bit bitstring identifying the
- particular reference source. This field is significant only in
- server messages, where for stratum 0 (kiss-o'-death message) and 1
- (primary server), the value is a four-character ASCII string, left
- justified and zero padded to 32 bits. For IPv4 secondary servers,
- the value is the 32-bit IPv4 address of the synchronization source.
- For IPv6 and OSI secondary servers, the value is the first 32 bits of
- the MD5 hash of the IPv6 or NSAP address of the synchronization
- source.
-
- Primary (stratum 1) servers set this field to a code identifying the
- external reference source according to Figure 2. If the external
- reference is one of those listed, the associated code should be used.
- Codes for sources not listed can be contrived, as appropriate.
-
- In previous NTP and SNTP secondary servers and clients, this field
- was often used to walk-back the synchronization subnet to the root
- (primary server) for management purposes. In SNTPv4 with IPv6 or
- OSI, this feature is not available, because the addresses are
- longer than 32 bits, and only a hash is available. However, a
- walk-back can be accomplished using the NTP control message and
- the reference identifier field described in RFC 1305.
-
- Reference Timestamp: This field is the time the system clock was last
- set or corrected, in 64-bit timestamp format.
-
- Originate Timestamp: This is the time at which the request departed
- the client for the server, in 64-bit timestamp format.
-
- Receive Timestamp: This is the time at which the request arrived at
- the server or the reply arrived at the client, in 64-bit timestamp
- format.
-
- Transmit Timestamp: This is the time at which the request departed
- the client or the reply departed the server, in 64-bit timestamp
- format.
-
- Authenticator (optional): When the NTP authentication scheme is
- implemented, the Key Identifier and Message Digest fields contain the
- message authentication code (MAC) information defined in Appendix C
- of RFC 1305.
-
-
-
-
-Mills Informational [Page 12]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
-5. SNTP Client Operations
-
- An SNTP client can operate in unicast, broadcast, or manycast modes.
- In unicast mode, the client sends a request (NTP mode 3) to a
- designated unicast server and expects a reply (NTP mode 4) from that
- server. In broadcast client mode, it sends no request and waits for
- a broadcast (NTP mode 5) from one or more broadcast servers. In
- manycast mode, the client sends a request (NTP mode 3) to a
- designated broadcast address and expects a reply (NTP mode 4) from
- one or more manycast servers. The client uses the first reply
- received to establish the particular server for subsequent unicast
- operations. Later replies from this server (duplicates) or any other
- server are ignored. Other than the selection of address in the
- request, the operations of manycast and unicast clients are
- identical.
-
- Client requests are normally sent at intervals depending on the
- frequency tolerance of the client clock and the required accuracy.
- However, under no conditions should requests be sent at less than
- one minute intervals. Further discussion on this point is in
- Section 9.
-
- A unicast or manycast client initializes the NTP message header,
- sends the request to the server, and strips the time of day from the
- Transmit Timestamp field of the reply. For this purpose, all the NTP
- header fields shown above are set to 0, except the Mode, VN, and
- optional Transmit Timestamp fields.
-
- NTP and SNTP clients set the mode field to 3 (client) for unicast and
- manycast requests. They set the VN field to any version number that
- is supported by the server, selected by configuration or discovery,
- and that can interoperate with all previous version NTP and SNTP
- servers. Servers reply with the same version as the request, so the
- VN field of the request also specifies the VN field of the reply. A
- prudent SNTP client can specify the earliest acceptable version on
- the expectation that any server of that or a later version will
- respond. NTP Version 3 (RFC 1305) and Version 2 (RFC 1119) servers
- accept all previous versions, including Version 1 (RFC 1059). Note
- that Version 0 (RFC 959) is no longer supported by current and future
- NTP and SNTP servers.
-
- Although setting the Transmit Timestamp field in the request to the
- time of day according to the client clock in NTP timestamp format is
- not necessary in a conforming client implementation, it is highly
- recommended in unicast and manycast modes. This allows a simple
- calculation to determine the propagation delay between the server and
- client and to align the system clock generally within a few tens of
- milliseconds relative to the server. In addition, this provides a
-
-
-
-Mills Informational [Page 13]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- simple method for verifying that the server reply is in fact a
- legitimate response to the specific client request and thereby for
- avoiding replays. In broadcast mode, the client has no information
- to calculate the propagation delay or to determine the validity of
- the server, unless one of the NTP authentication schemes is used.
-
- To calculate the roundtrip delay d and system clock offset t relative
- to the server, the client sets the Transmit Timestamp field in the
- request to the time of day according to the client clock in NTP
- timestamp format. For this purpose, the clock need not be
- synchronized. The server copies this field to the Originate
- Timestamp in the reply and sets the Receive Timestamp and Transmit
- Timestamp fields to the time of day according to the server clock in
- NTP timestamp format.
-
- When the server reply is received, the client determines a
- Destination Timestamp variable as the time of arrival according to
- its clock in NTP timestamp format. The following table summarizes
- the four timestamps.
-
- Timestamp Name ID When Generated
- ------------------------------------------------------------
- Originate Timestamp T1 time request sent by client
- Receive Timestamp T2 time request received by server
- Transmit Timestamp T3 time reply sent by server
- Destination Timestamp T4 time reply received by client
-
- The roundtrip delay d and system clock offset t are defined as:
-
- d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2.
-
- Note that in general both delay and offset are signed quantities and
- can be less than zero; however, a delay less than zero is possible
- only in symmetric modes, which SNTP clients are forbidden to use.
- The following table summarizes the required SNTP client operations in
- unicast, manycast, and broadcast modes. The recommended error checks
- are shown in the Reply and Broadcast columns in the table. The
- message should be considered valid only if all the fields shown
- contain values in the respective ranges. Whether to believe the
- message if one or more of the fields marked "ignore" contain invalid
- values is at the discretion of the implementation.
-
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 14]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- Field Name Unicast/Manycast Broadcast
- Request Reply
- ---------------------------------------------------------------
- LI 0 0-3 0-3
-
- VN 1-4 copied from 1-4
- request
-
- Mode 3 4 5
-
- Stratum 0 0-15 0-15
-
- Poll 0 ignore ignore
-
- Precision 0 ignore ignore
-
- Root Delay 0 ignore ignore
-
- Root Dispersion 0 ignore ignore
-
- Reference Identifier 0 ignore ignore
-
- Reference Timestamp 0 ignore ignore
-
- Originate Timestamp 0 (see text) ignore
-
- Receive Timestamp 0 (see text) ignore
-
- Transmit Timestamp (see text) nonzero nonzero
-
- Authenticator optional optional optional
-
- Although not required in a conforming SNTP client implementation, it
- is wise to consider a suite of sanity checks designed to avoid
- various kinds of abuse that might happen as the result of server
- implementation errors or malicious attack. Following is a list of
- suggested checks.
-
- 1. When the IP source and destination addresses are available for
- the client request, they should match the interchanged addresses
- in the server reply.
-
- 2. When the UDP source and destination ports are available for the
- client request, they should match the interchanged ports in the
- server reply.
-
- 3. The Originate Timestamp in the server reply should match the
- Transmit Timestamp used in the client request.
-
-
-
-Mills Informational [Page 15]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- 4. The server reply should be discarded if any of the LI, Stratum,
- or Transmit Timestamp fields is 0 or the Mode field is not 4
- (unicast) or 5 (broadcast).
-
- 5. A truly paranoid client can check that the Root Delay and Root
- Dispersion fields are each greater than or equal to 0 and less
- than infinity, where infinity is currently a cozy number like one
- second. This check avoids using a server whose synchronization
- source has expired for a very long time.
-
-6. SNTP Server Operations
-
- A SNTP server operating with either an NTP or SNTP client of the same
- or previous versions retains no persistent state. Because an SNTP
- server ordinarily does not implement the full suite of grooming and
- mitigation algorithms intended to support redundant servers and
- diverse network paths, it should be operated only in conjunction with
- a source of external synchronization, such as a reliable radio clock
- or telephone modem. In this case it operates as a primary (stratum
- 1) server.
-
- A SNTP server can operate with any unicast, manycast, or broadcast
- address or any combination of these addresses. A unicast or manycast
- server receives a request (NTP mode 3), modifies certain fields in
- the NTP header, and sends a reply (NTP mode 4), possibly using the
- same message buffer as the request. A manycast server listens on the
- designated broadcast address, but uses its own unicast IP address in
- the source address field of the reply. Other than the selection of
- address in the reply, the operations of manycast and unicast servers
- are identical. Broadcast messages are normally sent at intervals
- from 64 s to 1024 s, depending on the expected frequency tolerance of
- the client clocks and the required accuracy.
-
- Unicast and manycast servers copy the VN and Poll fields of the
- request intact to the reply and set the Stratum field to 1.
-
- Note that SNTP servers normally operate as primary (stratum 1)
- servers. Although operating at higher strata (up to 15) while
- synchronizing to an external source such as a GPS receiver is not
- forbidden, this is strongly discouraged.
-
- If the Mode field of the request is 3 (client), the reply is set to 4
- (server). If this field is set to 1 (symmetric active), the reply is
- set to 2 (symmetric passive). This allows clients configured in
- either client (NTP mode 3) or symmetric active (NTP mode 1) to
- interoperate successfully, even if configured in possibly suboptimal
- ways. For any other value in the Mode field, the request is
-
-
-
-
-Mills Informational [Page 16]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- discarded. In broadcast (unsolicited) mode, the VN field is set to
- 4, the Mode field is set to 5 (broadcast), and the Poll field set to
- the nearest integer base-2 logarithm of the poll interval.
-
- Note that it is highly desirable that a broadcast server also
- supports unicast clients. This is so a potential broadcast client
- can calculate the propagation delay using a client/server exchange
- prior to switching to broadcast client (listen-only) mode. By
- design, a manycast server is also a unicast server. There does
- not seem to be a great advantage for a server to operate as both
- broadcast and manycast at the same time, although the protocol
- specification does not forbid it.
-
- A broadcast or manycast server does not send packets if not
- synchronized to a correctly operating reference source. It may or
- may not respond to a client request if it is not synchronized, but
- the preferred option is to respond because this allows reachability
- to be determined regardless of synchronization state. If the server
- has never synchronized to a reference source, the LI field is set to
- 3 (unsynchronized). Once synchronized to a reference source, the LI
- field is set to one of the other three values and remains at the last
- value set even if the reference source becomes unreachable or turns
- faulty.
-
- If the server is synchronized to a reference source, the Stratum
- field is set to 1, and the Reference Identifier field is set to the
- ASCII source identifier shown in Figure 2. If the server is not
- synchronized, the Stratum field is set to zero, and the Reference
- Identifier field is set to an ASCII error identifier described below.
-
- The Precision field is set to reflect the maximum reading error of
- the system clock. For all practical cases it is computed as the
- negative base-2 logarithm of the number of significant bits to the
- right of the decimal point in the NTP timestamp format. The Root
- Delay and Root Dispersion fields are set to 0 for a primary server.
-
- The timestamp fields in the server message are set as follows. If
- the server is unsynchronized or first coming up, all timestamp fields
- are set to zero, with one exception. If the message is a reply to a
- previously received client request, the Transmit Timestamp field of
- the request is copied unchanged to the Originate Timestamp field of
- the reply. It is important that this field be copied intact, as an
- NTP or SNTP client uses it to avoid bogus messages.
-
- If the server is synchronized, the Reference Timestamp is set to the
- time the last update was received from the reference source. The
- Originate Timestamp field is set as in the unsynchronized case above.
- The Transmit Timestamp field is set to the time of day when the
-
-
-
-Mills Informational [Page 17]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- message is sent. In broadcast messages the Receive Timestamp field
- is set to zero and copied from the Transmit Timestamp field in other
- messages. The following table summarizes these actions.
-
- Field Name Unicast/Manycast Broadcast
- Request Reply
- ----------------------------------------------------------------
- LI ignore as needed as needed
-
- VN 1-4 copied from 4
- request
-
- Mode 3 4 5
-
- Stratum ignore 1 1
-
- Poll ignore copied from log2 poll
- request interval
-
- Precision ignore -log2 server -log2 server
- significant significant
- bits bits
-
- Root Delay ignore 0 0
-
- Root Dispersion ignore 0 0
-
- Reference Identifier ignore source ident source ident
-
- Reference Timestamp ignore time of last time of last
- source update source update
-
- Originate Timestamp ignore copied from 0
- transmit
- timestamp
-
- Receive Timestamp ignore time of day 0
-
- Transmit Timestamp (see text) time of day time of day
-
- Authenticator optional optional optional
-
- There is some latitude on the part of most clients to forgive invalid
- timestamps, such as might occur when the server is first coming up or
- during periods when the reference source is inoperative. The most
- important indicator of an unhealthy server is the Stratum field, in
-
-
-
-
-
-Mills Informational [Page 18]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- which a value of 0 indicates an unsynchronized condition. When this
- value is displayed, clients should discard the server message,
- regardless of the contents of other fields.
-
-7. Configuration and Management
-
- Initial setup for SNTP servers and clients can be done using a web
- client, if available, or a serial port, if not. Some folks hoped
- that in-service management of NTP and SNTPv4 servers and clients
- could be performed using SNMP and a suitable MIB to be published, and
- this has happened in some commercial SNTP servers. But, the means
- that have been used in the last two decades and probably will be used
- in the next is the NTP control and monitoring protocol defined in RFC
- 1305. Ordinarily, SNTP servers and clients are expected to operate
- with little or no site-specific configuration, other than specifying
- the client IP address, subnet mask, and gateway.
-
- Unicast clients must be provided with one or more designated server
- names or IP addresses. If more than one server is provided, one can
- be used for active operation and one of the others for backup should
- the active one fail or show an error condition. It is not normally
- useful to use more than one server at a time, as with millions of
- SNTP-enabled devices expected in the near future, such use would
- represent unnecessary drain on network and server resources.
-
- Broadcast servers and manycast clients must be provided with the TTL
- and local broadcast or multicast group address. Unicast and manycast
- servers and broadcast clients may be configured with a list of
- address-mask pairs for access control, so that only those clients or
- servers known to be trusted will be accepted. Multicast servers and
- clients must implement the IGMP protocol and be provided with the
- local broadcast or multicast group address as well. The
- configuration data for cryptographic authentication is beyond the
- scope of this memo.
-
- There are several scenarios that provide automatic server discovery
- and selection for SNTP clients with no pre-specified server
- configuration. For instance, a role server with CNAME such as
- pool.ntp.org returns a randomized list of volunteer secondary server
- addresses, and the client can select one or more as candidates. For
- an IP subnet or LAN segment including an NTP or SNTP server, SNTP
- clients can be configured as broadcast clients. The same approach
- can be used with multicast servers and clients. In both cases,
- provision of an access control list is a good way to ensure that only
- trusted sources can be used to set the system clock.
-
-
-
-
-
-
-Mills Informational [Page 19]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- In another scenario suitable for an extended network with significant
- network propagation delays, clients can be configured for manycast
- addresses, both upon initial startup and after some period when the
- currently selected unicast source has not been heard. Following the
- defined protocol, the client binds to the server from which the first
- reply is received and continues operation in unicast mode.
-
-8. The Kiss-o'-Death Packet
-
- In the rambunctious Internet of today, it is imperative that some
- means be available to tell a client to stop making requests and to go
- somewhere else. A recent experience involved a large number of
- home/office routers all configured to use a particular university
- time server. Under some error conditions, a substantial fraction of
- these routers would send packets at intervals of one second. The
- resulting traffic spike was dramatic, and extreme measures were
- required to diagnose the problem and to bring it under control. The
- conclusion is that clients must respect the means available to
- targeted servers to stop them from sending packets.
-
- According to the NTP specification RFC 1305, if the Stratum field in
- the NTP header is 1, indicating a primary server, the Reference
- Identifier field contains an ASCII string identifying the particular
- reference clock type. However, in RFC 1305 nothing is said about the
- Reference Identifier field if the Stratum field is 0, which is called
- out as "unspecified". However, if the Stratum field is 0, the
- Reference Identifier field can be used to convey messages useful for
- status reporting and access control. In NTPv4 and SNTPv4, packets of
- this kind are called Kiss-o'-Death (KoD) packets, and the ASCII
- messages they convey are called kiss codes. The KoD packets got
- their name because an early use was to tell clients to stop sending
- packets that violate server access controls.
-
- In general, an SNTP client should stop sending to a particular server
- if that server returns a reply with a Stratum field of 0, regardless
- of kiss code, and an alternate server is available. If no alternate
- server is available, the client should retransmit using an
- exponential-backoff algorithm described in the next section.
-
- The kiss codes can provide useful information for an intelligent
- client. These codes are encoded in four-character ASCII strings left
- justified and zero filled. The strings are designed for character
- displays and log files. Usually, only a few of these codes can occur
- with SNTP clients, including DENY, RSTR, and RATE. Others can occur
- more rarely, including INIT and STEP, when the server is in some
- special temporary condition. Figure 3 shows a list of the kiss codes
- currently defined. These are for informational purposes only; the
- list might be modified or extended in the future.
-
-
-
-Mills Informational [Page 20]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- Code Meaning
- --------------------------------------------------------------
- ACST The association belongs to a anycast server
- AUTH Server authentication failed
- AUTO Autokey sequence failed
- BCST The association belongs to a broadcast server
- CRYP Cryptographic authentication or identification failed
- DENY Access denied by remote server
- DROP Lost peer in symmetric mode
- RSTR Access denied due to local policy
- INIT The association has not yet synchronized for the first
- time
- MCST The association belongs to a manycast server
- NKEY No key found. Either the key was never installed or
- is not trusted
- RATE Rate exceeded. The server has temporarily denied access
- because the client exceeded the rate threshold
- RMOT Somebody is tinkering with the association from a remote
- host running ntpdc. Not to worry unless some rascal has
- stolen your keys
- STEP A step change in system time has occurred, but the
- association has not yet resynchronized
-
- Figure 3. Kiss Codes
-
-9. On Being a Good Network Citizen
-
- SNTP and its big brother NTP have been in explosive growth over the
- last few years, mirroring the growth of the Internet. Just about
- every Internet appliance has some kind of NTP support, including
- Windows XP, Cisco routers, embedded controllers, and software systems
- of all kinds. This is the first edition of the SNTP RFC where it has
- become necessary to lay down rules of engagement in the form of
- design criteria for SNTP client implementations. This is necessary
- to educate software developers regarding the proper use of Internet
- time server resources as the Internet expands and demands on time
- servers increase, and to prevent the recurrence of the sort of
- problem mentioned above.
-
-10. Best Practices
-
- NTP and SNTP clients can consume considerable network and server
- resources if they are not good network citizens. There are now
- consumer Internet commodity devices numbering in the millions that
- are potential customers of public and private NTP and SNTP servers.
- Recent experience strongly suggests that device designers pay
- particular attention to minimizing resource impacts, especially if
- large numbers of these devices are deployed. The most important
-
-
-
-Mills Informational [Page 21]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- design consideration is the interval between client requests, called
- the poll interval. It is extremely important that the design use the
- maximum poll interval consistent with acceptable accuracy.
-
- 1. A client MUST NOT under any conditions use a poll interval less
- than 15 seconds.
-
- 2. A client SHOULD increase the poll interval using exponential
- backoff as performance permits and especially if the server does
- not respond within a reasonable time.
-
- 3. A client SHOULD use local servers whenever available to avoid
- unnecessary traffic on backbone networks.
-
- 4. A client MUST allow the operator to configure the primary and/or
- alternate server names or addresses in addition to or in place of
- a firmware default IP address.
-
- 5. If a firmware default server IP address is provided, it MUST be a
- server operated by the manufacturer or seller of the device or
- another server, but only with the operator's permission.
-
- 6. A client SHOULD use the Domain Name System (DNS) to resolve the
- server IP addresses, so the operator can do effective load
- balancing among a server clique and change IP address binding to
- canonical names.
-
- 7. A client SHOULD re-resolve the server IP address at periodic
- intervals, but not at intervals less than the time-to-live field
- in the DNS response.
-
- 8. A client SHOULD support the NTP access-refusal mechanism so that
- a server kiss-o'-death reply in response to a client request
- causes the client to cease sending requests to that server and to
- switch to an alternate, if available.
-
- The following algorithm can be used as a pattern for specific
- implementations. It uses the following variables:
-
- Timer: This is a counter that decrements at a fixed rate. When it
- reaches zero, a packet is sent, and the timer is initialized with the
- timeout for the next packet.
-
- Maximum timeout: This is the maximum timeout determined from the
- given oscillator frequency tolerance and the required accuracy.
-
-
-
-
-
-
-Mills Informational [Page 22]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- Server Name: This is the DNS name of the server. There may be more
- than one of them, to be selected by some algorithm not considered
- here.
-
- Server IP Address: This is the IPv4, IPv6, or OSI address of the
- server.
-
- If the firmware or documentation includes specific server names, the
- names should be those the manufacturer or seller operates as a
- customer convenience or those for which specific permission has been
- obtained from the operator. A DNS request for a generic server name,
- such as ntp.mytimeserver.com, should result in a random selection of
- server IP addresses available for that purpose. Each time a DNS
- request is received, a new randomized list is returned. The client
- ordinarily uses the first address on the list.
-
- When candidate SNTP or NTP servers are selected, it is imperative
- to respect the server operator's conditions of access. Lists of
- public servers and their conditions of access are available at
- www.ntp.org. A semi-automatic server discovery scheme using DNS
- is described at that site. Some ISPs operate public servers,
- although finding them via their help desks can be difficult.
-
- A well-behaved client operates as follows (note that steps 2-4
- constitute a synchronization loop):
-
- 1. Consider the specified frequency tolerance of the system clock
- oscillator. Define the required accuracy of the system clock,
- then calculate the maximum timeout. For instance, if the
- frequency tolerance is 200 parts per million (PPM) and the
- required accuracy is one minute, the maximum timeout is about 3.5
- days. Use the longest maximum timeout possible given the system
- constraints to minimize time server aggregate load, but never
- make it less than 15 minutes.
-
- 2. When the client is first coming up or after reset, randomize the
- timeout from one to five minutes. This is to minimize shock when
- 3000 PCs are rebooted at the same time power is restored after a
- blackout. Assume at this time that the IP address is unknown and
- that the system clock is unsynchronized. Otherwise, use the
- timeout value as calculated in previous loop steps. Note that it
- may be necessary to refrain from implementing the aforementioned
- random delay for some classes of International Computer Security
- Association (ICSA) certification.
-
-
-
-
-
-
-
-Mills Informational [Page 23]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- 3. When the timer reaches zero, if the IP address is not known, send
- a DNS query packet; otherwise, send an NTP request packet to that
- address. If no reply packet has been heard since the last
- timeout, double the timeout, but do not make it greater than the
- maximum timeout. If primary and secondary time servers have been
- configured, alternate queries between the primary and secondary
- servers when no successful response has been received.
-
- 4. If a DNS reply packet is received, save the IP address and
- continue at step 2. If a KoD packet is received, remove that
- time server from the list, activate the secondary time server,
- and continue at step 2. If a received packet fails the sanity
- checks, drop that packet and also continue at step 2. If a valid
- NTP packet is received, update the system clock, set the timeout
- to the maximum, and continue at step 2.
-
-11. Security Considerations
-
- Without cryptographic authentication, SNTPv4 service is vulnerable to
- disruption by misbehaving or hostile SNTP or NTP broadcast servers
- elsewhere in the Internet. It is strongly recommended that access
- controls and/or cryptographic authentication means be provided for
- additional security. This document includes protocol provisions for
- adding such security mechanisms, but it does not define the
- mechanisms themselves. A separate document [MIL03] in preparation
- will define a cryptographic security mechanism for SNTP.
-
-12. Acknowledgements
-
- Jeff Learman was helpful in developing the OSI model for this
- protocol. Ajit Thyagarajan provided valuable suggestions and
- corrections.
-
-13. Contributors
-
- D. Plonka
-
- J. Montgomery
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 24]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
-14. Informative References
-
- [BRA97] Bradner, S., "Key words for use in RFCs to Indicate
- Requirement Levels", BCP 14, RFC 2119, March 1997.
-
- [COL94] Colella, R., Callon, R., Gardner, E., and Y. Rekhter,
- "Guidelines for OSI NSAP Allocation in the Internet", RFC
- 1629, May 1994.
-
- [DEE89] Deering, S., "Host extensions for IP multicasting", STD 5,
- RFC 1112, August 1989.
-
- [DEE98] Deering, S. and R. Hinden, "Internet Protocol, Version 6
- (IPv6) Specification", RFC 2460, December 1998.
-
- [DOB91] Shue, C., Haggerty, W., and K. Dobbins, "OSI connectionless
- transport services on top of UDP: Version 1", RFC 1240, June
- 1991.
-
- [FUR94] Furniss, P., "Octet Sequences for Upper-Layer OSI to Support
- Basic Communications Applications", RFC 1698, October 1994.
-
- [ISO86] International Standards 8602 - Information Processing
- Systems - OSI: Connectionless Transport Protocol
- Specification. International Standards Organization,
- December 1986.
-
- [MIL92] Mills, D., "Network Time Protocol (Version 3) Specification,
- Implementation and Analysis", RFC 1305, March 1992.
-
- [MIL03] Mills, D., "The Autokey Security Architecture, Protocol and
- Algorithms", http://eecis.udel.edu/~mills/database/reports/
- stime/stime.pdf, August 2003.
-
- [PAR93] Partridge, C., Mendez, T., and W. Milliken, "Host Anycasting
- Service", RFC 1546, November 1993.
-
- [POS80] Postel, J., "User Datagram Protocol", STD 6, RFC 768, August
- 1980.
-
- [POS83] Postel, J. and K. Harrenstien, "Time Protocol", STD 26, RFC
- 868, May 1983.
-
- [SRI99] Srisuresh, P. and M. Holdrege, "IP Network Address
- Translator (NAT) Terminology and Considerations", RFC 2663,
- August 1999.
-
-
-
-
-
-Mills Informational [Page 25]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
- [SRI01] Srisuresh, P. and K. Egevang, "Traditional IP Network
- Address Translator (Traditional NAT)", RFC 3022, January
- 2001.
-
-Author's Address
-
- David L. Mills
- Electrical and Computer Engineering Department
- University of Delaware
- Newark, DE 19716
-
- Phone: (302) 831-8247
- EMail: mills@udel.edu
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills Informational [Page 26]
-\f
-RFC 4330 SNTPv4 for IPv4, IPv6 and OSI January 2006
-
-
-Full Copyright Statement
-
- Copyright (C) The Internet Society (2006).
-
- This document is subject to the rights, licenses and restrictions
- contained in BCP 78 and at www.rfc-editor.org/copyright.html, and
- except as set forth therein, the authors retain all their rights.
-
- This document and the information contained herein are provided on an
- "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
- OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
- ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
- INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
- INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
- WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
-
-Intellectual Property
-
- The IETF takes no position regarding the validity or scope of any
- Intellectual Property Rights or other rights that might be claimed to
- pertain to the implementation or use of the technology described in
- this document or the extent to which any license under such rights
- might or might not be available; nor does it represent that it has
- made any independent effort to identify any such rights. Information
- on the procedures with respect to rights in RFC documents can be
- found in BCP 78 and BCP 79.
-
- Copies of IPR disclosures made to the IETF Secretariat and any
- assurances of licenses to be made available, or the result of an
- attempt made to obtain a general license or permission for the use of
- such proprietary rights by implementers or users of this
- specification can be obtained from the IETF on-line IPR repository at
- http://www.ietf.org/ipr.
-
- The IETF invites any interested party to bring to its attention any
- copyrights, patents or patent applications, or other proprietary
- rights that may cover technology that may be required to implement
- this standard. Please address the information to the IETF at
- ietf-ipr@ietf.org.
-
-Acknowledgement
-
- Funding for the RFC Editor function is provided by the IETF
- Administrative Support Activity (IASA).
-
-
-
-
-
-
-
-Mills Informational [Page 27]
-\f
+# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
-AC_INIT([msntp])
+m4_include([../version.m4])
+AC_INIT([sntp], [VERSION_NUMBER])
-# Increment msntp_configure_cache_version by one for each change to
+# Increment sntp_configure_cache_version by one for each change to
# configure.ac or .m4 files which invalidates cached values from
# previous versions.
#
# the date YYYYMMDD optionally with -HHMM if there is more than one
# bump in a day.
-msntp_configure_cache_version=20090503
+sntp_configure_cache_version=20090503
# When the version of config.cache and configure do not
# match, NTP_CACHEVERSION will flush the cache.
-NTP_CACHEVERSION([msntp], [$msntp_configure_cache_version])
+NTP_CACHEVERSION([sntp], [$sntp_configure_cache_version])
-AM_INIT_AUTOMAKE([msntp],[1.6])
-AC_CONFIG_SRCDIR([header.h])
+AM_INIT_AUTOMAKE
AC_CANONICAL_HOST
-AM_CONFIG_HEADER(config.h)
+dnl the 'build' machine is where we run configure and compile
+dnl the 'host' machine is where the resulting stuff runs.
+AC_DEFINE_UNQUOTED([STR_SYSTEM], "$host", [canonical system (cpu-vendor-os) of where we should run])
+AC_CONFIG_HEADER([config.h])
+dnl AC_ARG_PROGRAM
+AC_PREREQ([2.53])
# Checks for programs.
AC_PROG_CC
-# So far, the only shared library we might use is libopts.
-# It's a small library - we might as well use a static version of it.
-AC_DISABLE_SHARED
+# AC_PROG_CC_STDC has two functions. It attempts to find a compiler
+# capable of C99, or failing that, for C89. CC is set afterward with
+# the selected invocation, such as "gcc --std=gnu99". Also, the
+# ac_cv_prog_cc_stdc variable is no if the compiler selected for CC
+# does not accept C89.
-m4_defun([_LT_AC_LANG_CXX_CONFIG], [:])
-m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
+AC_PROG_CC_STDC
-AC_PROG_LIBTOOL
+case "$ac_cv_prog_cc_stdc" in
+ no)
+ AC_MSG_WARN([ANSI C89/ISO C90 is the minimum to compile SNTP ]
+ [version 4.2.5 and higher.])
+esac
+
+case "$GCC" in
+ yes)
+ SAVED_CFLAGS_AC="$CFLAGS"
+ CFLAGS="$CFLAGS -Wstrict-overflow"
+ AC_CACHE_CHECK(
+ [if $CC can handle -Wstrict-overflow],
+ ac_cv_gcc_Wstrict_overflow,
+ [
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([], [])],
+ [ac_cv_gcc_Wstrict_overflow=yes],
+ [ac_cv_gcc_Wstrict_overflow=no]
+ )
+ ]
+ )
+ CFLAGS="$SAVED_CFLAGS_AC"
+ SAVED_CFLAGS_AC=
+
+ CFLAGS="$CFLAGS -Wall"
+ # CFLAGS="$CFLAGS -Wcast-align"
+ CFLAGS="$CFLAGS -Wcast-qual"
+ # CFLAGS="$CFLAGS -Wconversion"
+ # CFLAGS="$CFLAGS -Werror"
+ # CFLAGS="$CFLAGS -Wextra"
+ # CFLAGS="$CFLAGS -Wfloat-equal"
+ CFLAGS="$CFLAGS -Wmissing-prototypes"
+ CFLAGS="$CFLAGS -Wpointer-arith"
+ CFLAGS="$CFLAGS -Wshadow"
+ CFLAGS="$CFLAGS -Wstrict-prototypes"
+ # CFLAGS="$CFLAGS -Wtraditional"
+ # CFLAGS="$CFLAGS -Wwrite-strings"
+ case "$ac_cv_gcc_Wstrict_overflow" in
+ yes)
+ CFLAGS="$CFLAGS -Wstrict-overflow"
+ esac
+esac
+
+# HMS: These need to be moved to AM_CPPFLAGS and/or AM_CFLAGS
+case "$host" in
+ *-*-solaris*)
+ # see "man standards".
+ # -D_XOPEN_SOURCE=500 is probably OK for c89 and before
+ # -D_XOPEN_SOURCE=600 seems OK for c99
+ #CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500 -D__EXTENSIONS__"
+ CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
+ libxnet=-lxnet
+ ;;
+esac
+
+AC_DISABLE_SHARED
# NTP has (so far) been relying on leading-edge autogen.
# Therefore, by default:
set) ;;
*) enable_libopts_install=no ;;
esac
-LIBOPTS_CHECK
+LIBOPTS_CHECK([libopts])
-AC_MSG_CHECKING([[if $CC can handle #warning]])
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[#warning foo]])],[ac_cv_cpp_warning=yes],[ac_cv_cpp_warning=no])
-AC_MSG_RESULT([$ac_cv_cpp_warning])
+m4_defun([_LT_AC_LANG_CXX_CONFIG], [:])
+m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
-case "$ac_cv_cpp_warning" in
- no)
- AC_DEFINE([NO_OPTION_NAME_WARNINGS], [1], [Should we avoid #warning on option name collisions?])
- AC_MSG_RESULT([[Enabling NO_OPTION_NAME_WARNINGS as #warning does not work]])
- ;;
-esac
+AC_PROG_LIBTOOL
+
+# Checks for libraries.
+
+AC_CHECK_FUNC([gethostent], ,
+ [AC_SEARCH_LIBS([gethostent], [nsl], , , [$libxnet -lsocket])])
+AC_CHECK_FUNC([openlog], ,
+ [AC_SEARCH_LIBS([openlog], [gen], ,
+ [AC_SEARCH_LIBS([openlog], [syslog], , , [$libxnet -lsocket])])])
+
+AC_CHECK_FUNC([setsockopt], ,
+ [AC_SEARCH_LIBS([setsockopt], [socket xnet])])
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([netdb.h netinet/in.h stdlib.h string.h strings.h syslog.h])
+AC_CHECK_HEADERS([sys/socket.h sys/time.h])
+AC_HEADER_TIME
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_HEADER_STDBOOL
+AC_C_CONST
+AC_TYPE_SIZE_T
AC_C_INLINE
AC_SUBST(HAVE_INLINE)
esac
-# HMS: These need to be moved to AM_CPPFLAGS and/or AM_CFLAGS
-case "$host" in
- *-*-solaris*)
- # see "man standards".
- # -D_XOPEN_SOURCE=500 is probably OK for c89 and before
- # -D_XOPEN_SOURCE=600 seems OK for c99
- #CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500 -D__EXTENSIONS__"
- CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
- libxnet=-lxnet
+AC_C_CHAR_UNSIGNED dnl CROSS_COMPILE?
+AC_CHECK_SIZEOF([signed char])
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([long])
+
+AC_CHECK_TYPES([s_char])
+case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
+ *yes)
+ # We have a typedef for s_char. Might as well believe it...
+ ;;
+ no0no)
+ # We have signed chars, can't say 'signed char', no s_char typedef.
+ AC_DEFINE([NEED_S_CHAR_TYPEDEF], 1, [Do we need an s_char typedef?])
+ ;;
+ no1no)
+ # We have signed chars, can say 'signed char', no s_char typedef.
+ AC_DEFINE([NEED_S_CHAR_TYPEDEF])
+ ;;
+ yes0no)
+ # We have unsigned chars, can't say 'signed char', no s_char typedef.
+ AC_MSG_ERROR([No way to specify a signed character!])
+ ;;
+ yes1no)
+ # We have unsigned chars, can say 'signed char', no s_char typedef.
+ AC_DEFINE([NEED_S_CHAR_TYPEDEF])
;;
esac
+AC_TYPE_UID_T
+AC_MSG_CHECKING([type of socklen arg for getsockname()])
+AC_CACHE_VAL(ac_cv_func_getsockname_arg2,dnl
+[AC_CACHE_VAL(ac_cv_func_getsockname_socklen_type,dnl
+ [for ac_cv_func_getsockname_arg2 in 'struct sockaddr *' 'void *'; do
+ for ac_cv_func_getsockname_socklen_type in 'socklen_t' 'size_t' 'unsigned int' 'int'; do
+ AC_TRY_COMPILE(dnl
+[#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+extern getsockname (int, $ac_cv_func_getsockname_arg2, $ac_cv_func_getsockname_socklen_type *);],,dnl
+ [ac_not_found=no ; break 2], ac_not_found=yes)
+ done
+ done
+ ])dnl AC_CACHE_VAL
+])dnl AC_CACHE_VAL
+if test "$ac_not_found" = yes; then
+ ac_cv_func_getsockname_socklen_type='socklen_t'
+fi
+AC_MSG_RESULT([$ac_cv_func_getsockname_socklen_type])
+AC_DEFINE_UNQUOTED([GETSOCKNAME_SOCKLEN_TYPE],
+ $ac_cv_func_getsockname_socklen_type,
+ [What is getsockname()'s socklen type?])
-# Checks for libraries.
-
-# Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h limits.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h])
-
-# Checks for typedefs, structures, and compiler characteristics.
-AC_C_CONST
-AC_TYPE_SIZE_T
-AC_HEADER_TIME
-AC_STRUCT_TM
+AC_CACHE_CHECK(for struct sockaddr_storage, ac_cv_struct_sockaddr_storage,
+[AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+],[
+struct sockaddr_storage n;],
+ ac_cv_struct_sockaddr_storage=yes,
+ ac_cv_struct_sockaddr_storage=no)
+])
+if test $ac_cv_struct_sockaddr_storage = yes; then
+ AC_DEFINE([HAVE_STRUCT_SOCKADDR_STORAGE], 1, [Does a system header define struct sockaddr_storage?])
+fi
AC_CACHE_CHECK([for ss_family field in struct sockaddr_storage],
ac_cv_have_ss_family_in_struct_ss, [
[ ac_cv_have_ss_family_in_struct_ss="no" ],
)
])
-case "$ac_cv_have_ss_family_in_struct_ss" in
- yes)
- AC_DEFINE(HAVE_SS_FAMILY_IN_SS, 1, [Does struct sockaddr_storage have ss_family?])
- ;;
-esac
+if test "x$ac_cv_have_ss_family_in_struct_ss" = "xyes" ; then
+ AC_DEFINE(HAVE_SS_FAMILY_IN_SS, 1, [Does struct sockaddr_storage have ss_family?])
+else
+ # Hack around a problem...
+ # HMS: This is $host because we need the -D if we are building *for* it.
+ # HMS: 061029: Now that we separate the ss_* checks this is causing
+ # a problem - disable it until we get to the bottom of it.
+ case "$host" in
+ XXX*-*-hpux11.11) CPPFLAGS="$CPPFLAGS -D_NETINET_IN6_H"
+ ;;
+ esac
+fi
AC_CACHE_CHECK([for __ss_family field in struct sockaddr_storage],
ac_cv_have___ss_family_in_struct_ss, [
[ ac_cv_have___ss_family_in_struct_ss="no" ]
)
])
-case "$ac_cv_have___ss_family_in_struct_ss" in
+if test "x$ac_cv_have___ss_family_in_struct_ss" = "xyes" ; then
+ AC_DEFINE(HAVE___SS_FAMILY_IN_SS, 1, [Does struct sockaddr_storage have __ss_family?])
+fi
+
+AH_VERBATIM([X_HAVE_SS_FAMILY_IN_SS],
+[/* Handle ss_family */
+#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
+# define ss_family __ss_family
+#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */])
+
+
+AC_ARG_ENABLE([ipv6], [AC_HELP_STRING([--enable-ipv6], [s use IPv6?])])
+
+case "$enable_ipv6" in
+ yes|''|autodetect)
+ case "$host" in
+ powerpc-ibm-aix4*) ;;
+ *)
+ AC_DEFINE([WANT_IPV6], ,[ISC: Want IPv6?])
+ ;;
+ esac
+ ;;
+ no)
+ ;;
+esac
+
+
+AC_CACHE_CHECK(
+ [for IPv6 structures],
+ ac_cv_isc_found_ipv6,
+ [
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ ],
+ [
+ struct sockaddr_in6 sin6;
+ ]
+ )
+ ],
+ [ac_cv_isc_found_ipv6=yes],
+ [ac_cv_isc_found_ipv6=no]
+ )
+ ]
+)
+
+#
+# See whether IPv6 support is provided via a Kame add-on.
+# This is done before other IPv6 linking tests so LIBS is properly set.
+#
+AC_MSG_CHECKING([for Kame IPv6 support])
+AC_ARG_WITH(kame,
+ [AC_HELP_STRING([--with-kame], [- =/usr/local/v6])],
+ use_kame="$withval", use_kame="no")
+
+case "$use_kame" in
+ no)
+ ;;
yes)
- AC_DEFINE(HAVE___SS_FAMILY_IN_SS, 1, [Does struct sockaddr_storage have __ss_family?])
+ kame_path=/usr/local/v6
+ ;;
+ *)
+ kame_path="$use_kame"
;;
esac
-case "$ac_cv_have_ss_family_in_struct_ss$ac_cv_have___ss_family_in_struct_ss" in
- noyes)
- AC_DEFINE_UNQUOTED([ss_family], [__ss_family], [normalize ss_family access])
- AC_DEFINE_UNQUOTED([ss_len], [__ss_len], [normalize ss_len access])
+case "$use_kame" in
+ no)
+ AC_MSG_RESULT(no)
+ ;;
+ *)
+ if test -f $kame_path/lib/libinet6.a; then
+ AC_MSG_RESULT($kame_path/lib/libinet6.a)
+ LIBS="-L$kame_path/lib -linet6 $LIBS"
+ else
+ AC_MSG_ERROR([$kame_path/lib/libinet6.a not found.
+
+Please choose the proper path with the following command:
+
+ configure --with-kame=PATH
+])
+ fi
;;
esac
-# Checks for library functions.
-AC_CHECK_FUNC([gethostent], ,
- [AC_SEARCH_LIBS([gethostent], [nsl], , , [$libxnet -lsocket])])
-#AC_FUNC_MEMCMP dnl HMS: we don't have a memcmp.c to use here, so why bother?
-AC_FUNC_SETVBUF_REVERSED
-AC_TYPE_SIGNAL
-AC_CHECK_FUNCS([alarm])
-AC_CHECK_FUNCS([gettimeofday inet_ntoa memset])
-AC_CHECK_FUNCS([socket], , AC_SEARCH_LIBS([socket], [socket]))
-AC_CHECK_FUNCS([sqrt], , AC_SEARCH_LIBS([sqrt], [m]))
-AC_CHECK_FUNCS([strrchr])
+#
+# Whether netinet6/in6.h is needed has to be defined in isc/platform.h.
+# Including it on Kame-using platforms is very bad, though, because
+# Kame uses #error against direct inclusion. So include it on only
+# the platform that is otherwise broken without it -- BSD/OS 4.0 through 4.1.
+# This is done before the in6_pktinfo check because that's what
+# netinet6/in6.h is needed for.
+#
+case "$host" in
+ *-bsdi4.[[01]]*)
+ AC_DEFINE(ISC_PLATFORM_NEEDNETINET6IN6H, 1, [Do we need netinet6/in6.h?])
+ # does anything use LWRES_PLATFORM_NEEDNETINET6IN6H? Can't it use above?
+ AC_DEFINE(LWRES_PLATFORM_NEEDNETINET6IN6H, 1, [Do we need netinet6/in6.h?])
+ isc_netinet6in6_hack="#include <netinet6/in6.h>"
+ ;;
+ *)
+ isc_netinet6in6_hack=""
+esac
+#
+# This is similar to the netinet6/in6.h issue.
+#
case "$host" in
- *-*-hpux10.*) # at least for hppa2.0-hp-hpux10.20
- case "$GCC" in
+ *-sco-sysv*uw*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
+ AC_DEFINE(ISC_PLATFORM_FIXIN6ISADDR, 1,[Do we need to fix in6isaddr?])
+ isc_netinetin6_hack="#include <netinet/in6.h>"
+ ;;
+ *)
+ isc_netinetin6_hack=""
+esac
+
+
+case "$ac_cv_isc_found_ipv6" in
+ yes)
+ AC_DEFINE(ISC_PLATFORM_HAVEIPV6, ,[have IPv6?])
+
+ AC_CACHE_CHECK(
+ [for in6_pktinfo],
+ ac_cv_have_in6_pktinfo,
+ [
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ $isc_netinetin6_hack
+ $isc_netinet6in6_hack
+ ],
+ [
+ struct in6_pktinfo xyzzy;
+ ]
+ )
+ ],
+ [ac_cv_have_in6_pktinfo=yes],
+ [ac_cv_have_in6_pktinfo=no]
+ )
+ ]
+ )
+
+ case "$ac_cv_have_in6_pktinfo" in
yes)
- ;;
- *) CFLAGS="$CFLAGS -Wp,-H18816"
- ;;
+ AC_DEFINE(ISC_PLATFORM_HAVEIN6PKTINFO, , [have struct in6_pktinfo?])
esac
- ;;
- *-*-linux*)
- CFLAGS="$CFLAGS -DADJTIME_MISSING"
- ;;
- *-*-sunos*)
- CFLAGS="$CFLAGS -DNONBLOCK_BROKEN"
- ;;
+
+
+ # HMS: Use HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID instead?
+ AC_CACHE_CHECK(
+ [for sockaddr_in6.sin6_scope_id],
+ ac_cv_have_sin6_scope_id,
+ [
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ $isc_netinetin6_hack
+ $isc_netinet6in6_hack
+ ],
+ [
+ struct sockaddr_in6 xyzzy;
+ xyzzy.sin6_scope_id = 0;
+ ]
+ )
+ ],
+ [ac_cv_have_sin6_scope_id=yes],
+ [ac_cv_have_sin6_scope_id=no]
+ )
+ ]
+ )
+
+ case "$ac_cv_have_sin6_scope_id" in
+ yes)
+ AC_DEFINE(ISC_PLATFORM_HAVESCOPEID, , [have sin6_scope_id?])
+ esac
+esac
+
+
+# We need this check run even without ac_cv_isc_found_ipv6=yes
+
+AC_CACHE_CHECK(
+ [for in6addr_any],
+ ac_cv_have_in6addr_any,
+ [
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ $isc_netinetin6_hack
+ $isc_netinet6in6_hack
+ ],
+ [
+ struct in6_addr in6;
+ in6 = in6addr_any;
+ ]
+ )
+ ],
+ [ac_cv_have_in6addr_any=yes],
+ [ac_cv_have_in6addr_any=no]
+ )
+ ]
+)
+
+case "$ac_cv_have_in6addr_any" in
+ no)
+ AC_DEFINE(ISC_PLATFORM_NEEDIN6ADDRANY, , [missing in6addr_any?])
+esac
+
+
+AC_CACHE_CHECK(
+ [for struct if_laddrconf],
+ ac_cv_isc_struct_if_laddrconf,
+ [
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [
+ #include <sys/types.h>
+ #include <net/if6.h>
+ ],
+ [
+ struct if_laddrconf a;
+ ]
+ )
+ ],
+ [ac_cv_isc_struct_if_laddrconf=yes],
+ [ac_cv_isc_struct_if_laddrconf=no]
+ )
+ ]
+)
+
+case "$ac_cv_isc_struct_if_laddrconf" in
+ yes)
+ AC_DEFINE(ISC_PLATFORM_HAVEIF_LADDRCONF, , [have struct if_laddrconf?])
esac
+AC_CACHE_CHECK(
+ [for struct if_laddrreq],
+ ac_cv_isc_struct_if_laddrreq,
+ [
+ AC_COMPILE_IFELSE(
+ [
+ AC_LANG_PROGRAM(
+ [
+ #include <sys/types.h>
+ #include <net/if6.h>
+ ],
+ [
+ struct if_laddrreq a;
+ ]
+ )
+ ],
+ [ac_cv_isc_struct_if_laddrreq=yes],
+ [ac_cv_isc_struct_if_laddrreq=no]
+ )
+ ]
+)
+
+case "$ac_cv_isc_struct_if_laddrreq" in
+ yes)
+ AC_DEFINE(ISC_PLATFORM_HAVEIF_LADDRREQ, , [have struct if_laddrreq?])
+esac
+
+
+###
+
+# Hacks
+AC_DEFINE(HAVE_NO_NICE, 1, [sntp does not care about 'nice'])
+AC_DEFINE(HAVE_TERMIOS, 1, [sntp does not care about TTY stuff])
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([atexit memset socket])
+
AC_MSG_CHECKING(for bin subdirectory)
AC_ARG_WITH(binsubdir,
- AC_HELP_STRING([--with-binsubdir], [bin ={bin,sbin}]),
+ [AC_HELP_STRING([--with-binsubdir], [bin ={bin,sbin}])],
use_binsubdir="$withval", use_binsubdir="bin")
case "$use_binsubdir" in
+++ /dev/null
-
-
-
-
-
-INTERNET DRAFT D. Mills
-Network Working Group University of Delaware
-Obsoletes: 2030, 1769 D. Plonka
-Category: Informational University of Wisconsin
- J. Montgomery
- Netgear
- September 2003
-
- Simple Network Time Protocol (SNTP) Version 4
- for IPv4, IPv6 and OSI
- <draft-mills-sntp-v4-00.txt>
-
-Status of this memo
-
- This document is an Internet-Draft and is in full conformance with
- all provisions of Section 10 of RFC2026. Internet-Drafts are working
- documents of the Internet Engineering Task Force (IETF), its areas,
- and its working groups. Note that other groups may also distribute
- working documents as Internet-Drafts.
-
- Internet-Drafts are draft documents valid for a maximum of six months
- and may be updated, replaced, or obsolete by other documents at any
- time. It is inappropriate to use Internet-Drafts as reference
- material or to cite them other than as "work in progress."
-
- The list of current Internet-Drafts can be accessed at
- http://www.ietf.org/ietf/1id-abstracts.txt
-
- The list of Internet-Draft Shadow Directories can be accessed at
- http://www.ietf.org/shadow.html.
-
-Abstract
-
- This memorandum describes the Simple Network Time Protocol (SNTP)
- Version 4, which is a subset of the Network Time Protocol (NTP) used
- to synchronize computer clocks in the Internet. SNTP can be used when
- the ultimate performance of the full NTP implementation described in
- RFC-1305 is not needed or justified. SNTP Version 4 clarifies
- certain design features of NTP which allow operation in a simple,
- stateless remote-procedure call (RPC) mode with accuracy and
- reliability expectations similar to the UDP/TIME protocol described
- in RFC-868.
-
- The only significant protocol change in SNTP Version 4 is a modified
- header interpretation to accommodate Internet Protocol Version 6
- (IPv6) (RFC-1883) and OSI (RFC-1629) addressing. However, SNTP
- Version 4 includes an anycast mode and a public-key based
- authentication scheme designed specifically for broadcast and anycast
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 1]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- applications. The authentication scheme extension is described in
- another RFC. Until a definitive specification is published, these
- extensions should be considered provisional. In addition, this memo
- introduces the kiss-o'-death message, which can be used by servers to
- suppress client requests as circumstances require.
-
- This memorandum obsoletes RFC-1769, which describes SNTP Version 3,
- and RFC-2030, which describes SNTP Version 4.
-
-Table of Contents
-
- 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 2
- 2. Operating Modes and Addressing . . . . . . . . . . . . . . . . 5
- 3. NTP Timestamp Format . . . . . . . . . . . . . . . . . . . . . 6
- 4. Message Format . . . . . . . . . . . . . . . . . . . . . . . . 8
- 5. SNTP Client Operations . . . . . . . . . . . . . . . . . . . . 12
- 6. SNTP Server Operations . . . . . . . . . . . . . . . . . . . . 16
- 7. Configuration and Management . . . . . . . . . . . . . . . . . 19
- 8. The Kiss-o'-Death Packet . . . . . . . . . . . . . . . . . . . 20
- 9. On Being a Good Network Citizen. . . . . . . . . . . . . . . . 21
- 10. Best Practices . . . . . . . . . . . . . . . . . . . . . . . . 22
- 11. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 24
- 12. Informative References . . . . . . . . . . . . . . . . . . . . 24
- 13. Security Considerations. . . . . . . . . . . . . . . . . . . . 26
- 14. Author's Address . . . . . . . . . . . . . . . . . . . . . . . 26
- 15. Full Copyright Statement . . . . . . . . . . . . . . . . . . . 27
-
-1. Introduction
-
- The Network Time Protocol Version 3 (NTPv3) specified in RFC-1305
- [MIL92] is widely used to synchronize computer clocks in the global
- Internet. It provides comprehensive mechanisms to access national
- time and frequency dissemination services, organize the NTP subnet of
- servers and clients and adjust the system clock in each participant.
- In most places of the Internet of today, NTP provides accuracies of
- 1-50 ms, depending on the characteristics of the synchronization
- source and network paths.
-
- RFC-1305 specifies the NTP protocol machine in terms of events,
- states, transition functions and actions and, in addition, engineered
- algorithms to improve the timekeeping quality and mitigate among
- several synchronization sources, some of which may be faulty. To
- achieve accuracies in the low milliseconds over paths spanning major
- portions of the Internet, these intricate algorithms, or their
- functional equivalents, are necessary. In many applications,
- accuracies in the order of significant fractions of a second are
- acceptable. In simple home router applications, accuracies of up to
- a minute may suffice. In such cases, simpler protocols such as the
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 2]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- Time Protocol specified in RFC-868 [POS83], have been used for this
- purpose. These protocols involve an RPC exchange where the client
- requests the time of day and the server returns it in seconds past a
- known reference epoch.
-
- NTP is designed for use by clients and servers with a wide range of
- capabilities and over a wide range of network jitter and clock
- frequency wander characteristics. Many users of NTP in the Internet
- of today use a software distribution available from www.ntp.org. The
- distribution, which includes the full suite of NTP options,
- mitigation algorithms and security schemes, is a relatively complex,
- real-time application. While the software has been ported to a wide
- variety of hardware platforms ranging from personal computers to
- supercomputers, its sheer size and complexity is not appropriate for
- many applications. Accordingly, it is useful to explore alternative
- strategies using simpler software appropriate for less stringent
- accuracy expectations.
-
- This memo describes the Simple Network Time Protocol Version 4
- (SNTPv4), which is a simplified access paradigm for servers and
- clients using NTP and SNTP, current and previous versions. The
- access paradigm is identical to the UDP/TIME Protocol and, in fact,
- it should be easily possible to adapt a UDP/TIME client
- implementation, say for a personal computer, to operate using SNTP.
- Moreover, SNTP is also designed to operate in a dedicated server
- configuration including an integrated radio clock. With careful
- design and control of the various latencies in the system, which is
- practical in a dedicated design, it is possible to deliver time
- accurate to the order of microseconds.
-
- When operating with current and previous versions of NTP and SNTP,
- SNTPv4 requires no changes to the protocol or implementations now
- running or likely to be implemented specifically for future NTP or
- SNTP versions. The NTP and SNTP packet formats are the same and the
- arithmetic operations to calculate the client time, clock offset and
- roundtrip delay are the same. To a NTP or SNTP server, NTP and SNTP
- clients are indistinguishable; to a NTP or SNTP client, NTP and SNTP
- servers are indistinguishable. Like NTP servers operating in non-
- symmetric modes, SNTP servers are stateless and can support large
- numbers of clients; however, unlike most NTP clients, SNTP clients
- normally operate with only a single server at a time.
-
- The full degree of reliability ordinarily expected of NTP servers is
- possible only using redundant sources, diverse paths and the crafted
- algorithms of a full NTP implementation. It is strongly recommended
- that SNTP clients be used only at the extremities of the
- synchronization subnet. SNTP clients should operate only at the
- leaves (highest stratum) of the subnet and in configurations where no
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 3]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- NTP or SNTP client is dependent on another SNTP client for
- synchronization. SNTP servers should operate only at the root
- (stratum 1) of the subnet and then only in configurations where no
- other source of synchronization other than a reliable radio clock or
- telephone modem is available.
-
- An important provision in this memo is the interpretation of certain
- NTP header fields which provide for IPv6 and OSI addressing. The
- only significant difference between the NTP and SNTPv4 header formats
- is the four-octet Reference Identifier field, which is used primarily
- to detect and avoid synchronization loops. In all NTP and SNTP
- versions providing IPv4 addressing, primary servers use a four-
- character ASCII reference clock identifier in this field, while
- secondary servers use the 32-bit IPv4 address of the synchronization
- source. In SNTP version 4 providing IPv6 and OSI addressing, primary
- servers use the same clock identifier, but secondary servers use the
- first 32 bits of the MD5 hash of the IPv6 or NSAP address of the
- synchronization source. A further use of this field is when the
- server sends a kiss-o'-death message documented later in this memo.
-
- NTP Version 4 (NTPv4) now in deployment, but not yet the subject
- of a standards document, uses the same Reference Identifier field
- as SNTPv4.
-
- In the case of OSI, the Connectionless Transport Service (CLTS) is
- used as in [ISO86]. Each SNTP packet is transmitted as the TS-
- Userdata parameter of a T-UNITDATA Request primitive. Alternately,
- the header can be encapsulated in a TPDU which itself is transported
- using UDP, as described in RFC-1240 [DOB91]. It is not advised that
- NTP be operated at the upper layers of the OSI stack, such as might
- be inferred from RFC-1698 [FUR94], as this could seriously degrade
- accuracy. With the header formats defined in this memo, it is in
- principle possible to interwork between servers and clients of one
- protocol family and another, although the practical difficulties may
- make this inadvisable.
-
- In the following, indented paragraphs such as this one contain
- information not required by the formal protocol specification, but
- considered good practice in protocol implementations.
-
- This memo is organized as follows. Section 2 describes how the
- protocol works, the various modes and how IP addresses and UDP ports
- are used. Section 3 describes the NTP timestamp format and Section 4
- the NTP message format. Section 5 summarizes SNTP client operations
- and Section 6 summarizes SNTP server operations. Section 7
- summarizes operation and management issues. Section 8 describes the
- kiss-o'-death message newly minted with functions similar to the ICMP
- Source Quench and ICMP Destination Unreachable messages. Section 9
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 4]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- summarizes design issues important for good network citizenry and
- presents an example algorithm designed to give good reliability while
- minimizing network and server resource demands.
-
-2. Operating Modes and Addressing
-
- Unless excepted in context, reference to broadcast address means IPv4
- broadcast address, IPv4 multicast group address or IPv6 site-local
- scope address. Further information on the broadcast/multicast model
- is in RFC-1112 [DEE89]. Details of address format, scoping rules,
- etc., are beyond the scope of this memo. SNTPv4 can operate with
- either unicast (point to point), broadcast (point to multipoint) or
- anycast (multipoint to point) addressing modes. A unicast client
- sends a request to a designated server at its unicast address and
- expects a reply from which it can determine the time and, optionally,
- the roundtrip delay and clock offset relative to the server. A
- broadcast server periodically sends an unsolicited message to a
- designated broadcast address. A broadcast client listens on this
- address and ordinarily sends no requests.
-
- Anycast is designed for use with a set of cooperating servers whose
- addresses are not known beforehand. The anycast client sends an
- ordinary NTP client request to a designated broadcast address. One
- or more anycast servers listen on that address. Upon receiving a
- request, an anycast server sends an ordinary NTP server reply to the
- client. The client then binds to the server from which the first
- such message was received and continues operation with that unicast
- addresses. Subsequent replies from other anycast servers are
- ignored.
-
- Broadcast servers should respond to client unicast requests, as
- well as send unsolicited broadcast messages. Broadcast clients
- may send unicast requests in order to measure the network
- propagation delay between the server and client and then continue
- operation in listen-only mode. However, broadcast servers may
- choose not to respond to unicast requests, so unicast clients
- should be prepared to abandon the measurement and assume a default
- value for the delay.
-
- The client and server addresses are assigned following the usual
- IPv4, IPv6 or OSI conventions. For NTP multicast, the IANA has
- reserved the IPv4 group address 224.0.1.1 and the IPv6 group address
- ending :101, with prefix determined by scoping rules. The NTP
- broadcast address for OSI has yet to be determined. Notwithstanding
- the IANA reserved addresses, other multicast addresses can be used
- which do not conflict with others assigned in scope. In the case of
- IPv4 multicast or IPv6 broadcast addresses, the client must implement
- the Internet Group Management Protocol (IGMP) as described in RFC-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 5]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- 3376 [CAIN02], in order that the local router joins the multicast
- group and relays messages to the IPv4 or IPv6 multicast group. The
- scoping, routing and group membership procedures are determined by
- considerations beyond the scope of this memo.
-
- It is important to adjust the time-to-live (TTL) field in the IP
- header of multicast messages to a reasonable value in order to
- limit the network resources used by this (and any other) multicast
- service. Only multicast clients in scope will receive multicast
- server messages. Only cooperating anycast servers in scope will
- reply to a client request. The engineering principles which
- determine the proper values to be used are beyond the scope of
- this memo.
-
- In the case of SNTP as specified herein, there is a very real
- vulnerability that SNTP broadcast clients can be disrupted by
- misbehaving or hostile SNTP or NTP broadcast servers elsewhere in
- the Internet. It is strongly recommended that access controls
- and/or cryptographic authentication means be provided for
- additional security in such cases.
-
- While not integral to the SNTP specification, it is intended that
- IP broadcast addresses will be used primarily in IP subnets and
- LAN segments including a fully functional NTP server with a number
- of dependent SNTP broadcast clients on the same subnet, while IP
- multicast group addresses will be used only in cases where the TTL
- is engineered specifically for each service domain.
-
-3. NTP Timestamp Format
-
- SNTP uses the standard NTP timestamp format described in RFC-1305 and
- previous versions of that document. In conformance with standard
- Internet practice, NTP data are specified as integer or fixed-point
- quantities, with bits numbered in big-endian fashion from 0 starting
- at the left or most significant end. Unless specified otherwise, all
- quantities are unsigned and may occupy the full field width with an
- implied 0 preceding bit 0.
-
- Since NTP timestamps are cherished data and, in fact, represent the
- main product of the protocol, a special timestamp format has been
- established. NTP timestamps are represented as a 64-bit unsigned
- fixed-point number, in seconds relative to 0h on 1 January 1900. The
- integer part is in the first 32 bits and the fraction part in the
- last 32 bits. In the fraction part, the non-significant low order
- bits are not specified and ordinarily set to 0.
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 6]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- It is advisable to fill the non-significant low order bits of the
- timestamp with a random, unbiased bitstring, both to avoid
- systematic roundoff errors and as a means of loop detection and
- replay detection (see below). It is important that the bitstring
- be unpredictable by a intruder. One way of doing this is to
- generate a random 128-bit bitstring at startup. After that, Each
- time the system clock is read the string consisting of the
- timestamp and bitstring is hashed with the MD5 algorithm, then the
- non-significant bits of the timestamp are copied from the result.
-
- The NTP format allows convenient multiple-precision arithmetic and
- conversion to UDP/TIME message (seconds), but does complicate the
- conversion to ICMP Timestamp message (milliseconds) and Unix time
- values (seconds and microseconds or seconds and nanoseconds). The
- maximum number that can be represented is 4,294,967,295 seconds with
- a precision of about 232 picoseconds, which should be adequate for
- even the most exotic requirements.
-
- 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Seconds |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Seconds Fraction (0-padded) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- Note that, since some time in 1968 (second 2,147,483,648) the most
- significant bit (bit 0 of the integer part) has been set and that the
- 64-bit field will overflow some time in 2036 (second 4,294,967,296).
- There will exist a 232-picosecond interval, henceforth ignored, every
- 136 years when the 64-bit field will be 0, which by convention is
- interpreted as an invalid or unavailable timestamp.
-
- As the NTP timestamp format has been in use for over 20 years, it
- remains a possibility that it will be in use 33 years from now
- when the seconds field overflows. As it is probably inappropriate
- to archive NTP timestamps before bit 0 was set in 1968, a
- convenient way to extend the useful life of NTP timestamps is the
- following convention: If bit 0 is set, the UTC time is in the
- range 1968-2036 and UTC time is reckoned from 0h 0m 0s UTC on 1
- January 1900. If bit 0 is not set, the time is in the range
- 2036-2104 and UTC time is reckoned from 6h 28m 16s UTC on 7
- February 2036. Note that when calculating the correspondence,
- 2000 is a leap year and leap seconds are not included in the
- reckoning.
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 7]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
-4. Message Format
-
- Both NTP and SNTP are clients of the User Datagram Protocol (UDP)
- specified in RFC-768 [POS80], which itself is a client of the
- Internet Protocol (IP) specified in RFC-791) [DAR81]. The structure
- of the IP and UDP headers is described in the cited specification
- documents and will not be detailed further here. The UDP port number
- assigned by the IANA to NTP is 123. The SNTP client should use this
- value in the UDP Destination Port field for client request messages.
- The Source Port field of these messages can be any nonzero value
- chosen for identification or multiplexing purposes. The server
- interchanges these fields for the corresponding reply messages.
-
- This differs from the RFC-2030 specifications which required both
- the source and destination ports to be 123. The intent of this
- change is to allow the identification of particular client
- implementations (which are now allowed to use unreserved port
- numbers, including ones of their choosing) and also for
- compatibility with Network Address Port Translation (NAPT)
- described in RFC-2663 [SRI99] and RFC-3022 [SRI02].
-
- Figure 1 is a description of the NTP and SNTP message format, which
- follows the IP and UDP headers in the message. This format is
- identical to the NTP message format described in RFC-1305, with the
- exception of the Reference Identifier field described below. For
- SNTP client messages most of these fields are zero or initialized
- with pre-specified data. For completeness, the function of each
- field is briefly summarized below.
-
- Leap Indicator (LI): This is a two-bit code warning of an impending
- leap second to be inserted/deleted in the last minute of the current
- day. This field is significant only in server messages, where the
- values are defined as follows:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 8]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |LI | VN |Mode | Stratum | Poll | Precision |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Root Delay |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Root Dispersion |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Reference Identifier |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Reference Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Originate Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Receive Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | Transmit Timestamp (64) |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Key Identifier (optional) (32) |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | |
- | |
- | Message Digest (optional) (128) |
- | |
- | |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- Figure 1. NTP Packet Header
-
- LI Meaning
- ---------------------------------------------
- 0 no warning
- 1 last minute has 61 seconds
- 2 last minute has 59 seconds)
- 3 alarm condition (clock not synchronized)
-
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 9]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- On startup, servers set this field to 3 (clock not synchronized) and
- set this field to some other value when synchronized to the primary
- reference clock. Once set to other than 3, the field is never set to
- that value again, even if all synchronization sources become
- unreachable or defective.
-
- Version Number (VN): This is a three-bit integer indicating the
- NTP/SNTP version number, currently 4. If necessary to distinguish
- between IPv4, IPv6 and OSI, the encapsulating context must be
- inspected.
-
- Mode: This is a three-bit number indicating the protocol mode. The
- values are defined as follows:
-
- Mode Meaning
- ------------------------------------
- 0 reserved
- 1 symmetric active
- 2 symmetric passive
- 3 client
- 4 server
- 5 broadcast
- 6 reserved for NTP control message
- 7 reserved for private use
-
- In unicast and anycast modes, the client sets this field to 3
- (client) in the request and the server sets it to 4 (server) in the
- reply. In broadcast mode, the server sets this field to 5
- (broadcast). The other modes are not used by SNTP servers and
- clients.
-
- Stratum: This is a eight-bit unsigned integer indicating the stratum.
- This field is significant only in SNTP server messages, where the
- values are defined as follows:
-
- Stratum Meaning
- ----------------------------------------------
- 0 kiss-o'-death message (see below)
- 1 primary reference (e.g., synchronized by radio clock)
- 2-15 secondary reference (synchronized by NTP or SNTP)
- 16-255 reserved
-
- Poll Interval: This is an eight-bit unsigned integer used as an
- exponent of two, where the resulting value is the maximum interval
- between successive messages in seconds. This field is significant
- only in SNTP server messages, where the values range from 4 (16 s) to
- 17 (131,072 s - about 36 h).
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 10]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- Precision: This is an eight-bit signed integer used as an exponent of
- two, where the resulting value is the precision of the system clock
- in seconds. This field is significant only in server messages, where
- the values range from -6 for mains-frequency clocks to -20 for
- microsecond clocks found in some workstations.
-
- Root Delay: This is a 32-bit signed fixed-point number indicating the
- total roundtrip delay to the primary reference source, in seconds
- with fraction point between bits 15 and 16. Note that this variable
- can take on both positive and negative values, depending on the
- relative time and frequency offsets. This field is significant only
- in server messages, where the values range from negative values of a
- few milliseconds to positive values of several hundred milliseconds.
-
- Root Dispersion: This is a 32-bit unsigned fixed-point number
- indicating the nominal error relative to the primary reference
- source, in seconds with fraction point between bits 15 and 16. This
- field is significant only in server messages, where the values range
- from zero to several hundred milliseconds.
-
- Code External Reference Source
- ------------------------------------------------------------------
- LOCL uncalibrated local clock
- CESM calibrated Cesium clock
- RBDM calibrated Rubidium clock
- PPS calibrated quartz clock or other pulse-per-second
- source
- IRIG Inter-Range Instrumentation Group
- ACTS NIST telephone modem service
- USNO USNO telephone modem service
- PTB PTB (Germany) telephone modem service
- TDF Allouis (France) Radio 164 kHz
- DCF Mainflingen (Germany) Radio 77.5 kHz
- MSF Rugby (UK) Radio 60 kHz
- WWV Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz
- WWVB Boulder (US) Radio 60 kHz
- WWVH Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz
- CHU Ottawa (Canada) Radio 3330, 7335, 14670 kHz
- LORC LORAN-C radionavigation system
- OMEG OMEGA radionavigation system
- GPS Global Positioning Service
-
- Figure 2. Reference Identifier Codes
-
- Reference Identifier: This is a 32-bit bitstring identifying the
- particular reference source. This field is significant only in
- server messages, where for stratum 0 (kiss-o'-death message) and 1
- (primary server), the value is a four-character ASCII string, left
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 11]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- justified and zero padded to 32 bits. For IPv4 secondary servers,
- the value is the 32-bit IPv4 address of the synchronization source.
- For IPv6 and OSI secondary servers, the value is the first 32 bits of
- the MD5 hash of the IPv6 or NSAP address of the synchronization
- source.
-
- Primary (stratum 1) servers set this field to a code identifying the
- external reference source according to Figure 2. If the external
- reference is one of those listed, the associated code should be used.
- Codes for sources not listed can be contrived as appropriate.
-
- In previous NTP and SNTP secondary servers and clients this field
- was often used to walk-back the synchronization subnet to the root
- (primary server) for management purposes. In SNTPv4 with IPv6 or
- OSI, this feature is not available, since the addresses are longer
- than 32 bits and only a hash is available. However, a walk-back
- can be accomplished using the NTP control message and the
- reference identifier field described in RFC-1305.
-
- Reference Timestamp: This field is significant only in server
- messages, where the value is the time at which the system clock was
- last set or corrected, in 64-bit timestamp format.
-
- Originate Timestamp: This is the time at which the request departed
- the client for the server, in 64-bit timestamp format.
-
- Receive Timestamp: This is the time at which the request arrived at
- the server or the reply arrived at the client, in 64-bit timestamp
- format.
-
- Transmit Timestamp: This is the time at which the request departed
- the client or the reply departed the server, in 64-bit timestamp
- format.
-
- Authenticator (optional): When the NTP authentication scheme is
- implemented, the Key Identifier and Message Digest fields contain the
- message authentication code (MAC) information defined in Appendix C
- of RFC-1305.
-
-5. SNTP Client Operations
-
- A SNTP client can operate in unicast, broadcast or anycast modes. In
- unicast mode the client sends a request (NTP mode 3) to a designated
- unicast server and expects a reply (NTP mode 4) from that server. In
- broadcast client mode it sends no request and waits for a broadcast
- (NTP mode 5) from one or more broadcast servers. In anycast mode,
- the client sends a request (NTP mode 3) to a designated broadcast
- address and expects a reply (NTP mode 4) from one or more anycast
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 12]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- servers. The client uses the first reply received to establish the
- particular server for subsequent unicast operations. Later replies
- from this server (duplicates) or any other server are ignored. Other
- than the selection of address in the request, the operations of
- anycast and unicast clients are identical.
-
- Client requests are normally sent at intervals depending on the
- frequency tolerance of the client clock and the required accuracy.
- However, under no conditions should requests be sent at less than
- one minute intervals. Further discussion on this point is in
- Section 9.
-
- A unicast or anycast client initializes the NTP message header, sends
- the request to the server and strips the time of day from the
- Transmit Timestamp field of the reply. For this purpose, all of the
- NTP header fields shown above are set to 0, except the Mode, VN and
- optional Transmit Timestamp fields.
-
- NTP and SNTP clients set the mode field to 3 (client) for unicast and
- anycast requests. They set the VN field to any version number
- supported by the server selected by configuration or discovery and
- can interoperate with all previous version NTP and SNTP servers.
- Servers reply with the same version as the request, so the VN field
- of the request also specifies the VN field of the reply. A prudent
- SNTP client can specify the earliest acceptable version on the
- expectation that any server of that or later version will respond.
- NTP Version 3 (RFC-1305) and Version 2 (RFC-1119) servers accept all
- previous versions, including Version 1 (RFC-1059). Note that Version
- 0 (RFC-959) is no longer supported by current and future NTP and SNTP
- servers.
-
- While not necessary in a conforming client implementation, in unicast
- and anycast modes it highly recommended that the Transmit Timestamp
- field in the request is set to the time of day according to the
- client clock in NTP timestamp format. This allows a simple
- calculation to determine the propagation delay between the server and
- client and to align the system clock generally within a few tens of
- milliseconds relative to the server. In addition, this provides a
- simple method to verify that the server reply is in fact a legitimate
- response to the specific client request and avoid replays. In
- broadcast mode, the client has no information to calculate the
- propagation delay or determine the validity of the server, unless one
- of the NTP authentication schemes is used.
-
- To calculate the roundtrip delay d and system clock offset t relative
- to the server, the client sets the Transmit Timestamp field in the
- request to the time of day according to the client clock in NTP
- timestamp format. For this purpose the clock need not be
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 13]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- synchronized. The server copies this field to the originate timestamp
- in the reply and sets the Receive Timestamp and Transmit Timestamp
- fields to the time of day according to the server clock in NTP
- timestamp format.
-
- When the server reply is received, the client determines a
- Destination Timestamp variable as the time of arrival according to
- its clock in NTP timestamp format. The following table summarizes
- the four timestamps.
-
- Timestamp Name ID When Generated
- ------------------------------------------------------------
- Originate Timestamp T1 time request sent by client
- Receive Timestamp T2 time request received by server
- Transmit Timestamp T3 time reply sent by server
- Destination Timestamp T4 time reply received by client
-
- The roundtrip delay d and local clock offset t are defined as
-
- d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2.
-
- Note that in general both delay and offset are signed quantities and
- can in general be less than zero; however, a delay less than zero is
- possible only in symmetric modes, which SNTP clients are forbidden to
- use. The following table summarizes the required SNTP client
- operations in unicast, anycast and broadcast modes. The recommended
- error checks are shown in the Reply and Broadcast columns in the
- table. The message should be considered valid only if all the fields
- shown contain values in the respective ranges. Whether to believe
- the message if one or more of the fields marked "ignore" contain
- invalid values is at the discretion of the implementation.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 14]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- Field Name Unicast/Anycast Broadcast
- Request Reply
- ---------------------------------------------------------------
- LI 0 0-3 0-3
-
- VN 1-4 copied from 1-4
- request
-
- Mode 1 or 3 2 or 4 5
-
- Stratum 0 0-15 0-15
-
- Poll 0 ignore ignore
-
- Precision 0 ignore ignore
-
- Root Delay 0 ignore ignore
-
- Root Dispersion 0 ignore ignore
-
- Reference Identifier 0 ignore ignore
-
- Reference Timestamp 0 ignore ignore
-
- Originate Timestamp 0 (see text) ignore
-
- Receive Timestamp 0 (see text) ignore
-
- Transmit Timestamp (see text) nonzero nonzero
-
- Authenticator optional optional optional
-
- While not required in a conforming SNTP client implementation, it is
- wise to consider a suite of sanity checks designed to avoid various
- kinds of abuse that might happen as the result of server
- implementation errors or malicious attack. Following is a list of
- suggested checks.
-
- 1. When the IP source and destination addresses are available for the
- client request, they should match the interchanged addresses in
- the server reply.
-
- 2. When the UDP source and destination ports are available for the
- client request, they should match the interchanged ports in the
- server reply.
-
- 3. The Originate Timestamp in the server reply should match the
- Transmit Timestamp used in the client request.
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 15]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- 4. The server reply should be discarded if any of the LI, Stratum, or
- Transmit Timestamp fields are 0 or the Mode field is not 4
- (unicast) or 5 (broadcast).
-
- 5. A truly paranoid client can check the Root Delay and Root
- Dispersion fields are each greater than or equal to 0 and less
- than infinity, where infinity is currently a cozy number like 16
- seconds. This check avoids using a server whose synchronization
- source has expired for a very long time.
-
-6. SNTP Server Operations
-
- A SNTP server operating with either a NTP or SNTP client of the same
- or previous versions retains no persistent state. Since a SNTP
- server ordinarily does not implement the full suite of grooming and
- mitigation algorithms intended to support redundant servers and
- diverse network paths, a SNTP server should be operated only in
- conjunction with a source of external synchronization, such as a
- reliable radio clock or telephone modem. In this case it operates as
- a primary (stratum 1) server.
-
- A SNTP server can operate with any unicast, anycast or broadcast
- address or any combination of these addresses. A unicast or anycast
- server receives a request (NTP mode 3), modifies certain fields in
- the NTP header, and sends a reply (NTP mode 4), possibly using the
- same message buffer as the request. A anycast server listens on the
- designated broadcast address, but uses its own unicast IP address in
- the source address field of the reply. Other than the selection of
- address in the reply, the operations of anycast and unicast servers
- are identical. Broadcast messages are normally sent at poll
- intervals from 64 s to 1024 s, depending on the expected frequency
- tolerance of the client clocks and the required accuracy.
-
- Unicast and anycast servers copy the VN and Poll fields of the
- request intact to the reply and set the Stratum field to 1.
-
- Note that SNTP servers normally operate as primary (stratum 1)
- servers. While operating at higher strata (up to 15) and at the
- same time synchronizing to an external source such as a GPS
- receiver is not forbidden, this is strongly discouraged.
-
- If the Mode field of the request is 3 (client), the reply is set to 4
- (server). If this field is set to 1 (symmetric active), the reply is
- set to 2 (symmetric passive). This allows clients configured in
- either client (NTP mode 3) or symmetric active (NTP mode 1) to
- interoperate successfully, even if configured in possibly suboptimal
- ways. For any other value in the Mode field, the request is
- discarded. In broadcast (unsolicited) mode, the VN field is set to
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 16]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- 4, the Mode field is set to 5 (broadcast), and the Poll field set to
- the nearest integer base-2 logarithm of the poll interval.
-
- Note that it is highly desirable that a broadcast server also
- supports unicast clients. This is so a potential broadcast client
- can calculate the propagation delay using a client/server exchange
- prior to switching to broadcast client (listen-only) mode. A
- anycast server by design also is a unicast server. There does not
- seem to be a great advantage for a server to operate as both
- broadcast and anycast at the same time, although the protocol
- specification does not forbid it.
-
- A broadcast or anycast server may or may not respond if not
- synchronized to a correctly operating reference source, but the
- preferred option is to respond, since this allows reachability to be
- determined regardless of synchronization state. If the server has
- never synchronized to a reference source, the LI field is set to 3
- (unsynchronized). Once synchronized to a reference source, the LI
- field is set to one of the other three values and remains at the last
- value set even if the reference source becomes unreachable or turns
- faulty.
-
- If synchronized to a reference source the Stratum field is set to 1
- and the Reference Identifier field is set to the ASCII source
- identifier shown in Figure 2. If not synchronized, the Stratum field
- is set to zero and the Reference Identifier field set to an ASCII
- error identifier described below. In broadcast mode, the server
- sends broadcasts only if synchronized to a correctly operating
- reference source.
-
- The Precision field is set to reflect the maximum reading error of
- the system clock. For all practical cases it is computed as the
- negative base-2 logarithm of the number of significant bits to the
- right of the decimal point in the NTP timestamp format. The Root
- Delay and Root Dispersion fields are set to 0 for a primary server;
- optionally, the Root Dispersion field can be set to a value
- corresponding to the maximum expected error of the radio clock
- itself.
-
- The timestamp fields in the server message are set as follows. If
- the server is unsynchronized or first coming up, all timestamp fields
- are set to zero with one exception. If the message is a reply to a
- previously received client request, the Transmit Timestamp field of
- the request is copied unchanged to the Originate Timestamp field of
- the reply. It is important that this field be copied intact, as an
- NTP or SNTP client uses it to avoid bogus messages.
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 17]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- If the server is synchronized, the Reference Timestamp is set to the
- time the last update was received from the reference source. The
- Originate Timestamp field is set as in the unsynchronized case above.
- The Transmit Timestamp field are set to the time of day when the
- message is sent. In broadcast messages the Receive Timestamp field
- is set to zero and copied from the Transmit Timestamp field in other
- messages. The following table summarizes these actions.
-
- Field Name Unicast/Anycast Broadcast
- Request Reply
- ----------------------------------------------------------------
- LI ignore as needed as needed
-
- VN 1-4 copied from 4
- request
-
- Mode 1 or 3 2 or 4 5
-
- Stratum ignore 1 1
-
- Poll ignore copied from log2 poll
- request interval
-
- Precision ignore -log2 server -log2 server
- significant significant
- bits bits
-
- Root Delay ignore 0 0
-
- Root Dispersion ignore 0 0
-
- Reference Identifier ignore source ident source ident
-
- Reference Timestamp ignore time of last time of last
- source update source update
-
- Originate Timestamp ignore copied from 0
- transmit
- timestamp
-
- Receive Timestamp ignore time of day 0
-
- Transmit Timestamp (see text) time of day time of day
-
- Authenticator optional optional optional
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 18]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- There is some latitude on the part of most clients to forgive invalid
- timestamps, such as might occur when first coming up or during
- periods when the reference source is inoperative. The most important
- indicator of an unhealthy server is the Stratum field, in which a
- value of 0 indicates an unsynchronized condition. When this value is
- displayed, clients should discard the server message, regardless of
- the contents of other fields.
-
-7. Configuration and Management
-
- Initial setup for SNTP servers and clients can be done using a web
- client, if available, or a serial port if not. Some folks hoped that
- in-service management of NTP and SNTPv4 servers and clients be
- performed using SNMP and a suitable MIB to be published, and this has
- happened in some commercial SNTP servers. But, the means used in the
- last decade and probably in the next is the NTP control and
- monitoring protocol defined in RFC-1305. Ordinarily, SNTP servers
- and clients are expected to operate with little or no site-specific
- configuration, other than specifying the client IP address, subnet
- mask, gateway.
-
- Unicast clients must be provided with one or more designated server
- names or IP addresses. If more than one server is provided, one can
- be used for active operation and one of the others for backup should
- the active one fail or show an error condition. It is not normally
- useful to use more than one server at a time, as with millions of
- SNTP-enabled devices expected in the near future, such use would
- represent unnecessary drain on network and server resources.
-
- Broadcast servers and anycast clients must be provided with the TTL
- and local broadcast or multicast group address. Unicast and anycast
- servers and broadcast clients may be configured with a list of
- address-mask pairs for access control, so that only those clients or
- servers known to be trusted will be accepted. Multicast servers and
- clients must implement the IGMP protocol and be provided with the
- local broadcast or multicast group address as well. The
- configuration data for cryptographic authentication is beyond the
- scope of this memo.
-
- There are several scenarios which provide automatic server discovery
- and selection for SNTP clients with no pre-specified server
- configuration. For instance a role server with CNAME such as
- pool.ntp.org returns a randomized list of volunteer secondary server
- addresses and the client can select one or more as candidates. For
- an IP subnet or LAN segment including a NTP or SNTP server, SNTP
- clients can be configured as broadcast clients. The same approach
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 19]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- can be used with multicast servers and clients. In both cases,
- provision of an access control list is a good way to insure only
- trusted sources can be used to set the system clock.
-
- In another scenario suitable for an extended network with significant
- network propagation delays, clients can be configured for anycast
- addresses, both upon initial startup and after some period when the
- currently selected unicast source has not been heard. Following the
- defined protocol, the client binds to the server from which the first
- reply is received and continues operation in unicast mode.
-
-8. The Kiss-o'-Death Packet
-
- In the rambunctious Internet of today, it is imperative that some
- means be available to tell a client to stop making requests and go
- somewhere else. A recent experience involved a large number of
- home/office routers all configured to use a particular university
- time server. Under some error conditions a substantial fraction of
- these routers would send packets at intervals of one second. The
- resulting traffic spike was dramatic, and extreme measures were
- required to diagnose the problem and bring it under control. The
- conclusion is that clients must respect the means available to
- targeted servers to stop them from sending packets.
-
- According to the NTP specification RFC-1305, if the Stratum field in
- the NTP header is 1, indicating a primary server, the Reference
- Identifier field contains an ASCII string identifying the particular
- reference clock type. However, in RFC-1305 nothing is said about the
- Reference Identifier field if the Stratum field is 0, which is called
- out as "unspecified". However, if the Stratum field is 0, the
- Reference Identifier field can be used to convey messages useful for
- status reporting and access control. In NTPv4 and SNTPv4, packets of
- this kind are called Kiss-o'-Death (KoD) packets and the ASCII
- messages they convey are called kiss codes. The KoD packets got
- their name because an early use was to tell clients to stop sending
- packets that violate server access controls.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 20]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- Code Meaning
- --------------------------------------------------------------
- ACST The association belongs to a anycast server
- AUTH Server authentication failed
- AUTO Autokey sequence failed
- BCST The association belongs to a broadcast server
- CRYP Cryptographic authentication or identification failed
- DENY Access denied by remote server
- DROP Lost peer in symmetric mode
- RSTR Access denied due to local policy
- INIT The association has not yet synchronized for the first
- time
- MCST The association belongs to a manycast server
- NKEY No key found. Either the key was never installed or
- is not trusted
- RATE Rate exceeded. The server has temporarily denied access
- because the client exceeded the rate threshold
- RMOT Somebody is tinkering with the association from a remote
- host running ntpdc. Not to worry unless some rascal has
- stolen your keys
- STEP A step change in system time has occurred, but the
- association has not yet resynchronized
-
- Figure 3. Kiss Codes
-
- In general, a SNTP client should stop sending to a particular server
- if that server returns a reply with a Stratum field of 0, regardless
- of kiss code, and an alternate server is available. If no alternate
- server is available, the client should retransmit using an
- exponential-backoff algorithm described in the next section.
-
- The kiss codes can provide useful information for an intelligent
- client. These codes are encoded in four-character ASCII strings left
- justified and zero filled. The strings are designed for character
- displays and log files. Usually, only a few of these codes can occur
- with SNTP clients, including DENY, RSTR and RATE. Others can occur
- more rarely, including INIT and STEP, when the server is in some
- special temporary condition. Figure 3 shows a list of the kiss codes
- currently defined.
-
-9. On Being a Good Network Citizen
-
- SNTP and its big brother NTP have been in explosive growth over the
- last few years, mirroring the growth of the Internet. Just about
- every Internet appliance has some kind of NTP support, including
- Windows XP, Cisco routers, embedded controllers and software systems
- of all kinds. This is the first edition of the SNTP RFC where it has
- become necessary to lay down rules of engagement in the form of
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 21]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- design criteria for SNTP client implementations. This is necessary
- to educate software developers regarding the proper use of Internet
- time server resources as the Internet expands and demands on time
- servers increase, and to prevent the recurrence of the sort of
- problem mentioned above.
-
-10. Best Practices
-
- NTP and SNTP clients can consume considerable network and server
- resources if not good network citizens. There are now consumer
- Internet commodity devices numbering in the millions that are
- potential customers of public and private NTP and SNTP servers.
- Recent experience strongly suggests that device designers pay
- particular attention to minimizing resource impacts, especially if
- large numbers of these devices are deployed. The most important
- design consideration is the interval between client requests, called
- the poll interval. It is extremely important that the design use the
- maximum poll interval consistent with acceptable accuracy.
-
- 1. A client MUST NOT under any conditions use a poll interval less
- than one minute.
-
- 2. A client SHOULD increase the poll interval using exponential
- backoff as performance permits and especially if the server does
- not respond within a reasonable time.
-
- 3. A client SHOULD use local servers whenever available to avoid
- unnecessary traffic on backbone networks.
-
- 4. A client MUST allow the operator to configure the primary and/or
- alternate server names or addresses in addition to or in place of
- a firmware default IP address.
-
- 5. If a firmware default server IP address is provided, it MUST be a
- server operated by the manufacturer or seller of the device or
- another server, but only with the operator's permission.
-
- 6. A client SHOULD use the Domain Name System (DNS) to resolve the
- server IP addresses, so the operator can do effective load
- balancing among a server clique and change IP address binding to
- canonical names.
-
- 7. A client SHOULD re-resolve the server IP address on a periodic
- intervals, but not less than the time-to-live field in the DNS
- response.
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 22]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- 8. A client SHOULD support the NTP access-refusal mechanism, so that
- a server kiss-o'-death reply in response to a client request
- causes the client to cease sending requests to that server and to
- switch to an alternate, if available.
-
- The following algorithm can be used as a pattern for specific
- implementations. It uses the following variables:
-
- Timer: This is a counter that decrements at a fixed rate. When it
- reaches zero, a packet is sent and the timer initialized with the
- timeout for the next packet.
-
- Maximum timeout: This is the maximum timeout determined from the
- given oscillator frequency tolerance and the required accuracy.
-
- Server Name: This is the DNS name of the server. There may be more
- than one of them to be selected by some algorithm not considered
- here.
-
- Server IP Address: This is the IPv4, IPv6 or OSI address of the
- server.
-
- If the firmware or documentation includes specific server names, the
- names should be those the manufacturer or seller operates as a
- customer convenience or those for which specific permission has been
- obtained from the operator. A DNS request for a generic server name
- such as ntp.mytimeserver.com results should result in a random
- selection of server IP addresses available for that purpose. Each
- time a DNS request is received, a new randomized list is returned.
- The client ordinarily uses the first address on the list.
-
- When selecting candidate SNTP or NTP servers, it is imperative to
- respect the server operator's conditions of access. Lists of
- public servers and their conditions of access are available at
- www.ntp.org. A semi-automatic server discovery scheme using DNS
- is described at that site. Some ISPs operate public servers,
- although finding them via their helpdesks can be difficult.
-
- A well behaved client operates as follows (note that steps 2 - 4
- comprise a synchronization loop):
-
- 1. Consider the specified frequency tolerance of the system clock
- oscillator. Define the required accuracy of the system clock,
- then calculate the maximum timeout. For instance, if the
- frequency tolerance is 200 parts-per-million (PPM) and the
- required accuracy is one minute, the maximum timeout is about 3.5
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 23]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- days. Use the longest maximum timeout possible given the system
- constraints to minimize time server aggregate load, but never less
- than 15 minutes.
-
- 2. When first coming up or after reset, randomize the timeout from
- one to five minutes. This is to minimize shock when 3000 PCs are
- rebooted at the same time power is restored after a blackout.
- Assume at this time the IP address is unknown and the system clock
- is unsynchronized. Otherwise use the timeout value as calculated
- in previous loop steps. Note that it may be necessary to refrain
- from implementing the aforementioned random delay for some classes
- of ICSA certification.
-
- 3. When the timer reaches zero, if the IP address is not known, send
- a DNS query packet; otherwise send a NTP request packet to that
- address. If no reply packet has been heard since the last
- timeout, double the timeout, but not greater than the maximum
- timeout. If primary and secondary time servers have been
- configured, alternate queries between the primary and secondary
- servers when no successful response has been received.
-
- 4. If a DNS reply packet is received, save the IP address and
- continue in step 2. If a KoD packet is received remove that time
- server from the list, activate the secondary time server and
- continue in step 2. If a received packet fails the sanity checks,
- drop that packet and also continue in step 2. If a valid NTP
- packet is received, update the system clock, set the timeout to
- the maximum, and continue to step 2.
-
-11. Acknowledgements
-
- Jeff Learman was helpful in developing the OSI model for this
- protocol. Ajit Thyagarajan provided valuable suggestions and
- corrections.
-
-12. Informative References
-
- [CAIN02] Cain, B., Deering, S., Kouvalas, I., Fenner, B. and A.
- Thyagarajan, "Internet Group Management Protocol, Version
- 3", RFC 3376, Cereva Networks, October 2002.
-
- [COL94] Colella, R., Callon, R., Gardner, E. and Y. Rekhter,
- "Guidelines for OSI NSAP Allocation in the Internet", RFC
- 1629, May 1994.
-
- [DAR81] Postel, J., "Internet Protocol", STD 5, RFC 791, September
- 1981.
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 24]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
- [DEE89] Deering, S., "Host extensions for IP multicasting", STD 5,
- RFC 1112, August 1989.
-
- [DEE96] Deering, S. and R. Hinden, "Internet Protocol, Version 6
- (IPv6) Specification", RFC 1883, January 1996.
-
- [DOB91] Dobbins, K, Haggerty, W. and C. Shue, "OSI connectionless
- transport services on top of UDP - Version: 1", RFC 1240,
- June 1991.
-
- [EAS95] Eastlake, D., 3rd., and C. Kaufman, "Domain Name System
- Security Extensions", Work in Progress.
-
- [FUR94] Furniss, P., "Octet Sequences for Upper-Layer OSI to Support
- Basic Communications Applications", RFC 1698, October 1994.
-
- [HIN96] Hinden, R. and S. Deering, "IP Version 6 Addressing
- Architecture", RFC 1884, January 1996.
-
- [HIN03] Hinden, R. and S. Deering, "Internet Protocol Version 6
- (IPv6) Addressing Architecture", RFC 3513, April 2003.
-
- [ISO86] International Standards 8602 - Information Processing
- Systems - OSI: Connectionless Transport Protocol
- Specification. International Standards Organization,
- December 1986.
-
- [MIL92] Mills, D., "Network Time Protocol (Version 3) Specification,
- Implementation", RFC 1305, March 1992.
-
- [PAR93] Partridge, C., Mendez, T. and W. Milliken, "Host Anycasting
- Service", RFC 1546, November 1993.
-
- [POS80] Postel, J., "User Datagram Protocol", STD 6, RFC 768, August
- 1980.
-
- [POS83] Postel, J., "Time Protocol", STD 26, RFC 868, May 1983.
-
- [SRI99] Srisuresh, P. and M. Holdrege. "IP Network Address
- Translator (NAT) Terminology and Considerations", RFC 2663,
- August 1999.
-
- [SRI01] Srisuresh, P. and K. Egevang. "Traditional IP Network
- Address Translator (Traditional NAT)", RFC 3022, January
- 2001.
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 25]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
-13. Security Considerations
-
- Security issues are not discussed in this memo.
-
-14. Author's Address
-
- David L. Mills
- Electrical and Computer Engineering Department
- University of Delaware
- Newark, DE 19716
- Phone: (302) 831-8247
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 26]
-\f
-Internet-Draft SNTPv4 for IPv4, IPv6 and OSI September 2003
-
-
-15. Full Copyright Statement
-
- Copyright (C) The Internet Society (2003). All Rights Reserved.
-
- This document and translations of it may be copied and furnished to
- others, and derivative works that comment on or otherwise explain it
- or assist in its implementation may be prepared, copied, published
- and distributed, in whole or in part, without restriction of any
- kind, provided that the above copyright notice and this paragraph are
- included on all such copies and derivative works. However, this
- document itself may not be modified in any way, such as by removing
- the copyright notice or references to the Internet Society or other
- Internet organizations, except as needed for the purpose of
- developing Internet standards in which case the procedures for
- copyrights defined in the Internet Standards process must be
- followed, or as required to translate it into languages other than
- English.
-
- The limited permissions granted above are perpetual and will not be
- revoked by the Internet Society or its successors or assignees.
-
- This document and the information contained herein is provided on an
- "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
- TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
- BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
- HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
-
-Acknowledgement
-
- Funding for the RFC Editor function is currently provided by the
- Internet Society.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Mills, et al. draft-mills-sntp-v4-00.txt [Page 27]
-\f
-#define VERSION "1.6" /* Just the version string */
#define MAX_SOCKETS 10 /* Maximum number of addresses */
#ifndef LOCKNAME
# define SAVENAME "/etc/sntp.state" /* Stores the recovery state */
#endif
+#define DEBUG
+
/* Defined in main.c */
#define op_client 1 /* Behave as a challenge client */
#define op_listen 2 /* Behave as a listening client */
-extern const char *argv0;
+/* extern const char *argv0;
extern int verbose, operation;
-/* Defined in unix.c */
+ Defined in unix.c */
extern void do_nothing (int seconds);
extern int flush_socket (int which);
-extern void close_socket (int which);
+/* extern void close_socket (int which); */
+++ /dev/null
-/* Copyright (C) 1996 N.M. Maclaren
- Copyright (C) 1996 The University of Cambridge
-
-This includes all of the code needed to handle Internet addressing. It is way
-outside current POSIX, unfortunately. It should be easy to convert to a system
-that uses another mechanism. The signal handling is not necessary for its
-function, but is an attempt to avoid the program hanging when the name server
-is inaccessible. */
-
-
-
-#include "header.h"
-#include "internet.h"
-
-#include <netdb.h>
-#include <arpa/inet.h>
-
-#define INTERNET
-#include "kludges.h"
-#undef INTERNET
-
-
-/* Used to force dns resolving to ipv4 or ipv6 addresses. */
-static int pref_family;
-
-/* There needs to be some disgusting grobble for handling timeouts, which is
-identical to the grobble in socket.c. */
-
-static jmp_buf jump_buffer;
-
-static void jump_handler (int sig) {
- longjmp(jump_buffer,1);
-}
-
-static void clear_alarm (void) {
- int k;
-
- k = errno;
- alarm(0);
- errno = 0;
- if (signal(SIGALRM,SIG_DFL) == SIG_ERR)
- fatal(1,"unable to reset signal handler",NULL);
- errno = k;
-}
-
-void preferred_family(int fam) {
- switch(fam) {
- case PREF_FAM_INET:
- pref_family = AF_INET;
- break;
-#ifdef HAVE_IPV6
- case PREF_FAM_INET6:
- pref_family = AF_INET6;
- break;
-#endif
- default:
- fatal(0,"unable to set the preferred family", NULL);
- break;
- }
-}
-
-#ifdef HAVE_IPV6
-
-void find_address (struct sockaddr_storage *address,
- struct sockaddr_storage *anywhere,
- int *port, char *hostname, int timespan) {
-
-/* Locate the specified NTP server and return its Internet address and port
-number. */
-
- int family, rval;
- struct addrinfo hints;
- struct addrinfo *res;
-
- res = NULL;
- memset(address, 0, sizeof(struct sockaddr_storage));
- memset(anywhere, 0, sizeof(struct sockaddr_storage));
-
- if (setjmp(jump_buffer))
- fatal(0,"unable to set up access to NTP server %s",hostname);
- errno = 0;
- if (signal(SIGALRM,jump_handler) == SIG_ERR)
- fatal(1,"unable to set up signal handler",NULL);
- alarm((unsigned int)timespan);
-
-/* Look up the Internet name or IP number. */
- memset(&hints, 0, sizeof(hints));
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_family = pref_family;
- rval = getaddrinfo(hostname, "ntp", &hints, &res);
- if (rval != 0)
- fatal(0, "getaddrinfo(hostname, ntp) failed with %s",
- gai_strerror(rval));
-
-/* Now clear the timer and check the result. */
-
- clear_alarm();
- /* There can be more than one address in the list, but for now only
- use the first. */
- memcpy(address, res->ai_addr, res->ai_addrlen);
- family = res->ai_family;
- freeaddrinfo(res);
-
- switch(family) {
- case AF_INET:
- hints.ai_family = AF_INET;
- hints.ai_flags = AI_PASSIVE;
- rval = getaddrinfo(NULL, "ntp", &hints, &res);
- if (rval != 0)
- fatal(0, "getaddrinfo(NULL, ntp) failed with %s",
- gai_strerror(rval));
- memcpy(anywhere, res->ai_addr, res->ai_addrlen);
- freeaddrinfo(res);
- break;
- case AF_INET6:
- hints.ai_family = AF_INET6;
- hints.ai_flags = AI_PASSIVE;
- rval = getaddrinfo(NULL, "ntp", &hints, &res);
- if (rval != 0)
- fatal(0, "getaddrinfo(NULL, ntp, INET6, AI_PASSIVE) failed with %s",
- gai_strerror(rval));
- memcpy(anywhere, res->ai_addr, res->ai_addrlen);
- freeaddrinfo(res);
- break;
- }
-}
-
-#else
-
-void find_address (struct in_addr *address, struct in_addr *anywhere,
- int *port, char *hostname, int timespan) {
-
-/* Locate the specified NTP server and return its Internet address and port
-number. */
-
- unsigned long ipaddr;
- struct in_addr nowhere[1];
- struct hostent *host;
- struct servent *service;
-
-/* Set up the reserved Internet addresses, attempting not to assume that
-addresses are 32 bits. */
-
- local_to_address(nowhere,INADDR_LOOPBACK);
- local_to_address(anywhere,INADDR_ANY);
-
-/* Check the address, if any. This assumes that the DNS is reliable, or is at
-least checked by someone else. But it doesn't assume that it is accessible, so
-it needs to set up a timeout. */
-
- if (hostname == NULL)
- *address = *anywhere;
- else {
- if (setjmp(jump_buffer))
- fatal(0,"unable to set up access to NTP server %s",hostname);
- errno = 0;
- if (signal(SIGALRM,jump_handler) == SIG_ERR)
- fatal(1,"unable to set up signal handler",NULL);
- alarm((unsigned int)timespan);
-
-/* Look up the Internet name or IP number. */
-
- if (! isdigit(hostname[0])) {
- errno = 0;
- host = gethostbyname(hostname);
- } else {
- if ((ipaddr = inet_addr(hostname)) == (unsigned long)-1)
- fatal(0,"invalid IP number %s",hostname);
- network_to_address(address,ipaddr);
- errno = 0;
- host = gethostbyaddr((void *)address,sizeof(struct in_addr),
- AF_INET);
- }
-
-/* Now clear the timer and check the result. */
-
- clear_alarm();
- if (host == NULL) fatal(1,"unable to locate IP address/number",NULL);
- if (host->h_length != sizeof(struct in_addr))
- fatal(0,"the address does not seem to be an Internet one",NULL);
- *address = *((struct in_addr **)host->h_addr_list)[0];
- if (memcmp(address,nowhere,sizeof(struct in_addr)) == 0
- || memcmp(address,anywhere,sizeof(struct in_addr)) == 0)
- fatal(0,"reserved IP numbers cannot be used",NULL);
- if (verbose)
- fprintf(stderr,
- "%s: using NTP server %s (%s)\n",
- argv0,host->h_name,inet_ntoa(*address));
- }
-
-/* Find out the port number (usually from /etc/services), and leave it in
-network format. This is assumed not to be obtained from a network service!
-Note that a port number is not assumed to be 16 bits. */
-
- if ((service = getservbyname("ntp","udp")) != NULL) {
- *port = service->s_port;
- if (verbose > 2)
- fprintf(stderr,"Using port %d for NTP\n",port_to_integer(*port));
- } else {
- *port = NTP_PORT;
- if (verbose)
- fprintf(stderr,
- "%s: assuming port %d for NTP - check /etc/services\n",
- argv0,port_to_integer(*port));
- }
-}
-#endif
+++ /dev/null
-/* Copyright (C) 1996 N.M. Maclaren
- Copyright (C) 1996 The University of Cambridge
-
-This includes all of the 'Internet' headers and definitions used across
-modules, including those for handling timeouts. No changes should be needed
-for any version of Unix with Internet (IP version 5) addressing, but would be
-for other addressing domains. It needs <sys/socket.h> only because AF_INET is
-needed by gethostbyaddr and is defined there rather than in <netdb.h>, for some
-damn-fool reason. */
-
-
-
-#include <setjmp.h>
-#include <signal.h>
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-
-
-/* It is most unclear whether these should be here or in kludges.h, as they are
-kludges to keep 32-bit address dependencies out of the main body of internet.c,
-to allow for the much heralded arrival of IP version 6. It will be interesting
-to see whether the universal availability of 64-bit integers arrives first. */
-
-#define local_to_address(x,y) ((x)->s_addr = htonl((unsigned long)y))
-#define network_to_address(x,y) ((x)->s_addr = (y))
-
-#define NTP_PORT htons((unsigned short)123) /* If not in /etc/services */
-#define port_to_integer(x) (ntohs((unsigned short)(x)))
-
-
-#if defined(_SS_MAXSIZE) || defined(_SS_SIZE)
-#define HAVE_IPV6
-#endif
-
-/* Defined in internet.c */
-#ifdef HAVE_IPV6
-extern void find_address (struct sockaddr_storage *address,
- struct sockaddr_storage *anywhere,
- int *port, char *hostname, int timespan);
-#else
-extern void find_address (struct in_addr *address, struct in_addr *anywhere,
- int *port, char *hostname, int timespan);
-#endif
+++ /dev/null
-/* Copyright (C) 1996, 2000 N.M. Maclaren
- Copyright (C) 1996, 2000 The University of Cambridge
-
-This includes all of the kludges necessary for certain broken systems. It is
-called after all other headers. All of the modules set a flag to say which
-they are, but none of the current kludges critically need that information. */
-
-
-
-/* stdlib.h is broken under SunOS4. */
-
-#ifndef EXIT_SUCCESS
-#define EXIT_SUCCESS 0
-#define EXIT_FAILURE 1
-#endif
-
-
-
-/* stdio.h is also broken under SunOS4. */
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-
-
-
-/* netinet/in.h sometimes omits INADDR_LOOPBACK, or makes it conditional on
-peculiar preprocessor symbols. */
-
-#ifndef INADDR_LOOPBACK
-#define INADDR_LOOPBACK 0x7f000001ul
-#endif
-
-
-
-/* HP-UX up to version 9.x does not have adjtime, so make it fail. This needs
-a flag setting in Makefile. */
-
-#ifdef ADJTIME_MISSING
-#define adjtime(x,y) 1
-#endif
-
-
-
-/* O_NONBLOCK doesn't work under Ultrix 4.3. This needs a flag setting in
-Makefile. */
-
-#ifdef NONBLOCK_BROKEN
-#ifdef O_NONBLOCK
-#undef O_NONBLOCK
-#endif
-#define O_NONBLOCK O_NDELAY
-#endif
-
-
-
-/* Some older systems use EWOULDBLOCK rather than EAGAIN, but don't assume that
-it is defined. The differences are not relevant to this program. */
-
-#ifndef EWOULDBLOCK
-#define EWOULDBLOCK EAGAIN
-#endif
-/* Copyright (C) 1996, 1997, 2000 N.M. Maclaren
- Copyright (C) 1996, 1997, 2000 The University of Cambridge
-
-This is a complete SNTP implementation, which was easier to write than to port
-xntp to a new version of Unix with any hope of maintaining it thereafter. It
-supports the full SNTP (RFC 2030) client- and server-side challenge-response
-and broadcast protocols. It should achieve nearly optimal accuracy with very
-few transactions, provided only that a client has access to a trusted server
-and that communications are not INVARIABLY slow. As this is the environment in
-which 90-99% of all NTP systems are run ....
-
-The specification of this program is:
-
- sntp [ --help | -h | -? ] [ -v | -V | -W ]
- [ -q [ -f savefile ] |
- [ { -r | -a } [ -P prompt ] [ -l lockfile ] ]
- [ -c count ] [ -e minerr ][ -E maxerr ]
- [ -d delay | -x [ separation ] [ -f savefile ] ]
- [ -4 | -6 ] [ address(es) ] ]
-
- --help, -h and -? all print the syntax of the command.
-
- -v indicates that diagnostic messages should be written to standard error,
-and -V requests more output for investigating apparently inconsistent
-timestamps. -W requests very verbose debugging output, and will interfere with
-the timing when writing to the terminal (because of line buffered output from
-C); it is useful only when debugging the source. Note that the times produced
-by -V and -W are the corrections needed, and not the error in the local clock.
-
- -q indicates that it will query a savefile that is being maintained by
-it being run in daemon mode.
-
- The default is that it should behave as a client, and the following options
-are then relevant:
-
- -r indicates that the system clock should be reset by 'settimeofday'.
-Naturally, this will work only if the user has enough privilege.
-
- -a indicates that the system clock should be reset by 'adjtime'.
-Naturally, this will work only if the user has enough privilege.
-
- -x indicates that the program should run as a daemon (i.e. forever), and
-allow for clock drift.
-
- -4 or -6 force dns resolving to ipv4 or ipv6 addresses.
-
- The default is to write the current date and time to the standard output in
-a format like '1996 Oct 15 20:17:25.123 + 4.567 +/- 0.089 secs', indicating the
-estimated true (local) time and the error in the local clock. In daemon mode,
-it will add drift information in a format like ' + 1.3 +/- 0.1 ppm', and
-display this at roughly 'separation' intervals.
-
- 'minerr' is the maximum ignorable variation between the clocks. Acceptable
-values are from 0.001 to 1, and the default is 0.1 if 'address' is specified
-and 0.5 otherwise.
-
- 'maxerr' is the maximum value of various delays that are deemed acceptable.
-Acceptable values are from 1 to 60, and the default is 5. It should sometimes
-be increased if there are problems with the network, NTP server or system
-clock, but take care.
-
- 'prompt' is the maximum clock change that will be made automatically.
-Acceptable values are from 1 to 3600, and the default is 30. If the program is
-being run interactively, larger values will cause a prompt. The value may also
-be 'no', and the change will be made without prompting.
-
- 'count' is the maximum number of NTP packets to require. Acceptable values
-are from 1 to 25 if 'address' is specified and '-x' is not, and from 5 to 25
-otherwise; the default is 5. If the maximum isn't enough, you need a better
-consistency algorithm than this program uses. Don't increase it.
-
- 'delay' is a rough limit on the total running time in seconds. Acceptable
-values are from 1 to 3600, and the default is 15 if 'address' is specified and
-300 otherwise.
-
- 'separation' is the time to wait between calls to the server in minutes if
-'address' is specified, and the minimum time between broadcast packets if not.
-Acceptable values are from 1 to 1440 (a day), and the default is 300.
-
- 'lockfile' may be used in an update mode to ensure that there is only
-one copy of sntp running at once. The default is installation-dependent,
-but will usually be /etc/sntp.pid.
-
- 'savefile' may be used in daemon mode to store a record of previous
-packets, which may speed up recalculating the drift after sntp has to be
-restarted (e.g. because of network or server outages). The default is
-installation-dependent, but will usually be /etc/sntp.state. Note that
-there is no locking of this file, and using it twice may cause chaos.
-
- 'address' is the DNS name or IP number of a host to poll; if no name is
-given, the program waits for broadcasts. Note that a single component numeric
-address is not allowed.
-
-For sanity, it is also required that 'minerr' < 'maxerr' < 'delay' (if
-listening for broadcasts, 'delay/count' and, in daemon mode, 'separation') and,
-for sordid Unixish reasons, that 2*'count' < 'delay'. The last could be fixed,
-but isn't worth it. Note that none of the above values are closely linked to
-the limits described in the NTP protocol (RFC 1305). Do not increase the
-compiled-in bounds excessively, or the code will fail.
-
-The algorithm used to decide whether to accept a correction is whether it would
-seem to improve matters. Unlike the 'xntp' suite, little attempt is made to
-handle really knotted scenarios, and diagnostics are written to standard error.
-In non-daemon client mode, it is intended to be run as a command or in a 'cron'
-job. Unlike 'ntpdate', its default mode is simply to display the clock error.
-
-It assumes that floating-point arithmetic is tolerably efficient, which is true
-for even the cheapest personal computer nowadays. If, however, you want to
-port this to a toaster, you may have problems!
-
-In its terminating modes, its return code is EXIT_SUCCESS if the operation was
-completed successfully and EXIT_FAILURE otherwise.
-
-In daemon mode, it runs for ever and stops with a return code EXIT_FAILURE
-only after a severe error. In daemon mode, it will fail if the server is
-inaccessible for a long time or seriously sick, and will need manual
-restarting.
-
-
-WARNING: this program has reached its 'hack count' and needs restructuring,
-badly. Perhaps the worst code is in run_daemon(). You are advised not to
-fiddle unless you really have to. */
-
-
-
-#include "header.h"
-
-#include <limits.h>
-#include <float.h>
-#include <math.h>
-
-#define MAIN
-#include "kludges.h"
-#undef MAIN
-
-
-
-/* NTP definitions. Note that these assume 8-bit bytes - sigh. There is
-little point in parameterising everything, as it is neither feasible nor
-useful. It would be very useful if more fields could be defined as
-unspecified. The NTP packet-handling routines contain a lot of extra
-assumptions. */
-
-#define JAN_1970 2208988800.0 /* 1970 - 1900 in seconds */
-#define NTP_SCALE 4294967296.0 /* 2^32, of course! */
-
-#define NTP_PACKET_MIN 48 /* Without authentication */
-#define NTP_PACKET_MAX 68 /* With authentication (ignored) */
-#define NTP_DISP_FIELD 8 /* Offset of dispersion field */
-#define NTP_REFERENCE 16 /* Offset of reference timestamp */
-#define NTP_ORIGINATE 24 /* Offset of originate timestamp */
-#define NTP_RECEIVE 32 /* Offset of receive timestamp */
-#define NTP_TRANSMIT 40 /* Offset of transmit timestamp */
-
-#define NTP_LI_FUDGE 0 /* The current 'status' */
-#define NTP_VERSION 3 /* The current version */
-#define NTP_VERSION_MAX 4 /* The maximum valid version */
-#define NTP_STRATUM 15 /* The current stratum as a server */
-#define NTP_STRATUM_MAX 15 /* The maximum valid stratum */
-#define NTP_POLLING 8 /* The current 'polling interval' */
-#define NTP_PRECISION 0 /* The current 'precision' - 1 sec. */
-
-#define NTP_ACTIVE 1 /* NTP symmetric active request */
-#define NTP_PASSIVE 2 /* NTP symmetric passive response */
-#define NTP_CLIENT 3 /* NTP client request */
-#define NTP_SERVER 4 /* NTP server response */
-#define NTP_BROADCAST 5 /* NTP server broadcast */
-
-#define NTP_INSANITY 3600.0 /* Errors beyond this are hopeless */
-#define RESET_MIN 15 /* Minimum period between resets */
-#define ABSCISSA 3.0 /* Scale factor for standard errors */
-
-
-
-/* Local definitions and global variables (mostly options). These are all of
-the quantities that control the main actions of the program. The first three
-are the only ones that are exported to other modules. */
-
-const char *argv0 = NULL; /* For diagnostics only - not NULL */
-int verbose = 0, /* Default = 0, -v = 1, -V = 2, -W = 3 */
- operation = 0; /* Defined in header.h - see action */
-const char *lockname = NULL; /* The name of the lock file */
-int unprivport = 0; /* Use an unpriv port for query? */
-
-#define COUNT_MAX 25 /* Do NOT increase this! */
-#define WEEBLE_FACTOR 1.2 /* See run_server() and run_daemon() */
-#define ETHERNET_MAX 5 /* See run_daemon() and run_client() */
-
-#define action_display 1 /* Just display the result */
-#define action_reset 2 /* Reset using 'settimeofday' */
-#define action_adjust 3 /* Reset using 'adjtime' */
-#define action_broadcast 4 /* Behave as a server, broadcasting */
-#define action_server 5 /* Behave as a server for clients */
-#define action_query 6 /* Query a daemon savefile */
-
-#define save_read_only 1 /* Read the saved state only */
-#define save_read_check 2 /* Read and check it */
-#define save_write 3 /* Write the saved state */
-#define save_clear 4 /* Clear the saved state */
-
-static const char version[] = VERSION; /* For reverse engineering :-) */
-static int action = 0, /* Defined above - see operation */
- count = 0, /* -c value in seconds */
- delay = 0, /* -d or -x value in seconds */
- attempts = 0, /* Packets transmitted up to 2*count */
- waiting = 0, /* -d/-c except for in daemon mode */
- locked = 0; /* set_lock(1) has been called */
-static double outgoing[2*COUNT_MAX], /* Transmission timestamps */
- minerr = 0.0, /* -e value in seconds */
- maxerr = 0.0, /* -E value in seconds */
- prompt = 0.0, /* -p value in seconds */
- dispersion = 0.0; /* The source dispersion in seconds */
-static FILE *savefile = NULL; /* Holds the data to restart from */
-
-
-
-/* The unpacked NTP data structure, with all the fields even remotely relevant
-to SNTP. */
-
-typedef struct NTP_DATA {
- unsigned char status, version, mode, stratum, polling;
- signed char precision;
- double dispersion, reference, originate, receive, transmit, current;
-} ntp_data;
-
-
-
-/* The following structure is used to keep a record of packets in daemon mode;
-it contains only the information that is actually used for the drift and error
-calculations. */
-
-typedef struct {
- double dispersion, weight, when, offset, error;
-} data_record;
-
-void syntax(int);
-void display_data(ntp_data *);
-void display_packet(unsigned char *, int);
-void pack_ntp(unsigned char *, int, ntp_data *);
-void unpack_ntp(ntp_data *, unsigned char *, int);
-void make_packet(ntp_data *, int);
-int read_packet(int, ntp_data *, double *, double *);
-void format_time(char *, int, double, double, double, double, int);
-double reset_clock(double, double, int);
-void run_server(void);
-double estimate_stats(int *, int *, data_record *, double, double *, double *,
- double *, double *, double *, double *, int *, int);
-double correct_drift(double *, double *, double);
-void handle_saving(int, int *, int *, int *, data_record *, double *,
- double *, double *);
-void query_savefile(void);
-void run_daemon(char **, int, int);
-void run_client(char **, int);
-
-void fatal (int syserr, const char *message, const char *insert) {
-
-/* Issue a diagnostic and stop. Be a little paranoid about recursion. */
-
- int k = errno;
- static int called = 0;
-
- if (message != NULL) {
- fprintf(stderr,"%s: ",argv0);
- fprintf(stderr,message,insert);
- fprintf(stderr,"\n");
- }
- errno = k;
- if (syserr) perror(argv0);
- if (! called) {
- called = 1;
- if (savefile != NULL && fclose(savefile))
- fatal(1,"unable to close the daemon save file",NULL);
- if (locked) set_lock(0);
- }
- exit(EXIT_FAILURE);
+#include <isc/result.h>
+#include <isc/net.h>
+#include <l_stdlib.h>
+#include <ntp_fp.h>
+#include <ntp.h>
+#include <ntp_stdlib.h>
+#include <ntp_unixtime.h>
+#include <stdio.h>
+
+#include <sntp-opts.h>
+
+#include "crypto.h"
+#include "kod_management.h"
+#include "networking.h"
+#include "utilities.h"
+#include "log.h"
+
+
+int ai_fam_pref;
+volatile int debug;
+char adr_buf[INET6_ADDRSTRLEN];
+
+struct key *keys = NULL;
+
+void set_li_vn_mode (struct pkt *spkt, char leap, char version, char mode);
+int sntp_main (int argc, char **argv);
+int on_wire (struct addrinfo *host);
+int set_time (double offset);
+
+
+#if !HAVE_MALLOC
+void *
+rpl_malloc (size_t n)
+{
+ if (n == 0)
+ n = 1;
+ return malloc (n);
}
-
-
-
-void syntax (int halt) {
-
-/* The standard, unfriendly Unix error message. Some errors are diagnosed more
-helpfully. This is called before any files or sockets are opened. */
-
- fprintf(stderr,"Syntax: %s [ --help | -h | -? ] [ -v | -V | -W ] \n",argv0);
- fprintf(stderr," [ -q [ -f savefile ] |\n");
- fprintf(stderr," [ { -r | -a } [ -P prompt ] [ -l lockfile ] ]\n");
- fprintf(stderr," [ -c count ] [ -e minerr ] [ -E maxerr ]\n");
- fprintf(stderr," [ -d delay | -x [ separation ] ");
- fprintf(stderr,"[ -f savefile ] ]\n");
- fprintf(stderr," [ -4 | -6 ] [-u] [ address(es) ] ]\n");
- if (halt) exit(EXIT_FAILURE);
+#endif /* !HAVE_MALLOC */
+
+int
+main (
+ int argc,
+ char **argv
+ )
+{
+ return sntp_main(argc, argv);
}
-
-
-void display_data (ntp_data *data) {
-
-/* This formats the essential NTP data, as a debugging aid. */
-
- fprintf(stderr,"sta=%d ver=%d mod=%d str=%d pol=%d dis=%.6f ref=%.6f\n",
- data->status,data->version,data->mode,data->stratum,data->polling,
- data->dispersion,data->reference);
- fprintf(stderr,"ori=%.6f rec=%.6f\n",data->originate,data->receive);
- fprintf(stderr,"tra=%.6f cur=%.6f\n",data->transmit,data->current);
+/*
+ * The actual main function.
+ */
+int
+sntp_main (
+ int argc,
+ char **argv
+ )
+{
+ register int c;
+ struct kod_entry *reason = NULL;
+ int optct;
+ int sync_data_suc = 0;
+ struct addrinfo **resh = NULL;
+ int resc;
+
+ /* IPv6 available? */
+ if (isc_net_probeipv6() != ISC_R_SUCCESS) {
+ ai_fam_pref = AF_INET;
+#ifdef DEBUG
+ printf("No ipv6 support available, forcing ipv4\n");
+#endif
+ }
+ else {
+ /* Check for options -4 and -6 */
+ if(ENABLED_OPT(IPV4))
+ ai_fam_pref = AF_INET;
+ else if(ENABLED_OPT(IPV6))
+ ai_fam_pref = AF_INET6;
+ else
+ ai_fam_pref = 0;
+ }
+
+ log_msg("Started sntp", 0);
+
+ optct = optionProcess(&sntpOptions, argc, argv);
+ argc -= optct;
+ argv += optct;
+
+ /* Parse config file if declared TODO */
+
+ /* Initialize logging system */
+ if (HAVE_OPT(FILELOG))
+ init_log(OPT_ARG(FILELOG));
+
+ /* If there's a specified KOD file init KOD system.
+ * If not and system may save to HD use default file.
+ */
+ if (HAVE_OPT(KOD))
+ kod_init_kod_db(OPT_ARG(KOD));
+
+ if (HAVE_OPT(KEYFILE))
+ auth_init(OPT_ARG(KEYFILE), &keys);
+
+
+ /* Considering employing a variable that prevents functions of doing anything until
+ * everything is initialized properly
+ */
+ resc = resolve_hosts(argv, argc, &resh, ai_fam_pref);
+
+ if (resc < 1) {
+ printf("Unable to resolve hostname(s)\n");
+ return -1;
+ }
+
+ /* Select a certain ntp server according to simple criteria? For now
+ * let's just pay attention to previous KoDs.
+ */
+ for (c = 0; c < resc && !sync_data_suc; c++) {
+ getnameinfo(resh[c]->ai_addr, resh[c]->ai_addrlen, adr_buf,
+ sizeof(adr_buf), NULL, 0, NI_NUMERICHOST);
+
+ int kodc;
+ char *hostname = addrinfo_to_str(resh[c]);
+
+ if ((kodc = search_entry(hostname, &reason)) == 0) {
+ if (is_reachable(resh[c])) {
+ int ow_ret = on_wire(resh[c]);
+
+ if (ow_ret < 0)
+ printf("on_wire failed for server %s!\n", hostname);
+ else
+ sync_data_suc = 1;
+ }
+ } else {
+ printf("KoD %i packages exists for %s, stopping any further communication.\n",
+ kodc, adr_buf);
+ free(reason);
+ }
+
+ freeaddrinfo(resh[c]);
+ free(hostname);
+ }
+ free(resh);
+
+ return 0;
}
+/* The heart of (S)NTP, exchange NTP packets and compute values to correct the local clock */
+int
+on_wire (
+ struct addrinfo *host
+ )
+{
+ register int try;
+ SOCKET sock;
+ struct pkt *x_pkt = (struct pkt *) alloca(sizeof(struct pkt));
+ struct pkt *r_pkt = (struct pkt *) alloca(sizeof(struct pkt));
+
+ for(try=0; try<5; try++) {
+ struct timeval tv_xmt, tv_dst;
+ double t21, t34, delta, offset;
+ int error, rpktl, sw_case;
+ char *hostname = NULL, *ts_str = NULL;
+ l_fp p_rec, p_xmt, p_ref, p_org, xmt, tmp, dst;
+
+ memset(r_pkt, 0, sizeof(*r_pkt));
+ memset(x_pkt, 0, sizeof(*x_pkt));
+
+ error = GETTIMEOFDAY(&tv_xmt, (struct timezone *)NULL);
+
+ tv_xmt.tv_sec += JAN_1970;
+
+#ifdef DEBUG
+ printf("sntp on_wire: Current time sec: %i msec: %i\n", (unsigned int) tv_xmt.tv_sec,
+ (unsigned int) tv_xmt.tv_usec);
+#endif
+
+ TVTOTS(&tv_xmt, &xmt);
+ HTONL_FP(&xmt, &(x_pkt->xmt));
+ x_pkt->stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
+ x_pkt->ppoll = 8;
+ /* FIXME! Modus broadcast + adr. check -> bdr. pkt */
+ set_li_vn_mode(x_pkt, LEAP_NOTINSYNC, 4, 3);
-void display_packet (unsigned char *packet, int length) {
-
-/* This formats a possible packet very roughly, as a debugging aid. */
-
- int i;
-
- if (length < NTP_PACKET_MIN || length > NTP_PACKET_MAX) return;
- for (i = 0; i < length; ++i) {
- if (i != 0 && i%32 == 0)
- fprintf(stderr,"\n");
- else if (i != 0 && i%4 == 0)
- fprintf(stderr," ");
- fprintf(stderr,"%.2x",packet[i]);
- }
- fprintf(stderr,"\n");
-}
-
+ create_socket(&sock, (sockaddr_u *)host->ai_addr);
+ sendpkt(sock, (sockaddr_u *)host->ai_addr, x_pkt, LEN_PKT_NOMAC);
+ rpktl = recvpkt(sock, r_pkt, x_pkt);
-void pack_ntp (unsigned char *packet, int length, ntp_data *data) {
-
-/* Pack the essential data into an NTP packet, bypassing struct layout and
-endian problems. Note that it ignores fields irrelevant to SNTP. */
-
- int i, k;
- double d;
-
- memset(packet,0,(size_t)length);
- packet[0] = (data->status<<6)|(data->version<<3)|data->mode;
- packet[1] = data->stratum;
- packet[2] = data->polling;
- packet[3] = data->precision;
- d = data->originate/NTP_SCALE;
- for (i = 0; i < 8; ++i) {
- if ((k = (int)(d *= 256.0)) >= 256) k = 255;
- packet[NTP_ORIGINATE+i] = k;
- d -= k;
- }
- d = data->receive/NTP_SCALE;
- for (i = 0; i < 8; ++i) {
- if ((k = (int)(d *= 256.0)) >= 256) k = 255;
- packet[NTP_RECEIVE+i] = k;
- d -= k;
- }
- d = data->transmit/NTP_SCALE;
- for (i = 0; i < 8; ++i) {
- if ((k = (int)(d *= 256.0)) >= 256) k = 255;
- packet[NTP_TRANSMIT+i] = k;
- d -= k;
- }
-}
-
+ closesocket(sock);
+ if(rpktl > 0)
+ sw_case = 1;
+ else
+ sw_case = rpktl;
-void unpack_ntp (ntp_data *data, unsigned char *packet, int length) {
-
-/* Unpack the essential data from an NTP packet, bypassing struct layout and
-endian problems. Note that it ignores fields irrelevant to SNTP. */
-
- int i;
- double d;
-
- data->current = current_time(JAN_1970); /* Best to come first */
- data->status = (packet[0] >> 6);
- data->version = (packet[0] >> 3)&0x07;
- data->mode = packet[0]&0x07;
- data->stratum = packet[1];
- data->polling = packet[2];
- data->precision = packet[3];
- d = 0.0;
- for (i = 0; i < 4; ++i) d = 256.0*d+packet[NTP_DISP_FIELD+i];
- data->dispersion = d/65536.0;
- d = 0.0;
- for (i = 0; i < 8; ++i) d = 256.0*d+packet[NTP_REFERENCE+i];
- data->reference = d/NTP_SCALE;
- d = 0.0;
- for (i = 0; i < 8; ++i) d = 256.0*d+packet[NTP_ORIGINATE+i];
- data->originate = d/NTP_SCALE;
- d = 0.0;
- for (i = 0; i < 8; ++i) d = 256.0*d+packet[NTP_RECEIVE+i];
- data->receive = d/NTP_SCALE;
- d = 0.0;
- for (i = 0; i < 8; ++i) d = 256.0*d+packet[NTP_TRANSMIT+i];
- data->transmit = d/NTP_SCALE;
-}
+ switch(sw_case) {
+ case SERVER_UNUSEABLE:
+ return -1;
+ break;
+ case PACKET_UNUSEABLE:
+ break;
+ case SERVER_AUTH_FAIL:
+ break;
-void make_packet (ntp_data *data, int mode) {
-
-/* Create an outgoing NTP packet, either from scratch or starting from a
-request from a client. Note that it implements the NTP specification, even
-when this is clearly misguided, except possibly for the setting of LI. It
-would be easy enough to add a sanity flag, but I am not in the business of
-designing an alternative protocol (however much better it might be). */
-
- data->status = NTP_LI_FUDGE<<6;
- data->stratum = NTP_STRATUM;
- data->reference = data->dispersion = 0.0;
- if (mode == NTP_SERVER) {
- data->mode = (data->mode == NTP_CLIENT ? NTP_SERVER : NTP_PASSIVE);
- data->originate = data->transmit;
- data->receive = data->current;
- } else {
- data->version = NTP_VERSION;
- data->mode = mode;
- data->polling = NTP_POLLING;
- data->precision = NTP_PRECISION;
- data->receive = data->originate = 0.0;
- }
- data->current = data->transmit = current_time(JAN_1970);
-}
+ case KOD_DEMOBILIZE:
+ /* Received a DENY or RESTR KOD packet */
+ hostname = addrinfo_to_str(host);
+ add_entry(hostname, (char *) &r_pkt->refid);
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("sntp on_wire: Received KOD packet with code: %s from %s, demobilizing all connections\n",
+ (char *) r_pkt->refid, hostname);
+ char *log_str = (char *) malloc(sizeof(char) * (INET6_ADDRSTRLEN + 72));
+ snprintf(log_str, sizeof(log_str),
+ "Received a KOD packet with code %s from %s, demobilizing all connections",
+ (char *) &r_pkt->refid, hostname);
-int read_packet (int which, ntp_data *data, double *off, double *err) {
-
-/* Check the packet and work out the offset and optionally the error. Note
-that this contains more checking than xntp does. This returns 0 for success, 1
-for failure and 2 for an ignored broadcast packet (a kludge for servers). Note
-that it must not change its arguments if it fails. */
-
- unsigned char receive[NTP_PACKET_MAX+1];
- double delay1, delay2, x, y;
- int response = 0, failed, length, i, k;
-
-/* Read the packet and deal with diagnostics. */
-
- if ((length = read_socket(which,receive,NTP_PACKET_MAX+1,waiting)) <= 0)
- return 1;
- if (length < NTP_PACKET_MIN || length > NTP_PACKET_MAX) {
- if (verbose)
- fprintf(stderr,"%s: bad length %d for NTP packet on socket %d\n",
- argv0,length,which);
- return 1;
- }
- if (verbose > 2) {
- fprintf(stderr,"Incoming packet on socket %d:\n",which);
- display_packet(receive,length);
- }
- unpack_ntp(data,receive,length);
- if (verbose > 2) display_data(data);
-
-/* Start by checking that the packet looks reasonable. Be a little paranoid,
-but allow for version 1 semantics and sick clients. */
-
- if (operation == op_listen)
- failed = (data->mode != NTP_BROADCAST);
- else {
- failed = (data->mode != NTP_SERVER && data->mode != NTP_PASSIVE);
- response = 1;
- }
- if (failed || data->status == 3 || data->version < 1 ||
- data->version > NTP_VERSION_MAX ||
- data->stratum > NTP_STRATUM_MAX) {
- if (verbose)
- fprintf(stderr,
- "%s: Unusable NTP packet rejected on socket %d (f=%d, status %d, version %d, stratum %d)\n",
- argv0, which,
- failed, data->status, data->version, data->stratum);
- return 1;
- }
-
-/* Note that the conventions are very poorly defined in the NTP protocol, so we
-have to guess. Any full NTP server perpetrating completely unsynchronised
-packets is an abomination, anyway, so reject it. */
-
- delay1 = data->transmit-data->receive;
- delay2 = data->current-data->originate;
- failed = (
- ( data->stratum != 0
- /* && data->stratum != NTP_STRATUM_MAX */
- && data->reference == 0.0
- )
- || data->transmit == 0.0
- );
- if (response &&
- (data->originate == 0.0 || data->receive == 0.0 ||
- (data->reference != 0.0 && data->receive < data->reference) ||
- delay1 < 0.0 || delay1 > NTP_INSANITY || delay2 < 0.0 ||
- data->dispersion > NTP_INSANITY))
- failed = 1;
- if (failed) {
- if (verbose)
- fprintf(stderr,
- "%s: incomprehensible NTP packet rejected on socket %d\n",
- argv0,which);
- return 1;
- }
- if (data->stratum == NTP_STRATUM_MAX) {
- fprintf(stderr,
- "%s: unsynch NTP response on socket %d\n",
- argv0,which);
- return 1;
- }
-
-/* If it is a response, check that it corresponds to one of our requests and
-has got here in a reasonable length of time. */
-
- if (response) {
- k = 0;
- for (i = 0; i < attempts; ++i)
- if (data->originate == outgoing[i]) {
- outgoing[i] = 0.0;
- ++k;
- }
- if (k != 1 || delay2 > NTP_INSANITY) {
- if (verbose)
- fprintf(stderr,
- "%s: bad response from NTP server rejected on socket %d\n",
- argv0,which);
- return 1;
- }
- }
-
-/* Now return the time information. If it is a server response, it contains
-enough information that we can be almost certain that we have not been fooled
-too badly. Heaven help us with broadcasts - make a wild kludge here, and see
-elsewhere for other kludges. */
-
- if (dispersion < data->dispersion) dispersion = data->dispersion;
- if (operation == op_listen) {
- *off = data->transmit-data->current;
- *err = NTP_INSANITY;
- } else {
- x = data->receive-data->originate;
- y = (data->transmit == 0.0 ? 0.0 : data->transmit-data->current);
- *off = 0.5*(x+y);
- *err = x-y;
- x = data->current-data->originate;
- if (0.5*x > *err) *err = 0.5*x;
- }
- return 0;
-}
+ log_msg(log_str, 2);
+ free(log_str);
+ break;
+ case KOD_RATE:
+ /* Hmm... probably we should sleep a bit here */
+ break;
-void format_time (char *text, int length, double offset, double error,
- double drift, double drifterr, int precision) {
-
-/* Format the current time into a string, with the extra information as
-requested. Note that the rest of the program uses the correction needed, which
-is what is printed for diagnostics, but this formats the error in the local
-system for display to users. So the results from this are the negation of
-those printed by the verbose options. */
-
- int milli, len;
- time_t now;
- struct tm *gmt;
- static const char *months[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
-
-/* Work out and format the current local time. Note that some semi-ANSI
-systems do not set the return value from (s)printf. */
-
- now = convert_time(current_time(offset),&milli);
- errno = 0;
- if ((gmt = localtime(&now)) == NULL)
- fatal(1,"unable to work out local time",NULL);
- len = 21;
- if (length <= len) fatal(0,"internal error calling format_time",NULL);
- errno = 0;
- precision /= -3;
- len += precision;
- sprintf(text,"%.4d %s %.2d %.2d:%.2d:%.2d.%.*d",
- gmt->tm_year+1900,months[gmt->tm_mon],gmt->tm_mday,
- gmt->tm_hour,gmt->tm_min,gmt->tm_sec,precision,milli);
- if (strlen(text) != len)
- fatal(1,"unable to format current local time",NULL);
-
-/* Append the information about the offset, if requested. */
-
- if (error >= 0.0) {
- if (length < len+30)
- fatal(0,"internal error calling format_time",NULL);
- errno = 0;
- sprintf(&text[len]," %c %.*f +/- %.*f secs",(offset > 0.0 ? '-' : '+'),
- precision,(offset > 0.0 ? offset : -offset),
- precision,dispersion+error);
- if (strlen(&text[len]) < 22)
- fatal(1,"unable to format clock correction",NULL);
- }
-
-/* Append the information about the drift, if requested. */
-
- if (drifterr >= 0.0) {
- len = strlen(text);
- if (length < len+25)
- fatal(0,"internal error calling format_time",NULL);
- errno = 0;
- sprintf(&text[len]," %c %.1f +/- %.1f ppm",
- (drift > 0.0 ? '-' : '+'),1.0e6*fabs(drift),
- 1.0e6*drifterr);
- if (strlen(&text[len]) < 17)
- fatal(1,"unable to format clock correction",NULL);
- }
-
-/* It would be better to check for field overflow, but it is a lot of code to
-trap extremely implausible scenarios. This will usually stop chaos from
-spreading. */
-
- if (strlen(text) >= length)
- fatal(0,"internal error calling format_time",NULL);
-}
+ case 1:
+ /* Convert timestamps from network to host byte order */
+ NTOHL_FP(&r_pkt->reftime, &p_ref);
+ NTOHL_FP(&r_pkt->org, &p_org);
+ NTOHL_FP(&r_pkt->rec, &p_rec);
+ NTOHL_FP(&r_pkt->xmt, &p_xmt);
+ if(ENABLED_OPT(NORMALVERBOSE)) {
+ getnameinfo(host->ai_addr, host->ai_addrlen, adr_buf,
+ sizeof(adr_buf), NULL, 0, NI_NUMERICHOST);
-double reset_clock (double offset, double error, int daemon) {
-
-/* Reset the clock, if appropriate, and return the correction actually used.
-This contains most of the checking for whether changes are worthwhile, except
-in daemon mode. */
-
- double absoff = (offset < 0 ? -offset : offset);
- char text[50];
-
-/* If the correction is large, ask for confirmation before proceeding. */
-
- if (absoff > prompt) {
- if (! daemon && ftty(stdin) && ftty(stdout)) {
- printf("The time correction is %.3f +/- %.3f+%.3f seconds\n",
- offset,dispersion,error);
- printf("Do you want to correct the time anyway? ");
- fflush(stdout);
- if (toupper(getchar()) != 'Y') {
- printf("OK - quitting\n");
- fatal(0,NULL,NULL);
- }
- } else {
- sprintf(text,"%.3f +/- %.3f+%.3f",offset,dispersion,error);
- fatal(0,"time correction too large: %s seconds",text);
- }
- }
-
-/* See if the correction is reasonably reliable and worth making. */
-
- if (absoff < (daemon ? 0.5 : 1.0)*minerr) {
- if (daemon ? verbose > 1 : verbose)
- fprintf(stderr,"%s: correction %.3f +/- %.3f+%.3f secs - ignored\n",
- argv0,offset,dispersion,error);
- return 0.0;
- } else if (absoff < 2.0*error) {
- if (daemon ? verbose > 1 : verbose)
- fprintf(stderr,
- "%s: correction %.3f +/- %.3f+%.3f secs - suppressed\n",
- argv0,offset,dispersion,error);
- return 0.0;
- }
-
-/* Make the correction. Provide some protection against the previous
-correction not having completed, but it will rarely help much. */
-
- adjust_time(offset,(action == action_reset ? 1 : 0),
- (daemon ? 2.0*minerr : 0.0));
- if (daemon ? verbose > 1 : verbose) {
- format_time(text,50,0.0,-1.0,0.0,-1.0,-10);
- fprintf(stderr,
- "%s: time changed by %.3f secs to %s +/- %.3f+%.3f\n",
- argv0,offset,text,dispersion,error);
- }
- return offset;
-}
+ printf("sntp on_wire: Received %i bytes from %s\n", rpktl, adr_buf);
+ }
+#ifdef DEBUG
+ pkt_output(r_pkt, rpktl, stdout);
+
+ printf("sntp on_wire: rpkt->reftime:\n");
+ l_fp_output(&(r_pkt->reftime), stdout);
+ printf("sntp on_wire: rpkt->org:\n");
+ l_fp_output(&(r_pkt->org), stdout);
+ printf("sntp on_wire: rpkt->rec:\n");
+ l_fp_output(&(r_pkt->rec), stdout);
+ printf("sntp on_wire: rpkt->rec:\n");
+ l_fp_output_bin(&(r_pkt->rec), stdout);
+ printf("sntp on_wire: rpkt->rec:\n");
+ l_fp_output_dec(&(r_pkt->rec), stdout);
+ printf("sntp on_wire: rpkt->xmt:\n");
+ l_fp_output(&(r_pkt->xmt), stdout);
+#endif
-double estimate_stats (int *a_total, int *a_index, data_record *record,
- double correction, double *a_disp, double *a_when, double *a_offset,
- double *a_error, double *a_drift, double *a_drifterr, int *a_wait,
- int update) {
-
-/* This updates the running statistics and returns the best estimate of what to
-do now. It returns the timestamp relevant to the correction. If broadcasts
-are rare and the drift is large, it will fail - you should then use a better
-synchronisation method. It will also fail if something goes severely wrong
-(e.g. if the local clock is reset by another process or the transmission errors
-are beyond reason).
-
-There is a kludge for synchronisation loss during down time. If it detects
-this, it will update only the history data and return zero; this is then
-handled specially in run_daemon(). While it could correct the offset, this
-might not always be the right thing to do. */
-
- double weight, disp, when, offset, error, drift, drifterr,
- now, e, w, x, y, z;
- int total = *a_total, index = *a_index, wait = *a_wait, i;
- char text[50];
-
-/* Correct the previous data and store a new entry in the circular buffer. */
-
- for (i = 0; i < total; ++i) {
- record[i].when += correction;
- record[i].offset -= correction;
- }
- if (update) {
- record[index].dispersion = *a_disp;
- record[index].when = *a_when;
- record[index].offset = *a_offset;
- if (verbose > 1)
- fprintf(stderr,"%s: corr=%.3f when=%.3f disp=%.3f off=%.3f",
- argv0,correction,*a_when,*a_disp,*a_offset); /* See below */
- if (operation == op_listen) {
- if (verbose > 1) fprintf(stderr,"\n");
- record[index].error = minerr;
- record[index].weight = 1.0;
- } else {
- if (verbose > 1) fprintf(stderr," err=%.3f\n",*a_error);
- record[index].error = x = *a_error;
- record[index].weight = 1.0/(x > minerr ? x*x : minerr*minerr);
- }
- if (++index >= count) index = 0;
- *a_index = index;
- if (++total > count) total = count;
- *a_total = total;
- if (verbose > 2)
- fprintf(stderr,"corr=%.6f tot=%d ind=%d\n",correction,total,index);
- }
-
-/* If there is insufficient data yet, use the latest estimates and return
-forthwith. Note that this will not work for broadcasts, but they will be
-disabled in run_daemon(). */
-
- if ((operation == op_listen && total < count && update) || total < 3) {
- *a_drift = 0.0;
- *a_drifterr = -1.0;
- *a_wait = delay;
- return *a_when;
- }
-
-/* Work out the average time, offset, error etc. Note that the dispersion is
-not subject to the central limit theorem. Unfortunately, the variation in the
-source's dispersion is our only indication of how consistent its clock is. */
-
- disp = weight = when = offset = y = 0.0;
- for (i = 0; i < total; ++i) {
- weight += w = record[i].weight;
- when += w*record[i].when;
- offset += w*record[i].offset;
- y += w*record[i].dispersion;
- if (disp < record[i].dispersion)
- disp = record[i].dispersion;
- }
- when /= weight;
- offset /= weight;
- y /= weight;
- if (verbose > 2)
- fprintf(stderr,"disp=%.6f wgt=%.3f when=%.6f off=%.6f\n",
- disp,weight,when,offset);
-
-/* If there is enough data, estimate the drift and errors by regression. Note
-that it is essential to calculate the mean square error, not the mean error. */
-
- error = drift = x = z = 0.0;
- for (i = 0; i < total; ++i) {
- w = record[i].weight/weight;
- x += w*(record[i].when-when)*(record[i].when-when);
- drift += w*(record[i].when-when)*(record[i].offset-offset);
- z += w*(record[i].offset-offset)*(record[i].offset-offset);
- error += w*record[i].error*record[i].error+
- 2.0*w*(record[i].dispersion-y)*(record[i].dispersion-y);
- }
- if (verbose > 2)
- fprintf(stderr,"X2=%.3f XY=%.6f Y2=%.9f E2=%.9f ",x,drift,z,error);
-
-/* When calculating the errors, add some paranoia mainly to check for coding
-errors and complete lunacy, attempting to retry if at all possible. Because
-glitches at this point are so common, log a reset even in non-verbose mode.
-There will be more thorough checks later. Note that we cannot usefully check
-the error for broadcasts. */
-
- z -= drift*drift/x;
- if (verbose > 2) fprintf(stderr,"S2=%.9f\n",z);
- if (! update) {
- if (z > 1.0e6)
- fatal(0,"stored data too unreliable for time estimation",NULL);
- } else if (operation == op_client) {
- e = error+disp*disp+minerr*minerr;
- if (z > e) {
- if (verbose || z >= maxerr*maxerr)
- fprintf(stderr,
- "%s: excessively high error %.3f > %.3f > %.3f\n",
- argv0,sqrt(z),sqrt(e),sqrt(error));
- if (total <= 1)
- return 0.0;
- else if (z < maxerr*maxerr) {
- sprintf(text,"resetting on error %.3g > %.3g",
- sqrt(z),sqrt(e));
- log_message(text);
- return 0.0;
- } else
- fatal(0,"incompatible (i.e. erroneous) timestamps",NULL);
- } else if (z > error && verbose)
- fprintf(stderr,
- "%s: anomalously high error %.3f > %.3f, but < %.3f\n",
- argv0,sqrt(z),sqrt(error),sqrt(e));
- } else {
- if (z > maxerr*maxerr)
- fatal(0,"broadcasts too unreliable for time estimation",NULL);
- }
- drift /= x;
- drifterr = ABSCISSA*sqrt(z/(x*total));
- error = (operation == op_listen ? minerr : 0.0)+ABSCISSA*sqrt(z/total);
- if (verbose > 2)
- fprintf(stderr,"err=%.6f drift=%.6f+/-%.6f\n",error,drift,drifterr);
- if (error+drifterr*delay > NTP_INSANITY)
- fatal(0,"unable to get a reasonable drift estimate",NULL);
-
-/* Estimate the optimal short-loop period, checking it carefully. Remember to
-check that this whole process is likely to be accurate enough and that the
-delay function may be inaccurate. */
-
- wait = delay;
- x = (drift < 0.0 ? -drift : drift);
- if (x*delay < 0.5*minerr) {
- if (verbose > 2) fprintf(stderr,"Drift too small to correct\n");
- } else if (x < 2.0*drifterr) {
- if (verbose > 2)
- fprintf(stderr,"Drift correction suppressed\n");
- } else {
- if ((z = drifterr*delay) < 0.5*minerr) z = 0.5*minerr;
- wait = (x < z/delay ? delay : (int)(z/x+0.5));
- wait = (int)(delay/(int)(delay/(double)wait+0.999)+0.999);
- if (wait > delay)
- fatal(0,"internal error in drift calculation",NULL);
- if (update && (drift*wait > maxerr || wait < RESET_MIN)) {
- sprintf(text,"%.6f+/-%.6f",drift,drifterr);
- fatal(0,"drift correction too large: %s",text);
- }
- }
- if (wait < *a_wait/2) wait = *a_wait/2;
- if (wait > *a_wait*2) wait = *a_wait*2;
-
-/* Now work out what the correction should be, as distinct from what it should
-have been, remembering that older times are less certain. */
-
- now = current_time(JAN_1970);
- x = now-when;
- offset += x*drift;
- error += x*drifterr;
- for (i = 0; i < total; ++i) {
- x = now-record[i].when;
- z = record[i].error+x*drifterr;
- if (z < error) {
- when = record[i].when;
- offset = record[i].offset+x*drift;
- error = z;
- }
- }
- if (verbose > 2)
- fprintf(stderr,"now=%.6f when=%.6f off=%.6f err=%.6f wait=%d\n",
- now,when,offset,error,wait);
-
-/* Finally, return the result. */
-
- *a_disp = disp;
- *a_when = when;
- *a_offset = offset;
- *a_error = error;
- *a_drift = drift;
- *a_drifterr = drifterr;
- *a_wait = wait;
- return now;
-}
+ /* Compute offset etc. */
+ GETTIMEOFDAY(&tv_dst, (struct timezone *)NULL);
+ tv_dst.tv_sec += JAN_1970;
+ tmp = p_rec;
+ L_SUB(&tmp, &p_org);
-double correct_drift (double *a_when, double *a_offset, double drift) {
+ LFPTOD(&tmp, t21);
-/* Correct for the drift since the last time it was done, provided that a long
-enough time has elapsed. And do remember to kludge up the time and
-discrepancy, when appropriate. */
+ TVTOTS(&tv_dst, &dst);
- double d, x;
+ tmp = dst;
+ L_SUB(&tmp, &p_xmt);
- d = current_time(JAN_1970)-*a_when;
- *a_when += d;
- x = *a_offset+d*drift;
- if (verbose > 2)
- fprintf(stderr,"Correction %.6f @ %.6f off=%.6f ",x,*a_when,*a_offset);
- if (d >= waiting && (x < 0.0 ? -x : x) >= 0.5*minerr) {
- if (verbose > 2) fprintf(stderr,"performed\n");
- adjust_time(x,(action == action_reset ? 1 : 0),0.5*minerr);
- *a_offset = 0.0;
- return x;
- } else {
- if (verbose > 2) fprintf(stderr,"ignored\n");
- *a_offset = x;
- return 0.0;
- }
-}
+ LFPTOD(&tmp, t34);
+ offset = (t21 + t34) / 2.;
+ delta = t21 - t34;
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("sntp on_wire:\tt21: %.6f\t\t t34: %.6f\n\t\tdelta: %.6f\t offset: %.6f\n",
+ t21, t34, delta, offset);
-void handle_saving (int operation, int *total, int *index, int *cycle,
- data_record *record, double *previous, double *when, double *correction) {
-
-/* This handles the saving and restoring of the state to a file. While it is
-subject to spoofing, this is not a major security problem. But, out of general
-paranoia, check everything in sight when restoring. Note that this function
-has no external effect if something goes wrong. */
-
- struct {
- data_record record[COUNT_MAX];
- double previous, when, correction;
- int operation, delay, count, total, index, cycle, waiting;
- } buffer;
- double x, y;
- int i, j;
-
- if (savefile == NULL) return;
-
-/* Read the restart file and print its data in diagnostic mode. Note that some
-care is necessary to avoid introducing a security exposure - but we trust the
-C library not to trash the stack on bad numbers! */
-
- if (operation == save_read_only || operation == save_read_check) {
- if (fread(&buffer,sizeof(buffer),1,savefile) != 1 || ferror(savefile)) {
- if (ferror(savefile))
- fatal(1,"unable to read record from daemon save file",NULL);
- else if (verbose)
- fprintf(stderr,"%s: bad daemon restart information\n",argv0);
- return;
- }
- if (verbose > 2) {
- fprintf(stderr,"Reading prev=%.6f when=%.6f corr=%.6f\n",
- buffer.previous,buffer.when,buffer.correction);
- fprintf(stderr,"op=%d dly=%d cnt=%d tot=%d ind=%d cyc=%d wait=%d\n",
- buffer.operation,buffer.delay,buffer.count,buffer.total,
- buffer.index,buffer.cycle,buffer.waiting);
- if (buffer.total < COUNT_MAX)
- for (i = 0; i < buffer.total; ++i)
- fprintf(stderr,
- "disp=%.6f wgt=%.3f when=%.6f off=%.6f err=%.6f\n",
- buffer.record[i].dispersion,buffer.record[i].weight,
- buffer.record[i].when,buffer.record[i].offset,
- buffer.record[i].error);
- }
-
-
-/* Start checking the data for sanity. */
-
- if (buffer.operation == 0 && buffer.delay == 0 && buffer.count == 0) {
- if (operation < 0)
- fatal(0,"the daemon save file has been cleared",NULL);
- if (verbose)
- fprintf(stderr,"%s: restarting from a cleared file\n",argv0);
- return;
- }
- if (operation == save_read_check) {
- if (buffer.operation != operation || buffer.delay != delay ||
- buffer.count != count) {
- if (verbose)
- fprintf(stderr,"%s: different parameters for restart\n",
- argv0);
- return;
- }
- if (buffer.total < 1 || buffer.total > count || buffer.index < 0 ||
- buffer.index >= count || buffer.cycle < 0 ||
- buffer.cycle >= count || buffer.correction < -maxerr ||
- buffer.correction > maxerr || buffer.waiting < RESET_MIN ||
- buffer.waiting > delay || buffer.previous > buffer.when ||
- buffer.previous < buffer.when-count*delay ||
- buffer.when >= *when) {
- if (verbose)
- fprintf(stderr,"%s: corrupted restart information\n",argv0);
- return;
- }
-
-/* Checking the record is even more tedious. */
-
- x = *when;
- y = 0.0;
- for (i = 0; i < buffer.total; ++i) {
- if (buffer.record[i].dispersion < 0.0 ||
- buffer.record[i].dispersion > maxerr ||
- buffer.record[i].weight <= 0.0 ||
- buffer.record[i].weight > 1.001/(minerr*minerr) ||
- buffer.record[i].offset < -count*maxerr ||
- buffer.record[i].offset > count*maxerr ||
- buffer.record[i].error < 0.0 ||
- buffer.record[i].error > maxerr) {
- if (verbose)
- fprintf(stderr,"%s: corrupted restart record\n",argv0);
- return;
- }
- if (buffer.record[i].when < x) x = buffer.record[i].when;
- if (buffer.record[i].when > y) y = buffer.record[i].when;
- }
-
-/* Check for consistency and, finally, whether this is too old. */
-
- if (y > buffer.when || y-x < (buffer.total-1)*delay ||
- y-x > (buffer.total-1)*count*delay) {
- if (verbose)
- fprintf(stderr,"%s: corrupted restart times\n",argv0);
- return;
- }
- if (buffer.when < *when-count*delay) {
- if (verbose)
- fprintf(stderr,"%s: restart information too old\n",argv0);
- return;
- }
- }
-
-/* If we get here, just copy the data back. */
-
- memcpy(record,buffer.record,sizeof(buffer.record));
- *previous = buffer.previous;
- *when = buffer.when;
- *correction = buffer.correction;
- *total = buffer.total;
- *index = buffer.index;
- *cycle = buffer.cycle;
- waiting = buffer.waiting;
- memset(&buffer,0,sizeof(buffer));
-
-/* Print out the data if requested. */
-
- if (verbose > 1) {
- fprintf(stderr,"%s: prev=%.3f when=%.3f corr=%.3f\n",
- argv0,*previous,*when,*correction);
- for (i = 0; i < *total; ++i) {
- if ((j = i+*index-*total) < 0) j += *total;
- fprintf(stderr,"%s: when=%.3f disp=%.3f off=%.3f",
- argv0,record[j].when,record[j].dispersion,record[j].offset);
- if (operation == op_client)
- fprintf(stderr," err=%.3f\n",record[j].error);
- else
- fprintf(stderr,"\n");
- }
- }
-
-/* All errors on output are fatal. */
-
- } else if (operation == save_write) {
- memcpy(buffer.record,record,sizeof(buffer.record));
- buffer.previous = *previous;
- buffer.when = *when;
- buffer.correction = *correction;
- buffer.operation = operation;
- buffer.delay = delay;
- buffer.count = count;
- buffer.total = *total;
- buffer.index = *index;
- buffer.cycle = *cycle;
- buffer.waiting = waiting;
- if (fseek(savefile,0l,SEEK_SET) != 0 ||
- fwrite(&buffer,sizeof(buffer),1,savefile) != 1 ||
- fflush(savefile) != 0 || ferror(savefile))
- fatal(1,"unable to write record to daemon save file",NULL);
- if (verbose > 2) {
- fprintf(stderr,"Writing prev=%.6f when=%.6f corr=%.6f\n",
- *previous,*when,*correction);
- fprintf(stderr,"op=%d dly=%d cnt=%d tot=%d ind=%d cyc=%d wait=%d\n",
- operation,delay,count,*total,*index,*cycle,waiting);
- if (*total < COUNT_MAX)
- for (i = 0; i < *total; ++i)
- fprintf(stderr,
- "disp=%.6f wgt=%.3f when=%.6f off=%.6f err=%.6f\n",
- record[i].dispersion,record[i].weight,
- record[i].when,record[i].offset,record[i].error);
- }
-
-/* Clearing the save file is similar. */
-
- } else if (operation == save_clear) {
- memset(&buffer, 0, sizeof(buffer));
-
- if (fseek(savefile,0l,SEEK_SET) != 0 ||
- fwrite(&buffer,sizeof(buffer),1,savefile) != 1 ||
- fflush(savefile) != 0 || ferror(savefile))
- fatal(1,"unable to clear daemon save file",NULL);
- } else
- fatal(0,"internal error in handle_saving",NULL);
-}
+ ts_str = tv_to_str(&tv_dst);
+ printf("%s ", ts_str);
+ if(offset > 0)
+ printf("+");
+
+ printf("%.3f\n", offset);
+ free(ts_str);
-void query_savefile (void) {
+ if(ENABLED_OPT(SETTOD) || ENABLED_OPT(ADJTIME))
+ return set_time(offset);
-/* This queries a daemon save file. */
+ return 0;
+ }
+ }
- double previous, when, correction = 0.0, offset = 0.0, error = -1.0,
- drift = 0.0, drifterr = -1.0;
- data_record record[COUNT_MAX];
- int total = 0, index = 0, cycle = 0;
- char text[100];
+ char logmsg[32 + INET6_ADDRSTRLEN];
+ getnameinfo(host->ai_addr, host->ai_addrlen, adr_buf, sizeof(adr_buf), NULL, 0, NI_NUMERICHOST);
-/* This is a few lines stripped out of run_daemon() and slightly hacked. */
+ snprintf(logmsg, sizeof(logmsg), "Received no useable packet from %s!", adr_buf);
- previous = when = current_time(JAN_1970);
- if (verbose > 2) {
- format_time(text,50,0.0,-1.0,0.0,-1.0,-10);
- fprintf(stderr,"Started=%.6f %s\n",when,text);
- }
- handle_saving(save_read_only,&total,&index,&cycle,record,&previous,&when,
- &correction);
- estimate_stats(&total,&index,record,correction,&dispersion,
- &when,&offset,&error,&drift,&drifterr,&waiting,0);
- format_time(text,100,offset,error,drift,drifterr,-10);
- printf("%s\n",text);
- if (fclose(savefile)) fatal(1,"unable to close daemon save file",NULL);
- if (verbose > 2) fprintf(stderr,"Stopped normally\n");
- exit(EXIT_SUCCESS);
-}
+ if(ENABLED_OPT(NORMALVERBOSE))
+ printf("sntp on_wire: Received no useable packet from %s!\n", adr_buf);
+ log_msg(logmsg, 1);
-void run_daemon (char *hostnames[], int nhosts, int initial) {
-
-/* This does not adjust the time between calls to the server, but it does
-adjust the time between clock resets. This function will survive short periods
-of server inaccessibility or network glitches, but not long ones, and will then
-need restarting manually.
-
-It is far too complex for a single function, but could really only be
-simplified by making most of its variables global or by a similarly horrible
-trick. Oh, for nested scopes as in Algol 68! */
-
- double history[COUNT_MAX], started, previous, when, correction = 0.0,
- weeble = 1.0, accepts = 0.0, rejects = 0.0, flushes = 0.0,
- replicates = 0.0, skips = 0.0, offset = 0.0, error = -1.0,
- drift = 0.0, drifterr = -1.0, maxoff = 0.0, x;
- data_record record[COUNT_MAX];
- int total = 0, index = 0, item = 0, rej_level = 0, rep_level = 0,
- cycle = 0, retry = 1, i, j, k;
- unsigned char transmit[NTP_PACKET_MIN];
- ntp_data data;
- char text[100];
-
-/* After initialising, restore from a previous run if possible. Note that
-only a few of the variables are actually needed to control the operation and
-the rest are mainly for diagnostics. */
-
- started = previous = when = current_time(JAN_1970);
- if (verbose > 2) {
- format_time(text,50,0.0,-1.0,0.0,-1.0,-10);
- fprintf(stderr,"Started=%.6f %s\n",when,text);
- }
- if (initial) {
- handle_saving(save_read_check,&total,&index,&cycle,record,
- &previous,&when,&correction);
- cycle = (nhosts > 0 ? cycle%nhosts : 0);
- if (total > 0 && started-previous < delay) {
- if (verbose > 2) fprintf(stderr,"Last packet too recent\n");
- retry = 0;
- }
- if (verbose > 2)
- fprintf(stderr,"prev=%.6f when=%.6f retry=%d\n",
- previous,when,retry);
- for (i = 0; i < nhosts; ++i) open_socket(i,hostnames[i],delay);
- if (action != action_display) {
- set_lock(1);
- locked = 1;
- }
- }
- dispersion = 0.0;
- attempts = 0;
- for (i = 0; i < count; ++i) history[i] = 0.0;
- while (1) {
-
-/* Print out a reasonable amount of diagnostics, rather like a server. Note
-that it may take a little time, but shouldn't affect the estimates much. Then
-check that we aren't in a failing loop. */
-
- if (verbose > 2) fprintf(stderr,"item=%d rej=%d\n",item,rej_level);
- x = current_time(JAN_1970)-started;
- if (verbose &&
- x/3600.0+accepts+rejects+flushes+replicates+skips >= weeble) {
- weeble *= WEEBLE_FACTOR;
- x -= 3600.0*(i = (int)(x/3600.0));
- x -= 60.0*(j = (int)(x/60.0));
- if (i > 0)
- fprintf(stderr,"%s: after %d hours %d mins ",argv0,i,j);
- else if (j > 0)
- fprintf(stderr,"%s: after %d mins %.0f secs ",argv0,j,x);
- else
- fprintf(stderr,"%s: after %.1f secs ",argv0,x);
- fprintf(stderr,"acc. %.0f rej. %.0f flush %.0f",
- accepts,rejects,flushes);
- if (operation == op_listen)
- fprintf(stderr," rep. %.0f skip %.0f",replicates,skips);
- fprintf(stderr," max.off. %.3f corr. %.3f\n",maxoff,correction);
- format_time(text,100,offset,error,drift,drifterr,-10);
- fprintf(stderr,"%s: %s\n",argv0,text);
- maxoff = 0.0;
- }
- if (current_time(JAN_1970)-previous > count*delay) {
- if (verbose)
- fprintf(stderr,"%s: no packets in too long a period\n",argv0);
- return;
- }
-
-/* Listen for the next broadcast packet. This allows up to ETHERNET_MAX
-replications per packet, for systems with multiple addresses for receiving
-broadcasts; the only reason for a limit is to protect against broken NTP
-servers always returning the same time. */
-
- if (operation == op_listen) {
- flushes += flush_socket(0);
- if (read_packet(0,&data,&offset,&error)) {
- ++rejects;
- if (++rej_level > count)
- fatal(0,"too many bad or lost packets",NULL);
- if (action != action_display && drifterr >= 0.0) {
- correction += correct_drift(&when,&offset,drift);
- handle_saving(save_write,&total,&index,&cycle,record,
- &previous,&when,&correction);
- }
- continue;
- }
- if ((rej_level -= (count < 5 ? count : 5)) < 0) rej_level = 0;
- x = data.transmit;
- for (i = 0; i < count; ++i)
- if (x == history[i]) {
- ++replicates;
- if (++rep_level > ETHERNET_MAX)
- fatal(0,"too many replicated packets",NULL);
- goto continue1;
- }
- rep_level = 0;
- history[item] = x;
- if (++item >= count) item = 0;
-
-/* Accept a packet only after a long enough period has elapsed. */
-
- when = data.current;
- if (! retry && when < previous+delay) {
- if (verbose > 2) fprintf(stderr,"Skipping too recent packet\n");
- ++skips;
- continue;
- }
- retry = 0;
- if (verbose > 2)
- fprintf(stderr,"Offset=%.6f @ %.6f disp=%.6f\n",
- offset,when,dispersion);
-
-/* Handle the client/server model. It keeps a record of transmitted times,
-mainly out of paranoia. The waiting time is kludged up to attempt to provide
-reasonable resilience against both lost packets and dead servers. But it
-won't handle much of either, and will stop after a while, needing manual
-restarting. Running it under cron is the best approach. */
-
- } else {
- if (! retry) {
- if (verbose > 2) fprintf(stderr,"Sleeping for %d\n",waiting);
- do_nothing(waiting);
- }
- make_packet(&data,NTP_CLIENT);
- outgoing[item] = data.transmit;
- if (++item >= 2*count) item = 0;
- if (attempts < 2*count) ++attempts;
- if (verbose > 2) {
- fprintf(stderr,"Outgoing packet on socket %d:\n",cycle);
- display_data(&data);
- }
- pack_ntp(transmit,NTP_PACKET_MIN,&data);
- if (verbose > 2) display_packet(transmit,NTP_PACKET_MIN);
- flushes += flush_socket(cycle);
- write_socket(cycle,transmit,NTP_PACKET_MIN);
-
-/* Read the packet and check that it is an appropriate response. Because this
-is rather more numerically sensitive than simple resynchronisation, reject all
-very inaccurate packets. Be careful if you modify this, because the error
-handling is rather nasty to avoid replicating code. */
-
- k = read_packet(cycle,&data,&offset,&error);
- if (++cycle >= nhosts) cycle = 0;
- if (! k)
- when = (data.originate+data.current)/2.0;
- else if (action != action_display && drifterr >= 0.0) {
- correction += correct_drift(&when,&offset,drift);
- handle_saving(save_write,&total,&index,&cycle,record,
- &previous,&when,&correction);
- }
- if (! k && ! retry && when < previous+delay-2) {
- if (verbose)
- fprintf(stderr,"%s: packets out of order on socket %d\n",
- argv0,cycle);
- k = 1;
- }
- if (! k && data.current-data.originate > maxerr) {
- if (verbose)
- fprintf(stderr,
- "%s: very slow response rejected on socket %d\n",
- argv0,cycle);
- k = 1;
- }
-
-/* Count the number of rejected packets and fail if there are too many. */
-
- if (k) {
- ++rejects;
- if (++rej_level > count)
- fatal(0,"too many bad or lost packets",NULL);
- else {
- retry = 1;
- continue;
- }
- } else
- retry = 0;
- if ((rej_level -= (count < 5 ? count : 5)) < 0) rej_level = 0;
- if (verbose > 2)
- fprintf(stderr,"Offset=%.6f+/-%.6f @ %.6f disp=%.6f\n",
- offset,error,when,dispersion);
- }
-
-/* Calculate the statistics, and display the results or make the initial
-correction. Note that estimate_stats() will return zero if a timestamp
-indicates synchronisation loss (usually due to down time or a change of server,
-somewhere upstream), and that the recovery operation is unstructured, so great
-care should be taken when modifying it. Also, we want to clear the saved state
-is the statistics are bad. */
-
- handle_saving(save_clear,&total,&index,&cycle,record,&previous,&when,
- &correction);
- ++accepts;
- dispersion = data.dispersion;
- previous = when =
- estimate_stats(&total,&index,record,correction,&dispersion,
- &when,&offset,&error,&drift,&drifterr,&waiting,1);
- if (verbose > 2) {
- fprintf(stderr,"tot=%d ind=%d dis=%.3f when=%.3f off=%.3f ",
- total,index,dispersion,when,offset);
- fprintf(stderr,"err=%.3f wait=%d\n",error,waiting);
- }
- if (when == 0.0) return;
- x = (maxoff < 0.0 ? -maxoff : maxoff);
- if ((offset < 0.0 ? -offset : offset) > x) maxoff = offset;
- correction = 0.0;
- if (operation == op_client || accepts >= count) {
- if (action == action_display) {
- format_time(text,100,offset,error,drift,drifterr,-10);
- printf("%s\n",text);
- } else {
- x = reset_clock(offset,error,1);
- correction += x;
- offset -= x;
- }
- } else
- waiting = delay;
- handle_saving(save_write,&total,&index,&cycle,record,&previous,&when,
- &correction);
-
-/* Now correct the clock for a while, before getting another packet and
-updating the statistics. */
-
- while (when < previous+delay-waiting) {
- do_nothing(waiting);
- if (action == action_display)
- when += waiting;
- else {
- correction += correct_drift(&when,&offset,drift);
- handle_saving(save_write,&total,&index,&cycle,record,
- &previous,&when,&correction);
- }
- }
-continue1: ;
- }
+ return -1;
}
-
-
-void run_client (char *hostnames[], int nhosts) {
-
-/* Get enough responses to do something with; or not, as the case may be. Note
-that it allows for half of the packets to be bad, so may make up to twice as
-many attempts as specified by the -c value. The deadline checking is merely
-paranoia, to protect against broken signal handling - it cannot easily be
-triggered if the signal handling works. */
-
- double history[COUNT_MAX], guesses[COUNT_MAX], offset, error, deadline,
- a, b, x, y;
- int precs[COUNT_MAX], precision = 0;
- int accepts = 0, rejects = 0, flushes = 0, replicates = 0, cycle = 0, k;
- unsigned char transmit[NTP_PACKET_MIN];
- ntp_data data;
- char text[100];
-
- guesses[0] = 0;
- precs[0] = 0;
-
- if (verbose > 2) {
- format_time(text,50,0.0,-1.0,0.0,-1.0,-10);
- fprintf(stderr,"Started=%.6f %s\n",current_time(JAN_1970),text);
- }
- for (k = 0; k < nhosts; ++k) open_socket(k,hostnames[k],delay);
- if (action != action_display) {
- set_lock(1);
- locked = 1;
- }
- attempts = 0;
- deadline = current_time(JAN_1970)+delay;
-
-/* Listen to broadcast packets and select the best (i.e. earliest). This will
-be sensitive to a bad NTP broadcaster, but I believe such things are very rare
-in practice. In any case, if you have one, it is probably the only one on your
-subnet, so you are knackered! This allows up to ETHERNET_MAX replications per
-packet, for systems with multiple addresses for receiving broadcasts; the only
-reason for a limit is to protect against broken NTP servers always returning
-the same time. */
-
- if (operation == op_listen) {
- while (accepts < count) {
- if (current_time(JAN_1970) > deadline)
- fatal(0,"not enough valid broadcasts received in time",NULL);
- flushes += flush_socket(0);
- if (read_packet(0,&data,&x,&y)) {
- if (++rejects > count)
- fatal(0,"too many bad or lost packets",NULL);
- else
- continue;
- } else {
- a = data.transmit;
- for (k = 0; k < accepts; ++k)
- if (a == history[k]) {
- if (++replicates > ETHERNET_MAX*count)
- fatal(0,"too many replicated packets",NULL);
- goto continue1;
- }
- history[accepts] = a;
- precs[accepts] = data.precision;
- guesses[accepts++] = x;
- }
- if (verbose > 2)
- fprintf(stderr,"Offset=%.6f disp=%.6f\n",x,dispersion);
- else if (verbose > 1)
- fprintf(stderr,"%s: offset=%.3f disp=%.3f\n",
- argv0,x,dispersion);
-
-/* Note that bubblesort IS a good method for this amount of data. */
-
- for (k = accepts-2; k >= 0; --k)
- if (guesses[k] < guesses[k+1])
- break;
- else {
- x = guesses[k];
- guesses[k] = guesses[k+1];
- guesses[k+1] = x;
- precision = precs[k];
- precs[k] = precs[k+1];
- precs[k+1] = precision;
- }
-continue1: ;
- }
- offset = guesses[0];
- precision = precs[0];
- error = minerr+guesses[count <= 5 ? count-1 : 5]-offset;
- if (verbose > 2)
- fprintf(stderr,"accepts=%d rejects=%d flushes=%d replicates=%d\n",
- accepts,rejects,flushes,replicates);
-
-/* Handle the client/server model. It keeps a record of transmitted times,
-mainly out of paranoia. */
-
- } else {
- offset = 0.0;
- precision = 0;
- error = NTP_INSANITY;
- while (accepts < count && attempts < 2*count) {
- if (current_time(JAN_1970) > deadline)
- fatal(0,"not enough valid responses received in time",NULL);
- make_packet(&data,NTP_CLIENT);
- precs[attempts] = data.precision;
- outgoing[attempts++] = data.transmit;
- if (verbose > 2) {
- fprintf(stderr,"Outgoing packet on socket %d:\n",cycle);
- display_data(&data);
- }
- pack_ntp(transmit,NTP_PACKET_MIN,&data);
- if (verbose > 2) display_packet(transmit,NTP_PACKET_MIN);
- flushes += flush_socket(cycle);
- write_socket(cycle,transmit,NTP_PACKET_MIN);
- if (read_packet(cycle,&data,&x,&y)) {
- if (++rejects > count)
- fatal(0,"too many bad or lost packets",NULL);
- else
- continue;
- } else
- ++accepts;
- if (++cycle >= nhosts) cycle = 0;
-
-/* Work out the most accurate time, and check that it isn't more accurate than
-the results warrant. */
-
- if (verbose > 2)
- fprintf(stderr,"Offset=%.6f+/-%.6f disp=%.6f\n",x,y,dispersion);
- else if (verbose > 1)
- fprintf(stderr,"%s: offset=%.3f+/-%.3f disp=%.3f\n",
- argv0,x,y,dispersion);
- if ((a = x-offset) < 0.0) a = -a;
- if (accepts <= 1) a = 0.0;
- b = error+y;
- if (y < error) {
- offset = x;
- error = y;
- precision = data.precision;
- }
- if (verbose > 2)
- fprintf(stderr,"best=%.6f+/-%.6f\n",offset,error);
- if (a > b) {
- sprintf(text,"%d",cycle);
- fatal(0,"inconsistent times got from NTP server on socket %s",
- text);
- }
- if (error <= minerr) break;
- }
- if (verbose > 2)
- fprintf(stderr,"accepts=%d rejects=%d flushes=%d\n",
- accepts,rejects,flushes);
- }
-
-/* Tidy up the socket, issues diagnostics and perform the action. */
-
- for (k = 0; k < nhosts; ++k) close_socket(k);
- if (accepts == 0) fatal(0,"no acceptable packets received",NULL);
- if (error > NTP_INSANITY)
- fatal(0,"unable to get a reasonable time estimate",NULL);
- if (verbose > 2)
- fprintf(stderr,"Correction: %.6f +/- %.6f disp=%.6f\n",
- offset,error,dispersion);
- if (action == action_display) {
- format_time(text,75,offset,error,0.0,-1.0,precision);
- printf("%s\n",text);
- } else
- (void)reset_clock(offset,error,0);
- if (locked) set_lock(0);
- if (verbose > 2) fprintf(stderr,"Stopped normally\n");
- exit(EXIT_SUCCESS);
+/* Compute the 8 bits for li_vn_mode */
+void
+set_li_vn_mode (
+ struct pkt *spkt,
+ char leap,
+ char version,
+ char mode
+ )
+{
+
+ if(leap > 3) {
+ debug_msg("set_li_vn_mode: leap > 3 using max. 3");
+ leap = 3;
+ }
+
+ if(mode > 7) {
+ debug_msg("set_li_vn_mode: mode > 7, using client mode 3");
+ mode = 3;
+ }
+
+ spkt->li_vn_mode = leap << 6;
+ spkt->li_vn_mode |= version << 3;
+ spkt->li_vn_mode |= mode;
}
-
-
-int main (int argc, char *argv[]) {
-
-/* This is the entry point and all that. It decodes the arguments and calls
-one of the specialised routines to do the work. */
-
- char *hostnames[MAX_SOCKETS], *savename = NULL;
- int daemon = 0, nhosts = 0, help = 0, args = argc-1, k;
- char c;
-
- if (argv[0] == NULL || argv[0][0] == '\0')
- argv0 = "sntp";
- else if ((argv0 = strrchr(argv[0],'/')) != NULL)
- ++argv0;
- else
- argv0 = argv[0];
-
- setvbuf(stdout,NULL,_IOLBF,BUFSIZ);
- setvbuf(stderr,NULL,_IOLBF,BUFSIZ);
-
- if (INT_MAX < 2147483647) fatal(0,"sntp requires >= 32-bit ints",NULL);
- if (DBL_EPSILON > 1.0e-13)
- fatal(0,"sntp requires doubles with eps <= 1.0e-13",NULL);
- for (k = 0; k < MAX_SOCKETS; ++k) hostnames[k] = NULL;
-
-/* Decode the arguments. */
-
- while (argc > 1) {
- k = 1;
- if (strcmp(argv[1],"-4") == 0)
- preferred_family(PREF_FAM_INET);
- else if (strcmp(argv[1],"-6") == 0)
- preferred_family(PREF_FAM_INET6);
- else if (strcmp(argv[1],"-u") == 0)
- ++unprivport;
- else if (strcmp(argv[1],"-q") == 0 && action == 0)
- action = action_query;
- else if (strcmp(argv[1],"-r") == 0 && action == 0)
- action = action_reset;
- else if (strcmp(argv[1],"-a") == 0 && action == 0)
- action = action_adjust;
- else if (strcmp(argv[1],"-l") == 0 && lockname == NULL && argc > 2) {
- lockname = argv[2];
- k = 2;
- } else if ((strcmp(argv[1],"-x") == 0) &&
- daemon == 0) {
- if (argc > 2 && sscanf(argv[2],"%d%c",&daemon,&c) == 1) {
- if (daemon < 1 || daemon > 1440)
- fatal(0,"%s option value out of range",argv[1]);
- k = 2;
- } else
- daemon = 300;
- } else if (strcmp(argv[1],"-f") == 0 && savename == NULL && argc > 2) {
- savename = argv[2];
- k = 2;
- } else if ((strcmp(argv[1],"--help") == 0 ||
- strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"-?") == 0) &&
- help == 0)
- help = 1;
- else if (strcmp(argv[1],"-v") == 0 && verbose == 0)
- verbose = 1;
- else if (strcmp(argv[1],"-V") == 0 && verbose == 0)
- verbose = 2;
- else if (strcmp(argv[1],"-W") == 0 && verbose == 0)
- verbose = 3;
- else if (strcmp(argv[1],"-e") == 0 && minerr == 0.0 && argc > 2) {
- if (sscanf(argv[2],"%lf%c",&minerr,&c) != 1) syntax(1);
- if (minerr <= 0.000999999 || minerr > 1.0)
- fatal(0,"%s option value out of range","-e");
- k = 2;
- } else if (strcmp(argv[1],"-E") == 0 && maxerr == 0.0 && argc > 2) {
- if (sscanf(argv[2],"%lf%c",&maxerr,&c) != 1) syntax(1);
- if (maxerr < 1.0 || maxerr > 60.0)
- fatal(0,"%s option value out of range","-E");
- k = 2;
- } else if (strcmp(argv[1],"-P") == 0 && prompt == 0.0 && argc > 2) {
- if (strcmp(argv[2],"no") == 0)
- prompt = (double)INT_MAX;
- else {
- if (sscanf(argv[2],"%lf%c",&prompt,&c) != 1) syntax(1);
- if (prompt < 1.0 || prompt > 3600.0)
- fatal(0,"%s option value out of range","-p");
- }
- k = 2;
- } else if (strcmp(argv[1],"-d") == 0 && delay == 0 && argc > 2) {
- if (sscanf(argv[2],"%d%c",&delay,&c) != 1) syntax(1);
- if (delay < 1 || delay > 3600)
- fatal(0,"%s option value out of range","-d");
- k = 2;
- } else if (strcmp(argv[1],"-c") == 0 && count == 0 && argc > 2) {
- if (sscanf(argv[2],"%d%c",&count,&c) != 1) syntax(1);
- if (count < 1 || count > COUNT_MAX)
- fatal(0,"%s option value out of range","-c");
- k = 2;
- } else
- break;
- argc -= k;
- argv += k;
- }
-
-/* Check the arguments for consistency and set the defaults. */
-
- if (action == action_query) {
- if (argc != 1 || minerr != 0.0 || maxerr != 0.0 || count != 0 ||
- delay != 0 || daemon != 0 || prompt != 0.0 || lockname != NULL)
- syntax(1);
- } else {
- if (argc < 1 || argc > MAX_SOCKETS || (daemon != 0 && delay != 0))
- syntax(1);
- if ((prompt || lockname != NULL) &&
- action != action_reset && action != action_adjust)
- syntax(1);
- if (count > 0 && count < argc-1)
- fatal(0,"-c value less than number of addresses",NULL);
- if (argc > 1) {
- operation = op_client;
- for (k = 1; k < argc; ++k) {
- if (argv[k][0] == '\0' || argv[k][0] == '-')
- fatal(0,"invalid Internet address '%s'",argv[k]);
- hostnames[k-1] = argv[k];
- }
- nhosts = argc-1;
- } else {
- operation = op_listen;
- nhosts = 0;
- }
- if (action == 0) action = action_display;
- if (minerr <= 0.0) minerr = (operation == op_listen ? 0.5 : 0.1);
- if (maxerr <= 0.0) maxerr = 5.0;
- if (count == 0) count = (argc-1 < 5 ? 5 : argc-1);
- if ((argc == 1 || (daemon != 0 && action != action_query)) && count < 5)
- fatal(0,"at least 5 packets needed in this mode",NULL);
- if ((action == action_reset || action == action_adjust) &&
- lockname == NULL)
- lockname = LOCKNAME;
-
-/* The '-x' option changes the implications of many other settings, though this
-is not usually apparent to the caller. Most of the time delays are to ensure
-that stuck states terminate, and do not affect the result. */
-
- if (daemon != 0) {
- if (minerr >= maxerr || maxerr >= daemon)
- fatal(0,"values not in order -e < -E < -x",NULL);
- waiting = delay = daemon *= 60;
- } else {
- if (savename != NULL)
- fatal(0,"-f can be specified only with -x",NULL);
- if (delay == 0)
- delay = (operation == op_listen ? 300 :
- (2*count >= 15 ? 2*count+1 :15));
- if (operation == op_listen) {
- if (minerr >= maxerr || maxerr >= delay/count)
- fatal(0,"values not in order -e < -E < -d/-c",NULL);
- } else {
- if (minerr >= maxerr || maxerr >= delay)
- fatal(0,"values not in order -e < -E < -d",NULL);
- }
- if (2*count >= delay) fatal(0,"-c must be less than half -d",NULL);
- waiting = delay/count;
- }
- if (prompt == 0.0) prompt = 30.0;
- }
- if ((daemon || action == action_query) && savename == NULL)
- savename = SAVENAME;
-
-/* Diagnose where we are, if requested, and separate out the classes of
-operation. The calls do not return. */
-
- if (help) syntax(args == 1);
- if (verbose) {
- fprintf(stderr,"%s options: a=%d v=%d e=%.3f E=%.3f P=%.3f\n",
- argv0,action,verbose,minerr,maxerr,prompt);
- fprintf(stderr," d=%d c=%d %c=%d op=%d l=%s f=%s",
- delay,count,'x',daemon,operation,
- (lockname == NULL ? "" : lockname),
- (savename == NULL ? "" : savename));
- for (k = 0; k < MAX_SOCKETS; ++k)
- if (hostnames[k] != NULL) fprintf(stderr," %s",hostnames[k]);
- fprintf(stderr,"\n");
- }
- if (nhosts == 0) nhosts = 1; /* Kludge for broadcasts */
- if (action == action_query) {
- if (savename == NULL || savename[0] == '\0')
- fatal(0,"no daemon save file specified",NULL);
- else if ((savefile = fopen(savename,"rb")) == NULL)
- fatal(0,"unable to open the daemon save file",NULL);
- query_savefile();
- } else if (daemon != 0) {
- if (savename != NULL && savename[0] != '\0' &&
- (savefile = fopen(savename,"rb+")) == NULL &&
- (savefile = fopen(savename,"wb+")) == NULL)
- fatal(0,"unable to open the daemon save file",NULL);
- run_daemon(hostnames,nhosts,1);
- while (1) run_daemon(hostnames,nhosts,0);
- } else
- run_client(hostnames,nhosts);
- fatal(0,"internal error at end of main",NULL);
- return EXIT_FAILURE;
+/* set_time corrects the local clock by offset with either settimeofday() or by default
+ * with adjtime()/adjusttimeofday().
+ */
+int
+set_time (
+ double offset
+ )
+{
+ struct timeval tp;
+
+ if(ENABLED_OPT(SETTOD)) {
+ GETTIMEOFDAY(&tp, (struct timezone *)NULL);
+
+ tp.tv_sec += (int) offset;
+ tp.tv_usec += offset - (double)((int)offset);
+
+ if(SETTIMEOFDAY(&tp, (struct timezone *)NULL) < 0) {
+ if(errno == EPERM)
+ printf("set_time: You don't have enough priviledges to call settimeofday(), cannot set time!\n");
+
+ else
+ printf("set_time: settimeofday() returned with an error, couldn't set time!\n");
+
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ tp.tv_sec = (int) offset;
+ tp.tv_usec = offset - (double)((int)offset);
+
+ if(ADJTIMEOFDAY(&tp, NULL) < 0) {
+ if(errno == EPERM)
+ printf("set_time: You don't have enough priviledges to call adjtime(), cannot set time!\n");
+ else
+ printf("set_time: adjtime() returned with an error, couldn't set time!\n");
+
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ }
}
/*
* EDIT THIS FILE WITH CAUTION (sntp-opts.c)
*
- * It has been AutoGen-ed August 9, 2009 at 07:53:59 AM by AutoGen 5.9.9pre5
+ * It has been AutoGen-ed August 9, 2009 at 07:52:56 AM by AutoGen 5.9.9pre5
* From the definitions sntp-opts.def
* and the template file options
*
*
* This source file is copyrighted and licensed under the following terms:
*
- * sntp copyright (c) 1970-2006 ntp.org - all rights reserved
+ * sntp copyright (c) 2008 ntp.org - all rights reserved
*
- * General Public Licence for the software known as MSNTP
- * ------------------------------------------------------
*
- * (c) Copyright, N.M. Maclaren, 1996, 1997, 2000
- * (c) Copyright, University of Cambridge, 1996, 1997, 2000
- *
- *
- *
- * Free use of MSNTP in source and binary forms is permitted, provided that this
- * entire licence is duplicated in all copies, and that any documentation,
- * announcements, and other materials related to use acknowledge that the software
- * was developed by N.M. Maclaren (hereafter refered to as the Author) at the
- * University of Cambridge. Neither the name of the Author nor the University of
- * Cambridge may be used to endorse or promote products derived from this material
- * without specific prior written permission.
- *
- * The Author and the University of Cambridge retain the copyright and all other
- * legal rights to the software and make it available non-exclusively. All users
- * must ensure that the software in all its derivations carries a copyright notice
- * in the form:
- * (c) Copyright N.M. Maclaren,
- * (c) Copyright University of Cambridge.
- *
- *
- *
- * NO WARRANTY
- *
- * Because the MSNTP software is licensed free of charge, the Author and the
- * University of Cambridge provide absolutely no warranty, 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 MSNTP software is with you. Should MSNTP
- * prove defective, you assume the cost of all necessary servicing or repair.
- *
- * In no event, unless required by law, will the Author or the University of
- * Cambridge, or any other party who may modify and redistribute this software as
- * permitted in accordance with the provisions below, be liable for damages for
- * any losses whatsoever, including but not limited to lost profits, lost monies,
- * lost or corrupted data, or other special, incidental or consequential losses
- * that may arise out of the use or inability to use the MSNTP software.
- *
- *
- *
- * COPYING POLICY
- *
- * Permission is hereby granted for copying and distribution of copies of the
- * MSNTP source and binary files, and of any part thereof, subject to the
- * following licence conditions:
- *
- * 1. You may distribute MSNTP or components of MSNTP, with or without additions
- * developed by you or by others. No charge, other than an "at-cost" distribution
- * fee, may be charged for copies, derivations, or distributions of this material
- * without the express written consent of the copyright holders.
- *
- * 2. You may also distribute MSNTP along with any other product for sale,
- * provided that the cost of the bundled package is the same regardless of whether
- * MSNTP is included or not, and provided that those interested only in MSNTP must
- * be notified that it is a product freely available from the University of
- * Cambridge.
- *
- * 3. If you distribute MSNTP software or parts of MSNTP, with or without
- * additions developed by you or others, then you must either make available the
- * source to all portions of the MSNTP system (exclusive of any additions made by
- * you or by others) upon request, or instead you may notify anyone requesting
- * source that it is freely available from the University of Cambridge.
- *
- * 4. You may not omit any of the copyright notices on either the source files,
- * the executable files, or the documentation.
- *
- * 5. You may not omit transmission of this License agreement with whatever
- * portions of MSNTP that are distributed.
- *
- * 6. Any users of this software must be notified that it is without warranty or
- * guarantee of any nature, express or implied, nor is there any fitness for use
- * represented.
- *
- *
- * October 1996
- * April 1997
- * October 2000
*/
#include <sys/types.h>
/* TRANSLATORS: choose the translation for option names wisely because you
cannot ever change your mind. */
tSCC zCopyright[] =
- "sntp copyright (c) 1970-2006 ntp.org, all rights reserved"
-/* extracted from sntp-opts.def near line 12 */
+ "sntp copyright (c) 2008 ntp.org, all rights reserved"
+/* extracted from sntp-opts.def near line 17 */
;
-tSCC zCopyrightNotice[3602] =
-"General Public Licence for the software known as MSNTP\n\
-------------------------------------------------------\n\n\
-(c) Copyright, N.M. Maclaren, 1996, 1997, 2000 (c) Copyright, University of\n\
-Cambridge, 1996, 1997, 2000\n\n\n\n\
-Free use of MSNTP in source and binary forms is permitted, provided that this\n\
-entire licence is duplicated in all copies, and that any documentation,\n\
-announcements, and other materials related to use acknowledge that the software\n\
-was developed by N.M. Maclaren (hereafter refered to as the Author) at the\n\
-University of Cambridge. Neither the name of the Author nor the University of\n\
-Cambridge may be used to endorse or promote products derived from this material\n\
-without specific prior written permission.\n\n\
-The Author and the University of Cambridge retain the copyright and all other\n\
-legal rights to the software and make it available non-exclusively. All users\n\
-must ensure that the software in all its derivations carries a copyright notice\n\
-in the form: (c) Copyright N.M. Maclaren, (c) Copyright University of\n\
-Cambridge.\n\n\n\n\
-NO WARRANTY\n\n\
-Because the MSNTP software is licensed free of charge, the Author and the\n\
-University of Cambridge provide absolutely no warranty, either expressed or\n\
-implied, including, but not limited to, the implied warranties of\n\
-merchantability and fitness for a particular purpose. The entire risk as to\n\
-the quality and performance of the MSNTP software is with you. Should MSNTP\n\
-prove defective, you assume the cost of all necessary servicing or repair.\n\n\
-In no event, unless required by law, will the Author or the University of\n\
-Cambridge, or any other party who may modify and redistribute this software as\n\
-permitted in accordance with the provisions below, be liable for damages for\n\
-any losses whatsoever, including but not limited to lost profits, lost monies,\n\
-lost or corrupted data, or other special, incidental or consequential losses\n\
-that may arise out of the use or inability to use the MSNTP software.\n\n\n\n\
-COPYING POLICY\n\n\
-Permission is hereby granted for copying and distribution of copies of the\n\
-MSNTP source and binary files, and of any part thereof, subject to the\n\
-following licence conditions:\n\n\
-1. You may distribute MSNTP or components of MSNTP, with or without additions\n\
-developed by you or by others. No charge, other than an \"at-cost\" distribution\n\
-fee, may be charged for copies, derivations, or distributions of this material\n\
-without the express written consent of the copyright holders.\n\n\
-2. You may also distribute MSNTP along with any other product for sale,\n\
-provided that the cost of the bundled package is the same regardless of whether\n\
-MSNTP is included or not, and provided that those interested only in MSNTP must\n\
-be notified that it is a product freely available from the University of\n\
-Cambridge.\n\n\
-3. If you distribute MSNTP software or parts of MSNTP, with or without\n\
-additions developed by you or others, then you must either make available the\n\
-source to all portions of the MSNTP system (exclusive of any additions made by\n\
-you or by others) upon request, or instead you may notify anyone requesting\n\
-source that it is freely available from the University of Cambridge.\n\n\
-4. You may not omit any of the copyright notices on either the source files,\n\
-the executable files, or the documentation.\n\n\
-5. You may not omit transmission of this License agreement with whatever\n\
-portions of MSNTP that are distributed.\n\n\
-6. Any users of this software must be notified that it is without warranty or\n\
-guarantee of any nature, express or implied, nor is there any fitness for use\n\
-represented.\n\n\n\
-October 1996 April 1997 October 2000";
+tSCC zCopyrightNotice[1] =
+"";
extern tUsageProc optionUsage;
#define IPV6_FLAGS (OPTST_DISABLED)
/*
- * Unprivport option description:
- */
-tSCC zUnprivportText[] =
- "Use an unprivileged port";
-tSCC zUnprivport_NAME[] = "UNPRIVPORT";
-tSCC zUnprivport_Name[] = "unprivport";
-#define UNPRIVPORT_FLAGS (OPTST_DISABLED)
-
-/*
- * Normalverbose option description with
- * "Must also have options" and "Incompatible options":
+ * Normalverbose option description:
*/
tSCC zNormalverboseText[] =
- "Slightly verbose";
+ "Normal verbose";
tSCC zNormalverbose_NAME[] = "NORMALVERBOSE";
tSCC zNormalverbose_Name[] = "normalverbose";
-static const int
- aNormalverboseCantList[] = {
- INDEX_OPT_EXTRAVERBOSE,
- INDEX_OPT_MEGAVERBOSE, NO_EQUIVALENT };
#define NORMALVERBOSE_FLAGS (OPTST_DISABLED)
/*
- * Extraverbose option description with
+ * Kod option description:
+ */
+tSCC zKodText[] =
+ "Specify a file for the KOD packet storage";
+tSCC zKod_NAME[] = "KOD";
+tSCC zKod_Name[] = "kod";
+#define KOD_FLAGS (OPTST_DISABLED \
+ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
+
+/*
+ * Syslog option description with
* "Must also have options" and "Incompatible options":
*/
-tSCC zExtraverboseText[] =
- "Extra verbose";
-tSCC zExtraverbose_NAME[] = "EXTRAVERBOSE";
-tSCC zExtraverbose_Name[] = "extraverbose";
+tSCC zSyslogText[] =
+ "Logging with syslog";
+tSCC zSyslog_NAME[] = "SYSLOG";
+tSCC zSyslog_Name[] = "syslog";
static const int
- aExtraverboseCantList[] = {
- INDEX_OPT_NORMALVERBOSE,
- INDEX_OPT_MEGAVERBOSE, NO_EQUIVALENT };
-#define EXTRAVERBOSE_FLAGS (OPTST_DISABLED)
+ aSyslogCantList[] = {
+ INDEX_OPT_FILELOG, NO_EQUIVALENT };
+#define SYSLOG_FLAGS (OPTST_DISABLED)
/*
- * Megaverbose option description with
+ * Filelog option description with
* "Must also have options" and "Incompatible options":
*/
-tSCC zMegaverboseText[] =
- "Mega verbose";
-tSCC zMegaverbose_NAME[] = "MEGAVERBOSE";
-tSCC zMegaverbose_Name[] = "megaverbose";
+tSCC zFilelogText[] =
+ "Logging to specified logfile";
+tSCC zFilelog_NAME[] = "FILELOG";
+tSCC zFilelog_Name[] = "filelog";
static const int
- aMegaverboseCantList[] = {
- INDEX_OPT_NORMALVERBOSE,
- INDEX_OPT_EXTRAVERBOSE, NO_EQUIVALENT };
-#define MEGAVERBOSE_FLAGS (OPTST_DISABLED)
+ aFilelogCantList[] = {
+ INDEX_OPT_SYSLOG, NO_EQUIVALENT };
+#define FILELOG_FLAGS (OPTST_DISABLED \
+ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
/*
- * Settimeofday option description with
+ * Settod option description with
* "Must also have options" and "Incompatible options":
*/
-tSCC zSettimeofdayText[] =
+tSCC zSettodText[] =
"Set (step) the time with settimeofday()";
-tSCC zSettimeofday_NAME[] = "SETTIMEOFDAY";
-tSCC zSettimeofday_Name[] = "settimeofday";
+tSCC zSettod_NAME[] = "SETTOD";
+tSCC zSettod_Name[] = "settod";
static const int
- aSettimeofdayCantList[] = {
+ aSettodCantList[] = {
INDEX_OPT_ADJTIME, NO_EQUIVALENT };
-#define SETTIMEOFDAY_FLAGS (OPTST_DISABLED)
+#define SETTOD_FLAGS (OPTST_DISABLED)
/*
* Adjtime option description with
tSCC zAdjtime_Name[] = "adjtime";
static const int
aAdjtimeCantList[] = {
- INDEX_OPT_SETTIMEOFDAY, NO_EQUIVALENT };
+ INDEX_OPT_SETTOD, NO_EQUIVALENT };
#define ADJTIME_FLAGS (OPTST_DISABLED)
+/*
+ * Broadcast option description:
+ */
+tSCC zBroadcastText[] =
+ "Use broadcast packages from the broadcast address specified for synchronisation";
+tSCC zBroadcast_NAME[] = "BROADCAST";
+tSCC zBroadcast_Name[] = "broadcast";
+#define BROADCAST_FLAGS (OPTST_DISABLED \
+ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
+
+/*
+ * Timeout option description:
+ */
+tSCC zTimeoutText[] =
+ "Specify the number of seconds until SNTP times out when waiting for broadcast packets";
+tSCC zTimeout_NAME[] = "TIMEOUT";
+tSCC zTimeout_Name[] = "timeout";
+#define TIMEOUT_FLAGS (OPTST_DISABLED \
+ | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
+
+/*
+ * Authentication option description:
+ */
+tSCC zAuthenticationText[] =
+ "Enable authentication with the key keyno. This option is used as -a keyno";
+tSCC zAuthentication_NAME[] = "AUTHENTICATION";
+tSCC zAuthentication_Name[] = "authentication";
+#define AUTHENTICATION_FLAGS (OPTST_DISABLED \
+ | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
+
+/*
+ * Keyfile option description:
+ */
+tSCC zKeyfileText[] =
+ "Specify a keyfile. SNTP will look in this file for the key specified with -a";
+tSCC zKeyfile_NAME[] = "KEYFILE";
+tSCC zKeyfile_Name[] = "keyfile";
+#define KEYFILE_FLAGS (OPTST_DISABLED \
+ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
+
/*
* Help/More_Help/Version option descriptions:
*/
* if multiple copies are allowed.
*/
extern tOptProc
- optionPagedUsage, optionVersionStderr;
+ optionNumericVal, optionPagedUsage, optionVersionStderr;
static tOptProc
doUsageOpt;
* When not under test, there are different procs to use
*/
extern tOptProc
- optionPagedUsage, optionPrintVersion;
+ optionNumericVal, optionPagedUsage, optionPrintVersion;
static tOptProc
doUsageOpt;
#endif /* defined(TEST_SNTP_OPTS) */
/* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 2, VALUE_OPT_UNPRIVPORT,
- /* equiv idx, value */ 2, VALUE_OPT_UNPRIVPORT,
+ { /* entry idx, value */ 2, VALUE_OPT_NORMALVERBOSE,
+ /* equiv idx, value */ 2, VALUE_OPT_NORMALVERBOSE,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ UNPRIVPORT_FLAGS, 0,
+ /* opt state flags */ NORMALVERBOSE_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ NULL,
- /* desc, NAME, name */ zUnprivportText, zUnprivport_NAME, zUnprivport_Name,
+ /* desc, NAME, name */ zNormalverboseText, zNormalverbose_NAME, zNormalverbose_Name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 3, VALUE_OPT_NORMALVERBOSE,
- /* equiv idx, value */ 3, VALUE_OPT_NORMALVERBOSE,
+ { /* entry idx, value */ 3, VALUE_OPT_KOD,
+ /* equiv idx, value */ 3, VALUE_OPT_KOD,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ NORMALVERBOSE_FLAGS, 0,
+ /* opt state flags */ KOD_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aNormalverboseCantList,
+ /* must/cannot opts */ NULL, NULL,
/* option proc */ NULL,
- /* desc, NAME, name */ zNormalverboseText, zNormalverbose_NAME, zNormalverbose_Name,
+ /* desc, NAME, name */ zKodText, zKod_NAME, zKod_Name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 4, VALUE_OPT_EXTRAVERBOSE,
- /* equiv idx, value */ 4, VALUE_OPT_EXTRAVERBOSE,
+ { /* entry idx, value */ 4, VALUE_OPT_SYSLOG,
+ /* equiv idx, value */ 4, VALUE_OPT_SYSLOG,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ EXTRAVERBOSE_FLAGS, 0,
+ /* opt state flags */ SYSLOG_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aExtraverboseCantList,
+ /* must/cannot opts */ NULL, aSyslogCantList,
/* option proc */ NULL,
- /* desc, NAME, name */ zExtraverboseText, zExtraverbose_NAME, zExtraverbose_Name,
+ /* desc, NAME, name */ zSyslogText, zSyslog_NAME, zSyslog_Name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 5, VALUE_OPT_MEGAVERBOSE,
- /* equiv idx, value */ 5, VALUE_OPT_MEGAVERBOSE,
+ { /* entry idx, value */ 5, VALUE_OPT_FILELOG,
+ /* equiv idx, value */ 5, VALUE_OPT_FILELOG,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ MEGAVERBOSE_FLAGS, 0,
+ /* opt state flags */ FILELOG_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aMegaverboseCantList,
+ /* must/cannot opts */ NULL, aFilelogCantList,
/* option proc */ NULL,
- /* desc, NAME, name */ zMegaverboseText, zMegaverbose_NAME, zMegaverbose_Name,
+ /* desc, NAME, name */ zFilelogText, zFilelog_NAME, zFilelog_Name,
/* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 6, VALUE_OPT_SETTIMEOFDAY,
- /* equiv idx, value */ 6, VALUE_OPT_SETTIMEOFDAY,
+ { /* entry idx, value */ 6, VALUE_OPT_SETTOD,
+ /* equiv idx, value */ 6, VALUE_OPT_SETTOD,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ SETTIMEOFDAY_FLAGS, 0,
+ /* opt state flags */ SETTOD_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aSettimeofdayCantList,
+ /* must/cannot opts */ NULL, aSettodCantList,
/* option proc */ NULL,
- /* desc, NAME, name */ zSettimeofdayText, zSettimeofday_NAME, zSettimeofday_Name,
+ /* desc, NAME, name */ zSettodText, zSettod_NAME, zSettod_Name,
/* disablement strs */ NULL, NULL },
{ /* entry idx, value */ 7, VALUE_OPT_ADJTIME,
/* desc, NAME, name */ zAdjtimeText, zAdjtime_NAME, zAdjtime_Name,
/* disablement strs */ NULL, NULL },
+ { /* entry idx, value */ 8, VALUE_OPT_BROADCAST,
+ /* equiv idx, value */ 8, VALUE_OPT_BROADCAST,
+ /* equivalenced to */ NO_EQUIVALENT,
+ /* min, max, act ct */ 0, 1, 0,
+ /* opt state flags */ BROADCAST_FLAGS, 0,
+ /* last opt argumnt */ { NULL },
+ /* arg list/cookie */ NULL,
+ /* must/cannot opts */ NULL, NULL,
+ /* option proc */ NULL,
+ /* desc, NAME, name */ zBroadcastText, zBroadcast_NAME, zBroadcast_Name,
+ /* disablement strs */ NULL, NULL },
+
+ { /* entry idx, value */ 9, VALUE_OPT_TIMEOUT,
+ /* equiv idx, value */ 9, VALUE_OPT_TIMEOUT,
+ /* equivalenced to */ NO_EQUIVALENT,
+ /* min, max, act ct */ 0, 1, 0,
+ /* opt state flags */ TIMEOUT_FLAGS, 0,
+ /* last opt argumnt */ { NULL },
+ /* arg list/cookie */ NULL,
+ /* must/cannot opts */ NULL, NULL,
+ /* option proc */ optionNumericVal,
+ /* desc, NAME, name */ zTimeoutText, zTimeout_NAME, zTimeout_Name,
+ /* disablement strs */ NULL, NULL },
+
+ { /* entry idx, value */ 10, VALUE_OPT_AUTHENTICATION,
+ /* equiv idx, value */ 10, VALUE_OPT_AUTHENTICATION,
+ /* equivalenced to */ NO_EQUIVALENT,
+ /* min, max, act ct */ 0, 1, 0,
+ /* opt state flags */ AUTHENTICATION_FLAGS, 0,
+ /* last opt argumnt */ { NULL },
+ /* arg list/cookie */ NULL,
+ /* must/cannot opts */ NULL, NULL,
+ /* option proc */ optionNumericVal,
+ /* desc, NAME, name */ zAuthenticationText, zAuthentication_NAME, zAuthentication_Name,
+ /* disablement strs */ NULL, NULL },
+
+ { /* entry idx, value */ 11, VALUE_OPT_KEYFILE,
+ /* equiv idx, value */ 11, VALUE_OPT_KEYFILE,
+ /* equivalenced to */ NO_EQUIVALENT,
+ /* min, max, act ct */ 0, 1, 0,
+ /* opt state flags */ KEYFILE_FLAGS, 0,
+ /* last opt argumnt */ { NULL },
+ /* arg list/cookie */ NULL,
+ /* must/cannot opts */ NULL, NULL,
+ /* option proc */ NULL,
+ /* desc, NAME, name */ zKeyfileText, zKeyfile_NAME, zKeyfile_Name,
+ /* disablement strs */ NULL, NULL },
+
#ifdef NO_OPTIONAL_OPT_ARGS
# define VERSION_OPT_FLAGS OPTST_IMM | OPTST_NO_INIT
#else
tSCC zPROGNAME[] = "SNTP";
tSCC zUsageTitle[] =
"sntp - standard SNTP program - Ver. 4.2.5p199\n\
-USAGE: %s [ -<flag> | --<name> ]...\n";
+USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... ...\n";
tSCC zRcName[] = ".ntprc";
tSCC* apzHomeList[] = {
"$HOME",
+ OPTPROC_LONGOPT
+ OPTPROC_NO_REQ_OPT
+ OPTPROC_ENVIRON
- + OPTPROC_NO_ARGS ),
+ + OPTPROC_ARGS_REQ ),
0, NULL, /* current option index, current option */
NULL, NULL, zPROGNAME,
zRcName, zCopyright, zCopyrightNotice,
NO_EQUIVALENT, /* '-#' option index */
NO_EQUIVALENT /* index of default opt */
},
- 13 /* full option count */, 8 /* user option count */,
+ 17 /* full option count */, 12 /* user option count */,
sntp_full_usage, sntp_short_usage,
NULL, NULL
};
#include autogen-version.def
+prog-name = "sntp";
+prog-title = "standard SNTP program";
+homerc = $HOME, ".";
+argument = '...';
+
copyright = {
- date = "1970-2006";
+ date = "2008";
owner = "ntp.org";
eaddr = "http://bugs.ntp.org, bugs@ntp.org";
type = note;
};
-prog-name = "sntp";
-prog-title = "standard SNTP program";
-homerc = $HOME, ".";
long-opts;
config-header = "config.h";
_EndOfDoc_;
};
-flag = {
- name = unprivport;
- value = u;
- descrip = "Use an unprivileged port";
- doc = <<- _EndOfDoc_
- Use an unprivilegded UDP port for our queries.
- _EndOfDoc_;
-};
-
flag = {
name = normalverbose;
- value = v;
- flags-cant = extraverbose, megaverbose;
- descrip = "Slightly verbose";
+ value = d;
+ descrip = "Normal verbose";
doc = <<- _EndOfDoc_
Diagnostic messages for non-fatal errors and a limited amount of
tracing should be written to standard error. Fatal ones always
};
flag = {
- name = extraverbose;
- value = V;
- flags-cant = normalverbose, megaverbose;
- descrip = "Extra verbose";
+ name = kod;
+ value = K;
+ arg-type = string;
+ descrip = "Specify a file for the KOD packet storage";
doc = <<- _EndOfDoc_
- Produce more and less comprehensible output, mainly for investigating
- problems with apparently inconsistent timestamps. This option should
- be set when the program fails with a message indicating that is the
- trouble.
+ Specifies the file to be used to store KOD packaet information.
_EndOfDoc_;
};
+
flag = {
- name = megaverbose;
- value = W;
- flags-cant = normalverbose, extraverbose;
- descrip = "Mega verbose";
- doc = <<- _EndOfDoc_
- Very verbose debugging output that will interfere with the timing
- when writing to the terminal (because of line buffered output from C).
- Note that the times produced by this are the corrections needed, and
- not the error in the local clock. This option should be set only when
- debugging the source.
+ name = syslog;
+ value = p;
+ flags-cant = filelog;
+ descrip = "Logging with syslog";
+ doc = <<- _EndOfDoc_
+ When this option is set all logging will be done using syslog.
+ _EndOfDoc_;
+};
+
+flag = {
+ name = filelog;
+ value = l;
+ arg-type = string;
+ flags-cant = syslog;
+ descrip = "Logging to specified logfile";
+ doc = <<- _EndOfDoc_
+ This option causes the client to write log messages to the specified
+ logfile.
_EndOfDoc_;
};
flag = {
- name = settimeofday;
- value = r;
+ name = settod;
+ value = s;
flags-cant = adjtime;
descrip = "Set (step) the time with settimeofday()";
doc = <<- _EndOfDoc_
flag = {
name = adjtime;
- value = a;
- flags-cant = settimeofday;
+ value = j;
+ flags-cant = settod;
descrip = "Set (slew) the time with adjtime()";
doc = <<- _EndOfDoc_
_EndOfDoc_;
};
+flag = {
+ name = broadcast;
+ value = b;
+ descrip = "Use broadcast packages from the broadcast address specified for synchronisation";
+ arg-type = string;
+ doc = <<- _EndOfDoc_
+ If specified SNTP will wait 1 minute for broadcast packets
+ from the broadcast address specified for synchronisation.
+ The amount of time SNTP waits can be specified with -t.
+ _EndOfDoc_;
+};
+
+flag = {
+ name = timeout;
+ value = t;
+ descrip = "Specify the number of seconds until SNTP times out when waiting for broadcast packets";
+ arg-type = number;
+ doc = <<- _EndOfDoc_
+ When waiting for a broadcast packet SNTP will wait the number
+ of seconds specified and times out.
+ _EndOfDoc_;
+};
+
+flag = {
+ name = authentication;
+ value = a;
+ descrip = "Enable authentication with the key keyno. This option is used as -a keyno";
+ arg-type = number;
+ doc = <<- _EndOfDoc_
+ This option enables authentication using the key specified in this option\'s argument.
+ The argument of this option is the keyid, a number specified in the keyfile as this
+ key\'s identifier. See the keyfile option -k for more details.
+ _EndOfDoc_;
+};
+
+flag = {
+ name = keyfile;
+ value = k;
+ descrip = "Specify a keyfile. SNTP will look in this file for the key specified with -a";
+ arg-type = string;
+ doc = <<- _EndOfDoc_
+ This option specifies the keyfile. SNTP will search for the key specified with -a keyno in this
+ file. Key files follow the following format:
+
+ keyid keytype key
+
+ Where keyid is a number identifying this key
+ keytype is one of the follow:
+ S Key in 64 Bit hexadecimal number as specified in in the DES specification.
+ N Key in 64 Bit hexadecimal number as specified in the NTP standard.
+ A Key in a 1-to-8 character ASCII string.
+ M Key in a 1-to-8 character ASCII string using the MD5 authentication scheme.
+
+ See more information see ntp.keys(5).
+ _EndOfDoc_;
+};
+
+
+
+
detail = <<- _END_DETAIL
.I sntp
can be used as a SNTP client to query a NTP or SNTP server and either display
that the times produced by this are the corrections needed, and not the error
in the local clock. This option should be set only when debugging the source.
.TP
-.B \-q
-indicates that it should query a daemon save file being maintained by it.
-This needs no privilege and will change neither the save file nor the clock.
-.PP
-The default is that it should behave as a client, and the following options
-are then relevant:
-.TP
.B \-r
indicates that the system clock should be reset by
-.IR settimeofday .
+.IR settod .
Naturally, this will work only if the user has enough privilege.
.TP
.B \-a
running at once. The default is installation-dependent, but will usually be
.IR /etc/sntp.pid .
.TP
-.BI \-e " minerr"
-sets the maximum ignorable variation between the clocks to
-.IR minerr .
-Acceptable values are from 0.001 to 1, and the default is 0.1 if a NTP host is
-is specified and 0.5 otherwise.
-.TP
-.BI \-E " maxerr"
-sets the maximum value of various delays that are deemed acceptable to
-.IR maxerr .
-Acceptable values are from 1 to 60, and the default is 5. It should sometimes
-be increased if there are problems with the network, NTP server or system
-clock, but take care.
-.TP
-.BI \-P " prompt"
-sets the maximum clock change that will be made automatically to
-.IR maxerr .
-Acceptable values are from 1 to 3600 or
-.IR no ,
-and the default is 30. If the program is being run interactively in ordinary
-client mode, and the system clock is to be changed, larger corrections will
-prompt the user for confirmation. Specifying
-.I no
-will disable this and the correction will be made regardless.
-.TP
.BI \-c " count"
sets the maximum number of NTP packets required to
.IR count .
otherwise, and the default is 5. If the maximum isn't enough, the system needs
a better consistency algorithm than this program uses.
.TP
-.BI \-d " delay"
-sets a rough limit on the total running time to
-.I delay
-seconds. Acceptable values are from 1 to 3600, and the default is 15 if a NTP
-host is specified and 300 otherwise.
-.TP
.B -4
force IPv4 DNS resolution.
.TP
.PP
Constraints:
.IP
-.B minerr
-must be less than
-.B maxerr
-which must be less than
-.B delay
-(or, if a NTP host is not specified
.BR delay / count "),"
and
.B count
In update mode,
.B maxerr
must be less than
-.BR prompt.
-.PP
-Note that none of the above values are closely linked to the limits described
-in the NTP protocol (RFC 1305).
.SH USAGE
The simplest use of this program is as an unprivileged command to check the
current time and error in the local clock. For example:
.IR inittab ,
to do this automatically.
.PP
-The error cannot be estimated reliably with broadcast packets or for the drift
-in daemon mode (even with client-server packets), and the guess made by the
-program may be wrong (possibly even very wrong). If this is a problem, then
-setting the
-.B \-c
-option to a larger value may help. Or it may not.
.SH AUTHOR
.I sntp
-was developed by N.M. Maclaren of the University of Cambridge Computing
-Service.
_END_PROG_MAN_DESCRIP;
/*
* EDIT THIS FILE WITH CAUTION (sntp-opts.h)
*
- * It has been AutoGen-ed August 9, 2009 at 07:53:58 AM by AutoGen 5.9.9pre5
+ * It has been AutoGen-ed August 9, 2009 at 07:52:55 AM by AutoGen 5.9.9pre5
* From the definitions sntp-opts.def
* and the template file options
*
*
* This source file is copyrighted and licensed under the following terms:
*
- * sntp copyright (c) 1970-2006 ntp.org - all rights reserved
+ * sntp copyright (c) 2008 ntp.org - all rights reserved
*
- * General Public Licence for the software known as MSNTP
- * ------------------------------------------------------
*
- * (c) Copyright, N.M. Maclaren, 1996, 1997, 2000
- * (c) Copyright, University of Cambridge, 1996, 1997, 2000
- *
- *
- *
- * Free use of MSNTP in source and binary forms is permitted, provided that this
- * entire licence is duplicated in all copies, and that any documentation,
- * announcements, and other materials related to use acknowledge that the software
- * was developed by N.M. Maclaren (hereafter refered to as the Author) at the
- * University of Cambridge. Neither the name of the Author nor the University of
- * Cambridge may be used to endorse or promote products derived from this material
- * without specific prior written permission.
- *
- * The Author and the University of Cambridge retain the copyright and all other
- * legal rights to the software and make it available non-exclusively. All users
- * must ensure that the software in all its derivations carries a copyright notice
- * in the form:
- * (c) Copyright N.M. Maclaren,
- * (c) Copyright University of Cambridge.
- *
- *
- *
- * NO WARRANTY
- *
- * Because the MSNTP software is licensed free of charge, the Author and the
- * University of Cambridge provide absolutely no warranty, 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 MSNTP software is with you. Should MSNTP
- * prove defective, you assume the cost of all necessary servicing or repair.
- *
- * In no event, unless required by law, will the Author or the University of
- * Cambridge, or any other party who may modify and redistribute this software as
- * permitted in accordance with the provisions below, be liable for damages for
- * any losses whatsoever, including but not limited to lost profits, lost monies,
- * lost or corrupted data, or other special, incidental or consequential losses
- * that may arise out of the use or inability to use the MSNTP software.
- *
- *
- *
- * COPYING POLICY
- *
- * Permission is hereby granted for copying and distribution of copies of the
- * MSNTP source and binary files, and of any part thereof, subject to the
- * following licence conditions:
- *
- * 1. You may distribute MSNTP or components of MSNTP, with or without additions
- * developed by you or by others. No charge, other than an "at-cost" distribution
- * fee, may be charged for copies, derivations, or distributions of this material
- * without the express written consent of the copyright holders.
- *
- * 2. You may also distribute MSNTP along with any other product for sale,
- * provided that the cost of the bundled package is the same regardless of whether
- * MSNTP is included or not, and provided that those interested only in MSNTP must
- * be notified that it is a product freely available from the University of
- * Cambridge.
- *
- * 3. If you distribute MSNTP software or parts of MSNTP, with or without
- * additions developed by you or others, then you must either make available the
- * source to all portions of the MSNTP system (exclusive of any additions made by
- * you or by others) upon request, or instead you may notify anyone requesting
- * source that it is freely available from the University of Cambridge.
- *
- * 4. You may not omit any of the copyright notices on either the source files,
- * the executable files, or the documentation.
- *
- * 5. You may not omit transmission of this License agreement with whatever
- * portions of MSNTP that are distributed.
- *
- * 6. Any users of this software must be notified that it is without warranty or
- * guarantee of any nature, express or implied, nor is there any fitness for use
- * represented.
- *
- *
- * October 1996
- * April 1997
- * October 2000
*/
/*
* This file contains the programmatic interface to the Automated
* Enumeration of each option:
*/
typedef enum {
- INDEX_OPT_IPV4 = 0,
- INDEX_OPT_IPV6 = 1,
- INDEX_OPT_UNPRIVPORT = 2,
- INDEX_OPT_NORMALVERBOSE = 3,
- INDEX_OPT_EXTRAVERBOSE = 4,
- INDEX_OPT_MEGAVERBOSE = 5,
- INDEX_OPT_SETTIMEOFDAY = 6,
- INDEX_OPT_ADJTIME = 7,
- INDEX_OPT_VERSION = 8,
- INDEX_OPT_HELP = 9,
- INDEX_OPT_MORE_HELP = 10,
- INDEX_OPT_SAVE_OPTS = 11,
- INDEX_OPT_LOAD_OPTS = 12
+ INDEX_OPT_IPV4 = 0,
+ INDEX_OPT_IPV6 = 1,
+ INDEX_OPT_NORMALVERBOSE = 2,
+ INDEX_OPT_KOD = 3,
+ INDEX_OPT_SYSLOG = 4,
+ INDEX_OPT_FILELOG = 5,
+ INDEX_OPT_SETTOD = 6,
+ INDEX_OPT_ADJTIME = 7,
+ INDEX_OPT_BROADCAST = 8,
+ INDEX_OPT_TIMEOUT = 9,
+ INDEX_OPT_AUTHENTICATION = 10,
+ INDEX_OPT_KEYFILE = 11,
+ INDEX_OPT_VERSION = 12,
+ INDEX_OPT_HELP = 13,
+ INDEX_OPT_MORE_HELP = 14,
+ INDEX_OPT_SAVE_OPTS = 15,
+ INDEX_OPT_LOAD_OPTS = 16
} teOptIndex;
-#define OPTION_CT 13
+#define OPTION_CT 17
#define SNTP_VERSION "4.2.5p199"
#define SNTP_FULL_VERSION "sntp - standard SNTP program - Ver. 4.2.5p199"
# warning undefining IPV6 due to option name conflict
# undef IPV6
# endif
-# ifdef UNPRIVPORT
-# warning undefining UNPRIVPORT due to option name conflict
-# undef UNPRIVPORT
-# endif
# ifdef NORMALVERBOSE
# warning undefining NORMALVERBOSE due to option name conflict
# undef NORMALVERBOSE
# endif
-# ifdef EXTRAVERBOSE
-# warning undefining EXTRAVERBOSE due to option name conflict
-# undef EXTRAVERBOSE
+# ifdef KOD
+# warning undefining KOD due to option name conflict
+# undef KOD
+# endif
+# ifdef SYSLOG
+# warning undefining SYSLOG due to option name conflict
+# undef SYSLOG
# endif
-# ifdef MEGAVERBOSE
-# warning undefining MEGAVERBOSE due to option name conflict
-# undef MEGAVERBOSE
+# ifdef FILELOG
+# warning undefining FILELOG due to option name conflict
+# undef FILELOG
# endif
-# ifdef SETTIMEOFDAY
-# warning undefining SETTIMEOFDAY due to option name conflict
-# undef SETTIMEOFDAY
+# ifdef SETTOD
+# warning undefining SETTOD due to option name conflict
+# undef SETTOD
# endif
# ifdef ADJTIME
# warning undefining ADJTIME due to option name conflict
# undef ADJTIME
# endif
+# ifdef BROADCAST
+# warning undefining BROADCAST due to option name conflict
+# undef BROADCAST
+# endif
+# ifdef TIMEOUT
+# warning undefining TIMEOUT due to option name conflict
+# undef TIMEOUT
+# endif
+# ifdef AUTHENTICATION
+# warning undefining AUTHENTICATION due to option name conflict
+# undef AUTHENTICATION
+# endif
+# ifdef KEYFILE
+# warning undefining KEYFILE due to option name conflict
+# undef KEYFILE
+# endif
#else /* NO_OPTION_NAME_WARNINGS */
# undef IPV4
# undef IPV6
-# undef UNPRIVPORT
# undef NORMALVERBOSE
-# undef EXTRAVERBOSE
-# undef MEGAVERBOSE
-# undef SETTIMEOFDAY
+# undef KOD
+# undef SYSLOG
+# undef FILELOG
+# undef SETTOD
# undef ADJTIME
+# undef BROADCAST
+# undef TIMEOUT
+# undef AUTHENTICATION
+# undef KEYFILE
#endif /* NO_OPTION_NAME_WARNINGS */
/* * * * * *
#define WHICH_OPT_IPV4 (DESC(IPV4).optActualValue)
#define WHICH_IDX_IPV4 (DESC(IPV4).optActualIndex)
#define VALUE_OPT_IPV6 '6'
-#define VALUE_OPT_UNPRIVPORT 'u'
-#define VALUE_OPT_NORMALVERBOSE 'v'
-#define VALUE_OPT_EXTRAVERBOSE 'V'
-#define VALUE_OPT_MEGAVERBOSE 'W'
-#define VALUE_OPT_SETTIMEOFDAY 'r'
-#define VALUE_OPT_ADJTIME 'a'
+#define VALUE_OPT_NORMALVERBOSE 'd'
+#define VALUE_OPT_KOD 'K'
+#define VALUE_OPT_SYSLOG 'p'
+#define VALUE_OPT_FILELOG 'l'
+#define VALUE_OPT_SETTOD 's'
+#define VALUE_OPT_ADJTIME 'j'
+#define VALUE_OPT_BROADCAST 'b'
+#define VALUE_OPT_TIMEOUT 't'
+#define OPT_VALUE_TIMEOUT (DESC(TIMEOUT).optArg.argInt)
+#define VALUE_OPT_AUTHENTICATION 'a'
+#define OPT_VALUE_AUTHENTICATION (DESC(AUTHENTICATION).optArg.argInt)
+#define VALUE_OPT_KEYFILE 'k'
#define VALUE_OPT_HELP '?'
#define VALUE_OPT_MORE_HELP '!'
#define VALUE_OPT_VERSION 'v'
#
# EDIT THIS FILE WITH CAUTION (sntp-opts.texi)
#
-# It has been AutoGen-ed August 9, 2009 at 07:54:01 AM by AutoGen 5.9.9pre5
+# It has been AutoGen-ed August 9, 2009 at 07:52:59 AM by AutoGen 5.9.9pre5
# From the definitions sntp-opts.def
# and the template file aginfo.tpl
@end ignore
@menu
* sntp usage:: sntp usage help (-?)
-* sntp adjtime:: adjtime option (-a)
-* sntp extraverbose:: extraverbose option (-V)
+* sntp adjtime:: adjtime option (-j)
+* sntp authentication:: authentication option (-a)
+* sntp broadcast:: broadcast option (-b)
+* sntp filelog:: filelog option (-l)
* sntp ipv4:: ipv4 option (-4)
* sntp ipv6:: ipv6 option (-6)
-* sntp megaverbose:: megaverbose option (-W)
-* sntp normalverbose:: normalverbose option (-v)
-* sntp settimeofday:: settimeofday option (-r)
-* sntp unprivport:: unprivport option (-u)
+* sntp keyfile:: keyfile option (-k)
+* sntp kod:: kod option (-K)
+* sntp normalverbose:: normalverbose option (-d)
+* sntp settod:: settod option (-s)
+* sntp syslog:: syslog option (-p)
+* sntp timeout:: timeout option (-t)
@end menu
@node sntp usage
Force DNS resolution of following host names on the command line
to the IPv6 namespace.
-@node sntp unprivport
-@subsection unprivport option (-u)
-@cindex sntp-unprivport
-
-This is the ``use an unprivileged port'' option.
-Use an unprivilegded UDP port for our queries.
-
@node sntp normalverbose
-@subsection normalverbose option (-v)
+@subsection normalverbose option (-d)
@cindex sntp-normalverbose
-This is the ``slightly verbose'' option.
-
-This option has some usage constraints. It:
-@itemize @bullet
-@item
-must not appear in combination with any of the following options:
-extraverbose, megaverbose.
-@end itemize
-
+This is the ``normal verbose'' option.
Diagnostic messages for non-fatal errors and a limited amount of
tracing should be written to standard error. Fatal ones always
produce a diagnostic. This option should be set when there is a
suspected problem with the server, network or the source.
-@node sntp extraverbose
-@subsection extraverbose option (-V)
-@cindex sntp-extraverbose
+@node sntp kod
+@subsection kod option (-K)
+@cindex sntp-kod
+
+This is the ``specify a file for the kod packet storage'' option.
+Specifies the file to be used to store KOD packaet information.
+
+@node sntp syslog
+@subsection syslog option (-p)
+@cindex sntp-syslog
-This is the ``extra verbose'' option.
+This is the ``logging with syslog'' option.
This option has some usage constraints. It:
@itemize @bullet
@item
must not appear in combination with any of the following options:
-normalverbose, megaverbose.
+filelog.
@end itemize
-Produce more and less comprehensible output, mainly for investigating
-problems with apparently inconsistent timestamps. This option should
-be set when the program fails with a message indicating that is the
-trouble.
+When this option is set all logging will be done using syslog.
-@node sntp megaverbose
-@subsection megaverbose option (-W)
-@cindex sntp-megaverbose
+@node sntp filelog
+@subsection filelog option (-l)
+@cindex sntp-filelog
-This is the ``mega verbose'' option.
+This is the ``logging to specified logfile'' option.
This option has some usage constraints. It:
@itemize @bullet
@item
must not appear in combination with any of the following options:
-normalverbose, extraverbose.
+syslog.
@end itemize
-Very verbose debugging output that will interfere with the timing
-when writing to the terminal (because of line buffered output from C).
-Note that the times produced by this are the corrections needed, and
-not the error in the local clock. This option should be set only when
-debugging the source.
+This option causes the client to write log messages to the specified
+logfile.
-@node sntp settimeofday
-@subsection settimeofday option (-r)
-@cindex sntp-settimeofday
+@node sntp settod
+@subsection settod option (-s)
+@cindex sntp-settod
This is the ``set (step) the time with settimeofday()'' option.
@node sntp adjtime
-@subsection adjtime option (-a)
+@subsection adjtime option (-j)
@cindex sntp-adjtime
This is the ``set (slew) the time with adjtime()'' option.
@itemize @bullet
@item
must not appear in combination with any of the following options:
-settimeofday.
+settod.
@end itemize
+
+@node sntp broadcast
+@subsection broadcast option (-b)
+@cindex sntp-broadcast
+
+This is the ``use broadcast packages from the broadcast address specified for synchronisation'' option.
+If specified SNTP will wait 1 minute for broadcast packets
+from the broadcast address specified for synchronisation.
+The amount of time SNTP waits can be specified with -t.
+
+@node sntp timeout
+@subsection timeout option (-t)
+@cindex sntp-timeout
+
+This is the ``specify the number of seconds until sntp times out when waiting for broadcast packets'' option.
+When waiting for a broadcast packet SNTP will wait the number
+of seconds specified and times out.
+
+@node sntp authentication
+@subsection authentication option (-a)
+@cindex sntp-authentication
+
+This is the ``enable authentication with the key keyno. this option is used as -a keyno'' option.
+This option enables authentication using the key specified in this option\'s argument.
+The argument of this option is the keyid, a number specified in the keyfile as this
+key\'s identifier. See the keyfile option -k for more details.
+
+@node sntp keyfile
+@subsection keyfile option (-k)
+@cindex sntp-keyfile
+
+This is the ``specify a keyfile. sntp will look in this file for the key specified with -a'' option.
+This option specifies the keyfile. SNTP will search for the key specified with -a keyno in this
+file. Key files follow the following format:
+
+keyid keytype key
+
+Where keyid is a number identifying this key
+keytype is one of the follow:
+S Key in 64 Bit hexadecimal number as specified in in the DES specification.
+N Key in 64 Bit hexadecimal number as specified in the NTP standard.
+A Key in a 1-to-8 character ASCII string.
+M Key in a 1-to-8 character ASCII string using the MD5 authentication scheme.
+
+See more information see ntp.keys(5).
.TH SNTP 1 2009-08-09 "( 4.2.5p199)" "Programmer's Manual"
.\" EDIT THIS FILE WITH CAUTION (sntp.1)
.\"
-.\" It has been AutoGen-ed August 9, 2009 at 07:54:00 AM by AutoGen 5.9.9pre5
+.\" It has been AutoGen-ed August 9, 2009 at 07:52:57 AM by AutoGen 5.9.9pre5
.\" From the definitions sntp-opts.def
.\" and the template file agman1.tpl
.\"
.B sntp
.\" Mixture of short (flag) options and long options
.RB [ \-\fIflag\fP " [\fIvalue\fP]]... [" \--\fIopt-name\fP " [[=| ]\fIvalue\fP]]..."
-.PP
-All arguments must be options.
+.br
+.in +8
+...
.SH "DESCRIPTION"
This manual page briefly documents the \fBsntp\fP command.
.I sntp
that the times produced by this are the corrections needed, and not the error
in the local clock. This option should be set only when debugging the source.
.TP
-.B \-q
-indicates that it should query a daemon save file being maintained by it.
-This needs no privilege and will change neither the save file nor the clock.
-.PP
-The default is that it should behave as a client, and the following options
-are then relevant:
-.TP
.B \-r
indicates that the system clock should be reset by
-.IR settimeofday .
+.IR settod .
Naturally, this will work only if the user has enough privilege.
.TP
.B \-a
running at once. The default is installation-dependent, but will usually be
.IR /etc/sntp.pid .
.TP
-.BI \-e " minerr"
-sets the maximum ignorable variation between the clocks to
-.IR minerr .
-Acceptable values are from 0.001 to 1, and the default is 0.1 if a NTP host is
-is specified and 0.5 otherwise.
-.TP
-.BI \-E " maxerr"
-sets the maximum value of various delays that are deemed acceptable to
-.IR maxerr .
-Acceptable values are from 1 to 60, and the default is 5. It should sometimes
-be increased if there are problems with the network, NTP server or system
-clock, but take care.
-.TP
-.BI \-P " prompt"
-sets the maximum clock change that will be made automatically to
-.IR maxerr .
-Acceptable values are from 1 to 3600 or
-.IR no ,
-and the default is 30. If the program is being run interactively in ordinary
-client mode, and the system clock is to be changed, larger corrections will
-prompt the user for confirmation. Specifying
-.I no
-will disable this and the correction will be made regardless.
-.TP
.BI \-c " count"
sets the maximum number of NTP packets required to
.IR count .
otherwise, and the default is 5. If the maximum isn't enough, the system needs
a better consistency algorithm than this program uses.
.TP
-.BI \-d " delay"
-sets a rough limit on the total running time to
-.I delay
-seconds. Acceptable values are from 1 to 3600, and the default is 15 if a NTP
-host is specified and 300 otherwise.
-.TP
.B \-4
force IPv4 DNS resolution.
.TP
.PP
Constraints:
.IP
-.B minerr
-must be less than
-.B maxerr
-which must be less than
-.B delay
-(or, if a NTP host is not specified
.BR delay / count "),"
and
.B count
In update mode,
.B maxerr
must be less than
-.BR prompt.
-.PP
-Note that none of the above values are closely linked to the limits described
-in the NTP protocol (RFC 1305).
.SH USAGE
The simplest use of this program is as an unprivileged command to check the
current time and error in the local clock. For example:
.IR inittab ,
to do this automatically.
.PP
-The error cannot be estimated reliably with broadcast packets or for the drift
-in daemon mode (even with client-server packets), and the guess made by the
-program may be wrong (possibly even very wrong). If this is a problem, then
-setting the
-.B \-c
-option to a larger value may help. Or it may not.
.SH AUTHOR
.I sntp
-was developed by N.M. Maclaren of the University of Cambridge Computing
-Service.
.SH OPTIONS
.TP
.BR \-4 ", " \--ipv4
Force DNS resolution of following host names on the command line
to the IPv6 namespace.
.TP
-.BR \-u ", " \--unprivport
-Use an unprivileged port.
-.sp
-Use an unprivilegded UDP port for our queries.
-.TP
-.BR \-v ", " \--normalverbose
-Slightly verbose.
-This option must not appear in combination with any of the following options:
-extraverbose, megaverbose.
+.BR \-d ", " \--normalverbose
+Normal verbose.
.sp
Diagnostic messages for non-fatal errors and a limited amount of
tracing should be written to standard error. Fatal ones always
produce a diagnostic. This option should be set when there is a
suspected problem with the server, network or the source.
.TP
-.BR \-V ", " \--extraverbose
-Extra verbose.
+.BR \-K " \fIstring\fP, " \--kod "=" \fIstring\fP
+Specify a file for the KOD packet storage.
+.sp
+Specifies the file to be used to store KOD packaet information.
+.TP
+.BR \-p ", " \--syslog
+Logging with syslog.
This option must not appear in combination with any of the following options:
-normalverbose, megaverbose.
+filelog.
.sp
-Produce more and less comprehensible output, mainly for investigating
-problems with apparently inconsistent timestamps. This option should
-be set when the program fails with a message indicating that is the
-trouble.
+When this option is set all logging will be done using syslog.
.TP
-.BR \-W ", " \--megaverbose
-Mega verbose.
+.BR \-l " \fIstring\fP, " \--filelog "=" \fIstring\fP
+Logging to specified logfile.
This option must not appear in combination with any of the following options:
-normalverbose, extraverbose.
+syslog.
.sp
-Very verbose debugging output that will interfere with the timing
-when writing to the terminal (because of line buffered output from C).
-Note that the times produced by this are the corrections needed, and
-not the error in the local clock. This option should be set only when
-debugging the source.
+This option causes the client to write log messages to the specified
+logfile.
.TP
-.BR \-r ", " \--settimeofday
+.BR \-s ", " \--settod
Set (step) the time with settimeofday().
This option must not appear in combination with any of the following options:
adjtime.
.sp
.TP
-.BR \-a ", " \--adjtime
+.BR \-j ", " \--adjtime
Set (slew) the time with adjtime().
This option must not appear in combination with any of the following options:
-settimeofday.
+settod.
+.sp
+
+.TP
+.BR \-b " \fIstring\fP, " \--broadcast "=" \fIstring\fP
+Use broadcast packages from the broadcast address specified for synchronisation.
+.sp
+If specified SNTP will wait 1 minute for broadcast packets
+from the broadcast address specified for synchronisation.
+The amount of time SNTP waits can be specified with \-t.
+.TP
+.BR \-t " \fInumber\fP, " \--timeout "=" \fInumber\fP
+Specify the number of seconds until SNTP times out when waiting for broadcast packets.
+This option takes an integer number as its argument.
+.sp
+When waiting for a broadcast packet SNTP will wait the number
+of seconds specified and times out.
+.TP
+.BR \-a " \fInumber\fP, " \--authentication "=" \fInumber\fP
+Enable authentication with the key keyno. This option is used as \-a keyno.
+This option takes an integer number as its argument.
+.sp
+This option enables authentication using the key specified in this option\\'s argument.
+The argument of this option is the keyid, a number specified in the keyfile as this
+key\\'s identifier. See the keyfile option \-k for more details.
+.TP
+.BR \-k " \fIstring\fP, " \--keyfile "=" \fIstring\fP
+Specify a keyfile. SNTP will look in this file for the key specified with \-a.
.sp
+This option specifies the keyfile. SNTP will search for the key specified with \-a keyno in this
+file. Key files follow the following format:
+
+keyid keytype key
+
+Where keyid is a number identifying this key
+keytype is one of the follow:
+S Key in 64 Bit hexadecimal number as specified in in the DES specification.
+N Key in 64 Bit hexadecimal number as specified in the NTP standard.
+A Key in a 1-to-8 character ASCII string.
+M Key in a 1-to-8 character ASCII string using the MD5 authentication scheme.
+See more information see ntp.keys(5).
.TP
.BR \-? , " \--help"
Display usage information and exit.
.PP
.nf
.na
- General Public Licence for the software known as MSNTP
- \------------------------------------------------------
-
- (c) Copyright, N.M. Maclaren, 1996, 1997, 2000
- (c) Copyright, University of Cambridge, 1996, 1997, 2000
-
-
-
-Free use of MSNTP in source and binary forms is permitted, provided that this
-entire licence is duplicated in all copies, and that any documentation,
-announcements, and other materials related to use acknowledge that the software
-was developed by N.M. Maclaren (hereafter refered to as the Author) at the
-University of Cambridge. Neither the name of the Author nor the University of
-Cambridge may be used to endorse or promote products derived from this material
-without specific prior written permission.
-
-The Author and the University of Cambridge retain the copyright and all other
-legal rights to the software and make it available non-exclusively. All users
-must ensure that the software in all its derivations carries a copyright notice
-in the form:
- (c) Copyright N.M. Maclaren,
- (c) Copyright University of Cambridge.
-
-
-
- NO WARRANTY
-
-Because the MSNTP software is licensed free of charge, the Author and the
-University of Cambridge provide absolutely no warranty, 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 MSNTP software is with you. Should MSNTP
-prove defective, you assume the cost of all necessary servicing or repair.
-
-In no event, unless required by law, will the Author or the University of
-Cambridge, or any other party who may modify and redistribute this software as
-permitted in accordance with the provisions below, be liable for damages for
-any losses whatsoever, including but not limited to lost profits, lost monies,
-lost or corrupted data, or other special, incidental or consequential losses
-that may arise out of the use or inability to use the MSNTP software.
-
-
-
- COPYING POLICY
-
-Permission is hereby granted for copying and distribution of copies of the
-MSNTP source and binary files, and of any part thereof, subject to the
-following licence conditions:
-
-1. You may distribute MSNTP or components of MSNTP, with or without additions
-developed by you or by others. No charge, other than an "at-cost" distribution
-fee, may be charged for copies, derivations, or distributions of this material
-without the express written consent of the copyright holders.
-
-2. You may also distribute MSNTP along with any other product for sale,
-provided that the cost of the bundled package is the same regardless of whether
-MSNTP is included or not, and provided that those interested only in MSNTP must
-be notified that it is a product freely available from the University of
-Cambridge.
-
-3. If you distribute MSNTP software or parts of MSNTP, with or without
-additions developed by you or others, then you must either make available the
-source to all portions of the MSNTP system (exclusive of any additions made by
-you or by others) upon request, or instead you may notify anyone requesting
-source that it is freely available from the University of Cambridge.
-
-4. You may not omit any of the copyright notices on either the source files,
-the executable files, or the documentation.
-
-5. You may not omit transmission of this License agreement with whatever
-portions of MSNTP that are distributed.
-
-6. Any users of this software must be notified that it is without warranty or
-guarantee of any nature, express or implied, nor is there any fitness for use
-represented.
-
-October 1996
-April 1997
-October 2000
.fi
.ad
.PP
+++ /dev/null
-/* Copyright (C) 1996, 2000 N.M. Maclaren
- Copyright (C) 1996, 2000 The University of Cambridge
-
-This includes all of the code needed to handle Berkeley sockets. It is way
-outside current POSIX, unfortunately. It should be easy to convert to a system
-that uses another mechanism. It does not currently use socklen_t, because
-the only system that the author uses that has it is Linux. */
-
-
-
-#include "config.h"
-
-#include "header.h"
-#include "internet.h"
-#include <fcntl.h>
-
-#define SOCKET
-#include "kludges.h"
-#undef SOCKET
-
-
-
-/* The code needs to set some variables during the open, for use by later
-functions. */
-
-static int initial = 1,
- descriptors[MAX_SOCKETS];
-
-#ifdef HAVE_IPV6
-static struct sockaddr_storage here[MAX_SOCKETS], there[MAX_SOCKETS];
-#else
-static struct sockaddr_in here[MAX_SOCKETS], there[MAX_SOCKETS];
-#endif
-
-void display_in_hex(const void *, int);
-#ifdef HAVE_IPV6
-void display_sock_in_hex(struct sockaddr_storage *);
-#else
-void display_sock_in_hex (struct sockaddr_in *);
-#endif
-
-/* There needs to be some disgusting grobble for handling timeouts, that is
-identical to the grobble in internet.c. */
-
-static jmp_buf jump_buffer;
-
-static void jump_handler (int sig) {
- longjmp(jump_buffer,1);
-}
-
-static void clear_alarm (void) {
- int k;
-
- k = errno;
- alarm(0);
- errno = 0;
- if (signal(SIGALRM,SIG_DFL) == SIG_ERR)
- fatal(1,"unable to reset signal handler",NULL);
- errno = k;
-}
-
-
-
-void display_in_hex (const void *data, int length) {
- int i;
-
- for (i = 0; i < length; ++i)
- fprintf(stderr,"%.2x",((const unsigned char *)data)[i]);
-}
-
-#ifdef HAVE_IPV6
-
-void display_sock_in_hex (struct sockaddr_storage *sock) {
- int family;
- struct sockaddr_in *sin;
- struct sockaddr_in6 *sin6;
-
- family = sock->ss_family;
- switch(family) {
- case AF_INET:
- sin = (struct sockaddr_in *)sock;
- display_in_hex(&sin->sin_addr, sizeof(struct in_addr));
- fprintf(stderr,"/");
- display_in_hex(&sin->sin_port, 2);
- break;
- case AF_INET6:
- sin6 = (struct sockaddr_in6 *)sock;
- display_in_hex(&sin6->sin6_addr, sizeof(struct in6_addr));
- fprintf(stderr,"/");
- display_in_hex(&sin6->sin6_port, 2);
- break;
- }
-}
-
-#else
-
-void display_sock_in_hex (struct sockaddr_in *sock) {
- int family, len;
- struct sockaddr_in *sin;
-
- family = sock->sin_family;
- switch(family) {
- case AF_INET:
- sin = (struct sockaddr_in *)sock;
- display_in_hex(&sin->sin_addr, sizeof(struct in_addr));
- fprintf(stderr,"/");
- display_in_hex(&sin->sin_port, 2);
- break;
- }
-}
-#endif
-
-extern int unprivport;
-
-#ifdef HAVE_IPV6
-
-void open_socket (int which, char *hostname, int timespan) {
-
-/* Locate the specified NTP server, set up a couple of addresses and open a
-socket. */
-
- int port, k, sl;
- struct sockaddr_storage address, anywhere;
-
-/* Initialise and find out the server and port number. Note that the port
-number is in network format. */
-
- if (initial)
- for (k = 0; k < MAX_SOCKETS; ++k)
- descriptors[k] = -1;
- initial = 0;
- if (which < 0 || which >= MAX_SOCKETS || descriptors[which] >= 0)
- fatal(0,"socket index out of range or already open",NULL);
- if (verbose > 2)
- fprintf(stderr,"Looking for the socket addresses\n");
- find_address(&address,&anywhere,&port,hostname,timespan);
- if (verbose > 2) {
- fprintf(stderr,"Internet address: address=");
- display_sock_in_hex(&address);
- fprintf(stderr," anywhere=");
- display_sock_in_hex(&anywhere);
- fputc('\n',stderr);
- }
-
-/* Set up our own and the target addresses. Note that the target address will
-be reset before use in server mode. */
-
- memset(&here[which], 0, sizeof(struct sockaddr_storage));
- here[which] = anywhere;
- if (operation != op_listen || unprivport)
- ((struct sockaddr_in6 *)&here[which])->sin6_port = 0;
- memset(&there[which], 0, sizeof(struct sockaddr_storage));
- there[which] = address;
- if (verbose > 2) {
- fprintf(stderr,"Initial sockets: here=");
- display_sock_in_hex(&here[which]);
- fprintf(stderr," there=");
- display_sock_in_hex(&there[which]);
- fputc('\n',stderr);
- }
-
-/* Allocate a local UDP socket and configure it. */
-
- switch(((struct sockaddr_in *)&there[which])->sin_family) {
- case AF_INET:
- sl = sizeof(struct sockaddr_in);
- break;
-#ifdef HAVE_IPV6
- case AF_INET6:
- sl = sizeof(struct sockaddr_in6);
- break;
-#endif
- default:
- sl = 0;
- break;
- }
- errno = 0;
- if ((descriptors[which] = socket(here[which].ss_family,SOCK_DGRAM,0)) < 0
- || bind(descriptors[which],(struct sockaddr *)&here[which], sl) < 0)
- fatal(1,"unable to allocate socket for NTP",NULL);
-}
-
-#else
-
-void open_socket (int which, char *hostname, int timespan) {
-
-/* Locate the specified NTP server, set up a couple of addresses and open a
-socket. */
-
- int port, k;
- struct in_addr address, anywhere;
-
-/* Initialise and find out the server and port number. Note that the port
-number is in network format. */
-
- if (initial) for (k = 0; k < MAX_SOCKETS; ++k) descriptors[k] = -1;
- initial = 0;
- if (which < 0 || which >= MAX_SOCKETS || descriptors[which] >= 0)
- fatal(0,"socket index out of range or already open",NULL);
- if (verbose > 2) fprintf(stderr,"Looking for the socket addresses\n");
- find_address(&address,&anywhere,&port,hostname,timespan);
- if (verbose > 2) {
- fprintf(stderr,"Internet address: address=");
- display_in_hex(&address,sizeof(struct in_addr));
- fprintf(stderr," anywhere=");
- display_in_hex(&anywhere,sizeof(struct in_addr));
- fputc('\n',stderr);
- }
-
-/* Set up our own and the target addresses. */
-
- memset(&here[which],0,sizeof(struct sockaddr_in));
- here[which].sin_family = AF_INET;
- here[which].sin_port =
- (operation == op_listen || !unprivport ? port : 0);
- here[which].sin_addr = anywhere;
- memset(&there[which],0,sizeof(struct sockaddr_in));
- there[which].sin_family = AF_INET;
- there[which].sin_port = port;
- there[which].sin_addr = address;
- if (verbose > 2) {
- fprintf(stderr,"Initial sockets: here=");
- display_in_hex(&here[which].sin_addr,sizeof(struct in_addr));
- fputc('/',stderr);
- display_in_hex(&here[which].sin_port,sizeof(here[which].sin_port));
- fprintf(stderr," there=");
- display_in_hex(&there[which].sin_addr,sizeof(struct in_addr));
- fputc('/',stderr);
- display_in_hex(&there[which].sin_port,sizeof(there[which].sin_port));
- fputc('\n',stderr);
- }
-
-/* Allocate a local UDP socket and configure it. */
-
- errno = 0;
- if ((descriptors[which] = socket(AF_INET,SOCK_DGRAM,0)) < 0 ||
- bind(descriptors[which],(struct sockaddr *)&here[which],
- sizeof(here[which])) < 0)
- fatal(1,"unable to allocate socket for NTP",NULL);
-}
-
-#endif
-
-extern void write_socket (int which, void *packet, int length) {
-
-/* Any errors in doing this are fatal - including blocking. Yes, this leaves a
-server vulnerable to a denial of service attack. */
-
- int k, sl;
-
- switch(((struct sockaddr_in *)&there[which])->sin_family) {
- case AF_INET:
- sl = sizeof(struct sockaddr_in);
- break;
-#ifdef HAVE_IPV6
- case AF_INET6:
- sl = sizeof(struct sockaddr_in6);
- break;
-#endif
- default:
- sl = 0;
- break;
- }
- if (which < 0 || which >= MAX_SOCKETS || descriptors[which] < 0)
- fatal(0,"socket index out of range or not open",NULL);
- errno = 0;
- k = sendto(descriptors[which],packet,(size_t)length,0,
- (struct sockaddr *)&there[which],sl);
- if (k != length) fatal(1,"unable to send NTP packet",NULL);
-}
-
-
-
-extern int read_socket (int which, void *packet, int length, int waiting) {
-
-/* Read a packet and return its length or -1 for failure. Only incorrect
-length and timeout are not fatal. */
-
-#ifdef HAVE_IPV6
- struct sockaddr_storage scratch, *ptr;
-#else
- struct sockaddr_in scratch, *ptr;
-#endif
- int n;
- int k;
-
-/* Under normal circumstances, set up a timeout. */
-
- if (which < 0 || which >= MAX_SOCKETS || descriptors[which] < 0)
- fatal(0,"socket index out of range or not open",NULL);
- if (waiting > 0) {
- if (setjmp(jump_buffer)) {
- if (verbose > 2)
- fprintf(stderr,"Receive timed out\n");
- else if (verbose > 1)
- fprintf(stderr,"%s: receive timed out after %d seconds\n",
- argv0,waiting);
- return -1;
- }
- errno = 0;
- if (signal(SIGALRM,jump_handler) == SIG_ERR)
- fatal(1,"unable to set up signal handler",NULL);
- alarm((unsigned int)waiting);
- }
-
-/* Get the packet and clear the timeout, if any. */
-
- memcpy(ptr = &scratch,&there[which],sizeof(scratch));
- n = sizeof(scratch);
- errno = 0;
- k = recvfrom(descriptors[which],packet,(size_t)length,0,
- (struct sockaddr *)ptr,&n);
- if (waiting > 0) clear_alarm();
-
-/* Now issue some low-level diagnostics. */
-
- if (k <= 0) fatal(1,"unable to receive NTP packet from server",NULL);
- if (verbose > 2) {
- fprintf(stderr,"Packet of length %d received from ",k);
- display_sock_in_hex(ptr);
- fputc('\n',stderr);
- }
- return k;
-}
-
-
-
-extern int flush_socket (int which) {
-
-/* Get rid of any outstanding input, because it may have been hanging around
-for a while. Ignore packet length oddities and return the number of packets
-skipped. */
-
-#ifdef HAVE_IPV6
- struct sockaddr_storage scratch;
-#else
- struct sockaddr_in scratch;
-#endif
- int n;
- char buffer[256];
- int flags, count = 0, total = 0, k;
-
-/* The code is the obvious. */
-
- if (which < 0 || which >= MAX_SOCKETS || descriptors[which] < 0)
- fatal(0,"socket index out of range or not open",NULL);
- if (verbose > 2) fprintf(stderr,"Flushing outstanding packets\n");
- errno = 0;
- if ((flags = fcntl(descriptors[which],F_GETFL,0)) < 0 ||
- fcntl(descriptors[which],F_SETFL,flags|O_NONBLOCK) == -1)
- fatal(1,"unable to set non-blocking mode",NULL);
- while (1) {
- n = sizeof(scratch);
- errno = 0;
- k = recvfrom(descriptors[which],buffer,256,0,
- (struct sockaddr *)&scratch,&n);
- if (k < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) break;
- fatal(1,"unable to flush socket",NULL);
- }
- ++count;
- total += k;
- }
- errno = 0;
- if (fcntl(descriptors[which],F_SETFL,flags) == -1)
- fatal(1,"unable to restore blocking mode",NULL);
- if (verbose > 2)
- fprintf(stderr,"Flushed %d packets totalling %d bytes\n",count,total);
- return count;
-}
-
-
-
-extern void close_socket (int which) {
-
-/* There is little point in shielding this with a timeout, because any hangs
-are unlikely to be interruptible. It can get called when the sockets haven't
-been opened, so ignore that case. */
-
- if (which < 0 || which >= MAX_SOCKETS)
- fatal(0,"socket index out of range",NULL);
- if (descriptors[which] < 0) return;
- errno = 0;
- if (close(descriptors[which])) fatal(1,"unable to close NTP socket",NULL);
-}
+++ /dev/null
-/* Copyright (C) 1996 N.M. Maclaren
- Copyright (C) 1996 The University of Cambridge
-
-This includes all of the code needed to handle the time. It assumes rather
-more than is defined by POSIX, unfortunately. Systems that do not have the
-'X/Open' extensions may need changes. */
-
-
-
-#include "header.h"
-
-#include <sys/types.h>
-#include <sys/time.h>
-
-#define TIMING
-#include "kludges.h"
-#undef TIMING
-
-
-
-#define MILLION_L 1000000l /* For conversion to/from timeval */
-#define MILLION_D 1.0e6 /* Must be equal to MILLION_L */
-
-
-
-double current_time (double offset) {
-
-/* Get the current UTC time in seconds since the Epoch plus an offset (usually
-the time from the beginning of the century to the Epoch!) */
-
- struct timeval current;
-
- errno = 0;
- if (gettimeofday(¤t,NULL))
- fatal(1,"unable to read current machine/system time",NULL);
- return offset+current.tv_sec+1.0e-6*current.tv_usec;
-}
-
-
-
-time_t convert_time (double value, int *millisecs) {
-
-/* Convert the time to the ANSI C form. */
-
- time_t result = (time_t)value;
-
- if ((*millisecs = (int)(1000.0*(value-result))) >= 1000) {
- *millisecs = 0;
- ++result;
- }
- return result;
-}
-
-
-
-void adjust_time (double difference, int immediate, double ignore) {
-
-/* Adjust the current UTC time. This is portable, even if struct timeval uses
-an unsigned long for tv_sec. */
-
- struct timeval old, new, adjust, previous;
- char text[40];
- long n;
-
-/* Start by converting to timeval format. Note that we have to cater for
-negative, unsigned values. */
-
- if ((n = (long)difference) > difference) --n;
- adjust.tv_sec = n;
- adjust.tv_usec = (long)(MILLION_D*(difference-n));
- errno = 0;
- if (gettimeofday(&old,NULL))
- fatal(1,"unable to read machine/system time",NULL);
- new.tv_sec = old.tv_sec+adjust.tv_sec;
- new.tv_usec = (n = (long)old.tv_usec+(long)adjust.tv_usec);
- if (n < 0) {
- new.tv_usec += MILLION_L;
- --new.tv_sec;
- } else if (n >= MILLION_L) {
- new.tv_usec -= MILLION_L;
- ++new.tv_sec;
- }
-
-/* Now diagnose the situation if necessary, and perform the dirty deed. */
-
- if (verbose > 2)
- fprintf(stderr,
- "Times: old=(%ld,%.6ld) new=(%ld,%.6ld) adjust=(%ld,%.6ld)\n",
- (long)old.tv_sec,(long)old.tv_usec,
- (long)new.tv_sec,(long)new.tv_usec,
- (long)adjust.tv_sec,(long)adjust.tv_usec);
- if (immediate) {
- errno = 0;
- if (settimeofday(&new,NULL))
- fatal(1,"unable to reset current system time",NULL);
- } else {
- previous.tv_sec = 0;
- previous.tv_usec = 0;
- errno = 0;
- if (adjtime(&adjust,&previous))
- fatal(1,"unable to adjust current system time",NULL);
- if (previous.tv_sec != 0 || previous.tv_usec != 0) {
- sprintf(text,"(%ld,%.6ld)",
- (long)previous.tv_sec,(long)previous.tv_usec);
- if (previous.tv_sec+1.0e-6*previous.tv_usec > ignore)
- fatal(0,"outstanding time adjustment %s",text);
- else if (verbose)
- fprintf(stderr,"%s: outstanding time adjustment %s\n",
- argv0,text);
- }
- }
-}
+++ /dev/null
-/* Copyright (C) 1996 N.M. Maclaren
- Copyright (C) 1996 The University of Cambridge
-
-This includes code that really should have been part of ANSI/ISO C, but was
-left out for historical reasons (despite requests to define ftty), plus
-the get_lock() and log_message() functions.
-*/
-
-#include "header.h"
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-
-#define UNIX
-#include "kludges.h"
-#undef UNIX
-
-
-void do_nothing (int seconds) {
-
-/* Wait for a fixed period, possibly uninterruptibly. This should not wait
-for less than the specified period, if that can be avoided. */
-
- sleep((unsigned int)(seconds+2)); /* +2 is enough for POSIX */
-}
-
-
-
-int ftty (FILE *file) {
-
-/* Return whether the file is attached to an interactive device. */
-
- return isatty(fileno(file));
-}
-
-
-
-void set_lock (int lock) {
-
-/* Check that we have enough privileges to reset the time and that no other
-updating msntp process is running, but don't bother with fancy interlocking.
-This function is really only to permit the daemon mode to be restarted in a
-cron job and improve the diagnostics; it can be replaced by a 'return'
-statement if it causes implementation difficulties. Note that there is little
-point in clearing the lock under Unix, but do so anyway. */
-
- FILE *file;
- long pid;
-
- if (lockname == NULL || lockname[0] == '\0') return;
- if (lock) {
- errno = 0;
- if ((file = fopen(lockname,"r")) != NULL &&
- fscanf(file,"%ld",&pid) == 1 && kill(pid,0) == 0) {
- if (verbose || isatty(STDIN_FILENO) || isatty(STDOUT_FILENO))
- fatal(0,"another msntp process is currently running",NULL);
- else
- fatal(0,NULL,NULL);
- }
- if (file != NULL) fclose(file);
- errno = 0;
- if ((file = fopen(lockname,"w")) == NULL ||
- fprintf(file,"%ld\n",(long)getpid()) <= 0 ||
- ferror(file) || fclose(file) != 0)
- fatal(1,"unable to write PID to %s",lockname);
- adjust_time(0.0,1,0.0);
- } else {
- errno = 0;
- if (remove(lockname) != 0)
- fatal(1,"unable to remove the msntp lockname %s",lockname);
- }
-}
-
-
-
-/*
- * Log a message, crudely.
- * This is used in only one place, but could be used more widely.
- */
-
-void
-log_message (const char *message)
-{
-
- syslog(
-#ifdef LOG_DAEMON
- LOG_DAEMON |
-#endif
- LOG_WARNING, "%s", message);
-}