summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'grammar')
-rw-r--r--grammar/Makefile.am20
-rw-r--r--grammar/Makefile.in810
-rw-r--r--grammar/grammar.c2342
-rw-r--r--grammar/grammar.h186
-rw-r--r--grammar/grammar.y243
-rw-r--r--grammar/lexer.c4150
-rw-r--r--grammar/lexer.l590
-rw-r--r--grammar/parserif.h44
-rw-r--r--grammar/rainerscript.c5806
-rw-r--r--grammar/rainerscript.h409
10 files changed, 14600 insertions, 0 deletions
diff --git a/grammar/Makefile.am b/grammar/Makefile.am
new file mode 100644
index 0000000..17bc634
--- /dev/null
+++ b/grammar/Makefile.am
@@ -0,0 +1,20 @@
+BUILT_SOURCES = grammar.h
+CLEANFILES = grammar.h grammar.c lexer.c
+AM_YFLAGS = -d
+noinst_LTLIBRARIES = libgrammar.la
+#bin_PROGRAMS = testdriver # TODO: make this conditional
+
+libgrammar_la_SOURCES = \
+ grammar.y \
+ lexer.l \
+ rainerscript.c \
+ rainerscript.h \
+ parserif.h \
+ grammar.h
+libgrammar_la_CPPFLAGS = $(RSRT_CFLAGS) $(LIBLOGGING_STDLOG_CFLAGS)
+libgrammar_la_LIBADD =
+
+#testdriver_SOURCES = testdriver.c libgrammar.la
+#testdriver_CPPFLAGS = $(RSRT_CFLAGS)
+#testdriver_LDADD = libgrammar.la
+#testdriver_LDFLAGS = -lestr
diff --git a/grammar/Makefile.in b/grammar/Makefile.in
new file mode 100644
index 0000000..7e452f3
--- /dev/null
+++ b/grammar/Makefile.in
@@ -0,0 +1,810 @@
+# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = grammar
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_define.m4 \
+ $(top_srcdir)/m4/atomic_operations.m4 \
+ $(top_srcdir)/m4/atomic_operations_64bit.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libgrammar_la_DEPENDENCIES =
+am_libgrammar_la_OBJECTS = libgrammar_la-grammar.lo \
+ libgrammar_la-lexer.lo libgrammar_la-rainerscript.lo
+libgrammar_la_OBJECTS = $(am_libgrammar_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/libgrammar_la-grammar.Plo \
+ ./$(DEPDIR)/libgrammar_la-lexer.Plo \
+ ./$(DEPDIR)/libgrammar_la-rainerscript.Plo
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+LEXCOMPILE = $(LEX) $(AM_LFLAGS) $(LFLAGS)
+LTLEXCOMPILE = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(LEX) $(AM_LFLAGS) $(LFLAGS)
+AM_V_LEX = $(am__v_LEX_@AM_V@)
+am__v_LEX_ = $(am__v_LEX_@AM_DEFAULT_V@)
+am__v_LEX_0 = @echo " LEX " $@;
+am__v_LEX_1 =
+YLWRAP = $(top_srcdir)/ylwrap
+am__yacc_c2h = sed -e s/cc$$/hh/ -e s/cpp$$/hpp/ -e s/cxx$$/hxx/ \
+ -e s/c++$$/h++/ -e s/c$$/h/
+YACCCOMPILE = $(YACC) $(AM_YFLAGS) $(YFLAGS)
+LTYACCCOMPILE = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(YACC) $(AM_YFLAGS) $(YFLAGS)
+AM_V_YACC = $(am__v_YACC_@AM_V@)
+am__v_YACC_ = $(am__v_YACC_@AM_DEFAULT_V@)
+am__v_YACC_0 = @echo " YACC " $@;
+am__v_YACC_1 =
+SOURCES = $(libgrammar_la_SOURCES)
+DIST_SOURCES = $(libgrammar_la_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
+ $(top_srcdir)/ylwrap grammar.c grammar.h lexer.c
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APU_CFLAGS = @APU_CFLAGS@
+APU_LIBS = @APU_LIBS@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CIVETWEB_LIBS = @CIVETWEB_LIBS@
+CONF_FILE_PATH = @CONF_FILE_PATH@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CURL_CFLAGS = @CURL_CFLAGS@
+CURL_LIBS = @CURL_LIBS@
+CYGPATH_W = @CYGPATH_W@
+CZMQ_CFLAGS = @CZMQ_CFLAGS@
+CZMQ_LIBS = @CZMQ_LIBS@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DL_LIBS = @DL_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FAUP_LIBS = @FAUP_LIBS@
+FGREP = @FGREP@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_LIBS = @GLIB_LIBS@
+GNUTLS_CFLAGS = @GNUTLS_CFLAGS@
+GNUTLS_LIBS = @GNUTLS_LIBS@
+GREP = @GREP@
+GSS_LIBS = @GSS_LIBS@
+GT_KSI_LS12_CFLAGS = @GT_KSI_LS12_CFLAGS@
+GT_KSI_LS12_LIBS = @GT_KSI_LS12_LIBS@
+HASH_XXHASH_LIBS = @HASH_XXHASH_LIBS@
+HIREDIS_CFLAGS = @HIREDIS_CFLAGS@
+HIREDIS_LIBS = @HIREDIS_LIBS@
+IMUDP_LIBS = @IMUDP_LIBS@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+IP = @IP@
+JAVA = @JAVA@
+JAVAC = @JAVAC@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LEX = @LEX@
+LEXLIB = @LEXLIB@
+LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
+LIBCAPNG_CFLAGS = @LIBCAPNG_CFLAGS@
+LIBCAPNG_LIBS = @LIBCAPNG_LIBS@
+LIBCAPNG_PRESENT_CFLAGS = @LIBCAPNG_PRESENT_CFLAGS@
+LIBCAPNG_PRESENT_LIBS = @LIBCAPNG_PRESENT_LIBS@
+LIBDBI_CFLAGS = @LIBDBI_CFLAGS@
+LIBDBI_LIBS = @LIBDBI_LIBS@
+LIBESTR_CFLAGS = @LIBESTR_CFLAGS@
+LIBESTR_LIBS = @LIBESTR_LIBS@
+LIBEVENT_CFLAGS = @LIBEVENT_CFLAGS@
+LIBEVENT_LIBS = @LIBEVENT_LIBS@
+LIBFASTJSON_CFLAGS = @LIBFASTJSON_CFLAGS@
+LIBFASTJSON_LIBS = @LIBFASTJSON_LIBS@
+LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
+LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
+LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
+LIBLOGGING_CFLAGS = @LIBLOGGING_CFLAGS@
+LIBLOGGING_LIBS = @LIBLOGGING_LIBS@
+LIBLOGGING_STDLOG_CFLAGS = @LIBLOGGING_STDLOG_CFLAGS@
+LIBLOGGING_STDLOG_LIBS = @LIBLOGGING_STDLOG_LIBS@
+LIBLOGNORM_CFLAGS = @LIBLOGNORM_CFLAGS@
+LIBLOGNORM_LIBS = @LIBLOGNORM_LIBS@
+LIBLZ4_CFLAGS = @LIBLZ4_CFLAGS@
+LIBLZ4_LIBS = @LIBLZ4_LIBS@
+LIBM = @LIBM@
+LIBMONGOC_CFLAGS = @LIBMONGOC_CFLAGS@
+LIBMONGOC_LIBS = @LIBMONGOC_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBRDKAFKA_CFLAGS = @LIBRDKAFKA_CFLAGS@
+LIBRDKAFKA_LIBS = @LIBRDKAFKA_LIBS@
+LIBS = @LIBS@
+LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@
+LIBSYSTEMD_JOURNAL_CFLAGS = @LIBSYSTEMD_JOURNAL_CFLAGS@
+LIBSYSTEMD_JOURNAL_LIBS = @LIBSYSTEMD_JOURNAL_LIBS@
+LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@
+LIBTOOL = @LIBTOOL@
+LIBUUID_CFLAGS = @LIBUUID_CFLAGS@
+LIBUUID_LIBS = @LIBUUID_LIBS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MYSQL_CFLAGS = @MYSQL_CFLAGS@
+MYSQL_CONFIG = @MYSQL_CONFIG@
+MYSQL_LIBS = @MYSQL_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OPENSSL_CFLAGS = @OPENSSL_CFLAGS@
+OPENSSL_LIBS = @OPENSSL_LIBS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PGSQL_CFLAGS = @PGSQL_CFLAGS@
+PGSQL_LIBS = @PGSQL_LIBS@
+PG_CONFIG = @PG_CONFIG@
+PID_FILE_PATH = @PID_FILE_PATH@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PROTON_CFLAGS = @PROTON_CFLAGS@
+PROTON_LIBS = @PROTON_LIBS@
+PROTON_PROACTOR_CFLAGS = @PROTON_PROACTOR_CFLAGS@
+PROTON_PROACTOR_LIBS = @PROTON_PROACTOR_LIBS@
+PTHREADS_CFLAGS = @PTHREADS_CFLAGS@
+PTHREADS_LIBS = @PTHREADS_LIBS@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RABBITMQ_CFLAGS = @RABBITMQ_CFLAGS@
+RABBITMQ_LIBS = @RABBITMQ_LIBS@
+RANLIB = @RANLIB@
+READLINK = @READLINK@
+REDIS = @REDIS@
+RELP_CFLAGS = @RELP_CFLAGS@
+RELP_LIBS = @RELP_LIBS@
+RSRT_CFLAGS = @RSRT_CFLAGS@
+RSRT_CFLAGS1 = @RSRT_CFLAGS1@
+RSRT_LIBS = @RSRT_LIBS@
+RSRT_LIBS1 = @RSRT_LIBS1@
+RST2MAN = @RST2MAN@
+RT_LIBS = @RT_LIBS@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SNMP_CFLAGS = @SNMP_CFLAGS@
+SNMP_LIBS = @SNMP_LIBS@
+SOL_LIBS = @SOL_LIBS@
+STRIP = @STRIP@
+TCL_BIN_DIR = @TCL_BIN_DIR@
+TCL_INCLUDE_SPEC = @TCL_INCLUDE_SPEC@
+TCL_LIB_FILE = @TCL_LIB_FILE@
+TCL_LIB_FLAG = @TCL_LIB_FLAG@
+TCL_LIB_SPEC = @TCL_LIB_SPEC@
+TCL_PATCH_LEVEL = @TCL_PATCH_LEVEL@
+TCL_SRC_DIR = @TCL_SRC_DIR@
+TCL_STUB_LIB_FILE = @TCL_STUB_LIB_FILE@
+TCL_STUB_LIB_FLAG = @TCL_STUB_LIB_FLAG@
+TCL_STUB_LIB_SPEC = @TCL_STUB_LIB_SPEC@
+TCL_VERSION = @TCL_VERSION@
+UDPSPOOF_CFLAGS = @UDPSPOOF_CFLAGS@
+UDPSPOOF_LIBS = @UDPSPOOF_LIBS@
+VALGRIND = @VALGRIND@
+VERSION = @VERSION@
+WARN_CFLAGS = @WARN_CFLAGS@
+WARN_LDFLAGS = @WARN_LDFLAGS@
+WARN_SCANNERFLAGS = @WARN_SCANNERFLAGS@
+WGET = @WGET@
+YACC = @YACC@
+YACC_FOUND = @YACC_FOUND@
+YFLAGS = @YFLAGS@
+ZLIB_CFLAGS = @ZLIB_CFLAGS@
+ZLIB_LIBS = @ZLIB_LIBS@
+ZSTD_CFLAGS = @ZSTD_CFLAGS@
+ZSTD_LIBS = @ZSTD_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+moddirs = @moddirs@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+BUILT_SOURCES = grammar.h
+CLEANFILES = grammar.h grammar.c lexer.c
+AM_YFLAGS = -d
+noinst_LTLIBRARIES = libgrammar.la
+#bin_PROGRAMS = testdriver # TODO: make this conditional
+libgrammar_la_SOURCES = \
+ grammar.y \
+ lexer.l \
+ rainerscript.c \
+ rainerscript.h \
+ parserif.h \
+ grammar.h
+
+libgrammar_la_CPPFLAGS = $(RSRT_CFLAGS) $(LIBLOGGING_STDLOG_CFLAGS)
+libgrammar_la_LIBADD =
+all: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .l .lo .o .obj .y
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu grammar/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnu grammar/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+grammar.h: grammar.c
+ @if test ! -f $@; then rm -f grammar.c; else :; fi
+ @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) grammar.c; else :; fi
+
+libgrammar.la: $(libgrammar_la_OBJECTS) $(libgrammar_la_DEPENDENCIES) $(EXTRA_libgrammar_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(LINK) $(libgrammar_la_OBJECTS) $(libgrammar_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrammar_la-grammar.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrammar_la-lexer.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrammar_la-rainerscript.Plo@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+libgrammar_la-grammar.lo: grammar.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrammar_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libgrammar_la-grammar.lo -MD -MP -MF $(DEPDIR)/libgrammar_la-grammar.Tpo -c -o libgrammar_la-grammar.lo `test -f 'grammar.c' || echo '$(srcdir)/'`grammar.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgrammar_la-grammar.Tpo $(DEPDIR)/libgrammar_la-grammar.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='grammar.c' object='libgrammar_la-grammar.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrammar_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libgrammar_la-grammar.lo `test -f 'grammar.c' || echo '$(srcdir)/'`grammar.c
+
+libgrammar_la-lexer.lo: lexer.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrammar_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libgrammar_la-lexer.lo -MD -MP -MF $(DEPDIR)/libgrammar_la-lexer.Tpo -c -o libgrammar_la-lexer.lo `test -f 'lexer.c' || echo '$(srcdir)/'`lexer.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgrammar_la-lexer.Tpo $(DEPDIR)/libgrammar_la-lexer.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='lexer.c' object='libgrammar_la-lexer.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrammar_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libgrammar_la-lexer.lo `test -f 'lexer.c' || echo '$(srcdir)/'`lexer.c
+
+libgrammar_la-rainerscript.lo: rainerscript.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrammar_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libgrammar_la-rainerscript.lo -MD -MP -MF $(DEPDIR)/libgrammar_la-rainerscript.Tpo -c -o libgrammar_la-rainerscript.lo `test -f 'rainerscript.c' || echo '$(srcdir)/'`rainerscript.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgrammar_la-rainerscript.Tpo $(DEPDIR)/libgrammar_la-rainerscript.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rainerscript.c' object='libgrammar_la-rainerscript.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrammar_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libgrammar_la-rainerscript.lo `test -f 'rainerscript.c' || echo '$(srcdir)/'`rainerscript.c
+
+.l.c:
+ $(AM_V_LEX)$(am__skiplex) $(SHELL) $(YLWRAP) $< $(LEX_OUTPUT_ROOT).c $@ -- $(LEXCOMPILE)
+
+.y.c:
+ $(AM_V_YACC)$(am__skipyacc) $(SHELL) $(YLWRAP) $< y.tab.c $@ y.tab.h `echo $@ | $(am__yacc_c2h)` y.output $*.output -- $(YACCCOMPILE)
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+install: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+ -rm -f grammar.c
+ -rm -f grammar.h
+ -rm -f lexer.c
+ -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -f ./$(DEPDIR)/libgrammar_la-grammar.Plo
+ -rm -f ./$(DEPDIR)/libgrammar_la-lexer.Plo
+ -rm -f ./$(DEPDIR)/libgrammar_la-rainerscript.Plo
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f ./$(DEPDIR)/libgrammar_la-grammar.Plo
+ -rm -f ./$(DEPDIR)/libgrammar_la-lexer.Plo
+ -rm -f ./$(DEPDIR)/libgrammar_la-rainerscript.Plo
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: all check install install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+ clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ cscopelist-am ctags ctags-am distclean distclean-compile \
+ distclean-generic distclean-libtool distclean-tags distdir dvi \
+ dvi-am html html-am info info-am install install-am \
+ install-data install-data-am install-dvi install-dvi-am \
+ install-exec install-exec-am install-html install-html-am \
+ install-info install-info-am install-man install-pdf \
+ install-pdf-am install-ps install-ps-am install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am
+
+.PRECIOUS: Makefile
+
+
+#testdriver_SOURCES = testdriver.c libgrammar.la
+#testdriver_CPPFLAGS = $(RSRT_CFLAGS)
+#testdriver_LDADD = libgrammar.la
+#testdriver_LDFLAGS = -lestr
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/grammar/grammar.c b/grammar/grammar.c
new file mode 100644
index 0000000..0c4f4a6
--- /dev/null
+++ b/grammar/grammar.c
@@ -0,0 +1,2342 @@
+/* A Bison parser, made by GNU Bison 3.5.1. */
+
+/* Bison implementation for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Undocumented macros, especially those whose name start with YY_,
+ are private implementation details. Do not rely on them. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "3.5.1"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 0
+
+/* Push parsers. */
+#define YYPUSH 0
+
+/* Pull parsers. */
+#define YYPULL 1
+
+
+
+
+/* First part of user prologue. */
+#line 29 "grammar.y"
+
+#define IN_GRAMMAR_Y /* tell parserif.h not to redefine things! */
+
+#include "config.h"
+#include <stdio.h>
+#include <libestr.h>
+#include "rainerscript.h"
+#include "parserif.h"
+#define YYDEBUG 1
+extern int yylineno;
+extern char *yytext;
+
+/* keep compile rule clean of errors */
+extern int yylex(void);
+extern int yyerror(const char*);
+
+#line 87 "grammar.c"
+
+# ifndef YY_CAST
+# ifdef __cplusplus
+# define YY_CAST(Type, Val) static_cast<Type> (Val)
+# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
+# else
+# define YY_CAST(Type, Val) ((Type) (Val))
+# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
+# endif
+# endif
+# ifndef YY_NULLPTR
+# if defined __cplusplus
+# if 201103L <= __cplusplus
+# define YY_NULLPTR nullptr
+# else
+# define YY_NULLPTR 0
+# endif
+# else
+# define YY_NULLPTR ((void*)0)
+# endif
+# endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Use api.header.include to #include this header
+ instead of duplicating it here. */
+#ifndef YY_YY_GRAMMAR_H_INCLUDED
+# define YY_YY_GRAMMAR_H_INCLUDED
+/* Debug traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
+#endif
+
+/* Token type. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ enum yytokentype
+ {
+ NAME = 258,
+ FUNC = 259,
+ BEGINOBJ = 260,
+ ENDOBJ = 261,
+ BEGIN_INCLUDE = 262,
+ BEGIN_ACTION = 263,
+ BEGIN_PROPERTY = 264,
+ BEGIN_CONSTANT = 265,
+ BEGIN_TPL = 266,
+ BEGIN_RULESET = 267,
+ STOP = 268,
+ SET = 269,
+ RESET = 270,
+ UNSET = 271,
+ CONTINUE = 272,
+ EXISTS = 273,
+ CALL = 274,
+ CALL_INDIRECT = 275,
+ LEGACY_ACTION = 276,
+ LEGACY_RULESET = 277,
+ PRIFILT = 278,
+ PROPFILT = 279,
+ BSD_TAG_SELECTOR = 280,
+ BSD_HOST_SELECTOR = 281,
+ RELOAD_LOOKUP_TABLE_PROCEDURE = 282,
+ IF = 283,
+ THEN = 284,
+ ELSE = 285,
+ FOREACH = 286,
+ ITERATOR_ASSIGNMENT = 287,
+ DO = 288,
+ OR = 289,
+ AND = 290,
+ NOT = 291,
+ VAR = 292,
+ STRING = 293,
+ NUMBER = 294,
+ CMP_EQ = 295,
+ CMP_NE = 296,
+ CMP_LE = 297,
+ CMP_GE = 298,
+ CMP_LT = 299,
+ CMP_GT = 300,
+ CMP_CONTAINS = 301,
+ CMP_CONTAINSI = 302,
+ CMP_STARTSWITH = 303,
+ CMP_STARTSWITHI = 304,
+ UMINUS = 305
+ };
+#endif
+/* Tokens. */
+#define NAME 258
+#define FUNC 259
+#define BEGINOBJ 260
+#define ENDOBJ 261
+#define BEGIN_INCLUDE 262
+#define BEGIN_ACTION 263
+#define BEGIN_PROPERTY 264
+#define BEGIN_CONSTANT 265
+#define BEGIN_TPL 266
+#define BEGIN_RULESET 267
+#define STOP 268
+#define SET 269
+#define RESET 270
+#define UNSET 271
+#define CONTINUE 272
+#define EXISTS 273
+#define CALL 274
+#define CALL_INDIRECT 275
+#define LEGACY_ACTION 276
+#define LEGACY_RULESET 277
+#define PRIFILT 278
+#define PROPFILT 279
+#define BSD_TAG_SELECTOR 280
+#define BSD_HOST_SELECTOR 281
+#define RELOAD_LOOKUP_TABLE_PROCEDURE 282
+#define IF 283
+#define THEN 284
+#define ELSE 285
+#define FOREACH 286
+#define ITERATOR_ASSIGNMENT 287
+#define DO 288
+#define OR 289
+#define AND 290
+#define NOT 291
+#define VAR 292
+#define STRING 293
+#define NUMBER 294
+#define CMP_EQ 295
+#define CMP_NE 296
+#define CMP_LE 297
+#define CMP_GE 298
+#define CMP_LT 299
+#define CMP_GT 300
+#define CMP_CONTAINS 301
+#define CMP_CONTAINSI 302
+#define CMP_STARTSWITH 303
+#define CMP_STARTSWITHI 304
+#define UMINUS 305
+
+/* Value type. */
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+union YYSTYPE
+{
+#line 46 "grammar.y"
+
+ char *s;
+ long long n;
+ es_str_t *estr;
+ enum cnfobjType objType;
+ struct cnfobj *obj;
+ struct cnfstmt *stmt;
+ struct nvlst *nvlst;
+ struct objlst *objlst;
+ struct cnfexpr *expr;
+ struct cnfarray *arr;
+ struct cnffunc *func;
+ struct cnffuncexists *exists;
+ struct cnffparamlst *fparams;
+ struct cnfitr *itr;
+
+#line 256 "grammar.c"
+
+};
+typedef union YYSTYPE YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+
+extern YYSTYPE yylval;
+
+int yyparse (void);
+
+#endif /* !YY_YY_GRAMMAR_H_INCLUDED */
+
+
+
+#ifdef short
+# undef short
+#endif
+
+/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
+ <limits.h> and (if available) <stdint.h> are included
+ so that the code can choose integer types of a good width. */
+
+#ifndef __PTRDIFF_MAX__
+# include <limits.h> /* INFRINGES ON USER NAME SPACE */
+# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
+# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_STDINT_H
+# endif
+#endif
+
+/* Narrow types that promote to a signed type and that can represent a
+ signed or unsigned integer of at least N bits. In tables they can
+ save space and decrease cache pressure. Promoting to a signed type
+ helps avoid bugs in integer arithmetic. */
+
+#ifdef __INT_LEAST8_MAX__
+typedef __INT_LEAST8_TYPE__ yytype_int8;
+#elif defined YY_STDINT_H
+typedef int_least8_t yytype_int8;
+#else
+typedef signed char yytype_int8;
+#endif
+
+#ifdef __INT_LEAST16_MAX__
+typedef __INT_LEAST16_TYPE__ yytype_int16;
+#elif defined YY_STDINT_H
+typedef int_least16_t yytype_int16;
+#else
+typedef short yytype_int16;
+#endif
+
+#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
+typedef __UINT_LEAST8_TYPE__ yytype_uint8;
+#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
+ && UINT_LEAST8_MAX <= INT_MAX)
+typedef uint_least8_t yytype_uint8;
+#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
+typedef unsigned char yytype_uint8;
+#else
+typedef short yytype_uint8;
+#endif
+
+#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
+typedef __UINT_LEAST16_TYPE__ yytype_uint16;
+#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
+ && UINT_LEAST16_MAX <= INT_MAX)
+typedef uint_least16_t yytype_uint16;
+#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
+typedef unsigned short yytype_uint16;
+#else
+typedef int yytype_uint16;
+#endif
+
+#ifndef YYPTRDIFF_T
+# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
+# define YYPTRDIFF_T __PTRDIFF_TYPE__
+# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
+# elif defined PTRDIFF_MAX
+# ifndef ptrdiff_t
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# endif
+# define YYPTRDIFF_T ptrdiff_t
+# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
+# else
+# define YYPTRDIFF_T long
+# define YYPTRDIFF_MAXIMUM LONG_MAX
+# endif
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM \
+ YY_CAST (YYPTRDIFF_T, \
+ (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
+ ? YYPTRDIFF_MAXIMUM \
+ : YY_CAST (YYSIZE_T, -1)))
+
+#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
+
+/* Stored state numbers (used for stacks). */
+typedef yytype_uint8 yy_state_t;
+
+/* State numbers in computations. */
+typedef int yy_state_fast_t;
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(Msgid) Msgid
+# endif
+#endif
+
+#ifndef YY_ATTRIBUTE_PURE
+# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
+# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
+# else
+# define YY_ATTRIBUTE_PURE
+# endif
+#endif
+
+#ifndef YY_ATTRIBUTE_UNUSED
+# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
+# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+# else
+# define YY_ATTRIBUTE_UNUSED
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(E) ((void) (E))
+#else
+# define YYUSE(E) /* empty */
+#endif
+
+#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#endif
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
+#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
+# define YY_IGNORE_USELESS_CAST_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
+# define YY_IGNORE_USELESS_CAST_END \
+ _Pragma ("GCC diagnostic pop")
+#endif
+#ifndef YY_IGNORE_USELESS_CAST_BEGIN
+# define YY_IGNORE_USELESS_CAST_BEGIN
+# define YY_IGNORE_USELESS_CAST_END
+#endif
+
+
+#define YY_ASSERT(E) ((void) (0 && (E)))
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's 'empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined EXIT_SUCCESS \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined EXIT_SUCCESS
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined EXIT_SUCCESS
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yy_state_t yyss_alloc;
+ YYSTYPE yyvs_alloc;
+};
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+# define YYCOPY_NEEDED 1
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
+ do \
+ { \
+ YYPTRDIFF_T yynewbytes; \
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
+ Stack = &yyptr->Stack_alloc; \
+ yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / YYSIZEOF (*yyptr); \
+ } \
+ while (0)
+
+#endif
+
+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
+/* Copy COUNT objects from SRC to DST. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(Dst, Src, Count) \
+ __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
+# else
+# define YYCOPY(Dst, Src, Count) \
+ do \
+ { \
+ YYPTRDIFF_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (Dst)[yyi] = (Src)[yyi]; \
+ } \
+ while (0)
+# endif
+# endif
+#endif /* !YYCOPY_NEEDED */
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 2
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 507
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 66
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 20
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 81
+/* YYNSTATES -- Number of states. */
+#define YYNSTATES 165
+
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 305
+
+
+/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex, with out-of-bounds checking. */
+#define YYTRANSLATE(YYX) \
+ (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex. */
+static const yytype_int8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 55, 52, 2,
+ 61, 62, 53, 50, 63, 51, 2, 54, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 60,
+ 2, 59, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 64, 2, 65, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 57, 2, 58, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 56
+};
+
+#if YYDEBUG
+ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
+static const yytype_uint8 yyrline[] =
+{
+ 0, 135, 135, 136, 137, 138, 139, 140, 141, 142,
+ 143, 144, 148, 152, 156, 157, 158, 159, 160, 161,
+ 162, 163, 164, 165, 166, 167, 168, 169, 173, 177,
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
+ 190, 191, 193, 194, 195, 196, 197, 200, 201, 202,
+ 203, 204, 205, 206, 207, 208, 209, 210, 211, 212,
+ 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
+ 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
+ 233, 234
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || 0
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "NAME", "FUNC", "BEGINOBJ", "ENDOBJ",
+ "BEGIN_INCLUDE", "BEGIN_ACTION", "BEGIN_PROPERTY", "BEGIN_CONSTANT",
+ "BEGIN_TPL", "BEGIN_RULESET", "STOP", "SET", "RESET", "UNSET",
+ "CONTINUE", "EXISTS", "CALL", "CALL_INDIRECT", "LEGACY_ACTION",
+ "LEGACY_RULESET", "PRIFILT", "PROPFILT", "BSD_TAG_SELECTOR",
+ "BSD_HOST_SELECTOR", "RELOAD_LOOKUP_TABLE_PROCEDURE", "IF", "THEN",
+ "ELSE", "FOREACH", "ITERATOR_ASSIGNMENT", "DO", "OR", "AND", "NOT",
+ "VAR", "STRING", "NUMBER", "CMP_EQ", "CMP_NE", "CMP_LE", "CMP_GE",
+ "CMP_LT", "CMP_GT", "CMP_CONTAINS", "CMP_CONTAINSI", "CMP_STARTSWITH",
+ "CMP_STARTSWITHI", "'+'", "'-'", "'&'", "'*'", "'/'", "'%'", "UMINUS",
+ "'{'", "'}'", "'='", "';'", "'('", "')'", "','", "'['", "']'", "$accept",
+ "conf", "include", "obj", "propconst", "property", "constant", "nvlst",
+ "nv", "value", "script", "stmt", "block", "actlst", "s_act", "expr",
+ "fparams", "array", "iterator_decl", "arrayelt", YY_NULLPTR
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[NUM] -- (External) token number corresponding to the
+ (internal) symbol number NUM (which must be that of a token). */
+static const yytype_int16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
+ 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
+ 43, 45, 38, 42, 47, 37, 305, 123, 125, 61,
+ 59, 40, 41, 44, 91, 93
+};
+# endif
+
+#define YYPACT_NINF (-48)
+
+#define yypact_value_is_default(Yyn) \
+ ((Yyn) == YYPACT_NINF)
+
+#define YYTABLE_NINF (-20)
+
+#define yytable_value_is_error(Yyn) \
+ 0
+
+ /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+static const yytype_int16 yypact[] =
+{
+ -48, 273, -48, 7, -48, -48, -48, -48, -48, -26,
+ -17, 9, -48, 30, 103, -48, -48, 234, 234, -48,
+ -48, -27, 103, -12, -48, -48, -48, 2, -48, 12,
+ 13, 35, 36, 37, 1, 6, -5, -48, 0, 5,
+ 103, -48, -48, -48, 103, 103, 19, 338, -48, -48,
+ 460, -48, -48, -48, 103, 365, 26, 34, 4, 31,
+ -48, -48, -48, -48, 32, 38, 103, 103, -48, 95,
+ 54, -48, -48, 292, -48, -1, 103, 103, 103, 103,
+ 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
+ 103, 103, 103, 103, -48, 155, -48, 268, 39, 234,
+ 60, 234, -48, -29, -48, 180, 387, 409, -48, 40,
+ 43, -48, 55, -48, 452, 452, -24, -24, -24, -24,
+ -24, -24, -24, -24, -24, -24, -3, -3, -3, -48,
+ -48, -48, -48, -48, 103, -48, 64, 103, -48, -48,
+ -48, -48, -2, -48, 209, -48, -48, -48, -48, -48,
+ -48, 234, 315, -48, -48, -48, -48, -48, -48, -48,
+ -48, 41, 42, -48, -48
+};
+
+ /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
+ Performed when YYTABLE does not specify something else to do. Zero
+ means the default is an error. */
+static const yytype_int8 yydefact[] =
+{
+ 2, 0, 1, 37, 19, 19, 19, 19, 44, 0,
+ 0, 0, 47, 0, 0, 43, 5, 0, 0, 6,
+ 7, 0, 0, 0, 36, 3, 4, 26, 40, 0,
+ 0, 0, 0, 0, 0, 0, 0, 45, 0, 0,
+ 0, 74, 73, 72, 0, 0, 0, 0, 75, 37,
+ 0, 38, 33, 34, 0, 0, 0, 0, 0, 0,
+ 9, 20, 8, 42, 10, 0, 0, 0, 32, 0,
+ 0, 50, 68, 0, 80, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 46, 0, 24, 76, 0, 0,
+ 0, 0, 41, 0, 14, 0, 0, 0, 70, 0,
+ 0, 67, 0, 78, 49, 48, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 62, 63, 61, 64,
+ 65, 66, 39, 25, 0, 35, 27, 0, 29, 22,
+ 21, 23, 0, 13, 0, 31, 30, 71, 69, 81,
+ 77, 0, 0, 19, 19, 11, 15, 16, 12, 28,
+ 79, 0, 0, 17, 18
+};
+
+ /* YYPGOTO[NTERM-NUM]. */
+static const yytype_int8 yypgoto[] =
+{
+ -48, -48, -48, -48, -48, -48, -48, -4, -48, -48,
+ -9, 3, -13, -48, 45, -8, -47, -6, -48, -48
+};
+
+ /* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int16 yydefgoto[] =
+{
+ -1, 1, 24, 25, 142, 156, 157, 29, 61, 140,
+ 95, 51, 52, 27, 28, 97, 98, 48, 57, 75
+};
+
+ /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule whose
+ number is the opposite. If YYTABLE_NINF, syntax error. */
+static const yytype_int16 yytable[] =
+{
+ 30, 31, 32, 33, 26, 53, 47, 153, 154, 139,
+ -19, 34, 5, -19, 55, 59, 59, 8, 60, 62,
+ 35, 12, 109, 13, 14, 15, 88, 89, 90, 91,
+ 92, 93, 71, 37, 54, 46, 72, 73, 59, 59,
+ 59, 63, 64, 65, 59, 59, 36, 163, 164, 56,
+ 91, 92, 93, 96, 58, 68, 155, 74, 106, 107,
+ 66, 69, 112, 100, 113, 67, 70, 101, 114, 115,
+ 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
+ 126, 127, 128, 129, 130, 131, 136, 150, 138, 104,
+ 103, 110, 137, 149, 151, 105, 144, 141, 133, 38,
+ 0, 135, 147, 102, 0, 148, 0, 38, 96, 0,
+ 0, 0, 0, 39, 0, 0, 0, 0, 0, 0,
+ 0, 39, 0, 0, 0, 0, 0, 0, 0, 152,
+ 0, 40, 41, 42, 43, 0, 0, 0, 159, 40,
+ 41, 42, 43, 0, 0, 0, 44, 133, 0, 161,
+ 162, 0, 0, 0, 44, 0, 45, 108, 0, 46,
+ 49, 0, 4, 5, 45, 0, 0, 46, 8, 9,
+ 10, 11, 12, 0, 13, 14, 15, 0, 17, 18,
+ 0, 0, 21, 22, 0, 49, 23, 4, 5, 0,
+ 0, 0, 0, 8, 9, 10, 11, 12, 0, 13,
+ 14, 15, 0, 17, 18, 0, 0, 21, 22, 0,
+ 0, 23, 0, 132, 49, 0, 4, 5, 0, 0,
+ 0, 0, 8, 9, 10, 11, 12, 0, 13, 14,
+ 15, 0, 17, 18, 0, 0, 21, 22, 143, 49,
+ 23, 4, 5, 0, 0, 0, 0, 8, 9, 10,
+ 11, 12, 0, 13, 14, 15, 0, 17, 18, 0,
+ 0, 21, 22, 0, 0, 23, 0, 158, 0, 0,
+ 0, 0, 0, 2, 0, 0, 0, 0, 3, 0,
+ 4, 5, 0, 0, 6, 7, 8, 9, 10, 11,
+ 12, 50, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 76, 77, 23, 0, 0, 0, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 93, 0, 0, 76, 77, 0, 0,
+ 0, 134, 78, 79, 80, 81, 82, 83, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 93, 0, 76,
+ 77, 0, 0, 0, 111, 78, 79, 80, 81, 82,
+ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
+ 93, 0, 76, 77, 0, 0, 0, 160, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 93, 99, 0, 0, 0, 94, 76,
+ 77, 0, 0, 0, 0, 78, 79, 80, 81, 82,
+ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
+ 93, 76, 77, 0, 0, 0, 0, 78, 79, 80,
+ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 93, 76, 77, 0, 0, 145, 0, 78,
+ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
+ 89, 90, 91, 92, 93, 49, 0, 4, 5, 146,
+ 0, 0, 0, 8, 9, 10, 11, 12, 0, 13,
+ 14, 15, 0, 17, 18, 0, 0, 21, 22, 0,
+ 0, 23, 78, 79, 80, 81, 82, 83, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 93
+};
+
+static const yytype_int16 yycheck[] =
+{
+ 4, 5, 6, 7, 1, 18, 14, 9, 10, 38,
+ 3, 37, 8, 6, 22, 3, 3, 13, 6, 6,
+ 37, 17, 69, 19, 20, 21, 50, 51, 52, 53,
+ 54, 55, 40, 3, 61, 64, 44, 45, 3, 3,
+ 3, 6, 6, 6, 3, 3, 37, 6, 6, 61,
+ 53, 54, 55, 50, 52, 60, 58, 38, 66, 67,
+ 59, 61, 63, 37, 65, 59, 61, 33, 76, 77,
+ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
+ 88, 89, 90, 91, 92, 93, 99, 134, 101, 57,
+ 59, 37, 32, 38, 30, 57, 105, 103, 95, 4,
+ -1, 62, 62, 58, -1, 62, -1, 4, 105, -1,
+ -1, -1, -1, 18, -1, -1, -1, -1, -1, -1,
+ -1, 18, -1, -1, -1, -1, -1, -1, -1, 137,
+ -1, 36, 37, 38, 39, -1, -1, -1, 151, 36,
+ 37, 38, 39, -1, -1, -1, 51, 144, -1, 153,
+ 154, -1, -1, -1, 51, -1, 61, 62, -1, 64,
+ 5, -1, 7, 8, 61, -1, -1, 64, 13, 14,
+ 15, 16, 17, -1, 19, 20, 21, -1, 23, 24,
+ -1, -1, 27, 28, -1, 5, 31, 7, 8, -1,
+ -1, -1, -1, 13, 14, 15, 16, 17, -1, 19,
+ 20, 21, -1, 23, 24, -1, -1, 27, 28, -1,
+ -1, 31, -1, 58, 5, -1, 7, 8, -1, -1,
+ -1, -1, 13, 14, 15, 16, 17, -1, 19, 20,
+ 21, -1, 23, 24, -1, -1, 27, 28, 58, 5,
+ 31, 7, 8, -1, -1, -1, -1, 13, 14, 15,
+ 16, 17, -1, 19, 20, 21, -1, 23, 24, -1,
+ -1, 27, 28, -1, -1, 31, -1, 58, -1, -1,
+ -1, -1, -1, 0, -1, -1, -1, -1, 5, -1,
+ 7, 8, -1, -1, 11, 12, 13, 14, 15, 16,
+ 17, 57, 19, 20, 21, 22, 23, 24, 25, 26,
+ 27, 28, 34, 35, 31, -1, -1, -1, 40, 41,
+ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
+ 52, 53, 54, 55, -1, -1, 34, 35, -1, -1,
+ -1, 63, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, -1, 34,
+ 35, -1, -1, -1, 62, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, -1, 34, 35, -1, -1, -1, 62, 40, 41,
+ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
+ 52, 53, 54, 55, 29, -1, -1, -1, 60, 34,
+ 35, -1, -1, -1, -1, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 34, 35, -1, -1, -1, -1, 40, 41, 42,
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
+ 53, 54, 55, 34, 35, -1, -1, 60, -1, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
+ 51, 52, 53, 54, 55, 5, -1, 7, 8, 60,
+ -1, -1, -1, 13, 14, 15, 16, 17, -1, 19,
+ 20, 21, -1, 23, 24, -1, -1, 27, 28, -1,
+ -1, 31, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55
+};
+
+ /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_int8 yystos[] =
+{
+ 0, 67, 0, 5, 7, 8, 11, 12, 13, 14,
+ 15, 16, 17, 19, 20, 21, 22, 23, 24, 25,
+ 26, 27, 28, 31, 68, 69, 77, 79, 80, 73,
+ 73, 73, 73, 73, 37, 37, 37, 3, 4, 18,
+ 36, 37, 38, 39, 51, 61, 64, 81, 83, 5,
+ 57, 77, 78, 78, 61, 81, 61, 84, 52, 3,
+ 6, 74, 6, 6, 6, 6, 59, 59, 60, 61,
+ 61, 81, 81, 81, 38, 85, 34, 35, 40, 41,
+ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
+ 52, 53, 54, 55, 60, 76, 77, 81, 82, 29,
+ 37, 33, 80, 59, 57, 57, 81, 81, 62, 82,
+ 37, 62, 63, 65, 81, 81, 81, 81, 81, 81,
+ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
+ 81, 81, 58, 77, 63, 62, 78, 32, 78, 38,
+ 75, 83, 70, 58, 76, 60, 60, 62, 62, 38,
+ 82, 30, 81, 9, 10, 58, 71, 72, 58, 78,
+ 62, 73, 73, 6, 6
+};
+
+ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_int8 yyr1[] =
+{
+ 0, 66, 67, 67, 67, 67, 67, 67, 68, 69,
+ 69, 69, 69, 69, 70, 70, 70, 71, 72, 73,
+ 73, 74, 75, 75, 76, 76, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 78, 78,
+ 79, 79, 80, 80, 80, 80, 80, 80, 81, 81,
+ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
+ 81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
+ 81, 81, 81, 81, 81, 81, 82, 82, 83, 84,
+ 85, 85
+};
+
+ /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
+static const yytype_int8 yyr2[] =
+{
+ 0, 2, 0, 2, 2, 2, 2, 2, 3, 3,
+ 3, 6, 6, 5, 0, 2, 2, 3, 3, 0,
+ 2, 3, 1, 1, 1, 2, 1, 4, 6, 4,
+ 5, 5, 3, 2, 2, 4, 1, 1, 1, 3,
+ 1, 3, 3, 1, 1, 2, 3, 1, 3, 3,
+ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 2, 4,
+ 3, 4, 1, 1, 1, 1, 1, 3, 3, 5,
+ 1, 3
+};
+
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+ do \
+ if (yychar == YYEMPTY) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (yylen); \
+ yystate = *yyssp; \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+ while (0)
+
+/* Error token number */
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
+
+/* This macro is provided for backward compatibility. */
+#ifndef YY_LOCATION_PRINT
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+#endif
+
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
+
+/*-----------------------------------.
+| Print this symbol's value on YYO. |
+`-----------------------------------*/
+
+static void
+yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
+{
+ FILE *yyoutput = yyo;
+ YYUSE (yyoutput);
+ if (!yyvaluep)
+ return;
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
+# endif
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ YYUSE (yytype);
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
+
+
+/*---------------------------.
+| Print this symbol on YYO. |
+`---------------------------*/
+
+static void
+yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
+{
+ YYFPRINTF (yyo, "%s %s (",
+ yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
+
+ yy_symbol_value_print (yyo, yytype, yyvaluep);
+ YYFPRINTF (yyo, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+static void
+yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; yybottom <= yytop; yybottom++)
+ {
+ int yybot = *yybottom;
+ YYFPRINTF (stderr, " %d", yybot);
+ }
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+static void
+yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule)
+{
+ int yylno = yyrline[yyrule];
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr,
+ yystos[+yyssp[yyi + 1 - yynrhs]],
+ &yyvsp[(yyi + 1) - (yynrhs)]
+ );
+ YYFPRINTF (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyssp, yyvsp, Rule); \
+} while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
+# else
+/* Return the length of YYSTR. */
+static YYPTRDIFF_T
+yystrlen (const char *yystr)
+{
+ YYPTRDIFF_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYPTRDIFF_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYPTRDIFF_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ else
+ goto append;
+
+ append:
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (yyres)
+ return yystpcpy (yyres, yystr) - yyres;
+ else
+ return yystrlen (yystr);
+}
+# endif
+
+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
+ about the unexpected token YYTOKEN for the state stack whose top is
+ YYSSP.
+
+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
+ not large enough to hold the message. In that case, also set
+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the
+ required number of bytes is too large to store. */
+static int
+yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
+ yy_state_t *yyssp, int yytoken)
+{
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ /* Internationalized format string. */
+ const char *yyformat = YY_NULLPTR;
+ /* Arguments of yyformat: reported tokens (one for the "unexpected",
+ one per "expected"). */
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ /* Actual size of YYARG. */
+ int yycount = 0;
+ /* Cumulated lengths of YYARG. */
+ YYPTRDIFF_T yysize = 0;
+
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yychar) is if
+ this state is a consistent state with a default action. Thus,
+ detecting the absence of a lookahead is sufficient to determine
+ that there is no unexpected or expected token to report. In that
+ case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is a
+ consistent state with a default action. There might have been a
+ previous inconsistent state, consistent state with a non-default
+ action, or user semantic action that manipulated yychar.
+ - Of course, the expected token list depends on states to have
+ correct lookahead information, and it depends on the parser not
+ to perform extra reductions after fetching a lookahead from the
+ scanner and before detecting a syntax error. Thus, state merging
+ (from LALR or IELR) and default reductions corrupt the expected
+ token list. However, the list is correct for canonical LR with
+ one exception: it will still contain any token that will not be
+ accepted due to an error action in a later state.
+ */
+ if (yytoken != YYEMPTY)
+ {
+ int yyn = yypact[+*yyssp];
+ YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
+ yysize = yysize0;
+ yyarg[yycount++] = yytname[yytoken];
+ if (!yypact_value_is_default (yyn))
+ {
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. In other words, skip the first -YYN actions for
+ this state because they are default actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yyx;
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
+ && !yytable_value_is_error (yytable[yyx + yyn]))
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ {
+ YYPTRDIFF_T yysize1
+ = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
+ if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
+ yysize = yysize1;
+ else
+ return 2;
+ }
+ }
+ }
+ }
+
+ switch (yycount)
+ {
+# define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ default: /* Avoid compiler warnings. */
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+# undef YYCASE_
+ }
+
+ {
+ /* Don't count the "%s"s in the final size, but reserve room for
+ the terminator. */
+ YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1;
+ if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
+ yysize = yysize1;
+ else
+ return 2;
+ }
+
+ if (*yymsg_alloc < yysize)
+ {
+ *yymsg_alloc = 2 * yysize;
+ if (! (yysize <= *yymsg_alloc
+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
+ return 1;
+ }
+
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ {
+ char *yyp = *yymsg;
+ int yyi = 0;
+ while ((*yyp = *yyformat) != '\0')
+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyformat += 2;
+ }
+ else
+ {
+ ++yyp;
+ ++yyformat;
+ }
+ }
+ return 0;
+}
+#endif /* YYERROR_VERBOSE */
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
+{
+ YYUSE (yyvaluep);
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ YYUSE (yytype);
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
+
+
+
+
+/* The lookahead symbol. */
+int yychar;
+
+/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;
+/* Number of syntax errors so far. */
+int yynerrs;
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+int
+yyparse (void)
+{
+ yy_state_fast_t yystate;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+
+ /* The stacks and their tools:
+ 'yyss': related to states.
+ 'yyvs': related to semantic values.
+
+ Refer to the stacks through separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yy_state_t yyssa[YYINITDEPTH];
+ yy_state_t *yyss;
+ yy_state_t *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs;
+ YYSTYPE *yyvsp;
+
+ YYPTRDIFF_T yystacksize;
+
+ int yyn;
+ int yyresult;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken = 0;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ yyssp = yyss = yyssa;
+ yyvsp = yyvs = yyvsa;
+ yystacksize = YYINITDEPTH;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+ goto yysetstate;
+
+
+/*------------------------------------------------------------.
+| yynewstate -- push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+
+/*--------------------------------------------------------------------.
+| yysetstate -- set current state (the top of the stack) to yystate. |
+`--------------------------------------------------------------------*/
+yysetstate:
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+ YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
+ YY_IGNORE_USELESS_CAST_BEGIN
+ *yyssp = YY_CAST (yy_state_t, yystate);
+ YY_IGNORE_USELESS_CAST_END
+
+ if (yyss + yystacksize - 1 <= yyssp)
+#if !defined yyoverflow && !defined YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+#else
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYPTRDIFF_T yysize = yyssp - yyss + 1;
+
+# if defined yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ yy_state_t *yyss1 = yyss;
+ YYSTYPE *yyvs1 = yyvs;
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * YYSIZEOF (*yyssp),
+ &yyvs1, yysize * YYSIZEOF (*yyvsp),
+ &yystacksize);
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+# else /* defined YYSTACK_RELOCATE */
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yy_state_t *yyss1 = yyss;
+ union yyalloc *yyptr =
+ YY_CAST (union yyalloc *,
+ YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+ YY_IGNORE_USELESS_CAST_BEGIN
+ YYDPRINTF ((stderr, "Stack size increased to %ld\n",
+ YY_CAST (long, yystacksize)));
+ YY_IGNORE_USELESS_CAST_END
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
+
+ if (yystate == YYFINAL)
+ YYACCEPT;
+
+ goto yybackup;
+
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+ /* Do appropriate processing given the current state. Read a
+ lookahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to lookahead token. */
+ yyn = yypact[yystate];
+ if (yypact_value_is_default (yyn))
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = yylex ();
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yytable_value_is_error (yyn))
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the lookahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+ yystate = yyn;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+
+ /* Discard the shifted token. */
+ yychar = YYEMPTY;
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 3:
+#line 136 "grammar.y"
+ { cnfDoObj((yyvsp[0].obj)); }
+#line 1615 "grammar.c"
+ break;
+
+ case 4:
+#line 137 "grammar.y"
+ { cnfDoScript((yyvsp[0].stmt)); }
+#line 1621 "grammar.c"
+ break;
+
+ case 5:
+#line 138 "grammar.y"
+ { cnfDoCfsysline((yyvsp[0].s)); }
+#line 1627 "grammar.c"
+ break;
+
+ case 6:
+#line 139 "grammar.y"
+ { cnfDoBSDTag((yyvsp[0].s)); }
+#line 1633 "grammar.c"
+ break;
+
+ case 7:
+#line 140 "grammar.y"
+ { cnfDoBSDHost((yyvsp[0].s)); }
+#line 1639 "grammar.c"
+ break;
+
+ case 8:
+#line 141 "grammar.y"
+ { includeProcessCnf((yyvsp[-1].nvlst)); }
+#line 1645 "grammar.c"
+ break;
+
+ case 9:
+#line 142 "grammar.y"
+ { (yyval.obj) = cnfobjNew((yyvsp[-2].objType), (yyvsp[-1].nvlst)); }
+#line 1651 "grammar.c"
+ break;
+
+ case 10:
+#line 143 "grammar.y"
+ { (yyval.obj) = cnfobjNew(CNFOBJ_TPL, (yyvsp[-1].nvlst)); }
+#line 1657 "grammar.c"
+ break;
+
+ case 11:
+#line 145 "grammar.y"
+ { (yyval.obj) = cnfobjNew(CNFOBJ_TPL, (yyvsp[-4].nvlst));
+ (yyval.obj)->subobjs = (yyvsp[-1].objlst);
+ }
+#line 1665 "grammar.c"
+ break;
+
+ case 12:
+#line 149 "grammar.y"
+ { (yyval.obj) = cnfobjNew(CNFOBJ_RULESET, (yyvsp[-4].nvlst));
+ (yyval.obj)->script = (yyvsp[-1].stmt);
+ }
+#line 1673 "grammar.c"
+ break;
+
+ case 13:
+#line 153 "grammar.y"
+ { (yyval.obj) = cnfobjNew(CNFOBJ_RULESET, (yyvsp[-3].nvlst));
+ (yyval.obj)->script = NULL;
+ }
+#line 1681 "grammar.c"
+ break;
+
+ case 14:
+#line 156 "grammar.y"
+ { (yyval.objlst) = NULL; }
+#line 1687 "grammar.c"
+ break;
+
+ case 15:
+#line 157 "grammar.y"
+ { (yyval.objlst) = objlstAdd((yyvsp[-1].objlst), (yyvsp[0].obj)); }
+#line 1693 "grammar.c"
+ break;
+
+ case 16:
+#line 158 "grammar.y"
+ { (yyval.objlst) = objlstAdd((yyvsp[-1].objlst), (yyvsp[0].obj)); }
+#line 1699 "grammar.c"
+ break;
+
+ case 17:
+#line 159 "grammar.y"
+ { (yyval.obj) = cnfobjNew(CNFOBJ_PROPERTY, (yyvsp[-1].nvlst)); }
+#line 1705 "grammar.c"
+ break;
+
+ case 18:
+#line 160 "grammar.y"
+ { (yyval.obj) = cnfobjNew(CNFOBJ_CONSTANT, (yyvsp[-1].nvlst)); }
+#line 1711 "grammar.c"
+ break;
+
+ case 19:
+#line 161 "grammar.y"
+ { (yyval.nvlst) = NULL; }
+#line 1717 "grammar.c"
+ break;
+
+ case 20:
+#line 162 "grammar.y"
+ { (yyvsp[0].nvlst)->next = (yyvsp[-1].nvlst); (yyval.nvlst) = (yyvsp[0].nvlst); }
+#line 1723 "grammar.c"
+ break;
+
+ case 21:
+#line 163 "grammar.y"
+ { (yyval.nvlst) = nvlstSetName((yyvsp[0].nvlst), (yyvsp[-2].estr)); }
+#line 1729 "grammar.c"
+ break;
+
+ case 22:
+#line 164 "grammar.y"
+ { (yyval.nvlst) = nvlstNewStr((yyvsp[0].estr)); }
+#line 1735 "grammar.c"
+ break;
+
+ case 23:
+#line 165 "grammar.y"
+ { (yyval.nvlst) = nvlstNewArray((yyvsp[0].arr)); }
+#line 1741 "grammar.c"
+ break;
+
+ case 24:
+#line 166 "grammar.y"
+ { (yyval.stmt) = (yyvsp[0].stmt); }
+#line 1747 "grammar.c"
+ break;
+
+ case 25:
+#line 167 "grammar.y"
+ { (yyval.stmt) = scriptAddStmt((yyvsp[-1].stmt), (yyvsp[0].stmt)); }
+#line 1753 "grammar.c"
+ break;
+
+ case 26:
+#line 168 "grammar.y"
+ { (yyval.stmt) = (yyvsp[0].stmt); }
+#line 1759 "grammar.c"
+ break;
+
+ case 27:
+#line 169 "grammar.y"
+ { (yyval.stmt) = cnfstmtNew(S_IF);
+ (yyval.stmt)->d.s_if.expr = (yyvsp[-2].expr);
+ (yyval.stmt)->d.s_if.t_then = (yyvsp[0].stmt);
+ (yyval.stmt)->d.s_if.t_else = NULL; }
+#line 1768 "grammar.c"
+ break;
+
+ case 28:
+#line 173 "grammar.y"
+ { (yyval.stmt) = cnfstmtNew(S_IF);
+ (yyval.stmt)->d.s_if.expr = (yyvsp[-4].expr);
+ (yyval.stmt)->d.s_if.t_then = (yyvsp[-2].stmt);
+ (yyval.stmt)->d.s_if.t_else = (yyvsp[0].stmt); }
+#line 1777 "grammar.c"
+ break;
+
+ case 29:
+#line 177 "grammar.y"
+ { (yyval.stmt) = cnfstmtNew(S_FOREACH);
+ (yyval.stmt)->d.s_foreach.iter = (yyvsp[-2].itr);
+ (yyval.stmt)->d.s_foreach.body = (yyvsp[0].stmt);}
+#line 1785 "grammar.c"
+ break;
+
+ case 30:
+#line 180 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewSet((yyvsp[-3].s), (yyvsp[-1].expr), 1); }
+#line 1791 "grammar.c"
+ break;
+
+ case 31:
+#line 181 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewSet((yyvsp[-3].s), (yyvsp[-1].expr), 0); }
+#line 1797 "grammar.c"
+ break;
+
+ case 32:
+#line 182 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewUnset((yyvsp[-1].s)); }
+#line 1803 "grammar.c"
+ break;
+
+ case 33:
+#line 183 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewPRIFILT((yyvsp[-1].s), (yyvsp[0].stmt)); }
+#line 1809 "grammar.c"
+ break;
+
+ case 34:
+#line 184 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewPROPFILT((yyvsp[-1].s), (yyvsp[0].stmt)); }
+#line 1815 "grammar.c"
+ break;
+
+ case 35:
+#line 185 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewReloadLookupTable((yyvsp[-1].fparams));}
+#line 1821 "grammar.c"
+ break;
+
+ case 36:
+#line 186 "grammar.y"
+ { (yyval.stmt) = NULL; }
+#line 1827 "grammar.c"
+ break;
+
+ case 37:
+#line 187 "grammar.y"
+ { (yyval.stmt) = NULL; parser_errmsg("declarative object '%s' not permitted in action block [stmt]", yytext);}
+#line 1833 "grammar.c"
+ break;
+
+ case 38:
+#line 188 "grammar.y"
+ { (yyval.stmt) = (yyvsp[0].stmt); }
+#line 1839 "grammar.c"
+ break;
+
+ case 39:
+#line 189 "grammar.y"
+ { (yyval.stmt) = (yyvsp[-1].stmt); }
+#line 1845 "grammar.c"
+ break;
+
+ case 40:
+#line 190 "grammar.y"
+ { (yyval.stmt) = (yyvsp[0].stmt); }
+#line 1851 "grammar.c"
+ break;
+
+ case 41:
+#line 191 "grammar.y"
+ { (yyval.stmt) = scriptAddStmt((yyvsp[-2].stmt), (yyvsp[0].stmt)); }
+#line 1857 "grammar.c"
+ break;
+
+ case 42:
+#line 193 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewAct((yyvsp[-1].nvlst)); }
+#line 1863 "grammar.c"
+ break;
+
+ case 43:
+#line 194 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewLegaAct((yyvsp[0].s)); }
+#line 1869 "grammar.c"
+ break;
+
+ case 44:
+#line 195 "grammar.y"
+ { (yyval.stmt) = cnfstmtNew(S_STOP); }
+#line 1875 "grammar.c"
+ break;
+
+ case 45:
+#line 196 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewCall((yyvsp[0].estr)); }
+#line 1881 "grammar.c"
+ break;
+
+ case 46:
+#line 197 "grammar.y"
+ { (yyval.stmt) = cnfstmtNew(S_CALL_INDIRECT);
+ (yyval.stmt)->d.s_call_ind.expr = (yyvsp[-1].expr);
+ }
+#line 1889 "grammar.c"
+ break;
+
+ case 47:
+#line 200 "grammar.y"
+ { (yyval.stmt) = cnfstmtNewContinue(); }
+#line 1895 "grammar.c"
+ break;
+
+ case 48:
+#line 201 "grammar.y"
+ { (yyval.expr) = cnfexprNew(AND, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1901 "grammar.c"
+ break;
+
+ case 49:
+#line 202 "grammar.y"
+ { (yyval.expr) = cnfexprNew(OR, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1907 "grammar.c"
+ break;
+
+ case 50:
+#line 203 "grammar.y"
+ { (yyval.expr) = cnfexprNew(NOT, NULL, (yyvsp[0].expr)); }
+#line 1913 "grammar.c"
+ break;
+
+ case 51:
+#line 204 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_EQ, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1919 "grammar.c"
+ break;
+
+ case 52:
+#line 205 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_NE, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1925 "grammar.c"
+ break;
+
+ case 53:
+#line 206 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_LE, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1931 "grammar.c"
+ break;
+
+ case 54:
+#line 207 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_GE, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1937 "grammar.c"
+ break;
+
+ case 55:
+#line 208 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_LT, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1943 "grammar.c"
+ break;
+
+ case 56:
+#line 209 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_GT, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1949 "grammar.c"
+ break;
+
+ case 57:
+#line 210 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_CONTAINS, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1955 "grammar.c"
+ break;
+
+ case 58:
+#line 211 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_CONTAINSI, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1961 "grammar.c"
+ break;
+
+ case 59:
+#line 212 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_STARTSWITH, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1967 "grammar.c"
+ break;
+
+ case 60:
+#line 213 "grammar.y"
+ { (yyval.expr) = cnfexprNew(CMP_STARTSWITHI, (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1973 "grammar.c"
+ break;
+
+ case 61:
+#line 214 "grammar.y"
+ { (yyval.expr) = cnfexprNew('&', (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1979 "grammar.c"
+ break;
+
+ case 62:
+#line 215 "grammar.y"
+ { (yyval.expr) = cnfexprNew('+', (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1985 "grammar.c"
+ break;
+
+ case 63:
+#line 216 "grammar.y"
+ { (yyval.expr) = cnfexprNew('-', (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1991 "grammar.c"
+ break;
+
+ case 64:
+#line 217 "grammar.y"
+ { (yyval.expr) = cnfexprNew('*', (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 1997 "grammar.c"
+ break;
+
+ case 65:
+#line 218 "grammar.y"
+ { (yyval.expr) = cnfexprNew('/', (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 2003 "grammar.c"
+ break;
+
+ case 66:
+#line 219 "grammar.y"
+ { (yyval.expr) = cnfexprNew('%', (yyvsp[-2].expr), (yyvsp[0].expr)); }
+#line 2009 "grammar.c"
+ break;
+
+ case 67:
+#line 220 "grammar.y"
+ { (yyval.expr) = (yyvsp[-1].expr); }
+#line 2015 "grammar.c"
+ break;
+
+ case 68:
+#line 221 "grammar.y"
+ { (yyval.expr) = cnfexprNew('M', NULL, (yyvsp[0].expr)); }
+#line 2021 "grammar.c"
+ break;
+
+ case 69:
+#line 222 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) cnffuncexistsNew((yyvsp[-1].s)); }
+#line 2027 "grammar.c"
+ break;
+
+ case 70:
+#line 223 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) cnffuncNew((yyvsp[-2].estr), NULL); }
+#line 2033 "grammar.c"
+ break;
+
+ case 71:
+#line 224 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) cnffuncNew((yyvsp[-3].estr), (yyvsp[-1].fparams)); }
+#line 2039 "grammar.c"
+ break;
+
+ case 72:
+#line 225 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) cnfnumvalNew((yyvsp[0].n)); }
+#line 2045 "grammar.c"
+ break;
+
+ case 73:
+#line 226 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) cnfstringvalNew((yyvsp[0].estr)); }
+#line 2051 "grammar.c"
+ break;
+
+ case 74:
+#line 227 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) cnfvarNew((yyvsp[0].s)); }
+#line 2057 "grammar.c"
+ break;
+
+ case 75:
+#line 228 "grammar.y"
+ { (yyval.expr) = (struct cnfexpr*) (yyvsp[0].arr); }
+#line 2063 "grammar.c"
+ break;
+
+ case 76:
+#line 229 "grammar.y"
+ { (yyval.fparams) = cnffparamlstNew((yyvsp[0].expr), NULL); }
+#line 2069 "grammar.c"
+ break;
+
+ case 77:
+#line 230 "grammar.y"
+ { (yyval.fparams) = cnffparamlstNew((yyvsp[-2].expr), (yyvsp[0].fparams)); }
+#line 2075 "grammar.c"
+ break;
+
+ case 78:
+#line 231 "grammar.y"
+ { (yyval.arr) = (yyvsp[-1].arr); }
+#line 2081 "grammar.c"
+ break;
+
+ case 79:
+#line 232 "grammar.y"
+ { (yyval.itr) = cnfNewIterator((yyvsp[-3].s), (yyvsp[-1].expr)); }
+#line 2087 "grammar.c"
+ break;
+
+ case 80:
+#line 233 "grammar.y"
+ { (yyval.arr) = cnfarrayNew((yyvsp[0].estr)); }
+#line 2093 "grammar.c"
+ break;
+
+ case 81:
+#line 234 "grammar.y"
+ { (yyval.arr) = cnfarrayAdd((yyvsp[-2].arr), (yyvsp[0].estr)); }
+#line 2099 "grammar.c"
+ break;
+
+
+#line 2103 "grammar.c"
+
+ default: break;
+ }
+ /* User semantic actions sometimes alter yychar, and that requires
+ that yytoken be updated with the new translation. We take the
+ approach of translating immediately before every use of yytoken.
+ One alternative is translating here after every semantic action,
+ but that translation would be missed if the semantic action invokes
+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
+ incorrect destructor might then be invoked immediately. In the
+ case of YYERROR or YYBACKUP, subsequent parser actions might lead
+ to an incorrect destructor call or verbose syntax error message
+ before the lookahead is translated. */
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+ /* Now 'shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+ {
+ const int yylhs = yyr1[yyn] - YYNTOKENS;
+ const int yyi = yypgoto[yylhs] + *yyssp;
+ yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
+ ? yytable[yyi]
+ : yydefgoto[yylhs]);
+ }
+
+ goto yynewstate;
+
+
+/*--------------------------------------.
+| yyerrlab -- here on detecting error. |
+`--------------------------------------*/
+yyerrlab:
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (YY_("syntax error"));
+#else
+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
+ yyssp, yytoken)
+ {
+ char const *yymsgp = YY_("syntax error");
+ int yysyntax_error_status;
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ if (yysyntax_error_status == 0)
+ yymsgp = yymsg;
+ else if (yysyntax_error_status == 1)
+ {
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
+ if (!yymsg)
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ yysyntax_error_status = 2;
+ }
+ else
+ {
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ yymsgp = yymsg;
+ }
+ }
+ yyerror (yymsgp);
+ if (yysyntax_error_status == 2)
+ goto yyexhaustedlab;
+ }
+# undef YYSYNTAX_ERROR
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+ /* Pacify compilers when the user code never invokes YYERROR and the
+ label yyerrorlab therefore never appears in user code. */
+ if (0)
+ YYERROR;
+
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (!yypact_value_is_default (yyn))
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+
+#if !defined yyoverflow || YYERROR_VERBOSE
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+
+/*-----------------------------------------------------.
+| yyreturn -- parsing is finished, return the result. |
+`-----------------------------------------------------*/
+yyreturn:
+ if (yychar != YYEMPTY)
+ {
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = YYTRANSLATE (yychar);
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval);
+ }
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[+*yyssp], yyvsp);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ return yyresult;
+}
+#line 236 "grammar.y"
+
+/*
+int yyerror(char *s)
+{
+ printf("parse failure on or before line %d: %s\n", yylineno, s);
+ return 0;
+}
+*/
diff --git a/grammar/grammar.h b/grammar/grammar.h
new file mode 100644
index 0000000..18eaeff
--- /dev/null
+++ b/grammar/grammar.h
@@ -0,0 +1,186 @@
+/* A Bison parser, made by GNU Bison 3.5.1. */
+
+/* Bison interface for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ 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/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* Undocumented macros, especially those whose name start with YY_,
+ are private implementation details. Do not rely on them. */
+
+#ifndef YY_YY_GRAMMAR_H_INCLUDED
+# define YY_YY_GRAMMAR_H_INCLUDED
+/* Debug traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
+#endif
+
+/* Token type. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ enum yytokentype
+ {
+ NAME = 258,
+ FUNC = 259,
+ BEGINOBJ = 260,
+ ENDOBJ = 261,
+ BEGIN_INCLUDE = 262,
+ BEGIN_ACTION = 263,
+ BEGIN_PROPERTY = 264,
+ BEGIN_CONSTANT = 265,
+ BEGIN_TPL = 266,
+ BEGIN_RULESET = 267,
+ STOP = 268,
+ SET = 269,
+ RESET = 270,
+ UNSET = 271,
+ CONTINUE = 272,
+ EXISTS = 273,
+ CALL = 274,
+ CALL_INDIRECT = 275,
+ LEGACY_ACTION = 276,
+ LEGACY_RULESET = 277,
+ PRIFILT = 278,
+ PROPFILT = 279,
+ BSD_TAG_SELECTOR = 280,
+ BSD_HOST_SELECTOR = 281,
+ RELOAD_LOOKUP_TABLE_PROCEDURE = 282,
+ IF = 283,
+ THEN = 284,
+ ELSE = 285,
+ FOREACH = 286,
+ ITERATOR_ASSIGNMENT = 287,
+ DO = 288,
+ OR = 289,
+ AND = 290,
+ NOT = 291,
+ VAR = 292,
+ STRING = 293,
+ NUMBER = 294,
+ CMP_EQ = 295,
+ CMP_NE = 296,
+ CMP_LE = 297,
+ CMP_GE = 298,
+ CMP_LT = 299,
+ CMP_GT = 300,
+ CMP_CONTAINS = 301,
+ CMP_CONTAINSI = 302,
+ CMP_STARTSWITH = 303,
+ CMP_STARTSWITHI = 304,
+ UMINUS = 305
+ };
+#endif
+/* Tokens. */
+#define NAME 258
+#define FUNC 259
+#define BEGINOBJ 260
+#define ENDOBJ 261
+#define BEGIN_INCLUDE 262
+#define BEGIN_ACTION 263
+#define BEGIN_PROPERTY 264
+#define BEGIN_CONSTANT 265
+#define BEGIN_TPL 266
+#define BEGIN_RULESET 267
+#define STOP 268
+#define SET 269
+#define RESET 270
+#define UNSET 271
+#define CONTINUE 272
+#define EXISTS 273
+#define CALL 274
+#define CALL_INDIRECT 275
+#define LEGACY_ACTION 276
+#define LEGACY_RULESET 277
+#define PRIFILT 278
+#define PROPFILT 279
+#define BSD_TAG_SELECTOR 280
+#define BSD_HOST_SELECTOR 281
+#define RELOAD_LOOKUP_TABLE_PROCEDURE 282
+#define IF 283
+#define THEN 284
+#define ELSE 285
+#define FOREACH 286
+#define ITERATOR_ASSIGNMENT 287
+#define DO 288
+#define OR 289
+#define AND 290
+#define NOT 291
+#define VAR 292
+#define STRING 293
+#define NUMBER 294
+#define CMP_EQ 295
+#define CMP_NE 296
+#define CMP_LE 297
+#define CMP_GE 298
+#define CMP_LT 299
+#define CMP_GT 300
+#define CMP_CONTAINS 301
+#define CMP_CONTAINSI 302
+#define CMP_STARTSWITH 303
+#define CMP_STARTSWITHI 304
+#define UMINUS 305
+
+/* Value type. */
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+union YYSTYPE
+{
+#line 46 "grammar.y"
+
+ char *s;
+ long long n;
+ es_str_t *estr;
+ enum cnfobjType objType;
+ struct cnfobj *obj;
+ struct cnfstmt *stmt;
+ struct nvlst *nvlst;
+ struct objlst *objlst;
+ struct cnfexpr *expr;
+ struct cnfarray *arr;
+ struct cnffunc *func;
+ struct cnffuncexists *exists;
+ struct cnffparamlst *fparams;
+ struct cnfitr *itr;
+
+#line 174 "grammar.h"
+
+};
+typedef union YYSTYPE YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+
+extern YYSTYPE yylval;
+
+int yyparse (void);
+
+#endif /* !YY_YY_GRAMMAR_H_INCLUDED */
diff --git a/grammar/grammar.y b/grammar/grammar.y
new file mode 100644
index 0000000..d6e3eed
--- /dev/null
+++ b/grammar/grammar.y
@@ -0,0 +1,243 @@
+/* Bison file for rsyslog config format v2 (RainerScript).
+ * Please note: this file introduces the new config format, but maintains
+ * backward compatibility. In order to do so, the grammar is not 100% clean,
+ * but IMHO still sufficiently easy both to understand for programmers
+ * maitaining the code as well as users writing the config file. Users are,
+ * of course, encouraged to use new constructs only. But it needs to be noted
+ * that some of the legacy constructs (specifically the in-front-of-action
+ * PRI filter) are very hard to beat in ease of use, at least for simpler
+ * cases.
+ *
+ * Copyright 2011-2020 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * -or-
+ * see COPYING.ASL20 in the source distribution
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+%{
+#define IN_GRAMMAR_Y /* tell parserif.h not to redefine things! */
+
+#include "config.h"
+#include <stdio.h>
+#include <libestr.h>
+#include "rainerscript.h"
+#include "parserif.h"
+#define YYDEBUG 1
+extern int yylineno;
+extern char *yytext;
+
+/* keep compile rule clean of errors */
+extern int yylex(void);
+extern int yyerror(const char*);
+%}
+
+%union {
+ char *s;
+ long long n;
+ es_str_t *estr;
+ enum cnfobjType objType;
+ struct cnfobj *obj;
+ struct cnfstmt *stmt;
+ struct nvlst *nvlst;
+ struct objlst *objlst;
+ struct cnfexpr *expr;
+ struct cnfarray *arr;
+ struct cnffunc *func;
+ struct cnffuncexists *exists;
+ struct cnffparamlst *fparams;
+ struct cnfitr *itr;
+}
+
+%token <estr> NAME
+%token <estr> FUNC
+%token <objType> BEGINOBJ
+%token ENDOBJ
+%token BEGIN_INCLUDE
+%token BEGIN_ACTION
+%token BEGIN_PROPERTY
+%token BEGIN_CONSTANT
+%token BEGIN_TPL
+%token BEGIN_RULESET
+%token STOP
+%token SET
+%token RESET
+%token UNSET
+%token CONTINUE
+%token EXISTS
+%token <cnfstmt> CALL
+%token <cnfstmt> CALL_INDIRECT
+%token <s> LEGACY_ACTION
+%token <s> LEGACY_RULESET
+%token <s> PRIFILT
+%token <s> PROPFILT
+%token <s> BSD_TAG_SELECTOR
+%token <s> BSD_HOST_SELECTOR
+%token <s> RELOAD_LOOKUP_TABLE_PROCEDURE
+%token IF
+%token THEN
+%token ELSE
+%token FOREACH
+%token ITERATOR_ASSIGNMENT
+%token DO
+%token OR
+%token AND
+%token NOT
+%token <s> VAR
+%token <estr> STRING
+%token <n> NUMBER
+%token CMP_EQ
+%token CMP_NE
+%token CMP_LE
+%token CMP_GE
+%token CMP_LT
+%token CMP_GT
+%token CMP_CONTAINS
+%token CMP_CONTAINSI
+%token CMP_STARTSWITH
+%token CMP_STARTSWITHI
+
+%type <nvlst> nv nvlst value
+%type <obj> obj property constant
+%type <objlst> propconst
+%type <expr> expr
+%type <stmt> stmt s_act actlst block script
+%type <itr> iterator_decl
+%type <fparams> fparams
+%type <arr> array arrayelt
+
+%left AND OR
+%left CMP_EQ CMP_NE CMP_LE CMP_GE CMP_LT CMP_GT CMP_CONTAINS CMP_CONTAINSI CMP_STARTSWITH CMP_STARTSWITHI
+%left '+' '-' '&'
+%left '*' '/' '%'
+%nonassoc UMINUS NOT
+
+%expect 1 /* dangling else */
+/* If more erors show up, Use "bison -v grammar.y" if more conflicts arise and
+ * check grammar.output for were exactly these conflicts exits.
+ */
+%%
+/* note: we use left recursion below, because that saves stack space AND
+ * offers the right sequence so that we can submit the top-layer objects
+ * one by one.
+ */
+conf: /* empty (to end recursion) */
+ | conf obj { cnfDoObj($2); }
+ | conf stmt { cnfDoScript($2); }
+ | conf LEGACY_RULESET { cnfDoCfsysline($2); }
+ | conf BSD_TAG_SELECTOR { cnfDoBSDTag($2); }
+ | conf BSD_HOST_SELECTOR { cnfDoBSDHost($2); }
+include: BEGIN_INCLUDE nvlst ENDOBJ { includeProcessCnf($2); }
+obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2); }
+ | BEGIN_TPL nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_TPL, $2); }
+ | BEGIN_TPL nvlst ENDOBJ '{' propconst '}'
+ { $$ = cnfobjNew(CNFOBJ_TPL, $2);
+ $$->subobjs = $5;
+ }
+ | BEGIN_RULESET nvlst ENDOBJ '{' script '}'
+ { $$ = cnfobjNew(CNFOBJ_RULESET, $2);
+ $$->script = $5;
+ }
+ | BEGIN_RULESET nvlst ENDOBJ '{' '}'
+ { $$ = cnfobjNew(CNFOBJ_RULESET, $2);
+ $$->script = NULL;
+ }
+propconst: { $$ = NULL; }
+ | propconst property { $$ = objlstAdd($1, $2); }
+ | propconst constant { $$ = objlstAdd($1, $2); }
+property: BEGIN_PROPERTY nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_PROPERTY, $2); }
+constant: BEGIN_CONSTANT nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_CONSTANT, $2); }
+nvlst: { $$ = NULL; }
+ | nvlst nv { $2->next = $1; $$ = $2; }
+nv: NAME '=' value { $$ = nvlstSetName($3, $1); }
+value: STRING { $$ = nvlstNewStr($1); }
+ | array { $$ = nvlstNewArray($1); }
+script: stmt { $$ = $1; }
+ | script stmt { $$ = scriptAddStmt($1, $2); }
+stmt: actlst { $$ = $1; }
+ | IF expr THEN block { $$ = cnfstmtNew(S_IF);
+ $$->d.s_if.expr = $2;
+ $$->d.s_if.t_then = $4;
+ $$->d.s_if.t_else = NULL; }
+ | IF expr THEN block ELSE block { $$ = cnfstmtNew(S_IF);
+ $$->d.s_if.expr = $2;
+ $$->d.s_if.t_then = $4;
+ $$->d.s_if.t_else = $6; }
+ | FOREACH iterator_decl DO block { $$ = cnfstmtNew(S_FOREACH);
+ $$->d.s_foreach.iter = $2;
+ $$->d.s_foreach.body = $4;}
+ | RESET VAR '=' expr ';' { $$ = cnfstmtNewSet($2, $4, 1); }
+ | SET VAR '=' expr ';' { $$ = cnfstmtNewSet($2, $4, 0); }
+ | UNSET VAR ';' { $$ = cnfstmtNewUnset($2); }
+ | PRIFILT block { $$ = cnfstmtNewPRIFILT($1, $2); }
+ | PROPFILT block { $$ = cnfstmtNewPROPFILT($1, $2); }
+ | RELOAD_LOOKUP_TABLE_PROCEDURE '(' fparams ')' { $$ = cnfstmtNewReloadLookupTable($3);}
+ | include { $$ = NULL; }
+ | BEGINOBJ { $$ = NULL; parser_errmsg("declarative object '%s' not permitted in action block [stmt]", yytext);}
+block: stmt { $$ = $1; }
+ | '{' script '}' { $$ = $2; }
+actlst: s_act { $$ = $1; }
+ | actlst '&' s_act { $$ = scriptAddStmt($1, $3); }
+/* s_act are actions and action-like statements */
+s_act: BEGIN_ACTION nvlst ENDOBJ { $$ = cnfstmtNewAct($2); }
+ | LEGACY_ACTION { $$ = cnfstmtNewLegaAct($1); }
+ | STOP { $$ = cnfstmtNew(S_STOP); }
+ | CALL NAME { $$ = cnfstmtNewCall($2); }
+ | CALL_INDIRECT expr ';' { $$ = cnfstmtNew(S_CALL_INDIRECT);
+ $$->d.s_call_ind.expr = $2;
+ }
+ | CONTINUE { $$ = cnfstmtNewContinue(); }
+expr: expr AND expr { $$ = cnfexprNew(AND, $1, $3); }
+ | expr OR expr { $$ = cnfexprNew(OR, $1, $3); }
+ | NOT expr { $$ = cnfexprNew(NOT, NULL, $2); }
+ | expr CMP_EQ expr { $$ = cnfexprNew(CMP_EQ, $1, $3); }
+ | expr CMP_NE expr { $$ = cnfexprNew(CMP_NE, $1, $3); }
+ | expr CMP_LE expr { $$ = cnfexprNew(CMP_LE, $1, $3); }
+ | expr CMP_GE expr { $$ = cnfexprNew(CMP_GE, $1, $3); }
+ | expr CMP_LT expr { $$ = cnfexprNew(CMP_LT, $1, $3); }
+ | expr CMP_GT expr { $$ = cnfexprNew(CMP_GT, $1, $3); }
+ | expr CMP_CONTAINS expr { $$ = cnfexprNew(CMP_CONTAINS, $1, $3); }
+ | expr CMP_CONTAINSI expr { $$ = cnfexprNew(CMP_CONTAINSI, $1, $3); }
+ | expr CMP_STARTSWITH expr { $$ = cnfexprNew(CMP_STARTSWITH, $1, $3); }
+ | expr CMP_STARTSWITHI expr { $$ = cnfexprNew(CMP_STARTSWITHI, $1, $3); }
+ | expr '&' expr { $$ = cnfexprNew('&', $1, $3); }
+ | expr '+' expr { $$ = cnfexprNew('+', $1, $3); }
+ | expr '-' expr { $$ = cnfexprNew('-', $1, $3); }
+ | expr '*' expr { $$ = cnfexprNew('*', $1, $3); }
+ | expr '/' expr { $$ = cnfexprNew('/', $1, $3); }
+ | expr '%' expr { $$ = cnfexprNew('%', $1, $3); }
+ | '(' expr ')' { $$ = $2; }
+ | '-' expr %prec UMINUS { $$ = cnfexprNew('M', NULL, $2); }
+ | EXISTS '(' VAR ')' { $$ = (struct cnfexpr*) cnffuncexistsNew($3); }
+ | FUNC '(' ')' { $$ = (struct cnfexpr*) cnffuncNew($1, NULL); }
+ | FUNC '(' fparams ')' { $$ = (struct cnfexpr*) cnffuncNew($1, $3); }
+ | NUMBER { $$ = (struct cnfexpr*) cnfnumvalNew($1); }
+ | STRING { $$ = (struct cnfexpr*) cnfstringvalNew($1); }
+ | VAR { $$ = (struct cnfexpr*) cnfvarNew($1); }
+ | array { $$ = (struct cnfexpr*) $1; }
+fparams: expr { $$ = cnffparamlstNew($1, NULL); }
+ | expr ',' fparams { $$ = cnffparamlstNew($1, $3); }
+array: '[' arrayelt ']' { $$ = $2; }
+iterator_decl: '(' VAR ITERATOR_ASSIGNMENT expr ')' { $$ = cnfNewIterator($2, $4); }
+arrayelt: STRING { $$ = cnfarrayNew($1); }
+ | arrayelt ',' STRING { $$ = cnfarrayAdd($1, $3); }
+
+%%
+/*
+int yyerror(char *s)
+{
+ printf("parse failure on or before line %d: %s\n", yylineno, s);
+ return 0;
+}
+*/
diff --git a/grammar/lexer.c b/grammar/lexer.c
new file mode 100644
index 0000000..6667bfc
--- /dev/null
+++ b/grammar/lexer.c
@@ -0,0 +1,4150 @@
+#ifndef __clang_analyzer__ /* this is not really our code */
+#include "config.h"
+
+#line 5 "lexer.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 6
+#define YY_FLEX_SUBMINOR_VERSION 4
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* begin standard C++ headers. */
+
+/* TODO: this is always defined, so inline it */
+#define yyconst const
+
+#if defined(__GNUC__) && __GNUC__ >= 3
+#define yynoreturn __attribute__((__noreturn__))
+#else
+#define yynoreturn
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
+ */
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+extern int yyleng;
+
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
+ * access to the local variable yy_act. Since yyless() is a macro, it would break
+ * existing scanners that call yyless() from OUTSIDE yylex.
+ * One obvious solution it to make yy_act a global. I tried that, and saw
+ * a 5% performance hit in a non-yylineno scanner, because yy_act is
+ * normally declared as a register variable-- so it is not worth it.
+ */
+ #define YY_LESS_LINENO(n) \
+ do { \
+ int yyl;\
+ for ( yyl = n; yyl < yyleng; ++yyl )\
+ if ( yytext[yyl] == '\n' )\
+ --yylineno;\
+ }while(0)
+ #define YY_LINENO_REWIND_TO(dst) \
+ do {\
+ const char *p;\
+ for ( p = yy_cp-1; p >= (dst); --p)\
+ if ( *p == '\n' )\
+ --yylineno;\
+ }while(0)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ int yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = NULL;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart ( FILE *input_file );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
+void yy_delete_buffer ( YY_BUFFER_STATE b );
+void yy_flush_buffer ( YY_BUFFER_STATE b );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer );
+void yypop_buffer_state ( void );
+
+static void yyensure_buffer_stack ( void );
+static void yy_load_buffer_state ( void );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file );
+#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len );
+
+void *yyalloc ( yy_size_t );
+void *yyrealloc ( void *, yy_size_t );
+void yyfree ( void * );
+
+#define yy_new_buffer yy_create_buffer
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ yyensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define yywrap() (/*CONSTCOND*/1)
+#define YY_SKIP_YYWRAP
+typedef flex_uint8_t YY_CHAR;
+
+FILE *yyin = NULL, *yyout = NULL;
+
+typedef int yy_state_type;
+
+extern int yylineno;
+int yylineno = 1;
+
+extern char *yytext;
+#ifdef yytext_ptr
+#undef yytext_ptr
+#endif
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state ( void );
+static yy_state_type yy_try_NUL_trans ( yy_state_type current_state );
+static int yy_get_next_buffer ( void );
+static void yynoreturn yy_fatal_error ( const char* msg );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+#define YY_NUM_RULES 121
+#define YY_END_OF_BUFFER 122
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static const flex_int16_t yy_accept[667] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 9, 9, 0, 0, 122, 120, 119, 119,
+ 120, 120, 120, 56, 91, 120, 120, 120, 120, 96,
+ 120, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 57, 58, 90, 119, 91,
+ 120, 120, 120, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 112, 111,
+ 111, 112, 112, 97, 99, 112, 102, 98, 100, 101,
+ 112, 109, 109, 109, 71, 71, 70, 69, 68, 54,
+ 53, 53, 54, 10, 9, 9, 10, 10, 4, 8,
+
+ 7, 52, 49, 49, 52, 52, 44, 22, 24, 52,
+ 11, 28, 20, 23, 19, 25, 21, 43, 43, 14,
+ 34, 18, 35, 51, 51, 51, 51, 51, 51, 51,
+ 51, 51, 51, 26, 27, 52, 0, 0, 118, 0,
+ 0, 95, 95, 95, 93, 105, 96, 0, 96, 96,
+ 96, 96, 96, 96, 96, 1, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 0, 0, 0, 0, 0, 0, 0, 0, 95, 0,
+ 0, 0, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 1, 96, 96, 96, 96, 96, 96, 96,
+
+ 96, 96, 96, 96, 96, 96, 96, 0, 103, 0,
+ 0, 110, 106, 98, 0, 0, 104, 109, 109, 108,
+ 72, 68, 55, 9, 0, 6, 0, 0, 5, 0,
+ 32, 0, 47, 0, 0, 44, 44, 44, 44, 0,
+ 45, 0, 107, 41, 0, 43, 30, 33, 29, 31,
+ 51, 51, 51, 13, 51, 37, 51, 15, 51, 51,
+ 0, 0, 46, 0, 114, 0, 113, 0, 0, 116,
+ 0, 95, 95, 92, 92, 93, 94, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 63, 96, 96, 96,
+
+ 96, 89, 0, 117, 95, 0, 0, 89, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 63, 96, 96,
+ 96, 96, 0, 0, 0, 0, 0, 0, 48, 0,
+ 0, 0, 0, 0, 42, 16, 51, 51, 17, 51,
+ 51, 0, 0, 0, 115, 95, 92, 92, 94, 96,
+ 61, 96, 96, 96, 60, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 59,
+ 96, 96, 96, 0, 0, 0, 96, 61, 96, 96,
+ 60, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+
+ 96, 96, 96, 96, 96, 59, 96, 96, 96, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 51, 51, 51, 12, 0, 0, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 64, 96, 96, 96, 65, 0,
+ 0, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 64, 96, 96, 96, 65,
+ 0, 0, 0, 0, 51, 51, 51, 96, 96, 96,
+ 96, 96, 96, 96, 96, 0, 81, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 0, 0,
+
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 51, 50, 51, 0,
+ 87, 96, 96, 96, 96, 2, 0, 76, 96, 96,
+ 96, 0, 82, 0, 75, 96, 96, 96, 96, 96,
+ 96, 96, 0, 88, 0, 96, 96, 2, 96, 96,
+ 96, 96, 96, 96, 96, 51, 51, 96, 96, 66,
+ 96, 0, 86, 96, 96, 96, 96, 96, 96, 0,
+ 78, 96, 96, 88, 96, 66, 96, 96, 96, 96,
+ 96, 36, 51, 96, 0, 80, 96, 96, 96, 96,
+ 96, 0, 79, 96, 0, 77, 0, 74, 96, 96,
+
+ 51, 51, 96, 0, 84, 96, 96, 96, 96, 96,
+ 96, 96, 38, 39, 96, 96, 0, 73, 96, 96,
+ 96, 96, 51, 96, 96, 96, 96, 96, 96, 40,
+ 62, 0, 83, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 0,
+ 85, 96, 96, 96, 96, 96, 96, 96, 3, 96,
+ 96, 96, 96, 96, 67, 0
+ } ;
+
+static const YY_CHAR yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 21,
+ 21, 21, 21, 21, 21, 22, 22, 23, 24, 25,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
+ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
+ 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
+
+ 66, 67, 68, 69, 70, 39, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79, 80, 81, 51, 82, 83,
+ 84, 85, 86, 59, 87, 88, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static const YY_CHAR yy_meta[89] =
+ { 0,
+ 1, 2, 3, 4, 5, 6, 1, 7, 1, 1,
+ 8, 1, 1, 9, 10, 11, 12, 13, 14, 15,
+ 15, 16, 17, 18, 1, 19, 1, 20, 21, 22,
+ 23, 24, 24, 24, 22, 25, 25, 25, 25, 25,
+ 25, 25, 26, 25, 25, 25, 26, 25, 26, 25,
+ 27, 25, 28, 25, 25, 21, 8, 21, 1, 29,
+ 30, 22, 23, 24, 24, 24, 22, 25, 25, 25,
+ 25, 25, 25, 26, 25, 25, 25, 26, 25, 26,
+ 25, 25, 28, 25, 25, 1, 1, 1
+ } ;
+
+static const flex_int16_t yy_base[773] =
+ { 0,
+ 0, 88, 176, 0, 262, 263, 265, 268, 260, 265,
+ 287, 0, 374, 389, 405, 0, 1379, 4863, 4863, 4863,
+ 0, 1366, 0, 4863, 4863, 1351, 260, 0, 1346, 0,
+ 0, 462, 465, 444, 458, 456, 460, 462, 458, 473,
+ 476, 484, 473, 477, 470, 4863, 4863, 0, 547, 363,
+ 1339, 570, 538, 586, 599, 646, 611, 607, 609, 647,
+ 650, 645, 648, 667, 696, 669, 713, 711, 4863, 4863,
+ 4863, 506, 1342, 4863, 4863, 1325, 4863, 0, 4863, 4863,
+ 337, 1170, 1161, 1125, 0, 4863, 4863, 4863, 499, 4863,
+ 4863, 4863, 0, 4863, 564, 588, 531, 530, 4863, 4863,
+
+ 4863, 4863, 4863, 4863, 1091, 626, 748, 4863, 4863, 624,
+ 4863, 4863, 4863, 4863, 4863, 4863, 1069, 591, 716, 4863,
+ 257, 1048, 1031, 471, 0, 481, 549, 569, 562, 565,
+ 649, 679, 635, 4863, 4863, 342, 778, 1019, 4863, 806,
+ 787, 0, 793, 635, 0, 4863, 0, 994, 683, 720,
+ 729, 731, 847, 849, 853, 0, 866, 856, 664, 683,
+ 854, 855, 869, 864, 865, 858, 864, 867, 868, 866,
+ 944, 899, 0, 1002, 931, 0, 937, 919, 967, 981,
+ 500, 981, 1015, 944, 991, 1028, 990, 991, 1015, 939,
+ 989, 1012, 876, 1027, 1019, 1035, 1033, 1031, 1032, 1052,
+
+ 1073, 1044, 941, 1053, 1077, 1081, 1086, 641, 4863, 368,
+ 799, 4863, 4863, 0, 500, 376, 4863, 796, 790, 4863,
+ 0, 1116, 0, 1137, 648, 4863, 1122, 741, 4863, 1126,
+ 4863, 1098, 4863, 744, 1128, 1165, 1171, 0, 1179, 893,
+ 4863, 1142, 4863, 622, 0, 1138, 4863, 4863, 4863, 4863,
+ 0, 901, 973, 0, 1133, 0, 1051, 0, 1142, 1140,
+ 512, 1157, 4863, 1165, 4863, 784, 4863, 1240, 1210, 1229,
+ 781, 1327, 775, 0, 0, 0, 0, 1152, 1079, 1159,
+ 700, 1160, 1164, 1171, 1084, 1282, 1293, 1292, 1286, 1289,
+ 1306, 1295, 1296, 1298, 1309, 1310, 0, 1301, 1302, 1314,
+
+ 1315, 0, 1216, 4863, 1348, 629, 995, 1369, 1382, 1393,
+ 1313, 1364, 1360, 1378, 1392, 1316, 1375, 1318, 1387, 1377,
+ 1390, 1407, 1396, 1422, 1402, 1439, 1441, 1394, 1440, 1442,
+ 1454, 1455, 1472, 1479, 1195, 0, 1335, 0, 4863, 1401,
+ 1470, 0, 1481, 0, 0, 0, 1396, 1438, 0, 1450,
+ 1460, 1488, 0, 736, 4863, 712, 0, 0, 0, 1460,
+ 640, 1457, 1472, 1467, 0, 1489, 1492, 1474, 1476, 1480,
+ 627, 1490, 1498, 1499, 1491, 1505, 1511, 1494, 1496, 0,
+ 1504, 844, 1498, 1544, 1548, 1554, 1516, 1522, 1531, 1543,
+ 1525, 1538, 1555, 1542, 1546, 1548, 1549, 1536, 1565, 1578,
+
+ 1560, 1594, 1592, 1575, 1593, 1564, 1584, 1598, 1599, 1637,
+ 1625, 1631, 0, 1641, 0, 1647, 0, 1653, 0, 1655,
+ 0, 1619, 1610, 1620, 0, 1657, 0, 1637, 1625, 1654,
+ 1644, 1639, 1653, 1648, 1658, 1694, 1648, 1653, 1667, 1656,
+ 1661, 1661, 1660, 1675, 0, 1675, 1680, 1668, 0, 760,
+ 912, 1672, 1691, 1684, 1690, 1673, 1696, 1745, 1719, 1718,
+ 1724, 1726, 1729, 1725, 1741, 1709, 1742, 1747, 1748, 1738,
+ 957, 1167, 1773, 0, 1717, 1732, 1737, 1822, 1756, 1762,
+ 1757, 1782, 1778, 1825, 1784, 1829, 4863, 565, 1771, 1851,
+ 1854, 1790, 1803, 1791, 492, 1793, 1794, 1802, 1598, 978,
+
+ 1857, 1805, 1831, 1827, 1880, 1844, 1834, 1885, 1905, 1852,
+ 1859, 1864, 1870, 1873, 1878, 1861, 1806, 0, 872, 1935,
+ 4863, 1853, 1871, 1894, 1876, 0, 1959, 4863, 1962, 1892,
+ 1909, 1966, 4863, 1977, 4863, 1916, 1920, 1006, 1918, 1980,
+ 1933, 1939, 1123, 4863, 1928, 1947, 1957, 1935, 1991, 1963,
+ 1967, 1956, 2009, 1975, 1983, 1952, 1968, 1976, 2040, 0,
+ 1972, 2054, 4863, 1992, 1980, 1995, 1999, 2068, 2001, 2071,
+ 4863, 2075, 2082, 2042, 2086, 2019, 2021, 2054, 2098, 2101,
+ 2104, 464, 2016, 2050, 2117, 4863, 2128, 2051, 2075, 2077,
+ 2074, 2132, 4863, 2073, 2147, 4863, 2150, 4863, 2122, 2092,
+
+ 2085, 2088, 2103, 2163, 4863, 2106, 2177, 436, 2126, 2128,
+ 2130, 2143, 0, 344, 2129, 2138, 2183, 4863, 2126, 2141,
+ 2133, 2150, 2158, 2149, 2204, 2151, 2163, 2158, 2179, 0,
+ 0, 2223, 4863, 2180, 2169, 322, 2178, 2174, 2190, 2181,
+ 2198, 2188, 2194, 2210, 2203, 2276, 2188, 2210, 2212, 2279,
+ 4863, 2203, 2214, 2217, 2229, 2229, 2256, 2232, 0, 2260,
+ 2218, 2258, 263, 2259, 4863, 4863, 2336, 2366, 2396, 2426,
+ 2456, 2486, 2495, 2523, 2553, 2574, 2589, 2616, 2636, 2656,
+ 2684, 2708, 2728, 2757, 2787, 2805, 2834, 2864, 2894, 2913,
+ 2942, 2972, 3002, 3028, 3057, 3073, 3102, 3132, 3162, 3192,
+
+ 3222, 3252, 3273, 3288, 3315, 3335, 3352, 3374, 3398, 3426,
+ 3453, 3477, 3498, 3527, 3552, 3579, 3597, 3626, 3649, 3679,
+ 3709, 3728, 3757, 3782, 3810, 3835, 3863, 3893, 3918, 3942,
+ 3967, 3996, 4021, 4035, 4045, 4074, 4099, 4129, 4159, 4189,
+ 4219, 4249, 4279, 4309, 4339, 4360, 4385, 4410, 4434, 4455,
+ 4484, 4514, 4530, 4540, 4559, 4573, 4583, 4593, 4603, 4618,
+ 4642, 4672, 4702, 4732, 4748, 4758, 4768, 4778, 4788, 4798,
+ 4808, 4832
+ } ;
+
+static const flex_int16_t yy_def[773] =
+ { 0,
+ 666, 666, 666, 3, 667, 667, 668, 668, 669, 669,
+ 666, 11, 670, 670, 666, 15, 666, 666, 666, 666,
+ 671, 672, 673, 666, 666, 666, 674, 674, 675, 676,
+ 677, 676, 676, 676, 676, 676, 676, 676, 676, 676,
+ 676, 676, 676, 676, 676, 666, 666, 674, 678, 679,
+ 680, 681, 682, 683, 683, 683, 56, 56, 56, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 666, 666,
+ 666, 684, 685, 666, 666, 666, 666, 686, 666, 666,
+ 687, 688, 688, 666, 689, 666, 666, 666, 666, 666,
+ 666, 666, 690, 666, 666, 666, 691, 692, 666, 666,
+
+ 666, 666, 666, 666, 666, 693, 694, 666, 666, 695,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 696, 696, 696, 696, 696, 696, 696,
+ 696, 696, 696, 666, 666, 697, 698, 699, 666, 666,
+ 666, 700, 700, 701, 702, 666, 703, 704, 703, 703,
+ 703, 703, 703, 703, 703, 703, 703, 703, 703, 703,
+ 703, 703, 703, 703, 703, 703, 703, 703, 703, 703,
+ 705, 706, 707, 708, 706, 709, 666, 707, 710, 708,
+ 708, 711, 712, 703, 713, 713, 186, 186, 186, 186,
+ 186, 186, 186, 186, 186, 186, 186, 186, 186, 186,
+
+ 186, 186, 186, 186, 186, 186, 186, 714, 666, 715,
+ 716, 666, 666, 717, 718, 719, 666, 720, 720, 666,
+ 721, 666, 722, 666, 723, 666, 724, 725, 666, 726,
+ 666, 727, 666, 728, 729, 730, 730, 731, 730, 732,
+ 666, 733, 666, 666, 734, 666, 666, 666, 666, 666,
+ 735, 735, 735, 735, 735, 735, 735, 735, 735, 735,
+ 736, 737, 666, 666, 666, 738, 666, 666, 666, 666,
+ 739, 740, 741, 742, 743, 744, 745, 746, 746, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 746, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 746, 746,
+
+ 746, 747, 666, 666, 740, 666, 748, 749, 750, 750,
+ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
+ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
+ 310, 310, 751, 752, 666, 753, 666, 754, 666, 755,
+ 666, 756, 666, 757, 758, 759, 759, 759, 759, 759,
+ 759, 666, 760, 761, 666, 762, 763, 764, 745, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 746, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 746, 746,
+ 746, 746, 746, 748, 748, 748, 310, 310, 310, 310,
+ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
+
+ 310, 310, 310, 310, 310, 310, 310, 310, 310, 751,
+ 752, 666, 765, 666, 766, 666, 767, 666, 768, 666,
+ 769, 759, 759, 759, 759, 666, 770, 746, 746, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 746, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 746, 666,
+ 666, 310, 310, 310, 310, 310, 310, 310, 310, 310,
+ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
+ 751, 752, 666, 771, 759, 759, 759, 746, 746, 746,
+ 746, 746, 746, 746, 746, 666, 666, 746, 746, 746,
+ 746, 746, 746, 746, 746, 746, 746, 746, 666, 772,
+
+ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
+ 310, 310, 310, 310, 310, 310, 759, 759, 759, 666,
+ 666, 746, 746, 746, 746, 746, 666, 666, 746, 746,
+ 746, 666, 666, 666, 666, 746, 746, 746, 746, 746,
+ 746, 746, 772, 666, 772, 310, 310, 310, 310, 310,
+ 310, 310, 310, 310, 310, 759, 759, 746, 746, 746,
+ 746, 666, 666, 746, 746, 746, 746, 746, 746, 666,
+ 666, 746, 746, 772, 310, 310, 310, 310, 310, 310,
+ 310, 759, 759, 746, 666, 666, 746, 746, 746, 746,
+ 746, 666, 666, 746, 666, 666, 666, 666, 310, 310,
+
+ 759, 759, 746, 666, 666, 746, 746, 746, 746, 746,
+ 310, 310, 759, 759, 746, 746, 666, 666, 746, 746,
+ 746, 310, 759, 746, 746, 746, 746, 746, 310, 759,
+ 746, 666, 666, 746, 746, 746, 310, 746, 746, 746,
+ 310, 746, 746, 746, 310, 746, 746, 746, 310, 666,
+ 666, 746, 746, 310, 746, 746, 310, 746, 746, 310,
+ 746, 310, 746, 310, 666, 0, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666
+ } ;
+
+static const flex_int16_t yy_nxt[4952] =
+ { 0,
+ 18, 19, 20, 19, 21, 18, 22, 23, 18, 24,
+ 18, 18, 18, 25, 26, 18, 27, 28, 29, 30,
+ 30, 30, 31, 18, 18, 18, 28, 28, 28, 32,
+ 30, 33, 34, 35, 36, 37, 30, 38, 30, 30,
+ 39, 40, 30, 30, 41, 30, 42, 43, 44, 45,
+ 30, 30, 30, 30, 30, 18, 18, 18, 28, 30,
+ 18, 32, 30, 33, 34, 35, 36, 37, 30, 38,
+ 30, 39, 40, 30, 30, 41, 30, 42, 43, 44,
+ 45, 30, 30, 30, 30, 46, 47, 48, 18, 49,
+ 20, 49, 21, 18, 22, 23, 18, 24, 18, 18,
+
+ 18, 50, 51, 18, 52, 28, 29, 30, 30, 30,
+ 53, 18, 18, 18, 28, 28, 28, 54, 55, 56,
+ 57, 58, 59, 60, 55, 61, 55, 55, 62, 63,
+ 55, 55, 64, 55, 65, 66, 67, 68, 55, 55,
+ 55, 55, 55, 18, 18, 18, 28, 30, 18, 54,
+ 55, 56, 57, 58, 59, 60, 55, 61, 55, 62,
+ 63, 55, 55, 64, 55, 65, 66, 67, 68, 55,
+ 55, 55, 55, 46, 47, 48, 69, 70, 71, 70,
+ 69, 72, 73, 69, 69, 69, 69, 69, 74, 69,
+ 69, 75, 69, 69, 76, 69, 69, 69, 69, 69,
+
+ 69, 77, 69, 69, 69, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 79, 69, 80, 69, 69, 81, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 69, 69, 69, 83, 83, 86, 86, 86, 86,
+ 86, 86, 88, 143, 665, 84, 84, 88, 144, 89,
+ 89, 89, 247, 248, 89, 89, 89, 90, 91, 92,
+ 91, 90, 90, 90, 90, 90, 90, 90, 90, 90,
+
+ 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
+ 90, 90, 90, 90, 90, 90, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 90, 90, 90, 90, 90, 90, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 90, 90, 90, 95, 96, 95, 176, 97,
+ 176, 640, 177, 177, 98, 99, 100, 333, 333, 101,
+ 95, 96, 95, 216, 97, 334, 334, 217, 262, 98,
+
+ 99, 100, 263, 623, 101, 102, 103, 104, 103, 105,
+ 106, 102, 107, 108, 109, 110, 111, 112, 113, 114,
+ 115, 116, 102, 117, 118, 119, 119, 102, 120, 121,
+ 122, 123, 102, 102, 124, 125, 126, 127, 128, 125,
+ 125, 125, 129, 125, 125, 125, 125, 130, 131, 125,
+ 125, 125, 132, 133, 125, 125, 125, 125, 125, 125,
+ 134, 102, 135, 102, 102, 136, 124, 125, 126, 127,
+ 128, 125, 125, 125, 129, 125, 125, 125, 130, 131,
+ 125, 125, 125, 132, 133, 125, 125, 125, 125, 125,
+ 102, 102, 102, 149, 150, 619, 156, 152, 153, 154,
+
+ 155, 158, 159, 306, 157, 161, 166, 666, 151, 162,
+ 168, 209, 170, 252, 169, 307, 160, 164, 222, 222,
+ 222, 167, 163, 601, 253, 149, 150, 152, 156, 153,
+ 154, 155, 158, 165, 159, 157, 226, 161, 166, 151,
+ 229, 162, 168, 170, 252, 180, 169, 160, 171, 164,
+ 171, 539, 167, 163, 181, 253, 216, 148, 148, 148,
+ 217, 173, 210, 173, 165, 224, 224, 224, 262, 174,
+ 142, 142, 263, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 142, 143, 142, 142, 230, 227, 144, 224,
+ 224, 224, 254, 142, 142, 142, 142, 142, 142, 175,
+
+ 147, 183, 147, 176, 256, 184, 184, 147, 257, 147,
+ 244, 244, 175, 147, 183, 147, 176, 186, 184, 184,
+ 147, 255, 147, 254, 530, 142, 142, 142, 142, 142,
+ 142, 233, 306, 234, 241, 256, 185, 275, 185, 257,
+ 185, 244, 244, 245, 307, 147, 209, 190, 142, 186,
+ 185, 255, 191, 226, 185, 142, 142, 142, 147, 175,
+ 147, 183, 147, 176, 189, 184, 184, 147, 185, 147,
+ 185, 260, 185, 245, 185, 187, 185, 196, 190, 185,
+ 242, 185, 235, 191, 193, 185, 438, 192, 195, 188,
+ 185, 197, 194, 185, 189, 258, 198, 210, 185, 429,
+
+ 199, 288, 203, 260, 227, 147, 185, 187, 185, 196,
+ 185, 185, 185, 200, 355, 289, 193, 204, 192, 195,
+ 188, 185, 197, 194, 185, 185, 258, 259, 198, 201,
+ 185, 278, 199, 288, 203, 246, 246, 246, 355, 185,
+ 185, 185, 185, 185, 200, 202, 205, 289, 204, 339,
+ 206, 229, 236, 207, 185, 237, 185, 185, 259, 364,
+ 279, 201, 278, 450, 238, 236, 237, 238, 238, 238,
+ 185, 280, 185, 281, 185, 451, 202, 355, 205, 264,
+ 265, 264, 206, 355, 207, 185, 267, 185, 269, 270,
+ 269, 279, 219, 271, 272, 270, 272, 230, 219, 273,
+
+ 340, 212, 280, 238, 281, 238, 266, 266, 267, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266,
+ 266, 266, 266, 266, 266, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 266, 266, 266, 266, 266, 266, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 266, 266, 266, 282, 283, 284, 285, 448, 287,
+
+ 290, 291, 292, 241, 294, 296, 297, 298, 299, 300,
+ 286, 295, 293, 301, 176, 499, 176, 500, 177, 177,
+ 303, 304, 303, 557, 185, 282, 283, 284, 448, 285,
+ 287, 290, 291, 346, 292, 294, 296, 297, 298, 299,
+ 300, 286, 295, 293, 301, 171, 176, 171, 176, 242,
+ 177, 177, 176, 557, 176, 185, 177, 177, 173, 183,
+ 173, 176, 209, 184, 184, 346, 174, 142, 305, 304,
+ 305, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 142, 544, 306, 142, 313, 185, 666, 328,
+ 142, 142, 142, 142, 142, 142, 307, 181, 384, 385,
+
+ 148, 148, 148, 277, 175, 147, 183, 147, 176, 180,
+ 184, 184, 147, 210, 147, 347, 277, 313, 185, 302,
+ 328, 139, 142, 142, 142, 142, 142, 142, 302, 147,
+ 310, 147, 302, 311, 545, 314, 147, 185, 185, 185,
+ 302, 175, 147, 183, 147, 176, 347, 184, 184, 147,
+ 147, 147, 142, 142, 142, 315, 250, 312, 316, 568,
+ 185, 310, 318, 185, 311, 320, 314, 185, 185, 185,
+ 185, 317, 319, 249, 147, 185, 309, 321, 322, 185,
+ 185, 185, 243, 185, 327, 323, 315, 147, 312, 568,
+ 316, 185, 185, 318, 185, 324, 329, 320, 185, 349,
+
+ 185, 185, 317, 233, 319, 234, 185, 309, 321, 322,
+ 185, 185, 185, 325, 185, 327, 231, 323, 330, 361,
+ 326, 185, 331, 185, 368, 185, 324, 329, 544, 185,
+ 349, 185, 185, 332, 185, 222, 222, 222, 224, 224,
+ 224, 335, 335, 220, 325, 337, 337, 341, 341, 330,
+ 361, 326, 185, 331, 235, 368, 185, 246, 246, 246,
+ 185, 343, 343, 219, 332, 185, 264, 265, 264, 238,
+ 348, 350, 219, 351, 336, 238, 352, 352, 338, 545,
+ 342, 238, 238, 238, 238, 238, 238, 238, 238, 360,
+ 238, 238, 238, 365, 344, 238, 238, 366, 238, 238,
+
+ 238, 367, 348, 350, 336, 351, 362, 363, 338, 353,
+ 342, 269, 270, 269, 412, 412, 271, 303, 304, 303,
+ 238, 360, 238, 216, 344, 365, 238, 217, 238, 366,
+ 269, 270, 269, 367, 238, 271, 238, 362, 363, 353,
+ 266, 266, 267, 266, 266, 266, 266, 266, 266, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 266, 266, 266, 266, 266,
+
+ 266, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 266, 266, 266, 272, 270,
+ 272, 369, 370, 273, 371, 372, 373, 374, 213, 375,
+ 376, 377, 378, 379, 212, 380, 381, 382, 383, 305,
+ 304, 305, 141, 185, 414, 414, 394, 396, 185, 146,
+ 389, 390, 369, 370, 141, 371, 372, 373, 139, 374,
+ 375, 376, 377, 302, 378, 379, 380, 381, 666, 382,
+ 383, 666, 302, 147, 185, 147, 302, 394, 396, 185,
+ 147, 389, 390, 391, 302, 175, 147, 183, 147, 176,
+
+ 185, 184, 184, 147, 185, 147, 175, 147, 183, 147,
+ 176, 392, 184, 184, 147, 185, 147, 185, 185, 387,
+ 416, 416, 393, 364, 395, 391, 398, 185, 147, 397,
+ 185, 185, 185, 388, 185, 185, 185, 399, 400, 666,
+ 401, 147, 185, 392, 422, 403, 185, 185, 185, 185,
+ 666, 387, 147, 417, 393, 395, 666, 398, 185, 666,
+ 397, 185, 185, 185, 388, 185, 402, 185, 399, 666,
+ 400, 401, 404, 185, 405, 422, 403, 209, 185, 185,
+ 185, 185, 185, 417, 406, 423, 407, 408, 409, 418,
+ 418, 410, 410, 185, 185, 185, 424, 402, 411, 411,
+
+ 420, 420, 425, 428, 404, 430, 405, 426, 426, 431,
+ 185, 185, 185, 185, 432, 406, 423, 407, 433, 408,
+ 409, 434, 666, 435, 436, 185, 185, 424, 210, 437,
+ 439, 440, 441, 425, 428, 216, 430, 442, 443, 217,
+ 444, 431, 445, 446, 447, 432, 449, 384, 385, 666,
+ 433, 666, 666, 434, 435, 436, 185, 450, 666, 452,
+ 437, 439, 185, 440, 441, 185, 666, 455, 442, 451,
+ 443, 185, 444, 445, 446, 447, 460, 449, 185, 453,
+ 454, 429, 185, 185, 456, 666, 185, 185, 185, 185,
+ 452, 457, 666, 185, 458, 185, 185, 459, 461, 455,
+
+ 185, 499, 185, 500, 185, 185, 463, 460, 438, 185,
+ 453, 462, 454, 185, 185, 185, 456, 185, 185, 185,
+ 185, 465, 457, 466, 468, 458, 185, 464, 459, 666,
+ 461, 185, 185, 185, 185, 185, 185, 463, 185, 185,
+ 467, 666, 209, 462, 472, 472, 185, 470, 475, 185,
+ 225, 225, 469, 465, 466, 468, 471, 471, 476, 464,
+ 228, 228, 479, 185, 185, 185, 473, 473, 477, 185,
+ 185, 467, 232, 232, 240, 240, 261, 261, 470, 478,
+ 475, 216, 469, 480, 483, 217, 481, 482, 484, 476,
+ 485, 666, 488, 210, 479, 486, 486, 486, 489, 477,
+
+ 490, 666, 491, 492, 493, 487, 494, 495, 496, 497,
+ 478, 498, 185, 505, 501, 480, 483, 481, 482, 484,
+ 502, 504, 485, 488, 185, 666, 503, 666, 506, 489,
+ 185, 185, 490, 491, 492, 493, 185, 494, 666, 495,
+ 496, 497, 498, 185, 505, 501, 486, 486, 486, 185,
+ 666, 508, 502, 504, 517, 185, 487, 503, 185, 185,
+ 506, 185, 185, 507, 185, 185, 185, 185, 510, 185,
+ 509, 512, 511, 513, 666, 514, 515, 666, 185, 518,
+ 185, 185, 185, 508, 519, 185, 517, 185, 185, 185,
+ 185, 516, 234, 234, 507, 185, 185, 185, 522, 510,
+
+ 185, 509, 512, 511, 523, 513, 524, 514, 515, 185,
+ 518, 525, 185, 185, 526, 519, 185, 529, 185, 185,
+ 531, 666, 516, 520, 520, 520, 527, 527, 527, 522,
+ 486, 486, 486, 521, 537, 523, 528, 524, 536, 538,
+ 487, 540, 541, 525, 542, 185, 526, 546, 556, 529,
+ 666, 531, 532, 532, 532, 534, 534, 534, 520, 520,
+ 520, 666, 533, 548, 666, 535, 537, 185, 521, 536,
+ 538, 185, 540, 541, 185, 542, 185, 549, 546, 556,
+ 547, 527, 527, 527, 185, 558, 532, 532, 532, 666,
+ 551, 528, 185, 530, 666, 548, 533, 185, 185, 185,
+
+ 550, 185, 185, 555, 185, 185, 534, 534, 534, 549,
+ 185, 547, 552, 185, 666, 185, 535, 558, 185, 559,
+ 185, 553, 551, 185, 561, 185, 554, 560, 185, 539,
+ 185, 550, 185, 574, 555, 185, 520, 520, 520, 666,
+ 564, 185, 565, 552, 185, 185, 521, 666, 666, 185,
+ 559, 185, 553, 566, 567, 561, 185, 554, 569, 560,
+ 527, 527, 527, 562, 562, 562, 572, 532, 532, 532,
+ 528, 564, 573, 563, 565, 185, 185, 533, 534, 534,
+ 534, 570, 570, 570, 545, 566, 567, 185, 535, 569,
+ 576, 571, 562, 562, 562, 575, 185, 185, 572, 582,
+
+ 577, 578, 563, 185, 573, 583, 185, 185, 580, 579,
+ 570, 570, 570, 584, 666, 185, 581, 666, 185, 587,
+ 571, 588, 576, 185, 666, 666, 575, 185, 185, 589,
+ 582, 185, 577, 578, 185, 590, 591, 583, 185, 579,
+ 580, 585, 585, 585, 594, 584, 185, 544, 581, 185,
+ 587, 586, 666, 588, 185, 562, 562, 562, 666, 185,
+ 589, 599, 185, 666, 602, 563, 590, 666, 591, 592,
+ 592, 592, 570, 570, 570, 594, 595, 595, 595, 593,
+ 185, 606, 571, 597, 597, 597, 596, 585, 585, 585,
+ 185, 600, 599, 598, 185, 602, 603, 586, 545, 592,
+
+ 592, 592, 595, 595, 595, 597, 597, 597, 607, 593,
+ 608, 666, 596, 606, 609, 598, 610, 666, 585, 585,
+ 585, 666, 613, 600, 614, 185, 185, 603, 586, 604,
+ 604, 604, 612, 592, 592, 592, 615, 666, 185, 605,
+ 607, 185, 608, 593, 185, 609, 616, 610, 595, 595,
+ 595, 597, 597, 597, 613, 611, 614, 185, 596, 620,
+ 624, 598, 185, 612, 604, 604, 604, 621, 615, 185,
+ 185, 625, 185, 626, 605, 185, 622, 616, 617, 617,
+ 617, 627, 628, 185, 617, 617, 617, 611, 618, 619,
+ 629, 620, 624, 185, 618, 630, 666, 631, 621, 634,
+
+ 635, 185, 636, 625, 626, 632, 632, 632, 622, 638,
+ 666, 639, 627, 628, 185, 633, 637, 666, 185, 185,
+ 641, 629, 642, 643, 632, 632, 632, 630, 631, 644,
+ 634, 645, 635, 636, 633, 646, 647, 652, 185, 648,
+ 653, 638, 639, 185, 655, 649, 666, 666, 637, 185,
+ 185, 641, 185, 642, 656, 643, 666, 185, 657, 658,
+ 644, 654, 659, 645, 663, 661, 646, 647, 652, 185,
+ 665, 648, 653, 666, 185, 655, 649, 650, 650, 650,
+ 650, 650, 650, 185, 666, 656, 660, 651, 185, 657,
+ 651, 658, 654, 662, 659, 663, 185, 661, 185, 185,
+
+ 185, 666, 666, 666, 664, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 660, 666,
+ 666, 666, 666, 666, 666, 662, 666, 185, 666, 185,
+ 185, 185, 666, 666, 666, 664, 82, 82, 82, 82,
+ 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
+ 82, 82, 82, 82, 82, 82, 82, 82, 82, 82,
+ 82, 82, 82, 82, 82, 82, 85, 85, 85, 85,
+ 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
+ 85, 85, 85, 85, 85, 85, 85, 85, 85, 85,
+ 85, 85, 85, 85, 85, 85, 87, 87, 87, 87,
+
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 94, 94, 94, 94,
+ 94, 94, 94, 94, 94, 94, 94, 94, 94, 94,
+ 94, 94, 94, 94, 94, 94, 94, 94, 94, 94,
+ 94, 94, 94, 94, 94, 94, 137, 666, 666, 666,
+ 137, 137, 137, 137, 137, 137, 137, 137, 137, 137,
+ 137, 137, 137, 137, 137, 137, 137, 137, 137, 137,
+ 137, 137, 137, 137, 137, 137, 138, 138, 138, 138,
+ 138, 138, 138, 138, 138, 138, 138, 138, 138, 138,
+
+ 138, 138, 138, 138, 138, 138, 138, 138, 138, 138,
+ 138, 138, 138, 138, 138, 138, 140, 140, 140, 140,
+ 140, 140, 140, 142, 142, 666, 142, 142, 142, 142,
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 142, 145, 145, 145, 145, 145, 145, 145,
+ 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+ 145, 145, 145, 145, 145, 145, 145, 145, 145, 145,
+ 145, 145, 145, 147, 147, 147, 666, 666, 147, 147,
+ 666, 147, 666, 666, 666, 147, 147, 147, 147, 147,
+
+ 147, 147, 147, 148, 148, 666, 666, 666, 666, 666,
+ 148, 148, 148, 148, 148, 148, 148, 172, 666, 172,
+ 666, 666, 666, 666, 172, 172, 666, 172, 666, 666,
+ 666, 666, 172, 666, 666, 666, 666, 172, 172, 172,
+ 172, 172, 172, 172, 175, 666, 175, 666, 175, 666,
+ 175, 666, 666, 666, 666, 666, 666, 175, 175, 175,
+ 175, 175, 175, 175, 178, 666, 666, 178, 178, 666,
+ 178, 178, 178, 666, 666, 666, 666, 178, 178, 178,
+ 178, 178, 178, 178, 179, 179, 666, 179, 179, 179,
+ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179,
+
+ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179,
+ 179, 179, 179, 179, 182, 666, 666, 666, 666, 182,
+ 666, 666, 182, 182, 666, 666, 666, 666, 666, 182,
+ 182, 182, 182, 182, 182, 182, 185, 185, 185, 185,
+ 185, 666, 185, 185, 666, 185, 666, 666, 666, 185,
+ 185, 185, 185, 185, 185, 185, 185, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 211, 211, 211,
+ 211, 211, 211, 211, 211, 211, 211, 211, 211, 211,
+
+ 211, 211, 211, 211, 211, 211, 211, 211, 211, 211,
+ 211, 211, 211, 211, 211, 211, 211, 214, 666, 214,
+ 214, 666, 666, 666, 666, 666, 214, 214, 214, 214,
+ 214, 214, 214, 214, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 218, 218, 218, 218, 218, 218,
+ 218, 218, 666, 218, 218, 218, 218, 218, 218, 218,
+ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218,
+ 218, 218, 218, 218, 221, 666, 666, 666, 221, 221,
+
+ 221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
+ 221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
+ 221, 221, 221, 221, 223, 223, 666, 223, 223, 666,
+ 666, 666, 666, 666, 223, 223, 223, 223, 223, 223,
+ 223, 223, 225, 225, 225, 225, 225, 225, 666, 225,
+ 225, 225, 225, 225, 225, 225, 225, 225, 225, 225,
+ 225, 225, 225, 225, 225, 225, 225, 225, 225, 225,
+ 225, 225, 228, 228, 228, 228, 228, 228, 228, 228,
+ 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+ 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+
+ 228, 228, 232, 232, 232, 232, 232, 232, 232, 232,
+ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+ 232, 232, 239, 666, 239, 666, 666, 666, 666, 239,
+ 239, 239, 239, 239, 666, 666, 666, 666, 239, 239,
+ 239, 239, 239, 239, 239, 239, 239, 240, 240, 240,
+ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
+ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
+ 240, 240, 240, 240, 240, 240, 240, 251, 251, 666,
+ 666, 666, 666, 666, 251, 251, 251, 251, 251, 251,
+
+ 251, 251, 261, 261, 261, 261, 261, 261, 261, 261,
+ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261,
+ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261,
+ 261, 261, 137, 137, 137, 137, 137, 137, 137, 137,
+ 137, 137, 137, 137, 137, 137, 137, 137, 137, 137,
+ 137, 137, 137, 137, 137, 137, 137, 137, 137, 137,
+ 137, 137, 138, 138, 138, 138, 138, 138, 138, 138,
+ 138, 138, 138, 138, 138, 138, 138, 138, 138, 138,
+ 138, 138, 138, 138, 138, 138, 138, 138, 138, 138,
+ 138, 138, 142, 142, 666, 142, 142, 142, 142, 142,
+
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 274, 274, 274, 274, 274, 274, 274, 274,
+ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274,
+ 274, 274, 274, 274, 274, 274, 274, 274, 274, 274,
+ 274, 274, 276, 276, 666, 276, 276, 276, 276, 276,
+ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276,
+ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276,
+ 276, 276, 147, 147, 147, 666, 666, 147, 147, 666,
+ 147, 666, 666, 666, 147, 147, 147, 147, 147, 147,
+
+ 147, 147, 148, 148, 148, 666, 666, 666, 666, 148,
+ 148, 148, 148, 148, 148, 148, 172, 666, 172, 666,
+ 666, 666, 666, 172, 172, 666, 172, 666, 666, 666,
+ 666, 172, 666, 666, 666, 666, 172, 172, 172, 172,
+ 172, 172, 172, 175, 666, 175, 666, 175, 666, 175,
+ 666, 666, 666, 666, 666, 666, 175, 175, 175, 175,
+ 175, 175, 175, 178, 178, 666, 178, 178, 178, 666,
+ 666, 666, 666, 178, 178, 178, 178, 178, 178, 178,
+ 181, 666, 666, 666, 666, 181, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 181, 181, 181, 181, 181,
+
+ 181, 181, 302, 666, 666, 666, 302, 666, 302, 666,
+ 302, 666, 302, 666, 666, 302, 302, 666, 666, 302,
+ 302, 302, 302, 302, 302, 302, 179, 179, 179, 179,
+ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179,
+ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179,
+ 179, 179, 179, 179, 179, 179, 182, 666, 666, 666,
+ 666, 666, 666, 182, 182, 666, 666, 182, 182, 182,
+ 666, 666, 666, 666, 182, 182, 182, 182, 182, 182,
+ 182, 308, 666, 666, 666, 308, 308, 308, 308, 308,
+ 666, 308, 308, 666, 308, 308, 666, 666, 308, 308,
+
+ 308, 308, 308, 308, 308, 308, 185, 185, 185, 185,
+ 185, 666, 185, 185, 666, 185, 666, 666, 666, 185,
+ 185, 185, 185, 185, 185, 185, 185, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 208, 666, 208,
+ 666, 666, 666, 666, 666, 666, 208, 666, 666, 666,
+ 666, 208, 666, 208, 208, 666, 666, 208, 208, 211,
+ 211, 211, 211, 211, 211, 211, 211, 211, 211, 211,
+ 211, 211, 211, 211, 211, 211, 211, 211, 211, 211,
+
+ 211, 211, 211, 211, 211, 211, 211, 211, 211, 214,
+ 666, 214, 214, 666, 666, 666, 666, 666, 214, 214,
+ 214, 214, 214, 214, 214, 214, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 666, 666, 666,
+ 666, 666, 666, 215, 666, 666, 666, 666, 215, 666,
+ 215, 215, 666, 666, 215, 215, 666, 666, 215, 218,
+ 218, 218, 218, 218, 218, 218, 218, 666, 218, 218,
+ 218, 218, 218, 218, 218, 218, 218, 218, 218, 218,
+
+ 218, 218, 218, 218, 218, 218, 218, 218, 218, 221,
+ 666, 666, 666, 221, 221, 221, 221, 221, 221, 221,
+ 221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
+ 221, 221, 221, 221, 221, 221, 221, 221, 221, 223,
+ 223, 666, 223, 223, 666, 666, 666, 666, 666, 223,
+ 223, 223, 223, 223, 223, 223, 223, 225, 225, 225,
+ 225, 225, 225, 666, 225, 225, 225, 225, 225, 225,
+ 225, 225, 225, 225, 225, 225, 225, 225, 225, 225,
+ 225, 225, 225, 225, 225, 225, 225, 225, 225, 225,
+ 666, 666, 666, 666, 666, 666, 225, 666, 666, 666,
+
+ 666, 666, 666, 666, 225, 666, 666, 225, 666, 225,
+ 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+ 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+ 228, 228, 228, 228, 228, 228, 228, 228, 228, 228,
+ 228, 228, 228, 666, 666, 666, 666, 666, 666, 228,
+ 666, 666, 666, 666, 666, 666, 666, 228, 666, 666,
+ 228, 666, 228, 232, 232, 232, 232, 232, 232, 232,
+ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232,
+ 232, 232, 232, 234, 234, 234, 234, 234, 234, 234,
+
+ 234, 234, 234, 234, 234, 234, 234, 234, 234, 234,
+ 234, 234, 234, 234, 234, 234, 234, 234, 234, 234,
+ 234, 234, 234, 232, 232, 232, 666, 666, 666, 666,
+ 666, 666, 232, 666, 666, 666, 666, 666, 666, 666,
+ 232, 666, 666, 232, 666, 232, 239, 666, 666, 666,
+ 666, 666, 666, 239, 239, 666, 239, 239, 666, 666,
+ 666, 666, 239, 239, 239, 239, 239, 239, 239, 239,
+ 239, 238, 666, 666, 666, 666, 666, 666, 238, 238,
+ 666, 238, 238, 666, 666, 666, 666, 238, 238, 238,
+ 238, 238, 238, 238, 238, 238, 240, 240, 240, 240,
+
+ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
+ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240,
+ 240, 240, 240, 240, 240, 240, 240, 240, 240, 666,
+ 666, 666, 666, 666, 666, 240, 666, 666, 666, 666,
+ 666, 666, 666, 240, 666, 666, 240, 666, 240, 345,
+ 345, 666, 666, 666, 666, 666, 345, 345, 345, 251,
+ 251, 666, 666, 666, 666, 666, 251, 251, 251, 251,
+ 251, 251, 251, 251, 261, 261, 261, 261, 261, 261,
+ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261,
+ 261, 261, 261, 261, 261, 261, 261, 261, 261, 261,
+
+ 261, 261, 261, 261, 261, 666, 261, 666, 666, 666,
+ 666, 666, 666, 261, 666, 666, 666, 666, 666, 666,
+ 666, 261, 666, 666, 261, 666, 261, 666, 261, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266,
+ 266, 266, 266, 266, 266, 266, 266, 266, 266, 354,
+ 354, 354, 354, 354, 354, 354, 354, 354, 354, 354,
+ 354, 354, 354, 354, 354, 354, 354, 354, 354, 354,
+ 354, 354, 354, 354, 354, 354, 354, 354, 354, 142,
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 142,
+ 142, 142, 142, 142, 142, 142, 142, 142, 142, 356,
+ 356, 356, 356, 356, 356, 356, 356, 356, 356, 356,
+ 356, 356, 356, 356, 356, 356, 356, 356, 356, 356,
+ 356, 356, 356, 356, 356, 356, 356, 356, 356, 357,
+ 357, 666, 357, 357, 357, 357, 357, 357, 357, 357,
+ 357, 357, 357, 357, 357, 357, 357, 357, 357, 357,
+ 357, 357, 357, 357, 357, 357, 357, 357, 357, 358,
+ 358, 666, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 276,
+ 276, 666, 276, 276, 276, 276, 276, 276, 276, 276,
+ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276,
+ 276, 276, 276, 276, 276, 276, 276, 276, 276, 359,
+ 359, 666, 359, 359, 359, 359, 359, 359, 359, 359,
+ 359, 359, 359, 359, 359, 359, 359, 359, 359, 359,
+ 359, 359, 359, 359, 359, 359, 359, 359, 359, 147,
+ 147, 147, 666, 666, 147, 147, 666, 147, 666, 666,
+ 666, 147, 147, 147, 147, 147, 147, 147, 147, 302,
+ 666, 666, 666, 302, 666, 302, 666, 302, 666, 302,
+
+ 666, 666, 302, 302, 666, 666, 302, 302, 302, 302,
+ 302, 302, 302, 386, 386, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 386, 386, 386, 386, 386, 386, 386, 308, 666,
+ 666, 666, 308, 308, 308, 308, 308, 666, 308, 308,
+ 666, 308, 308, 666, 666, 308, 308, 308, 308, 308,
+ 308, 308, 308, 185, 185, 185, 185, 185, 666, 185,
+ 185, 666, 185, 666, 666, 666, 185, 185, 185, 185,
+ 185, 185, 185, 185, 208, 208, 208, 208, 208, 208,
+ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208,
+
+ 208, 208, 208, 208, 208, 208, 208, 208, 208, 208,
+ 208, 208, 208, 208, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 215, 215, 215, 215, 215, 215,
+ 215, 215, 215, 215, 413, 413, 666, 666, 666, 666,
+ 666, 413, 413, 413, 415, 415, 666, 666, 666, 666,
+ 666, 415, 415, 415, 234, 234, 234, 666, 666, 666,
+ 666, 666, 666, 234, 666, 666, 666, 666, 666, 666,
+ 666, 234, 666, 666, 234, 666, 234, 419, 419, 666,
+ 666, 666, 666, 666, 419, 419, 419, 421, 421, 666,
+
+ 666, 666, 666, 666, 421, 421, 421, 345, 345, 666,
+ 666, 666, 666, 666, 345, 345, 345, 251, 251, 666,
+ 666, 666, 666, 666, 251, 251, 251, 251, 251, 251,
+ 251, 251, 427, 427, 666, 666, 666, 666, 666, 427,
+ 427, 427, 354, 354, 354, 354, 354, 354, 354, 354,
+ 354, 354, 354, 354, 354, 354, 354, 354, 354, 354,
+ 354, 354, 354, 354, 354, 354, 354, 354, 354, 354,
+ 354, 354, 356, 356, 356, 356, 356, 356, 356, 356,
+ 356, 356, 356, 356, 356, 356, 356, 356, 356, 356,
+ 356, 356, 356, 356, 356, 356, 356, 356, 356, 356,
+
+ 356, 356, 357, 357, 666, 357, 357, 357, 357, 357,
+ 357, 357, 357, 357, 357, 357, 357, 357, 357, 357,
+ 357, 357, 357, 357, 357, 357, 357, 357, 357, 357,
+ 357, 357, 358, 358, 666, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 358, 358, 358, 358, 358, 358, 358, 358,
+ 358, 358, 225, 225, 666, 666, 666, 666, 666, 225,
+ 225, 225, 228, 228, 666, 666, 666, 666, 666, 228,
+ 228, 228, 474, 474, 666, 666, 666, 666, 666, 474,
+ 474, 474, 232, 232, 666, 666, 666, 666, 666, 232,
+
+ 232, 232, 240, 240, 666, 666, 666, 666, 666, 240,
+ 240, 240, 261, 261, 666, 666, 666, 666, 666, 261,
+ 261, 261, 234, 234, 666, 666, 666, 666, 666, 234,
+ 234, 234, 543, 543, 543, 543, 543, 543, 543, 543,
+ 543, 543, 543, 543, 543, 543, 543, 543, 543, 543,
+ 543, 543, 543, 543, 543, 543, 543, 543, 543, 543,
+ 543, 543, 17, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666
+ } ;
+
+static const flex_int16_t yy_chk[4952] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 5, 6, 7, 7, 7, 8,
+ 8, 8, 9, 27, 663, 5, 6, 10, 27, 9,
+ 9, 9, 121, 121, 10, 10, 10, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 13, 13, 13, 50, 13,
+ 50, 636, 50, 50, 13, 13, 13, 210, 210, 13,
+ 14, 14, 14, 81, 14, 216, 216, 81, 136, 14,
+
+ 14, 14, 136, 614, 14, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 32, 33, 608, 38, 34, 35, 36,
+
+ 37, 39, 40, 181, 38, 41, 43, 181, 33, 41,
+ 44, 72, 45, 124, 44, 181, 40, 42, 89, 89,
+ 89, 43, 41, 582, 126, 32, 33, 34, 38, 35,
+ 36, 37, 39, 42, 40, 38, 97, 41, 43, 33,
+ 98, 41, 44, 45, 124, 53, 44, 40, 49, 42,
+ 49, 495, 43, 41, 53, 126, 215, 53, 53, 53,
+ 215, 49, 72, 49, 42, 95, 95, 95, 261, 49,
+ 52, 52, 261, 52, 52, 52, 52, 52, 52, 52,
+ 52, 52, 52, 52, 52, 52, 98, 97, 52, 96,
+ 96, 96, 127, 52, 52, 52, 52, 52, 52, 54,
+
+ 54, 54, 54, 54, 129, 54, 54, 54, 130, 54,
+ 118, 118, 55, 55, 55, 55, 55, 54, 55, 55,
+ 55, 128, 55, 127, 488, 52, 52, 52, 52, 52,
+ 52, 106, 306, 106, 110, 129, 58, 144, 59, 130,
+ 57, 244, 244, 118, 306, 54, 208, 58, 144, 54,
+ 58, 128, 59, 225, 57, 52, 52, 52, 55, 56,
+ 56, 56, 56, 56, 57, 56, 56, 56, 58, 56,
+ 59, 133, 57, 118, 62, 56, 60, 63, 58, 61,
+ 110, 58, 106, 59, 61, 57, 371, 60, 62, 56,
+ 60, 63, 61, 61, 57, 131, 64, 208, 66, 361,
+
+ 64, 159, 66, 133, 225, 56, 62, 56, 60, 63,
+ 64, 61, 66, 64, 356, 160, 61, 66, 60, 62,
+ 56, 60, 63, 61, 61, 65, 131, 132, 64, 65,
+ 66, 149, 64, 159, 66, 119, 119, 119, 354, 65,
+ 68, 64, 67, 66, 64, 65, 67, 160, 66, 234,
+ 67, 228, 107, 68, 68, 107, 67, 65, 132, 281,
+ 150, 65, 149, 450, 107, 107, 107, 107, 107, 107,
+ 65, 151, 68, 152, 67, 450, 65, 273, 67, 137,
+ 137, 137, 67, 271, 68, 68, 266, 67, 141, 141,
+ 141, 150, 219, 141, 143, 143, 143, 228, 218, 143,
+
+ 234, 211, 151, 107, 152, 107, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
+ 140, 140, 140, 140, 153, 154, 155, 157, 382, 158,
+
+ 161, 162, 163, 240, 164, 165, 166, 167, 168, 169,
+ 157, 164, 163, 170, 172, 451, 172, 451, 172, 172,
+ 178, 178, 178, 519, 193, 153, 154, 155, 382, 157,
+ 158, 161, 162, 252, 163, 164, 165, 166, 167, 168,
+ 169, 157, 164, 163, 170, 171, 175, 171, 175, 240,
+ 175, 175, 177, 519, 177, 193, 177, 177, 171, 184,
+ 171, 184, 471, 184, 184, 252, 171, 179, 179, 179,
+ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179,
+ 179, 179, 179, 500, 182, 179, 190, 190, 180, 203,
+ 179, 179, 179, 179, 179, 179, 182, 182, 307, 307,
+
+ 182, 182, 182, 182, 185, 185, 185, 185, 185, 174,
+ 185, 185, 185, 471, 185, 253, 148, 190, 190, 183,
+ 203, 138, 179, 179, 179, 179, 179, 179, 183, 183,
+ 187, 183, 183, 188, 500, 191, 183, 191, 187, 188,
+ 183, 186, 186, 186, 186, 186, 253, 186, 186, 186,
+ 185, 186, 179, 179, 179, 192, 123, 189, 194, 538,
+ 192, 187, 195, 189, 188, 197, 191, 195, 191, 187,
+ 188, 194, 196, 122, 183, 194, 186, 198, 199, 198,
+ 199, 197, 117, 196, 202, 200, 192, 186, 189, 538,
+ 194, 192, 202, 195, 189, 200, 204, 197, 195, 257,
+
+ 200, 204, 194, 232, 196, 232, 194, 186, 198, 199,
+ 198, 199, 197, 201, 196, 202, 105, 200, 205, 279,
+ 201, 201, 206, 202, 285, 205, 200, 204, 543, 206,
+ 257, 200, 204, 207, 207, 222, 222, 222, 224, 224,
+ 224, 227, 227, 84, 201, 230, 230, 235, 235, 205,
+ 279, 201, 201, 206, 232, 285, 205, 246, 246, 246,
+ 206, 242, 242, 83, 207, 207, 264, 264, 264, 236,
+ 255, 259, 82, 260, 227, 237, 262, 262, 230, 543,
+ 235, 236, 236, 239, 236, 236, 236, 237, 237, 278,
+ 237, 237, 237, 282, 242, 239, 239, 283, 239, 239,
+
+ 239, 284, 255, 259, 227, 260, 280, 280, 230, 262,
+ 235, 269, 269, 269, 335, 335, 269, 303, 303, 303,
+ 236, 278, 236, 472, 242, 282, 237, 472, 237, 283,
+ 270, 270, 270, 284, 239, 270, 239, 280, 280, 262,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268,
+ 268, 268, 268, 268, 268, 268, 268, 268, 272, 272,
+ 272, 286, 287, 272, 288, 289, 290, 291, 76, 292,
+ 293, 294, 295, 296, 73, 298, 299, 300, 301, 305,
+ 305, 305, 51, 311, 337, 337, 316, 318, 318, 29,
+ 311, 311, 286, 287, 26, 288, 289, 290, 22, 291,
+ 292, 293, 294, 308, 295, 296, 298, 299, 17, 300,
+ 301, 0, 308, 308, 311, 308, 308, 316, 318, 318,
+ 308, 311, 311, 313, 308, 309, 309, 309, 309, 309,
+
+ 313, 309, 309, 309, 312, 309, 310, 310, 310, 310,
+ 310, 314, 310, 310, 310, 317, 310, 320, 314, 309,
+ 340, 340, 315, 312, 317, 313, 320, 319, 308, 319,
+ 321, 313, 315, 310, 328, 312, 323, 321, 322, 0,
+ 323, 309, 325, 314, 347, 325, 317, 322, 320, 314,
+ 0, 309, 310, 340, 315, 317, 0, 320, 319, 0,
+ 319, 321, 324, 315, 310, 328, 324, 323, 321, 0,
+ 322, 323, 326, 325, 327, 347, 325, 333, 322, 326,
+ 329, 327, 330, 340, 329, 348, 330, 331, 332, 341,
+ 341, 333, 333, 324, 331, 332, 350, 324, 334, 334,
+
+ 343, 343, 351, 360, 326, 362, 327, 352, 352, 363,
+ 326, 329, 327, 330, 364, 329, 348, 330, 366, 331,
+ 332, 367, 0, 368, 369, 331, 332, 350, 333, 370,
+ 372, 373, 374, 351, 360, 334, 362, 375, 376, 334,
+ 377, 363, 378, 379, 381, 364, 383, 384, 384, 0,
+ 366, 385, 385, 367, 368, 369, 387, 386, 386, 387,
+ 370, 372, 388, 373, 374, 391, 0, 392, 375, 386,
+ 376, 389, 377, 378, 379, 381, 398, 383, 392, 389,
+ 390, 388, 394, 390, 393, 0, 395, 387, 396, 397,
+ 387, 394, 0, 388, 395, 393, 391, 396, 399, 392,
+
+ 401, 499, 389, 499, 406, 399, 401, 398, 397, 392,
+ 389, 400, 390, 394, 390, 404, 393, 395, 400, 396,
+ 397, 403, 394, 404, 407, 395, 393, 402, 396, 0,
+ 399, 401, 403, 405, 402, 406, 399, 401, 408, 409,
+ 405, 0, 410, 400, 411, 411, 404, 409, 422, 400,
+ 412, 412, 408, 403, 404, 407, 410, 410, 423, 402,
+ 414, 414, 429, 403, 405, 402, 416, 416, 424, 408,
+ 409, 405, 418, 418, 420, 420, 426, 426, 409, 428,
+ 422, 411, 408, 430, 433, 411, 431, 432, 434, 423,
+ 435, 0, 437, 410, 429, 436, 436, 436, 438, 424,
+
+ 439, 0, 440, 441, 442, 436, 443, 444, 446, 447,
+ 428, 448, 452, 456, 452, 430, 433, 431, 432, 434,
+ 453, 455, 435, 437, 454, 0, 454, 0, 457, 438,
+ 455, 453, 439, 440, 441, 442, 457, 443, 0, 444,
+ 446, 447, 448, 452, 456, 452, 458, 458, 458, 466,
+ 0, 460, 453, 455, 475, 454, 458, 454, 460, 459,
+ 457, 455, 453, 459, 461, 464, 462, 457, 462, 463,
+ 461, 464, 463, 465, 0, 467, 468, 0, 470, 476,
+ 466, 465, 467, 460, 477, 458, 475, 468, 469, 460,
+ 459, 469, 473, 473, 459, 461, 464, 462, 479, 462,
+
+ 463, 461, 464, 463, 480, 465, 481, 467, 468, 470,
+ 476, 482, 465, 467, 483, 477, 458, 485, 468, 469,
+ 489, 0, 469, 478, 478, 478, 484, 484, 484, 479,
+ 486, 486, 486, 478, 493, 480, 484, 481, 492, 494,
+ 486, 496, 497, 482, 498, 502, 483, 502, 517, 485,
+ 0, 489, 490, 490, 490, 491, 491, 491, 501, 501,
+ 501, 0, 490, 504, 0, 491, 493, 504, 501, 492,
+ 494, 503, 496, 497, 507, 498, 502, 506, 502, 517,
+ 503, 505, 505, 505, 506, 522, 508, 508, 508, 0,
+ 511, 505, 510, 507, 0, 504, 508, 501, 504, 511,
+
+ 510, 516, 503, 516, 512, 507, 509, 509, 509, 506,
+ 513, 503, 512, 514, 0, 506, 509, 522, 515, 523,
+ 505, 514, 511, 510, 525, 508, 515, 524, 501, 513,
+ 511, 510, 516, 545, 516, 512, 520, 520, 520, 0,
+ 530, 513, 531, 512, 514, 509, 520, 0, 0, 515,
+ 523, 505, 514, 536, 537, 525, 508, 515, 539, 524,
+ 527, 527, 527, 529, 529, 529, 541, 532, 532, 532,
+ 527, 530, 542, 529, 531, 548, 509, 532, 534, 534,
+ 534, 540, 540, 540, 545, 536, 537, 546, 534, 539,
+ 547, 540, 549, 549, 549, 546, 552, 547, 541, 556,
+
+ 550, 551, 549, 550, 542, 557, 548, 551, 554, 552,
+ 553, 553, 553, 558, 0, 554, 555, 0, 546, 561,
+ 553, 564, 547, 555, 0, 0, 546, 552, 547, 565,
+ 556, 549, 550, 551, 550, 566, 567, 557, 551, 552,
+ 554, 559, 559, 559, 569, 558, 554, 574, 555, 553,
+ 561, 559, 0, 564, 555, 562, 562, 562, 0, 576,
+ 565, 577, 549, 0, 583, 562, 566, 0, 567, 568,
+ 568, 568, 570, 570, 570, 569, 572, 572, 572, 568,
+ 553, 588, 570, 573, 573, 573, 572, 575, 575, 575,
+ 576, 578, 577, 573, 578, 583, 584, 575, 574, 579,
+
+ 579, 579, 580, 580, 580, 581, 581, 581, 589, 579,
+ 590, 0, 580, 588, 591, 581, 594, 0, 585, 585,
+ 585, 0, 601, 578, 602, 578, 575, 584, 585, 587,
+ 587, 587, 600, 592, 592, 592, 603, 0, 579, 587,
+ 589, 580, 590, 592, 581, 591, 606, 594, 595, 595,
+ 595, 597, 597, 597, 601, 599, 602, 575, 595, 609,
+ 615, 597, 599, 600, 604, 604, 604, 610, 603, 579,
+ 611, 616, 580, 619, 604, 581, 612, 606, 607, 607,
+ 607, 620, 621, 612, 617, 617, 617, 599, 607, 611,
+ 622, 609, 615, 599, 617, 623, 0, 624, 610, 626,
+
+ 627, 611, 628, 616, 619, 625, 625, 625, 612, 634,
+ 0, 635, 620, 621, 612, 625, 629, 0, 637, 629,
+ 637, 622, 638, 639, 632, 632, 632, 623, 624, 640,
+ 626, 641, 627, 628, 632, 642, 643, 647, 641, 644,
+ 648, 634, 635, 645, 652, 645, 0, 0, 629, 637,
+ 629, 637, 649, 638, 653, 639, 0, 654, 654, 655,
+ 640, 649, 656, 641, 661, 658, 642, 643, 647, 641,
+ 664, 644, 648, 0, 645, 652, 645, 646, 646, 646,
+ 650, 650, 650, 649, 0, 653, 657, 646, 654, 654,
+ 650, 655, 649, 660, 656, 661, 657, 658, 662, 664,
+
+ 660, 0, 0, 0, 662, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 657, 0,
+ 0, 0, 0, 0, 0, 660, 0, 657, 0, 662,
+ 664, 660, 0, 0, 0, 662, 667, 667, 667, 667,
+ 667, 667, 667, 667, 667, 667, 667, 667, 667, 667,
+ 667, 667, 667, 667, 667, 667, 667, 667, 667, 667,
+ 667, 667, 667, 667, 667, 667, 668, 668, 668, 668,
+ 668, 668, 668, 668, 668, 668, 668, 668, 668, 668,
+ 668, 668, 668, 668, 668, 668, 668, 668, 668, 668,
+ 668, 668, 668, 668, 668, 668, 669, 669, 669, 669,
+
+ 669, 669, 669, 669, 669, 669, 669, 669, 669, 669,
+ 669, 669, 669, 669, 669, 669, 669, 669, 669, 669,
+ 669, 669, 669, 669, 669, 669, 670, 670, 670, 670,
+ 670, 670, 670, 670, 670, 670, 670, 670, 670, 670,
+ 670, 670, 670, 670, 670, 670, 670, 670, 670, 670,
+ 670, 670, 670, 670, 670, 670, 671, 0, 0, 0,
+ 671, 671, 671, 671, 671, 671, 671, 671, 671, 671,
+ 671, 671, 671, 671, 671, 671, 671, 671, 671, 671,
+ 671, 671, 671, 671, 671, 671, 672, 672, 672, 672,
+ 672, 672, 672, 672, 672, 672, 672, 672, 672, 672,
+
+ 672, 672, 672, 672, 672, 672, 672, 672, 672, 672,
+ 672, 672, 672, 672, 672, 672, 673, 673, 673, 673,
+ 673, 673, 673, 674, 674, 0, 674, 674, 674, 674,
+ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674,
+ 674, 674, 674, 674, 674, 674, 674, 674, 674, 674,
+ 674, 674, 674, 675, 675, 675, 675, 675, 675, 675,
+ 675, 675, 675, 675, 675, 675, 675, 675, 675, 675,
+ 675, 675, 675, 675, 675, 675, 675, 675, 675, 675,
+ 675, 675, 675, 676, 676, 676, 0, 0, 676, 676,
+ 0, 676, 0, 0, 0, 676, 676, 676, 676, 676,
+
+ 676, 676, 676, 677, 677, 0, 0, 0, 0, 0,
+ 677, 677, 677, 677, 677, 677, 677, 678, 0, 678,
+ 0, 0, 0, 0, 678, 678, 0, 678, 0, 0,
+ 0, 0, 678, 0, 0, 0, 0, 678, 678, 678,
+ 678, 678, 678, 678, 679, 0, 679, 0, 679, 0,
+ 679, 0, 0, 0, 0, 0, 0, 679, 679, 679,
+ 679, 679, 679, 679, 680, 0, 0, 680, 680, 0,
+ 680, 680, 680, 0, 0, 0, 0, 680, 680, 680,
+ 680, 680, 680, 680, 681, 681, 0, 681, 681, 681,
+ 681, 681, 681, 681, 681, 681, 681, 681, 681, 681,
+
+ 681, 681, 681, 681, 681, 681, 681, 681, 681, 681,
+ 681, 681, 681, 681, 682, 0, 0, 0, 0, 682,
+ 0, 0, 682, 682, 0, 0, 0, 0, 0, 682,
+ 682, 682, 682, 682, 682, 682, 683, 683, 683, 683,
+ 683, 0, 683, 683, 0, 683, 0, 0, 0, 683,
+ 683, 683, 683, 683, 683, 683, 683, 684, 684, 684,
+ 684, 684, 684, 684, 684, 684, 684, 684, 684, 684,
+ 684, 684, 684, 684, 684, 684, 684, 684, 684, 684,
+ 684, 684, 684, 684, 684, 684, 684, 685, 685, 685,
+ 685, 685, 685, 685, 685, 685, 685, 685, 685, 685,
+
+ 685, 685, 685, 685, 685, 685, 685, 685, 685, 685,
+ 685, 685, 685, 685, 685, 685, 685, 686, 0, 686,
+ 686, 0, 0, 0, 0, 0, 686, 686, 686, 686,
+ 686, 686, 686, 686, 687, 687, 687, 687, 687, 687,
+ 687, 687, 687, 687, 687, 687, 687, 687, 687, 687,
+ 687, 687, 687, 687, 687, 687, 687, 687, 687, 687,
+ 687, 687, 687, 687, 688, 688, 688, 688, 688, 688,
+ 688, 688, 0, 688, 688, 688, 688, 688, 688, 688,
+ 688, 688, 688, 688, 688, 688, 688, 688, 688, 688,
+ 688, 688, 688, 688, 689, 0, 0, 0, 689, 689,
+
+ 689, 689, 689, 689, 689, 689, 689, 689, 689, 689,
+ 689, 689, 689, 689, 689, 689, 689, 689, 689, 689,
+ 689, 689, 689, 689, 690, 690, 0, 690, 690, 0,
+ 0, 0, 0, 0, 690, 690, 690, 690, 690, 690,
+ 690, 690, 691, 691, 691, 691, 691, 691, 0, 691,
+ 691, 691, 691, 691, 691, 691, 691, 691, 691, 691,
+ 691, 691, 691, 691, 691, 691, 691, 691, 691, 691,
+ 691, 691, 692, 692, 692, 692, 692, 692, 692, 692,
+ 692, 692, 692, 692, 692, 692, 692, 692, 692, 692,
+ 692, 692, 692, 692, 692, 692, 692, 692, 692, 692,
+
+ 692, 692, 693, 693, 693, 693, 693, 693, 693, 693,
+ 693, 693, 693, 693, 693, 693, 693, 693, 693, 693,
+ 693, 693, 693, 693, 693, 693, 693, 693, 693, 693,
+ 693, 693, 694, 0, 694, 0, 0, 0, 0, 694,
+ 694, 694, 694, 694, 0, 0, 0, 0, 694, 694,
+ 694, 694, 694, 694, 694, 694, 694, 695, 695, 695,
+ 695, 695, 695, 695, 695, 695, 695, 695, 695, 695,
+ 695, 695, 695, 695, 695, 695, 695, 695, 695, 695,
+ 695, 695, 695, 695, 695, 695, 695, 696, 696, 0,
+ 0, 0, 0, 0, 696, 696, 696, 696, 696, 696,
+
+ 696, 696, 697, 697, 697, 697, 697, 697, 697, 697,
+ 697, 697, 697, 697, 697, 697, 697, 697, 697, 697,
+ 697, 697, 697, 697, 697, 697, 697, 697, 697, 697,
+ 697, 697, 698, 698, 698, 698, 698, 698, 698, 698,
+ 698, 698, 698, 698, 698, 698, 698, 698, 698, 698,
+ 698, 698, 698, 698, 698, 698, 698, 698, 698, 698,
+ 698, 698, 699, 699, 699, 699, 699, 699, 699, 699,
+ 699, 699, 699, 699, 699, 699, 699, 699, 699, 699,
+ 699, 699, 699, 699, 699, 699, 699, 699, 699, 699,
+ 699, 699, 700, 700, 0, 700, 700, 700, 700, 700,
+
+ 700, 700, 700, 700, 700, 700, 700, 700, 700, 700,
+ 700, 700, 700, 700, 700, 700, 700, 700, 700, 700,
+ 700, 700, 701, 701, 701, 701, 701, 701, 701, 701,
+ 701, 701, 701, 701, 701, 701, 701, 701, 701, 701,
+ 701, 701, 701, 701, 701, 701, 701, 701, 701, 701,
+ 701, 701, 702, 702, 0, 702, 702, 702, 702, 702,
+ 702, 702, 702, 702, 702, 702, 702, 702, 702, 702,
+ 702, 702, 702, 702, 702, 702, 702, 702, 702, 702,
+ 702, 702, 703, 703, 703, 0, 0, 703, 703, 0,
+ 703, 0, 0, 0, 703, 703, 703, 703, 703, 703,
+
+ 703, 703, 704, 704, 704, 0, 0, 0, 0, 704,
+ 704, 704, 704, 704, 704, 704, 705, 0, 705, 0,
+ 0, 0, 0, 705, 705, 0, 705, 0, 0, 0,
+ 0, 705, 0, 0, 0, 0, 705, 705, 705, 705,
+ 705, 705, 705, 706, 0, 706, 0, 706, 0, 706,
+ 0, 0, 0, 0, 0, 0, 706, 706, 706, 706,
+ 706, 706, 706, 707, 707, 0, 707, 707, 707, 0,
+ 0, 0, 0, 707, 707, 707, 707, 707, 707, 707,
+ 708, 0, 0, 0, 0, 708, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 708, 708, 708, 708, 708,
+
+ 708, 708, 709, 0, 0, 0, 709, 0, 709, 0,
+ 709, 0, 709, 0, 0, 709, 709, 0, 0, 709,
+ 709, 709, 709, 709, 709, 709, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 711, 0, 0, 0,
+ 0, 0, 0, 711, 711, 0, 0, 711, 711, 711,
+ 0, 0, 0, 0, 711, 711, 711, 711, 711, 711,
+ 711, 712, 0, 0, 0, 712, 712, 712, 712, 712,
+ 0, 712, 712, 0, 712, 712, 0, 0, 712, 712,
+
+ 712, 712, 712, 712, 712, 712, 713, 713, 713, 713,
+ 713, 0, 713, 713, 0, 713, 0, 0, 0, 713,
+ 713, 713, 713, 713, 713, 713, 713, 714, 714, 714,
+ 714, 714, 714, 714, 714, 714, 714, 714, 714, 714,
+ 714, 714, 714, 714, 714, 714, 714, 714, 714, 714,
+ 714, 714, 714, 714, 714, 714, 714, 715, 0, 715,
+ 0, 0, 0, 0, 0, 0, 715, 0, 0, 0,
+ 0, 715, 0, 715, 715, 0, 0, 715, 715, 716,
+ 716, 716, 716, 716, 716, 716, 716, 716, 716, 716,
+ 716, 716, 716, 716, 716, 716, 716, 716, 716, 716,
+
+ 716, 716, 716, 716, 716, 716, 716, 716, 716, 717,
+ 0, 717, 717, 0, 0, 0, 0, 0, 717, 717,
+ 717, 717, 717, 717, 717, 717, 718, 718, 718, 718,
+ 718, 718, 718, 718, 718, 718, 718, 718, 718, 718,
+ 718, 718, 718, 718, 718, 718, 718, 718, 718, 718,
+ 718, 718, 718, 718, 718, 718, 719, 0, 0, 0,
+ 0, 0, 0, 719, 0, 0, 0, 0, 719, 0,
+ 719, 719, 0, 0, 719, 719, 0, 0, 719, 720,
+ 720, 720, 720, 720, 720, 720, 720, 0, 720, 720,
+ 720, 720, 720, 720, 720, 720, 720, 720, 720, 720,
+
+ 720, 720, 720, 720, 720, 720, 720, 720, 720, 721,
+ 0, 0, 0, 721, 721, 721, 721, 721, 721, 721,
+ 721, 721, 721, 721, 721, 721, 721, 721, 721, 721,
+ 721, 721, 721, 721, 721, 721, 721, 721, 721, 722,
+ 722, 0, 722, 722, 0, 0, 0, 0, 0, 722,
+ 722, 722, 722, 722, 722, 722, 722, 723, 723, 723,
+ 723, 723, 723, 0, 723, 723, 723, 723, 723, 723,
+ 723, 723, 723, 723, 723, 723, 723, 723, 723, 723,
+ 723, 723, 723, 723, 723, 723, 723, 724, 724, 724,
+ 0, 0, 0, 0, 0, 0, 724, 0, 0, 0,
+
+ 0, 0, 0, 0, 724, 0, 0, 724, 0, 724,
+ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
+ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
+ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
+ 726, 726, 726, 0, 0, 0, 0, 0, 0, 726,
+ 0, 0, 0, 0, 0, 0, 0, 726, 0, 0,
+ 726, 0, 726, 727, 727, 727, 727, 727, 727, 727,
+ 727, 727, 727, 727, 727, 727, 727, 727, 727, 727,
+ 727, 727, 727, 727, 727, 727, 727, 727, 727, 727,
+ 727, 727, 727, 728, 728, 728, 728, 728, 728, 728,
+
+ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728,
+ 728, 728, 728, 728, 728, 728, 728, 728, 728, 728,
+ 728, 728, 728, 729, 729, 729, 0, 0, 0, 0,
+ 0, 0, 729, 0, 0, 0, 0, 0, 0, 0,
+ 729, 0, 0, 729, 0, 729, 730, 0, 0, 0,
+ 0, 0, 0, 730, 730, 0, 730, 730, 0, 0,
+ 0, 0, 730, 730, 730, 730, 730, 730, 730, 730,
+ 730, 731, 0, 0, 0, 0, 0, 0, 731, 731,
+ 0, 731, 731, 0, 0, 0, 0, 731, 731, 731,
+ 731, 731, 731, 731, 731, 731, 732, 732, 732, 732,
+
+ 732, 732, 732, 732, 732, 732, 732, 732, 732, 732,
+ 732, 732, 732, 732, 732, 732, 732, 732, 732, 732,
+ 732, 732, 732, 732, 732, 732, 733, 733, 733, 0,
+ 0, 0, 0, 0, 0, 733, 0, 0, 0, 0,
+ 0, 0, 0, 733, 0, 0, 733, 0, 733, 734,
+ 734, 0, 0, 0, 0, 0, 734, 734, 734, 735,
+ 735, 0, 0, 0, 0, 0, 735, 735, 735, 735,
+ 735, 735, 735, 735, 736, 736, 736, 736, 736, 736,
+ 736, 736, 736, 736, 736, 736, 736, 736, 736, 736,
+ 736, 736, 736, 736, 736, 736, 736, 736, 736, 736,
+
+ 736, 736, 736, 736, 737, 0, 737, 0, 0, 0,
+ 0, 0, 0, 737, 0, 0, 0, 0, 0, 0,
+ 0, 737, 0, 0, 737, 0, 737, 0, 737, 738,
+ 738, 738, 738, 738, 738, 738, 738, 738, 738, 738,
+ 738, 738, 738, 738, 738, 738, 738, 738, 738, 738,
+ 738, 738, 738, 738, 738, 738, 738, 738, 738, 739,
+ 739, 739, 739, 739, 739, 739, 739, 739, 739, 739,
+ 739, 739, 739, 739, 739, 739, 739, 739, 739, 739,
+ 739, 739, 739, 739, 739, 739, 739, 739, 739, 740,
+ 740, 740, 740, 740, 740, 740, 740, 740, 740, 740,
+
+ 740, 740, 740, 740, 740, 740, 740, 740, 740, 740,
+ 740, 740, 740, 740, 740, 740, 740, 740, 740, 741,
+ 741, 741, 741, 741, 741, 741, 741, 741, 741, 741,
+ 741, 741, 741, 741, 741, 741, 741, 741, 741, 741,
+ 741, 741, 741, 741, 741, 741, 741, 741, 741, 742,
+ 742, 0, 742, 742, 742, 742, 742, 742, 742, 742,
+ 742, 742, 742, 742, 742, 742, 742, 742, 742, 742,
+ 742, 742, 742, 742, 742, 742, 742, 742, 742, 743,
+ 743, 0, 743, 743, 743, 743, 743, 743, 743, 743,
+ 743, 743, 743, 743, 743, 743, 743, 743, 743, 743,
+
+ 743, 743, 743, 743, 743, 743, 743, 743, 743, 744,
+ 744, 0, 744, 744, 744, 744, 744, 744, 744, 744,
+ 744, 744, 744, 744, 744, 744, 744, 744, 744, 744,
+ 744, 744, 744, 744, 744, 744, 744, 744, 744, 745,
+ 745, 0, 745, 745, 745, 745, 745, 745, 745, 745,
+ 745, 745, 745, 745, 745, 745, 745, 745, 745, 745,
+ 745, 745, 745, 745, 745, 745, 745, 745, 745, 746,
+ 746, 746, 0, 0, 746, 746, 0, 746, 0, 0,
+ 0, 746, 746, 746, 746, 746, 746, 746, 746, 747,
+ 0, 0, 0, 747, 0, 747, 0, 747, 0, 747,
+
+ 0, 0, 747, 747, 0, 0, 747, 747, 747, 747,
+ 747, 747, 747, 748, 748, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 748, 748, 748, 748, 748, 748, 748, 749, 0,
+ 0, 0, 749, 749, 749, 749, 749, 0, 749, 749,
+ 0, 749, 749, 0, 0, 749, 749, 749, 749, 749,
+ 749, 749, 749, 750, 750, 750, 750, 750, 0, 750,
+ 750, 0, 750, 0, 0, 0, 750, 750, 750, 750,
+ 750, 750, 750, 750, 751, 751, 751, 751, 751, 751,
+ 751, 751, 751, 751, 751, 751, 751, 751, 751, 751,
+
+ 751, 751, 751, 751, 751, 751, 751, 751, 751, 751,
+ 751, 751, 751, 751, 752, 752, 752, 752, 752, 752,
+ 752, 752, 752, 752, 752, 752, 752, 752, 752, 752,
+ 752, 752, 752, 752, 752, 752, 752, 752, 752, 752,
+ 752, 752, 752, 752, 753, 753, 0, 0, 0, 0,
+ 0, 753, 753, 753, 754, 754, 0, 0, 0, 0,
+ 0, 754, 754, 754, 755, 755, 755, 0, 0, 0,
+ 0, 0, 0, 755, 0, 0, 0, 0, 0, 0,
+ 0, 755, 0, 0, 755, 0, 755, 756, 756, 0,
+ 0, 0, 0, 0, 756, 756, 756, 757, 757, 0,
+
+ 0, 0, 0, 0, 757, 757, 757, 758, 758, 0,
+ 0, 0, 0, 0, 758, 758, 758, 759, 759, 0,
+ 0, 0, 0, 0, 759, 759, 759, 759, 759, 759,
+ 759, 759, 760, 760, 0, 0, 0, 0, 0, 760,
+ 760, 760, 761, 761, 761, 761, 761, 761, 761, 761,
+ 761, 761, 761, 761, 761, 761, 761, 761, 761, 761,
+ 761, 761, 761, 761, 761, 761, 761, 761, 761, 761,
+ 761, 761, 762, 762, 762, 762, 762, 762, 762, 762,
+ 762, 762, 762, 762, 762, 762, 762, 762, 762, 762,
+ 762, 762, 762, 762, 762, 762, 762, 762, 762, 762,
+
+ 762, 762, 763, 763, 0, 763, 763, 763, 763, 763,
+ 763, 763, 763, 763, 763, 763, 763, 763, 763, 763,
+ 763, 763, 763, 763, 763, 763, 763, 763, 763, 763,
+ 763, 763, 764, 764, 0, 764, 764, 764, 764, 764,
+ 764, 764, 764, 764, 764, 764, 764, 764, 764, 764,
+ 764, 764, 764, 764, 764, 764, 764, 764, 764, 764,
+ 764, 764, 765, 765, 0, 0, 0, 0, 0, 765,
+ 765, 765, 766, 766, 0, 0, 0, 0, 0, 766,
+ 766, 766, 767, 767, 0, 0, 0, 0, 0, 767,
+ 767, 767, 768, 768, 0, 0, 0, 0, 0, 768,
+
+ 768, 768, 769, 769, 0, 0, 0, 0, 0, 769,
+ 769, 769, 770, 770, 0, 0, 0, 0, 0, 770,
+ 770, 770, 771, 771, 0, 0, 0, 0, 0, 771,
+ 771, 771, 772, 772, 772, 772, 772, 772, 772, 772,
+ 772, 772, 772, 772, 772, 772, 772, 772, 772, 772,
+ 772, 772, 772, 772, 772, 772, 772, 772, 772, 772,
+ 772, 772, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666, 666, 666, 666, 666, 666, 666, 666, 666, 666,
+ 666
+ } ;
+
+/* Table of booleans, true if rule could match eol. */
+static const flex_int32_t yy_rule_can_match_eol[122] =
+ { 0,
+0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
+ 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1,
+ 0, 0, };
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int yy_flex_debug;
+int yy_flex_debug = 0;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "lexer.l"
+#line 2 "lexer.l"
+ /* Lex file for rsyslog config format v2 (RainerScript).
+ * Please note: this file introduces the new config format, but maintains
+ * backward compatibility. In order to do so, the grammar is not 100% clean,
+ * but IMHO still sufficiently easy both to understand for programmers
+ * maitaining the code as well as users writing the config file. Users are,
+ * of course, encouraged to use new constructs only. But it needs to be noted
+ * that some of the legacy constructs (specifically the in-front-of-action
+ * PRI filter) are very hard to beat in ease of use, at least for simpler
+ * cases. So while we hope that cfsysline support can be dropped some time in
+ * the future, we will probably keep these useful constructs.
+ *
+ * Copyright 2011-2014 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * -or-
+ * see COPYING.ASL20 in the source distribution
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <libestr.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "rsyslog.h"
+#include "srUtils.h"
+#include "parserif.h"
+
+PRAGMA_IGNORE_Wsign_compare
+PRAGMA_IGNORE_Wmissing_noreturn
+
+FILE *fp_rs_full_conf_output = NULL;
+
+/* TODO: move this to a better modules, refactor -- rgerhards, 2018-01-22 */
+static char *
+read_file(const char *const filename)
+{
+ char *content = NULL;
+ int fd = -1;
+ struct stat sb;
+ ssize_t nread;
+ assert(filename != NULL);
+
+ if((fd = open((const char*) filename, O_RDONLY)) == -1) {
+ goto done;
+ }
+
+ if(fstat(fd, &sb) == -1) {
+ goto done;
+ }
+
+ content = malloc(sb.st_size+1);
+ if(content == NULL) {
+ goto done;
+ }
+
+ nread = read(fd, content, sb.st_size);
+ content[nread] = '\0';
+ if(nread != (ssize_t) sb.st_size) {
+ free(content);
+ content = NULL;
+ goto done;
+ }
+
+done:
+ if(fd != -1) {
+ close(fd);
+ }
+ return content;
+}
+
+static es_str_t* ATTR_NONNULL(1)
+expand_backticks_echo(const char *param)
+{
+ assert(param != NULL);
+ assert(strncmp(param, "echo ", sizeof("echo ")-1) == 0);
+ char envvar[512];
+ int i_envvar = 0;
+ int in_env = 0;
+ es_str_t *estr;
+
+ param += sizeof("echo ")-1;
+ if((estr = es_newStr(strlen(param))) == NULL) {
+ goto done;
+ }
+
+ while(*param) {
+ if(in_env) {
+ if(isspace(*param) || *param == '/') {
+ envvar[i_envvar] = '\0';
+ const char *envval = getenv(envvar);
+ if(envval != NULL)
+ es_addBuf(&estr, envval, strlen(envval));
+ es_addChar(&estr, *param); /* curr char part of output! */
+ i_envvar = 0;
+ in_env = 0;
+ } else if(i_envvar > sizeof(envvar) - 1) {
+ parser_errmsg("environment variable too long, begins with %s", envvar);
+ goto done;
+ } else {
+ envvar[i_envvar++] = *param;
+ }
+ } else if (*param == '$') {
+ in_env = 1;
+ } else {
+ es_addChar(&estr, *param);
+ }
+ ++param;
+ }
+
+ /* final check, we may be in env var name (very probable!) */
+ if(in_env) {
+ envvar[i_envvar] = '\0';
+ const char *envval = getenv(envvar);
+ if(envval != NULL)
+ es_addBuf(&estr, envval, strlen(envval));
+ }
+
+done: return estr;
+}
+
+
+static es_str_t* ATTR_NONNULL(1)
+expand_backticks(char *const param)
+{
+ es_str_t *estr;
+ assert(param != NULL);
+
+ if(strncmp(param, "echo ", sizeof("echo ")-1) == 0) {
+ estr = expand_backticks_echo(param);
+ } else if(strncmp(param, "cat ", sizeof("cat ")-1) == 0) {
+ const char *val = read_file(param+4);
+ if(val == NULL) {
+ parser_errmsg("file could not be accessed for `%s`", param);
+ const char *errmsg = "/* file cound not be accessed - see"
+ "error messages */";
+ estr = es_newStrFromCStr(errmsg, strlen(errmsg));
+ } else {
+ estr = es_newStrFromCStr(val, strlen(val));
+ }
+ free((void*) val);
+ } else {
+ parser_errmsg("invalid backtick parameter `%s` - replaced by "
+ "empty string (\"\")", param);
+ estr = es_newStr(1);
+ }
+
+ return estr;
+}
+#line 1974 "lexer.c"
+#line 172 "lexer.l"
+ /*%option noyywrap nodefault case-insensitive */
+/* avoid compiler warning: `yyunput' defined but not used */
+#define YY_NO_INPUT 1
+
+ /* INOBJ is selected if we are inside an object (name/value pairs!) */
+
+ /* COMMENT is "the usual trick" to handle C-style comments */
+
+ /* INCL is in $IncludeConfig processing (skip to include file) */
+
+ /* LINENO: support for setting the linenumber */
+
+ /* INCALL: support for the call statement */
+
+ /* IN_PROCEDURE_CALL: support for the call statement */
+
+ /* EXPR is a bit ugly, but we need it to support pre v6-syntax. The problem
+ * is that cfsysline statement start with $..., the same like variables in
+ * an expression. However, cfsysline statements can never appear inside an
+ * expression. So we create a specific expr mode, which is turned on after
+ * we lexed a keyword that needs to be followed by an expression (using
+ * knowledge from the upper layer...). In expr mode, we strictly do
+ * expression-based parsing. Expr mode is stopped when we reach a token
+ * that can not be part of an expression (currently only "then"). As I
+ * wrote this ugly, but the price needed to pay in order to remain
+ * compatible to the previous format.
+ */
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <libestr.h>
+#include "rainerscript.h"
+#include "parserif.h"
+#include "grammar.h"
+static int preCommentState; /* save for lex state before a comment */
+
+struct bufstack {
+ struct bufstack *prev;
+ YY_BUFFER_STATE bs;
+ int lineno;
+ char *fn;
+ es_str_t *estr;
+} *currbs = NULL;
+
+char *cnfcurrfn; /* name of currently processed file */
+
+int popfile(void);
+int cnfSetLexFile(const char *fname);
+
+static void cnfPrintToken(const char *token);
+extern int yydebug;
+
+/* somehow, I need these prototype even though the headers are
+ * included. I guess that's some autotools magic I don't understand...
+ */
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) \
+ && !defined(__DragonflyBSD__) && !defined(_AIX)
+int fileno(FILE *stream);
+#endif
+
+
+#line 2039 "lexer.c"
+#line 2040 "lexer.c"
+
+#define INITIAL 0
+#define INOBJ 1
+#define COMMENT 2
+#define INCL 3
+#define LINENO 4
+#define INCALL 5
+#define IN_PROCEDURE_CALL 6
+#define EXPR 7
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+static int yy_init_globals ( void );
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int yylex_destroy ( void );
+
+int yyget_debug ( void );
+
+void yyset_debug ( int debug_flag );
+
+YY_EXTRA_TYPE yyget_extra ( void );
+
+void yyset_extra ( YY_EXTRA_TYPE user_defined );
+
+FILE *yyget_in ( void );
+
+void yyset_in ( FILE * _in_str );
+
+FILE *yyget_out ( void );
+
+void yyset_out ( FILE * _out_str );
+
+ int yyget_leng ( void );
+
+char *yyget_text ( void );
+
+int yyget_lineno ( void );
+
+void yyset_lineno ( int _line_number );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap ( void );
+#else
+extern int yywrap ( void );
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy ( char *, const char *, int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen ( const char * );
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput ( void );
+#else
+static int input ( void );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ int n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int yylex (void);
+
+#define YY_DECL int yylex (void)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK /*LINTED*/break;
+#endif
+
+#define YY_RULE_SETUP \
+ if ( yyleng > 0 ) \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
+ (yytext[yyleng - 1] == '\n'); \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_load_buffer_state( );
+ }
+
+ {
+#line 240 "lexer.l"
+
+
+#line 243 "lexer.l"
+ /* keywords */
+#line 2270 "lexer.c"
+
+ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of yytext. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+ yy_current_state += YY_AT_BOL();
+yy_match:
+ do
+ {
+ YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 667 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ ++yy_cp;
+ }
+ while ( yy_base[yy_current_state] != 4863 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+ if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
+ {
+ int yyl;
+ for ( yyl = 0; yyl < yyleng; ++yyl )
+ if ( yytext[yyl] == '\n' )
+
+ yylineno++;
+;
+ }
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 244 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return IF; }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 245 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return FOREACH; }
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 246 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN IN_PROCEDURE_CALL; return RELOAD_LOOKUP_TABLE_PROCEDURE; }
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 247 "lexer.l"
+{ cnfPrintToken(yytext); return yytext[0]; }
+ YY_BREAK
+case 5:
+/* rule 5 can match eol */
+YY_RULE_SETUP
+#line 248 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+ YY_BREAK
+case 6:
+/* rule 6 can match eol */
+YY_RULE_SETUP
+#line 253 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 258 "lexer.l"
+{ cnfPrintToken(yytext); return yytext[0]; }
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 259 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INITIAL; return yytext[0]; }
+ YY_BREAK
+case 9:
+/* rule 9 can match eol */
+YY_RULE_SETUP
+#line 260 "lexer.l"
+{cnfPrintToken(yytext); }
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 261 "lexer.l"
+{ cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in expression "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 264 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return yytext[0]; }
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 265 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INITIAL; return THEN; }
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 266 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INITIAL; return DO; }
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 267 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INITIAL; return ';'; }
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 268 "lexer.l"
+{ cnfPrintToken(yytext); return OR; }
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 269 "lexer.l"
+{ cnfPrintToken(yytext); return AND; }
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 270 "lexer.l"
+{ cnfPrintToken(yytext); return NOT; }
+ YY_BREAK
+case 18:
+#line 272 "lexer.l"
+case 19:
+#line 273 "lexer.l"
+case 20:
+#line 274 "lexer.l"
+case 21:
+#line 275 "lexer.l"
+case 22:
+#line 276 "lexer.l"
+case 23:
+#line 277 "lexer.l"
+case 24:
+#line 278 "lexer.l"
+case 25:
+#line 279 "lexer.l"
+case 26:
+#line 280 "lexer.l"
+case 27:
+#line 281 "lexer.l"
+case 28:
+YY_RULE_SETUP
+#line 281 "lexer.l"
+{ cnfPrintToken(yytext); return yytext[0]; }
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 282 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_EQ; }
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 283 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_LE; }
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 284 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_GE; }
+ YY_BREAK
+case 32:
+#line 286 "lexer.l"
+case 33:
+YY_RULE_SETUP
+#line 286 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_NE; }
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 287 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_LT; }
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 288 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_GT; }
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 289 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_CONTAINS; }
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 290 "lexer.l"
+{ cnfPrintToken(yytext); return ITERATOR_ASSIGNMENT; }
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 291 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_CONTAINSI; }
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 292 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_STARTSWITH; }
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 293 "lexer.l"
+{ cnfPrintToken(yytext); return CMP_STARTSWITHI; }
+ YY_BREAK
+case 41:
+#line 295 "lexer.l"
+case 42:
+#line 296 "lexer.l"
+case 43:
+YY_RULE_SETUP
+#line 296 "lexer.l"
+{ cnfPrintToken(yytext); yylval.n = strtoll(yytext, NULL, 0); return NUMBER; }
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 297 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = strdup(yytext+1); return VAR; }
+ YY_BREAK
+case 45:
+/* rule 45 can match eol */
+YY_RULE_SETUP
+#line 298 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+ YY_BREAK
+case 46:
+/* rule 46 can match eol */
+YY_RULE_SETUP
+#line 303 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = expand_backticks(yytext+1);
+ return STRING; }
+ YY_BREAK
+case 47:
+/* rule 47 can match eol */
+YY_RULE_SETUP
+#line 308 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+ YY_BREAK
+case 48:
+/* rule 48 can match eol */
+YY_RULE_SETUP
+#line 313 "lexer.l"
+{
+ cnfPrintToken(yytext); parser_errmsg("$-sign in double quotes must be "
+ "escaped, problem string is: %s",
+ yytext); }
+ YY_BREAK
+case 49:
+/* rule 49 can match eol */
+YY_RULE_SETUP
+#line 317 "lexer.l"
+{ cnfPrintToken(yytext); }
+ YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 318 "lexer.l"
+{ cnfPrintToken(yytext); return EXISTS; } /* special case function (see rainerscript.c) */
+ YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 319 "lexer.l"
+{ cnfPrintToken(yytext); yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ return FUNC; }
+ YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 321 "lexer.l"
+{ cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in expression "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+ YY_BREAK
+case 53:
+/* rule 53 can match eol */
+YY_RULE_SETUP
+#line 324 "lexer.l"
+{ cnfPrintToken(yytext); }
+ YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 325 "lexer.l"
+{ cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in 'call' statement"
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+ YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 328 "lexer.l"
+{ cnfPrintToken(yytext); yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ BEGIN INITIAL;
+ return NAME; }
+ YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 331 "lexer.l"
+{ cnfPrintToken(yytext); return '&'; }
+ YY_BREAK
+case 57:
+YY_RULE_SETUP
+#line 332 "lexer.l"
+{ cnfPrintToken(yytext); return '{'; }
+ YY_BREAK
+case 58:
+YY_RULE_SETUP
+#line 333 "lexer.l"
+{ cnfPrintToken(yytext); return '}'; }
+ YY_BREAK
+case 59:
+YY_RULE_SETUP
+#line 334 "lexer.l"
+{ cnfPrintToken(yytext); return STOP; }
+ YY_BREAK
+case 60:
+YY_RULE_SETUP
+#line 335 "lexer.l"
+{ cnfPrintToken(yytext); return ELSE; }
+ YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 336 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INCALL; return CALL; }
+ YY_BREAK
+case 62:
+YY_RULE_SETUP
+#line 337 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return CALL_INDIRECT; }
+ YY_BREAK
+case 63:
+YY_RULE_SETUP
+#line 338 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return SET; }
+ YY_BREAK
+case 64:
+YY_RULE_SETUP
+#line 339 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return RESET; }
+ YY_BREAK
+case 65:
+YY_RULE_SETUP
+#line 340 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN EXPR; return UNSET; }
+ YY_BREAK
+case 66:
+YY_RULE_SETUP
+#line 341 "lexer.l"
+{ cnfPrintToken(yytext); return CONTINUE; }
+ YY_BREAK
+/* line number support because the "preprocessor" combines lines and so needs
+ * to tell us the real source line.
+ */
+case 67:
+YY_RULE_SETUP
+#line 345 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN LINENO; }
+ YY_BREAK
+case 68:
+YY_RULE_SETUP
+#line 346 "lexer.l"
+{ cnfPrintToken(yytext); yylineno = atoi(yytext) - 1; }
+ YY_BREAK
+case 69:
+YY_RULE_SETUP
+#line 347 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INITIAL; }
+ YY_BREAK
+case 70:
+/* rule 70 can match eol */
+YY_RULE_SETUP
+#line 348 "lexer.l"
+
+ YY_BREAK
+/* $IncludeConfig must be detected as part of CFSYSLINE, because this is
+ * always the longest match :-(
+ */
+case 71:
+/* rule 71 can match eol */
+YY_RULE_SETUP
+#line 352 "lexer.l"
+
+ YY_BREAK
+case 72:
+YY_RULE_SETUP
+#line 353 "lexer.l"
+{ cnfPrintToken(yytext); if(cnfDoInclude(yytext, 0) != 0)
+ yyterminate();
+ BEGIN INITIAL; }
+ YY_BREAK
+case 73:
+/* rule 73 can match eol */
+YY_RULE_SETUP
+#line 356 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_MAINQ;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 74:
+/* rule 74 can match eol */
+YY_RULE_SETUP
+#line 358 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_TIMEZONE;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 75:
+/* rule 75 can match eol */
+YY_RULE_SETUP
+#line 360 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_PARSER;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 76:
+/* rule 76 can match eol */
+YY_RULE_SETUP
+#line 362 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_GLOBAL;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 77:
+/* rule 77 can match eol */
+YY_RULE_SETUP
+#line 364 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_TPL;
+ BEGIN INOBJ; return BEGIN_TPL; }
+ YY_BREAK
+case 78:
+/* rule 78 can match eol */
+YY_RULE_SETUP
+#line 366 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_RULESET;
+ BEGIN INOBJ; return BEGIN_RULESET; }
+ YY_BREAK
+case 79:
+/* rule 79 can match eol */
+YY_RULE_SETUP
+#line 368 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_PROPERTY;
+ BEGIN INOBJ; return BEGIN_PROPERTY; }
+ YY_BREAK
+case 80:
+/* rule 80 can match eol */
+YY_RULE_SETUP
+#line 370 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_CONSTANT;
+ BEGIN INOBJ; return BEGIN_CONSTANT; }
+ YY_BREAK
+case 81:
+/* rule 81 can match eol */
+YY_RULE_SETUP
+#line 372 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_INPUT;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 82:
+/* rule 82 can match eol */
+YY_RULE_SETUP
+#line 374 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_MODULE;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 83:
+/* rule 83 can match eol */
+YY_RULE_SETUP
+#line 376 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_LOOKUP_TABLE;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 84:
+/* rule 84 can match eol */
+YY_RULE_SETUP
+#line 378 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_DYN_STATS;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 85:
+/* rule 85 can match eol */
+YY_RULE_SETUP
+#line 380 "lexer.l"
+{ cnfPrintToken(yytext); yylval.objType = CNFOBJ_PERCTILE_STATS;
+ BEGIN INOBJ; return BEGINOBJ; }
+ YY_BREAK
+case 86:
+/* rule 86 can match eol */
+YY_RULE_SETUP
+#line 382 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INOBJ; return BEGIN_INCLUDE; }
+ YY_BREAK
+case 87:
+/* rule 87 can match eol */
+YY_RULE_SETUP
+#line 383 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INOBJ; return BEGIN_ACTION; }
+ YY_BREAK
+case 88:
+/* rule 88 can match eol */
+YY_RULE_SETUP
+#line 384 "lexer.l"
+{
+ cnfPrintToken(yytext); yylval.s = strdup(rmLeadingSpace(yytext));
+ dbgprintf("lexer: propfilt is '%s'\n", yylval.s);
+ return PROPFILT;
+ }
+ YY_BREAK
+case 89:
+YY_RULE_SETUP
+#line 389 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = strdup(rmLeadingSpace(yytext)); return PRIFILT; }
+ YY_BREAK
+case 90:
+#line 391 "lexer.l"
+case 91:
+#line 392 "lexer.l"
+case 92:
+/* rule 92 can match eol */
+#line 393 "lexer.l"
+case 93:
+/* rule 93 can match eol */
+#line 394 "lexer.l"
+case 94:
+/* rule 94 can match eol */
+#line 395 "lexer.l"
+case 95:
+/* rule 95 can match eol */
+#line 396 "lexer.l"
+case 96:
+/* rule 96 can match eol */
+YY_RULE_SETUP
+#line 396 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = yytext; return LEGACY_ACTION; }
+ YY_BREAK
+case 97:
+YY_RULE_SETUP
+#line 397 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN INITIAL; return ENDOBJ; }
+ YY_BREAK
+case 98:
+YY_RULE_SETUP
+#line 398 "lexer.l"
+{ cnfPrintToken(yytext); yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ return NAME; }
+ YY_BREAK
+case 99:
+#line 401 "lexer.l"
+case 100:
+#line 402 "lexer.l"
+case 101:
+#line 403 "lexer.l"
+case 102:
+YY_RULE_SETUP
+#line 403 "lexer.l"
+{ cnfPrintToken(yytext); return(yytext[0]); }
+ YY_BREAK
+case 103:
+/* rule 103 can match eol */
+YY_RULE_SETUP
+#line 404 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+ YY_BREAK
+case 104:
+/* rule 104 can match eol */
+YY_RULE_SETUP
+#line 409 "lexer.l"
+{
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = expand_backticks(yytext+1);
+ return STRING; }
+ YY_BREAK
+/*yylval.estr = es_newStrFromBuf(yytext+1, yyleng-2);
+ return VALUE; }*/
+case 105:
+YY_RULE_SETUP
+#line 416 "lexer.l"
+{ cnfPrintToken(yytext); preCommentState = YY_START; BEGIN COMMENT; }
+ YY_BREAK
+case 106:
+YY_RULE_SETUP
+#line 417 "lexer.l"
+{ cnfPrintToken(yytext); preCommentState = YY_START; BEGIN COMMENT; }
+ YY_BREAK
+case 107:
+YY_RULE_SETUP
+#line 418 "lexer.l"
+{ cnfPrintToken(yytext); preCommentState = YY_START; BEGIN COMMENT; }
+ YY_BREAK
+case 108:
+YY_RULE_SETUP
+#line 419 "lexer.l"
+{ cnfPrintToken(yytext); BEGIN preCommentState; }
+ YY_BREAK
+case 109:
+/* rule 109 can match eol */
+YY_RULE_SETUP
+#line 420 "lexer.l"
+
+ YY_BREAK
+case 110:
+*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
+(yy_c_buf_p) = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 421 "lexer.l"
+/* skip comments in input */
+ YY_BREAK
+case 111:
+/* rule 111 can match eol */
+YY_RULE_SETUP
+#line 422 "lexer.l"
+{ cnfPrintToken(yytext); }
+ YY_BREAK
+case 112:
+YY_RULE_SETUP
+#line 423 "lexer.l"
+{ cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in object definition "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+ YY_BREAK
+case 113:
+*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
+(yy_c_buf_p) = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 426 "lexer.l"
+{ cnfPrintToken(yytext); /* see comment on $IncludeConfig above */
+ if(!strncasecmp(yytext, "$includeconfig ", 14)) {
+ yyless((yy_size_t)14);
+ BEGIN INCL;
+ } else if(!strncasecmp(yytext, "$ruleset ", 9)) {
+ yylval.s = strdup(yytext);
+ return LEGACY_RULESET;
+ } else {
+ cnfDoCfsysline(strdup(yytext));
+ }
+ }
+ YY_BREAK
+case 114:
+*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
+(yy_c_buf_p) = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 437 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_TAG_SELECTOR; }
+ YY_BREAK
+case 115:
+/* rule 115 can match eol */
+*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
+YY_LINENO_REWIND_TO(yy_cp - 1);
+(yy_c_buf_p) = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 438 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_HOST_SELECTOR; }
+ YY_BREAK
+case 116:
+/* rule 116 can match eol */
+*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
+YY_LINENO_REWIND_TO(yy_cp - 1);
+(yy_c_buf_p) = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 439 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_HOST_SELECTOR; }
+ YY_BREAK
+case 117:
+*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */
+(yy_c_buf_p) = yy_cp -= 1;
+YY_DO_BEFORE_ACTION; /* set up yytext again */
+YY_RULE_SETUP
+#line 440 "lexer.l"
+{ cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_HOST_SELECTOR; }
+ YY_BREAK
+case 118:
+/* rule 118 can match eol */
+YY_RULE_SETUP
+#line 441 "lexer.l"
+{cnfPrintToken(yytext); }/* skip comments in input */
+ YY_BREAK
+case 119:
+/* rule 119 can match eol */
+YY_RULE_SETUP
+#line 442 "lexer.l"
+{cnfPrintToken(yytext); }/* drop whitespace */
+ YY_BREAK
+case 120:
+YY_RULE_SETUP
+#line 443 "lexer.l"
+{ cnfPrintToken(yytext); parser_errmsg("invalid character '%s' "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(INOBJ):
+case YY_STATE_EOF(COMMENT):
+case YY_STATE_EOF(INCL):
+case YY_STATE_EOF(LINENO):
+case YY_STATE_EOF(INCALL):
+case YY_STATE_EOF(IN_PROCEDURE_CALL):
+case YY_STATE_EOF(EXPR):
+#line 446 "lexer.l"
+{ if(popfile() != 0) yyterminate(); }
+ YY_BREAK
+case 121:
+YY_RULE_SETUP
+#line 448 "lexer.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 3030 "lexer.c"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_c_buf_p);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( yywrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of user's declarations */
+} /* end of yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (void)
+{
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = (yytext_ptr);
+ int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ int num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = NULL;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart( yyin );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (void)
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+
+ yy_current_state = (yy_start);
+ yy_current_state += YY_AT_BOL();
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 667 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+{
+ int yy_is_jam;
+ char *yy_cp = (yy_c_buf_p);
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 667 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ yy_is_jam = (yy_current_state == 666);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_UNPUT
+
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ yyrestart( yyin );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( yywrap( ) )
+ return 0;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve yytext */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n');
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )
+
+ yylineno++;
+;
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void yyrestart (FILE * input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ yyensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ yy_create_buffer( yyin, YY_BUF_SIZE );
+ }
+
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file );
+ yy_load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
+ */
+ yyensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ yy_load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+static void yy_load_buffer_state (void)
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer( b, file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with yy_create_buffer()
+ *
+ */
+ void yy_delete_buffer (YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ yyfree( (void *) b->yy_ch_buf );
+
+ yyfree( (void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a yyrestart() or at EOF.
+ */
+ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
+
+{
+ int oerrno = errno;
+
+ yy_flush_buffer( b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void yy_flush_buffer (YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ yy_load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
+{
+ if (new_buffer == NULL)
+ return;
+
+ yyensure_buffer_stack();
+
+ /* This block is copied from yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void yypop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ yy_delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ yy_load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void yyensure_buffer_stack (void)
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
+ (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ yy_size_t grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return NULL;
+
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+ b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = NULL;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer( b );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ *
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE yy_scan_string (const char * yystr )
+{
+
+ return yy_scan_bytes( yystr, (int) strlen(yystr) );
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer( buf, n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yynoreturn yy_fatal_error (const char* msg )
+{
+ fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = (yy_hold_char); \
+ (yy_c_buf_p) = yytext + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the current line number.
+ *
+ */
+int yyget_lineno (void)
+{
+
+ return yylineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *yyget_in (void)
+{
+ return yyin;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *yyget_out (void)
+{
+ return yyout;
+}
+
+/** Get the length of the current token.
+ *
+ */
+int yyget_leng (void)
+{
+ return yyleng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *yyget_text (void)
+{
+ return yytext;
+}
+
+/** Set the current line number.
+ * @param _line_number line number
+ *
+ */
+void yyset_lineno (int _line_number )
+{
+
+ yylineno = _line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param _in_str A readable stream.
+ *
+ * @see yy_switch_to_buffer
+ */
+void yyset_in (FILE * _in_str )
+{
+ yyin = _in_str ;
+}
+
+void yyset_out (FILE * _out_str )
+{
+ yyout = _out_str ;
+}
+
+int yyget_debug (void)
+{
+ return yy_flex_debug;
+}
+
+void yyset_debug (int _bdebug )
+{
+ yy_flex_debug = _bdebug ;
+}
+
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from yylex_destroy(), so don't allocate here.
+ */
+
+ /* We do not touch yylineno unless the option is enabled. */
+ yylineno = 1;
+
+ (yy_buffer_stack) = NULL;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = NULL;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = NULL;
+ yyout = NULL;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * yylex_init()
+ */
+ return 0;
+}
+
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int yylex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ yy_delete_buffer( YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ yypop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ yyfree((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * yylex() is called, initialization will occur. */
+ yy_init_globals( );
+
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, const char * s2, int n )
+{
+
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (const char * s )
+{
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *yyalloc (yy_size_t size )
+{
+ return malloc(size);
+}
+
+void *yyrealloc (void * ptr, yy_size_t size )
+{
+
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return realloc(ptr, size);
+}
+
+void yyfree (void * ptr )
+{
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 448 "lexer.l"
+
+static void cnfPrintToken(const char *token)
+{
+ if(fp_rs_full_conf_output != NULL) {
+ fprintf(fp_rs_full_conf_output, "%s", token);
+ }
+}
+
+/* add config file or text the the stack of config objects to be
+ * processed.
+ * cnfobjname is either the file name or "text" if generated from
+ * text ("text" can also be replaced by something more intelligent
+ * by the caller.
+ * The provided string is freed.
+ */
+int ATTR_NONNULL()
+cnfAddConfigBuffer(es_str_t *const str, const char *const cnfobj_name)
+{
+ struct bufstack *bs;
+ int r = 0;
+ assert(str != NULL);
+ assert(cnfobj_name != NULL);
+
+ if((bs = malloc(sizeof(struct bufstack))) == NULL) {
+ r = 1;
+ goto done;
+ }
+
+ if(currbs != NULL)
+ currbs->lineno = yylineno;
+ bs->prev = currbs;
+ bs->fn = strdup(cnfobj_name);
+ yy_size_t lll = es_strlen(str);
+ /* NOTE: yy_scan_buffer() does an automatic yy_switch_to_buffer to the new buffer */
+ bs->bs = yy_scan_buffer((char*)es_getBufAddr(str), lll);
+ bs->estr = str; /* needed so we can free it later */
+ currbs = bs;
+ cnfcurrfn = bs->fn;
+ yylineno = 1;
+ dbgprintf("config parser: pushed config fragment on top of stack: %s\n", cnfobj_name);
+
+ if(fp_rs_full_conf_output != NULL) {
+ fprintf(fp_rs_full_conf_output, "\n##### BEGIN CONFIG: %s (put on stack)\n", cnfcurrfn);
+ }
+
+done:
+ if(r != 0) {
+ es_deleteStr(str);
+ }
+ return r;
+}
+
+
+/* set a new buffers. Returns 0 on success, 1 on error, 2 on file not exists.
+ * note: in case of error, errno must be kept valid!
+ */
+int
+cnfSetLexFile(const char *const fname)
+{
+ es_str_t *str = NULL;
+ struct bufstack *bs;
+ FILE *fp;
+ int r = 0;
+
+ /* check for invalid recursive include */
+ for(bs = currbs ; bs != NULL ; bs = bs->prev) {
+ if(!strcmp(fname, bs->fn)) {
+ parser_errmsg("trying to include file '%s', "
+ "which is already included - ignored", fname);
+ r = 1;
+ goto done;
+ }
+ }
+
+ if(fname == NULL) {
+ fp = stdin;
+ } else {
+ if((fp = fopen(fname, "r")) == NULL) {
+ r = 2;
+ goto done;
+ }
+ }
+ readConfFile(fp, &str);
+ if(fp != stdin)
+ fclose(fp);
+
+ r = cnfAddConfigBuffer(str, ((fname == NULL) ? "stdin" : fname));
+
+done:
+ return r;
+}
+
+
+/* returns 0 on success, something else otherwise */
+int
+popfile(void)
+{
+ struct bufstack *bs = currbs;
+
+ if(fp_rs_full_conf_output != NULL) {
+ fprintf(fp_rs_full_conf_output, "\n##### END CONFIG: %s\n", cnfcurrfn);
+ }
+
+ if(bs == NULL)
+ return 1;
+
+ /* delete current entry. But we must not free the file name if
+ * this is the top-level file, because then it may still be used
+ * in error messages for other processing steps.
+ * TODO: change this to another method which stores the file
+ * name inside the config objects. In the longer term, this is
+ * necessary, as otherwise we may provide wrong file name information
+ * at the end of include files as well. -- rgerhards, 2011-07-22
+ */
+ dbgprintf("config parser: reached end of file %s\n", bs->fn);
+ yy_delete_buffer(bs->bs);
+ if(bs->prev != NULL)
+ free(bs->fn);
+ free(bs->estr);
+
+ /* switch back to previous */
+ currbs = bs->prev;
+ free(bs);
+
+ if(currbs == NULL) {
+ dbgprintf("config parser: parsing completed\n");
+ return 1; /* all processed */
+ }
+
+ yy_switch_to_buffer(currbs->bs);
+ yylineno = currbs->lineno;
+ cnfcurrfn = currbs->fn;
+ dbgprintf("config parser: resume parsing of file %s at line %d\n",
+ cnfcurrfn, yylineno);
+ return 0;
+}
+
+void
+tellLexEndParsing(void)
+{
+ free(cnfcurrfn);
+ cnfcurrfn= NULL;
+}
+#endif // #ifndef __clang_analyzer__
+
diff --git a/grammar/lexer.l b/grammar/lexer.l
new file mode 100644
index 0000000..f2e7bba
--- /dev/null
+++ b/grammar/lexer.l
@@ -0,0 +1,590 @@
+ /* Lex file for rsyslog config format v2 (RainerScript).
+ * Please note: this file introduces the new config format, but maintains
+ * backward compatibility. In order to do so, the grammar is not 100% clean,
+ * but IMHO still sufficiently easy both to understand for programmers
+ * maitaining the code as well as users writing the config file. Users are,
+ * of course, encouraged to use new constructs only. But it needs to be noted
+ * that some of the legacy constructs (specifically the in-front-of-action
+ * PRI filter) are very hard to beat in ease of use, at least for simpler
+ * cases. So while we hope that cfsysline support can be dropped some time in
+ * the future, we will probably keep these useful constructs.
+ *
+ * Copyright 2011-2014 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * -or-
+ * see COPYING.ASL20 in the source distribution
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+%top{
+#ifndef __clang_analyzer__ /* this is not really our code */
+#include "config.h"
+}
+
+%{
+#include <libestr.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "rsyslog.h"
+#include "srUtils.h"
+#include "parserif.h"
+
+PRAGMA_IGNORE_Wsign_compare
+PRAGMA_IGNORE_Wmissing_noreturn
+
+FILE *fp_rs_full_conf_output = NULL;
+
+/* TODO: move this to a better modules, refactor -- rgerhards, 2018-01-22 */
+static char *
+read_file(const char *const filename)
+{
+ char *content = NULL;
+ int fd = -1;
+ struct stat sb;
+ ssize_t nread;
+ assert(filename != NULL);
+
+ if((fd = open((const char*) filename, O_RDONLY)) == -1) {
+ goto done;
+ }
+
+ if(fstat(fd, &sb) == -1) {
+ goto done;
+ }
+
+ content = malloc(sb.st_size+1);
+ if(content == NULL) {
+ goto done;
+ }
+
+ nread = read(fd, content, sb.st_size);
+ content[nread] = '\0';
+ if(nread != (ssize_t) sb.st_size) {
+ free(content);
+ content = NULL;
+ goto done;
+ }
+
+done:
+ if(fd != -1) {
+ close(fd);
+ }
+ return content;
+}
+
+static es_str_t* ATTR_NONNULL(1)
+expand_backticks_echo(const char *param)
+{
+ assert(param != NULL);
+ assert(strncmp(param, "echo ", sizeof("echo ")-1) == 0);
+ char envvar[512];
+ int i_envvar = 0;
+ int in_env = 0;
+ es_str_t *estr;
+
+ param += sizeof("echo ")-1;
+ if((estr = es_newStr(strlen(param))) == NULL) {
+ goto done;
+ }
+
+ while(*param) {
+ if(in_env) {
+ if(isspace(*param) || *param == '/') {
+ envvar[i_envvar] = '\0';
+ const char *envval = getenv(envvar);
+ if(envval != NULL)
+ es_addBuf(&estr, envval, strlen(envval));
+ es_addChar(&estr, *param); /* curr char part of output! */
+ i_envvar = 0;
+ in_env = 0;
+ } else if(i_envvar > sizeof(envvar) - 1) {
+ parser_errmsg("environment variable too long, begins with %s", envvar);
+ goto done;
+ } else {
+ envvar[i_envvar++] = *param;
+ }
+ } else if (*param == '$') {
+ in_env = 1;
+ } else {
+ es_addChar(&estr, *param);
+ }
+ ++param;
+ }
+
+ /* final check, we may be in env var name (very probable!) */
+ if(in_env) {
+ envvar[i_envvar] = '\0';
+ const char *envval = getenv(envvar);
+ if(envval != NULL)
+ es_addBuf(&estr, envval, strlen(envval));
+ }
+
+done: return estr;
+}
+
+
+static es_str_t* ATTR_NONNULL(1)
+expand_backticks(char *const param)
+{
+ es_str_t *estr;
+ assert(param != NULL);
+
+ if(strncmp(param, "echo ", sizeof("echo ")-1) == 0) {
+ estr = expand_backticks_echo(param);
+ } else if(strncmp(param, "cat ", sizeof("cat ")-1) == 0) {
+ const char *val = read_file(param+4);
+ if(val == NULL) {
+ parser_errmsg("file could not be accessed for `%s`", param);
+ const char *errmsg = "/* file cound not be accessed - see"
+ "error messages */";
+ estr = es_newStrFromCStr(errmsg, strlen(errmsg));
+ } else {
+ estr = es_newStrFromCStr(val, strlen(val));
+ }
+ free((void*) val);
+ } else {
+ parser_errmsg("invalid backtick parameter `%s` - replaced by "
+ "empty string (\"\")", param);
+ estr = es_newStr(1);
+ }
+
+ return estr;
+}
+%}
+
+%option noyywrap nodefault case-insensitive yylineno
+ /*%option noyywrap nodefault case-insensitive */
+
+/* avoid compiler warning: `yyunput' defined but not used */
+%option nounput noinput
+
+
+%x INOBJ
+ /* INOBJ is selected if we are inside an object (name/value pairs!) */
+%x COMMENT
+ /* COMMENT is "the usual trick" to handle C-style comments */
+%x INCL
+ /* INCL is in $IncludeConfig processing (skip to include file) */
+%x LINENO
+ /* LINENO: support for setting the linenumber */
+%x INCALL
+ /* INCALL: support for the call statement */
+%x IN_PROCEDURE_CALL
+ /* IN_PROCEDURE_CALL: support for the call statement */
+%x EXPR
+ /* EXPR is a bit ugly, but we need it to support pre v6-syntax. The problem
+ * is that cfsysline statement start with $..., the same like variables in
+ * an expression. However, cfsysline statements can never appear inside an
+ * expression. So we create a specific expr mode, which is turned on after
+ * we lexed a keyword that needs to be followed by an expression (using
+ * knowledge from the upper layer...). In expr mode, we strictly do
+ * expression-based parsing. Expr mode is stopped when we reach a token
+ * that can not be part of an expression (currently only "then"). As I
+ * wrote this ugly, but the price needed to pay in order to remain
+ * compatible to the previous format.
+ */
+%{
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <libestr.h>
+#include "rainerscript.h"
+#include "parserif.h"
+#include "grammar.h"
+static int preCommentState; /* save for lex state before a comment */
+
+struct bufstack {
+ struct bufstack *prev;
+ YY_BUFFER_STATE bs;
+ int lineno;
+ char *fn;
+ es_str_t *estr;
+} *currbs = NULL;
+
+char *cnfcurrfn; /* name of currently processed file */
+
+int popfile(void);
+int cnfSetLexFile(const char *fname);
+
+static void cnfPrintToken(const char *token);
+extern int yydebug;
+
+/* somehow, I need these prototype even though the headers are
+ * included. I guess that's some autotools magic I don't understand...
+ */
+#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) \
+ && !defined(__DragonflyBSD__) && !defined(_AIX)
+int fileno(FILE *stream);
+#endif
+
+
+%}
+
+%%
+
+ /* keywords */
+"if" { cnfPrintToken(yytext); BEGIN EXPR; return IF; }
+"foreach" { cnfPrintToken(yytext); BEGIN EXPR; return FOREACH; }
+"reload_lookup_table" { cnfPrintToken(yytext); BEGIN IN_PROCEDURE_CALL; return RELOAD_LOOKUP_TABLE_PROCEDURE; }
+<IN_PROCEDURE_CALL>"(" { cnfPrintToken(yytext); return yytext[0]; }
+<IN_PROCEDURE_CALL>\'([^'\\]|\\['"\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\' {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+<IN_PROCEDURE_CALL>\"([^"\\$]|\\["'\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\" {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+<IN_PROCEDURE_CALL>"," { cnfPrintToken(yytext); return yytext[0]; }
+<IN_PROCEDURE_CALL>")" { cnfPrintToken(yytext); BEGIN INITIAL; return yytext[0]; }
+<IN_PROCEDURE_CALL>[ \t\n]* {cnfPrintToken(yytext); }
+<IN_PROCEDURE_CALL>. { cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in expression "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+<EXPR>"(" { cnfPrintToken(yytext); BEGIN EXPR; return yytext[0]; }
+<EXPR>"then" { cnfPrintToken(yytext); BEGIN INITIAL; return THEN; }
+<EXPR>"do" { cnfPrintToken(yytext); BEGIN INITIAL; return DO; }
+<EXPR>";" { cnfPrintToken(yytext); BEGIN INITIAL; return ';'; }
+<EXPR>"or" { cnfPrintToken(yytext); return OR; }
+<EXPR>"and" { cnfPrintToken(yytext); return AND; }
+<EXPR>"not" { cnfPrintToken(yytext); return NOT; }
+<EXPR>"=" |
+<EXPR>"," |
+<EXPR>"*" |
+<EXPR>"/" |
+<EXPR>"%" |
+<EXPR>"+" |
+<EXPR>"&" |
+<EXPR>"-" |
+<EXPR>"[" |
+<EXPR>"]" |
+<EXPR>")" { cnfPrintToken(yytext); return yytext[0]; }
+<EXPR>"==" { cnfPrintToken(yytext); return CMP_EQ; }
+<EXPR>"<=" { cnfPrintToken(yytext); return CMP_LE; }
+<EXPR>">=" { cnfPrintToken(yytext); return CMP_GE; }
+<EXPR>"!=" |
+<EXPR>"<>" { cnfPrintToken(yytext); return CMP_NE; }
+<EXPR>"<" { cnfPrintToken(yytext); return CMP_LT; }
+<EXPR>">" { cnfPrintToken(yytext); return CMP_GT; }
+<EXPR>"contains" { cnfPrintToken(yytext); return CMP_CONTAINS; }
+<EXPR>"in" { cnfPrintToken(yytext); return ITERATOR_ASSIGNMENT; }
+<EXPR>"contains_i" { cnfPrintToken(yytext); return CMP_CONTAINSI; }
+<EXPR>"startswith" { cnfPrintToken(yytext); return CMP_STARTSWITH; }
+<EXPR>"startswith_i" { cnfPrintToken(yytext); return CMP_STARTSWITHI; }
+<EXPR>0[0-7]+ | /* octal number */
+<EXPR>0x[0-9a-f]+ | /* hex number, following rule is dec; strtoll handles all! */
+<EXPR>([1-9][0-9]*|0) { cnfPrintToken(yytext); yylval.n = strtoll(yytext, NULL, 0); return NUMBER; }
+<EXPR>\$[$!./]{0,1}[@a-z_]*[!@a-z0-9\-_\.\[\]]* { cnfPrintToken(yytext); yylval.s = strdup(yytext+1); return VAR; }
+<EXPR>\'([^'\\]|\\['"\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\' {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+<EXPR>`([^`\\]|\\['`"\\bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*` {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = expand_backticks(yytext+1);
+ return STRING; }
+<EXPR>\"([^"\\$]|\\["'\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\" {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+<EXPR>\"([^"\\]|\\["'\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\" {
+ cnfPrintToken(yytext); parser_errmsg("$-sign in double quotes must be "
+ "escaped, problem string is: %s",
+ yytext); }
+<EXPR>[ \t\n] { cnfPrintToken(yytext); }
+<EXPR>"exists" { cnfPrintToken(yytext); return EXISTS; } /* special case function (see rainerscript.c) */
+<EXPR>[a-z][a-z0-9_]* { cnfPrintToken(yytext); yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ return FUNC; }
+<EXPR>. { cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in expression "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+<INCALL>[ \t\n] { cnfPrintToken(yytext); }
+<INCALL>. { cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in 'call' statement"
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+<INCALL>[a-zA-Z][a-zA-Z0-9\-_\.]* { cnfPrintToken(yytext); yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ BEGIN INITIAL;
+ return NAME; }
+"&" { cnfPrintToken(yytext); return '&'; }
+"{" { cnfPrintToken(yytext); return '{'; }
+"}" { cnfPrintToken(yytext); return '}'; }
+"stop" { cnfPrintToken(yytext); return STOP; }
+"else" { cnfPrintToken(yytext); return ELSE; }
+"call" { cnfPrintToken(yytext); BEGIN INCALL; return CALL; }
+"call_indirect" { cnfPrintToken(yytext); BEGIN EXPR; return CALL_INDIRECT; }
+"set" { cnfPrintToken(yytext); BEGIN EXPR; return SET; }
+"reset" { cnfPrintToken(yytext); BEGIN EXPR; return RESET; }
+"unset" { cnfPrintToken(yytext); BEGIN EXPR; return UNSET; }
+"continue" { cnfPrintToken(yytext); return CONTINUE; }
+ /* line number support because the "preprocessor" combines lines and so needs
+ * to tell us the real source line.
+ */
+"preprocfilelinenumber(" { cnfPrintToken(yytext); BEGIN LINENO; }
+<LINENO>[0-9]+ { cnfPrintToken(yytext); yylineno = atoi(yytext) - 1; }
+<LINENO>")" { cnfPrintToken(yytext); BEGIN INITIAL; }
+<LINENO>.|\n
+ /* $IncludeConfig must be detected as part of CFSYSLINE, because this is
+ * always the longest match :-(
+ */
+<INCL>.|\n
+<INCL>[^ \t\n]+ { cnfPrintToken(yytext); if(cnfDoInclude(yytext, 0) != 0)
+ yyterminate();
+ BEGIN INITIAL; }
+"main_queue"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_MAINQ;
+ BEGIN INOBJ; return BEGINOBJ; }
+"timezone"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_TIMEZONE;
+ BEGIN INOBJ; return BEGINOBJ; }
+"parser"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_PARSER;
+ BEGIN INOBJ; return BEGINOBJ; }
+"global"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_GLOBAL;
+ BEGIN INOBJ; return BEGINOBJ; }
+"template"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_TPL;
+ BEGIN INOBJ; return BEGIN_TPL; }
+"ruleset"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_RULESET;
+ BEGIN INOBJ; return BEGIN_RULESET; }
+"property"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_PROPERTY;
+ BEGIN INOBJ; return BEGIN_PROPERTY; }
+"constant"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_CONSTANT;
+ BEGIN INOBJ; return BEGIN_CONSTANT; }
+"input"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_INPUT;
+ BEGIN INOBJ; return BEGINOBJ; }
+"module"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_MODULE;
+ BEGIN INOBJ; return BEGINOBJ; }
+"lookup_table"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_LOOKUP_TABLE;
+ BEGIN INOBJ; return BEGINOBJ; }
+"dyn_stats"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_DYN_STATS;
+ BEGIN INOBJ; return BEGINOBJ; }
+"percentile_stats"[ \n\t]*"(" { cnfPrintToken(yytext); yylval.objType = CNFOBJ_PERCTILE_STATS;
+ BEGIN INOBJ; return BEGINOBJ; }
+"include"[ \n\t]*"(" { cnfPrintToken(yytext); BEGIN INOBJ; return BEGIN_INCLUDE; }
+"action"[ \n\t]*"(" { cnfPrintToken(yytext); BEGIN INOBJ; return BEGIN_ACTION; }
+^[ \t]*:\$?[a-z\-]+[ ]*,[ ]*!?[a-z]+[ ]*,[ ]*\"(\\\"|[^\"])*\" {
+ cnfPrintToken(yytext); yylval.s = strdup(rmLeadingSpace(yytext));
+ dbgprintf("lexer: propfilt is '%s'\n", yylval.s);
+ return PROPFILT;
+ }
+^[ \t]*[\*a-z][\*a-z]*[0-7]*[\.,][,!=;\.\*a-z0-7]+ { cnfPrintToken(yytext); yylval.s = strdup(rmLeadingSpace(yytext)); return PRIFILT; }
+"~" |
+"*" |
+\-\/[^*][^\n]* |
+\/[^*][^\n]* |
+:[a-z0-9]+:[^\n]* |
+[\|\.\-\@\^?~>][^\n]+ |
+[a-z0-9_][a-z0-9_\-\+,;]* { cnfPrintToken(yytext); yylval.s = yytext; return LEGACY_ACTION; }
+<INOBJ>")" { cnfPrintToken(yytext); BEGIN INITIAL; return ENDOBJ; }
+<INOBJ>[a-z][a-z0-9_\.]* { cnfPrintToken(yytext); yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ return NAME; }
+<INOBJ>"," |
+<INOBJ>"[" |
+<INOBJ>"]" |
+<INOBJ>"=" { cnfPrintToken(yytext); return(yytext[0]); }
+<INOBJ>\"([^"\\]|\\['"?\\abfnrtv]|\\[0-7]{1,3})*\" {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = es_newStrFromBuf(yytext+1, strlen(yytext)-1);
+ return STRING; }
+<INOBJ>`([^`\\]|\\['`?\\abfnrtv]|\\[0-7]{1,3})*` {
+ cnfPrintToken(yytext); yytext[yyleng-1] = '\0';
+ unescapeStr((uchar*)yytext+1, yyleng-2);
+ yylval.estr = expand_backticks(yytext+1);
+ return STRING; }
+ /*yylval.estr = es_newStrFromBuf(yytext+1, yyleng-2);
+ return VALUE; }*/
+"/*" { cnfPrintToken(yytext); preCommentState = YY_START; BEGIN COMMENT; }
+<INOBJ>"/*" { cnfPrintToken(yytext); preCommentState = YY_START; BEGIN COMMENT; }
+<EXPR>"/*" { cnfPrintToken(yytext); preCommentState = YY_START; BEGIN COMMENT; }
+<COMMENT>"*/" { cnfPrintToken(yytext); BEGIN preCommentState; }
+<COMMENT>([^*]|\n)+|.
+<INOBJ>#.*$ /* skip comments in input */
+<INOBJ>[ \n\t] { cnfPrintToken(yytext); }
+<INOBJ>. { cnfPrintToken(yytext); parser_errmsg("invalid character '%s' in object definition "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+\$[a-z]+.*$ { cnfPrintToken(yytext); /* see comment on $IncludeConfig above */
+ if(!strncasecmp(yytext, "$includeconfig ", 14)) {
+ yyless((yy_size_t)14);
+ BEGIN INCL;
+ } else if(!strncasecmp(yytext, "$ruleset ", 9)) {
+ yylval.s = strdup(yytext);
+ return LEGACY_RULESET;
+ } else {
+ cnfDoCfsysline(strdup(yytext));
+ }
+ }
+![^ \t\n]+[ \t]*$ { cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_TAG_SELECTOR; }
+[+-]\*[ \t\n]*#.*$ { cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_HOST_SELECTOR; }
+[+-]\*[ \t\n]*$ { cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_HOST_SELECTOR; }
+^[ \t]*[+-][a-z0-9.:-]+[ \t]*$ { cnfPrintToken(yytext); yylval.s = strdup(yytext); return BSD_HOST_SELECTOR; }
+\#.*\n {cnfPrintToken(yytext); }/* skip comments in input */
+[\n\t ] {cnfPrintToken(yytext); }/* drop whitespace */
+. { cnfPrintToken(yytext); parser_errmsg("invalid character '%s' "
+ "- is there an invalid escape sequence somewhere?",
+ yytext); }
+<<EOF>> { if(popfile() != 0) yyterminate(); }
+
+%%
+static void cnfPrintToken(const char *token)
+{
+ if(fp_rs_full_conf_output != NULL) {
+ fprintf(fp_rs_full_conf_output, "%s", token);
+ }
+}
+
+/* add config file or text the the stack of config objects to be
+ * processed.
+ * cnfobjname is either the file name or "text" if generated from
+ * text ("text" can also be replaced by something more intelligent
+ * by the caller.
+ * The provided string is freed.
+ */
+int ATTR_NONNULL()
+cnfAddConfigBuffer(es_str_t *const str, const char *const cnfobj_name)
+{
+ struct bufstack *bs;
+ int r = 0;
+ assert(str != NULL);
+ assert(cnfobj_name != NULL);
+
+ if((bs = malloc(sizeof(struct bufstack))) == NULL) {
+ r = 1;
+ goto done;
+ }
+
+ if(currbs != NULL)
+ currbs->lineno = yylineno;
+ bs->prev = currbs;
+ bs->fn = strdup(cnfobj_name);
+ yy_size_t lll = es_strlen(str);
+ /* NOTE: yy_scan_buffer() does an automatic yy_switch_to_buffer to the new buffer */
+ bs->bs = yy_scan_buffer((char*)es_getBufAddr(str), lll);
+ bs->estr = str; /* needed so we can free it later */
+ currbs = bs;
+ cnfcurrfn = bs->fn;
+ yylineno = 1;
+ dbgprintf("config parser: pushed config fragment on top of stack: %s\n", cnfobj_name);
+
+ if(fp_rs_full_conf_output != NULL) {
+ fprintf(fp_rs_full_conf_output, "\n##### BEGIN CONFIG: %s (put on stack)\n", cnfcurrfn);
+ }
+
+done:
+ if(r != 0) {
+ es_deleteStr(str);
+ }
+ return r;
+}
+
+
+/* set a new buffers. Returns 0 on success, 1 on error, 2 on file not exists.
+ * note: in case of error, errno must be kept valid!
+ */
+int
+cnfSetLexFile(const char *const fname)
+{
+ es_str_t *str = NULL;
+ struct bufstack *bs;
+ FILE *fp;
+ int r = 0;
+
+ /* check for invalid recursive include */
+ for(bs = currbs ; bs != NULL ; bs = bs->prev) {
+ if(!strcmp(fname, bs->fn)) {
+ parser_errmsg("trying to include file '%s', "
+ "which is already included - ignored", fname);
+ r = 1;
+ goto done;
+ }
+ }
+
+ if(fname == NULL) {
+ fp = stdin;
+ } else {
+ if((fp = fopen(fname, "r")) == NULL) {
+ r = 2;
+ goto done;
+ }
+ }
+ readConfFile(fp, &str);
+ if(fp != stdin)
+ fclose(fp);
+
+ r = cnfAddConfigBuffer(str, ((fname == NULL) ? "stdin" : fname));
+
+done:
+ return r;
+}
+
+
+/* returns 0 on success, something else otherwise */
+int
+popfile(void)
+{
+ struct bufstack *bs = currbs;
+
+ if(fp_rs_full_conf_output != NULL) {
+ fprintf(fp_rs_full_conf_output, "\n##### END CONFIG: %s\n", cnfcurrfn);
+ }
+
+ if(bs == NULL)
+ return 1;
+
+ /* delete current entry. But we must not free the file name if
+ * this is the top-level file, because then it may still be used
+ * in error messages for other processing steps.
+ * TODO: change this to another method which stores the file
+ * name inside the config objects. In the longer term, this is
+ * necessary, as otherwise we may provide wrong file name information
+ * at the end of include files as well. -- rgerhards, 2011-07-22
+ */
+ dbgprintf("config parser: reached end of file %s\n", bs->fn);
+ yy_delete_buffer(bs->bs);
+ if(bs->prev != NULL)
+ free(bs->fn);
+ free(bs->estr);
+
+ /* switch back to previous */
+ currbs = bs->prev;
+ free(bs);
+
+ if(currbs == NULL) {
+ dbgprintf("config parser: parsing completed\n");
+ return 1; /* all processed */
+ }
+
+ yy_switch_to_buffer(currbs->bs);
+ yylineno = currbs->lineno;
+ cnfcurrfn = currbs->fn;
+ dbgprintf("config parser: resume parsing of file %s at line %d\n",
+ cnfcurrfn, yylineno);
+ return 0;
+}
+
+void
+tellLexEndParsing(void)
+{
+ free(cnfcurrfn);
+ cnfcurrfn= NULL;
+}
+#endif // #ifndef __clang_analyzer__
diff --git a/grammar/parserif.h b/grammar/parserif.h
new file mode 100644
index 0000000..a22f8dd
--- /dev/null
+++ b/grammar/parserif.h
@@ -0,0 +1,44 @@
+/* rsyslog parser interface.
+ *
+ * Copyright 2011-2016 Rainer Gerhards
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * -or-
+ * see COPYING.ASL20 in the source distribution
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef PARSERIF_H_DEFINED
+#define PARSERIF_H_DEFINED
+#include "rainerscript.h"
+int cnfSetLexFile(const char*);
+void parser_errmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void parser_warnmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void tellLexEndParsing(void);
+#ifndef IN_GRAMMAR_Y
+int yyparse(void);
+extern int yydebug;
+extern int yylineno;
+extern char *cnfcurrfn;
+extern FILE *fp_rs_full_conf_output;
+#endif
+
+/* entry points to be called after the parser has processed the
+ * element in question. Actual processing must than be done inside
+ * these functions.
+ */
+void cnfDoObj(struct cnfobj *o);
+void cnfDoScript(struct cnfstmt *script);
+void cnfDoCfsysline(char *ln);
+void cnfDoBSDTag(char *ln);
+void cnfDoBSDHost(char *ln);
+int cnfAddConfigBuffer(es_str_t *const str, const char *const cnfobj_name);
+#endif
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
new file mode 100644
index 0000000..69d0b38
--- /dev/null
+++ b/grammar/rainerscript.c
@@ -0,0 +1,5806 @@
+/* rainerscript.c - routines to support RainerScript config language
+ *
+ * Module begun 2011-07-01 by Rainer Gerhards
+ *
+ * Copyright 2011-2022 Rainer Gerhards and Others.
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * The rsyslog runtime library 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.
+ *
+ * The rsyslog runtime library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
+ */
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <glob.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <libestr.h>
+#include <time.h>
+
+#include "rsyslog.h"
+#include "rainerscript.h"
+#include "conf.h"
+#include "parserif.h"
+#include "parse.h"
+#include "rsconf.h"
+#include "grammar.h"
+#include "queue.h"
+#include "srUtils.h"
+#include "regexp.h"
+#include "datetime.h"
+#include "obj.h"
+#include "modules.h"
+#include "ruleset.h"
+#include "msg.h"
+#include "wti.h"
+#include "unicode-helper.h"
+#include "errmsg.h"
+
+PRAGMA_INGORE_Wswitch_enum
+
+DEFobjCurrIf(obj)
+DEFobjCurrIf(regexp)
+DEFobjCurrIf(datetime)
+
+struct cnfexpr* cnfexprOptimize(struct cnfexpr *expr);
+static void cnfstmtOptimizePRIFilt(struct cnfstmt *stmt);
+static void cnfarrayPrint(struct cnfarray *ar, int indent);
+struct cnffunc * cnffuncNew_prifilt(int fac);
+
+static struct cnfparamdescr incpdescr[] = {
+ { "file", eCmdHdlrString, 0 },
+ { "text", eCmdHdlrString, 0 },
+ { "mode", eCmdHdlrGetWord, 0 }
+};
+static struct cnfparamblk incpblk =
+ { CNFPARAMBLK_VERSION,
+ sizeof(incpdescr)/sizeof(struct cnfparamdescr),
+ incpdescr
+ };
+
+/* debug support: convert token to a human-readable string. Note that
+ * this function only supports a single thread due to a static buffer.
+ * This is deemed a solid solution, as it is intended to be used during
+ * startup, only.
+ * NOTE: This function MUST be updated if new tokens are defined in the
+ * grammar.
+ */
+static const char *
+tokenToString(const int token)
+{
+ const char *tokstr;
+ static char tokbuf[512];
+
+ switch(token) {
+ case NAME: tokstr = "NAME"; break;
+ case FUNC: tokstr = "FUNC"; break;
+ case BEGINOBJ: tokstr ="BEGINOBJ"; break;
+ case ENDOBJ: tokstr ="ENDOBJ"; break;
+ case BEGIN_ACTION: tokstr ="BEGIN_ACTION"; break;
+ case BEGIN_PROPERTY: tokstr ="BEGIN_PROPERTY"; break;
+ case BEGIN_CONSTANT: tokstr ="BEGIN_CONSTANT"; break;
+ case BEGIN_TPL: tokstr ="BEGIN_TPL"; break;
+ case BEGIN_RULESET: tokstr ="BEGIN_RULESET"; break;
+ case STOP: tokstr ="STOP"; break;
+ case SET: tokstr ="SET"; break;
+ case UNSET: tokstr ="UNSET"; break;
+ case CONTINUE: tokstr ="CONTINUE"; break;
+ case CALL: tokstr ="CALL"; break;
+ case LEGACY_ACTION: tokstr ="LEGACY_ACTION"; break;
+ case LEGACY_RULESET: tokstr ="LEGACY_RULESET"; break;
+ case PRIFILT: tokstr ="PRIFILT"; break;
+ case PROPFILT: tokstr ="PROPFILT"; break;
+ case IF: tokstr ="IF"; break;
+ case THEN: tokstr ="THEN"; break;
+ case ELSE: tokstr ="ELSE"; break;
+ case OR: tokstr ="OR"; break;
+ case AND: tokstr ="AND"; break;
+ case NOT: tokstr ="NOT"; break;
+ case VAR: tokstr ="VAR"; break;
+ case STRING: tokstr ="STRING"; break;
+ case NUMBER: tokstr ="NUMBER"; break;
+ case CMP_EQ: tokstr ="CMP_EQ"; break;
+ case CMP_NE: tokstr ="CMP_NE"; break;
+ case CMP_LE: tokstr ="CMP_LE"; break;
+ case CMP_GE: tokstr ="CMP_GE"; break;
+ case CMP_LT: tokstr ="CMP_LT"; break;
+ case CMP_GT: tokstr ="CMP_GT"; break;
+ case CMP_CONTAINS: tokstr ="CMP_CONTAINS"; break;
+ case CMP_CONTAINSI: tokstr ="CMP_CONTAINSI"; break;
+ case CMP_STARTSWITH: tokstr ="CMP_STARTSWITH"; break;
+ case CMP_STARTSWITHI: tokstr ="CMP_STARTSWITHI"; break;
+ case UMINUS: tokstr ="UMINUS"; break;
+ case '&': tokstr ="&"; break;
+ case '+': tokstr ="+"; break;
+ case '-': tokstr ="-"; break;
+ case '*': tokstr ="*"; break;
+ case '/': tokstr ="/"; break;
+ case '%': tokstr ="%"; break;
+ case 'M': tokstr ="M"; break;
+ case 'N': tokstr ="N"; break;
+ case 'S': tokstr ="S"; break;
+ case 'V': tokstr ="V"; break;
+ case 'F': tokstr ="F"; break;
+ case 'A': tokstr ="A"; break;
+ case S_FUNC_EXISTS: tokstr ="exists()"; break;
+ default: snprintf(tokbuf, sizeof(tokbuf), "%c[%d]", token, token);
+ tokstr = tokbuf; break;
+ }
+ return tokstr;
+}
+
+
+const char*
+getFIOPName(const unsigned iFIOP)
+{
+ const char *pRet;
+ switch(iFIOP) {
+ case FIOP_CONTAINS:
+ pRet = "contains";
+ break;
+ case FIOP_ISEQUAL:
+ pRet = "isequal";
+ break;
+ case FIOP_STARTSWITH:
+ pRet = "startswith";
+ break;
+ case FIOP_REGEX:
+ pRet = "regex";
+ break;
+ case FIOP_EREREGEX:
+ pRet = "ereregex";
+ break;
+ case FIOP_ISEMPTY:
+ pRet = "isempty";
+ break;
+ default:
+ pRet = "NOP";
+ break;
+ }
+ return pRet;
+}
+
+const char*
+cnfFiltType2str(const enum cnfFiltType filttype)
+{
+ switch(filttype) {
+ case CNFFILT_NONE:
+ return("filter:none");
+ case CNFFILT_PRI:
+ return("filter:pri");
+ case CNFFILT_PROP:
+ return("filter:prop");
+ case CNFFILT_SCRIPT:
+ return("filter:script");
+ default:
+ return("error:invalid_filter_type"); /* should never be reached */
+ }
+}
+
+const char*
+cnfobjType2str(const enum cnfobjType ot)
+{
+ switch(ot) {
+ case CNFOBJ_ACTION:
+ return "action";
+ break;
+ case CNFOBJ_RULESET:
+ return "ruleset";
+ break;
+ case CNFOBJ_GLOBAL:
+ return "global";
+ break;
+ case CNFOBJ_INPUT:
+ return "input";
+ break;
+ case CNFOBJ_MODULE:
+ return "module";
+ break;
+ case CNFOBJ_TPL:
+ return "template";
+ break;
+ case CNFOBJ_PROPERTY:
+ return "property";
+ break;
+ case CNFOBJ_CONSTANT:
+ return "constant";
+ break;
+ case CNFOBJ_MAINQ:
+ return "main_queue";
+ case CNFOBJ_LOOKUP_TABLE:
+ return "lookup_table";
+ case CNFOBJ_PARSER:
+ return "parser";
+ break;
+ case CNFOBJ_TIMEZONE:
+ return "timezone";
+ break;
+ case CNFOBJ_DYN_STATS:
+ return "dyn_stats";
+ break;
+ case CNFOBJ_PERCTILE_STATS:
+ return "perctile_stats";
+ break;
+ default:return "error: invalid cnfobjType";
+ }
+}
+
+/* This function takes the filter part of a property
+ * based filter and decodes it. It processes the line up to the beginning
+ * of the action part.
+ */
+static rsRetVal
+DecodePropFilter(uchar *pline, struct cnfstmt *stmt)
+{
+ rsParsObj *pPars = NULL;
+ cstr_t *pCSCompOp = NULL;
+ cstr_t *pCSPropName = NULL;
+ int iOffset; /* for compare operations */
+ DEFiRet;
+
+ assert(pline != NULL);
+
+ DBGPRINTF("Decoding property-based filter '%s'\n", pline);
+
+ /* create parser object starting with line string without leading colon */
+ if((iRet = rsParsConstructFromSz(&pPars, pline+1)) != RS_RET_OK) {
+ parser_errmsg("error %d constructing parser object", iRet);
+ FINALIZE;
+ }
+
+ /* read property */
+ iRet = parsDelimCStr(pPars, &pCSPropName, ',', 1, 1, 1);
+ if(iRet != RS_RET_OK) {
+ parser_errmsg("error %d parsing filter property", iRet);
+ FINALIZE;
+ }
+ CHKiRet(msgPropDescrFill(&stmt->d.s_propfilt.prop, cstrGetSzStrNoNULL(pCSPropName),
+ cstrLen(pCSPropName)));
+
+ /* read operation */
+ iRet = parsDelimCStr(pPars, &pCSCompOp, ',', 1, 1, 1);
+ if(iRet != RS_RET_OK) {
+ parser_errmsg("error %d compare operation property - ignoring selector", iRet);
+ FINALIZE;
+ }
+
+ /* we now first check if the condition is to be negated. To do so, we first
+ * must make sure we have at least one char in the param and then check the
+ * first one.
+ * rgerhards, 2005-09-26
+ */
+ if(rsCStrLen(pCSCompOp) > 0) {
+ if(*rsCStrGetBufBeg(pCSCompOp) == '!') {
+ stmt->d.s_propfilt.isNegated = 1;
+ iOffset = 1; /* ignore '!' */
+ } else {
+ stmt->d.s_propfilt.isNegated = 0;
+ iOffset = 0;
+ }
+ } else {
+ stmt->d.s_propfilt.isNegated = 0;
+ iOffset = 0;
+ }
+
+ if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "contains", 8)) {
+ stmt->d.s_propfilt.operation = FIOP_CONTAINS;
+ } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "isequal", 7)) {
+ stmt->d.s_propfilt.operation = FIOP_ISEQUAL;
+ } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "isempty", 7)) {
+ stmt->d.s_propfilt.operation = FIOP_ISEMPTY;
+ } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "startswith", 10)) {
+ stmt->d.s_propfilt.operation = FIOP_STARTSWITH;
+ } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "regex", 5)) {
+ stmt->d.s_propfilt.operation = FIOP_REGEX;
+ } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "ereregex", 8)) {
+ stmt->d.s_propfilt.operation = FIOP_EREREGEX;
+ } else {
+ parser_errmsg("error: invalid compare operation '%s'",
+ (char*) rsCStrGetSzStrNoNULL(pCSCompOp));
+ ABORT_FINALIZE(RS_RET_ERR);
+ }
+
+ if(stmt->d.s_propfilt.operation != FIOP_ISEMPTY) {
+ /* read compare value */
+ iRet = parsQuotedCStr(pPars, &stmt->d.s_propfilt.pCSCompValue);
+ if(iRet != RS_RET_OK) {
+ parser_errmsg("error %d compare value property", iRet);
+ FINALIZE;
+ }
+ }
+
+finalize_it:
+ if(pPars != NULL)
+ rsParsDestruct(pPars);
+ if(pCSCompOp != NULL)
+ rsCStrDestruct(&pCSCompOp);
+ if(pCSPropName != NULL)
+ cstrDestruct(&pCSPropName);
+ RETiRet;
+}
+
+static void
+prifiltInvert(struct funcData_prifilt *__restrict__ const prifilt)
+{
+ int i;
+ for(i = 0 ; i < LOG_NFACILITIES+1 ; ++i) {
+ prifilt->pmask[i] = ~prifilt->pmask[i];
+ }
+}
+
+/* set prifilt so that it matches for some severities, sev is its numerical
+ * value. Mode is one of the compop tokens CMP_EQ, CMP_LT, CMP_LE, CMP_GT,
+ * CMP_GE, CMP_NE.
+ */
+static void
+prifiltSetSeverity(struct funcData_prifilt *prifilt, int sev, int mode)
+{
+ static int lessthanmasks[] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+ int i;
+ for(i = 0 ; i < LOG_NFACILITIES+1 ; ++i) {
+ if(mode == CMP_EQ || mode == CMP_NE)
+ prifilt->pmask[i] = 1 << sev;
+ else if(mode == CMP_LT)
+ prifilt->pmask[i] = lessthanmasks[sev];
+ else if(mode == CMP_LE)
+ prifilt->pmask[i] = lessthanmasks[sev+1];
+ else if(mode == CMP_GT)
+ prifilt->pmask[i] = ~lessthanmasks[sev+1];
+ else if(mode == CMP_GE)
+ prifilt->pmask[i] = ~lessthanmasks[sev];
+ else
+ DBGPRINTF("prifiltSetSeverity: program error, invalid mode %s\n",
+ tokenToString(mode));
+ }
+ if(mode == CMP_NE)
+ prifiltInvert(prifilt);
+}
+
+/* set prifilt so that it matches for some facilities, fac is its numerical
+ * value. Mode is one of the compop tokens CMP_EQ, CMP_LT, CMP_LE, CMP_GT,
+ * CMP_GE, CMP_NE. For the given facilities, all severities are enabled.
+ * NOTE: fac MUST be in the range 0..24 (not multiplied by 8)!
+ */
+static void
+prifiltSetFacility(struct funcData_prifilt *__restrict__ const prifilt, const int fac, const int mode)
+{
+ int i;
+
+ memset(prifilt->pmask, 0, sizeof(prifilt->pmask));
+ switch(mode) {
+ case CMP_EQ:
+ prifilt->pmask[fac] = TABLE_ALLPRI;
+ break;
+ case CMP_NE:
+ prifilt->pmask[fac] = TABLE_ALLPRI;
+ prifiltInvert(prifilt);
+ break;
+ case CMP_LT:
+ for(i = 0 ; i < fac ; ++i)
+ prifilt->pmask[i] = TABLE_ALLPRI;
+ break;
+ case CMP_LE:
+ for(i = 0 ; i < fac+1 ; ++i)
+ prifilt->pmask[i] = TABLE_ALLPRI;
+ break;
+ case CMP_GE:
+ for(i = fac ; i < LOG_NFACILITIES+1 ; ++i)
+ prifilt->pmask[i] = TABLE_ALLPRI;
+ break;
+ case CMP_GT:
+ for(i = fac+1 ; i < LOG_NFACILITIES+1 ; ++i)
+ prifilt->pmask[i] = TABLE_ALLPRI;
+ break;
+ default:break;
+ }
+}
+
+/* combine a prifilt with AND/OR (the respective token values are
+ * used to keep things simple).
+ */
+static void
+prifiltCombine(struct funcData_prifilt *__restrict__ const prifilt,
+ struct funcData_prifilt *__restrict__ const prifilt2,
+ const int mode)
+{
+ int i;
+ for(i = 0 ; i < LOG_NFACILITIES+1 ; ++i) {
+ if(mode == AND)
+ prifilt->pmask[i] = prifilt->pmask[i] & prifilt2->pmask[i];
+ else
+ prifilt->pmask[i] = prifilt->pmask[i] | prifilt2->pmask[i];
+ }
+}
+
+
+void
+readConfFile(FILE * const fp, es_str_t **str)
+{
+ char ln[10240];
+ char buf[512];
+ int lenBuf;
+ int bWriteLineno = 0;
+ int len, i;
+ int start; /* start index of to be submitted text */
+ int bContLine = 0;
+ int lineno = 0;
+
+ *str = es_newStr(4096);
+
+ while(fgets(ln, sizeof(ln), fp) != NULL) {
+ ++lineno;
+ if(bWriteLineno) {
+ bWriteLineno = 0;
+ lenBuf = sprintf(buf, "PreprocFileLineNumber(%d)\n", lineno);
+ es_addBuf(str, buf, lenBuf);
+ }
+ len = strlen(ln);
+ /* if we are continuation line, we need to drop leading WS */
+ if(bContLine) {
+ for(start = 0 ; start < len && isspace(ln[start]) ; ++start)
+ /* JUST SCAN */;
+ } else {
+ start = 0;
+ }
+ for(i = len - 1 ; i >= start && isspace(ln[i]) ; --i)
+ /* JUST SCAN */;
+ if(i >= 0) {
+ if(ln[i] == '\\') {
+ --i;
+ bContLine = 1;
+ } else {
+ if(bContLine) /* write line number if we had cont line */
+ bWriteLineno = 1;
+ bContLine = 0;
+ }
+ /* add relevant data to buffer */
+ es_addBuf(str, ln+start, i+1 - start);
+ }
+ if(!bContLine)
+ es_addChar(str, '\n');
+ }
+ /* indicate end of buffer to flex */
+ es_addChar(str, '\0');
+ es_addChar(str, '\0');
+}
+
+/* comparison function for qsort() and bsearch() string array compare */
+static int
+qs_arrcmp(const void *s1, const void *s2)
+{
+ return es_strcmp(*((es_str_t**)s1), *((es_str_t**)s2));
+}
+
+
+struct objlst*
+objlstNew(struct cnfobj *o)
+{
+ struct objlst *lst;
+
+ if((lst = malloc(sizeof(struct objlst))) != NULL) {
+ lst->next = NULL;
+ lst->obj = o;
+ }
+cnfobjPrint(o);
+
+ return lst;
+}
+
+/* add object to end of object list, always returns pointer to root object */
+struct objlst*
+objlstAdd(struct objlst *root, struct cnfobj *o)
+{
+ struct objlst *l;
+ struct objlst *newl;
+
+ newl = objlstNew(o);
+ if(root == 0) {
+ root = newl;
+ } else { /* find last, linear search ok, as only during config phase */
+ for(l = root ; l->next != NULL ; l = l->next)
+ ;
+ l->next = newl;
+ }
+ return root;
+}
+
+/* add stmt to current script, always return root stmt pointer */
+struct cnfstmt*
+scriptAddStmt(struct cnfstmt *root, struct cnfstmt *s)
+{
+ struct cnfstmt *l;
+
+ if(root == NULL) {
+ root = s;
+ } else { /* find last, linear search ok, as only during config phase */
+ for(l = root ; l->next != NULL ; l = l->next)
+ ;
+ l->next = s;
+ }
+ return root;
+}
+
+void
+objlstDestruct(struct objlst *lst)
+{
+ struct objlst *toDel;
+
+ while(lst != NULL) {
+ toDel = lst;
+ lst = lst->next;
+ cnfobjDestruct(toDel->obj);
+ free(toDel);
+ }
+}
+
+void
+objlstPrint(struct objlst *lst)
+{
+ dbgprintf("objlst %p:\n", lst);
+ while(lst != NULL) {
+ cnfobjPrint(lst->obj);
+ lst = lst->next;
+ }
+}
+
+struct nvlst* ATTR_NONNULL(1)
+nvlstNewStr(es_str_t *const value)
+{
+ struct nvlst *lst;
+
+ if((lst = malloc(sizeof(struct nvlst))) != NULL) {
+ lst->next = NULL;
+ lst->val.datatype = 'S';
+ lst->val.d.estr = value;
+ lst->bUsed = 0;
+ }
+
+ return lst;
+}
+
+struct nvlst* ATTR_NONNULL(1)
+nvlstNewStrBackticks(es_str_t *const value)
+{
+ es_str_t *val = NULL;
+ const char *realval;
+
+ char *const param = es_str2cstr(value, NULL);
+ if(param == NULL)
+ goto done;
+
+ if(strncmp(param, "echo $", sizeof("echo $")-1) != 0) {
+ parser_errmsg("invalid backtick parameter `%s` currently "
+ "only `echo $<var>` is supported - replaced by "
+ "empty strong (\"\")", param);
+ realval = NULL;
+ } else {
+ size_t i;
+ const size_t len = strlen(param);
+ for(i = len - 1 ; isspace(param[i]) ; --i) {
+ ; /* just go down */
+ }
+ if(i > 6 && i < len - 1) {
+ param[i+1] = '\0';
+ }
+ realval = getenv(param+6);
+ }
+
+ free((void*)param);
+ if(realval == NULL) {
+ realval = "";
+ }
+ val = es_newStrFromCStr(realval, strlen(realval));
+ es_deleteStr(value);
+
+done:
+ return (val == NULL) ? NULL : nvlstNewStr(val);
+}
+
+struct nvlst*
+nvlstNewArray(struct cnfarray *ar)
+{
+ struct nvlst *lst;
+
+ if((lst = malloc(sizeof(struct nvlst))) != NULL) {
+ lst->next = NULL;
+ lst->val.datatype = 'A';
+ lst->val.d.ar = ar;
+ lst->bUsed = 0;
+ }
+
+ return lst;
+}
+
+struct nvlst*
+nvlstSetName(struct nvlst *lst, es_str_t *name)
+{
+ lst->name = name;
+ return lst;
+}
+
+void
+nvlstDestruct(struct nvlst *lst)
+{
+ struct nvlst *toDel;
+
+ while(lst != NULL) {
+ toDel = lst;
+ lst = lst->next;
+ es_deleteStr(toDel->name);
+ varDelete(&toDel->val);
+ free(toDel);
+ }
+}
+
+void
+nvlstPrint(struct nvlst *lst)
+{
+ char *name, *value;
+ dbgprintf("nvlst %p:\n", lst);
+ while(lst != NULL) {
+ name = es_str2cstr(lst->name, NULL);
+ switch(lst->val.datatype) {
+ case 'A':
+ dbgprintf("\tname: '%s':\n", name);
+ cnfarrayPrint(lst->val.d.ar, 5);
+ break;
+ case 'S':
+ value = es_str2cstr(lst->val.d.estr, NULL);
+ dbgprintf("\tname: '%s', value '%s'\n", name, value);
+ free(value);
+ break;
+ default:dbgprintf("nvlstPrint: unknown type '%s'\n",
+ tokenToString(lst->val.datatype));
+ break;
+ }
+ free(name);
+ lst = lst->next;
+ }
+}
+
+/* find a name starting at node lst. Returns node with this
+ * name or NULL, if none found.
+ */
+struct nvlst*
+nvlstFindName(struct nvlst *lst, es_str_t *name)
+{
+ while(lst != NULL && es_strcmp(lst->name, name))
+ lst = lst->next;
+ return lst;
+}
+
+
+/* find a name starting at node lst. Same as nvlstFindName, but
+ * for classical C strings. This is useful because the config system
+ * uses C string constants.
+ */
+static struct nvlst*
+nvlstFindNameCStr(struct nvlst *lst, const char *const __restrict__ name)
+{
+ es_size_t lenName = strlen(name);
+ while(lst != NULL && es_strcasebufcmp(lst->name, (uchar*)name, lenName))
+ lst = lst->next;
+ return lst;
+}
+
+/* check if the nvlst is disabled, and mark config.enabled directive
+ * as used if it is not. Returns 1 if block is disabled, 0 otherwise.
+ */
+int nvlstChkDisabled(struct nvlst *lst)
+{
+ struct nvlst *valnode;
+
+ if((valnode = nvlstFindNameCStr(lst, "config.enabled")) != NULL) {
+ valnode->bUsed = 1;
+ if(es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+/* check if there are duplicate names inside a nvlst and emit
+ * an error message, if so.
+ */
+static void
+nvlstChkDupes(struct nvlst *lst)
+{
+ char *cstr;
+
+ while(lst != NULL) {
+ if(nvlstFindName(lst->next, lst->name) != NULL) {
+ cstr = es_str2cstr(lst->name, NULL);
+ parser_errmsg("duplicate parameter '%s' -- "
+ "interpretation is ambiguous, one value "
+ "will be randomly selected. Fix this problem.",
+ cstr);
+ free(cstr);
+ }
+ lst = lst->next;
+ }
+}
+
+
+/* check for unused params and emit error message is found. This must
+ * be called after all config params have been pulled from the object
+ * (otherwise the flags are not correctly set).
+ */
+void
+nvlstChkUnused(struct nvlst *lst)
+{
+ char *cstr;
+
+ while(lst != NULL) {
+ if(!lst->bUsed) {
+ cstr = es_str2cstr(lst->name, NULL);
+ parser_errmsg("parameter '%s' not known -- "
+ "typo in config file?",
+ cstr);
+ free(cstr);
+ }
+ lst = lst->next;
+ }
+}
+
+
+static int
+doGetSize(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ unsigned char *c;
+ es_size_t i;
+ long long n;
+ int r;
+ c = es_getBufAddr(valnode->val.d.estr);
+ n = 0;
+ i = 0;
+ while(i < es_strlen(valnode->val.d.estr) && isdigit(*c)) {
+ n = 10 * n + *c - '0';
+ ++i;
+ ++c;
+ }
+ if(i < es_strlen(valnode->val.d.estr)) {
+ ++i;
+ switch(*c) {
+ /* traditional binary-based definitions */
+ case 'k': n *= 1024; break;
+ case 'm': n *= 1024 * 1024; break;
+ case 'g': n *= 1024 * 1024 * 1024; break;
+ case 't': n *= (int64) 1024 * 1024 * 1024 * 1024; break; /* tera */
+ case 'p': n *= (int64) 1024 * 1024 * 1024 * 1024 * 1024; break; /* peta */
+ case 'e': n *= (int64) 1024 * 1024 * 1024 * 1024 * 1024 * 1024; break; /* exa */
+ /* and now the "new" 1000-based definitions */
+ case 'K': n *= 1000; break;
+ case 'M': n *= 1000000; break;
+ case 'G': n *= 1000000000; break;
+ /* we need to use the multiplication below because otherwise
+ * the compiler gets an error during constant parsing */
+ case 'T': n *= (int64) 1000 * 1000000000; break; /* tera */
+ case 'P': n *= (int64) 1000000 * 1000000000; break; /* peta */
+ case 'E': n *= (int64) 1000000000 * 1000000000; break; /* exa */
+ default: --i; break; /* indicates error */
+ }
+ }
+ if(i == es_strlen(valnode->val.d.estr)) {
+ val->val.datatype = 'N';
+ val->val.d.n = n;
+ r = 1;
+ } else {
+ parser_errmsg("parameter '%s' does not contain a valid size",
+ param->name);
+ r = 0;
+ }
+ return r;
+}
+
+
+static int
+doGetBinary(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ int r = 1;
+ val->val.datatype = 'N';
+ if(!es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) {
+ val->val.d.n = 1;
+ } else if(!es_strbufcmp(valnode->val.d.estr, (unsigned char*) "off", 3)) {
+ val->val.d.n = 0;
+ } else {
+ parser_errmsg("parameter '%s' must be \"on\" or \"off\" but "
+ "is neither. Results unpredictable.", param->name);
+ val->val.d.n = 0;
+ r = 0;
+ }
+ return r;
+}
+
+static int
+doGetQueueType(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ char *cstr;
+ int r = 1;
+ if(!es_strcasebufcmp(valnode->val.d.estr, (uchar*)"fixedarray", 10)) {
+ val->val.d.n = QUEUETYPE_FIXED_ARRAY;
+ } else if(!es_strcasebufcmp(valnode->val.d.estr, (uchar*)"linkedlist", 10)) {
+ val->val.d.n = QUEUETYPE_LINKEDLIST;
+ } else if(!es_strcasebufcmp(valnode->val.d.estr, (uchar*)"disk", 4)) {
+ val->val.d.n = QUEUETYPE_DISK;
+ } else if(!es_strcasebufcmp(valnode->val.d.estr, (uchar*)"direct", 6)) {
+ val->val.d.n = QUEUETYPE_DIRECT;
+ } else {
+ cstr = es_str2cstr(valnode->val.d.estr, NULL);
+ parser_errmsg("param '%s': unknown queue type: '%s'",
+ param->name, cstr);
+ free(cstr);
+ r = 0;
+ }
+ val->val.datatype = 'N';
+ return r;
+}
+
+
+/* A file create-mode must be a four-digit octal number
+ * starting with '0'.
+ */
+static int
+doGetFileCreateMode(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ int fmtOK = 0;
+ char *cstr;
+ uchar *c;
+ const int len_val = es_strlen(valnode->val.d.estr);
+
+ if(len_val >= 4) {
+ c = es_getBufAddr(valnode->val.d.estr);
+ if( (c[0] == '0')
+ && (c[1] >= '0' && c[1] <= '7')
+ && (c[2] >= '0' && c[2] <= '7')
+ && (c[3] >= '0' && c[3] <= '7') ) {
+ if(len_val == 5) {
+ if(c[4] >= '0' && c[4] <= '7') {
+ fmtOK = 1;
+ }
+ } else {
+ fmtOK = 1;
+ }
+ }
+ }
+
+ if(fmtOK) {
+ val->val.datatype = 'N';
+ val->val.d.n = (c[1]-'0') * 64 + (c[2]-'0') * 8 + (c[3]-'0');
+ if(len_val == 5) {
+ val->val.d.n = val->val.d.n * 8 + (c[4]-'0');
+ }
+ } else {
+ cstr = es_str2cstr(valnode->val.d.estr, NULL);
+ parser_errmsg("file modes need to be specified as "
+ "4- or 5-digit octal numbers starting with '0' -"
+ "parameter '%s=\"%s\"' is not a file mode",
+ param->name, cstr);
+ free(cstr);
+ }
+ return fmtOK;
+}
+
+static int
+doGetGID(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ char *cstr;
+ int r;
+ struct group *resultBuf = NULL;
+ struct group wrkBuf;
+ char *stringBuf = NULL;
+ size_t bufSize = 1024;
+ int e;
+
+ cstr = es_str2cstr(valnode->val.d.estr, NULL);
+ do {
+ char *p;
+
+ /* Increase bufsize and try again.*/
+ bufSize *= 2;
+ p = realloc(stringBuf, bufSize);
+ if(!p) {
+ e = ENOMEM;
+ break;
+ }
+ stringBuf = p;
+ e = getgrnam_r(cstr, &wrkBuf, stringBuf, bufSize, &resultBuf);
+ } while(!resultBuf && (e == ERANGE));
+
+ if(resultBuf == NULL) {
+ if(e != 0) {
+ if(loadConf->globals.abortOnIDResolutionFail) {
+ fprintf(stderr, "parameter '%s': error to "
+ "obtaining group id for '%s'", param->name, cstr);
+ exit(1); /* good exit */
+ } else {
+ LogError(e, RS_RET_ERR, "parameter '%s': error to "
+ "obtaining group id for '%s'", param->name, cstr);
+ }
+ }
+ parser_errmsg("parameter '%s': ID for group %s could not "
+ "be found", param->name, cstr);
+ r = 0;
+ } else {
+ val->val.datatype = 'N';
+ val->val.d.n = resultBuf->gr_gid;
+ DBGPRINTF("param '%s': uid %d obtained for group '%s'\n",
+ param->name, (int) resultBuf->gr_gid, cstr);
+ r = 1;
+ }
+ free(stringBuf);
+ free(cstr);
+ return r;
+}
+
+static int
+doGetUID(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ char *cstr;
+ int r;
+ struct passwd *resultBuf;
+ struct passwd wrkBuf;
+ char stringBuf[2048]; /* 2048 has been proven to be large enough */
+ char errStr[1024];
+
+ cstr = es_str2cstr(valnode->val.d.estr, NULL);
+ const int err_no = getpwnam_r(cstr, &wrkBuf, stringBuf, sizeof(stringBuf), &resultBuf);
+ if(resultBuf == NULL) {
+ rs_strerror_r((err_no == 0) ? ENOENT : errno, errStr, sizeof(errStr));
+ if(loadConf->globals.abortOnIDResolutionFail) {
+ fprintf(stderr, "parameter '%s': ID for user '%s' could not "
+ "be found: %s", param->name, cstr, errStr);
+ exit(1); /* good exit */
+ } else {
+ LogError(err_no, RS_RET_ERR, "parameter '%s': ID for user '%s' could not "
+ "be found: %s", param->name, cstr, errStr);
+ parser_errmsg("parameter '%s': ID for user '%s' could not "
+ "be found: %s", param->name, cstr, errStr);
+ }
+
+ r = 0;
+ } else {
+ val->val.datatype = 'N';
+ val->val.d.n = resultBuf->pw_uid;
+ DBGPRINTF("param '%s': uid %d obtained for user '%s'\n",
+ param->name, (int) resultBuf->pw_uid, cstr);
+ r = 1;
+ }
+ free(cstr);
+ return r;
+}
+
+/* note: we support all integer formats that es_str2num support,
+ * so hex and octal representations are also valid.
+ */
+static int
+doGetInt(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ long long n;
+ int bSuccess;
+
+ n = es_str2num(valnode->val.d.estr, &bSuccess);
+ if(!bSuccess) {
+ parser_errmsg("parameter '%s' is not a proper number",
+ param->name);
+ }
+ val->val.datatype = 'N';
+ val->val.d.n = n;
+ return bSuccess;
+}
+
+static int
+doGetNonNegInt(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ int bSuccess;
+
+ if((bSuccess = doGetInt(valnode, param, val))) {
+ if(val->val.d.n < 0) {
+ parser_errmsg("parameter '%s' cannot be less than zero (was %lld)",
+ param->name, val->val.d.n);
+ bSuccess = 0;
+ }
+ }
+ return bSuccess;
+}
+
+static int
+doGetPositiveInt(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ int bSuccess;
+
+ if((bSuccess = doGetInt(valnode, param, val))) {
+ if(val->val.d.n < 1) {
+ parser_errmsg("parameter '%s' cannot be less than one (was %lld)",
+ param->name, val->val.d.n);
+ bSuccess = 0;
+ }
+ }
+ return bSuccess;
+}
+
+static int
+doGetWord(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ es_size_t i;
+ int r = 1;
+ unsigned char *c;
+
+ val->val.datatype = 'S';
+ val->val.d.estr = es_newStr(32);
+ c = es_getBufAddr(valnode->val.d.estr);
+ for(i = 0 ; i < es_strlen(valnode->val.d.estr) && !isspace(c[i]) ; ++i) {
+ es_addChar(&val->val.d.estr, c[i]);
+ }
+ if(i != es_strlen(valnode->val.d.estr)) {
+ parser_errmsg("parameter '%s' contains whitespace, which is not "
+ "permitted",
+ param->name);
+ r = 0;
+ }
+ return r;
+}
+
+static int
+doGetArray(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ int r = 1;
+
+ switch(valnode->val.datatype) {
+ case 'S':
+ /* a constant string is assumed to be a single-element array */
+ val->val.datatype = 'A';
+ val->val.d.ar = cnfarrayNew(es_strdup(valnode->val.d.estr));
+ break;
+ case 'A':
+ val->val.datatype = 'A';
+ val->val.d.ar = cnfarrayDup(valnode->val.d.ar);
+ break;
+ default:parser_errmsg("parameter '%s' must be an array, but is a "
+ "different datatype", param->name);
+ r = 0;
+ break;
+ }
+ return r;
+}
+
+static int
+doGetChar(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ int r = 1;
+ if(es_strlen(valnode->val.d.estr) != 1) {
+ parser_errmsg("parameter '%s' must contain exactly one character "
+ "but contains %d - cannot be processed",
+ param->name, es_strlen(valnode->val.d.estr));
+ r = 0;
+ }
+ val->val.datatype = 'S';
+ val->val.d.estr = es_strdup(valnode->val.d.estr);
+ return r;
+}
+
+/* get a single parameter according to its definition. Helper to
+ * nvlstGetParams. returns 1 if success, 0 otherwise
+ */
+static int
+nvlstGetParam(struct nvlst *valnode, struct cnfparamdescr *param,
+ struct cnfparamvals *val)
+{
+ uchar *cstr;
+ int r;
+
+ DBGPRINTF("nvlstGetParam: name '%s', type %d, valnode->bUsed %d\n",
+ param->name, (int) param->type, valnode->bUsed);
+ if(valnode->val.datatype != 'S' && param->type != eCmdHdlrArray) {
+ parser_errmsg("parameter '%s' is not a string, which is not "
+ "permitted",
+ param->name);
+ r = 0;
+ goto done;
+ }
+ valnode->bUsed = 1;
+ val->bUsed = 1;
+ switch(param->type) {
+ case eCmdHdlrQueueType:
+ r = doGetQueueType(valnode, param, val);
+ break;
+ case eCmdHdlrUID:
+ r = doGetUID(valnode, param, val);
+ break;
+ case eCmdHdlrGID:
+ r = doGetGID(valnode, param, val);
+ break;
+ case eCmdHdlrBinary:
+ r = doGetBinary(valnode, param, val);
+ break;
+ case eCmdHdlrFileCreateMode:
+ r = doGetFileCreateMode(valnode, param, val);
+ break;
+ case eCmdHdlrInt:
+ r = doGetInt(valnode, param, val);
+ break;
+ case eCmdHdlrNonNegInt:
+ r = doGetNonNegInt(valnode, param, val);
+ break;
+ case eCmdHdlrPositiveInt:
+ r = doGetPositiveInt(valnode, param, val);
+ break;
+ case eCmdHdlrSize:
+ r = doGetSize(valnode, param, val);
+ break;
+ case eCmdHdlrGetChar:
+ r = doGetChar(valnode, param, val);
+ break;
+ case eCmdHdlrFacility:
+ cstr = (uchar*) es_str2cstr(valnode->val.d.estr, NULL);
+ val->val.datatype = 'N';
+ val->val.d.n = decodeSyslogName(cstr, syslogFacNames);
+ free(cstr);
+ r = 1;
+ break;
+ case eCmdHdlrSeverity:
+ cstr = (uchar*) es_str2cstr(valnode->val.d.estr, NULL);
+ val->val.datatype = 'N';
+ val->val.d.n = decodeSyslogName(cstr, syslogPriNames);
+ free(cstr);
+ r = 1;
+ break;
+ case eCmdHdlrGetWord:
+ r = doGetWord(valnode, param, val);
+ break;
+ case eCmdHdlrString:
+ val->val.datatype = 'S';
+ val->val.d.estr = es_strdup(valnode->val.d.estr);
+ r = 1;
+ break;
+ case eCmdHdlrArray:
+ r = doGetArray(valnode, param, val);
+ break;
+ case eCmdHdlrGoneAway:
+ parser_errmsg("parameter '%s' is no longer supported",
+ param->name);
+ r = 1; /* this *is* valid! */
+ break;
+ default:
+ DBGPRINTF("error: invalid param type\n");
+ r = 0;
+ break;
+ }
+done: return r;
+}
+
+
+/* obtain conf params from an nvlst and emit error messages if
+ * necessary. If an already-existing param value is passed, that is
+ * used. If NULL is passed instead, a new one is allocated. In that case,
+ * it is the caller's duty to free it when no longer needed.
+ * NULL is returned on error, otherwise a pointer to the vals array.
+ */
+struct cnfparamvals* ATTR_NONNULL(2)
+nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params,
+ struct cnfparamvals *vals)
+{
+#ifndef __clang_analyzer__ /* I give up on this one - let Coverity do the work */
+ int i;
+ int bValsWasNULL;
+ int bInError = 0;
+ struct nvlst *valnode;
+ struct cnfparamdescr *param;
+
+ if(params->version != CNFPARAMBLK_VERSION) {
+ DBGPRINTF("nvlstGetParams: invalid param block version "
+ "%d, expected %d\n",
+ params->version, CNFPARAMBLK_VERSION);
+ return NULL;
+ }
+
+ if(vals == NULL) {
+ bValsWasNULL = 1;
+ if((vals = calloc(params->nParams,
+ sizeof(struct cnfparamvals))) == NULL)
+ return NULL;
+ } else {
+ bValsWasNULL = 0;
+ }
+
+ for(i = 0 ; i < params->nParams ; ++i) {
+ param = params->descr + i;
+ if((valnode = nvlstFindNameCStr(lst, param->name)) == NULL) {
+ if(param->flags & CNFPARAM_REQUIRED) {
+ parser_errmsg("parameter '%s' required but not specified - "
+ "fix config", param->name);
+ bInError = 1;
+ }
+ continue;
+ }
+ if(param->flags & CNFPARAM_DEPRECATED) {
+ parser_errmsg("parameter '%s' deprecated but accepted, consider "
+ "removing or replacing it", param->name);
+ }
+ if(vals[i].bUsed) {
+ parser_errmsg("parameter '%s' specified more than once - "
+ "one instance is ignored. Fix config", param->name);
+ continue;
+ }
+ if(!nvlstGetParam(valnode, param, vals + i)) {
+ bInError = 1;
+ }
+ }
+
+ /* done parameter processing */
+ if(bInError) {
+ if(bValsWasNULL)
+ cnfparamvalsDestruct(vals, params);
+ vals = NULL;
+ }
+
+ return vals;
+#else
+ return NULL;
+#endif
+}
+
+
+/* check if at least one cnfparamval is actually set
+ * returns 1 if so, 0 otherwise
+ */
+int
+cnfparamvalsIsSet(struct cnfparamblk *params, struct cnfparamvals *vals)
+{
+ int i;
+
+ if(vals == NULL)
+ return 0;
+ if(params->version != CNFPARAMBLK_VERSION) {
+ DBGPRINTF("nvlstGetParams: invalid param block version "
+ "%d, expected %d\n",
+ params->version, CNFPARAMBLK_VERSION);
+ return 0;
+ }
+ for(i = 0 ; i < params->nParams ; ++i) {
+ if(vals[i].bUsed)
+ return 1;
+ }
+ return 0;
+}
+
+
+void
+cnfparamsPrint(const struct cnfparamblk *params, const struct cnfparamvals *vals)
+{
+ int i;
+ char *cstr;
+
+ if(!Debug)
+ return;
+
+ for(i = 0 ; i < params->nParams ; ++i) {
+ dbgprintf("%s: ", params->descr[i].name);
+ if(vals[i].bUsed) {
+ // TODO: other types!
+ switch(vals[i].val.datatype) {
+ case 'S':
+ cstr = es_str2cstr(vals[i].val.d.estr, NULL);
+ dbgprintf(" '%s'", cstr);
+ free(cstr);
+ break;
+ case 'A':
+ cnfarrayPrint(vals[i].val.d.ar, 0);
+ break;
+ case 'N':
+ dbgprintf("%lld", vals[i].val.d.n);
+ break;
+ default:
+ dbgprintf("(unsupported datatype %c)",
+ vals[i].val.datatype);
+ }
+ } else {
+ dbgprintf("(unset)");
+ }
+ dbgprintf("\n");
+ }
+}
+
+struct cnfobj*
+cnfobjNew(enum cnfobjType objType, struct nvlst *lst)
+{
+ struct cnfobj *o;
+
+ if((o = malloc(sizeof(struct cnfobj))) != NULL) {
+ nvlstChkDupes(lst);
+ o->objType = objType;
+ o->nvlst = lst;
+ o->subobjs = NULL;
+ o->script = NULL;
+ }
+
+ return o;
+}
+
+void
+cnfobjDestruct(struct cnfobj *o)
+{
+ if(o != NULL) {
+ nvlstDestruct(o->nvlst);
+ objlstDestruct(o->subobjs);
+ free(o);
+ }
+}
+
+void
+cnfobjPrint(struct cnfobj *o)
+{
+ dbgprintf("obj: '%s'\n", cnfobjType2str(o->objType));
+ nvlstPrint(o->nvlst);
+}
+
+
+struct cnfexpr*
+cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r)
+{
+ struct cnfexpr *expr;
+
+ /* optimize some constructs during parsing */
+ if(nodetype == 'M' && r->nodetype == 'N') {
+ ((struct cnfnumval*)r)->val *= -1;
+ expr = r;
+ goto done;
+ }
+
+ if((expr = malloc(sizeof(struct cnfexpr))) != NULL) {
+ expr->nodetype = nodetype;
+ expr->l = l;
+ expr->r = r;
+ }
+done:
+ return expr;
+}
+
+
+static int64_t
+str2num(es_str_t *s, int *bSuccess)
+{
+ size_t i;
+ int neg;
+ int64_t num = 0;
+ const uchar *const c = es_getBufAddr(s);
+
+ if(s->lenStr == 0) {
+ DBGPRINTF("rainerscript: str2num: strlen == 0; invalid input (no string)\n");
+ if(bSuccess != NULL) {
+ *bSuccess = 1;
+ }
+ goto done;
+ }
+ if(c[0] == '-') {
+ neg = -1;
+ i = 1;
+ } else {
+ neg = 1;
+ i = 0;
+ }
+ while(i < s->lenStr && isdigit(c[i])) {
+ num = num * 10 + c[i] - '0';
+ ++i;
+ }
+ num *= neg;
+ if(bSuccess != NULL)
+ *bSuccess = (i == s->lenStr) ? 1 : 0;
+done:
+ return num;
+}
+
+/* We support decimal integers. Unfortunately, previous versions
+ * said they support oct and hex, but that wasn't really the case.
+ * Everything based on JSON was just dec-converted. As this was/is
+ * the norm, we fix that inconsistency. Luckly, oct and hex support
+ * was never documented.
+ * rgerhards, 2015-11-12
+ */
+long long
+var2Number(struct svar *r, int *bSuccess)
+{
+ long long n = 0;
+ if(r->datatype == 'S') {
+ n = str2num(r->d.estr, bSuccess);
+ } else {
+ if(r->datatype == 'J') {
+ n = (r->d.json == NULL) ? 0 : json_object_get_int64(r->d.json);
+ } else {
+ n = r->d.n;
+ }
+ if(bSuccess != NULL)
+ *bSuccess = 1;
+ }
+ return n;
+}
+
+/* ensure that retval is a string
+ */
+static es_str_t *
+var2String(struct svar *__restrict__ const r, int *__restrict__ const bMustFree)
+{
+ es_str_t *estr;
+ const char *cstr;
+ rs_size_t lenstr;
+ if(r->datatype == 'N') {
+ *bMustFree = 1;
+ estr = es_newStrFromNumber(r->d.n);
+ } else if(r->datatype == 'J') {
+ *bMustFree = 1;
+ if(r->d.json == NULL) {
+ cstr = "",
+ lenstr = 0;
+ } else {
+ cstr = (char*)json_object_get_string(r->d.json);
+ lenstr = strlen(cstr);
+ }
+ estr = es_newStrFromCStr(cstr, lenstr);
+ } else {
+ *bMustFree = 0;
+ estr = r->d.estr;
+ }
+ return estr;
+}
+
+uchar*
+var2CString(struct svar *__restrict__ const r, int *__restrict__ const bMustFree)
+{
+ uchar *cstr;
+ es_str_t *estr;
+ estr = var2String(r, bMustFree);
+ cstr = (uchar*) es_str2cstr(estr, NULL);
+ if(*bMustFree)
+ es_deleteStr(estr);
+ *bMustFree = 1;
+ return cstr;
+}
+
+/* frees struct svar members, but not the struct itself. This is because
+ * it usually is allocated on the stack. Callers why dynamically allocate
+ * struct svar need to free the struct themselfes!
+ */
+
+int SKIP_NOTHING = 0x0;
+int SKIP_STRING = 0x1;
+
+static void
+varFreeMembersSelectively(const struct svar *r, const int skipMask)
+{
+ if(r->datatype == 'J') {
+ json_object_put(r->d.json);
+ } else if( !(skipMask & SKIP_STRING) && (r->datatype == 'S')) {
+ es_deleteStr(r->d.estr);
+ }
+}
+
+void
+varFreeMembers(const struct svar *r)
+{
+ varFreeMembersSelectively(r, SKIP_NOTHING);
+}
+
+
+static rsRetVal
+doExtractFieldByChar(uchar *str, uchar delim, const int matchnbr, uchar **resstr)
+{
+ int iCurrFld;
+ int allocLen;
+ int iLen;
+ uchar *pBuf;
+ uchar *pFld;
+ uchar *pFldEnd;
+ DEFiRet;
+
+ /* first, skip to the field in question */
+ iCurrFld = 1;
+ pFld = str;
+ while(*pFld && iCurrFld < matchnbr) {
+ /* skip fields until the requested field or end of string is found */
+ while(*pFld && (uchar) *pFld != delim)
+ ++pFld; /* skip to field terminator */
+ if(*pFld == delim) {
+ ++pFld; /* eat it */
+ ++iCurrFld;
+ }
+ }
+ DBGPRINTF("field() field requested %d, field found %d\n", matchnbr, iCurrFld);
+
+ if(iCurrFld == matchnbr) {
+ /* field found, now extract it */
+ /* first of all, we need to find the end */
+ pFldEnd = pFld;
+ while(*pFldEnd && *pFldEnd != delim)
+ ++pFldEnd;
+ --pFldEnd; /* we are already at the delimiter - so we need to
+ * step back a little not to copy it as part of the field. */
+ /* we got our end pointer, now do the copy */
+ iLen = pFldEnd - pFld + 1; /* the +1 is for an actual char, NOT \0! */
+ allocLen = iLen + 1;
+# ifdef VALGRIND
+ allocLen += (3 - (iLen % 4));
+ /*older versions of valgrind have a problem with strlen inspecting 4-bytes at a time*/
+# endif
+ CHKmalloc(pBuf = malloc(allocLen));
+ /* now copy */
+ memcpy(pBuf, pFld, iLen);
+ pBuf[iLen] = '\0'; /* terminate it */
+ *resstr = pBuf;
+ } else {
+ ABORT_FINALIZE(RS_RET_FIELD_NOT_FOUND);
+ }
+finalize_it:
+ RETiRet;
+}
+
+
+static rsRetVal
+doExtractFieldByStr(uchar *str, char *delim, const rs_size_t lenDelim, const int matchnbr, uchar **resstr)
+{
+ int iCurrFld;
+ int iLen;
+ uchar *pBuf;
+ uchar *pFld;
+ uchar *pFldEnd;
+ DEFiRet;
+
+ if (str == NULL || delim == NULL)
+ ABORT_FINALIZE(RS_RET_FIELD_NOT_FOUND);
+
+ /* first, skip to the field in question */
+ iCurrFld = 1;
+ pFld = str;
+ while(pFld != NULL && iCurrFld < matchnbr) {
+ if((pFld = (uchar*) strstr((char*)pFld, delim)) != NULL) {
+ pFld += lenDelim;
+ ++iCurrFld;
+ }
+ }
+ DBGPRINTF("field() field requested %d, field found %d\n", matchnbr, iCurrFld);
+
+ if(iCurrFld == matchnbr) {
+ /* field found, now extract it */
+ /* first of all, we need to find the end */
+ pFldEnd = (uchar*) strstr((char*)pFld, delim);
+ if(pFldEnd == NULL) {
+ iLen = strlen((char*) pFld);
+ } else { /* found delmiter! Note that pFldEnd *is* already on
+ * the first delmi char, we don't need that. */
+ iLen = pFldEnd - pFld;
+ }
+ /* we got our end pointer, now do the copy */
+ CHKmalloc(pBuf = malloc(iLen + 1));
+ /* now copy */
+ memcpy(pBuf, pFld, iLen);
+ pBuf[iLen] = '\0'; /* terminate it */
+ *resstr = pBuf;
+ } else {
+ ABORT_FINALIZE(RS_RET_FIELD_NOT_FOUND);
+ }
+finalize_it:
+ RETiRet;
+}
+
+static void
+doFunc_re_extract(struct cnffunc *func, struct svar *ret, void* usrptr, wti_t *const pWti)
+{
+ size_t submatchnbr;
+ short matchnbr;
+ regmatch_t pmatch[50];
+ int bMustFree;
+ es_str_t *estr = NULL; /* init just to keep compiler happy */
+ char *str;
+ struct svar r[CNFFUNC_MAX_ARGS];
+ int iLenBuf;
+ unsigned iOffs;
+ short iTry = 0;
+ uchar bFound = 0;
+ iOffs = 0;
+ sbool bHadNoMatch = 0;
+
+ cnfexprEval(func->expr[0], &r[0], usrptr, pWti);
+ /* search string is already part of the compiled regex, so we don't
+ * need it here!
+ */
+ cnfexprEval(func->expr[2], &r[2], usrptr, pWti);
+ cnfexprEval(func->expr[3], &r[3], usrptr, pWti);
+ str = (char*) var2CString(&r[0], &bMustFree);
+ matchnbr = (short) var2Number(&r[2], NULL);
+ submatchnbr = (size_t) var2Number(&r[3], NULL);
+ if(submatchnbr >= sizeof(pmatch)/sizeof(regmatch_t)) {
+ DBGPRINTF("re_extract() submatch %zd is too large\n", submatchnbr);
+ bHadNoMatch = 1;
+ goto finalize_it;
+ }
+
+ /* first see if we find a match, iterating through the series of
+ * potential matches over the string.
+ */
+ while(!bFound) {
+ int iREstat;
+ iREstat = regexp.regexec(func->funcdata, (char*)(str + iOffs),
+ submatchnbr+1, pmatch, 0);
+ DBGPRINTF("re_extract: regexec return is %d\n", iREstat);
+ if(iREstat == 0) {
+ if(pmatch[0].rm_so == -1) {
+ DBGPRINTF("oops ... start offset of successful regexec is -1\n");
+ break;
+ }
+ if(iTry == matchnbr) {
+ bFound = 1;
+ } else {
+ DBGPRINTF("re_extract: regex found at offset %d, new offset %d, tries %d\n",
+ iOffs, (int) (iOffs + pmatch[0].rm_eo), iTry);
+ iOffs += pmatch[0].rm_eo;
+ ++iTry;
+ }
+ } else {
+ break;
+ }
+ }
+ DBGPRINTF("re_extract: regex: end search, found %d\n", bFound);
+ if(!bFound) {
+ bHadNoMatch = 1;
+ goto finalize_it;
+ } else {
+ /* Match- but did it match the one we wanted? */
+ /* we got no match! */
+ if(pmatch[submatchnbr].rm_so == -1) {
+ bHadNoMatch = 1;
+ goto finalize_it;
+ }
+ /* OK, we have a usable match - we now need to malloc pB */
+ iLenBuf = pmatch[submatchnbr].rm_eo - pmatch[submatchnbr].rm_so;
+ estr = es_newStrFromBuf(str + iOffs + pmatch[submatchnbr].rm_so,
+ iLenBuf);
+ }
+
+finalize_it:
+ if(bMustFree) free(str);
+ varFreeMembers(&r[0]);
+ varFreeMembers(&r[2]);
+ varFreeMembers(&r[3]);
+
+ if(bHadNoMatch) {
+ cnfexprEval(func->expr[4], &r[4], usrptr, pWti);
+ estr = var2String(&r[4], &bMustFree);
+ varFreeMembersSelectively(&r[4], SKIP_STRING);
+ /* Note that we do NOT free the string that was returned/created
+ * for r[4]. We pass it to the caller, which in turn frees it.
+ * This saves us doing one unnecessary memory alloc & write.
+ */
+ }
+ ret->datatype = 'S';
+ ret->d.estr = estr;
+ return;
+}
+
+
+/* note that we do not need to evaluate any parameters, as the template pointer
+ * is set during initialization().
+ * TODO: think if we can keep our buffer; but that may not be trival thinking about
+ * multiple threads.
+ */
+static void
+doFunc_exec_template(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *const usrptr,
+ wti_t *const pWti __attribute__((unused)))
+{
+ smsg_t *const pMsg = (smsg_t*) usrptr;
+ rsRetVal localRet;
+ actWrkrIParams_t iparam;
+
+ wtiInitIParam(&iparam);
+ localRet = tplToString(func->funcdata, pMsg, &iparam, NULL);
+ if(localRet == RS_RET_OK) {
+ ret->d.estr = es_newStrFromCStr((char*)iparam.param, iparam.lenStr);
+ } else {
+ ret->d.estr = es_newStrFromCStr("", 0);
+ }
+ ret->datatype = 'S';
+ free(iparam.param);
+
+ return;
+}
+
+static es_str_t*
+doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restrict__ const findVal,
+ struct svar *__restrict__ const replaceWithVal) {
+ int freeOperand, freeFind, freeReplacement;
+ es_str_t *str = var2String(operandVal, &freeOperand);
+ es_str_t *findStr = var2String(findVal, &freeFind);
+ es_str_t *replaceWithStr = var2String(replaceWithVal, &freeReplacement);
+ uchar *find = es_getBufAddr(findStr);
+ uchar *replaceWith = es_getBufAddr(replaceWithStr);
+ uint lfind = es_strlen(findStr);
+ uint lReplaceWith = es_strlen(replaceWithStr);
+ uint lSrc = es_strlen(str);
+ uint lDst = 0;
+ uchar* src_buff = es_getBufAddr(str);
+ uint i, j;
+ for(i = j = 0; i <= lSrc; i++, lDst++) {
+ if (j == lfind) {
+ lDst = lDst - lfind + lReplaceWith;
+ j = 0;
+ }
+ if (i == lSrc) break;
+ if (src_buff[i] == find[j]) {
+ j++;
+ } else if (j > 0) {
+ i -= (j - 1);
+ lDst -= (j - 1);
+ j = 0;
+ }
+ }
+ es_str_t *res = es_newStr(lDst);
+ unsigned char* dest = es_getBufAddr(res);
+ uint k, s;
+ for(i = j = s = 0; i <= lSrc; i++, s++) {
+ if (j == lfind) {
+ s -= j;
+ for (k = 0; k < lReplaceWith; k++, s++) dest[s] = replaceWith[k];
+ j = 0;
+ }
+ if (i == lSrc) break;
+ if (src_buff[i] == find[j]) {
+ j++;
+ } else {
+ if (j > 0) {
+ i -= j;
+ s -= j;
+ j = 0;
+ }
+ dest[s] = src_buff[i];
+ }
+ }
+ if (j > 0) {
+ for (k = 1; k <= j; k++) dest[s - k] = src_buff[i - k];
+ }
+ res->lenStr = lDst;
+ if(freeOperand) es_deleteStr(str);
+ if(freeFind) es_deleteStr(findStr);
+ if(freeReplacement) es_deleteStr(replaceWithStr);
+ return res;
+}
+
+
+static void ATTR_NONNULL()
+doFunc_parse_json(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *const usrptr,
+ wti_t *const pWti)
+{
+ struct svar srcVal[2];
+ int bMustFree;
+ int bMustFree2;
+ smsg_t *const pMsg = (smsg_t*)usrptr;
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+ char *jsontext = (char*) var2CString(&srcVal[0], &bMustFree);
+ char *container = (char*) var2CString(&srcVal[1], &bMustFree2);
+ struct json_object *json;
+
+ int retVal;
+ assert(jsontext != NULL);
+ assert(container != NULL);
+ assert(pMsg != NULL);
+
+ struct json_tokener *const tokener = json_tokener_new();
+ if(tokener == NULL) {
+ retVal = 1;
+ goto finalize_it;
+ }
+ json = json_tokener_parse_ex(tokener, jsontext, strlen(jsontext));
+ if(json == NULL) {
+ retVal = RS_SCRIPT_EINVAL;
+ } else {
+ size_t off = (*container == '$') ? 1 : 0;
+ msgAddJSON(pMsg, (uchar*)container+off, json, 0, 0);
+ retVal = RS_SCRIPT_EOK;
+ }
+ wtiSetScriptErrno(pWti, retVal);
+ json_tokener_free(tokener);
+
+
+finalize_it:
+ ret->datatype = 'N';
+ ret->d.n = retVal;
+
+ if(bMustFree) {
+ free(jsontext);
+ }
+ if(bMustFree2) {
+ free(container);
+ }
+ varFreeMembers(&srcVal[0]);
+ varFreeMembers(&srcVal[1]);
+}
+
+
+static void ATTR_NONNULL()
+doFunc_get_property(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *const usrptr,
+ wti_t *const pWti)
+{
+ int retVal = RS_SCRIPT_EOK;
+ int bMustFree = 0;
+ char *expr = NULL;
+ struct svar srcVal[2] = {{.d={0}, .datatype=0}};
+ struct json_object *json = NULL;
+
+ /* ignore string literals */
+ if (func->expr[0]->nodetype == 'S') {
+ retVal = RS_SCRIPT_EINVAL;
+ FINALIZE;
+ }
+
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+ DBGPRINTF("srcval[0] datatype: %c\n", srcVal[0].datatype);
+ DBGPRINTF("srcval[1] datatype: %c\n", srcVal[1].datatype);
+
+ switch (srcVal[0].datatype) {
+ case 'J': {
+ json = srcVal[0].d.json;
+ break;
+ }
+ case 'S': {
+ ret->d.estr = es_strdup(srcVal[0].d.estr);
+ ret->datatype = 'S';
+ FINALIZE;
+ break;
+ }
+ default: {
+ ret->d.estr = es_newStrFromCStr("", 1);
+ ret->datatype = 'S';
+ FINALIZE;
+ break;
+ }
+ }
+
+ switch (json_object_get_type(json)) {
+ case json_type_object: {
+ expr = (char*) var2CString(&srcVal[1], &bMustFree);
+ if (expr && expr[0] == '\0') {
+ ret->d.json = json_object_get(json);
+ ret->datatype = 'J';
+ break;
+ }
+ if (expr && !json_object_object_get_ex(json, (char*)expr, &ret->d.json)) {
+ retVal = RS_SCRIPT_EINVAL;
+ FINALIZE;
+ }
+ if (ret->d.json) {
+ ret->d.json = json_object_get(ret->d.json);
+ ret->datatype = 'J';
+ } else {
+ ret->d.estr = es_newStrFromCStr("", 1);
+ ret->datatype = 'S';
+ }
+ break;
+ }
+ case json_type_array: {
+ int success = 0;
+ long long index = var2Number(&srcVal[1], &success);
+ if (!success || index < 0 || (size_t)index >= sizeof(size_t)) {
+ retVal = RS_SCRIPT_EINVAL;
+ FINALIZE;
+ }
+ ret->d.json = json_object_array_get_idx(json, index);
+ if (ret->d.json) {
+ ret->d.json = json_object_get(ret->d.json);
+ ret->datatype = 'J';
+ } else {
+ ret->d.estr = es_newStrFromCStr("", 1);
+ ret->datatype = 'S';
+ }
+ break;
+ }
+ case json_type_boolean:
+ case json_type_int: {
+ ret->d.n = json_object_get_int64(json);
+ ret->datatype = 'N';
+ break;
+ }
+ case json_type_double: {
+ ret->d.n = json_object_get_double(json);
+ ret->datatype = 'N';
+ break;
+ }
+ case json_type_string: {
+ ret->d.estr = es_newStrFromCStr(json_object_get_string(json), json_object_get_string_len(json));
+ ret->datatype = 'S';
+ break;
+ }
+ case json_type_null: {
+ ret->datatype = 'S';
+ ret->d.estr = es_newStrFromCStr("", 1);
+ break;
+ }
+ default:
+ LogError(0, RS_RET_INTERNAL_ERROR,
+ "Warning - unhandled json type(%d) !!!!\n", json_object_get_type(json));
+ retVal = RS_SCRIPT_EINVAL;
+ break;
+ }
+
+finalize_it:
+ wtiSetScriptErrno(pWti, retVal);
+
+ if (retVal != RS_SCRIPT_EOK) {
+ ret->datatype = 'S';
+ ret->d.estr = es_newStrFromCStr("", 1);
+ }
+ if (bMustFree) {
+ free(expr);
+ }
+ varFreeMembers(&srcVal[0]);
+ varFreeMembers(&srcVal[1]);
+}
+
+static void ATTR_NONNULL()
+doFunct_RandomGen(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ int success = 0;
+ struct svar srcVal;
+ long long retVal;
+ long int x;
+
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ long long max = var2Number(&srcVal, &success);
+ if (! success) {
+ DBGPRINTF("rainerscript: random(max) didn't get a valid 'max' limit, defaulting random-number "
+ "value to 0");
+ retVal = 0;
+ goto done;
+ }
+ if(max == 0) {
+ DBGPRINTF("rainerscript: random(max) invalid, 'max' is zero, , defaulting random-number value to 0");
+ retVal = 0;
+ goto done;
+ }
+ x = labs(randomNumber());
+ if (max > MAX_RANDOM_NUMBER) {
+ DBGPRINTF("rainerscript: desired random-number range [0 - %lld] "
+ "is wider than supported limit of [0 - %d)\n",
+ max, MAX_RANDOM_NUMBER);
+ }
+
+ retVal = (x % max);
+done:
+ ret->d.n = retVal;
+ ret->datatype = 'N';
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_LTrim(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ char *str = (char*)var2CString(&srcVal, &bMustFree);
+
+ const int len = strlen(str);
+ int i;
+ es_str_t *estr = NULL;
+
+ for(i = 0; i < len; i++) {
+ if(str[i] != ' ') {
+ break;
+ }
+ }
+
+ estr = es_newStrFromCStr(str + i, len - i);
+
+ ret->d.estr = estr;
+ ret->datatype = 'S';
+ varFreeMembers(&srcVal);
+ if(bMustFree)
+ free(str);
+}
+
+static void ATTR_NONNULL()
+doFunct_RTrim(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ char *str = (char*)var2CString(&srcVal, &bMustFree);
+
+ int len = strlen(str);
+ int i;
+ es_str_t *estr = NULL;
+
+ for(i = (len - 1); i > 0; i--) {
+ if(str[i] != ' ') {
+ break;
+ }
+ }
+
+ if(i > 0 || str[0] != ' ') {
+ estr = es_newStrFromCStr(str, (i + 1));
+ } else {
+ estr = es_newStr(1);
+ }
+
+ ret->d.estr = estr;
+ ret->datatype = 'S';
+ varFreeMembers(&srcVal);
+ if(bMustFree)
+ free(str);
+}
+
+static void ATTR_NONNULL()
+doFunct_Getenv(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ /* note: the optimizer shall have replaced calls to getenv()
+ * with a constant argument to a single string (once obtained via
+ * getenv()). So we do NOT need to check if there is just a
+ * string following.
+ */
+ struct svar srcVal;
+ char *envvar;
+ es_str_t *estr;
+ char *str;
+ int bMustFree;
+
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ estr = var2String(&srcVal, &bMustFree);
+ str = (char*) es_str2cstr(estr, NULL);
+ envvar = getenv(str);
+ if(envvar == NULL) {
+ ret->d.estr = es_newStr(0);
+ } else {
+ ret->d.estr = es_newStrFromCStr(envvar, strlen(envvar));
+ }
+ ret->datatype = 'S';
+ if(bMustFree) {
+ es_deleteStr(estr);
+ }
+ varFreeMembers(&srcVal);
+ free(str);
+
+}
+
+static void ATTR_NONNULL()
+doFunct_ToLower(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ es_str_t *estr;
+ int bMustFree;
+
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ estr = var2String(&srcVal, &bMustFree);
+ if(!bMustFree) {/* let caller handle that M) */
+ estr = es_strdup(estr);
+ }
+ es_tolower(estr);
+ ret->datatype = 'S';
+ ret->d.estr = estr;
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_CStr(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ es_str_t *estr;
+ int bMustFree;
+
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ estr = var2String(&srcVal, &bMustFree);
+ if(!bMustFree) /* let caller handle that M) */
+ estr = es_strdup(estr);
+ ret->datatype = 'S';
+ ret->d.estr = estr;
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_CNum(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+
+ if(func->expr[0]->nodetype == 'N') {
+ ret->d.n = ((struct cnfnumval*)func->expr[0])->val;
+ } else if(func->expr[0]->nodetype == 'S') {
+ ret->d.n = es_str2num(((struct cnfstringval*) func->expr[0])->estr,
+ NULL);
+ } else {
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ ret->d.n = var2Number(&srcVal, NULL);
+ varFreeMembers(&srcVal);
+ }
+ ret->datatype = 'N';
+ DBGPRINTF("JSONorString: cnum node type %c result %d\n", func->expr[0]->nodetype, (int) ret->d.n);
+}
+
+static void ATTR_NONNULL()
+doFunct_ReMatch(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ char *str;
+ int retval;
+
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ str = (char*) var2CString(&srcVal, &bMustFree);
+ retval = regexp.regexec(func->funcdata, str, 0, NULL, 0);
+ if(retval == 0)
+ ret->d.n = 1;
+ else {
+ ret->d.n = 0;
+ if(retval != REG_NOMATCH) {
+ DBGPRINTF("re_match: regexec returned error %d\n", retval);
+ }
+ }
+ ret->datatype = 'N';
+ if(bMustFree) {
+ free(str);
+ }
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_Ipv42num(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ char *str;
+
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ str = (char*)var2CString(&srcVal, &bMustFree);
+
+
+ unsigned num[4] = {0, 0, 0, 0};
+ long long value = -1;
+ size_t len = strlen(str);
+ int cyc = 0;
+ int prevdot = 0;
+ int startblank = 0;
+ int endblank = 0;
+ DBGPRINTF("rainerscript: (ipv42num) arg: '%s'\n", str);
+ for(unsigned int i = 0 ; i < len ; i++) {
+ switch(str[i]){
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if(endblank == 1){
+ DBGPRINTF("rainerscript: (ipv42num) error: wrong IP-Address format "
+ "(invalid space(1))\n");
+ goto done;
+ }
+ prevdot = 0;
+ startblank = 0;
+ DBGPRINTF("rainerscript: (ipv42num) cycle: %d\n", cyc);
+ num[cyc] = num[cyc]*10+(str[i]-'0');
+ break;
+ case ' ':
+ prevdot = 0;
+ if(i == 0 || startblank == 1){
+ startblank = 1;
+ break;
+ }
+ else{
+ endblank = 1;
+ break;
+ }
+ case '.':
+ if(endblank == 1){
+ DBGPRINTF("rainerscript: (ipv42num) error: wrong IP-Address format "
+ "(inalid space(2))\n");
+ goto done;
+ }
+ startblank = 0;
+ if(prevdot == 1){
+ DBGPRINTF("rainerscript: (ipv42num) error: wrong IP-Address format "
+ "(two dots after one another)\n");
+ goto done;
+ }
+ prevdot = 1;
+ cyc++;
+ if(cyc > 3){
+ DBGPRINTF("rainerscript: (ipv42num) error: wrong IP-Address format "
+ "(too many dots)\n");
+ goto done;
+ }
+ break;
+ default:
+ DBGPRINTF("rainerscript: (ipv42num) error: wrong IP-Address format (invalid charakter)\n");
+ goto done;
+ }
+ }
+ if(cyc != 3){
+ DBGPRINTF("rainerscript: (ipv42num) error: wrong IP-Address format (wrong number of dots)\n");
+ goto done;
+ }
+ value = num[0]*256*256*256+num[1]*256*256+num[2]*256+num[3];
+done:
+ DBGPRINTF("rainerscript: (ipv42num): return value:'%lld'\n",value);
+ ret->datatype = 'N';
+ ret->d.n = value;
+ varFreeMembers(&srcVal);
+ if(bMustFree)
+ free(str);
+}
+
+static void ATTR_NONNULL()
+doFunct_Int2Hex(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int success = 0;
+ char str[18];
+ es_str_t* estr = NULL;
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ long long num = var2Number(&srcVal, &success);
+
+ if (!success) {
+ DBGPRINTF("rainerscript: (int2hex) couldn't access number\n");
+ estr = es_newStrFromCStr("NAN", strlen("NAN"));
+ goto done;
+ }
+
+ snprintf(str, 18, "%llx", num);
+ estr = es_newStrFromCStr(str, strlen(str));
+
+done:
+ ret->d.estr = estr;
+ ret->datatype = 'S';
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_Replace(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal[3];
+
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+ cnfexprEval(func->expr[2], &srcVal[2], usrptr, pWti);
+ ret->d.estr = doFuncReplace(&srcVal[0], &srcVal[1], &srcVal[2]);
+ ret->datatype = 'S';
+ varFreeMembers(&srcVal[0]);
+ varFreeMembers(&srcVal[1]);
+ varFreeMembers(&srcVal[2]);
+}
+
+static void ATTR_NONNULL()
+doFunct_Wrap(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar sourceVal;
+ struct svar wrapperVal;
+ struct svar escaperVal;
+ int freeSource, freeWrapper;
+ es_str_t *sourceStr;
+
+ cnfexprEval(func->expr[0], &sourceVal, usrptr, pWti);
+ cnfexprEval(func->expr[1], &wrapperVal, usrptr, pWti);
+ if(func->nParams == 3) {
+ cnfexprEval(func->expr[2], &escaperVal, usrptr, pWti);
+ sourceStr = doFuncReplace(&sourceVal, &wrapperVal, &escaperVal);
+ freeSource = 1;
+
+ } else {
+ sourceStr = var2String(&sourceVal, &freeSource);
+ }
+ es_str_t *wrapperStr = var2String(&wrapperVal, &freeWrapper);
+ uchar *src = es_getBufAddr(sourceStr);
+ uchar *wrapper = es_getBufAddr(wrapperStr);
+ uint lWrapper = es_strlen(wrapperStr);
+ uint lSrc = es_strlen(sourceStr);
+ uint totalLen = lSrc + 2 * lWrapper;
+ es_str_t *res = es_newStr(totalLen);
+ uchar* resBuf = es_getBufAddr(res);
+ memcpy(resBuf, wrapper, lWrapper);
+ memcpy(resBuf + lWrapper, src, lSrc);
+ memcpy(resBuf + lSrc + lWrapper, wrapper, lWrapper);
+ res->lenStr = totalLen;
+ if (freeSource) {
+ es_deleteStr(sourceStr);
+ }
+ if (freeWrapper) {
+ es_deleteStr(wrapperStr);
+ }
+
+ ret->d.estr = res;
+ ret->datatype = 'S';
+ varFreeMembers(&sourceVal);
+ varFreeMembers(&wrapperVal);
+ if(func->nParams == 3) varFreeMembers(&escaperVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_StrLen(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ es_str_t *estr;
+
+ if(func->expr[0]->nodetype == 'S') {
+ /* if we already have a string, we do not need to
+ * do one more recursive call.
+ */
+ ret->d.n = es_strlen(((struct cnfstringval*) func->expr[0])->estr);
+ } else {
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ estr = var2String(&srcVal, &bMustFree);
+ ret->d.n = es_strlen(estr);
+ if(bMustFree) {
+ es_deleteStr(estr);
+ }
+ varFreeMembers(&srcVal);
+ }
+ ret->datatype = 'N';
+}
+
+static void ATTR_NONNULL()
+doFunct_Substring(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{ //TODO: generalize parameter getter? jgerhards, 2018-02-26
+ int bMustFree;
+ struct svar srcVal[3];
+
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+ cnfexprEval(func->expr[2], &srcVal[2], usrptr, pWti);
+ es_str_t *es = var2String(&srcVal[0], &bMustFree);
+ const int lenSrcStr = es_strlen(es);
+ int start = var2Number(&srcVal[1], NULL);
+ int subStrLen = var2Number(&srcVal[2], NULL);
+ if(start >= lenSrcStr) {
+ /* begin PAST the source string - ensure nothing is copied at all */
+ start = subStrLen = 0;
+ } else {
+ if(subStrLen < 0) {
+ subStrLen = lenSrcStr + subStrLen; /* "add" negative offset! */
+ if(subStrLen < 0) {
+ subStrLen = 0;
+ }
+ }
+ if(subStrLen > (lenSrcStr - start)) {
+ subStrLen = lenSrcStr - start;
+ }
+ }
+
+ ret->datatype = 'S';
+ ret->d.estr = es_newStrFromSubStr(es, (es_size_t)start, (es_size_t)subStrLen);
+ if(bMustFree) es_deleteStr(es);
+ varFreeMembers(&srcVal[0]);
+ varFreeMembers(&srcVal[1]);
+ varFreeMembers(&srcVal[2]);
+}
+
+static void ATTR_NONNULL()
+doFunct_Field(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal[3];
+ int bMustFree;
+ char *str;
+ uchar *resStr;
+ int matchnbr;
+ int delim;
+ rsRetVal localRet;
+
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+ cnfexprEval(func->expr[2], &srcVal[2], usrptr, pWti);
+ str = (char*) var2CString(&srcVal[0], &bMustFree);
+ matchnbr = var2Number(&srcVal[2], NULL);
+ if(srcVal[1].datatype == 'S') {
+ char *delimstr;
+ delimstr = (char*) es_str2cstr(srcVal[1].d.estr, NULL);
+ localRet = doExtractFieldByStr((uchar*)str, delimstr, es_strlen(srcVal[1].d.estr),
+ matchnbr, &resStr);
+ free(delimstr);
+ } else {
+ delim = var2Number(&srcVal[1], NULL);
+ localRet = doExtractFieldByChar((uchar*)str, (char) delim, matchnbr, &resStr);
+ }
+ if(localRet == RS_RET_OK) {
+ ret->d.estr = es_newStrFromCStr((char*)resStr, strlen((char*)resStr));
+ free(resStr);
+ } else if(localRet == RS_RET_FIELD_NOT_FOUND) {
+ ret->d.estr = es_newStrFromCStr("***FIELD NOT FOUND***",
+ sizeof("***FIELD NOT FOUND***")-1);
+ } else {
+ ret->d.estr = es_newStrFromCStr("***ERROR in field() FUNCTION***",
+ sizeof("***ERROR in field() FUNCTION***")-1);
+ }
+ ret->datatype = 'S';
+ if(bMustFree) free(str);
+ varFreeMembers(&srcVal[0]);
+ varFreeMembers(&srcVal[1]);
+ varFreeMembers(&srcVal[2]);
+}
+
+static void ATTR_NONNULL()
+doFunct_Prifilt(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *const pWti __attribute__((unused)))
+{
+ struct funcData_prifilt *pPrifilt;
+
+ pPrifilt = (struct funcData_prifilt*) func->funcdata;
+ if( (pPrifilt->pmask[((smsg_t*)usrptr)->iFacility] == TABLE_NOPRI) ||
+ ((pPrifilt->pmask[((smsg_t*)usrptr)->iFacility]
+ & (1<<((smsg_t*)usrptr)->iSeverity)) == 0) )
+ ret->d.n = 0;
+ else
+ ret->d.n = 1;
+ ret->datatype = 'N';
+}
+
+static void ATTR_NONNULL()
+doFunct_Lookup(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ lookup_key_t key;
+ uint8_t lookup_key_type;
+ lookup_ref_t *lookup_table_ref;
+ lookup_t *lookup_table;
+ int bMustFree;
+
+ ret->datatype = 'S';
+ if(func->funcdata == NULL) {
+ ret->d.estr = es_newStrFromCStr("TABLE-NOT-FOUND", sizeof("TABLE-NOT-FOUND")-1);
+ return;
+ }
+ cnfexprEval(func->expr[1], &srcVal, usrptr, pWti);
+ lookup_table_ref = (lookup_ref_t*) func->funcdata;
+ pthread_rwlock_rdlock(&lookup_table_ref->rwlock);
+ lookup_table = lookup_table_ref->self;
+ if (lookup_table != NULL) {
+ lookup_key_type = lookup_table->key_type;
+ bMustFree = 0;
+ if (lookup_key_type == LOOKUP_KEY_TYPE_STRING) {
+ key.k_str = (uchar*) var2CString(&srcVal, &bMustFree);
+ } else if (lookup_key_type == LOOKUP_KEY_TYPE_UINT) {
+ key.k_uint = var2Number(&srcVal, NULL);
+ } else {
+ DBGPRINTF("program error in %s:%d: lookup_key_type unknown\n",
+ __FILE__, __LINE__);
+ key.k_uint = 0;
+ }
+ ret->d.estr = lookupKey((lookup_ref_t*)func->funcdata, key);
+ if(bMustFree) {
+ free(key.k_str);
+ }
+ } else {
+ ret->d.estr = es_newStrFromCStr("", 1);
+ }
+ pthread_rwlock_unlock(&lookup_table_ref->rwlock);
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_DynInc(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ char *str;
+
+ ret->datatype = 'N';
+ if(func->funcdata == NULL) {
+ ret->d.n = -1;
+ return;
+ }
+ cnfexprEval(func->expr[1], &srcVal, usrptr, pWti);
+ str = (char*) var2CString(&srcVal, &bMustFree);
+ ret->d.n = dynstats_inc(func->funcdata, (uchar*)str);
+ if(bMustFree) free(str);
+ varFreeMembers(&srcVal);
+}
+
+static void ATTR_NONNULL()
+doFunct_FormatTime(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal[2];
+ int bMustFree;
+ char *str;
+ int retval;
+ long long unixtime;
+ const int resMax = 64;
+ char result[resMax];
+ char *formatstr = NULL;
+
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+
+ unixtime = var2Number(&srcVal[0], &retval);
+
+ // Make sure that the timestamp we got can fit into
+ // time_t on older systems.
+ if (sizeof(time_t) == sizeof(int)) {
+ if (unixtime < INT_MIN || unixtime > INT_MAX) {
+ LogMsg(
+ 0, RS_RET_VAL_OUT_OF_RANGE, LOG_WARNING,
+ "Timestamp value %lld is out of range for this system (time_t is "
+ "32bits)!\n", unixtime
+ );
+ retval = 0;
+ }
+ }
+
+ // We want the string form too so we can return it as the
+ // default if we run into problems parsing the number.
+ str = (char*) var2CString(&srcVal[0], &bMustFree);
+ formatstr = (char*) es_str2cstr(srcVal[1].d.estr, NULL);
+
+ ret->datatype = 'S';
+
+ if (objUse(datetime, CORE_COMPONENT) != RS_RET_OK) {
+ ret->d.estr = es_newStr(0);
+ } else {
+ if (!retval || datetime.formatUnixTimeFromTime_t(unixtime, formatstr, result, resMax) == -1) {
+ strncpy(result, str, resMax);
+ result[resMax - 1] = '\0';
+ }
+ ret->d.estr = es_newStrFromCStr(result, strlen(result));
+ }
+
+ if (bMustFree) {
+ free(str);
+ }
+ free(formatstr);
+
+ varFreeMembers(&srcVal[0]);
+ varFreeMembers(&srcVal[1]);
+
+}
+
+/*
+ * Uses the given (current) year/month to decide which year
+ * the incoming month likely belongs in.
+ *
+ * cy - Current Year (actual)
+ * cm - Current Month (actual)
+ * im - "Incoming" Month
+ */
+static int
+estimateYear(int cy, int cm, int im) {
+ im += 12;
+
+ if ((im - cm) == 1) {
+ if (cm == 12 && im == 13)
+ return cy + 1;
+ }
+
+ if ((im - cm) > 13)
+ return cy - 1;
+
+ return cy;
+}
+
+static void ATTR_NONNULL()
+doFunct_ParseTime(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ int bMustFree;
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ char *str = (char*) var2CString(&srcVal, &bMustFree);
+ ret->datatype = 'N';
+ ret->d.n = 0;
+ wtiSetScriptErrno(pWti, RS_SCRIPT_EOK);
+
+ if (objUse(datetime, CORE_COMPONENT) == RS_RET_OK) {
+ struct syslogTime s;
+ int len = strlen(str);
+ uchar *pszTS = (uchar*) str;
+ memset(&s, 0, sizeof(struct syslogTime));
+ // Attempt to parse the date/time string
+ if (datetime.ParseTIMESTAMP3339(&s, (uchar**) &pszTS, &len) == RS_RET_OK) {
+ ret->d.n = datetime.syslogTime2time_t(&s);
+ DBGPRINTF("parse_time: RFC3339 format found\n");
+ } else if (datetime.ParseTIMESTAMP3164(&s, (uchar**) &pszTS, &len,
+ NO_PARSE3164_TZSTRING, NO_PERMIT_YEAR_AFTER_TIME) == RS_RET_OK) {
+ time_t t = time(NULL);
+ struct tm tm;
+ gmtime_r(&t, &tm); // Get the current UTC date
+ // Since properly formatted RFC 3164 timestamps do not have a YEAR
+ // specified, we have to assume one that seems reasonable - SW.
+ s.year = estimateYear(tm.tm_year + 1900, tm.tm_mon + 1, s.month);
+ ret->d.n = datetime.syslogTime2time_t(&s);
+ DBGPRINTF("parse_time: RFC3164 format found\n");
+ } else {
+ DBGPRINTF("parse_time: no valid format found\n");
+ wtiSetScriptErrno(pWti, RS_SCRIPT_EINVAL);
+ }
+ }
+
+ if(bMustFree) {
+ free(str);
+ }
+ varFreeMembers(&srcVal);
+
+}
+
+static int ATTR_NONNULL(1,3,4)
+doFunc_is_time(const char *__restrict__ const str,
+ const char *__restrict__ const fmt,
+ struct svar *__restrict__ const r,
+ wti_t *pWti) {
+
+ assert(str != NULL);
+ assert(r != NULL);
+ assert(pWti != NULL);
+
+ int ret = 0;
+
+ wtiSetScriptErrno(pWti, RS_SCRIPT_EOK);
+
+ if (objUse(datetime, CORE_COMPONENT) == RS_RET_OK) {
+ struct syslogTime s;
+ int len = strlen(str);
+ uchar *pszTS = (uchar*) str;
+
+ int numFormats = 3;
+ dateTimeFormat_t formats[] = { DATE_RFC3164, DATE_RFC3339, DATE_UNIX };
+ dateTimeFormat_t pf[] = { DATE_INVALID };
+ dateTimeFormat_t *p = formats;
+
+ // Check if a format specifier was explicitly provided
+ if (fmt != NULL) {
+ numFormats = 1;
+ *pf = getDateTimeFormatFromStr(fmt);
+ p = pf;
+ }
+
+ // Enumerate format specifier options, looking for the first match
+ for (int i = 0; i < numFormats; i++) {
+ dateTimeFormat_t f = p[i];
+
+ if (f == DATE_RFC3339) {
+ if (datetime.ParseTIMESTAMP3339(&s, (uchar**) &pszTS, &len) == RS_RET_OK) {
+ DBGPRINTF("is_time: RFC3339 format found.\n");
+ ret = 1;
+ break;
+ }
+ } else if (f == DATE_RFC3164) {
+ if (datetime.ParseTIMESTAMP3164(&s, (uchar**) &pszTS, &len,
+ NO_PARSE3164_TZSTRING, NO_PERMIT_YEAR_AFTER_TIME) == RS_RET_OK) {
+ DBGPRINTF("is_time: RFC3164 format found.\n");
+ ret = 1;
+ break;
+ }
+ } else if (f == DATE_UNIX) {
+ int result;
+ var2Number(r, &result);
+
+ if (result) {
+ DBGPRINTF("is_time: UNIX format found.\n");
+ ret = 1;
+ break;
+ }
+ } else {
+ DBGPRINTF("is_time: %s is not a valid date/time format specifier!\n", fmt);
+ break;
+ }
+ }
+ }
+
+ // If not a valid date/time string, set 'errno'
+ if (ret == 0) {
+ DBGPRINTF("is_time: Invalid date-time string: %s.\n", str);
+ wtiSetScriptErrno(pWti, RS_SCRIPT_EINVAL);
+ }
+
+ return ret;
+}
+
+static void ATTR_NONNULL()
+doFunct_IsTime(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal[2];
+ int bMustFree;
+ int bMustFree2;
+ char *fmt = NULL;
+
+ cnfexprEval(func->expr[0], &srcVal[0], usrptr, pWti);
+ char *str = (char*) var2CString(&srcVal[0], &bMustFree);
+
+ bMustFree2 = 0;
+
+ // Check if the optional 2nd parameter was provided
+ if(func->nParams == 2) {
+ cnfexprEval(func->expr[1], &srcVal[1], usrptr, pWti);
+ fmt = (char*) var2CString(&srcVal[1], &bMustFree2);
+ }
+
+ ret->datatype = 'N';
+ ret->d.n = doFunc_is_time(str, fmt, &srcVal[0], pWti);
+
+ if(bMustFree) {
+ free(str);
+ }
+ if(bMustFree2) {
+ free(fmt);
+ }
+ varFreeMembers(&srcVal[0]);
+ if(func->nParams == 2) {
+ varFreeMembers(&srcVal[1]);
+ }
+}
+
+static void ATTR_NONNULL()
+doFunct_ScriptError(struct cnffunc *const func __attribute__((unused)),
+ struct svar *__restrict__ const ret,
+ void *const usrptr __attribute__((unused)),
+ wti_t *__restrict__ const pWti)
+{
+ ret->datatype = 'N';
+ ret->d.n = wtiGetScriptErrno(pWti);
+ DBGPRINTF("script_error() is %d\n", (int) ret->d.n);
+}
+
+static void ATTR_NONNULL()
+doFunct_PreviousActionSuspended(struct cnffunc *const func __attribute__((unused)),
+ struct svar *__restrict__ const ret,
+ void *const usrptr __attribute__((unused)),
+ wti_t *__restrict__ const pWti)
+{
+ ret->datatype = 'N';
+ ret->d.n = wtiGetPrevWasSuspended(pWti);
+ DBGPRINTF("previous_action_suspended() is %d\n", (int) ret->d.n);
+}
+
+static void ATTR_NONNULL()
+doFunct_num2ipv4(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar srcVal;
+ cnfexprEval(func->expr[0], &srcVal, usrptr, pWti);
+ int success = 0;
+ long long num = var2Number(&srcVal, &success);
+ varFreeMembers(&srcVal);
+
+ int numip[4];
+ char str[16];
+ size_t len;
+ DBGPRINTF("rainrescript: (num2ipv4) var2Number output: '%lld\n'", num);
+ if (! success) {
+ DBGPRINTF("rainerscript: (num2ipv4) couldn't access number\n");
+ len = snprintf(str, 16, "-1");
+ goto done;
+ }
+ if(num < 0 || num > 4294967295) {
+ DBGPRINTF("rainerscript: (num2ipv4) invalid number(too big/negative); does "
+ "not represent IPv4 address\n");
+ len = snprintf(str, 16, "-1");
+ goto done;
+ }
+ for(int i = 0 ; i < 4 ; i++){
+ numip[i] = num % 256;
+ num = num / 256;
+ }
+ DBGPRINTF("rainerscript: (num2ipv4) Numbers: 1:'%d' 2:'%d' 3:'%d' 4:'%d'\n",
+ numip[0], numip[1], numip[2], numip[3]);
+ len = snprintf(str, 16, "%d.%d.%d.%d", numip[3], numip[2], numip[1], numip[0]);
+done:
+ DBGPRINTF("rainerscript: (num2ipv4) ipv4-Address: %s, length: %zu\n", str, len);
+ ret->d.estr = es_newStrFromCStr(str, len);
+ ret->datatype = 'S';
+}
+
+
+/* Perform a function call. This has been moved out of cnfExprEval in order
+ * to keep the code small and easier to maintain.
+ */
+static void ATTR_NONNULL()
+doFuncCall(struct cnffunc *__restrict__ const func, struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+
+ if(Debug) {
+ char *fname = es_str2cstr(func->fname, NULL);
+ DBGPRINTF("rainerscript: executing function id %s\n", fname);
+ free(fname);
+ }
+ if(func->fPtr == NULL) {
+ char *fname = es_str2cstr(func->fname, NULL);
+ LogError(0, RS_RET_INTERNAL_ERROR,
+ "rainerscript: internal error: NULL pointer for function named '%s'\n",
+ fname);
+ free(fname);
+ ret->datatype = 'N';
+ ret->d.n = 0;
+ } else {
+ func->fPtr(func, ret, usrptr, pWti);
+ }
+}
+
+
+/* Perform the special "exists()" function to check presence of a variable.
+ */
+static int ATTR_NONNULL()
+evalFuncExists(struct cnffuncexists *__restrict__ const fexists, void *__restrict__ const usrptr)
+{
+ int r = 0;
+ rsRetVal localRet;
+
+ if(fexists->prop.id == PROP_CEE ||
+ fexists->prop.id == PROP_LOCAL_VAR ||
+ fexists->prop.id == PROP_GLOBAL_VAR ) {
+ localRet = msgCheckVarExists((smsg_t*)usrptr, &fexists->prop);
+ if(localRet == RS_RET_OK) {
+ r = 1;
+ }
+ }
+
+ return r;
+}
+
+static void
+evalVar(struct cnfvar *__restrict__ const var, void *__restrict__ const usrptr,
+ struct svar *__restrict__ const ret)
+{
+ rs_size_t propLen;
+ uchar *pszProp = NULL;
+ unsigned short bMustBeFreed = 0;
+ rsRetVal localRet;
+ struct json_object *json;
+ uchar *cstr;
+
+ if(var->prop.id == PROP_CEE ||
+ var->prop.id == PROP_LOCAL_VAR ||
+ var->prop.id == PROP_GLOBAL_VAR ) {
+ localRet = msgGetJSONPropJSONorString((smsg_t*)usrptr, &var->prop, &json, &cstr);
+ if(json != NULL) {
+ assert(cstr == NULL);
+ ret->datatype = 'J';
+ ret->d.json = (localRet == RS_RET_OK) ? json : NULL;
+ DBGPRINTF("rainerscript: (json) var %d:%s: '%s'\n",
+ var->prop.id, var->prop.name,
+ (ret->d.json == NULL) ? "" : json_object_get_string(ret->d.json));
+ } else { /* we have a string */
+ DBGPRINTF("rainerscript: (json/string) var %d: '%s'\n", var->prop.id, cstr);
+ ret->datatype = 'S';
+ ret->d.estr = (localRet != RS_RET_OK || cstr == NULL) ?
+ es_newStr(1)
+ : es_newStrFromCStr((char*) cstr, strlen((char*) cstr));
+ free(cstr);
+ }
+ } else {
+ ret->datatype = 'S';
+ pszProp = (uchar*) MsgGetProp((smsg_t*)usrptr, NULL, &var->prop, &propLen, &bMustBeFreed, NULL);
+ ret->d.estr = es_newStrFromCStr((char*)pszProp, propLen);
+ DBGPRINTF("rainerscript: (string) var %d: '%s'\n", var->prop.id, pszProp);
+ if(bMustBeFreed)
+ free(pszProp);
+ }
+
+}
+
+/* perform a string comparision operation against a while array. Semantic is
+ * that one one comparison is true, the whole construct is true.
+ * TODO: we can obviously optimize this process. One idea is to
+ * compile a regex, which should work faster than serial comparison.
+ * Note: compiling a regex does NOT work at all. I experimented with that
+ * and it was generally 5 to 10 times SLOWER than what we do here...
+ */
+static int
+evalStrArrayCmp(es_str_t *const estr_l,
+ const struct cnfarray *__restrict__ const ar,
+ const int cmpop)
+{
+ int i;
+ int r = 0;
+ es_str_t **res;
+ if(cmpop == CMP_EQ) {
+ res = bsearch(&estr_l, ar->arr, ar->nmemb, sizeof(es_str_t*), qs_arrcmp);
+ r = res != NULL;
+ } else if(cmpop == CMP_NE) {
+ res = bsearch(&estr_l, ar->arr, ar->nmemb, sizeof(es_str_t*), qs_arrcmp);
+ r = res == NULL;
+ } else {
+ for(i = 0 ; (r == 0) && (i < ar->nmemb) ; ++i) {
+ switch(cmpop) {
+ case CMP_STARTSWITH:
+ r = es_strncmp(estr_l, ar->arr[i], es_strlen(ar->arr[i])) == 0;
+ break;
+ case CMP_STARTSWITHI:
+ r = es_strncasecmp(estr_l, ar->arr[i], es_strlen(ar->arr[i])) == 0;
+ break;
+ case CMP_CONTAINS:
+ r = es_strContains(estr_l, ar->arr[i]) != -1;
+ break;
+ case CMP_CONTAINSI:
+ r = es_strCaseContains(estr_l, ar->arr[i]) != -1;
+ break;
+ }
+ }
+ }
+ return r;
+}
+
+#define FREE_BOTH_RET \
+ varFreeMembers(&r); \
+ varFreeMembers(&l)
+
+#define COMP_NUM_BINOP(x) \
+ cnfexprEval(expr->l, &l, usrptr, pWti); \
+ cnfexprEval(expr->r, &r, usrptr, pWti); \
+ ret->datatype = 'N'; \
+ ret->d.n = var2Number(&l, &convok_l) x var2Number(&r, &convok_r); \
+ FREE_BOTH_RET
+
+#define COMP_NUM_BINOP_DIV(x) \
+ cnfexprEval(expr->l, &l, usrptr, pWti); \
+ cnfexprEval(expr->r, &r, usrptr, pWti); \
+ ret->datatype = 'N'; \
+ if((ret->d.n = var2Number(&r, &convok_r)) == 0) { \
+ /* division by zero */ \
+ } else { \
+ ret->d.n = var2Number(&l, &convok_l) x ret->d.n; \
+ } \
+ FREE_BOTH_RET
+
+/* NOTE: array as right-hand argument MUST be handled by user */
+#define PREP_TWO_STRINGS \
+ cnfexprEval(expr->l, &l, usrptr, pWti); \
+ estr_l = var2String(&l, &bMustFree2); \
+ if(expr->r->nodetype == 'S') { \
+ estr_r = ((struct cnfstringval*)expr->r)->estr;\
+ bMustFree = 0; \
+ } else if(expr->r->nodetype != 'A') { \
+ cnfexprEval(expr->r, &r, usrptr, pWti); \
+ estr_r = var2String(&r, &bMustFree); \
+ } else { \
+ /* Note: this is not really necessary, but if we do not */ \
+ /* do it, we get a very irritating compiler warning... */ \
+ estr_r = NULL; \
+ }
+
+#define FREE_TWO_STRINGS \
+ if(bMustFree) es_deleteStr(estr_r); \
+ if(expr->r->nodetype != 'S' && expr->r->nodetype != 'A') varFreeMembers(&r); \
+ if(bMustFree2) es_deleteStr(estr_l); \
+ varFreeMembers(&l)
+
+/* helper to evaluate comparison in a strcmp() like manner. Result is
+ * to be used for final truth value evaluation.
+ */
+static int eval_strcmp_like(const struct cnfexpr *__restrict__ const expr,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ es_str_t *__restrict__ estr_r, *__restrict__ estr_l;
+ int bMustFree, bMustFree2;
+ int64_t n_r, n_l;
+ int convok_r, convok_l;
+ struct svar r, l; /* memory for subexpression results */
+ int ret;
+
+ cnfexprEval(expr->l, &l, usrptr, pWti);
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ n_l = var2Number(&l, &convok_l);
+ if(convok_l) {
+ n_r = var2Number(&r, &convok_r);
+ }
+ if(convok_l && convok_r) {
+ ret = n_l - n_r;
+ } else {
+ estr_l = var2String(&l, &bMustFree);
+ estr_r = var2String(&r, &bMustFree2);
+ ret = es_strcmp(estr_l, estr_r);
+ if(bMustFree) es_deleteStr(estr_l);
+ if(bMustFree2) es_deleteStr(estr_r);
+ }
+ FREE_BOTH_RET;
+ return ret;
+}
+
+/* evaluate an expression.
+ * Note that we try to avoid malloc whenever possible (because of
+ * the large overhead it has, especially on highly threaded programs).
+ * As such, the each caller level must provide buffer space for the
+ * result on its stack during recursion. This permits the callee to store
+ * the return value without malloc. As the value is a somewhat larger
+ * struct, we could otherwise not return it without malloc.
+ * Note that we implement boolean shortcut operations. For our needs, there
+ * simply is no case where full evaluation would make any sense at all.
+ */
+void ATTR_NONNULL()
+cnfexprEval(const struct cnfexpr *__restrict__ const expr,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ struct svar r, l; /* memory for subexpression results */
+ es_str_t *__restrict__ estr_r, *__restrict__ estr_l;
+ int convok_r, convok_l;
+ int bMustFree, bMustFree2;
+ long long n_r, n_l;
+
+ DBGPRINTF("eval expr %p, type '%s'\n", expr, tokenToString(expr->nodetype));
+ switch(expr->nodetype) {
+ /* note: comparison operations are extremely similar. The code can be copyied, only
+ * places flagged with "CMP" need to be changed.
+ */
+ case CMP_EQ:
+ /* this is optimized in regard to right param as a PoC for all compOps
+ * So this is a NOT yet the copy template!
+ */
+ cnfexprEval(expr->l, &l, usrptr, pWti);
+ ret->datatype = 'N';
+ if(l.datatype == 'S') {
+ if(expr->r->nodetype == 'S') {
+ ret->d.n = !es_strcmp(l.d.estr, ((struct cnfstringval*)expr->r)->estr); /*CMP*/
+ } else if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(l.d.estr, (struct cnfarray*) expr->r, CMP_EQ);
+ } else {
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ if(r.datatype == 'S') {
+ ret->d.n = !es_strcmp(l.d.estr, r.d.estr); /*CMP*/
+ } else {
+ n_l = var2Number(&l, &convok_l);
+ if(convok_l) {
+ ret->d.n = (n_l == r.d.n); /*CMP*/
+ } else {
+ estr_r = var2String(&r, &bMustFree);
+ ret->d.n = !es_strcmp(l.d.estr, estr_r); /*CMP*/
+ if(bMustFree) es_deleteStr(estr_r);
+ }
+ }
+ varFreeMembers(&r);
+ }
+ } else if(l.datatype == 'J') {
+ estr_l = var2String(&l, &bMustFree);
+ if(expr->r->nodetype == 'S') {
+ ret->d.n = !es_strcmp(estr_l, ((struct cnfstringval*)expr->r)->estr); /*CMP*/
+ } else if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(estr_l, (struct cnfarray*) expr->r, CMP_EQ);
+ } else {
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ if(r.datatype == 'S') {
+ ret->d.n = !es_strcmp(estr_l, r.d.estr); /*CMP*/
+ } else {
+ n_l = var2Number(&l, &convok_l);
+ if(convok_l) {
+ ret->d.n = (n_l == r.d.n); /*CMP*/
+ } else {
+ estr_r = var2String(&r, &bMustFree2);
+ ret->d.n = !es_strcmp(estr_l, estr_r); /*CMP*/
+ if(bMustFree2) es_deleteStr(estr_r);
+ }
+ }
+ varFreeMembers(&r);
+ }
+ if(bMustFree) es_deleteStr(estr_l);
+ } else {
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ if(r.datatype == 'S') {
+ n_r = var2Number(&r, &convok_r);
+ if(convok_r) {
+ ret->d.n = (l.d.n == n_r); /*CMP*/
+ } else {
+ estr_l = var2String(&l, &bMustFree);
+ ret->d.n = !es_strcmp(r.d.estr, estr_l); /*CMP*/
+ if(bMustFree) es_deleteStr(estr_l);
+ }
+ } else {
+ ret->d.n = (l.d.n == r.d.n); /*CMP*/
+ }
+ varFreeMembers(&r);
+ }
+ varFreeMembers(&l);
+ break;
+ case CMP_NE:
+ cnfexprEval(expr->l, &l, usrptr, pWti);
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ ret->datatype = 'N';
+ if(l.datatype == 'S') {
+ if(expr->r->nodetype == 'S') {
+ ret->d.n = es_strcmp(l.d.estr, ((struct cnfstringval*)expr->r)->estr); /*CMP*/
+ } else if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(l.d.estr, (struct cnfarray*) expr->r, CMP_NE);
+ } else {
+ if(r.datatype == 'S') {
+ ret->d.n = es_strcmp(l.d.estr, r.d.estr); /*CMP*/
+ } else {
+ n_l = var2Number(&l, &convok_l);
+ if(convok_l) {
+ ret->d.n = (n_l != r.d.n); /*CMP*/
+ } else {
+ estr_r = var2String(&r, &bMustFree);
+ ret->d.n = es_strcmp(l.d.estr, estr_r); /*CMP*/
+ if(bMustFree) es_deleteStr(estr_r);
+ }
+ }
+ }
+ } else if(l.datatype == 'J') {
+ estr_l = var2String(&l, &bMustFree);
+ if(r.datatype == 'S') {
+ ret->d.n = es_strcmp(estr_l, r.d.estr); /*CMP*/
+ } else {
+ n_l = var2Number(&l, &convok_l);
+ if(convok_l) {
+ ret->d.n = (n_l != r.d.n); /*CMP*/
+ } else {
+ estr_r = var2String(&r, &bMustFree2);
+ ret->d.n = es_strcmp(estr_l, estr_r); /*CMP*/
+ if(bMustFree2) es_deleteStr(estr_r);
+ }
+ }
+ if(bMustFree) es_deleteStr(estr_l);
+ } else {
+ if(r.datatype == 'S') {
+ n_r = var2Number(&r, &convok_r);
+ if(convok_r) {
+ ret->d.n = (l.d.n != n_r); /*CMP*/
+ } else {
+ estr_l = var2String(&l, &bMustFree);
+ ret->d.n = es_strcmp(r.d.estr, estr_l); /*CMP*/
+ if(bMustFree) es_deleteStr(estr_l);
+ }
+ } else {
+ ret->d.n = (l.d.n != r.d.n); /*CMP*/
+ }
+ }
+ FREE_BOTH_RET;
+ break;
+ case CMP_LE:
+ ret->datatype = 'N';
+ ret->d.n = eval_strcmp_like(expr, usrptr, pWti) <= 0;
+ break;
+ case CMP_GE:
+ ret->datatype = 'N';
+ ret->d.n = eval_strcmp_like(expr, usrptr, pWti) >= 0;
+ break;
+ case CMP_LT:
+ ret->datatype = 'N';
+ ret->d.n = eval_strcmp_like(expr, usrptr, pWti) < 0;
+ break;
+ case CMP_GT:
+ ret->datatype = 'N';
+ ret->d.n = eval_strcmp_like(expr, usrptr, pWti) > 0;
+ break;
+ case CMP_STARTSWITH:
+ PREP_TWO_STRINGS;
+ ret->datatype = 'N';
+ if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(estr_l, (struct cnfarray*) expr->r, CMP_STARTSWITH);
+ bMustFree = 0;
+ } else {
+ ret->d.n = es_strncmp(estr_l, estr_r, estr_r->lenStr) == 0;
+ }
+ FREE_TWO_STRINGS;
+ break;
+ case CMP_STARTSWITHI:
+ PREP_TWO_STRINGS;
+ ret->datatype = 'N';
+ if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(estr_l, (struct cnfarray*) expr->r, CMP_STARTSWITHI);
+ bMustFree = 0;
+ } else {
+ ret->d.n = es_strncasecmp(estr_l, estr_r, estr_r->lenStr) == 0;
+ }
+ FREE_TWO_STRINGS;
+ break;
+ case CMP_CONTAINS:
+ PREP_TWO_STRINGS;
+ ret->datatype = 'N';
+ if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(estr_l, (struct cnfarray*) expr->r, CMP_CONTAINS);
+ bMustFree = 0;
+ } else {
+ ret->d.n = es_strContains(estr_l, estr_r) != -1;
+ }
+ FREE_TWO_STRINGS;
+ break;
+ case CMP_CONTAINSI:
+ PREP_TWO_STRINGS;
+ ret->datatype = 'N';
+ if(expr->r->nodetype == 'A') {
+ ret->d.n = evalStrArrayCmp(estr_l, (struct cnfarray*) expr->r, CMP_CONTAINSI);
+ bMustFree = 0;
+ } else {
+ ret->d.n = es_strCaseContains(estr_l, estr_r) != -1;
+ }
+ FREE_TWO_STRINGS;
+ break;
+ case OR:
+ cnfexprEval(expr->l, &l, usrptr, pWti);
+ ret->datatype = 'N';
+ if(var2Number(&l, &convok_l)) {
+ ret->d.n = 1ll;
+ } else {
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ if(var2Number(&r, &convok_r))
+ ret->d.n = 1ll;
+ else
+ ret->d.n = 0ll;
+ varFreeMembers(&r);
+ }
+ varFreeMembers(&l);
+ break;
+ case AND:
+ cnfexprEval(expr->l, &l, usrptr, pWti);
+ ret->datatype = 'N';
+ if(var2Number(&l, &convok_l)) {
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ if(var2Number(&r, &convok_r))
+ ret->d.n = 1ll;
+ else
+ ret->d.n = 0ll;
+ varFreeMembers(&r);
+ } else {
+ ret->d.n = 0ll;
+ }
+ varFreeMembers(&l);
+ break;
+ case NOT:
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ ret->datatype = 'N';
+ ret->d.n = !var2Number(&r, &convok_r);
+ varFreeMembers(&r);
+ break;
+ case 'N':
+ ret->datatype = 'N';
+ ret->d.n = ((struct cnfnumval*)expr)->val;
+ break;
+ case 'S':
+ ret->datatype = 'S';
+ ret->d.estr = es_strdup(((struct cnfstringval*)expr)->estr);
+ break;
+ case 'A':
+ /* if an array is used with "normal" operations, it just evaluates
+ * to its first element.
+ */
+ ret->datatype = 'S';
+ ret->d.estr = es_strdup(((struct cnfarray*)expr)->arr[0]);
+ break;
+ case 'V':
+ evalVar((struct cnfvar*)expr, usrptr, ret);
+ break;
+ case '&':
+ /* TODO: think about optimization, should be possible ;) */
+ PREP_TWO_STRINGS;
+ if(expr->r->nodetype == 'A') {
+ estr_r = ((struct cnfarray*)expr->r)->arr[0];
+ bMustFree = 0;
+ }
+ ret->datatype = 'S';
+ ret->d.estr = es_strdup(estr_l);
+ es_addStr(&ret->d.estr, estr_r);
+ FREE_TWO_STRINGS;
+ break;
+ case '+':
+ COMP_NUM_BINOP(+);
+ break;
+ case '-':
+ COMP_NUM_BINOP(-);
+ break;
+ case '*':
+ COMP_NUM_BINOP(*);
+ break;
+ case '/':
+ COMP_NUM_BINOP_DIV(/);
+ break;
+ case '%':
+ COMP_NUM_BINOP_DIV(%);
+ break;
+ case 'M':
+ cnfexprEval(expr->r, &r, usrptr, pWti);
+ ret->datatype = 'N';
+ ret->d.n = -var2Number(&r, &convok_r);
+ varFreeMembers(&r);
+ break;
+ case 'F':
+ doFuncCall((struct cnffunc*) expr, ret, usrptr, pWti);
+ break;
+ case S_FUNC_EXISTS:
+ ret->datatype = 'N';
+ ret->d.n = evalFuncExists((struct cnffuncexists*) expr, usrptr);
+ break;
+ default:
+ ret->datatype = 'N';
+ ret->d.n = 0ll;
+ DBGPRINTF("eval error: unknown nodetype %u['%c']\n",
+ (unsigned) expr->nodetype, (char) expr->nodetype);
+ assert(0); /* abort on debug builds, this must not happen! */
+ break;
+ }
+ DBGPRINTF("eval expr %p, return datatype '%c':%d\n", expr, ret->datatype,
+ (ret->datatype == 'N') ? (int)ret->d.n: 0);
+}
+
+//---------------------------------------------------------
+
+void
+cnfarrayContentDestruct(struct cnfarray *ar)
+{
+ unsigned short i;
+ for(i = 0 ; i < ar->nmemb ; ++i) {
+ es_deleteStr(ar->arr[i]);
+ }
+ free(ar->arr);
+}
+
+static void
+regex_destruct(struct cnffunc *func) {
+ if(func->funcdata != NULL) {
+ regexp.regfree(func->funcdata);
+ }
+}
+
+static rsRetVal
+initFunc_dyn_stats(struct cnffunc *func)
+{
+ uchar *cstr = NULL;
+ DEFiRet;
+
+ func->destructable_funcdata = 0;
+
+ if(func->nParams != 2) {
+ parser_errmsg("rsyslog logic error in line %d of file %s\n",
+ __LINE__, __FILE__);
+ FINALIZE;
+ }
+
+ func->funcdata = NULL;
+ if(func->expr[0]->nodetype != 'S') {
+ parser_errmsg("dyn-stats bucket-name (param 1) of dyn-stats manipulating "
+ "functions like dyn_inc must be a constant string");
+ FINALIZE;
+ }
+
+ cstr = (uchar*)es_str2cstr(((struct cnfstringval*) func->expr[0])->estr, NULL);
+ if((func->funcdata = dynstats_findBucket(cstr)) == NULL) {
+ parser_errmsg("dyn-stats bucket '%s' not found", cstr);
+ FINALIZE;
+ }
+
+finalize_it:
+ free(cstr);
+ RETiRet;
+}
+
+static rsRetVal
+initFunc_perctile_obs(struct cnffunc *func)
+{
+ uchar *cstr = NULL;
+ DEFiRet;
+
+ func->destructable_funcdata = 0;
+ if (func->nParams != 3) {
+ parser_errmsg("rsyslog logic error in line %d of file %s\n",
+ __LINE__, __FILE__);
+ FINALIZE;
+ }
+
+ func->funcdata = NULL;
+ if (func->expr[0]->nodetype != 'S') {
+ parser_errmsg("percentile-stats bucket-name (param 1) of perctile-stats manipulating "
+ "functions like percentile_observe must be a constant string");
+ FINALIZE;
+ }
+
+ cstr = (uchar*) es_str2cstr(((struct cnfstringval*) func->expr[0])->estr, NULL);
+ if ( (func->funcdata = perctile_findBucket(cstr)) == NULL) {
+ parser_errmsg("perctile-stats bucket '%s' not found", cstr);
+ FINALIZE;
+ }
+
+finalize_it:
+ free(cstr);
+ RETiRet;
+}
+
+static void ATTR_NONNULL()
+doFunc_percentile_obs(struct cnffunc *__restrict__ const func,
+ struct svar *__restrict__ const ret,
+ void *__restrict__ const usrptr,
+ wti_t *__restrict__ const pWti)
+{
+ uchar *cstr = NULL;
+ struct svar srcVal;
+ int bMustFree;
+
+ ret->datatype = 'N';
+ if(func->funcdata == NULL) {
+ ret->d.n = -1;
+ return;
+ }
+
+ cnfexprEval(func->expr[1], &srcVal, usrptr, pWti);
+ cstr = (uchar*) var2CString(&srcVal, &bMustFree);
+
+ int success = 0;
+ struct svar srcVal2;
+ long long retVal;
+ cnfexprEval(func->expr[2], &srcVal2, usrptr, pWti);
+ long long val = var2Number(&srcVal2, &success);
+ if (!success) {
+ char *cstr2 = es_str2cstr(srcVal2.d.estr, NULL);
+ parser_errmsg("rainerscript: percentile_obs - didn't get a valid number: %s\n", cstr2);
+ free(cstr2);
+ retVal = 0;
+ FINALIZE;
+ }
+
+ retVal = perctile_obs(func->funcdata, cstr, val);
+
+finalize_it:
+ if (bMustFree) {
+ free(cstr);
+ }
+ varFreeMembers(&srcVal);
+ varFreeMembers(&srcVal2);
+ ret->d.n = retVal;
+ ret->datatype = 'N';
+}
+
+static rsRetVal
+initFunc_re_match_generic(struct cnffunc *const func, const unsigned flags)
+{
+ rsRetVal localRet;
+ char *regex = NULL;
+ regex_t *re;
+ DEFiRet;
+
+ if(func->nParams < 2) {
+ parser_errmsg("rsyslog logic error in line %d of file %s\n",
+ __LINE__, __FILE__);
+ FINALIZE;
+ }
+
+ func->funcdata = NULL;
+ if(func->expr[1]->nodetype != 'S') {
+ parser_errmsg("param 2 of re_match/extract() must be a constant string");
+ FINALIZE;
+ }
+
+ CHKmalloc(re = malloc(sizeof(regex_t)));
+ func->funcdata = re;
+
+ regex = es_str2cstr(((struct cnfstringval*) func->expr[1])->estr, NULL);
+
+ if((localRet = objUse(regexp, LM_REGEXP_FILENAME)) == RS_RET_OK) {
+ int errcode;
+ if((errcode = regexp.regcomp(re, (char*) regex, REG_EXTENDED | flags)) != 0) {
+ char errbuff[512];
+ regexp.regerror(errcode, re, errbuff, sizeof(errbuff));
+ parser_errmsg("cannot compile regex '%s': %s", regex, errbuff);
+ ABORT_FINALIZE(RS_RET_ERR);
+ }
+ } else { /* regexp object could not be loaded */
+ parser_errmsg("could not load regex support - regex ignored");
+ ABORT_FINALIZE(localRet);
+ }
+
+finalize_it:
+ free(regex);
+ RETiRet;
+}
+
+static rsRetVal
+initFunc_re_match(struct cnffunc *func)
+{
+ return initFunc_re_match_generic(func, 0);
+}
+
+static rsRetVal
+initFunc_re_match_i(struct cnffunc *func)
+{
+ return initFunc_re_match_generic(func, REG_ICASE);
+}
+
+static rsRetVal
+initFunc_exec_template(struct cnffunc *func)
+{
+ char *tplName = NULL;
+ DEFiRet;
+
+ func->destructable_funcdata = 0;
+
+ if(func->nParams != 1) {
+ parser_errmsg("rsyslog logic error in line %d of file %s\n",
+ __LINE__, __FILE__);
+ FINALIZE;
+ }
+
+ if(func->expr[0]->nodetype != 'S') {
+ parser_errmsg("exec_template(): param 1 must be a constant string");
+ FINALIZE;
+ }
+
+ tplName = es_str2cstr(((struct cnfstringval*) func->expr[0])->estr, NULL);
+ func->funcdata = tplFind(loadConf, tplName, strlen(tplName));
+ if(func->funcdata == NULL) {
+ parser_errmsg("exec_template(): template '%s' could not be found", tplName);
+ FINALIZE;
+ }
+
+
+finalize_it:
+ free(tplName);
+ RETiRet;
+}
+
+static rsRetVal
+initFunc_prifilt(struct cnffunc *func)
+{
+ struct funcData_prifilt *pData;
+ uchar *cstr;
+ DEFiRet;
+
+ if(func->nParams != 1) {
+ parser_errmsg("rsyslog logic error in line %d of file %s\n",
+ __LINE__, __FILE__);
+ FINALIZE;
+ }
+
+ func->funcdata = NULL;
+ if(func->expr[0]->nodetype != 'S') {
+ parser_errmsg("param 1 of prifilt() must be a constant string");
+ FINALIZE;
+ }
+
+ CHKmalloc(pData = calloc(1, sizeof(struct funcData_prifilt)));
+ func->funcdata = pData;
+ cstr = (uchar*)es_str2cstr(((struct cnfstringval*) func->expr[0])->estr, NULL);
+ CHKiRet(DecodePRIFilter(cstr, pData->pmask));
+ free(cstr);
+finalize_it:
+ RETiRet;
+}
+
+static rsRetVal
+resolveLookupTable(struct cnffunc *func)
+{
+ uchar *cstr = NULL;
+ char *fn_name = NULL;
+ DEFiRet;
+
+ func->destructable_funcdata = 0;
+
+ if(func->nParams == 0) {/*we assume first arg is lookup-table-name*/
+ parser_errmsg("rsyslog logic error in line %d of file %s\n",
+ __LINE__, __FILE__);
+ FINALIZE;
+ }
+
+ CHKmalloc(fn_name = es_str2cstr(func->fname, NULL));
+
+ func->funcdata = NULL;
+ if(func->expr[0]->nodetype != 'S') {
+ parser_errmsg("table name (param 1) of %s() must be a constant string", fn_name);
+ FINALIZE;
+ }
+
+ CHKmalloc(cstr = (uchar*)es_str2cstr(((struct cnfstringval*) func->expr[0])->estr, NULL));
+ if((func->funcdata = lookupFindTable(cstr)) == NULL) {
+ parser_errmsg("lookup table '%s' not found (used in function: %s)", cstr, fn_name);
+ FINALIZE;
+ }
+
+finalize_it:
+ free(cstr);
+ free(fn_name);
+ RETiRet;
+}
+
+struct modListNode {
+ int version;
+ struct scriptFunct *modFcts;
+ struct modListNode *next;
+};
+
+static struct modListNode *modListRoot = NULL;
+static struct modListNode *modListLast = NULL;
+
+static struct scriptFunct functions[] = {
+ {"strlen", 1, 1, doFunct_StrLen, NULL, NULL},
+ {"getenv", 1, 1, doFunct_Getenv, NULL, NULL},
+ {"num2ipv4", 1, 1, doFunct_num2ipv4, NULL, NULL},
+ {"int2hex", 1, 1, doFunct_Int2Hex, NULL, NULL},
+ {"substring", 3, 3, doFunct_Substring, NULL, NULL},
+ {"ltrim", 1, 1, doFunct_LTrim, NULL, NULL},
+ {"rtrim", 1, 1, doFunct_RTrim, NULL, NULL},
+ {"tolower", 1, 1, doFunct_ToLower, NULL, NULL},
+ {"cstr", 1, 1, doFunct_CStr, NULL, NULL},
+ {"cnum", 1, 1, doFunct_CNum, NULL, NULL},
+ {"ip42num", 1, 1, doFunct_Ipv42num, NULL, NULL},
+ {"ipv42num", 1, 1, doFunct_Ipv42num, NULL, NULL},
+ {"re_match", 2, 2, doFunct_ReMatch, initFunc_re_match, regex_destruct},
+ {"re_match_i", 2, 2, doFunct_ReMatch, initFunc_re_match_i, regex_destruct},
+ {"re_extract", 5, 5, doFunc_re_extract, initFunc_re_match, regex_destruct},
+ {"re_extract_i", 5, 5, doFunc_re_extract, initFunc_re_match_i, regex_destruct},
+ {"field", 3, 3, doFunct_Field, NULL, NULL},
+ {"exec_template", 1, 1, doFunc_exec_template, initFunc_exec_template, NULL},
+ {"prifilt", 1, 1, doFunct_Prifilt, initFunc_prifilt, NULL},
+ {"lookup", 2, 2, doFunct_Lookup, resolveLookupTable, NULL},
+ {"dyn_inc", 2, 2, doFunct_DynInc, initFunc_dyn_stats, NULL},
+ {"percentile_observe", 3, 3, doFunc_percentile_obs, initFunc_perctile_obs, NULL},
+ {"replace", 3, 3, doFunct_Replace, NULL, NULL},
+ {"wrap", 2, 3, doFunct_Wrap, NULL, NULL},
+ {"random", 1, 1, doFunct_RandomGen, NULL, NULL},
+ {"format_time", 2, 2, doFunct_FormatTime, NULL, NULL},
+ {"parse_time", 1, 1, doFunct_ParseTime, NULL, NULL},
+ {"is_time", 1, 2, doFunct_IsTime, NULL, NULL},
+ {"parse_json", 2, 2, doFunc_parse_json, NULL, NULL},
+ {"get_property", 2, 2, doFunc_get_property, NULL, NULL},
+ {"script_error", 0, 0, doFunct_ScriptError, NULL, NULL},
+ {"previous_action_suspended", 0, 0, doFunct_PreviousActionSuspended, NULL, NULL},
+ {NULL, 0, 0, NULL, NULL, NULL} //last element to check end of array
+};
+
+static rscriptFuncPtr ATTR_NONNULL()
+extractFuncPtr(const struct scriptFunct *const funct, const unsigned int nParams)
+{
+ rscriptFuncPtr retPtr = NULL;
+
+ if(funct->minParams == funct->maxParams) {
+ if(nParams == funct->maxParams) {
+ retPtr = funct->fPtr;
+ } else {
+ parser_errmsg("number of parameters for %s() must be %hu but is %d.",
+ funct->fname, funct->maxParams, nParams);
+ }
+ } else {
+ if(nParams < funct->minParams) {
+ parser_errmsg("number of parameters for %s() must be at least %hu but is %d.",
+ funct->fname, funct->minParams, nParams);
+ } else if(nParams > funct->maxParams) {
+ parser_errmsg("number of parameters for %s() must be at most %hu but is %d.",
+ funct->fname, funct->maxParams, nParams);
+ } else {
+ retPtr = funct->fPtr;
+ }
+ }
+
+ return retPtr;
+}
+
+static struct scriptFunct* ATTR_NONNULL()
+searchFunctArray(const char *const fname, struct scriptFunct *functArray)
+{
+ struct scriptFunct *retPtr = NULL;
+ int i = 0;
+ while(functArray[i].fname != NULL) {
+ if(!strcmp(fname, functArray[i].fname)){
+ retPtr = functArray + i;
+ goto done;
+ }
+ i++;
+ }
+done:
+ return retPtr;
+}
+
+static struct scriptFunct* ATTR_NONNULL()
+searchModList(const char *const fname)
+{
+ struct modListNode *modListCurr = modListRoot;
+ struct scriptFunct *foundFunct;
+
+ do {
+ foundFunct = searchFunctArray(fname, modListCurr->modFcts);
+ if(foundFunct != NULL) {
+ return foundFunct;
+ }
+ modListCurr = modListCurr->next;
+ } while(modListCurr != NULL);
+ return NULL;
+}
+
+static void
+cnffuncDestruct(struct cnffunc *func)
+{
+ unsigned short i;
+
+ for(i = 0 ; i < func->nParams ; ++i) {
+ cnfexprDestruct(func->expr[i]);
+ }
+
+ /* some functions require special destruction */
+ char *cstr = es_str2cstr(func->fname, NULL);
+ struct scriptFunct *foundFunc = searchModList(cstr);
+ free(cstr);
+ if(foundFunc->destruct != NULL) {
+ foundFunc->destruct(func);
+ }
+
+ if(func->destructable_funcdata) {
+ free(func->funcdata);
+ }
+ free(func->fname);
+}
+
+/* Destruct an expression and all sub-expressions contained in it.
+ */
+void
+cnfexprDestruct(struct cnfexpr *__restrict__ const expr)
+{
+
+ if(expr == NULL) {
+ /* this is valid and can happen during optimizer run! */
+ DBGPRINTF("cnfexprDestruct got NULL ptr - valid, so doing nothing\n");
+ return;
+ }
+
+ DBGPRINTF("cnfexprDestruct expr %p, type '%s'\n", expr, tokenToString(expr->nodetype));
+ switch(expr->nodetype) {
+ case CMP_NE:
+ case CMP_EQ:
+ case CMP_LE:
+ case CMP_GE:
+ case CMP_LT:
+ case CMP_GT:
+ case CMP_STARTSWITH:
+ case CMP_STARTSWITHI:
+ case CMP_CONTAINS:
+ case CMP_CONTAINSI:
+ case OR:
+ case AND:
+ case '&':
+ case '+':
+ case '-':
+ case '*':
+ case '/':
+ case '%': /* binary */
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ break;
+ case NOT:
+ case 'M': /* unary */
+ cnfexprDestruct(expr->r);
+ break;
+ case 'N':
+ break;
+ case 'S':
+ es_deleteStr(((struct cnfstringval*)expr)->estr);
+ break;
+ case 'V':
+ free(((struct cnfvar*)expr)->name);
+ msgPropDescrDestruct(&(((struct cnfvar*)expr)->prop));
+ break;
+ case 'F':
+ cnffuncDestruct((struct cnffunc*)expr);
+ break;
+ case 'A':
+ cnfarrayContentDestruct((struct cnfarray*)expr);
+ break;
+ default:break;
+ }
+ free(expr);
+}
+
+//---- END
+
+
+/* Evaluate an expression as a bool. This is added because expressions are
+ * mostly used inside filters, and so this function is quite common and
+ * important.
+ */
+int
+cnfexprEvalBool(struct cnfexpr *__restrict__ const expr, void *__restrict__ const usrptr, wti_t *const pWti)
+{
+ int convok;
+ struct svar ret;
+ cnfexprEval(expr, &ret, usrptr, pWti);
+ int retVal = var2Number(&ret, &convok);
+ varFreeMembers(&ret);
+ return retVal;
+}
+
+struct json_object*
+cnfexprEvalCollection(struct cnfexpr *__restrict__ const expr, void *__restrict__ const usrptr, wti_t *const pWti)
+{
+ struct svar ret;
+ void *retptr;
+ cnfexprEval(expr, &ret, usrptr, pWti);
+ if(ret.datatype == 'J') {
+ retptr = ret.d.json; /*caller is supposed to free the returned json-object*/
+ } else {
+ retptr = NULL;
+ varFreeMembers(&ret); /* we must free the element */
+ }
+ return retptr;
+}
+
+static void
+doIndent(int indent)
+{
+ int i;
+ for(i = 0 ; i < indent ; ++i)
+ dbgprintf(" ");
+}
+
+static void
+pmaskPrint(uchar *pmask, int indent)
+{
+ int i;
+ doIndent(indent);
+ dbgprintf("pmask: ");
+ for (i = 0; i <= LOG_NFACILITIES; i++)
+ if (pmask[i] == TABLE_NOPRI)
+ dbgprintf(" X ");
+ else
+ dbgprintf("%2X ", pmask[i]);
+ dbgprintf("\n");
+}
+
+static void
+cnfarrayPrint(struct cnfarray *ar, int indent)
+{
+ int i;
+ doIndent(indent); dbgprintf("ARRAY:\n");
+ for(i = 0 ; i < ar->nmemb ; ++i) {
+ doIndent(indent+1);
+ cstrPrint("string '", ar->arr[i]);
+ dbgprintf("'\n");
+ }
+}
+
+void
+cnfexprPrint(struct cnfexpr *expr, int indent)
+{
+ struct cnffunc *func;
+ char *fname;
+ int i;
+
+ switch(expr->nodetype) {
+ case CMP_EQ:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("==\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_NE:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("!=\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_LE:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("<=\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_GE:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf(">=\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_LT:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("<\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_GT:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf(">\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_CONTAINS:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("CONTAINS\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_CONTAINSI:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("CONTAINS_I\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_STARTSWITH:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("STARTSWITH\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case CMP_STARTSWITHI:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("STARTSWITH_I\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case OR:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("OR\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case AND:
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("AND\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case NOT:
+ doIndent(indent);
+ dbgprintf("NOT\n");
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ case S_FUNC_EXISTS:
+ doIndent(indent);
+ dbgprintf("exists(%s)\n", ((struct cnffuncexists*)expr)->varname);
+ break;
+ case 'S':
+ doIndent(indent);
+ cstrPrint("string '", ((struct cnfstringval*)expr)->estr);
+ dbgprintf("'\n");
+ break;
+ case 'A':
+ cnfarrayPrint((struct cnfarray*)expr, indent);
+ break;
+ case 'N':
+ doIndent(indent);
+ dbgprintf("%lld\n", ((struct cnfnumval*)expr)->val);
+ break;
+ case 'V':
+ doIndent(indent);
+ dbgprintf("var '%s'\n", ((struct cnfvar*)expr)->name);
+ break;
+ case 'F':
+ doIndent(indent);
+ func = (struct cnffunc*) expr;
+ cstrPrint("function '", func->fname);
+ fname = es_str2cstr(func->fname, NULL);
+ dbgprintf("' (name:%s, params:%hu)\n", fname, func->nParams);
+ free(fname);
+ if(func->fPtr == doFunct_Prifilt) {
+ struct funcData_prifilt *pD;
+ pD = (struct funcData_prifilt*) func->funcdata;
+ pmaskPrint(pD->pmask, indent+1);
+ }
+ for(i = 0 ; i < func->nParams ; ++i) {
+ cnfexprPrint(func->expr[i], indent+1);
+ }
+ break;
+ case '&':
+ case '+':
+ case '-':
+ case '*':
+ case '/':
+ case '%':
+ case 'M':
+ if(expr->l != NULL)
+ cnfexprPrint(expr->l, indent+1);
+ doIndent(indent);
+ dbgprintf("%c\n", (char) expr->nodetype);
+ cnfexprPrint(expr->r, indent+1);
+ break;
+ default:
+ dbgprintf("error: unknown nodetype %u['%c']\n",
+ (unsigned) expr->nodetype, (char) expr->nodetype);
+ assert(0); /* abort on debug builds, this must not happen! */
+ break;
+ }
+}
+
+/* print only the given stmt
+ * if "subtree" equals 1, the full statement subtree is printed, else
+ * really only the statement.
+ */
+void
+cnfstmtPrintOnly(struct cnfstmt *stmt, int indent, sbool subtree)
+{
+ char *cstr;
+ switch(stmt->nodetype) {
+ case S_NOP:
+ doIndent(indent); dbgprintf("NOP\n");
+ break;
+ case S_STOP:
+ doIndent(indent); dbgprintf("STOP\n");
+ break;
+ case S_CALL:
+ cstr = es_str2cstr(stmt->d.s_call.name, NULL);
+ doIndent(indent); dbgprintf("CALL [%s, queue:%d]\n", cstr,
+ stmt->d.s_call.ruleset == NULL ? 0 : 1);
+ free(cstr);
+ break;
+ case S_CALL_INDIRECT:
+ doIndent(indent); dbgprintf("CALL_INDIRECT\n");
+ cnfexprPrint(stmt->d.s_call_ind.expr, indent+1);
+ break;
+ case S_ACT:
+ doIndent(indent); dbgprintf("ACTION %d [%s:%s]\n", stmt->d.act->iActionNbr,
+ modGetName(stmt->d.act->pMod), stmt->printable);
+ break;
+ case S_IF:
+ doIndent(indent); dbgprintf("IF\n");
+ cnfexprPrint(stmt->d.s_if.expr, indent+1);
+ if(subtree) {
+ doIndent(indent); dbgprintf("THEN\n");
+ cnfstmtPrint(stmt->d.s_if.t_then, indent+1);
+ if(stmt->d.s_if.t_else != NULL) {
+ doIndent(indent); dbgprintf("ELSE\n");
+ cnfstmtPrint(stmt->d.s_if.t_else, indent+1);
+ }
+ doIndent(indent); dbgprintf("END IF\n");
+ }
+ break;
+ case S_FOREACH:
+ doIndent(indent); dbgprintf("FOREACH %s IN\n", stmt->d.s_foreach.iter->var);
+ cnfexprPrint(stmt->d.s_foreach.iter->collection, indent+1);
+ if(subtree) {
+ doIndent(indent); dbgprintf("DO\n");
+ cnfstmtPrint(stmt->d.s_foreach.body, indent+1);
+ doIndent(indent); dbgprintf("END FOREACH\n");
+ }
+ break;
+ case S_SET:
+ doIndent(indent); dbgprintf("SET %s =\n",
+ stmt->d.s_set.varname);
+ cnfexprPrint(stmt->d.s_set.expr, indent+1);
+ doIndent(indent); dbgprintf("END SET\n");
+ break;
+ case S_UNSET:
+ doIndent(indent); dbgprintf("UNSET %s\n",
+ stmt->d.s_unset.varname);
+ break;
+ case S_RELOAD_LOOKUP_TABLE:
+ doIndent(indent);
+ dbgprintf("RELOAD_LOOKUP_TABLE table(%s) (stub with '%s' on error)",
+ stmt->d.s_reload_lookup_table.table_name,
+ stmt->d.s_reload_lookup_table.stub_value);
+ break;
+ case S_PRIFILT:
+ doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->printable);
+ pmaskPrint(stmt->d.s_prifilt.pmask, indent);
+ if(subtree) {
+ cnfstmtPrint(stmt->d.s_prifilt.t_then, indent+1);
+ if(stmt->d.s_prifilt.t_else != NULL) {
+ doIndent(indent); dbgprintf("ELSE\n");
+ cnfstmtPrint(stmt->d.s_prifilt.t_else, indent+1);
+ }
+ doIndent(indent); dbgprintf("END PRIFILT\n");
+ }
+ break;
+ case S_PROPFILT:
+ doIndent(indent); dbgprintf("PROPFILT\n");
+ doIndent(indent); dbgprintf("\tProperty.: '%s'\n",
+ propIDToName(stmt->d.s_propfilt.prop.id));
+ if(stmt->d.s_propfilt.prop.id == PROP_CEE ||
+ stmt->d.s_propfilt.prop.id == PROP_LOCAL_VAR ||
+ stmt->d.s_propfilt.prop.id == PROP_GLOBAL_VAR) {
+ doIndent(indent);
+ dbgprintf("\tCEE-Prop.: '%s'\n", stmt->d.s_propfilt.prop.name);
+ }
+ doIndent(indent); dbgprintf("\tOperation: ");
+ if(stmt->d.s_propfilt.isNegated)
+ dbgprintf("NOT ");
+ dbgprintf("'%s'\n", getFIOPName(stmt->d.s_propfilt.operation));
+ if(stmt->d.s_propfilt.pCSCompValue != NULL) {
+ doIndent(indent); dbgprintf("\tValue....: '%s'\n",
+ rsCStrGetSzStrNoNULL(stmt->d.s_propfilt.pCSCompValue));
+ }
+ if(subtree) {
+ doIndent(indent); dbgprintf("THEN\n");
+ cnfstmtPrint(stmt->d.s_propfilt.t_then, indent+1);
+ doIndent(indent); dbgprintf("END PROPFILT\n");
+ }
+ break;
+ default:
+ dbgprintf("error: unknown stmt type %u\n",
+ (unsigned) stmt->nodetype);
+ break;
+ }
+}
+void
+cnfstmtPrint(struct cnfstmt *root, int indent)
+{
+ struct cnfstmt *stmt;
+ for(stmt = root ; stmt != NULL ; stmt = stmt->next) {
+ cnfstmtPrintOnly(stmt, indent, 1);
+ }
+}
+
+struct cnfnumval*
+cnfnumvalNew(const long long val)
+{
+ struct cnfnumval *numval;
+ if((numval = malloc(sizeof(struct cnfnumval))) != NULL) {
+ numval->nodetype = 'N';
+ numval->val = val;
+ }
+ return numval;
+}
+
+struct cnfstringval*
+cnfstringvalNew(es_str_t *const estr)
+{
+ struct cnfstringval *strval;
+ if((strval = malloc(sizeof(struct cnfstringval))) != NULL) {
+ strval->nodetype = 'S';
+ strval->estr = estr;
+ }
+ return strval;
+}
+
+/* creates array AND adds first element to it */
+struct cnfarray*
+cnfarrayNew(es_str_t *val)
+{
+ struct cnfarray *ar;
+ if((ar = malloc(sizeof(struct cnfarray))) != NULL) {
+ ar->nodetype = 'A';
+ ar->nmemb = 1;
+ if((ar->arr = malloc(sizeof(es_str_t*))) == NULL) {
+ free(ar);
+ ar = NULL;
+ goto done;
+ }
+ ar->arr[0] = val;
+ }
+done: return ar;
+}
+
+struct cnfarray*
+cnfarrayAdd(struct cnfarray *__restrict__ const ar, es_str_t *__restrict__ val)
+{
+ es_str_t **newptr;
+ if((newptr = realloc(ar->arr, (ar->nmemb+1)*sizeof(es_str_t*))) == NULL) {
+ DBGPRINTF("cnfarrayAdd: realloc failed, item ignored, ar->arr=%p\n", ar->arr);
+ goto done;
+ } else {
+ ar->arr = newptr;
+ ar->arr[ar->nmemb] = val;
+ ar->nmemb++;
+ }
+done: return ar;
+}
+
+/* duplicate an array (deep copy) */
+struct cnfarray*
+cnfarrayDup(struct cnfarray *old)
+{
+ int i;
+ struct cnfarray *ar;
+ ar = cnfarrayNew(es_strdup(old->arr[0]));
+ for(i = 1 ; i < old->nmemb ; ++i) {
+ cnfarrayAdd(ar, es_strdup(old->arr[i]));
+ }
+ return ar;
+}
+
+struct cnfvar*
+cnfvarNew(char *name)
+{
+ struct cnfvar *var;
+ if((var = malloc(sizeof(struct cnfvar))) != NULL) {
+ var->nodetype = 'V';
+ var->name = name;
+ msgPropDescrFill(&var->prop, (uchar*)var->name, strlen(var->name));
+ }
+ return var;
+}
+
+struct cnfstmt *
+cnfstmtNew(unsigned s_type)
+{
+ struct cnfstmt* cnfstmt;
+ if((cnfstmt = malloc(sizeof(struct cnfstmt))) != NULL) {
+ cnfstmt->nodetype = s_type;
+ cnfstmt->printable = NULL;
+ cnfstmt->next = NULL;
+ }
+ return cnfstmt;
+}
+
+/* This function disables a cnfstmt by setting it to NOP. This is
+ * useful when we detect errors late in the parsing processing, where
+ * we need to return a valid cnfstmt. The optimizer later removes the
+ * NOPs, so all is well.
+ * NOTE: this call assumes that no dynamic data structures have been
+ * allocated. If so, these MUST be freed before calling cnfstmtDisable().
+ */
+static void
+cnfstmtDisable(struct cnfstmt *cnfstmt)
+{
+ cnfstmt->nodetype = S_NOP;
+}
+
+void cnfstmtDestructLst(struct cnfstmt *root);
+
+static void cnfIteratorDestruct(struct cnfitr *itr);
+
+/* delete a single stmt */
+static void
+cnfstmtDestruct(struct cnfstmt *stmt)
+{
+ switch(stmt->nodetype) {
+ case S_NOP:
+ case S_STOP:
+ break;
+ case S_CALL:
+ es_deleteStr(stmt->d.s_call.name);
+ break;
+ case S_CALL_INDIRECT:
+ cnfexprDestruct(stmt->d.s_call_ind.expr);
+ break;
+ case S_ACT:
+ actionDestruct(stmt->d.act);
+ break;
+ case S_IF:
+ cnfexprDestruct(stmt->d.s_if.expr);
+ if(stmt->d.s_if.t_then != NULL) {
+ cnfstmtDestructLst(stmt->d.s_if.t_then);
+ }
+ if(stmt->d.s_if.t_else != NULL) {
+ cnfstmtDestructLst(stmt->d.s_if.t_else);
+ }
+ break;
+ case S_FOREACH:
+ cnfIteratorDestruct(stmt->d.s_foreach.iter);
+ cnfstmtDestructLst(stmt->d.s_foreach.body);
+ break;
+ case S_SET:
+ free(stmt->d.s_set.varname);
+ cnfexprDestruct(stmt->d.s_set.expr);
+ break;
+ case S_UNSET:
+ free(stmt->d.s_set.varname);
+ break;
+ case S_PRIFILT:
+ cnfstmtDestructLst(stmt->d.s_prifilt.t_then);
+ cnfstmtDestructLst(stmt->d.s_prifilt.t_else);
+ break;
+ case S_PROPFILT:
+ msgPropDescrDestruct(&stmt->d.s_propfilt.prop);
+ if(stmt->d.s_propfilt.regex_cache != NULL)
+ rsCStrRegexDestruct(&stmt->d.s_propfilt.regex_cache);
+ if(stmt->d.s_propfilt.pCSCompValue != NULL)
+ cstrDestruct(&stmt->d.s_propfilt.pCSCompValue);
+ cnfstmtDestructLst(stmt->d.s_propfilt.t_then);
+ break;
+ case S_RELOAD_LOOKUP_TABLE:
+ if (stmt->d.s_reload_lookup_table.table_name != NULL) {
+ free(stmt->d.s_reload_lookup_table.table_name);
+ }
+ if (stmt->d.s_reload_lookup_table.stub_value != NULL) {
+ free(stmt->d.s_reload_lookup_table.stub_value);
+ }
+ break;
+ default:
+ DBGPRINTF("error: unknown stmt type during destruct %u\n",
+ (unsigned) stmt->nodetype);
+ break;
+ }
+ free(stmt->printable);
+ free(stmt);
+}
+
+/* delete a stmt and all others following it */
+void
+cnfstmtDestructLst(struct cnfstmt *root)
+{
+ struct cnfstmt *stmt, *todel;
+ for(stmt = root ; stmt != NULL ; ) {
+ todel = stmt;
+ stmt = stmt->next;
+ cnfstmtDestruct(todel);
+ }
+}
+
+struct cnfitr *
+cnfNewIterator(char *var, struct cnfexpr *collection)
+{
+ struct cnfitr* itr;
+ if ((itr = malloc(sizeof(struct cnfitr))) != NULL) {
+ itr->var = var;
+ itr->collection = collection;
+ }
+ return itr;
+}
+
+static void
+cnfIteratorDestruct(struct cnfitr *itr)
+{
+ free(itr->var);
+ if(itr->collection != NULL)
+ cnfexprDestruct(itr->collection);
+ free(itr);
+}
+
+struct cnfstmt *
+cnfstmtNewSet(char *var, struct cnfexpr *expr, int force_reset)
+{
+ propid_t propid;
+ struct cnfstmt* cnfstmt;
+ if((cnfstmt = cnfstmtNew(S_SET)) != NULL) {
+ if(propNameToID((uchar *)var, &propid) == RS_RET_OK
+ && ( propid == PROP_CEE
+ || propid == PROP_LOCAL_VAR
+ || propid == PROP_GLOBAL_VAR)
+ ) {
+ cnfstmt->d.s_set.varname = (uchar*) var;
+ cnfstmt->d.s_set.expr = expr;
+ cnfstmt->d.s_set.force_reset = force_reset;
+ } else {
+ parser_errmsg("invalid variable '%s' in set statement.", var);
+ free(var);
+ cnfstmtDisable(cnfstmt);
+ }
+ }
+ return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewCall(es_str_t *name)
+{
+ struct cnfstmt* cnfstmt;
+ if((cnfstmt = cnfstmtNew(S_CALL)) != NULL) {
+ cnfstmt->d.s_call.name = name;
+ cnfstmt->d.s_call.ruleset = NULL;
+ }
+ return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewReloadLookupTable(struct cnffparamlst *fparams)
+{
+ int nParams;
+ struct cnffparamlst *param, *nxt;
+ struct cnfstmt* cnfstmt;
+ uint8_t failed = 0;
+ if((cnfstmt = cnfstmtNew(S_RELOAD_LOOKUP_TABLE)) != NULL) {
+ nParams = 0;
+ for(param = fparams ; param != NULL ; param = param->next) {
+ ++nParams;
+ }
+ cnfstmt->d.s_reload_lookup_table.table_name = cnfstmt->d.s_reload_lookup_table.stub_value = NULL;
+ switch(nParams) {
+ case 2:
+ param = fparams->next;
+ if (param->expr->nodetype != 'S') {
+ parser_errmsg("statement ignored: reload_lookup_table(table_name, "
+ "optional:stub_value_in_case_reload_fails) "
+ "expects a litteral string for second argument\n");
+ failed = 1;
+ }
+ if ((cnfstmt->d.s_reload_lookup_table.stub_value =
+ (uchar*) es_str2cstr(((struct cnfstringval*)param->expr)->estr, NULL)) == NULL) {
+ parser_errmsg("statement ignored: reload_lookup_table statement "
+ "failed to allocate memory for lookup-table stub-value\n");
+ failed = 1;
+ }
+ CASE_FALLTHROUGH
+ case 1:
+ param = fparams;
+ if (param->expr->nodetype != 'S') {
+ parser_errmsg("statement ignored: reload_lookup_table(table_name, "
+ "optional:stub_value_in_case_reload_fails) "
+ "expects a litteral string for first argument\n");
+ failed = 1;
+ }
+ if ((cnfstmt->d.s_reload_lookup_table.table_name =
+ (uchar*) es_str2cstr(((struct cnfstringval*)param->expr)->estr, NULL)) == NULL) {
+ parser_errmsg("statement ignored: reload_lookup_table statement "
+ "failed to allocate memory for lookup-table name\n");
+ failed = 1;
+ }
+ break;
+ default:
+ parser_errmsg("statement ignored: reload_lookup_table(table_name, optional:"
+ "stub_value_in_case_reload_fails) "
+ "expected 1 or 2 arguments, but found '%d'\n", nParams);
+ failed = 1;
+ }
+ }
+ param = fparams;
+ while(param != NULL) {
+ nxt = param->next;
+ if (param->expr != NULL) cnfexprDestruct(param->expr);
+ free(param);
+ param = nxt;
+ }
+ if (failed) {
+ cnfstmt->nodetype = S_NOP;
+ if (cnfstmt->d.s_reload_lookup_table.table_name != NULL) {
+ free(cnfstmt->d.s_reload_lookup_table.table_name);
+ }
+ if (cnfstmt->d.s_reload_lookup_table.stub_value != NULL) {
+ free(cnfstmt->d.s_reload_lookup_table.stub_value);
+ }
+ }
+ return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewUnset(char *var)
+{
+ propid_t propid;
+ struct cnfstmt* cnfstmt;
+ if((cnfstmt = cnfstmtNew(S_UNSET)) != NULL) {
+ if(propNameToID((uchar *)var, &propid) == RS_RET_OK
+ && ( propid == PROP_CEE
+ || propid == PROP_LOCAL_VAR
+ || propid == PROP_GLOBAL_VAR)
+ ) {
+ cnfstmt->d.s_unset.varname = (uchar*) var;
+ } else {
+ parser_errmsg("invalid variable '%s' in unset statement.", var);
+ free(var);
+ cnfstmtDisable(cnfstmt);
+ }
+ }
+ return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewContinue(void)
+{
+ return cnfstmtNew(S_NOP);
+}
+
+struct cnfstmt *
+cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then)
+{
+ struct cnfstmt* cnfstmt;
+ if((cnfstmt = cnfstmtNew(S_PRIFILT)) != NULL) {
+ cnfstmt->printable = (uchar*)prifilt;
+ cnfstmt->d.s_prifilt.t_then = t_then;
+ cnfstmt->d.s_prifilt.t_else = NULL;
+ DecodePRIFilter((uchar*)prifilt, cnfstmt->d.s_prifilt.pmask);
+ }
+ return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then)
+{
+ struct cnfstmt* cnfstmt;
+ if((cnfstmt = cnfstmtNew(S_PROPFILT)) != NULL) {
+ cnfstmt->printable = (uchar*)propfilt;
+ cnfstmt->d.s_propfilt.t_then = t_then;
+ cnfstmt->d.s_propfilt.regex_cache = NULL;
+ cnfstmt->d.s_propfilt.pCSCompValue = NULL;
+ if(DecodePropFilter((uchar*)propfilt, cnfstmt) != RS_RET_OK) {
+ cnfstmt->nodetype = S_NOP; /* disable action! */
+ cnfstmtDestructLst(t_then); /* we do no longer need this */
+ }
+ }
+ return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewAct(struct nvlst *lst)
+{
+ struct cnfstmt* cnfstmt;
+ char namebuf[256];
+ rsRetVal localRet;
+ if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) {
+ goto done;
+ }
+ if (nvlstChkDisabled(lst)) {
+ dbgprintf("action disabled by configuration\n");
+ cnfstmt->nodetype = S_NOP;
+ }
+ localRet = actionNewInst(lst, &cnfstmt->d.act);
+ if(localRet == RS_RET_OK_WARN) {
+ parser_errmsg("warnings occurred in file '%s' around line %d",
+ cnfcurrfn, yylineno);
+ } else if(localRet != RS_RET_OK) {
+ parser_errmsg("errors occurred in file '%s' around line %d",
+ cnfcurrfn, yylineno);
+ cnfstmt->nodetype = S_NOP; /* disable action! */
+ goto done;
+ }
+ snprintf(namebuf, sizeof(namebuf)-1, "action(type=\"%s\" ...)",
+ modGetName(cnfstmt->d.act->pMod));
+ namebuf[255] = '\0'; /* be on safe side */
+ cnfstmt->printable = (uchar*)strdup(namebuf);
+ nvlstChkUnused(lst);
+ nvlstDestruct(lst);
+done: return cnfstmt;
+}
+
+struct cnfstmt *
+cnfstmtNewLegaAct(char *actline)
+{
+ struct cnfstmt* cnfstmt;
+ rsRetVal localRet;
+ if((cnfstmt = cnfstmtNew(S_ACT)) == NULL)
+ goto done;
+ cnfstmt->printable = (uchar*)strdup((char*)actline);
+ localRet = cflineDoAction(loadConf, (uchar**)&actline, &cnfstmt->d.act);
+ if(localRet != RS_RET_OK) {
+ parser_errmsg("%s occurred in file '%s' around line %d",
+ (localRet == RS_RET_OK_WARN) ? "warnings" : "errors",
+ cnfcurrfn, yylineno);
+ if(localRet != RS_RET_OK_WARN) {
+ cnfstmt->nodetype = S_NOP; /* disable action! */
+ goto done;
+ }
+ }
+done: return cnfstmt;
+}
+
+
+/* returns 1 if the two expressions are constants, 0 otherwise
+ * if both are constants, the expression subtrees are destructed
+ * (this is an aid for constant folding optimizing)
+ */
+static int
+getConstNumber(struct cnfexpr *expr, long long *l, long long *r)
+{
+ int ret = 0;
+ cnfexprOptimize(expr->l);
+ cnfexprOptimize(expr->r);
+ if(expr->l->nodetype == 'N') {
+ if(expr->r->nodetype == 'N') {
+ ret = 1;
+ *l = ((struct cnfnumval*)expr->l)->val;
+ *r = ((struct cnfnumval*)expr->r)->val;
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ } else if(expr->r->nodetype == 'S') {
+ ret = 1;
+ *l = ((struct cnfnumval*)expr->l)->val;
+ *r = es_str2num(((struct cnfstringval*)expr->r)->estr, NULL);
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ }
+ } else if(expr->l->nodetype == 'S') {
+ if(expr->r->nodetype == 'N') {
+ ret = 1;
+ *l = es_str2num(((struct cnfstringval*)expr->l)->estr, NULL);
+ *r = ((struct cnfnumval*)expr->r)->val;
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ } else if(expr->r->nodetype == 'S') {
+ ret = 1;
+ *l = es_str2num(((struct cnfstringval*)expr->l)->estr, NULL);
+ *r = es_str2num(((struct cnfstringval*)expr->r)->estr, NULL);
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ }
+ }
+ return ret;
+}
+
+
+/* constant folding for string concatenation */
+static void
+constFoldConcat(struct cnfexpr *expr)
+{
+ es_str_t *estr;
+ cnfexprOptimize(expr->l);
+ cnfexprOptimize(expr->r);
+ if(expr->l->nodetype == 'S') {
+ if(expr->r->nodetype == 'S') {
+ estr = ((struct cnfstringval*)expr->l)->estr;
+ ((struct cnfstringval*)expr->l)->estr = NULL;
+ es_addStr(&estr, ((struct cnfstringval*)expr->r)->estr);
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ expr->nodetype = 'S';
+ ((struct cnfstringval*)expr)->estr = estr;
+ } else if(expr->r->nodetype == 'N') {
+ es_str_t *numstr;
+ estr = ((struct cnfstringval*)expr->l)->estr;
+ ((struct cnfstringval*)expr->l)->estr = NULL;
+ numstr = es_newStrFromNumber(((struct cnfnumval*)expr->r)->val);
+ es_addStr(&estr, numstr);
+ es_deleteStr(numstr);
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ expr->nodetype = 'S';
+ ((struct cnfstringval*)expr)->estr = estr;
+ }
+ } else if(expr->l->nodetype == 'N') {
+ if(expr->r->nodetype == 'S') {
+ estr = es_newStrFromNumber(((struct cnfnumval*)expr->l)->val);
+ es_addStr(&estr, ((struct cnfstringval*)expr->r)->estr);
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ expr->nodetype = 'S';
+ ((struct cnfstringval*)expr)->estr = estr;
+ } else if(expr->r->nodetype == 'N') {
+ es_str_t *numstr;
+ estr = es_newStrFromNumber(((struct cnfnumval*)expr->l)->val);
+ numstr = es_newStrFromNumber(((struct cnfnumval*)expr->r)->val);
+ es_addStr(&estr, numstr);
+ es_deleteStr(numstr);
+ cnfexprDestruct(expr->l);
+ cnfexprDestruct(expr->r);
+ expr->nodetype = 'S';
+ ((struct cnfstringval*)expr)->estr = estr;
+ }
+ }
+}
+
+
+/* optimize comparisons with syslog severity/facility. This is a special
+ * handler as the numerical values also support GT, LT, etc ops.
+ */
+static struct cnfexpr*
+cnfexprOptimize_CMP_severity_facility(struct cnfexpr *expr)
+{
+ struct cnffunc *func;
+
+ if(expr->l->nodetype != 'V')
+ FINALIZE;
+
+ if(!strcmp("syslogseverity", ((struct cnfvar*)expr->l)->name)) {
+ if(expr->r->nodetype == 'N') {
+ int sev = (int) ((struct cnfnumval*)expr->r)->val;
+ if(sev >= 0 && sev <= 7) {
+ DBGPRINTF("optimizer: change comparison OP to FUNC prifilt()\n");
+ func = cnffuncNew_prifilt(0); /* fac is irrelevant, set below... */
+ prifiltSetSeverity(func->funcdata, sev, expr->nodetype);
+ cnfexprDestruct(expr);
+ expr = (struct cnfexpr*) func;
+ } else {
+ parser_errmsg("invalid syslogseverity %d, expression will always "
+ "evaluate to FALSE", sev);
+ }
+ }
+ } else if(!strcmp("syslogfacility", ((struct cnfvar*)expr->l)->name)) {
+ if(expr->r->nodetype == 'N') {
+ int fac = (int) ((struct cnfnumval*)expr->r)->val;
+ if(fac >= 0 && fac <= 24) {
+ DBGPRINTF("optimizer: change comparison OP to FUNC prifilt()\n");
+ func = cnffuncNew_prifilt(0); /* fac is irrelevant, set below... */
+ prifiltSetFacility(func->funcdata, fac, expr->nodetype);
+ cnfexprDestruct(expr);
+ expr = (struct cnfexpr*) func;
+ } else {
+ parser_errmsg("invalid syslogfacility %d, expression will always "
+ "evaluate to FALSE", fac);
+ }
+ }
+ }
+finalize_it:
+ return expr;
+}
+
+/* optimize a comparison with a variable as left-hand operand
+ * NOTE: Currently support CMP_EQ, CMP_NE only and code NEEDS
+ * TO BE CHANGED fgr other comparisons!
+ */
+static struct cnfexpr*
+cnfexprOptimize_CMP_var(struct cnfexpr *expr)
+{
+ struct cnffunc *func;
+
+ if(!strcmp("syslogfacility-text", ((struct cnfvar*)expr->l)->name)) {
+ if(expr->r->nodetype == 'S') {
+ char *cstr = es_str2cstr(((struct cnfstringval*)expr->r)->estr, NULL);
+ int fac = decodeSyslogName((uchar*)cstr, syslogFacNames);
+ if(fac == -1) {
+ parser_errmsg("invalid facility '%s', expression will always "
+ "evaluate to FALSE", cstr);
+ } else {
+ /* we can actually optimize! */
+ DBGPRINTF("optimizer: change comparison OP to FUNC prifilt()\n");
+ func = cnffuncNew_prifilt(fac);
+ if(expr->nodetype == CMP_NE)
+ prifiltInvert(func->funcdata);
+ cnfexprDestruct(expr);
+ expr = (struct cnfexpr*) func;
+ }
+ free(cstr);
+ }
+ } else if(!strcmp("syslogseverity-text", ((struct cnfvar*)expr->l)->name)) {
+ if(expr->r->nodetype == 'S') {
+ char *cstr = es_str2cstr(((struct cnfstringval*)expr->r)->estr, NULL);
+ int sev = decodeSyslogName((uchar*)cstr, syslogPriNames);
+ if(sev == -1) {
+ parser_errmsg("invalid syslogseverity '%s', expression will always "
+ "evaluate to FALSE", cstr);
+ } else {
+ /* we can acutally optimize! */
+ DBGPRINTF("optimizer: change comparison OP to FUNC prifilt()\n");
+ func = cnffuncNew_prifilt(0);
+ prifiltSetSeverity(func->funcdata, sev, expr->nodetype);
+ cnfexprDestruct(expr);
+ expr = (struct cnfexpr*) func;
+ }
+ free(cstr);
+ }
+ } else {
+ expr = cnfexprOptimize_CMP_severity_facility(expr);
+ }
+ return expr;
+}
+
+static struct cnfexpr*
+cnfexprOptimize_NOT(struct cnfexpr *expr)
+{
+ struct cnffunc *func;
+
+ if(expr->r->nodetype == 'F') {
+ func = (struct cnffunc *)expr->r;
+ if(func->fPtr == doFunct_Prifilt) {
+ DBGPRINTF("optimize NOT prifilt() to inverted prifilt()\n");
+ expr->r = NULL;
+ cnfexprDestruct(expr);
+ prifiltInvert(func->funcdata);
+ expr = (struct cnfexpr*) func;
+ }
+ }
+ return expr;
+}
+
+static struct cnfexpr*
+cnfexprOptimize_AND_OR(struct cnfexpr *expr)
+{
+ struct cnffunc *funcl, *funcr;
+
+ if(expr->l->nodetype == 'F') {
+ if(expr->r->nodetype == 'F') {
+ funcl = (struct cnffunc *)expr->l;
+ funcr = (struct cnffunc *)expr->r;
+ if(funcl->fPtr == doFunct_Prifilt && funcr->fPtr == doFunct_Prifilt) {
+ DBGPRINTF("optimize combine AND/OR prifilt()\n");
+ expr->l = NULL;
+ prifiltCombine(funcl->funcdata, funcr->funcdata, expr->nodetype);
+ cnfexprDestruct(expr);
+ expr = (struct cnfexpr*) funcl;
+ }
+ }
+ }
+ return expr;
+}
+
+
+/* optimize array for EQ/NEQ comparisons. We sort the array in
+ * this case so that we can apply binary search later on.
+ */
+static inline void
+cnfexprOptimize_CMPEQ_arr(struct cnfarray *arr)
+{
+ DBGPRINTF("optimizer: sorting array of %d members for CMP_EQ/NEQ comparison\n", arr->nmemb);
+ qsort(arr->arr, arr->nmemb, sizeof(es_str_t*), qs_arrcmp);
+}
+
+
+/* (recursively) optimize an expression */
+struct cnfexpr*
+cnfexprOptimize(struct cnfexpr *expr)
+{
+ long long ln, rn;
+ struct cnfexpr *exprswap;
+
+ DBGPRINTF("optimize expr %p, type '%s'\n", expr, tokenToString(expr->nodetype));
+ switch(expr->nodetype) {
+ case '&':
+ constFoldConcat(expr);
+ break;
+ case '+':
+ if(getConstNumber(expr, &ln, &rn)) {
+ expr->nodetype = 'N';
+ ((struct cnfnumval*)expr)->val = ln + rn;
+ }
+ break;
+ case '-':
+ if(getConstNumber(expr, &ln, &rn)) {
+ expr->nodetype = 'N';
+ ((struct cnfnumval*)expr)->val = ln - rn;
+ }
+ break;
+ case '*':
+ if(getConstNumber(expr, &ln, &rn)) {
+ expr->nodetype = 'N';
+ ((struct cnfnumval*)expr)->val = ln * rn;
+ }
+ break;
+ case '/':
+ if(getConstNumber(expr, &ln, &rn)) {
+ expr->nodetype = 'N';
+ if(rn == 0) {
+ /* division by zero */
+ ((struct cnfnumval*)expr)->val = 0;
+ } else {
+ ((struct cnfnumval*)expr)->val = ln / rn;
+ }
+ }
+ break;
+ case '%':
+ if(getConstNumber(expr, &ln, &rn)) {
+ expr->nodetype = 'N';
+ if(rn == 0) {
+ /* division by zero */
+ ((struct cnfnumval*)expr)->val = 0;
+ } else {
+ ((struct cnfnumval*)expr)->val = ln % rn;
+ }
+ }
+ break;
+ case CMP_NE:
+ case CMP_EQ:
+ expr->l = cnfexprOptimize(expr->l);
+ expr->r = cnfexprOptimize(expr->r);
+ if(expr->l->nodetype == 'A') {
+ if(expr->r->nodetype == 'A') {
+ parser_errmsg("warning: '==' or '<>' "
+ "comparison of two constant string "
+ "arrays makes no sense");
+ } else { /* swap for simpler execution step */
+ exprswap = expr->l;
+ expr->l = expr->r;
+ expr->r = exprswap;
+ }
+ }
+ if(expr->r->nodetype == 'A') {
+ cnfexprOptimize_CMPEQ_arr((struct cnfarray *)expr->r);
+ }
+ /* This should be evaluated last because it may change expr
+ * to a function.
+ */
+ if(expr->l->nodetype == 'V') {
+ expr = cnfexprOptimize_CMP_var(expr);
+ }
+ break;
+ case CMP_LE:
+ case CMP_GE:
+ case CMP_LT:
+ case CMP_GT:
+ expr->l = cnfexprOptimize(expr->l);
+ expr->r = cnfexprOptimize(expr->r);
+ expr = cnfexprOptimize_CMP_severity_facility(expr);
+ break;
+ case CMP_CONTAINS:
+ case CMP_CONTAINSI:
+ case CMP_STARTSWITH:
+ case CMP_STARTSWITHI:
+ expr->l = cnfexprOptimize(expr->l);
+ expr->r = cnfexprOptimize(expr->r);
+ break;
+ case AND:
+ case OR:
+ expr->l = cnfexprOptimize(expr->l);
+ expr->r = cnfexprOptimize(expr->r);
+ expr = cnfexprOptimize_AND_OR(expr);
+ break;
+ case NOT:
+ expr->r = cnfexprOptimize(expr->r);
+ expr = cnfexprOptimize_NOT(expr);
+ break;
+ default:/* nodetypes we cannot optimize */
+ break;
+ }
+ return expr;
+}
+
+/* removes NOPs from a statement list and returns the
+ * first non-NOP entry.
+ */
+static struct cnfstmt *
+removeNOPs(struct cnfstmt *const root)
+{
+ struct cnfstmt *stmt, *toDel, *prevstmt = NULL;
+ struct cnfstmt *newRoot = NULL;
+
+ if(root == NULL) goto done;
+ stmt = root;
+ while(stmt != NULL) {
+ if(stmt->nodetype == S_NOP) {
+ if(prevstmt != NULL)
+ /* end chain, is rebuild if more non-NOPs follow */
+ prevstmt->next = NULL;
+ toDel = stmt;
+ stmt = stmt->next;
+ cnfstmtDestruct(toDel);
+ } else {
+ if(newRoot == NULL)
+ newRoot = stmt;
+ if(prevstmt != NULL)
+ prevstmt->next = stmt;
+ prevstmt = stmt;
+ stmt = stmt->next;
+ }
+ }
+done: return newRoot;
+}
+
+static void
+cnfstmtOptimizeForeach(struct cnfstmt *stmt)
+{
+ stmt->d.s_foreach.iter->collection = cnfexprOptimize(stmt->d.s_foreach.iter->collection);
+ stmt->d.s_foreach.body = cnfstmtOptimize(stmt->d.s_foreach.body);
+}
+
+
+static void
+cnfstmtOptimizeIf(struct cnfstmt *stmt)
+{
+ struct cnfstmt *t_then, *t_else;
+ struct cnfexpr *expr;
+ struct cnffunc *func;
+ struct funcData_prifilt *prifilt;
+
+ assert(stmt->nodetype == S_IF);
+ expr = stmt->d.s_if.expr = cnfexprOptimize(stmt->d.s_if.expr);
+ stmt->d.s_if.t_then = cnfstmtOptimize(stmt->d.s_if.t_then);
+ stmt->d.s_if.t_else = cnfstmtOptimize(stmt->d.s_if.t_else);
+
+ if(stmt->d.s_if.t_then == NULL && stmt->d.s_if.t_else == NULL) {
+ /* pointless if, probably constructed by config mgmt system */
+ DBGPRINTF("optimizer: if with both empty then and else - remove\n");
+ cnfexprDestruct(stmt->d.s_if.expr);
+ /* set to NOP, this will be removed in later stage */
+ stmt->nodetype = S_NOP;
+ goto done;
+ }
+
+ assert(stmt->nodetype == S_IF);
+ if(stmt->d.s_if.expr->nodetype == 'F') {
+ func = (struct cnffunc*)expr;
+ if(func->fPtr == doFunct_Prifilt) {
+ DBGPRINTF("optimizer: change IF to PRIFILT\n");
+ t_then = stmt->d.s_if.t_then;
+ t_else = stmt->d.s_if.t_else;
+ stmt->nodetype = S_PRIFILT;
+ prifilt = (struct funcData_prifilt*) func->funcdata;
+ memcpy(stmt->d.s_prifilt.pmask, prifilt->pmask,
+ sizeof(prifilt->pmask));
+ stmt->d.s_prifilt.t_then = t_then;
+ stmt->d.s_prifilt.t_else = t_else;
+ if(func->nParams == 0)
+ stmt->printable = (uchar*)strdup("[Optimizer Result]");
+ else
+ stmt->printable = (uchar*)
+ es_str2cstr(((struct cnfstringval*)func->expr[0])->estr, NULL);
+ cnfexprDestruct(expr);
+ cnfstmtOptimizePRIFilt(stmt);
+ }
+ }
+done: return;
+}
+
+static void
+cnfstmtOptimizeAct(struct cnfstmt *stmt)
+{
+ action_t *pAct;
+
+ pAct = stmt->d.act;
+ if(!strcmp((char*)modGetName(pAct->pMod), "builtin:omdiscard")) {
+ DBGPRINTF("optimizer: replacing omdiscard by STOP\n");
+ actionDestruct(stmt->d.act);
+ stmt->nodetype = S_STOP;
+ }
+}
+
+static void
+cnfstmtOptimizePRIFilt(struct cnfstmt *stmt)
+{
+ int i;
+ int isAlways = 1;
+ struct cnfstmt *subroot, *last;
+
+ stmt->d.s_prifilt.t_then = cnfstmtOptimize(stmt->d.s_prifilt.t_then);
+
+ for(i = 0; i <= LOG_NFACILITIES; i++)
+ if(stmt->d.s_prifilt.pmask[i] != 0xff) {
+ isAlways = 0;
+ break;
+ }
+ if(!isAlways)
+ goto done;
+
+ DBGPRINTF("optimizer: removing always-true PRIFILT %p\n", stmt);
+ if(stmt->d.s_prifilt.t_else != NULL) {
+ parser_errmsg("error: always-true PRI filter has else part!\n");
+ cnfstmtDestructLst(stmt->d.s_prifilt.t_else);
+ }
+ free(stmt->printable);
+ stmt->printable = NULL;
+ subroot = stmt->d.s_prifilt.t_then;
+ if(subroot == NULL) {
+ /* very strange, we set it to NOP, best we can do
+ * This case is NOT expected in practice
+ */
+ stmt->nodetype = S_NOP;
+ goto done;
+ }
+ for(last = subroot ; last->next != NULL ; last = last->next)
+ /* find last node in subtree */;
+ last->next = stmt->next;
+ memcpy(stmt, subroot, sizeof(struct cnfstmt));
+ free(subroot);
+
+done: return;
+}
+
+static void
+cnfstmtOptimizeReloadLookupTable(struct cnfstmt *stmt) {
+ if((stmt->d.s_reload_lookup_table.table = lookupFindTable(stmt->d.s_reload_lookup_table.table_name))
+ == NULL) {
+ parser_errmsg("lookup table '%s' not found\n", stmt->d.s_reload_lookup_table.table_name);
+ }
+}
+
+/* we abuse "optimize" a bit. Actually, we obtain a ruleset pointer, as
+ * all rulesets are only known later in the process (now!).
+ */
+static void
+cnfstmtOptimizeCall(struct cnfstmt *stmt)
+{
+ ruleset_t *pRuleset;
+ rsRetVal localRet;
+ uchar *rsName;
+
+ rsName = (uchar*) es_str2cstr(stmt->d.s_call.name, NULL);
+ localRet = rulesetGetRuleset(loadConf, &pRuleset, rsName);
+ if(localRet != RS_RET_OK) {
+ /* in that case, we accept that a NOP will "survive" */
+ parser_errmsg("ruleset '%s' cannot be found\n", rsName);
+ es_deleteStr(stmt->d.s_call.name);
+ stmt->nodetype = S_NOP;
+ goto done;
+ }
+ DBGPRINTF("CALL obtained ruleset ptr %p for ruleset '%s' [hasQueue:%d]\n",
+ pRuleset, rsName, rulesetHasQueue(pRuleset));
+ if(rulesetHasQueue(pRuleset)) {
+ stmt->d.s_call.ruleset = pRuleset;
+ } else {
+ stmt->d.s_call.ruleset = NULL;
+ stmt->d.s_call.stmt = pRuleset->root;
+ }
+done:
+ free(rsName);
+ return;
+}
+/* (recursively) optimize a statement */
+struct cnfstmt *
+cnfstmtOptimize(struct cnfstmt *root)
+{
+ struct cnfstmt *stmt;
+ if(root == NULL) goto done;
+ for(stmt = root ; stmt != NULL ; stmt = stmt->next) {
+ DBGPRINTF("optimizing cnfstmt type %d\n", (int) stmt->nodetype);
+ switch(stmt->nodetype) {
+ case S_IF:
+ cnfstmtOptimizeIf(stmt);
+ break;
+ case S_FOREACH:
+ cnfstmtOptimizeForeach(stmt);
+ break;
+ case S_PRIFILT:
+ cnfstmtOptimizePRIFilt(stmt);
+ break;
+ case S_PROPFILT:
+ stmt->d.s_propfilt.t_then = cnfstmtOptimize(stmt->d.s_propfilt.t_then);
+ break;
+ case S_SET:
+ stmt->d.s_set.expr = cnfexprOptimize(stmt->d.s_set.expr);
+ break;
+ case S_ACT:
+ cnfstmtOptimizeAct(stmt);
+ break;
+ case S_CALL:
+ cnfstmtOptimizeCall(stmt);
+ break;
+ case S_CALL_INDIRECT:
+ stmt->d.s_call_ind.expr = cnfexprOptimize(stmt->d.s_call_ind.expr);
+ break;
+ case S_STOP:
+ if(stmt->next != NULL)
+ parser_warnmsg("STOP is followed by unreachable statements!\n");
+ break;
+ case S_UNSET: /* nothing to do */
+ break;
+ case S_RELOAD_LOOKUP_TABLE:
+ cnfstmtOptimizeReloadLookupTable(stmt);
+ break;
+ case S_NOP:
+ // TODO: fix optimizer, re-enable. see:
+ // https://github.com/rsyslog/rsyslog/issues/2524
+ //LogError(0, RS_RET_INTERNAL_ERROR,
+ // "optimizer error: we see a NOP, how come?");
+ dbgprintf("optimizer error: we see a NOP, how come?");
+ break;
+ default:
+ LogError(0, RS_RET_INTERNAL_ERROR,
+ "internal error: unknown stmt type %u during optimizer run\n",
+ (unsigned) stmt->nodetype);
+ break;
+ }
+ }
+ root = removeNOPs(root);
+done: return root;
+}
+
+
+struct cnffparamlst *
+cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next)
+{
+ struct cnffparamlst* lst;
+ if((lst = malloc(sizeof(struct cnffparamlst))) != NULL) {
+ lst->nodetype = 'P';
+ lst->expr = expr;
+ lst->next = next;
+ }
+ return lst;
+}
+
+/* Obtain function id from name AND number of params. Issues the
+ * relevant error messages if errors are detected.
+ */
+static rscriptFuncPtr
+funcName2Ptr(char *const fname, const unsigned short nParams)
+{
+ struct scriptFunct *foundFunc = searchModList(fname);
+ if(foundFunc == NULL) {
+ parser_errmsg("function '%s' not found", fname);
+ return NULL;
+ } else {
+ return extractFuncPtr(foundFunc, nParams);
+ }
+}
+
+rsRetVal
+addMod2List(const int __attribute__((unused)) version, struct scriptFunct *functArray)
+/*version currently not used, might be needed later for versin check*/
+{
+ DEFiRet;
+ int i;
+ struct modListNode *newNode;
+ CHKmalloc(newNode = (struct modListNode*) malloc(sizeof(struct modListNode)));
+ newNode->version = 1;
+ newNode->next = NULL;
+
+ i = 0;
+ while(functArray[i].fname != NULL) {
+ if(searchModList(functArray[i].fname) != NULL) {
+ parser_errmsg("function %s defined multiple times, second time will be ignored",
+ functArray[i].fname);
+ }
+ i++;
+ }
+ newNode->modFcts = functArray;
+
+ modListLast->next = newNode;
+ modListLast = newNode;
+finalize_it:
+ RETiRet;
+}
+
+
+struct cnffunc *
+cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst)
+{
+ struct cnffunc* func;
+ struct cnffparamlst *param, *toDel;
+ unsigned short i;
+ unsigned short nParams;
+ char *cstr;
+
+ /* we first need to find out how many params we have */
+ nParams = 0;
+ for(param = paramlst ; param != NULL ; param = param->next)
+ ++nParams;
+ if((func = malloc(sizeof(struct cnffunc) + (nParams * sizeof(struct cnfexp*))))
+ != NULL) {
+ func->nodetype = 'F';
+ func->fname = fname;
+ func->nParams = nParams;
+ func->funcdata = NULL;
+ func->destructable_funcdata = 1;
+ cstr = es_str2cstr(fname, NULL);
+ func->fPtr = funcName2Ptr(cstr, nParams);
+
+ /* parse error if we have an unknown function */
+ if (func->fPtr == NULL) {
+ parser_errmsg("Invalid function %s", cstr);
+ }
+
+ /* shuffle params over to array (access speed!) */
+ param = paramlst;
+ for(i = 0 ; i < nParams ; ++i) {
+ func->expr[i] = param->expr;
+ toDel = param;
+ param = param->next;
+ free(toDel);
+ }
+ /* some functions require special initialization */
+ struct scriptFunct *foundFunc = searchModList(cstr);
+ if(foundFunc->initFunc != NULL) {
+ foundFunc->initFunc(func);
+ }
+ free(cstr);
+ }
+ return func;
+}
+
+
+/* A special function to create a prifilt() expression during optimization
+ * phase.
+ */
+struct cnffunc *
+cnffuncNew_prifilt(int fac)
+{
+ struct cnffunc* func;
+
+ fac >>= 3;
+ if (fac >= LOG_NFACILITIES + 1 || fac < 0)
+ return NULL;
+
+ if((func = malloc(sizeof(struct cnffunc))) != NULL) {
+ if ((func->funcdata = calloc(1, sizeof(struct funcData_prifilt))) == NULL) {
+ free(func);
+ return NULL;
+ }
+ func->nodetype = 'F';
+ func->fname = es_newStrFromCStr("prifilt", sizeof("prifilt")-1);
+ func->nParams = 0;
+ func->fPtr = doFunct_Prifilt;
+ func->destructable_funcdata = 1;
+ ((struct funcData_prifilt *)func->funcdata)->pmask[fac] = TABLE_ALLPRI;
+ }
+ return func;
+}
+
+
+/* The check-if-variable exists "exists($!var)" is a special beast and as such
+ * also needs special code (we must not evaluate the var but need its name).
+ */
+struct cnffuncexists * ATTR_NONNULL()
+cnffuncexistsNew(const char *const varname)
+{
+ struct cnffuncexists* f_exists;
+
+ if((f_exists = malloc(sizeof(struct cnffuncexists))) != NULL) {
+ f_exists->nodetype = S_FUNC_EXISTS;
+ f_exists->varname = varname;
+ msgPropDescrFill(&f_exists->prop, (uchar*)varname, strlen(varname));
+ }
+ return f_exists;
+}
+
+
+/* returns 0 if everything is OK and config parsing shall continue,
+ * and 1 if things are so wrong that config parsing shall be aborted.
+ */
+int ATTR_NONNULL()
+cnfDoInclude(const char *const name, const int optional)
+{
+ char *cfgFile;
+ const char *finalName;
+ int i;
+ int result;
+ glob_t cfgFiles;
+ int ret = 0;
+ struct stat fileInfo;
+ char errStr[1024];
+ char nameBuf[MAXFNAME+1];
+ char cwdBuf[MAXFNAME+1];
+
+ DBGPRINTF("cnfDoInclude: file: '%s', optional: %d\n", name, optional);
+ finalName = name;
+ if(stat(name, &fileInfo) == 0) {
+ /* stat usually fails if we have a wildcard - so this does NOT indicate error! */
+ if(S_ISDIR(fileInfo.st_mode)) {
+ /* if we have a directory, we need to add "*" to get its files */
+ snprintf(nameBuf, sizeof(nameBuf), "%s*", name);
+ finalName = nameBuf;
+ }
+ }
+
+ /* Use GLOB_MARK to append a trailing slash for directories. */
+ /* Use GLOB_NOMAGIC to detect wildcards that match nothing. */
+ #ifdef HAVE_GLOB_NOMAGIC
+ /* Silently ignore wildcards that match nothing */
+ result = glob(finalName, GLOB_MARK | GLOB_NOMAGIC, NULL, &cfgFiles);
+ if(result == GLOB_NOMATCH) {
+ #else
+ result = glob(finalName, GLOB_MARK, NULL, &cfgFiles);
+ if(result == GLOB_NOMATCH && containsGlobWildcard((char*)finalName)) {
+ #endif /* HAVE_GLOB_NOMAGIC */
+ goto done;
+ }
+
+ if(result == GLOB_NOSPACE || result == GLOB_ABORTED) {
+ if(optional == 0) {
+ rs_strerror_r(errno, errStr, sizeof(errStr));
+ if(getcwd(cwdBuf, sizeof(cwdBuf)) == NULL)
+ strcpy(cwdBuf, "??getcwd() failed??");
+ parser_errmsg("error accessing config file or directory '%s' "
+ "[cwd:%s]: %s", finalName, cwdBuf, errStr);
+ ret = 1;
+ }
+ goto done;
+ }
+
+ /* note: bison "stacks" the files, so we need to submit them
+ * in reverse order to the *stack* in order to get the proper
+ * parsing order. Also see
+ * http://bugzilla.adiscon.com/show_bug.cgi?id=411
+ */
+ for(i = cfgFiles.gl_pathc - 1; i >= 0 ; i--) {
+ cfgFile = cfgFiles.gl_pathv[i];
+ if(stat(cfgFile, &fileInfo) != 0) {
+ if(optional == 0) {
+ rs_strerror_r(errno, errStr, sizeof(errStr));
+ if(getcwd(cwdBuf, sizeof(cwdBuf)) == NULL)
+ strcpy(cwdBuf, "??getcwd() failed??");
+ parser_errmsg("error accessing config file or directory '%s' "
+ "[cwd: %s]: %s", cfgFile, cwdBuf, errStr);
+ ret = 1;
+ }
+ goto done;
+ }
+
+ if(S_ISREG(fileInfo.st_mode)) { /* config file */
+ DBGPRINTF("requested to include config file '%s'\n", cfgFile);
+ cnfSetLexFile(cfgFile);
+ } else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */
+ DBGPRINTF("requested to include directory '%s'\n", cfgFile);
+ cnfDoInclude(cfgFile, optional);
+ } else {
+ DBGPRINTF("warning: unable to process IncludeConfig directive '%s'\n", cfgFile);
+ }
+ }
+
+done:
+ globfree(&cfgFiles);
+ return ret;
+}
+
+
+/* Process include() objects */
+void
+includeProcessCnf(struct nvlst *const lst)
+{
+ struct cnfparamvals *pvals = NULL;
+ const char *inc_file = NULL;
+ const char *text = NULL;
+ int optional = 0;
+ int abort_if_missing = 0;
+ int i;
+
+ if(lst == NULL) {
+ parser_errmsg("include() must have either 'file' or 'text' "
+ "parameter - ignored");
+ goto done;
+ }
+
+ if (nvlstChkDisabled(lst)) {
+ DBGPRINTF("include statement disabled\n");
+ goto done;
+ }
+
+ pvals = nvlstGetParams(lst, &incpblk, NULL);
+ if(pvals == NULL) {
+ goto done;
+ }
+ DBGPRINTF("include param blk after includeProcessCnf:\n");
+ cnfparamsPrint(&incpblk, pvals);
+ for(i = 0 ; i < incpblk.nParams ; ++i) {
+ if(!pvals[i].bUsed) {
+ continue;
+ }
+
+ if(!strcmp(incpblk.descr[i].name, "file")) {
+ inc_file = es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(incpblk.descr[i].name, "text")) {
+ text = es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(incpblk.descr[i].name, "mode")) {
+ char *const md = es_str2cstr(pvals[i].val.d.estr, NULL);
+ if(!strcmp(md, "abort-if-missing")) {
+ optional = 0;
+ abort_if_missing = 1;
+ } else if(!strcmp(md, "required")) {
+ optional = 0;
+ } else if(!strcmp(md, "optional")) {
+ optional = 1;
+ } else {
+ parser_errmsg("invalid 'mode' parameter: '%s' - ignored", md);
+ }
+ free((void*)md);
+ } else {
+ LogError(0, RS_RET_INTERNAL_ERROR,
+ "rainerscript/include: program error, non-handled inclpblk "
+ "param '%s' in includeProcessCnf()", incpblk.descr[i].name);
+ }
+ }
+
+ if(text != NULL && inc_file != NULL) {
+ parser_errmsg("include() must have either 'file' or 'text' "
+ "parameter, but both are set - ignored");
+ goto done;
+ }
+
+ if(inc_file != NULL) {
+ if(cnfDoInclude(inc_file, optional) != 0 && abort_if_missing) {
+ fprintf(stderr, "include file '%s' mode is set to abort-if-missing "
+ "and the file is indeed missing - thus aborting rsyslog\n",
+ inc_file);
+ exit(1); /* "good exit" - during config processing, requested by user */
+ }
+ } else if(text != NULL) {
+ es_str_t *estr = es_newStrFromCStr((char*)text, strlen(text));
+ /* lex needs 2 \0 bytes as terminator indication (wtf ;-)) */
+ es_addChar(&estr, '\0');
+ es_addChar(&estr, '\0');
+ cnfAddConfigBuffer(estr, "text");
+ } else {
+ parser_errmsg("include must have either 'file' or 'text' "
+ "parameter - ignored");
+ goto done;
+ }
+
+done:
+ free((void*)text);
+ free((void*)inc_file);
+ nvlstDestruct(lst);
+ if(pvals != NULL)
+ cnfparamvalsDestruct(pvals, &incpblk);
+ return;
+}
+
+
+void
+varDelete(const struct svar *v)
+{
+ switch(v->datatype) {
+ case 'S':
+ case 'J':
+ varFreeMembers(v);
+ break;
+ case 'A':
+ cnfarrayContentDestruct(v->d.ar);
+ free(v->d.ar);
+ break;
+ default:break;
+ }
+}
+
+void
+cnfparamvalsDestruct(const struct cnfparamvals *paramvals, const struct cnfparamblk *blk)
+{
+ int i;
+ if(paramvals == NULL)
+ return;
+ for(i = 0 ; i < blk->nParams ; ++i) {
+ if(paramvals[i].bUsed) {
+ varDelete(&paramvals[i].val);
+ }
+ }
+ free((void*)paramvals);
+}
+
+/* find the index (or -1!) for a config param by name. This is used to
+ * address the parameter array. Of course, we could use with static
+ * indices, but that would create some extra bug potential. So we
+ * resort to names. As we do this only during the initial config parsing
+ * stage the (considerable!) extra overhead is OK. -- rgerhards, 2011-07-19
+ */
+int
+cnfparamGetIdx(struct cnfparamblk *params, const char *name)
+{
+ int i;
+ for(i = 0 ; i < params->nParams ; ++i)
+ if(!strcmp(params->descr[i].name, name))
+ break;
+ if(i == params->nParams)
+ i = -1; /* not found */
+ return i;
+}
+
+
+void
+cstrPrint(const char *text, es_str_t *estr)
+{
+ char *str;
+ str = es_str2cstr(estr, NULL);
+ dbgprintf("%s%s", text, str);
+ free(str);
+}
+
+char *
+rmLeadingSpace(char *s)
+{
+ char *p;
+ for(p = s ; *p && isspace(*p) ; ++p)
+ ;
+ return(p);
+}
+
+/* init must be called once before any parsing of the script files start */
+rsRetVal
+initRainerscript(void)
+{
+ DEFiRet;
+ CHKmalloc(modListRoot = (struct modListNode*) malloc(sizeof(struct modListNode)));
+ modListRoot->version = 1;
+ modListRoot->modFcts = functions;
+ modListRoot->next = NULL;
+ modListLast = modListRoot;
+ iRet = objGetObjInterface(&obj);
+finalize_it:
+ RETiRet;
+}
+
+/* we need a function to check for octal digits */
+static inline int
+isodigit(uchar c)
+{
+ return(c >= '0' && c <= '7');
+}
+
+/**
+ * Get numerical value of a hex digit. This is a helper function.
+ * @param[in] c a character containing 0..9, A..Z, a..z anything else
+ * is an (undetected) error.
+ */
+static int
+hexDigitVal(char c)
+{
+ int r;
+ if(c < 'A')
+ r = c - '0';
+ else if(c < 'a')
+ r = c - 'A' + 10;
+ else
+ r = c - 'a' + 10;
+ return r;
+}
+
+/* Handle the actual unescaping.
+ * a helper to unescapeStr(), to help make the function easier to read.
+ */
+static void
+doUnescape(unsigned char *c, int len, int *iSrc, int iDst)
+{
+ if(c[*iSrc] == '\\') {
+ if(++(*iSrc) == len) {
+ /* error, incomplete escape, treat as single char */
+ c[iDst] = '\\';
+ }
+ /* regular case, unescape */
+ switch(c[*iSrc]) {
+ case 'a':
+ c[iDst] = '\007';
+ break;
+ case 'b':
+ c[iDst] = '\b';
+ break;
+ case 'f':
+ c[iDst] = '\014';
+ break;
+ case 'n':
+ c[iDst] = '\n';
+ break;
+ case 'r':
+ c[iDst] = '\r';
+ break;
+ case 't':
+ c[iDst] = '\t';
+ break;
+ case '\'':
+ c[iDst] = '\'';
+ break;
+ case '"':
+ c[iDst] = '"';
+ break;
+ case '?':
+ c[iDst] = '?';
+ break;
+ case '$':
+ c[iDst] = '$';
+ break;
+ case '\\':
+ c[iDst] = '\\';
+ break;
+ case 'x':
+ if( (*iSrc)+2 >= len
+ || !isxdigit(c[(*iSrc)+1])
+ || !isxdigit(c[(*iSrc)+2])) {
+ /* error, incomplete escape, use as is */
+ c[iDst] = '\\';
+ --(*iSrc);
+ }
+ c[iDst] = (hexDigitVal(c[(*iSrc)+1]) << 4) +
+ hexDigitVal(c[(*iSrc)+2]);
+ *iSrc += 2;
+ break;
+ case '0': /* octal escape */
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ if( (*iSrc)+2 >= len
+ || !isodigit(c[(*iSrc)+1])
+ || !isodigit(c[(*iSrc)+2])) {
+ /* error, incomplete escape, use as is */
+ c[iDst] = '\\';
+ --(*iSrc);
+ }
+ c[iDst] = ((c[(*iSrc) ] - '0') << 6) +
+ ((c[(*iSrc)+1] - '0') << 3) +
+ ( c[(*iSrc)+2] - '0');
+ *iSrc += 2;
+ break;
+ default:
+ /* error, incomplete escape, indicate by '?' */
+ c[iDst] = '?';
+ break;
+ }
+ } else {
+ /* regular character */
+ c[iDst] = c[*iSrc];
+ }
+}
+
+void
+unescapeStr(uchar *s, int len)
+{
+ int iSrc, iDst;
+ assert(s != NULL);
+
+ /* scan for first escape sequence (if we are luky, there is none!) */
+ iSrc = 0;
+ while(iSrc < len && s[iSrc] != '\\')
+ ++iSrc;
+ /* now we have a sequence or end of string. In any case, we process
+ * all remaining characters (maybe 0!) and unescape.
+ */
+ if(iSrc != len) {
+ iDst = iSrc;
+ while(iSrc < len) {
+ doUnescape(s, len, &iSrc, iDst);
+ ++iSrc;
+ ++iDst;
+ }
+ s[iDst] = '\0';
+ }
+}
+
+const char *
+tokenval2str(const int tok)
+{
+ if(tok < 256) return "";
+ switch(tok) {
+ case NAME: return "NAME";
+ case FUNC: return "FUNC";
+ case BEGINOBJ: return "BEGINOBJ";
+ case ENDOBJ: return "ENDOBJ";
+ case BEGIN_ACTION: return "BEGIN_ACTION";
+ case BEGIN_PROPERTY: return "BEGIN_PROPERTY";
+ case BEGIN_CONSTANT: return "BEGIN_CONSTANT";
+ case BEGIN_TPL: return "BEGIN_TPL";
+ case BEGIN_INCLUDE: return "BEGIN_INCLUDE";
+ case BEGIN_RULESET: return "BEGIN_RULESET";
+ case STOP: return "STOP";
+ case SET: return "SET";
+ case UNSET: return "UNSET";
+ case CONTINUE: return "CONTINUE";
+ case CALL: return "CALL";
+ case LEGACY_ACTION: return "LEGACY_ACTION";
+ case LEGACY_RULESET: return "LEGACY_RULESET";
+ case PRIFILT: return "PRIFILT";
+ case PROPFILT: return "PROPFILT";
+ case BSD_TAG_SELECTOR: return "BSD_TAG_SELECTOR";
+ case BSD_HOST_SELECTOR: return "BSD_HOST_SELECTOR";
+ case IF: return "IF";
+ case THEN: return "THEN";
+ case ELSE: return "ELSE";
+ case OR: return "OR";
+ case AND: return "AND";
+ case NOT: return "NOT";
+ case VAR: return "VAR";
+ case STRING: return "STRING";
+ case NUMBER: return "NUMBER";
+ case CMP_EQ: return "CMP_EQ";
+ case CMP_NE: return "CMP_NE";
+ case CMP_LE: return "CMP_LE";
+ case CMP_GE: return "CMP_GE";
+ case CMP_LT: return "CMP_LT";
+ case CMP_GT: return "CMP_GT";
+ case CMP_CONTAINS: return "CMP_CONTAINS";
+ case CMP_CONTAINSI: return "CMP_CONTAINSI";
+ case CMP_STARTSWITH: return "CMP_STARTSWITH";
+ case CMP_STARTSWITHI: return "CMP_STARTSWITHI";
+ case UMINUS: return "UMINUS";
+ default: return "UNKNOWN TOKEN";
+ }
+}
diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h
new file mode 100644
index 0000000..329f8bd
--- /dev/null
+++ b/grammar/rainerscript.h
@@ -0,0 +1,409 @@
+/* rsyslog rainerscript definitions
+ *
+ * Copyright 2011-2018 Rainer Gerhards
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * -or-
+ * see COPYING.ASL20 in the source distribution
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef INC_UTILS_H
+#define INC_UTILS_H
+#include <stdio.h>
+#include <libestr.h>
+#include <typedefs.h>
+#include <sys/types.h>
+#include <json.h>
+#include <regex.h>
+#include "typedefs.h"
+
+#define LOG_NFACILITIES 24+1 /* we copy&paste this as including rsyslog.h gets us in off64_t trouble... :-( */
+#define CNFFUNC_MAX_ARGS 32
+ /**< maximum number of arguments that any function can have (among
+ * others, this is used to size data structures).
+ */
+
+enum cnfobjType {
+ CNFOBJ_ACTION,
+ CNFOBJ_RULESET,
+ CNFOBJ_GLOBAL,
+ CNFOBJ_INPUT,
+ CNFOBJ_MODULE,
+ CNFOBJ_TPL,
+ CNFOBJ_PROPERTY,
+ CNFOBJ_CONSTANT,
+ CNFOBJ_MAINQ,
+ CNFOBJ_LOOKUP_TABLE,
+ CNFOBJ_PARSER,
+ CNFOBJ_TIMEZONE,
+ CNFOBJ_DYN_STATS,
+ CNFOBJ_PERCTILE_STATS,
+ CNFOBJ_INVALID = 0
+};
+
+const char* cnfobjType2str(enum cnfobjType ot);
+
+/* a variant type, for example used for expression evaluation
+ * 2011-07-15/rger: note that there exists a "legacy" object var,
+ * which implements the same idea, but in a suboptimal manner. I have
+ * stipped this down as much as possible, but will keep it for a while
+ * to avoid unnecessary complexity during development. TODO: in the long
+ * term, var shall be replaced by struct svar.
+ */
+struct svar{
+ union {
+ es_str_t *estr;
+ struct cnfarray *ar;
+ long long n;
+ struct json_object *json;
+ } d;
+ char datatype; /* 'N' number, 'S' string, 'J' JSON, 'A' array
+ * Note: 'A' is only supported during config phase
+ */
+};
+
+struct cnfobj {
+ enum cnfobjType objType;
+ struct nvlst *nvlst;
+ struct objlst *subobjs;
+ struct cnfstmt *script;
+};
+
+struct objlst {
+ struct objlst *next;
+ struct cnfobj *obj;
+};
+
+struct nvlst {
+ struct nvlst *next;
+ es_str_t *name;
+ struct svar val;
+ unsigned char bUsed;
+ /**< was this node used during config processing? If not, this
+ * indicates an error. After all, the user specified a setting
+ * that the software does not know.
+ */
+};
+
+/* the following structures support expressions, and may (very much later
+ * be the sole foundation for the AST.
+ *
+ * nodetypes (list not yet complete)
+ * A - (string) array
+ * F - function
+ * N - number
+ * P - fparamlst
+ * R - rule
+ * S - string
+ * V - var
+ * ... plus the S_* #define's below:
+ */
+#define S_STOP 4000
+#define S_PRIFILT 4001
+#define S_PROPFILT 4002
+#define S_IF 4003
+#define S_ACT 4004
+#define S_NOP 4005 /* usually used to disable some statement */
+#define S_SET 4006
+#define S_UNSET 4007
+#define S_CALL 4008
+#define S_FOREACH 4009
+#define S_RELOAD_LOOKUP_TABLE 4010
+#define S_CALL_INDIRECT 4011
+#define S_FUNC_EXISTS 4012 /* special case function which must get varname only */
+
+enum cnfFiltType { CNFFILT_NONE, CNFFILT_PRI, CNFFILT_PROP, CNFFILT_SCRIPT };
+const char* cnfFiltType2str(const enum cnfFiltType filttype);
+
+
+struct cnfstmt {
+ unsigned nodetype;
+ struct cnfstmt *next;
+ uchar *printable; /* printable text for debugging */
+ union {
+ struct {
+ struct cnfexpr *expr;
+ struct cnfstmt *t_then;
+ struct cnfstmt *t_else;
+ } s_if;
+ struct {
+ uchar *varname;
+ struct cnfexpr *expr;
+ int force_reset;
+ } s_set;
+ struct {
+ uchar *varname;
+ } s_unset;
+ struct {
+ es_str_t *name;
+ struct cnfstmt *stmt;
+ ruleset_t *ruleset; /* non-NULL if the ruleset has a queue assigned */
+ } s_call;
+ struct {
+ struct cnfexpr *expr;
+ } s_call_ind;
+ struct {
+ uchar pmask[LOG_NFACILITIES+1]; /* priority mask */
+ struct cnfstmt *t_then;
+ struct cnfstmt *t_else;
+ } s_prifilt;
+ struct {
+ fiop_t operation;
+ regex_t *regex_cache;/* cache for compiled REs, if used */
+ struct cstr_s *pCSCompValue;/* value to "compare" against */
+ sbool isNegated;
+ msgPropDescr_t prop; /* requested property */
+ struct cnfstmt *t_then;
+ struct cnfstmt *t_else;
+ } s_propfilt;
+ struct action_s *act;
+ struct {
+ struct cnfitr *iter;
+ struct cnfstmt *body;
+ } s_foreach;
+ struct {
+ lookup_ref_t *table;
+ uchar *table_name;
+ uchar *stub_value;
+ } s_reload_lookup_table;
+ } d;
+};
+
+struct cnfexpr {
+ unsigned nodetype;
+ struct cnfexpr *l;
+ struct cnfexpr *r;
+} __attribute__((aligned (8)));
+
+struct cnfitr {
+ char* var;
+ struct cnfexpr* collection;
+} __attribute__((aligned (8)));
+
+struct cnfnumval {
+ unsigned nodetype;
+ long long val;
+} __attribute__((aligned (8)));
+
+struct cnfstringval {
+ unsigned nodetype;
+ es_str_t *estr;
+} __attribute__((aligned (8)));
+
+struct cnfvar {
+ unsigned nodetype;
+ char *name;
+ msgPropDescr_t prop;
+} __attribute__((aligned (8)));
+
+struct cnfarray {
+ unsigned nodetype;
+ int nmemb;
+ es_str_t **arr;
+} __attribute__((aligned (8)));
+
+struct cnffparamlst {
+ unsigned nodetype; /* P */
+ struct cnffparamlst *next;
+ struct cnfexpr *expr;
+} __attribute__((aligned (8)));
+
+enum cnffuncid {
+ CNFFUNC_INVALID = 0, /**< defunct entry, do not use (should normally not be present) */
+ CNFFUNC_NAME = 1, /**< use name to call function (for future use) */
+ CNFFUNC_STRLEN,
+ CNFFUNC_SUBSTRING,
+ CNFFUNC_GETENV,
+ CNFFUNC_TOLOWER,
+ CNFFUNC_CSTR,
+ CNFFUNC_CNUM,
+ CNFFUNC_RE_MATCH,
+ CNFFUNC_RE_EXTRACT,
+ CNFFUNC_FIELD,
+ CNFFUNC_PRIFILT,
+ CNFFUNC_LOOKUP,
+ CNFFUNC_EXEC_TEMPLATE,
+ CNFFUNC_REPLACE,
+ CNFFUNC_WRAP,
+ CNFFUNC_RANDOM,
+ CNFFUNC_DYN_INC,
+ CNFFUNC_IPV42NUM,
+ CNFFUNC_NUM2IPV4,
+ CNFFUNC_INT2HEX,
+ CNFFUNC_LTRIM,
+ CNFFUNC_RTRIM,
+ CNFFUNC_FORMAT_TIME,
+ CNFFUNC_PARSE_TIME,
+ CNFFUNC_PARSE_JSON,
+ CNFFUNC_GET_PROPERTY,
+ CNFFUNC_PREVIOUS_ACTION_SUSPENDED,
+ CNFFUNC_SCRIPT_ERROR,
+ CNFFUNC_HTTP_REQUEST,
+ CNFFUNC_IS_TIME
+};
+
+typedef struct cnffunc cnffunc_t;
+typedef void (*rscriptFuncPtr) (cnffunc_t *, struct svar *, void *, wti_t *);
+
+struct cnffunc {
+ unsigned nodetype;
+ es_str_t *fname;
+ unsigned short nParams;
+ rscriptFuncPtr fPtr;
+ void *funcdata; /* global data for function-specific use (e.g. compiled regex) */
+ uint8_t destructable_funcdata;
+ struct cnfexpr *expr[];
+} __attribute__((aligned (8)));
+
+
+struct cnffuncexists {
+ unsigned nodetype;
+ const char *varname;
+ msgPropDescr_t prop;
+} __attribute__((aligned (8)));
+
+struct scriptFunct {
+ const char *fname;
+ unsigned short minParams;
+ unsigned short maxParams;
+ rscriptFuncPtr fPtr;
+ rsRetVal (*initFunc) (struct cnffunc *);
+ void (*destruct) (struct cnffunc *);
+ /* currently no optimizer entrypoint, may be added later.
+ * Since the optimizer needs metadata about functions, it does
+ * not seem practical to add such a function at the current state
+ */
+};
+
+
+/* future extensions
+<code>
+struct x {
+ int nodetype;
+};
+</code>
+*/
+
+
+/* the following defines describe the parameter block for puling
+ * config parameters. Note that the focus is on ease and saveness of
+ * use, not performance. For example, we address parameters by name
+ * instead of index, because the former is less error-prone. The (severe)
+ * performance hit does not matter, as it is a one-time hit during config
+ * load but never during actual processing. So there is really no reason
+ * to care.
+ */
+struct cnfparamdescr { /* first the param description */
+ const char *name;/**< not a es_str_t to ease definition in code */
+ ecslCmdHdrlType type;
+ unsigned flags;
+};
+/* flags for cnfparamdescr: */
+#define CNFPARAM_REQUIRED 0x0001
+#define CNFPARAM_DEPRECATED 0x0002
+
+struct cnfparamblk { /* now the actual param block use in API calls */
+ unsigned short version;
+ unsigned short nParams;
+ struct cnfparamdescr *descr;
+};
+#define CNFPARAMBLK_VERSION 1
+ /**< caller must have same version as engine -- else things may
+ * be messed up. But note that we may support multiple versions
+ * inside the engine, if at some later stage we want to do
+ * that. -- rgerhards, 2011-07-15
+ */
+struct cnfparamvals { /* the values we obtained for param descr. */
+ struct svar val;
+ unsigned char bUsed;
+};
+
+struct funcData_prifilt {
+ uchar pmask[LOG_NFACILITIES+1]; /* priority mask */
+};
+
+/* script errno-like interface error codes: */
+#define RS_SCRIPT_EOK 0
+#define RS_SCRIPT_EINVAL 1
+
+void varFreeMembers(const struct svar *r);
+rsRetVal addMod2List(const int version, struct scriptFunct *functArray);
+void readConfFile(FILE *fp, es_str_t **str);
+struct objlst* objlstNew(struct cnfobj *obj);
+void objlstDestruct(struct objlst *lst);
+void objlstPrint(struct objlst *lst);
+struct nvlst* nvlstNewArray(struct cnfarray *ar);
+struct nvlst* nvlstNewStr(es_str_t *value);
+struct nvlst* nvlstNewStrBackticks(es_str_t *const value);
+struct nvlst* nvlstSetName(struct nvlst *lst, es_str_t *name);
+void nvlstDestruct(struct nvlst *lst);
+void nvlstPrint(struct nvlst *lst);
+void nvlstChkUnused(struct nvlst *lst);
+struct nvlst* nvlstFindName(struct nvlst *lst, es_str_t *name);
+int nvlstChkDisabled(struct nvlst *lst);
+struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst);
+void cnfobjDestruct(struct cnfobj *o);
+void cnfobjPrint(struct cnfobj *o);
+struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r);
+void cnfexprPrint(struct cnfexpr *expr, int indent);
+void cnfexprEval(const struct cnfexpr *const expr, struct svar *ret, void *pusr, wti_t *pWti);
+int cnfexprEvalBool(struct cnfexpr *expr, void *usrptr, wti_t *pWti);
+struct json_object* cnfexprEvalCollection(struct cnfexpr * const expr, void * const usrptr, wti_t *pWti);
+void cnfexprDestruct(struct cnfexpr *expr);
+struct cnfnumval* cnfnumvalNew(long long val);
+struct cnfstringval* cnfstringvalNew(es_str_t *estr);
+struct cnfvar* cnfvarNew(char *name);
+struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst);
+struct cnffuncexists * cnffuncexistsNew(const char *varname);
+struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next);
+int cnfDoInclude(const char *name, const int optional);
+int cnfparamGetIdx(struct cnfparamblk *params, const char *name);
+struct cnfparamvals* nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params,
+ struct cnfparamvals *vals);
+void cnfparamsPrint(const struct cnfparamblk *params, const struct cnfparamvals *vals);
+int cnfparamvalsIsSet(struct cnfparamblk *params, struct cnfparamvals *vals);
+void varDelete(const struct svar *v);
+void cnfparamvalsDestruct(const struct cnfparamvals *paramvals, const struct cnfparamblk *blk);
+struct cnfstmt * cnfstmtNew(unsigned s_type);
+struct cnfitr * cnfNewIterator(char *var, struct cnfexpr *collection);
+void cnfstmtPrintOnly(struct cnfstmt *stmt, int indent, sbool subtree);
+void cnfstmtPrint(struct cnfstmt *stmt, int indent);
+struct cnfstmt* scriptAddStmt(struct cnfstmt *root, struct cnfstmt *s);
+struct objlst* objlstAdd(struct objlst *root, struct cnfobj *o);
+char *rmLeadingSpace(char *s);
+struct cnfstmt * cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then);
+struct cnfstmt * cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then);
+struct cnfstmt * cnfstmtNewAct(struct nvlst *lst);
+struct cnfstmt * cnfstmtNewLegaAct(char *actline);
+struct cnfstmt * cnfstmtNewSet(char *var, struct cnfexpr *expr, int force_reset);
+struct cnfstmt * cnfstmtNewUnset(char *var);
+struct cnfstmt * cnfstmtNewCall(es_str_t *name);
+struct cnfstmt * cnfstmtNewContinue(void);
+struct cnfstmt * cnfstmtNewReloadLookupTable(struct cnffparamlst *fparams);
+void cnfstmtDestructLst(struct cnfstmt *root);
+struct cnfstmt *cnfstmtOptimize(struct cnfstmt *root);
+struct cnfarray* cnfarrayNew(es_str_t *val);
+struct cnfarray* cnfarrayDup(struct cnfarray *old);
+struct cnfarray* cnfarrayAdd(struct cnfarray *ar, es_str_t *val);
+void cnfarrayContentDestruct(struct cnfarray *ar);
+const char* getFIOPName(unsigned iFIOP);
+rsRetVal initRainerscript(void);
+void unescapeStr(uchar *s, int len);
+const char * tokenval2str(int tok);
+uchar* var2CString(struct svar *__restrict__ const r, int *__restrict__ const bMustFree);
+long long var2Number(struct svar *r, int *bSuccess);
+void includeProcessCnf(struct nvlst *const lst);
+
+/* debug helper */
+void cstrPrint(const char *text, es_str_t *estr);
+
+#endif