aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-11 23:29:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-11 23:29:43 +0300
commitc83027e3d85cb244427bfca9fd39f569a1afbe7e (patch)
tree8c75e84d505c5942a56005b7ec6de8063c509bb4
parent64cf82872c62d0e440ac4271eacc136b6d54e3d9 (diff)
downloadslb-c83027e3d85cb244427bfca9fd39f569a1afbe7e.tar.gz
slb-c83027e3d85cb244427bfca9fd39f569a1afbe7e.tar.bz2
Update grecs.
-rw-r--r--Makefile.am2
-rw-r--r--NEWS8
-rw-r--r--README-hacking2
-rw-r--r--configure.ac6
-rw-r--r--git2chg.awk45
m---------grecs0
-rw-r--r--src/Makefile.am4
-rw-r--r--src/config.c81
-rw-r--r--src/expr.y2
-rw-r--r--src/getopt.m4807
-rw-r--r--src/slb.c14
-rw-r--r--src/slb.h2
12 files changed, 65 insertions, 908 deletions
diff --git a/Makefile.am b/Makefile.am
index 120ea87..d5e8704 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,6 +22,6 @@ SUBDIRS=grecs src doc examples tests
ChangeLog:
$(AM_V_GEN)if test -d .git; then \
git log --pretty='format:%ct %an <%ae>%n%n%s%n%n%b%n' | \
- awk -f $(top_srcdir)/git2chg.awk > ChangeLog; \
+ awk -f $(top_srcdir)/grecs/build-aux/git2chg.awk > ChangeLog; \
fi
diff --git a/NEWS b/NEWS
index ab30ee6..0dbd394 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,16 @@
-SLB NEWS -- history of user-visible changes. 2011-04-26
+SLB NEWS -- history of user-visible changes. 2011-05-11
Copyright (C) 2011 Sergey Poznyakoff
See the end of file for copying conditions.
Please send SLB bug reports to <gray+slb@gnu.org.ua>
+Version 1.0.90 (Git)
+
+* Use newer Grecs
+* Drop unneeded dependencies
+
+
Version 1.0, 2011-04-26
First release.
diff --git a/README-hacking b/README-hacking
index 271d961..1a3cd41 100644
--- a/README-hacking
+++ b/README-hacking
@@ -4,7 +4,7 @@ See end of file for copying conditions.
* Requirements
If you have taken the sources from GIT you will need the following
-packages to build mailfromd. I don't make any extra effort to accommodate
+packages to build SLB. I don't make any extra effort to accommodate
older versions of these packages, so please make sure that you have the
latest stable version.
diff --git a/configure.ac b/configure.ac
index 02dd7f5..4e02031 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,7 +15,7 @@
# along with SLB. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ(2.63)
-AC_INIT([slb], 1.0, [gray+slb@gnu.org.ua])
+AC_INIT([slb], 1.0.90, [gray+slb@gnu.org.ua])
AC_CONFIG_SRCDIR([src/slb.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADER([config.h])
@@ -51,7 +51,7 @@ AC_SUBST(NET_SNMP_CONFIG)
# Grecs subsystem
-GRECS_SETUP([],[$(top_srcdir)/src/pp-setup])
+GRECS_SETUP([grecs],[tests getopt git2chg],[$(top_srcdir)/src/pp-setup])
AH_BOTTOM([
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
@@ -70,8 +70,6 @@ AM_MISSING_PROG([AUTOM4TE], [autom4te])
AC_CONFIG_FILES([Makefile
- grecs/Makefile
- grecs/src/Makefile
src/Makefile
doc/Makefile
examples/Makefile])
diff --git a/git2chg.awk b/git2chg.awk
deleted file mode 100644
index 0692a54..0000000
--- a/git2chg.awk
+++ /dev/null
@@ -1,45 +0,0 @@
-# This file is part of Smap.
-# Copyright (C) 2010 Sergey Poznyakoff
-#
-# Smap 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, or (at your option)
-# any later version.
-#
-# Smap 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 Smap. If not, see <http://www.gnu.org/licenses/>.
-
-/^[0-9]+ .* +<[^>]+>/ {
- s = strftime("%F", $1)
- sub(/^[0-9]+ +/,"")
- if (s == datestr && author == $0)
- next
- datestr = s
- author = $0
- if (runlen) { runlen = 0; print "" }
- printf("%s %s\n", datestr, author)
- next
-}
-/^Signed-off-by:/ { next }
-/^<unknown>$/ { next }
-NF==0 {
- runlen++
- next
-}
-{ if (runlen) { runlen = 0; print "" }
- print "\t" $0 }
-
-END {
- print "\f"
- # Make sure Emacs won't recognize this line:
- print "Local", "Variables:"
- print "mode: change-log"
- print "version-control: never"
- print "buffer-read-only: t"
- print "End:"
-}
diff --git a/grecs b/grecs
-Subproject 3f39626191970d57a8ad406b72474d565627b04
+Subproject 3e5d6e9683d5d3efa3a82556d0f73892d674ed7
diff --git a/src/Makefile.am b/src/Makefile.am
index 88fd778..827270c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,12 +31,12 @@ slb_SOURCES =\
symimp.c
BUILT_SOURCES=cmdline.h
-EXTRA_DIST=cmdline.opt getopt.m4 expr.output
+EXTRA_DIST=cmdline.opt expr.output
SUFFIXES=.opt .c .h
.opt.h:
- m4 -s $(srcdir)/getopt.m4 $< | sed '1d' > $@
+ m4 -s $(top_srcdir)/grecs/build-aux/getopt.m4 $< | sed '1d' > $@
#NET_SNMP_INCLUDES = `$(NET_SNMP_CONFIG) --cflags`
NET_SNMP_INCLUDES =
diff --git a/src/config.c b/src/config.c
index da17bbb..42595cb 100644
--- a/src/config.c
+++ b/src/config.c
@@ -100,19 +100,19 @@ cb_define_expression(enum grecs_callback_command cmd,
return 1;
}
- if (value->v.arg.v[0].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("first argument not a string"));
return 1;
}
- if (value->v.arg.v[1].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("second argument not a string"));
return 1;
}
- if (compile_expression(value->v.arg.v[1].v.string, locus, &expr))
+ if (compile_expression(value->v.arg.v[1]->v.string, locus, &expr))
return 1;
- expr->ex_name = value->v.arg.v[0].v.string;
+ expr->ex_name = value->v.arg.v[0]->v.string;
rc = register_expression(expr);
free(expr);
@@ -136,7 +136,7 @@ cb_server_expression(enum grecs_callback_command cmd,
grecs_error(locus, 0, _("expected single string as argument"));
return 1;
}
-
+
return compile_expression(value->v.string, locus, pexpr);
}
@@ -159,31 +159,31 @@ cb_server_variable(enum grecs_callback_command cmd,
grecs_error(locus, 0, _("expected two arguments"));
return 1;
}
-
- if (value->v.arg.v[0].type != GRECS_TYPE_STRING) {
+
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("first argument not a string"));
return 1;
}
- if (value->v.arg.v[1].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("second argument not a string"));
return 1;
}
install = 1;
- inst = varinst_lookupz(vt, value->v.arg.v[0].v.string, &install);
+ inst = varinst_lookupz(vt, value->v.arg.v[0]->v.string, &install);
if (!install)
grecs_error(locus, 0,
_("redefinition of %s"), inst->vi_sym.name);
inst->vi_oidlen = MAX_OID_LEN;
- if (!read_objid(value->v.arg.v[1].v.string,
+ if (!read_objid(value->v.arg.v[1]->v.string,
inst->vi_oid, &inst->vi_oidlen)) {
grecs_error(locus, 0, _("cannot parse oid"));
return 1;
}
- inst->vi_mib = value->v.arg.v[1].v.string;
+ inst->vi_mib = grecs_strdup(value->v.arg.v[1]->v.string);
return 0;
}
@@ -209,23 +209,23 @@ cb_server_constant(enum grecs_callback_command cmd,
return 1;
}
- if (value->v.arg.v[0].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("first argument not a string"));
return 1;
}
- if (value->v.arg.v[1].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("second argument not a string"));
return 1;
}
install = 1;
- inst = varinst_lookupz(vt, value->v.arg.v[0].v.string, &install);
+ inst = varinst_lookupz(vt, value->v.arg.v[0]->v.string, &install);
if (!install)
grecs_error(locus, 0,
_("redefinition of %s"), inst->vi_sym.name);
- inst->vi_value = strtod(value->v.arg.v[1].v.string, &p);
+ inst->vi_value = strtod(value->v.arg.v[1]->v.string, &p);
if (*p) {
grecs_error(locus, 0, _("not a valid floating point number"));
return 1;
@@ -259,33 +259,33 @@ cb_server_assert(enum grecs_callback_command cmd,
return 1;
}
- if (value->v.arg.v[0].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("first argument not a string"));
return 1;
}
- if (value->v.arg.v[1].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("second argument not a string"));
return 1;
}
- if (value->v.arg.v[2].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[2]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("third argument not a string"));
return 1;
}
- if (strcmp(value->v.arg.v[1].v.string, "eq") == 0)
+ if (strcmp(value->v.arg.v[1]->v.string, "eq") == 0)
flags = 0;
- else if (strcmp(value->v.arg.v[1].v.string, "ne") == 0)
+ else if (strcmp(value->v.arg.v[1]->v.string, "ne") == 0)
flags = SLB_ASSERT_NE;
else {
grecs_error(locus, 0, _("invalid operation: %s"),
- value->v.arg.v[1].v.string);
+ value->v.arg.v[1]->v.string);
return 1;
}
oidlen = MAX_OID_LEN;
- if (!read_objid(value->v.arg.v[0].v.string, oid, &oidlen)) {
+ if (!read_objid(value->v.arg.v[0]->v.string, oid, &oidlen)) {
grecs_error(locus, 0, _("cannot parse oid"));
return 1;
}
@@ -295,19 +295,19 @@ cb_server_assert(enum grecs_callback_command cmd,
if (!install)
grecs_error(locus, 0,
_("redefinition of %s"),
- value->v.arg.v[0].v.string);
+ value->v.arg.v[0]->v.string);
- len = strlen(value->v.arg.v[0].v.string) + 1 +
- strlen(value->v.arg.v[1].v.string) + 1 +
- strlen(value->v.arg.v[2].v.string) + 1;
+ len = strlen(value->v.arg.v[0]->v.string) + 1 +
+ strlen(value->v.arg.v[1]->v.string) + 1 +
+ strlen(value->v.arg.v[2]->v.string) + 1;
ap->text = grecs_malloc(len);
- strcpy(ap->text, value->v.arg.v[0].v.string);
+ strcpy(ap->text, value->v.arg.v[0]->v.string);
strcat(ap->text, " ");
- strcat(ap->text, value->v.arg.v[1].v.string);
+ strcat(ap->text, value->v.arg.v[1]->v.string);
strcat(ap->text, " ");
- strcat(ap->text, value->v.arg.v[2].v.string);
+ strcat(ap->text, value->v.arg.v[2]->v.string);
- ap->value = grecs_strdup(value->v.arg.v[2].v.string);
+ ap->value = grecs_strdup(value->v.arg.v[2]->v.string);
ap->flags = flags;
ap->locus = *locus;
return 0;
@@ -333,23 +333,23 @@ cb_server_macro(enum grecs_callback_command cmd,
return 1;
}
- if (value->v.arg.v[0].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("first argument not a string"));
return 1;
}
- if (value->v.arg.v[1].type != GRECS_TYPE_STRING) {
+ if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) {
grecs_error(locus, 0, _("second argument not a string"));
return 1;
}
install = 1;
- mac = macro_lookupz(mt, value->v.arg.v[0].v.string, &install);
+ mac = macro_lookupz(mt, value->v.arg.v[0]->v.string, &install);
if (!install)
grecs_error(locus, 0,
_("redefinition of macro %s"), mac->mac_sym.name);
- mac->mac_exp = value->v.arg.v[1].v.string;
+ mac->mac_exp = grecs_strdup(value->v.arg.v[1]->v.string);
return 0;
}
@@ -571,14 +571,13 @@ config_help()
static char docstring[] =
N_("Configuration file structure for SLB.\n"
"For more information, use `info slb configuration'.");
- grecs_format_docstring (stdout, docstring, 0);
- grecs_format_statement_array (stdout, slb_kw, 1, 0);
+ grecs_format_docstring(docstring, 0, stdout);
+ grecs_format_statement_array(slb_kw, 1, 0, stdout);
}
void
config_init()
{
- grecs_set_keywords(slb_kw);
grecs_include_path_setup(DEFAULT_VERSION_INCLUDE_DIR,
DEFAULT_INCLUDE_DIR, NULL);
grecs_preprocessor = DEFAULT_PREPROCESSOR;
@@ -621,11 +620,15 @@ run_config_finish_hooks()
}
void
-config_finish()
+config_finish(struct grecs_node *tree)
{
struct slb_server *srv;
struct slb_expression *defexpr = NULL;
-
+
+ if (grecs_tree_process(tree, slb_kw))
+ exit(EX_CONFIG);
+ grecs_tree_free(tree);
+
init_mib();
/* Load requested MIBs */
diff --git a/src/expr.y b/src/expr.y
index a309b16..32489a2 100644
--- a/src/expr.y
+++ b/src/expr.y
@@ -491,7 +491,7 @@ compile_expression(const char *text, grecs_locus_t *locus,
if (rc == 0) {
struct slb_expression *expr = grecs_zalloc(sizeof(*expr));
expr->ex_name = NULL;
- expr->ex_text = text;
+ expr->ex_text = grecs_strdup(text);
if (locus)
expr->ex_locus = *locus;
else
diff --git a/src/getopt.m4 b/src/getopt.m4
deleted file mode 100644
index 808c688..0000000
--- a/src/getopt.m4
+++ /dev/null
@@ -1,807 +0,0 @@
-dnl This file is part of SLB.
-dnl Copyright (C) 2010,2011 Sergey Poznyakoff
-dnl
-dnl SLB is free software; you can redistribute it and/or modify
-dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 3, or (at your option)
-dnl any later version.
-dnl
-dnl SLB is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-dnl GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with SLB. If not, see <http://www.gnu.org/licenses/>.
-divert(-1)
-changequote([<,>])
-changecom(/*,*/)
-
-dnl _getopt_mangle_option(NAME)
-dnl ---------------------------
-dnl Convert NAME to a valid m4 identifier, by replacing invalid characters
-dnl with underscores, and prepend the _GETOPT_OPTION_ suffix to it.
-define([<_getopt_mangle_option>],
- [<[<_GETOPT_OPTION_>]patsubst($1, [<[^a-zA-Z0-9_]>], [<_>])>])
-
-dnl _getopt_set_option(NAME[=VAL])
-dnl ------------------------------
-dnl Set option NAME.
-define([<_getopt_set_option>],
- [<ifelse(index([<$1>],=),-1,[<define(_getopt_mangle_option($1))>],
- [<define(regexp([<$1>],\([^=]+\)=\(.*\),
- [<_getopt_mangle_option(\1),[<\2>]>]))>])>])
-
-dnl _getopt_get_option(NAME[,DEFAULT])
-dnl ------------------------------
-define([<_getopt_get_option>],
- [<_getopt_if_option_set($1,[<indir(_getopt_mangle_option($1))>],[<$2>])>])
-
-dnl _getopt_if_option_set(NAME,IF-SET,IF-NOT-SET)
-dnl ---------------------------------------------
-dnl Check if option NAME is set.
-define([<_getopt_if_option_set>],
- [<ifdef(_getopt_mangle_option([<$1>]),[<$2>],[<$3>])>])
-
-dnl _getopt_option_switch(NAME1,IF-SET1,[NAME2,IF-SET2,[...]],[IF-NOT-SET])
-dnl ------------------------------------------------------------------------
-dnl If NAME1 is set, run IF-SET1. Otherwise, if NAME2 is set, run IF-SET2.
-dnl Continue the process for all name-if-set pairs within [...]. If none
-dnl of the options is set, run IF-NOT-SET.
-define([<_getopt_option_switch>],
- [<ifelse([<$4>],,[<_getopt_if_option_set($@)>],
- [<$3>],,[<_getopt_if_option_set($@)>],
- [<_getopt_if_option_set([<$1>],[<$2>],
- [<_getopt_option_switch(shift(shift($@)))>])>])>])
-
-dnl _getopt_if_option_val(NAME,val,IF-TRUE,IF-FALSE)
-dnl ---------------------------------------------
-dnl Check if option NAME is set.
-define([<_getopt_if_option_val>],
- [<ifelse(_getopt_get_option([<$1>]),[<$2>],[<$3>],[<$4>])>])
-
-define([<__getopt_switch_option_val>],
-[<ifelse([<$#>],2,[<$2>],dnl
- [<$#>],3,[<ifelse([<$1>],[<$2>],[<$3>])>],dnl
-[<ifelse([<$1>],[<$2>],[<$3>],dnl
-[<__getopt_switch_option_val([<$1>],shift(shift(shift($@))))>])>])>])
-
-dnl _getopt_switch_option_val(NAME,val1,IF-VAL1,val2,IF-VAL2...,ELSE)
-dnl -----------------------------------------------------------------
-dnl Check if option NAME is set.
-define([<_getopt_switch_option_val>],
-[<pushdef([<val>],[<_getopt_get_option($1)>])dnl
-__getopt_switch_option_val(val, shift($@))[<>]dnl
-popdef([<val>])>])
-
-dnl _getopt_set_options(OPTION[,OPTION...])
-dnl ---------------------------------------
-dnl Set options given as arguments.
-define([<_getopt_set_options>],
- [<ifelse([<$1>],,,
- [<_getopt_set_option([<$1>])
- _getopt_set_options(shift($@))>])>])
-
-dnl format_authors(name[,name...])
-dnl ------------------------------
-define([<format_authors>],dnl
- [<ifelse([<$1>],,NULL,[<"$1",
-format_authors(shift($@))>])>])
-
-dnl upcase(ARGS...)
-dnl Concatenate and convert ARGS to upper case.
-dnl
-define([<upcase>], [<translit([<$*>], [<a-z>], [<A-Z>])>])
-
-dnl concat(ARGS...)
-dnl Concatenate arguments, inserting ", " between each of pair of them.
-dnl
-define([<concat>],[<ifelse([<$#>],1,[<$1>],[<$1, concat(shift($@))>])>])
-
-dnl flushleft(ARGS...)
-dnl Concatenate ARGS and remove any leading whitespace
-dnl
-define([<flushleft>],
- [<patsubst([<concat($*)>], [<^[ ]+>])>])
-
-dnl chop(ARGS...)
-dnl Concatenate ARGS and remove any trailing whitespace
-dnl
-define([<chop>],
- [<patsubst([<$*>], [<[ ]+$>])>])
-
-dnl escape(ARGS...)
-dnl Concatenate ARGS and escape any occurrences of double-quotes with
-dnl backslashes.
-dnl
-define([<escape>],
-[<patsubst([<concat($*)>],[<[\"]>],[<\\\&>])>])
-
-dnl prep(ARG)
-dnl Prepare ARG for including in C strings: replace newlines with any amount
-dnl of preceding and following whitespace by a single space character, remove
-dnl leading whitespace, and escape double-quotes.
-dnl
-define([<prep>],
- [<escape(flushleft(patsubst([<$1>],[<[ ]*
-+[ ]*>],[< >])))>])
-
-dnl SHORT_OPTS
-dnl Accumulator for the 3rd argument of getopt_long
-dnl
-define([<SHORT_OPTS>],[<>])
-
-dnl GROUP(STRING)
-dnl Begin a named group of options
-dnl
-define([<GROUP>],[<dnl
-divert(3)
- { NULL, NULL, 0, N_("prep([<$1>])") },
-divert(-1)>])
-
-define([<__GATHER_OPTIONS>],[<
-define([<KEY>],ifelse([<$2>],,[<OPTION_>]upcase(patsubst($1,-,_)),'$2'))
-ifelse([<$2>],,[<
-divert(1)
- KEY,
-divert(-1)
->])
-define([<SELECTOR>],ifdef([<SELECTOR>],SELECTOR) case KEY:)
-ifelse([<$1>],,,[<
-divert(2)
- { "$1", ARGTYPE, 0, KEY },
-divert(-1)>])
-dnl
-define([<SHORT_OPTS>],SHORT_OPTS[<>]dnl
-ifelse([<$2>],,,$2[<>]ifelse(ARGTYPE,[<no_argument>],,ARGTYPE,[<required_argument>],:,ARGTYPE,[<optional_argument>],::)))
-dnl
-ifelse([<$1>],,,dnl
-[<define([<LONG_TAG>],ifelse(LONG_TAG,,[<--$1>],[<LONG_TAG; --$1>]))>])
-ifelse([<$2>],,,dnl
-[<define([<SHORT_TAG>],ifelse(SHORT_TAG,,[<-$2>],[<SHORT_TAG; -$2>]))>])
->])
-
-dnl OPTION(long-opt, short-opt, [arg], [descr])
-dnl Introduce a command line option. Arguments:
-dnl long-opt Long option.
-dnl short-opt Short option (a single char)
-dnl (At least one of long-opt or short-opt must be present)
-dnl
-dnl Optional arguments:
-dnl arg Option argument.
-dnl descr Option description
-dnl
-dnl If arg is absent, the option does not take any arguments. If arg is
-dnl enclosed in square brackets, the option takes an optional argument.
-dnl Otherwise, the argument is required.
-dnl
-dnl If descr is not given the option will not appear in the --help and
-dnl --usage outputs.
-dnl
-define([<OPTION>],[<
-pushdef([<LONG_TAG>])
-pushdef([<SHORT_TAG>])
-pushdef([<ARGNAME>],[<$3>])
-pushdef([<HIDDEN>],ifelse([<$4>],,1,0))
-pushdef([<DOCSTRING>],[<prep([<$4>])>])
-pushdef([<ARGTYPE>],[<ifelse([<$3>],,[<no_argument>],dnl
-patsubst([<$3>],[<\[.*\]>]),,[<optional_argument>],dnl
-[<required_argument>])>])
-__GATHER_OPTIONS($@)
->])
-
-dnl ALIAS(long-opt, short-opt)
-dnl Declare aliases for the previous OPTION statement.
-dnl long-opt Long option.
-dnl short-opt Short option (a single char)
-dnl (At least one of long-opt or short-opt must be present)
-dnl An OPTION statement may be followed by any number of ALIAS statements.
-dnl
-define([<ALIAS>],[<
-__GATHER_OPTIONS($1,$2)
->])
-
-dnl BEGIN
-dnl Start an action associated with the declared option. Must follow OPTION
-dnl statement, with optional ALIAS statements in between.
-dnl
-define([<BEGIN>],[<
-ifelse(HIDDEN,1,,[<
-divert(3)
- {
-#ifdef HAVE_GETOPT_LONG
- "translit(dnl
-ifelse(SHORT_TAG,,LONG_TAG,[<SHORT_TAG[<>]ifelse(LONG_TAG,,,; LONG_TAG)>]),
- [<;>],[<,>])",
-#else
- "translit(SHORT_TAG, [<;>],[<,>])",
-#endif
- ifelse(ARGNAME,,[<NULL, 0>],
-[<ifelse(ARGTYPE,[<optional_argument>],
-[<N_(>]"[<patsubst(ARGNAME,[<\[\(.*\)\]>],[<\1>])>][<"), 1>],[<N_("ARGNAME"), 0>])>]), N_("DOCSTRING") },
-divert(-1)>])
-popdef([<ARGTYPE>])
-popdef([<ARGNAME>])
-popdef([<DOCSTRING>])
-popdef([<HIDDEN>])
-divert(4)dnl
-popdef([<LONG_TAG>])dnl
-popdef([<SHORT_TAG>])dnl
- SELECTOR
- {
->])
-
-dnl END
-dnl Finish the associated action
-dnl
-define([<END>],[<
- break;
- }
-divert(-1)
-undefine([<SELECTOR>])>])
-
-dnl GETOPT(argc, argv, [long_index], [onerr])
-dnl Emit option parsing code. Arguments:
-dnl
-dnl argc Name of the 1st argument to getopt_long.
-dnl argv Name of the 2nd argument to getopt_long.
-dnl long_index 5th argument to getopt_long. If not given,
-dnl NULL will be passed.
-dnl onerr Action to take if parsing fails.
-dnl
-define([<GETOPT>],[<
- {
- int c;
-
-#ifdef HAVE_GETOPT_LONG
- while ((c = getopt_long($1, $2, "SHORT_OPTS",
- long_options, NULL)) != EOF)
-#else
- while ((c = getopt($1, $2, "SHORT_OPTS")) != EOF)
-#endif
- {
- switch (c)
- {
- default:
- ifelse([<$4>],,,[<$4;>])dnl
- exit(EX_USAGE);
- undivert(4)
- }
- }
- ifelse([<$3>],,[<
- if (optind < argc) {
- fprintf(stderr, "%s: unexpected arguments\n", $2[0]);
- exit(EX_USAGE);
- }
->],[<$3 = optind;>])
- }
->])
-
-define([<STDFUNC>],[<
-divert(0)
-void print_help(void);
-void print_usage(void);
-divert(5)
-const char *program_version = [<$1>];
-static char doc[] = N_("[<$3>]");
-static char args_doc[] = N_("[<$4>]");
-const char *program_bug_address = "<" PACKAGE_BUGREPORT ">";
-
-#define DESCRCOLUMN 30
-#define RMARGIN 79
-#define GROUPCOLUMN 2
-#define USAGECOLUMN 13
-
-static void
-indent (size_t start, size_t col)
-{
- for (; start < col; start++)
- putchar (' ');
-}
-
-static void
-print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
-{
- while (*descr)
- {
- size_t s = 0;
- size_t i;
- size_t width = rmargin - lmargin;
-
- for (i = 0; ; i++)
- {
- if (descr[i] == 0 || descr[i] == ' ' || descr[i] == '\t')
- {
- if (i > width)
- break;
- s = i;
- if (descr[i] == 0)
- break;
- }
- }
- printf ("%*.*s\n", s, s, descr);
- descr += s;
- if (*descr)
- {
- indent (0, lmargin);
- descr++;
- }
- }
-}
-
-#define NOPTHELP (sizeof (opthelp) / sizeof (opthelp[0]))
-
-static int
-optcmp (const void *a, const void *b)
-{
- struct opthelp const *ap = (struct opthelp const *)a;
- struct opthelp const *bp = (struct opthelp const *)b;
- const char *opta, *optb;
- size_t alen, blen;
-
- for (opta = ap->opt; *opta == '-'; opta++)
- ;
- alen = strcspn (opta, ",");
-
- for (optb = bp->opt; *optb == '-'; optb++)
- ;
- blen = strcspn (optb, ",");
-
- if (alen > blen)
- blen = alen;
-
- return strncmp (opta, optb, blen);
-}
-
-static void
-sort_options (int start, int count)
-{
- qsort (opthelp + start, count, sizeof (opthelp[0]), optcmp);
-}
-
-static int
-sort_group (int start)
-{
- int i;
-
- for (i = start; i < NOPTHELP && opthelp[i].opt; i++)
- ;
- sort_options (start, i - start);
- return i + 1;
-}
-
-static void
-sort_opthelp (void)
-{
- int start;
-
- for (start = 0; start < NOPTHELP; )
- {
- if (!opthelp[start].opt)
- start = sort_group (start + 1);
- else
- start = sort_group (start);
- }
-}
-
-void
-print_help (void)
-{
- unsigned i;
- int argsused = 0;
-
- printf ("%s %s [%s]... %s\n", _("Usage:"), [<$2>], _("[<OPTION>]"),
- gettext (args_doc));
- if (doc[0])
- print_option_descr(gettext (doc), 0, RMARGIN);
- putchar ('\n');
-
- sort_opthelp ();
- for (i = 0; i < NOPTHELP; i++)
- {
- unsigned n;
- if (opthelp[i].opt)
- {
- n = printf (" %s", opthelp[i].opt);
- if (opthelp[i].arg)
- {
- char *cb, *ce;
- argsused = 1;
- if (strlen (opthelp[i].opt) == 2)
- {
- if (!opthelp[i].is_optional)
- {
- putchar (' ');
- n++;
- }
- }
- else
- {
- putchar ('=');
- n++;
- }
- if (opthelp[i].is_optional)
- {
- cb = "[";
- ce = "]";
- }
- else
- cb = ce = "";
- n += printf ("%s%s%s", cb, gettext (opthelp[i].arg), ce);
- }
- if (n >= DESCRCOLUMN)
- {
- putchar ('\n');
- n = 0;
- }
- indent (n, DESCRCOLUMN);
- print_option_descr (gettext (opthelp[i].descr), DESCRCOLUMN, RMARGIN);
- }
- else
- {
- if (i)
- putchar ('\n');
- indent (0, GROUPCOLUMN);
- print_option_descr (gettext (opthelp[i].descr),
- GROUPCOLUMN, RMARGIN);
- putchar ('\n');
- }
- }
-
- putchar ('\n');
-dnl **************************************************************************
-dnl This string cannot be split over serveal lines, because this would trigger
-dnl a bug in GNU M4 (version 1.4.9 and 1.4.10), which would insert #line
-dnl directives between the lines.
-dnl **************************************************************************
- if (argsused)
- {
- print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN);
- putchar ('\n');
- }
-
- /* TRANSLATORS: The placeholder indicates the bug-reporting address
- for this package. Please add _another line_ saying
- "Report translation bugs to <...>\n" with the address for translation
- bugs (typically your translation team's web or email address). */
- printf (_("Report bugs to %s.\n"), program_bug_address);
-
-#ifdef PACKAGE_URL
- printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
-_getopt_if_option_set([<gnupackage>],[<#else
- printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"),
- PACKAGE_NAME, PACKAGE);
-#endif
- fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
- stdout);>],
-[<#endif>])
-}
-
-static int
-cmpidx_short (const void *a, const void *b)
-{
- unsigned const *ai = (unsigned const *)a;
- unsigned const *bi = (unsigned const *)b;
-
- return opthelp[*ai].opt[1] - opthelp[*bi].opt[1];
-}
-
-#ifdef HAVE_GETOPT_LONG
-static int
-cmpidx_long (const void *a, const void *b)
-{
- unsigned const *ai = (unsigned const *)a;
- unsigned const *bi = (unsigned const *)b;
- struct opthelp const *ap = opthelp + *ai;
- struct opthelp const *bp = opthelp + *bi;
- char const *opta, *optb;
- size_t lena, lenb;
-
- if (ap->opt[1] == '-')
- opta = ap->opt;
- else
- opta = ap->opt + 4;
- lena = strcspn (opta, ",");
-
- if (bp->opt[1] == '-')
- optb = bp->opt;
- else
- optb = bp->opt + 4;
- lenb = strcspn (optb, ",");
- return strncmp (opta, optb, lena > lenb ? lenb : lena);
-}
-#endif
-
-void
-print_usage (void)
-{
- unsigned i;
- unsigned n;
- char buf[RMARGIN+1];
- unsigned *idxbuf;
- unsigned nidx;
-
-#define FLUSH dnl
- do dnl
- { dnl
- buf[n] = 0; dnl
- printf ("%s\n", buf); dnl
- n = USAGECOLUMN; dnl
- memset (buf, ' ', n); dnl
- } dnl
- while (0)
-#define ADDC(c) dnl
- do { if (n == RMARGIN) FLUSH; buf[n++] = c; } while (0)
-
- idxbuf = calloc (NOPTHELP, sizeof (idxbuf[0]));
- if (!idxbuf)
- {
- fprintf (stderr, "not enough memory");
- abort ();
- }
-
- n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"), [<$2>]);
-
- /* Print a list of short options without arguments. */
- for (i = nidx = 0; i < NOPTHELP; i++)
- if (opthelp[i].opt && opthelp[i].descr && opthelp[i].opt[1] != '-'
- && opthelp[i].arg == NULL)
- idxbuf[nidx++] = i;
-
- if (nidx)
- {
- qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
-
- ADDC ('[');
- ADDC ('-');
- for (i = 0; i < nidx; i++)
- {
- ADDC (opthelp[idxbuf[i]].opt[1]);
- }
- ADDC (']');
- }
-
- /* Print a list of short options with arguments. */
- for (i = nidx = 0; i < NOPTHELP; i++)
- {
- if (opthelp[i].opt && opthelp[i].descr && opthelp[i].opt[1] != '-'
- && opthelp[i].arg)
- idxbuf[nidx++] = i;
- }
-
- if (nidx)
- {
- qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
-
- for (i = 0; i < nidx; i++)
- {
- struct opthelp *opt = opthelp + idxbuf[i];
- size_t len = 5 + strlen (opt->arg)
- + (opt->is_optional ? 2 : 1);
-
- if (n + len > RMARGIN) FLUSH;
- buf[n++] = ' ';
- buf[n++] = '[';
- buf[n++] = '-';
- buf[n++] = opt->opt[1];
- if (opt->is_optional)
- {
- buf[n++] = '[';
- strcpy (&buf[n], opt->arg);
- n += strlen (opt->arg);
- buf[n++] = ']';
- }
- else
- {
- buf[n++] = ' ';
- strcpy (&buf[n], opt->arg);
- n += strlen (opt->arg);
- }
- buf[n++] = ']';
- }
- }
-
-#ifdef HAVE_GETOPT_LONG
- /* Print a list of long options */
- for (i = nidx = 0; i < NOPTHELP; i++)
- {
- if (opthelp[i].opt && opthelp[i].descr
- && (opthelp[i].opt[1] == '-' || opthelp[i].opt[2] == ','))
- idxbuf[nidx++] = i;
- }
-
- if (nidx)
- {
- qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_long);
-
- for (i = 0; i < nidx; i++)
- {
- struct opthelp *opt = opthelp + idxbuf[i];
- size_t len;
- const char *longopt;
-
- if (opt->opt[1] == '-')
- longopt = opt->opt;
- else if (opt->opt[2] == ',')
- longopt = opt->opt + 4;
- else
- continue;
-
- len = 3 + strlen (longopt)
- + (opt->arg ? 1 + strlen (opt->arg)
- + (opt->is_optional ? 2 : 0) : 0);
- if (n + len > RMARGIN) FLUSH;
- buf[n++] = ' ';
- buf[n++] = '[';
- strcpy (&buf[n], longopt);
- n += strlen (longopt);
- if (opt->arg)
- {
- buf[n++] = '=';
- if (opt->is_optional)
- {
- buf[n++] = '[';
- strcpy (&buf[n], opt->arg);
- n += strlen (opt->arg);
- buf[n++] = ']';
- }
-